Merge pull request #65 from kwagyeman/master

* Move image macros to imlib.c.
* Add prefix to image macros.
* Add RGB LUT, and gen_rgb2rgb.py  script.
This commit is contained in:
Ibrahim Abd Elkader 2016-02-16 17:24:48 +02:00
commit e3b76ebabb
10 changed files with 1220 additions and 996 deletions

View File

@ -132,6 +132,7 @@ OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/img/,\
xyz_tab.o \ xyz_tab.o \
yuv_tab.o \ yuv_tab.o \
rainbow_tab.o \ rainbow_tab.o \
rgb2rgb_tab.o \
median.o \ median.o \
point.o \ point.o \
ppm.o \ ppm.o \

View File

@ -35,6 +35,7 @@ SRCS += $(addprefix img/, \
xyz_tab.c \ xyz_tab.c \
yuv_tab.c \ yuv_tab.c \
rainbow_tab.c \ rainbow_tab.c \
rgb2rgb_tab.c \
median.c \ median.c \
point.c \ point.c \
ppm.c \ ppm.c \

View File

@ -24,11 +24,8 @@
* line scan direction: forward * line scan direction: forward
* inverse: yes * inverse: yes
*/ */
#include <stdint.h>
#include "font.h" #include "font.h"
const glyph_t font[95] = { const glyph_t font[95] = {
// character: ' ' // character: ' '
{8, 10, {0x00, {8, 10, {0x00,
0x00, 0x00,

View File

@ -8,6 +8,7 @@
*/ */
#ifndef __FONT_H__ #ifndef __FONT_H__
#define __FONT_H__ #define __FONT_H__
#include <stdint.h>
typedef struct { typedef struct {
int w; int w;
int h; int h;

View File

@ -17,34 +17,6 @@
#include "mdefs.h" #include "mdefs.h"
#include "font.h" #include "font.h"
#define PIXEL_AT(src, x, y) \
({ __typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
src->data[_y*src->w+_x]; })
#define SET_PIXEL(src, x, y, c) \
({ __typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
src->data[_y*src->w+_x]=c; })
#define R565(p) \
(uint32_t)((p>>3)&0x1F)
#define G565(p) \
(uint32_t)(((p&0x07)<<3)|(p>>13))
#define B565(p) \
(uint32_t)((p>>8)&0x1F)
#define RGB565(r, g, b)\
(uint32_t)(((r&0x1F)<<3)|((g&0x3F)>>3)|(g<<13)|((b&0x1F)<<8))
#define SWAP16(x) __REV16(x)
#define SWAP32(x) __REV32(x)
#define MAX_GRAY_LEVEL (255)
/* XYZ lookup table */ /* XYZ lookup table */
extern const float xyz_table[256]; extern const float xyz_table[256];
/* RGB565->LAB lookup */ /* RGB565->LAB lookup */
@ -52,6 +24,28 @@ extern const int8_t lab_table[196608];
/* Grayscale [0..255] to rainbox lookup */ /* Grayscale [0..255] to rainbox lookup */
extern const uint16_t rainbow_table[256]; extern const uint16_t rainbow_table[256];
// Get pixel (handles boundary check and image type check).
int imlib_get_pixel(image_t *img, int x, int y)
{
return (IM_X_INSIDE(img, x) && IM_Y_INSIDE(img, y)) ?
( IM_IS_GS(img)
? IM_GET_GS_PIXEL(img, x, y)
: IM_GET_RGB565_PIXEL(img, x, y) )
: 0;
}
// Set pixel (handles boundary check and image type check).
void imlib_set_pixel(image_t *img, int x, int y, int p)
{
if (IM_X_INSIDE(img, x) && IM_Y_INSIDE(img, y)) {
if (IM_IS_GS(img)) {
IM_SET_GS_PIXEL(img, x, y, p);
} else {
IM_SET_RGB565_PIXEL(img, x, y, p);
}
}
}
uint32_t imlib_lab_distance(struct color *c0, struct color *c1) uint32_t imlib_lab_distance(struct color *c0, struct color *c1)
{ {
uint32_t sum=0; uint32_t sum=0;
@ -294,7 +288,7 @@ void imlib_threshold(image_t *src, image_t *dst, color_t *color, int color_size,
uint16_t r = color[c].r*31/255; uint16_t r = color[c].r*31/255;
uint16_t g = color[c].g*63/255; uint16_t g = color[c].g*63/255;
uint16_t b = color[c].b*31/255; uint16_t b = color[c].b*31/255;
uint32_t rgb = SWAP16((r << 11) | (g << 5) | b) * 3; uint32_t rgb = IM_SWAP16((r << 11) | (g << 5) | b) * 3;
color[c].L = lab_table[rgb]; color[c].L = lab_table[rgb];
color[c].A = lab_table[rgb+1]; color[c].A = lab_table[rgb+1];
@ -419,13 +413,13 @@ void imlib_blend(struct image *src, struct image *dst, int x_off, int y_off, uin
for (int x=x_off; x<src->w+x_off; x++) { for (int x=x_off; x<src->w+x_off; x++) {
spix = *srcp++; spix = *srcp++;
dpix = dstp[i+x]; dpix = dstp[i+x];
vr = __PKHBT(R565(dpix), R565(spix), 16); vr = __PKHBT(IM_R565(dpix), IM_R565(spix), 16);
vg = __PKHBT(G565(dpix), G565(spix), 16); vg = __PKHBT(IM_G565(dpix), IM_G565(spix), 16);
vb = __PKHBT(B565(dpix), B565(spix), 16); vb = __PKHBT(IM_B565(dpix), IM_B565(spix), 16);
r = __SMUAD(v0, vr)>>8; r = __SMUAD(v0, vr)>>8;
g = __SMUAD(v0, vg)>>8; g = __SMUAD(v0, vg)>>8;
b = __SMUAD(v0, vb)>>8; b = __SMUAD(v0, vb)>>8;
dstp[i+x]= RGB565(r, g, b); dstp[i+x]= IM_RGB565(r, g, b);
} }
} }
} }
@ -512,18 +506,18 @@ void imlib_scale_bilinear(struct image *src, struct image *dst)
D = srcp[index+w1+1]; D = srcp[index+w1+1];
// Yb = Ar(1-w)(1-h) + Br(w)(1-h) + Cr(h)(1-w) + Dr(wh) // Yb = Ar(1-w)(1-h) + Br(w)(1-h) + Cr(h)(1-w) + Dr(wh)
r = (int)(R565(A)*(1-x_diff)*(1-y_diff) + R565(B)*(x_diff)*(1-y_diff) + r = (int)(IM_R565(A)*(1-x_diff)*(1-y_diff) + IM_R565(B)*(x_diff)*(1-y_diff) +
R565(C)*(y_diff)*(1-x_diff) + R565(D)*(x_diff*y_diff)); IM_R565(C)*(y_diff)*(1-x_diff) + IM_R565(D)*(x_diff*y_diff));
// Yb = Ag(1-w)(1-h) + Bg(w)(1-h) + Cg(h)(1-w) + Dg(wh) // Yb = Ag(1-w)(1-h) + Bg(w)(1-h) + Cg(h)(1-w) + Dg(wh)
g = (int)(G565(A)*(1-x_diff)*(1-y_diff) + G565(B)*(x_diff)*(1-y_diff) + g = (int)(IM_G565(A)*(1-x_diff)*(1-y_diff) + IM_G565(B)*(x_diff)*(1-y_diff) +
G565(C)*(y_diff)*(1-x_diff) + G565(D)*(x_diff*y_diff)); IM_G565(C)*(y_diff)*(1-x_diff) + IM_G565(D)*(x_diff*y_diff));
// Yb = Ab(1-w)(1-h) + Bb(w)(1-h) + Cb(h)(1-w) + Db(wh) // Yb = Ab(1-w)(1-h) + Bb(w)(1-h) + Cb(h)(1-w) + Db(wh)
b =(int)(B565(A)*(1-x_diff)*(1-y_diff) + B565(B)*(x_diff)*(1-y_diff) + b =(int)(IM_B565(A)*(1-x_diff)*(1-y_diff) + IM_B565(B)*(x_diff)*(1-y_diff) +
B565(C)*(y_diff)*(1-x_diff) + B565(D)*(x_diff*y_diff)); IM_B565(C)*(y_diff)*(1-x_diff) + IM_B565(D)*(x_diff*y_diff));
dstp[offset++] = RGB565(r, g, b); dstp[offset++] = IM_RGB565(r, g, b);
} }
} }
} }
@ -625,21 +619,21 @@ void imlib_draw_circle(struct image *image, int cx, int cy, int r, color_t *colo
{ {
int x = r, y = 0; int x = r, y = 0;
int radiusError = 1-x; int radiusError = 1-x;
uint16_t c = RGB565(color->r, color->g, color->b); uint16_t c = IM_RGB565(color->r, color->g, color->b);
if (cx+r >= image->w || cx-r < 0 || if (cx+r >= image->w || cx-r < 0 ||
cy+r >= image->h || cy-r < 0) { cy+r >= image->h || cy-r < 0) {
return; return;
} }
while(x >= y) { while(x >= y) {
SET_PIXEL(image, x + cx, y + cy, c); imlib_set_pixel(image, x + cx, y + cy, c);
SET_PIXEL(image, y + cx, x + cy, c); imlib_set_pixel(image, y + cx, x + cy, c);
SET_PIXEL(image, -x + cx, y + cy, c); imlib_set_pixel(image, -x + cx, y + cy, c);
SET_PIXEL(image, -y + cx, x + cy, c); imlib_set_pixel(image, -y + cx, x + cy, c);
SET_PIXEL(image, -x + cx, -y + cy, c); imlib_set_pixel(image, -x + cx, -y + cy, c);
SET_PIXEL(image, -y + cx, -x + cy, c); imlib_set_pixel(image, -y + cx, -x + cy, c);
SET_PIXEL(image, x + cx, -y + cy, c); imlib_set_pixel(image, x + cx, -y + cy, c);
SET_PIXEL(image, y + cx, -x + cy, c); imlib_set_pixel(image, y + cx, -x + cy, c);
y++; y++;
if (radiusError<0) { if (radiusError<0) {
radiusError += 2 * y + 1; radiusError += 2 * y + 1;
@ -679,7 +673,7 @@ void imlib_draw_string(image_t *src, int x_off, int y_off, const char *str, colo
const glyph_t *g; const glyph_t *g;
uint8_t *srcp8 = (uint8_t*)src->pixels; uint8_t *srcp8 = (uint8_t*)src->pixels;
uint16_t *srcp16 = (uint16_t*)src->pixels; uint16_t *srcp16 = (uint16_t*)src->pixels;
uint16_t color = RGB565(c->r, c->g, c->b); uint16_t color = IM_RGB565(c->r, c->g, c->b);
for(char c; (c=*str); str++) { for(char c; (c=*str); str++) {
if (c < ' ' || c > '~') { if (c < ' ' || c > '~') {
@ -705,7 +699,7 @@ void imlib_histeq(struct image *src)
{ {
int i, sum; int i, sum;
int a = src->w*src->h; int a = src->w*src->h;
uint32_t hist[MAX_GRAY_LEVEL+1]={0}; uint32_t hist[IM_MAX_GS+1]={0};
/* compute image histogram */ /* compute image histogram */
for (i=0; i<a; i++) { for (i=0; i<a; i++) {
@ -713,13 +707,13 @@ void imlib_histeq(struct image *src)
} }
/* compute the CDF */ /* compute the CDF */
for (i=0, sum=0; i<MAX_GRAY_LEVEL+1; i++) { for (i=0, sum=0; i<IM_MAX_GS+1; i++) {
sum += hist[i]; sum += hist[i];
hist[i] = sum; hist[i] = sum;
} }
for (i=0; i<a; i++) { for (i=0; i<a; i++) {
src->pixels[i] = (uint8_t) ((MAX_GRAY_LEVEL/(float)a) * hist[src->pixels[i]]); src->pixels[i] = (uint8_t) ((IM_MAX_GS/(float)a) * hist[src->pixels[i]]);
} }
} }

View File

@ -8,20 +8,137 @@
*/ */
#ifndef __IMLIB_H__ #ifndef __IMLIB_H__
#define __IMLIB_H__ #define __IMLIB_H__
#include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include "array.h" #include "array.h"
#include "fmath.h" #include "fmath.h"
#define IM_SWAP16(x) __REV16(x) // Swap bottom two chars in short.
#define IM_SWAP32(x) __REV32(x) // Swap bottom two shorts in long.
#define IM_MIN(a,b) \ #define IM_MIN(a,b) \
({ __typeof__ (a) _a = (a); \ ({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \ __typeof__ (b) _b = (b); \
_a < _b ? _a : _b; }) _a < _b ? _a : _b; })
#define IM_MAX(a,b) \ #define IM_MAX(a,b) \
({ __typeof__ (a) _a = (a); \ ({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \ __typeof__ (b) _b = (b); \
_a > _b ? _a : _b; }) _a > _b ? _a : _b; })
// RGB565 to RGB888 conversion.
extern const uint8_t rb528_table[32];
extern const uint8_t g628_table[64];
#define IM_R528(p) \
({ __typeof__ (p) _p = (p); \
rb528_table[_p]; })
#define IM_G628(p) \
({ __typeof__ (p) _p = (p); \
g628_table[_p]; })
#define IM_B528(p) \
({ __typeof__ (p) _p = (p); \
rb528_table[_p]; })
// RGB888 to RGB565 conversion.
extern const uint8_t rb825_table[256];
extern const uint8_t g826_table[256];
#define IM_R825(p) \
({ __typeof__ (p) _p = (p); \
rb825_table[_p]; })
#define IM_G826(p) \
({ __typeof__ (p) _p = (p); \
g826_table[_p]; })
#define IM_B825(p) \
({ __typeof__ (p) _p = (p); \
rb825_table[_p]; })
// Split RGB565 values (note the RGB565 value is byte reversed).
#define IM_R565(p) \
({ __typeof__ (p) _p = (p); \
((_p)>>3)&0x1F; })
#define IM_G565(p) \
({ __typeof__ (p) _p = (p); \
(((_p)&0x07)<<3)|((_p)>>13); })
#define IM_B565(p) \
({ __typeof__ (p) _p = (p); \
((_p)>>8)&0x1F; })
// Merge RGB565 values (note the RGB565 value is byte reversed).
#define IM_RGB565(r, g, b) \
({ __typeof__ (r) _r = (r); \
__typeof__ (g) _g = (g); \
__typeof__ (b) _b = (b); \
((_r)<<3)|((_g)>>3)|((_g)<<13)|((_b)<<8); })
// Grayscale maxes
#define IM_MAX_GS (255)
// RGB565 maxes
#define IM_MAX_R5 (31)
#define IM_MAX_G6 (63)
#define IM_MAX_B5 (31)
#define IM_IS_NULL(img) \
({ __typeof__ (img) _img = (img); \
_img->bpp <= 0; })
#define IM_IS_GS(img) \
({ __typeof__ (img) _img = (img); \
_img->bpp == 1; })
#define IM_IS_RGB565(img) \
({ __typeof__ (img) _img = (img); \
_img->bpp == 2; })
#define IM_IS_JPEG(img) \
({ __typeof__ (img) _img = (img); \
_img->bpp >= 3; })
#define IM_X_INSIDE(img, x) \
({ __typeof__ (img) _img = (img); \
__typeof__ (x) _x = (x); \
(0<=_x)&&(_x<_img->w); })
#define IM_Y_INSIDE(img, y) \
({ __typeof__ (img) _img = (img); \
__typeof__ (y) _y = (y); \
(0<=_y)&&(_y<_img->h); })
#define IM_GET_GS_PIXEL(img, x, y) \
({ __typeof__ (img) _img = (img); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
((uint8_t*)_img->pixels)[(_y*_img->w)+_x]; })
#define IM_GET_RGB565_PIXEL(img, x, y) \
({ __typeof__ (img) _img = (img); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
((uint16_t*)_img->pixels)[(_y*_img->w)+_x]; })
#define IM_SET_GS_PIXEL(img, x, y, p) \
({ __typeof__ (img) _img = (img); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
__typeof__ (p) _p = (p); \
((uint8_t*)_img->pixels)[(_y*_img->w)+_x]=_p; })
#define IM_SET_RGB565_PIXEL(img, x, y, p) \
({ __typeof__ (img) _img = (img); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
__typeof__ (p) _p = (p); \
((uint16_t*)_img->pixels)[(_y*_img->w)+_x]=_p; })
typedef struct size { typedef struct size {
int w; int w;
@ -150,6 +267,9 @@ typedef enum interp {
INTERP_BICUBIC INTERP_BICUBIC
} interp_t; } interp_t;
int imlib_get_pixel(image_t *img, int x, int y);
void imlib_set_pixel(image_t *img, int x, int y, int p);
/* Point functions */ /* Point functions */
point_t *point_alloc(int16_t x, int16_t y); point_t *point_alloc(int16_t x, int16_t y);
bool point_equal(point_t *p1, point_t *p2); bool point_equal(point_t *p1, point_t *p2);

View File

@ -1,67 +1,35 @@
#include <stdint.h> #include <stdint.h>
const uint16_t rainbow_table[256] = { const uint16_t rainbow_table[256] = {
0x1F06, 0x3F06, 0x5F06, 0x5F06, 0x3F06, 0x3F06, 0x5F06, 0x7F06, 0x9F06, 0xBF06, 0xBF06, 0xDF06,
0x7F06, 0x9F06, 0xBF06, 0xDF06, 0xFF06, 0x1F07, 0x3F07, 0x3F07, 0x5F07, 0x7F07, 0x9F07, 0xBF07,
0xDF06, 0xFF06, 0x1F07, 0x3F07, 0xBF07, 0xDF07, 0xFF07, 0xFF07, 0xFE07, 0xFE07, 0xFD07, 0xFD07,
0x5F07, 0x5F07, 0x7F07, 0x9F07, 0xFD07, 0xFC07, 0xFC07, 0xFB07, 0xFB07, 0xFB07, 0xFA07, 0xFA07,
0xBF07, 0xDF07, 0xFF07, 0xFE07, 0xFA07, 0xF907, 0xF907, 0xF807, 0xF807, 0xF807, 0xF707, 0xF707,
0xFE07, 0xFD07, 0xFD07, 0xFC07, 0xF607, 0xF607, 0xF607, 0xF507, 0xF507, 0xF407, 0xF407, 0xF407,
0xFC07, 0xFC07, 0xFB07, 0xFB07, 0xF307, 0xF307, 0xF207, 0xF207, 0xF207, 0xF107, 0xF107, 0xF107,
0xFA07, 0xFA07, 0xFA07, 0xF907, 0xF007, 0xF007, 0xEF07, 0xEF07, 0xEF07, 0xEE07, 0xEE07, 0xED07,
0xF907, 0xF907, 0xF807, 0xF807, 0xED07, 0xED07, 0xEC07, 0xEC07, 0xEB07, 0xEB07, 0xEB07, 0xEA07,
0xF707, 0xF707, 0xF707, 0xF607, 0xEA07, 0xEA07, 0xE907, 0xE907, 0xE807, 0xE807, 0xE807, 0xE707,
0xF607, 0xF607, 0xF507, 0xF507, 0xE707, 0xE607, 0xE607, 0xE607, 0xE507, 0xE507, 0xE407, 0xE407,
0xF407, 0xF407, 0xF307, 0xF307, 0xE407, 0xE307, 0xE307, 0xE207, 0xE207, 0xE207, 0xE107, 0xE107,
0xF307, 0xF207, 0xF207, 0xF107, 0xE107, 0xE007, 0xE007, 0xE00F, 0xE00F, 0xE00F, 0xE017, 0xE017,
0xF107, 0xF107, 0xF007, 0xF007, 0xE01F, 0xE01F, 0xE01F, 0xE027, 0xE027, 0xE02F, 0xE02F, 0xE02F,
0xF007, 0xEF07, 0xEF07, 0xEE07, 0xE037, 0xE037, 0xE03F, 0xE03F, 0xE03F, 0xE047, 0xE047, 0xE047,
0xEE07, 0xEE07, 0xED07, 0xED07, 0xE04F, 0xE04F, 0xE057, 0xE057, 0xE057, 0xE05F, 0xE05F, 0xE067,
0xED07, 0xEC07, 0xEC07, 0xEB07, 0xE067, 0xE067, 0xE06F, 0xE06F, 0xE077, 0xE077, 0xE077, 0xE07F,
0xEB07, 0xEB07, 0xEA07, 0xEA07, 0xE07F, 0xE087, 0xE087, 0xE087, 0xE08F, 0xE08F, 0xE08F, 0xE097,
0xE907, 0xE907, 0xE807, 0xE807, 0xE097, 0xE09F, 0xE09F, 0xE09F, 0xE0A7, 0xE0A7, 0xE0AF, 0xE0AF,
0xE807, 0xE707, 0xE707, 0xE707, 0xE0AF, 0xE0B7, 0xE0B7, 0xE0BF, 0xE0BF, 0xE0BF, 0xE0C7, 0xE0C7,
0xE607, 0xE607, 0xE507, 0xE507, 0xE0C7, 0xE0CF, 0xE0CF, 0xE0D7, 0xE0D7, 0xE0D7, 0xE0DF, 0xE0DF,
0xE507, 0xE407, 0xE407, 0xE407, 0xE0E7, 0xE0E7, 0xE0E7, 0xE0EF, 0xE0EF, 0xE0F7, 0xE0F7, 0xE0F7,
0xE307, 0xE307, 0xE207, 0xE207, 0xE0FF, 0xE0FF, 0xC0FF, 0xA0FF, 0x80FF, 0x80FF, 0x60FF, 0x40FF,
0xE207, 0xE107, 0xE107, 0xE007, 0x20FF, 0x00FF, 0x00FF, 0xE0FE, 0xC0FE, 0xA0FE, 0x80FE, 0x80FE,
0xE007, 0xE007, 0xE007, 0xE007, 0x60FE, 0x40FE, 0x20FE, 0x00FE, 0x00FE, 0xE0FD, 0xC0FD, 0xA0FD,
0xE007, 0xE00F, 0xE00F, 0xE017, 0x80FD, 0x80FD, 0x60FD, 0x40FD, 0x20FD, 0x00FD, 0x00FD, 0xE0FC,
0xE017, 0xE017, 0xE01F, 0xE01F, 0xC0FC, 0xA0FC, 0xA0FC, 0x80FC, 0x60FC, 0x40FC, 0x20FC, 0x20FC,
0xE027, 0xE027, 0xE027, 0xE02F, 0x00FC, 0xE0FB, 0xC0FB, 0xA0FB, 0xA0FB, 0x80FB, 0x60FB, 0x40FB,
0xE02F, 0xE037, 0xE037, 0xE037, 0x20FB, 0x20FB, 0x00FB, 0xE0FA, 0xC0FA, 0xA0FA, 0xA0FA, 0x80FA,
0xE03F, 0xE03F, 0xE047, 0xE047, 0x60FA, 0x40FA, 0x20FA, 0x20FA, 0x00FA, 0xE0F9, 0xC0F9, 0xA0F9,
0xE047, 0xE04F, 0xE04F, 0xE04F, 0xA0F9, 0x80F9, 0x60F9, 0x40F9, 0x40F9, 0x20F9, 0x00F9, 0xE0F8,
0xE057, 0xE057, 0xE05F, 0xE05F, 0xC0F8, 0xC0F8, 0xA0F8, 0x80F8, 0x60F8, 0x40F8, 0x40F8, 0x20F8
0xE05F, 0xE067, 0xE067, 0xE06F,
0xE06F, 0xE06F, 0xE077, 0xE077,
0xE07F, 0xE07F, 0xE07F, 0xE087,
0xE087, 0xE08F, 0xE08F, 0xE08F,
0xE097, 0xE097, 0xE097, 0xE09F,
0xE09F, 0xE0A7, 0xE0A7, 0xE0A7,
0xE0AF, 0xE0AF, 0xE0B7, 0xE0B7,
0xE0B7, 0xE0BF, 0xE0BF, 0xE0C7,
0xE0C7, 0xE0C7, 0xE0CF, 0xE0CF,
0xE0D7, 0xE0D7, 0xE0D7, 0xE0DF,
0xE0DF, 0xE0DF, 0xE0E7, 0xE0E7,
0xE0EF, 0xE0EF, 0xE0EF, 0xE0F7,
0xE0F7, 0xC0FF, 0xA0FF, 0xA0FF,
0x80FF, 0x60FF, 0x40FF, 0x20FF,
0x20FF, 0xFF, 0xE0FE, 0xC0FE,
0xA0FE, 0xA0FE, 0x80FE, 0x60FE,
0x40FE, 0x20FE, 0x20FE, 0xFE,
0xE0FD, 0xC0FD, 0xA0FD, 0xA0FD,
0x80FD, 0x60FD, 0x40FD, 0x40FD,
0x20FD, 0xFD, 0xE0FC, 0xC0FC,
0xC0FC, 0xA0FC, 0x80FC, 0x60FC,
0x40FC, 0x40FC, 0x20FC, 0xFC,
0xE0FB, 0xC0FB, 0xC0FB, 0xA0FB,
0x80FB, 0x60FB, 0x40FB, 0x40FB,
0x20FB, 0xFB, 0xE0FA, 0xC0FA,
0xC0FA, 0xA0FA, 0x80FA, 0x60FA,
0x60FA, 0x40FA, 0x20FA, 0xFA,
0xE0F9, 0xE0F9, 0xC0F9, 0xA0F9,
0x80F9, 0x60F9, 0x60F9, 0x40F9,
0x20F9, 0xF9, 0xE0F8, 0xC0F8,
0xC0F8, 0xA0F8, 0x80F8, 0x60F8,
0x40F8, 0x40F8, 0x20F8, 0xF8,
}; };

85
src/omv/img/rgb2rgb_tab.c Normal file
View File

@ -0,0 +1,85 @@
#include <stdint.h>
const uint8_t rb528_table[32] = {
0, 8, 16, 25, 33, 41, 49, 58,
66, 74, 82, 90, 99, 107, 115, 123,
132, 140, 148, 156, 165, 173, 181, 189,
197, 206, 214, 222, 230, 239, 247, 255
};
const uint8_t g628_table[64] = {
0, 4, 8, 12, 16, 20, 24, 28,
32, 36, 40, 45, 49, 53, 57, 61,
65, 69, 73, 77, 81, 85, 89, 93,
97, 101, 105, 109, 113, 117, 121, 125,
130, 134, 138, 142, 146, 150, 154, 158,
162, 166, 170, 174, 178, 182, 186, 190,
194, 198, 202, 206, 210, 215, 219, 223,
227, 231, 235, 239, 243, 247, 251, 255
};
const uint8_t rb825_table[256] = {
0, 0, 0, 0, 0, 1, 1, 1,
1, 1, 1, 1, 1, 2, 2, 2,
2, 2, 2, 2, 2, 3, 3, 3,
3, 3, 3, 3, 3, 4, 4, 4,
4, 4, 4, 4, 4, 4, 5, 5,
5, 5, 5, 5, 5, 5, 6, 6,
6, 6, 6, 6, 6, 6, 7, 7,
7, 7, 7, 7, 7, 7, 8, 8,
8, 8, 8, 8, 8, 8, 9, 9,
9, 9, 9, 9, 9, 9, 9, 10,
10, 10, 10, 10, 10, 10, 10, 11,
11, 11, 11, 11, 11, 11, 11, 12,
12, 12, 12, 12, 12, 12, 12, 13,
13, 13, 13, 13, 13, 13, 13, 13,
14, 14, 14, 14, 14, 14, 14, 14,
15, 15, 15, 15, 15, 15, 15, 15,
16, 16, 16, 16, 16, 16, 16, 16,
17, 17, 17, 17, 17, 17, 17, 17,
18, 18, 18, 18, 18, 18, 18, 18,
18, 19, 19, 19, 19, 19, 19, 19,
19, 20, 20, 20, 20, 20, 20, 20,
20, 21, 21, 21, 21, 21, 21, 21,
21, 22, 22, 22, 22, 22, 22, 22,
22, 22, 23, 23, 23, 23, 23, 23,
23, 23, 24, 24, 24, 24, 24, 24,
24, 24, 25, 25, 25, 25, 25, 25,
25, 25, 26, 26, 26, 26, 26, 26,
26, 26, 27, 27, 27, 27, 27, 27,
27, 27, 27, 28, 28, 28, 28, 28,
28, 28, 28, 29, 29, 29, 29, 29,
29, 29, 29, 30, 30, 30, 30, 30,
30, 30, 30, 31, 31, 31, 31, 31
};
const uint8_t g826_table[256] = {
0, 0, 0, 1, 1, 1, 1, 2,
2, 2, 2, 3, 3, 3, 3, 4,
4, 4, 4, 5, 5, 5, 5, 6,
6, 6, 6, 7, 7, 7, 7, 8,
8, 8, 8, 9, 9, 9, 9, 10,
10, 10, 10, 11, 11, 11, 11, 12,
12, 12, 12, 13, 13, 13, 13, 14,
14, 14, 14, 15, 15, 15, 15, 16,
16, 16, 16, 17, 17, 17, 17, 18,
18, 18, 18, 19, 19, 19, 19, 20,
20, 20, 20, 21, 21, 21, 21, 21,
22, 22, 22, 22, 23, 23, 23, 23,
24, 24, 24, 24, 25, 25, 25, 25,
26, 26, 26, 26, 27, 27, 27, 27,
28, 28, 28, 28, 29, 29, 29, 29,
30, 30, 30, 30, 31, 31, 31, 31,
32, 32, 32, 32, 33, 33, 33, 33,
34, 34, 34, 34, 35, 35, 35, 35,
36, 36, 36, 36, 37, 37, 37, 37,
38, 38, 38, 38, 39, 39, 39, 39,
40, 40, 40, 40, 41, 41, 41, 41,
42, 42, 42, 42, 42, 43, 43, 43,
43, 44, 44, 44, 44, 45, 45, 45,
45, 46, 46, 46, 46, 47, 47, 47,
47, 48, 48, 48, 48, 49, 49, 49,
49, 50, 50, 50, 50, 51, 51, 51,
51, 52, 52, 52, 52, 53, 53, 53,
53, 54, 54, 54, 54, 55, 55, 55,
55, 56, 56, 56, 56, 57, 57, 57,
57, 58, 58, 58, 58, 59, 59, 59,
59, 60, 60, 60, 60, 61, 61, 61,
61, 62, 62, 62, 62, 63, 63, 63
};

View File

@ -1,23 +1,27 @@
#! /usr/bin/env python #!/usr/bin/env python
import colorsys # -*- coding: utf-8 -*-
NUM_COL=256 NUM_COL=256
SAT=1.0 SAT=1.0
VAL=1.0 VAL=1.0
OFFSET=220 OFFSET=220
import sys, colorsys
sys.stdout.write("#include <stdint.h>\n")
tup = [colorsys.hsv_to_rgb(1.0-(i/float(NUM_COL+OFFSET)), SAT, VAL) for i in range(OFFSET, NUM_COL+OFFSET)] tup = [colorsys.hsv_to_rgb(1.0-(i/float(NUM_COL+OFFSET)), SAT, VAL) for i in range(OFFSET, NUM_COL+OFFSET)]
col = [((int(r*255)*31/255)&0x1F)<<11 | col = [(int((((r*255)*31)+127.5)/255)&0x1F)<<11 |
((int(g*255)*63/255)&0x3F)<<5 | (int((((g*255)*63)+127.5)/255)&0x3F)<<5 |
((int(b*255)*31/255)&0x1F) for r,g,b in tup] (int((((b*255)*31)+127.5)/255)&0x1F) for r,g,b in tup]
print \ sys.stdout.write("const uint16_t rainbow_table[%d] = {\n" % NUM_COL)
"#include <stdint.h>\n"\ for i in range(NUM_COL):
"const uint16_t rainbow_table[%d] = {"%(NUM_COL) if not (i % 8):
sys.stdout.write(" ")
for i in range(0, NUM_COL): sys.stdout.write("0x%04X" % (((col[i]&0x00ff)<<8)|((col[i]&0xff00)>>8)))
if (i%4)==0 and i != (NUM_COL-1): if (i + 1) % 8:
if i >0: sys.stdout.write(", ")
print "" elif i != (NUM_COL-1):
print " ", sys.stdout.write(",\n")
print "0x%X,"%((col[i] & 0xff)<<8 |(col[i] & 0xff00) >> 8), else:
print "\n};" sys.stdout.write("\n};\n")

53
util/gen_rgb2rgb.py Normal file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.stdout.write("#include <stdint.h>\n")
sys.stdout.write("const uint8_t rb528_table[32] = {\n")
for i in range(32):
if not (i % 8):
sys.stdout.write(" ")
sys.stdout.write("%3d" % (((i * 255) + 15.5) // 31))
if (i + 1) % 8:
sys.stdout.write(", ")
elif i != 31:
sys.stdout.write(",\n")
else:
sys.stdout.write("\n};\n")
sys.stdout.write("const uint8_t g628_table[64] = {\n")
for i in range(64):
if not (i % 8):
sys.stdout.write(" ")
sys.stdout.write("%3d" % (((i * 255) + 31.5) // 63))
if (i + 1) % 8:
sys.stdout.write(", ")
elif i != 63:
sys.stdout.write(",\n")
else:
sys.stdout.write("\n};\n")
sys.stdout.write("const uint8_t rb825_table[256] = {\n")
for i in range(256):
if not (i % 8):
sys.stdout.write(" ")
sys.stdout.write("%3d" % (((i * 31) + 127.5) // 255))
if (i + 1) % 8:
sys.stdout.write(", ")
elif i != 255:
sys.stdout.write(",\n")
else:
sys.stdout.write("\n};\n")
sys.stdout.write("const uint8_t g826_table[256] = {\n")
for i in range(256):
if not (i % 8):
sys.stdout.write(" ")
sys.stdout.write("%3d" % (((i * 63) + 127.5) // 255))
if (i + 1) % 8:
sys.stdout.write(", ")
elif i != 255:
sys.stdout.write(",\n")
else:
sys.stdout.write("\n};\n")