mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2025-04-21 12:27:27 +03:00
ubb-vga2: added support for showing a PPM image
- Makefile (OBJS): added ppm.o and ppmimg.o - ppm.h (load_ppm), ppm.c: PPM file loader, adapted from eda-tools/schhist/ppmdiff/ppmdiff.c - ubb-vga.h (img_name, ppmimg), ppmimg.c: PPM image to frame buffer converter - ubb-vga2.c (usage, main): the threshold is now set with the option -l - ubb-vga2.c (usage, main): if a second argument is given, treat it as a PPM file - ubb-vga2.c (usage): also documented option -t
This commit is contained in:
63
ubb-vga/ppmimg.c
Normal file
63
ubb-vga/ppmimg.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
|
||||
static uint8_t pattern(int r, int g, int b)
|
||||
{
|
||||
return ((r ? R_VAL : 0) | (g ? G_VAL : 0) | (b ? B_VAL : 0))*0x11;
|
||||
}
|
||||
|
||||
|
||||
static void convert(uint8_t *f, int xres, int yres, uint8_t *ppm)
|
||||
{
|
||||
int x, y;
|
||||
uint8_t v, last = 0;
|
||||
|
||||
for (y = 0; y != yres; y++)
|
||||
for (x = 0; x != xres; x++) {
|
||||
v = pattern(ppm[0] >= thres, ppm[1] >= thres,
|
||||
ppm[2] >= thres);
|
||||
if (x & 1) {
|
||||
*f++ = last | v;
|
||||
} else {
|
||||
last = v << 4;
|
||||
}
|
||||
ppm += 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ppmimg(void *f, int xres, int yres)
|
||||
{
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user