mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-27 15:41:53 +02:00
ubb-vga2: replaced threshold-based color mapping with color cube model
- ubb-vga.h (ccube_init, ccube_map), ccube.c: color mapper based on proximity in color cube - grabfb.c (pattern, grabfb), ppmimg.c (pattern, convert): use the color cube mapper instead of inferios threshold-based mapping - ubb-vga2.c (session): initialize the color cube - ubb-vga.h (thres), grabfb.c (thres), ubb-vga2.c (usage, main): removed the threshold along with the option (-l) to set it - Makefile (OBJS): added ccube.o
This commit is contained in:
parent
f0eda51391
commit
6558f56de6
@ -3,7 +3,7 @@ CC=mipsel-linux-gcc
|
|||||||
|
|
||||||
CFLAGS=-Wall -g -O9 -march=mips32
|
CFLAGS=-Wall -g -O9 -march=mips32
|
||||||
LDFLAGS=-lm
|
LDFLAGS=-lm
|
||||||
OBJS=ubb-vga2.o grabfb.o tstimg.o ppm.o ppmimg.o
|
OBJS=ubb-vga2.o grabfb.o tstimg.o ppm.o ppmimg.o ccube.o
|
||||||
|
|
||||||
.PHONY: all asm sch clean spotless
|
.PHONY: all asm sch clean spotless
|
||||||
|
|
||||||
|
58
ubb-vga/ccube.c
Normal file
58
ubb-vga/ccube.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* ccube.c - Color mapper based on color cube model
|
||||||
|
*
|
||||||
|
* 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 "ubb-vga.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define W_RGB (256*0.5)
|
||||||
|
#define W_Y (256*0.25)
|
||||||
|
#define W_0 (256*0.125)
|
||||||
|
|
||||||
|
|
||||||
|
static struct col {
|
||||||
|
uint8_t r, g, b;
|
||||||
|
} col[16];
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t ccube_map(uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
{
|
||||||
|
unsigned best = 0;
|
||||||
|
int best_i = 0;
|
||||||
|
unsigned d;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i != 16; i++) {
|
||||||
|
d = (r-col[i].r)*(r-col[i].r)+
|
||||||
|
(g-col[i].g)*(g-col[i].g)+
|
||||||
|
(b-col[i].b)*(b-col[i].b);
|
||||||
|
if (!i || d < best) {
|
||||||
|
best = d;
|
||||||
|
best_i = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best_i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ccube_init(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i != 16; i++) {
|
||||||
|
col[i].r = W_0+(i & R_VAL ? W_RGB : 0)+(i & Y_VAL ? W_Y : 0);
|
||||||
|
col[i].g = W_0+(i & G_VAL ? W_RGB : 0)+(i & Y_VAL ? W_Y : 0);
|
||||||
|
col[i].b = W_0+(i & B_VAL ? W_RGB : 0)+(i & Y_VAL ? W_Y : 0);
|
||||||
|
}
|
||||||
|
}
|
@ -17,15 +17,6 @@
|
|||||||
#include "ubb-vga.h"
|
#include "ubb-vga.h"
|
||||||
|
|
||||||
|
|
||||||
uint8_t thres = 63;
|
|
||||||
|
|
||||||
|
|
||||||
static uint8_t pattern(int r, int g, int b)
|
|
||||||
{
|
|
||||||
return ((r ? R_VAL : 0) | (g ? G_VAL : 0) | (b ? B_VAL : 0))*0x11;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void grabfb(void *f, int xres, int yres)
|
void grabfb(void *f, int xres, int yres)
|
||||||
{
|
{
|
||||||
uint32_t *fb = map(0x01d00000, 4*320*240);
|
uint32_t *fb = map(0x01d00000, 4*320*240);
|
||||||
@ -42,8 +33,7 @@ void grabfb(void *f, int xres, int yres)
|
|||||||
r = pix >> 16;
|
r = pix >> 16;
|
||||||
g = pix >> 8;
|
g = pix >> 8;
|
||||||
b = pix;
|
b = pix;
|
||||||
p[0] = p[320] =
|
p[0] = p[320] = ccube_map(r, g, b)*0x11;
|
||||||
pattern(r >= thres, g >= thres, b >= thres);
|
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
p += 320;
|
p += 320;
|
||||||
|
@ -22,12 +22,6 @@
|
|||||||
char *img_name;
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void convert(uint8_t *f, int xres, int yres, uint8_t *ppm)
|
static void convert(uint8_t *f, int xres, int yres, uint8_t *ppm)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
@ -35,8 +29,7 @@ static void convert(uint8_t *f, int xres, int yres, uint8_t *ppm)
|
|||||||
|
|
||||||
for (y = 0; y != yres; y++)
|
for (y = 0; y != yres; y++)
|
||||||
for (x = 0; x != xres; x++) {
|
for (x = 0; x != xres; x++) {
|
||||||
v = pattern(ppm[0] >= thres, ppm[1] >= thres,
|
v = ccube_map(ppm[0], ppm[1], ppm[2]);
|
||||||
ppm[2] >= thres);
|
|
||||||
if (x & 1) {
|
if (x & 1) {
|
||||||
*f++ = last | v;
|
*f++ = last | v;
|
||||||
} else {
|
} else {
|
||||||
|
@ -26,9 +26,12 @@
|
|||||||
void *map(off_t addr, size_t size);
|
void *map(off_t addr, size_t size);
|
||||||
|
|
||||||
|
|
||||||
/* grabfb.c */
|
/* ccube.c */
|
||||||
|
|
||||||
extern uint8_t thres;
|
uint8_t ccube_map(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
void ccube_init(void);
|
||||||
|
|
||||||
|
/* grabfb.c */
|
||||||
|
|
||||||
void grabfb(void *f, int xres, int yres);
|
void grabfb(void *f, int xres, int yres);
|
||||||
|
|
||||||
|
@ -396,6 +396,7 @@ static void session(void (*gen)(void *fb, int xres, int yres), int frames)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
memset(f, 0, sizeof(f));
|
memset(f, 0, sizeof(f));
|
||||||
|
ccube_init();
|
||||||
gen(f, 640, 480);
|
gen(f, 640, 480);
|
||||||
|
|
||||||
disable_interrupts();
|
disable_interrupts();
|
||||||
@ -410,10 +411,9 @@ static void session(void (*gen)(void *fb, int xres, int yres), int frames)
|
|||||||
static void usage(const char *name)
|
static void usage(const char *name)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"usage: %s [-l threshold] [-t] frames [file]\n\n"
|
"usage: %s [-t] frames [file]\n\n"
|
||||||
" frames number of frames to display\n"
|
" frames number of frames to display\n"
|
||||||
" file PPM file\n\n"
|
" file PPM file\n\n"
|
||||||
" -l threshold channel on/off threshold\n"
|
|
||||||
" -t generate a test image\n"
|
" -t generate a test image\n"
|
||||||
, name);
|
, name);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -426,11 +426,8 @@ int main(int argc, char *const *argv)
|
|||||||
int frames;
|
int frames;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "l:t")) != EOF)
|
while ((c = getopt(argc, argv, "t")) != EOF)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'l':
|
|
||||||
thres = atoi(optarg);
|
|
||||||
break;
|
|
||||||
case 't':
|
case 't':
|
||||||
gen = tstimg;
|
gen = tstimg;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user