Root/ubb-vga/ppmimg.c

1/*
2 * ppmimg.c - Convert a PPM image
3 *
4 * Written 2011 by Werner Almesberger
5 * Copyright 2011 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdint.h>
15#include <stdlib.h>
16#include <stdio.h>
17
18#include "ppm.h"
19#include "ubb-vga.h"
20
21
22char *img_name;
23
24
25static void convert(void **f, int xres, int yres, uint8_t *ppm)
26{
27    int x, y;
28    uint8_t *p;
29    uint8_t v, last = 0;
30
31    for (y = 0; y != yres; y++) {
32        p = f[y];
33        for (x = 0; x != xres; x++) {
34            v = ccube_map(ppm[0], ppm[1], ppm[2]);
35            if (x & 1) {
36                *p++ = last | v;
37            } else {
38                last = v << 4;
39            }
40            ppm += 3;
41        }
42    }
43}
44
45
46void ppmimg(void **f, int xres, int yres)
47{
48    uint8_t *ppm;
49    int xr = 0, yr = 0;
50
51    ppm = load_ppm(img_name, &xr, &yr);
52    if (xr != xres || yr != yres) {
53        fprintf(stderr, "image is %dx%d, display is %dx%d\n",
54            xr, yr, xres, yres);
55        exit(1);
56    }
57    convert(f, xres, yres, ppm);
58    free(ppm);
59}
60

Archive Download this file

Branches:
master



interactive