2011-04-28 06:38:13 +03:00
|
|
|
/*
|
|
|
|
* ppmimg.c - Convert a PPM image
|
|
|
|
*
|
|
|
|
* Written 2011 by Werner Almesberger
|
|
|
|
* Copyright 2011 Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "ppm.h"
|
|
|
|
#include "ubb-vga.h"
|
|
|
|
|
|
|
|
|
|
|
|
char *img_name;
|
|
|
|
|
|
|
|
|
ubb-vga2: non-contiguous allocation of frame buffer memory
- ubb-vga.h (calloc_phys_vec), physmem.c: non-contiguous memory allocator
(for now, without really considering any mapping to physical memory)
- Makefile (OBJS): added physmem.o
- ubb-vga.h (grabfb), grabfb.c (grabfb): API change for non-contiguous
frame buffer
- ubb-vga.h (ppmimg), ppmimg.c (convert, ppmimg): API change for
non-contiguous frame buffer
- ubb-vga.h (tstimg), tstimg.c (pixel, color_bars, grill, grid, sides,
dot, line45, arc, printc, text, ctext, tstimg): API change for
non-contiguous frame buffer
- tstimg.c (tstimg): we no longer need to clear the frame buffer
- ubb-vga.c (frame, session, main): use a vector of line buffers instead
of a contiguous frame buffer
2011-04-29 19:04:02 +03:00
|
|
|
static void convert(void **f, int xres, int yres, uint8_t *ppm)
|
2011-04-28 06:38:13 +03:00
|
|
|
{
|
|
|
|
int x, y;
|
ubb-vga2: non-contiguous allocation of frame buffer memory
- ubb-vga.h (calloc_phys_vec), physmem.c: non-contiguous memory allocator
(for now, without really considering any mapping to physical memory)
- Makefile (OBJS): added physmem.o
- ubb-vga.h (grabfb), grabfb.c (grabfb): API change for non-contiguous
frame buffer
- ubb-vga.h (ppmimg), ppmimg.c (convert, ppmimg): API change for
non-contiguous frame buffer
- ubb-vga.h (tstimg), tstimg.c (pixel, color_bars, grill, grid, sides,
dot, line45, arc, printc, text, ctext, tstimg): API change for
non-contiguous frame buffer
- tstimg.c (tstimg): we no longer need to clear the frame buffer
- ubb-vga.c (frame, session, main): use a vector of line buffers instead
of a contiguous frame buffer
2011-04-29 19:04:02 +03:00
|
|
|
uint8_t *p;
|
2011-04-28 06:38:13 +03:00
|
|
|
uint8_t v, last = 0;
|
|
|
|
|
ubb-vga2: non-contiguous allocation of frame buffer memory
- ubb-vga.h (calloc_phys_vec), physmem.c: non-contiguous memory allocator
(for now, without really considering any mapping to physical memory)
- Makefile (OBJS): added physmem.o
- ubb-vga.h (grabfb), grabfb.c (grabfb): API change for non-contiguous
frame buffer
- ubb-vga.h (ppmimg), ppmimg.c (convert, ppmimg): API change for
non-contiguous frame buffer
- ubb-vga.h (tstimg), tstimg.c (pixel, color_bars, grill, grid, sides,
dot, line45, arc, printc, text, ctext, tstimg): API change for
non-contiguous frame buffer
- tstimg.c (tstimg): we no longer need to clear the frame buffer
- ubb-vga.c (frame, session, main): use a vector of line buffers instead
of a contiguous frame buffer
2011-04-29 19:04:02 +03:00
|
|
|
for (y = 0; y != yres; y++) {
|
|
|
|
p = f[y];
|
2011-04-28 06:38:13 +03:00
|
|
|
for (x = 0; x != xres; x++) {
|
2011-04-28 07:18:03 +03:00
|
|
|
v = ccube_map(ppm[0], ppm[1], ppm[2]);
|
2011-04-28 06:38:13 +03:00
|
|
|
if (x & 1) {
|
ubb-vga2: non-contiguous allocation of frame buffer memory
- ubb-vga.h (calloc_phys_vec), physmem.c: non-contiguous memory allocator
(for now, without really considering any mapping to physical memory)
- Makefile (OBJS): added physmem.o
- ubb-vga.h (grabfb), grabfb.c (grabfb): API change for non-contiguous
frame buffer
- ubb-vga.h (ppmimg), ppmimg.c (convert, ppmimg): API change for
non-contiguous frame buffer
- ubb-vga.h (tstimg), tstimg.c (pixel, color_bars, grill, grid, sides,
dot, line45, arc, printc, text, ctext, tstimg): API change for
non-contiguous frame buffer
- tstimg.c (tstimg): we no longer need to clear the frame buffer
- ubb-vga.c (frame, session, main): use a vector of line buffers instead
of a contiguous frame buffer
2011-04-29 19:04:02 +03:00
|
|
|
*p++ = last | v;
|
2011-04-28 06:38:13 +03:00
|
|
|
} else {
|
|
|
|
last = v << 4;
|
|
|
|
}
|
|
|
|
ppm += 3;
|
|
|
|
}
|
ubb-vga2: non-contiguous allocation of frame buffer memory
- ubb-vga.h (calloc_phys_vec), physmem.c: non-contiguous memory allocator
(for now, without really considering any mapping to physical memory)
- Makefile (OBJS): added physmem.o
- ubb-vga.h (grabfb), grabfb.c (grabfb): API change for non-contiguous
frame buffer
- ubb-vga.h (ppmimg), ppmimg.c (convert, ppmimg): API change for
non-contiguous frame buffer
- ubb-vga.h (tstimg), tstimg.c (pixel, color_bars, grill, grid, sides,
dot, line45, arc, printc, text, ctext, tstimg): API change for
non-contiguous frame buffer
- tstimg.c (tstimg): we no longer need to clear the frame buffer
- ubb-vga.c (frame, session, main): use a vector of line buffers instead
of a contiguous frame buffer
2011-04-29 19:04:02 +03:00
|
|
|
}
|
2011-04-28 06:38:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
ubb-vga2: non-contiguous allocation of frame buffer memory
- ubb-vga.h (calloc_phys_vec), physmem.c: non-contiguous memory allocator
(for now, without really considering any mapping to physical memory)
- Makefile (OBJS): added physmem.o
- ubb-vga.h (grabfb), grabfb.c (grabfb): API change for non-contiguous
frame buffer
- ubb-vga.h (ppmimg), ppmimg.c (convert, ppmimg): API change for
non-contiguous frame buffer
- ubb-vga.h (tstimg), tstimg.c (pixel, color_bars, grill, grid, sides,
dot, line45, arc, printc, text, ctext, tstimg): API change for
non-contiguous frame buffer
- tstimg.c (tstimg): we no longer need to clear the frame buffer
- ubb-vga.c (frame, session, main): use a vector of line buffers instead
of a contiguous frame buffer
2011-04-29 19:04:02 +03:00
|
|
|
void ppmimg(void **f, int xres, int yres)
|
2011-04-28 06:38:13 +03:00
|
|
|
{
|
|
|
|
uint8_t *ppm;
|
|
|
|
int xr = 0, yr = 0;
|
|
|
|
|
|
|
|
ppm = load_ppm(img_name, &xr, &yr);
|
|
|
|
if (xr != xres || yr != yres) {
|
|
|
|
fprintf(stderr, "image is %dx%d, display is %dx%d\n",
|
|
|
|
xr, yr, xres, yres);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
convert(f, xres, yres, ppm);
|
|
|
|
free(ppm);
|
|
|
|
}
|