From 6699ea4d0e9ec983b3029d67e20e96044a6a4dc6 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Mon, 15 Feb 2016 22:12:25 -0500 Subject: [PATCH] Added RGB LUT. And modified the rainbow table so that the RGB888 to RGB565 translation is done using a rounding technique versus hard floor. This is also used for the RGB565<->RGB888 LUTs. Additionally, I added a bunch of stuff to the image library to make working with images easier. I will using these helpers in the future. Finally, I cleaned up trailing space in the font stuff (pet peeve). --- src/Makefile | 1 + src/omv/Makefile | 1 + src/omv/img/font.c | 1713 ++++++++++++++++++------------------- src/omv/img/font.h | 1 + src/omv/img/imlib.c | 100 +-- src/omv/img/imlib.h | 130 ++- src/omv/img/rainbow_tab.c | 96 +-- src/omv/img/rgb2rgb_tab.c | 85 ++ util/gen_rainbow.py | 36 +- util/gen_rgb2rgb.py | 53 ++ 10 files changed, 1220 insertions(+), 996 deletions(-) create mode 100644 src/omv/img/rgb2rgb_tab.c create mode 100644 util/gen_rgb2rgb.py diff --git a/src/Makefile b/src/Makefile index adb923c18..e46466375 100755 --- a/src/Makefile +++ b/src/Makefile @@ -132,6 +132,7 @@ OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/img/,\ xyz_tab.o \ yuv_tab.o \ rainbow_tab.o \ + rgb2rgb_tab.o \ median.o \ point.o \ ppm.o \ diff --git a/src/omv/Makefile b/src/omv/Makefile index 53b17e15a..182315469 100644 --- a/src/omv/Makefile +++ b/src/omv/Makefile @@ -35,6 +35,7 @@ SRCS += $(addprefix img/, \ xyz_tab.c \ yuv_tab.c \ rainbow_tab.c \ + rgb2rgb_tab.c \ median.c \ point.c \ ppm.c \ diff --git a/src/omv/img/font.c b/src/omv/img/font.c index ac561c69b..9e8a38d56 100644 --- a/src/omv/img/font.c +++ b/src/omv/img/font.c @@ -24,1054 +24,1051 @@ * line scan direction: forward * inverse: yes */ -#include #include "font.h" - const glyph_t font[95] = { - // character: ' ' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, 0x00}}, // character: '!' - {8, 10, {0x00, - 0x00, - 0x10, - 0x10, - 0x10, - 0x10, - 0x00, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x10, + 0x10, + 0x10, + 0x10, + 0x00, + 0x10, + 0x00, 0x00}}, // character: '"' - {8, 10, {0x00, - 0x00, - 0x18, - 0x18, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, + {8, 10, {0x00, + 0x00, + 0x18, + 0x18, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, 0x00}}, // character: '#' - {8, 10, {0x00, - 0x00, - 0x24, - 0x7c, - 0x24, - 0x48, - 0x7c, - 0x48, - 0x00, + {8, 10, {0x00, + 0x00, + 0x24, + 0x7c, + 0x24, + 0x48, + 0x7c, + 0x48, + 0x00, 0x00}}, // character: '$' - {8, 10, {0x00, - 0x00, - 0x08, - 0x1c, - 0x20, - 0x18, - 0x04, - 0x38, - 0x08, + {8, 10, {0x00, + 0x00, + 0x08, + 0x1c, + 0x20, + 0x18, + 0x04, + 0x38, + 0x08, 0x00}}, // character: '%' - {8, 10, {0x00, - 0x00, - 0x24, - 0x58, - 0x28, - 0x14, - 0x1a, - 0x24, - 0x00, + {8, 10, {0x00, + 0x00, + 0x24, + 0x58, + 0x28, + 0x14, + 0x1a, + 0x24, + 0x00, 0x00}}, // character: '&' - {8, 10, {0x00, - 0x00, - 0x10, - 0x28, - 0x30, - 0x34, - 0x2c, - 0x1c, - 0x00, + {8, 10, {0x00, + 0x00, + 0x10, + 0x28, + 0x30, + 0x34, + 0x2c, + 0x1c, + 0x00, 0x00}}, // character: ''' - {8, 10, {0x00, - 0x00, - 0x10, - 0x10, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, + {8, 10, {0x00, + 0x00, + 0x10, + 0x10, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, 0x00}}, // character: '(' - {8, 10, {0x00, - 0x00, - 0x08, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x08, + {8, 10, {0x00, + 0x00, + 0x08, + 0x10, + 0x10, + 0x10, + 0x10, + 0x10, + 0x08, 0x00}}, // character: ')' - {8, 10, {0x00, - 0x00, - 0x20, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x20, + {8, 10, {0x00, + 0x00, + 0x20, + 0x10, + 0x10, + 0x10, + 0x10, + 0x10, + 0x20, 0x00}}, // character: '*' - {8, 10, {0x00, - 0x00, - 0x10, - 0x38, - 0x28, - 0x00, - 0x00, - 0x00, - 0x00, + {8, 10, {0x00, + 0x00, + 0x10, + 0x38, + 0x28, + 0x00, + 0x00, + 0x00, + 0x00, 0x00}}, // character: '+' - {8, 10, {0x00, - 0x00, - 0x00, - 0x10, - 0x10, - 0x7c, - 0x10, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x10, + 0x10, + 0x7c, + 0x10, + 0x10, + 0x00, 0x00}}, // character: ',' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x10, - 0x20, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x10, + 0x20, 0x00}}, // character: '-' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x18, - 0x00, - 0x00, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x18, + 0x00, + 0x00, + 0x00, 0x00}}, // character: '.' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x10, + 0x00, 0x00}}, // character: '/' - {8, 10, {0x00, - 0x00, - 0x08, - 0x08, - 0x10, - 0x10, - 0x10, - 0x20, - 0x20, + {8, 10, {0x00, + 0x00, + 0x08, + 0x08, + 0x10, + 0x10, + 0x10, + 0x20, + 0x20, 0x00}}, // character: '0' - {8, 10, {0x00, - 0x00, - 0x18, - 0x24, - 0x24, - 0x24, - 0x24, - 0x18, - 0x00, + {8, 10, {0x00, + 0x00, + 0x18, + 0x24, + 0x24, + 0x24, + 0x24, + 0x18, + 0x00, 0x00}}, // character: '1' - {8, 10, {0x00, - 0x00, - 0x08, - 0x18, - 0x08, - 0x08, - 0x08, - 0x08, - 0x00, + {8, 10, {0x00, + 0x00, + 0x08, + 0x18, + 0x08, + 0x08, + 0x08, + 0x08, + 0x00, 0x00}}, // character: '2' - {8, 10, {0x00, - 0x00, - 0x18, - 0x24, - 0x04, - 0x08, - 0x10, - 0x3c, - 0x00, + {8, 10, {0x00, + 0x00, + 0x18, + 0x24, + 0x04, + 0x08, + 0x10, + 0x3c, + 0x00, 0x00}}, // character: '3' - {8, 10, {0x00, - 0x00, - 0x38, - 0x04, - 0x18, - 0x04, - 0x04, - 0x38, - 0x00, + {8, 10, {0x00, + 0x00, + 0x38, + 0x04, + 0x18, + 0x04, + 0x04, + 0x38, + 0x00, 0x00}}, // character: '4' - {8, 10, {0x00, - 0x00, - 0x08, - 0x18, - 0x28, - 0x3c, - 0x08, - 0x08, - 0x00, + {8, 10, {0x00, + 0x00, + 0x08, + 0x18, + 0x28, + 0x3c, + 0x08, + 0x08, + 0x00, 0x00}}, // character: '5' - {8, 10, {0x00, - 0x00, - 0x1c, - 0x10, - 0x18, - 0x04, - 0x04, - 0x18, - 0x00, + {8, 10, {0x00, + 0x00, + 0x1c, + 0x10, + 0x18, + 0x04, + 0x04, + 0x18, + 0x00, 0x00}}, // character: '6' - {8, 10, {0x00, - 0x00, - 0x0c, - 0x10, - 0x38, - 0x24, - 0x24, - 0x18, - 0x00, + {8, 10, {0x00, + 0x00, + 0x0c, + 0x10, + 0x38, + 0x24, + 0x24, + 0x18, + 0x00, 0x00}}, // character: '7' - {8, 10, {0x00, - 0x00, - 0x38, - 0x08, - 0x08, - 0x10, - 0x10, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x38, + 0x08, + 0x08, + 0x10, + 0x10, + 0x10, + 0x00, 0x00}}, // character: '8' - {8, 10, {0x00, - 0x00, - 0x18, - 0x24, - 0x18, - 0x24, - 0x24, - 0x18, - 0x00, + {8, 10, {0x00, + 0x00, + 0x18, + 0x24, + 0x18, + 0x24, + 0x24, + 0x18, + 0x00, 0x00}}, // character: '9' - {8, 10, {0x00, - 0x00, - 0x18, - 0x24, - 0x24, - 0x3c, - 0x08, - 0x30, - 0x00, + {8, 10, {0x00, + 0x00, + 0x18, + 0x24, + 0x24, + 0x3c, + 0x08, + 0x30, + 0x00, 0x00}}, // character: ':' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x10, - 0x00, - 0x00, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x10, + 0x00, + 0x00, + 0x10, + 0x00, 0x00}}, // character: ';' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x10, - 0x00, - 0x00, - 0x10, - 0x20, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x10, + 0x00, + 0x00, + 0x10, + 0x20, 0x00}}, // character: '<' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x38, - 0x40, - 0x38, - 0x00, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x38, + 0x40, + 0x38, + 0x00, + 0x00, 0x00}}, // character: '=' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x3c, - 0x00, - 0x3c, - 0x00, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x3c, + 0x00, + 0x3c, + 0x00, + 0x00, 0x00}}, // character: '>' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x30, - 0x08, - 0x30, - 0x00, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x30, + 0x08, + 0x30, + 0x00, + 0x00, 0x00}}, // character: '?' - {8, 10, {0x00, - 0x00, - 0x18, - 0x08, - 0x08, - 0x10, - 0x00, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x18, + 0x08, + 0x08, + 0x10, + 0x00, + 0x10, + 0x00, 0x00}}, // character: '\x0040' - {8, 10, {0x00, - 0x00, - 0x38, - 0x44, - 0x9a, - 0xaa, - 0xaa, - 0xb4, - 0x40, + {8, 10, {0x00, + 0x00, + 0x38, + 0x44, + 0x9a, + 0xaa, + 0xaa, + 0xb4, + 0x40, 0x38}}, // character: 'A' - {8, 10, {0x00, - 0x00, - 0x10, - 0x28, - 0x28, - 0x28, - 0x7c, - 0x44, - 0x00, + {8, 10, {0x00, + 0x00, + 0x10, + 0x28, + 0x28, + 0x28, + 0x7c, + 0x44, + 0x00, 0x00}}, // character: 'B' - {8, 10, {0x00, - 0x00, - 0x38, - 0x24, - 0x38, - 0x24, - 0x24, - 0x38, - 0x00, + {8, 10, {0x00, + 0x00, + 0x38, + 0x24, + 0x38, + 0x24, + 0x24, + 0x38, + 0x00, 0x00}}, // character: 'C' - {8, 10, {0x00, - 0x00, - 0x1c, - 0x20, - 0x20, - 0x20, - 0x20, - 0x1c, - 0x00, + {8, 10, {0x00, + 0x00, + 0x1c, + 0x20, + 0x20, + 0x20, + 0x20, + 0x1c, + 0x00, 0x00}}, // character: 'D' - {8, 10, {0x00, - 0x00, - 0x78, - 0x44, - 0x44, - 0x44, - 0x44, - 0x78, - 0x00, + {8, 10, {0x00, + 0x00, + 0x78, + 0x44, + 0x44, + 0x44, + 0x44, + 0x78, + 0x00, 0x00}}, // character: 'E' - {8, 10, {0x00, - 0x00, - 0x3c, - 0x20, - 0x38, - 0x20, - 0x20, - 0x3c, - 0x00, + {8, 10, {0x00, + 0x00, + 0x3c, + 0x20, + 0x38, + 0x20, + 0x20, + 0x3c, + 0x00, 0x00}}, // character: 'F' - {8, 10, {0x00, - 0x00, - 0x38, - 0x20, - 0x30, - 0x20, - 0x20, - 0x20, - 0x00, + {8, 10, {0x00, + 0x00, + 0x38, + 0x20, + 0x30, + 0x20, + 0x20, + 0x20, + 0x00, 0x00}}, // character: 'G' - {8, 10, {0x00, - 0x00, - 0x1c, - 0x20, - 0x20, - 0x24, - 0x24, - 0x1c, - 0x00, + {8, 10, {0x00, + 0x00, + 0x1c, + 0x20, + 0x20, + 0x24, + 0x24, + 0x1c, + 0x00, 0x00}}, // character: 'H' - {8, 10, {0x00, - 0x00, - 0x44, - 0x44, - 0x7c, - 0x44, - 0x44, - 0x44, - 0x00, + {8, 10, {0x00, + 0x00, + 0x44, + 0x44, + 0x7c, + 0x44, + 0x44, + 0x44, + 0x00, 0x00}}, // character: 'I' - {8, 10, {0x00, - 0x00, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x10, + 0x10, + 0x10, + 0x10, + 0x10, + 0x10, + 0x00, 0x00}}, // character: 'J' - {8, 10, {0x00, - 0x00, - 0x08, - 0x08, - 0x08, - 0x08, - 0x08, - 0x30, - 0x00, + {8, 10, {0x00, + 0x00, + 0x08, + 0x08, + 0x08, + 0x08, + 0x08, + 0x30, + 0x00, 0x00}}, // character: 'K' - {8, 10, {0x00, - 0x00, - 0x24, - 0x28, - 0x30, - 0x30, - 0x28, - 0x24, - 0x00, + {8, 10, {0x00, + 0x00, + 0x24, + 0x28, + 0x30, + 0x30, + 0x28, + 0x24, + 0x00, 0x00}}, // character: 'L' - {8, 10, {0x00, - 0x00, - 0x20, - 0x20, - 0x20, - 0x20, - 0x20, - 0x38, - 0x00, + {8, 10, {0x00, + 0x00, + 0x20, + 0x20, + 0x20, + 0x20, + 0x20, + 0x38, + 0x00, 0x00}}, // character: 'M' - {8, 10, {0x00, - 0x00, - 0x44, - 0x6c, - 0x6c, - 0x54, - 0x54, - 0x44, - 0x00, + {8, 10, {0x00, + 0x00, + 0x44, + 0x6c, + 0x6c, + 0x54, + 0x54, + 0x44, + 0x00, 0x00}}, // character: 'N' - {8, 10, {0x00, - 0x00, - 0x42, - 0x62, - 0x52, - 0x4a, - 0x46, - 0x42, - 0x00, + {8, 10, {0x00, + 0x00, + 0x42, + 0x62, + 0x52, + 0x4a, + 0x46, + 0x42, + 0x00, 0x00}}, // character: 'O' - {8, 10, {0x00, - 0x00, - 0x38, - 0x44, - 0x44, - 0x44, - 0x44, - 0x38, - 0x00, + {8, 10, {0x00, + 0x00, + 0x38, + 0x44, + 0x44, + 0x44, + 0x44, + 0x38, + 0x00, 0x00}}, // character: 'P' - {8, 10, {0x00, - 0x00, - 0x38, - 0x24, - 0x24, - 0x38, - 0x20, - 0x20, - 0x00, + {8, 10, {0x00, + 0x00, + 0x38, + 0x24, + 0x24, + 0x38, + 0x20, + 0x20, + 0x00, 0x00}}, // character: 'Q' - {8, 10, {0x00, - 0x00, - 0x38, - 0x44, - 0x44, - 0x44, - 0x44, - 0x38, - 0x10, + {8, 10, {0x00, + 0x00, + 0x38, + 0x44, + 0x44, + 0x44, + 0x44, + 0x38, + 0x10, 0x08}}, // character: 'R' - {8, 10, {0x00, - 0x00, - 0x38, - 0x24, - 0x24, - 0x38, - 0x28, - 0x24, - 0x00, + {8, 10, {0x00, + 0x00, + 0x38, + 0x24, + 0x24, + 0x38, + 0x28, + 0x24, + 0x00, 0x00}}, // character: 'S' - {8, 10, {0x00, - 0x00, - 0x18, - 0x20, - 0x20, - 0x18, - 0x08, - 0x30, - 0x00, + {8, 10, {0x00, + 0x00, + 0x18, + 0x20, + 0x20, + 0x18, + 0x08, + 0x30, + 0x00, 0x00}}, // character: 'T' - {8, 10, {0x00, - 0x00, - 0x38, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x38, + 0x10, + 0x10, + 0x10, + 0x10, + 0x10, + 0x00, 0x00}}, // character: 'U' - {8, 10, {0x00, - 0x00, - 0x44, - 0x44, - 0x44, - 0x44, - 0x44, - 0x38, - 0x00, + {8, 10, {0x00, + 0x00, + 0x44, + 0x44, + 0x44, + 0x44, + 0x44, + 0x38, + 0x00, 0x00}}, // character: 'V' - {8, 10, {0x00, - 0x00, - 0x44, - 0x44, - 0x28, - 0x28, - 0x28, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x44, + 0x44, + 0x28, + 0x28, + 0x28, + 0x10, + 0x00, 0x00}}, // character: 'W' - {8, 10, {0x00, - 0x00, - 0x82, - 0x92, - 0xaa, - 0xaa, - 0xaa, - 0x44, - 0x00, + {8, 10, {0x00, + 0x00, + 0x82, + 0x92, + 0xaa, + 0xaa, + 0xaa, + 0x44, + 0x00, 0x00}}, // character: 'X' - {8, 10, {0x00, - 0x00, - 0x44, - 0x28, - 0x10, - 0x10, - 0x28, - 0x44, - 0x00, + {8, 10, {0x00, + 0x00, + 0x44, + 0x28, + 0x10, + 0x10, + 0x28, + 0x44, + 0x00, 0x00}}, // character: 'Y' - {8, 10, {0x00, - 0x00, - 0x44, - 0x28, - 0x28, - 0x10, - 0x10, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x44, + 0x28, + 0x28, + 0x10, + 0x10, + 0x10, + 0x00, 0x00}}, // character: 'Z' - {8, 10, {0x00, - 0x00, - 0x3c, - 0x04, - 0x08, - 0x10, - 0x20, - 0x3c, - 0x00, + {8, 10, {0x00, + 0x00, + 0x3c, + 0x04, + 0x08, + 0x10, + 0x20, + 0x3c, + 0x00, 0x00}}, // character: '[' - {8, 10, {0x00, - 0x00, - 0x18, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x18, + {8, 10, {0x00, + 0x00, + 0x18, + 0x10, + 0x10, + 0x10, + 0x10, + 0x10, + 0x18, 0x00}}, // character: '\' - {8, 10, {0x00, - 0x00, - 0x20, - 0x20, - 0x10, - 0x10, - 0x10, - 0x08, - 0x08, + {8, 10, {0x00, + 0x00, + 0x20, + 0x20, + 0x10, + 0x10, + 0x10, + 0x08, + 0x08, 0x00}}, // character: ']' - {8, 10, {0x00, - 0x00, - 0x30, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x30, + {8, 10, {0x00, + 0x00, + 0x30, + 0x10, + 0x10, + 0x10, + 0x10, + 0x10, + 0x30, 0x00}}, // character: '^' - {8, 10, {0x00, - 0x00, - 0x10, - 0x28, - 0x28, - 0x00, - 0x00, - 0x00, - 0x00, + {8, 10, {0x00, + 0x00, + 0x10, + 0x28, + 0x28, + 0x00, + 0x00, + 0x00, + 0x00, 0x00}}, // character: '_' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x78, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x78, 0x00}}, // character: '`' - {8, 10, {0x00, - 0x10, - 0x08, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, + {8, 10, {0x00, + 0x10, + 0x08, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, 0x00}}, // character: 'a' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x30, - 0x08, - 0x18, - 0x38, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x30, + 0x08, + 0x18, + 0x38, + 0x00, 0x00}}, // character: 'b' - {8, 10, {0x00, - 0x00, - 0x20, - 0x20, - 0x38, - 0x24, - 0x24, - 0x38, - 0x00, + {8, 10, {0x00, + 0x00, + 0x20, + 0x20, + 0x38, + 0x24, + 0x24, + 0x38, + 0x00, 0x00}}, // character: 'c' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x18, - 0x20, - 0x20, - 0x18, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x18, + 0x20, + 0x20, + 0x18, + 0x00, 0x00}}, // character: 'd' - {8, 10, {0x00, - 0x00, - 0x04, - 0x04, - 0x1c, - 0x24, - 0x24, - 0x1c, - 0x00, + {8, 10, {0x00, + 0x00, + 0x04, + 0x04, + 0x1c, + 0x24, + 0x24, + 0x1c, + 0x00, 0x00}}, // character: 'e' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x38, - 0x38, - 0x20, - 0x18, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x38, + 0x38, + 0x20, + 0x18, + 0x00, 0x00}}, // character: 'f' - {8, 10, {0x00, - 0x00, - 0x08, - 0x10, - 0x18, - 0x10, - 0x10, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x08, + 0x10, + 0x18, + 0x10, + 0x10, + 0x10, + 0x00, 0x00}}, // character: 'g' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x1c, - 0x24, - 0x1c, - 0x04, - 0x38, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x1c, + 0x24, + 0x1c, + 0x04, + 0x38, 0x00}}, // character: 'h' - {8, 10, {0x00, - 0x00, - 0x20, - 0x20, - 0x38, - 0x24, - 0x24, - 0x24, - 0x00, + {8, 10, {0x00, + 0x00, + 0x20, + 0x20, + 0x38, + 0x24, + 0x24, + 0x24, + 0x00, 0x00}}, // character: 'i' - {8, 10, {0x00, - 0x00, - 0x10, - 0x00, - 0x10, - 0x10, - 0x10, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x10, + 0x00, + 0x10, + 0x10, + 0x10, + 0x10, + 0x00, 0x00}}, // character: 'j' - {8, 10, {0x00, - 0x00, - 0x10, - 0x00, - 0x10, - 0x10, - 0x10, - 0x10, - 0x20, + {8, 10, {0x00, + 0x00, + 0x10, + 0x00, + 0x10, + 0x10, + 0x10, + 0x10, + 0x20, 0x00}}, // character: 'k' - {8, 10, {0x00, - 0x00, - 0x20, - 0x20, - 0x28, - 0x30, - 0x30, - 0x28, - 0x00, + {8, 10, {0x00, + 0x00, + 0x20, + 0x20, + 0x28, + 0x30, + 0x30, + 0x28, + 0x00, 0x00}}, // character: 'l' - {8, 10, {0x00, - 0x00, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x08, - 0x00, + {8, 10, {0x00, + 0x00, + 0x10, + 0x10, + 0x10, + 0x10, + 0x10, + 0x08, + 0x00, 0x00}}, // character: 'm' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0xec, - 0x92, - 0x92, - 0x92, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0xec, + 0x92, + 0x92, + 0x92, + 0x00, 0x00}}, // character: 'n' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x38, - 0x24, - 0x24, - 0x24, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x38, + 0x24, + 0x24, + 0x24, + 0x00, 0x00}}, // character: 'o' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x18, - 0x24, - 0x24, - 0x18, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x18, + 0x24, + 0x24, + 0x18, + 0x00, 0x00}}, // character: 'p' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x38, - 0x24, - 0x24, - 0x38, - 0x20, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x38, + 0x24, + 0x24, + 0x38, + 0x20, 0x00}}, // character: 'q' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x1c, - 0x24, - 0x24, - 0x1c, - 0x04, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x1c, + 0x24, + 0x24, + 0x1c, + 0x04, 0x00}}, // character: 'r' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x18, - 0x10, - 0x10, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x18, + 0x10, + 0x10, + 0x10, + 0x00, 0x00}}, // character: 's' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x18, - 0x20, - 0x18, - 0x30, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x18, + 0x20, + 0x18, + 0x30, + 0x00, 0x00}}, // character: 't' - {8, 10, {0x00, - 0x00, - 0x00, - 0x10, - 0x18, - 0x10, - 0x10, - 0x08, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x10, + 0x18, + 0x10, + 0x10, + 0x08, + 0x00, 0x00}}, // character: 'u' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x24, - 0x24, - 0x24, - 0x1c, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x24, + 0x24, + 0x24, + 0x1c, + 0x00, 0x00}}, // character: 'v' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x28, - 0x28, - 0x10, - 0x10, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x28, + 0x28, + 0x10, + 0x10, + 0x00, 0x00}}, // character: 'w' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x54, - 0x54, - 0x54, - 0x28, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x54, + 0x54, + 0x54, + 0x28, + 0x00, 0x00}}, // character: 'x' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x28, - 0x10, - 0x10, - 0x28, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x28, + 0x10, + 0x10, + 0x28, + 0x00, 0x00}}, // character: 'y' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x28, - 0x28, - 0x10, - 0x10, - 0x20, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x28, + 0x28, + 0x10, + 0x10, + 0x20, 0x00}}, // character: 'z' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x18, - 0x08, - 0x10, - 0x18, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x18, + 0x08, + 0x10, + 0x18, + 0x00, 0x00}}, // character: '{' - {8, 10, {0x00, - 0x00, - 0x08, - 0x10, - 0x10, - 0x20, - 0x10, - 0x10, - 0x08, + {8, 10, {0x00, + 0x00, + 0x08, + 0x10, + 0x10, + 0x20, + 0x10, + 0x10, + 0x08, 0x00}}, // character: '|' - {8, 10, {0x00, - 0x00, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, - 0x10, + {8, 10, {0x00, + 0x00, + 0x10, + 0x10, + 0x10, + 0x10, + 0x10, + 0x10, + 0x10, 0x00}}, // character: '}' - {8, 10, {0x00, - 0x00, - 0x20, - 0x10, - 0x10, - 0x08, - 0x10, - 0x10, - 0x20, + {8, 10, {0x00, + 0x00, + 0x20, + 0x10, + 0x10, + 0x08, + 0x10, + 0x10, + 0x20, 0x00}}, // character: '~' - {8, 10, {0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x28, - 0x50, - 0x00, - 0x00, + {8, 10, {0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x28, + 0x50, + 0x00, + 0x00, 0x00}} }; diff --git a/src/omv/img/font.h b/src/omv/img/font.h index 911e58080..d27143853 100644 --- a/src/omv/img/font.h +++ b/src/omv/img/font.h @@ -8,6 +8,7 @@ */ #ifndef __FONT_H__ #define __FONT_H__ +#include typedef struct { int w; int h; diff --git a/src/omv/img/imlib.c b/src/omv/img/imlib.c index 148ea797a..650248359 100644 --- a/src/omv/img/imlib.c +++ b/src/omv/img/imlib.c @@ -17,34 +17,6 @@ #include "mdefs.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 */ extern const float xyz_table[256]; /* RGB565->LAB lookup */ @@ -52,6 +24,28 @@ extern const int8_t lab_table[196608]; /* Grayscale [0..255] to rainbox lookup */ 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 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 g = color[c].g*63/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].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; xw+x_off; x++) { spix = *srcp++; dpix = dstp[i+x]; - vr = __PKHBT(R565(dpix), R565(spix), 16); - vg = __PKHBT(G565(dpix), G565(spix), 16); - vb = __PKHBT(B565(dpix), B565(spix), 16); + vr = __PKHBT(IM_R565(dpix), IM_R565(spix), 16); + vg = __PKHBT(IM_G565(dpix), IM_G565(spix), 16); + vb = __PKHBT(IM_B565(dpix), IM_B565(spix), 16); r = __SMUAD(v0, vr)>>8; g = __SMUAD(v0, vg)>>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]; // 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) + - R565(C)*(y_diff)*(1-x_diff) + R565(D)*(x_diff*y_diff)); + r = (int)(IM_R565(A)*(1-x_diff)*(1-y_diff) + IM_R565(B)*(x_diff)*(1-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) - g = (int)(G565(A)*(1-x_diff)*(1-y_diff) + G565(B)*(x_diff)*(1-y_diff) + - G565(C)*(y_diff)*(1-x_diff) + G565(D)*(x_diff*y_diff)); + g = (int)(IM_G565(A)*(1-x_diff)*(1-y_diff) + IM_G565(B)*(x_diff)*(1-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) - b =(int)(B565(A)*(1-x_diff)*(1-y_diff) + B565(B)*(x_diff)*(1-y_diff) + - B565(C)*(y_diff)*(1-x_diff) + B565(D)*(x_diff*y_diff)); + b =(int)(IM_B565(A)*(1-x_diff)*(1-y_diff) + IM_B565(B)*(x_diff)*(1-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 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 || cy+r >= image->h || cy-r < 0) { return; } while(x >= y) { - SET_PIXEL(image, x + cx, y + cy, c); - SET_PIXEL(image, y + cx, x + cy, c); - SET_PIXEL(image, -x + cx, y + cy, c); - SET_PIXEL(image, -y + cx, x + cy, c); - SET_PIXEL(image, -x + cx, -y + cy, c); - SET_PIXEL(image, -y + cx, -x + cy, c); - SET_PIXEL(image, x + cx, -y + cy, c); - SET_PIXEL(image, y + cx, -x + cy, c); + imlib_set_pixel(image, x + cx, y + cy, c); + imlib_set_pixel(image, y + cx, x + cy, c); + imlib_set_pixel(image, -x + cx, y + cy, c); + imlib_set_pixel(image, -y + cx, x + cy, c); + imlib_set_pixel(image, -x + cx, -y + cy, c); + imlib_set_pixel(image, -y + cx, -x + cy, c); + imlib_set_pixel(image, x + cx, -y + cy, c); + imlib_set_pixel(image, y + cx, -x + cy, c); y++; if (radiusError<0) { 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; uint8_t *srcp8 = (uint8_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++) { if (c < ' ' || c > '~') { @@ -705,7 +699,7 @@ void imlib_histeq(struct image *src) { int i, sum; 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 */ for (i=0; ipixels[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]]); } } diff --git a/src/omv/img/imlib.h b/src/omv/img/imlib.h index 02384f5bb..ae1605776 100644 --- a/src/omv/img/imlib.h +++ b/src/omv/img/imlib.h @@ -8,20 +8,137 @@ */ #ifndef __IMLIB_H__ #define __IMLIB_H__ -#include #include +#include #include "array.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) \ - ({ __typeof__ (a) _a = (a); \ + ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ - _a < _b ? _a : _b; }) + _a < _b ? _a : _b; }) #define IM_MAX(a,b) \ - ({ __typeof__ (a) _a = (a); \ + ({ __typeof__ (a) _a = (a); \ __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 { int w; @@ -150,6 +267,9 @@ typedef enum interp { INTERP_BICUBIC } 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_t *point_alloc(int16_t x, int16_t y); bool point_equal(point_t *p1, point_t *p2); diff --git a/src/omv/img/rainbow_tab.c b/src/omv/img/rainbow_tab.c index 73f4debb7..addcce25e 100644 --- a/src/omv/img/rainbow_tab.c +++ b/src/omv/img/rainbow_tab.c @@ -1,67 +1,35 @@ #include const uint16_t rainbow_table[256] = { - 0x1F06, 0x3F06, 0x5F06, 0x5F06, - 0x7F06, 0x9F06, 0xBF06, 0xDF06, - 0xDF06, 0xFF06, 0x1F07, 0x3F07, - 0x5F07, 0x5F07, 0x7F07, 0x9F07, - 0xBF07, 0xDF07, 0xFF07, 0xFE07, - 0xFE07, 0xFD07, 0xFD07, 0xFC07, - 0xFC07, 0xFC07, 0xFB07, 0xFB07, - 0xFA07, 0xFA07, 0xFA07, 0xF907, - 0xF907, 0xF907, 0xF807, 0xF807, - 0xF707, 0xF707, 0xF707, 0xF607, - 0xF607, 0xF607, 0xF507, 0xF507, - 0xF407, 0xF407, 0xF307, 0xF307, - 0xF307, 0xF207, 0xF207, 0xF107, - 0xF107, 0xF107, 0xF007, 0xF007, - 0xF007, 0xEF07, 0xEF07, 0xEE07, - 0xEE07, 0xEE07, 0xED07, 0xED07, - 0xED07, 0xEC07, 0xEC07, 0xEB07, - 0xEB07, 0xEB07, 0xEA07, 0xEA07, - 0xE907, 0xE907, 0xE807, 0xE807, - 0xE807, 0xE707, 0xE707, 0xE707, - 0xE607, 0xE607, 0xE507, 0xE507, - 0xE507, 0xE407, 0xE407, 0xE407, - 0xE307, 0xE307, 0xE207, 0xE207, - 0xE207, 0xE107, 0xE107, 0xE007, - 0xE007, 0xE007, 0xE007, 0xE007, - 0xE007, 0xE00F, 0xE00F, 0xE017, - 0xE017, 0xE017, 0xE01F, 0xE01F, - 0xE027, 0xE027, 0xE027, 0xE02F, - 0xE02F, 0xE037, 0xE037, 0xE037, - 0xE03F, 0xE03F, 0xE047, 0xE047, - 0xE047, 0xE04F, 0xE04F, 0xE04F, - 0xE057, 0xE057, 0xE05F, 0xE05F, - 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, + 0x3F06, 0x3F06, 0x5F06, 0x7F06, 0x9F06, 0xBF06, 0xBF06, 0xDF06, + 0xFF06, 0x1F07, 0x3F07, 0x3F07, 0x5F07, 0x7F07, 0x9F07, 0xBF07, + 0xBF07, 0xDF07, 0xFF07, 0xFF07, 0xFE07, 0xFE07, 0xFD07, 0xFD07, + 0xFD07, 0xFC07, 0xFC07, 0xFB07, 0xFB07, 0xFB07, 0xFA07, 0xFA07, + 0xFA07, 0xF907, 0xF907, 0xF807, 0xF807, 0xF807, 0xF707, 0xF707, + 0xF607, 0xF607, 0xF607, 0xF507, 0xF507, 0xF407, 0xF407, 0xF407, + 0xF307, 0xF307, 0xF207, 0xF207, 0xF207, 0xF107, 0xF107, 0xF107, + 0xF007, 0xF007, 0xEF07, 0xEF07, 0xEF07, 0xEE07, 0xEE07, 0xED07, + 0xED07, 0xED07, 0xEC07, 0xEC07, 0xEB07, 0xEB07, 0xEB07, 0xEA07, + 0xEA07, 0xEA07, 0xE907, 0xE907, 0xE807, 0xE807, 0xE807, 0xE707, + 0xE707, 0xE607, 0xE607, 0xE607, 0xE507, 0xE507, 0xE407, 0xE407, + 0xE407, 0xE307, 0xE307, 0xE207, 0xE207, 0xE207, 0xE107, 0xE107, + 0xE107, 0xE007, 0xE007, 0xE00F, 0xE00F, 0xE00F, 0xE017, 0xE017, + 0xE01F, 0xE01F, 0xE01F, 0xE027, 0xE027, 0xE02F, 0xE02F, 0xE02F, + 0xE037, 0xE037, 0xE03F, 0xE03F, 0xE03F, 0xE047, 0xE047, 0xE047, + 0xE04F, 0xE04F, 0xE057, 0xE057, 0xE057, 0xE05F, 0xE05F, 0xE067, + 0xE067, 0xE067, 0xE06F, 0xE06F, 0xE077, 0xE077, 0xE077, 0xE07F, + 0xE07F, 0xE087, 0xE087, 0xE087, 0xE08F, 0xE08F, 0xE08F, 0xE097, + 0xE097, 0xE09F, 0xE09F, 0xE09F, 0xE0A7, 0xE0A7, 0xE0AF, 0xE0AF, + 0xE0AF, 0xE0B7, 0xE0B7, 0xE0BF, 0xE0BF, 0xE0BF, 0xE0C7, 0xE0C7, + 0xE0C7, 0xE0CF, 0xE0CF, 0xE0D7, 0xE0D7, 0xE0D7, 0xE0DF, 0xE0DF, + 0xE0E7, 0xE0E7, 0xE0E7, 0xE0EF, 0xE0EF, 0xE0F7, 0xE0F7, 0xE0F7, + 0xE0FF, 0xE0FF, 0xC0FF, 0xA0FF, 0x80FF, 0x80FF, 0x60FF, 0x40FF, + 0x20FF, 0x00FF, 0x00FF, 0xE0FE, 0xC0FE, 0xA0FE, 0x80FE, 0x80FE, + 0x60FE, 0x40FE, 0x20FE, 0x00FE, 0x00FE, 0xE0FD, 0xC0FD, 0xA0FD, + 0x80FD, 0x80FD, 0x60FD, 0x40FD, 0x20FD, 0x00FD, 0x00FD, 0xE0FC, + 0xC0FC, 0xA0FC, 0xA0FC, 0x80FC, 0x60FC, 0x40FC, 0x20FC, 0x20FC, + 0x00FC, 0xE0FB, 0xC0FB, 0xA0FB, 0xA0FB, 0x80FB, 0x60FB, 0x40FB, + 0x20FB, 0x20FB, 0x00FB, 0xE0FA, 0xC0FA, 0xA0FA, 0xA0FA, 0x80FA, + 0x60FA, 0x40FA, 0x20FA, 0x20FA, 0x00FA, 0xE0F9, 0xC0F9, 0xA0F9, + 0xA0F9, 0x80F9, 0x60F9, 0x40F9, 0x40F9, 0x20F9, 0x00F9, 0xE0F8, + 0xC0F8, 0xC0F8, 0xA0F8, 0x80F8, 0x60F8, 0x40F8, 0x40F8, 0x20F8 }; diff --git a/src/omv/img/rgb2rgb_tab.c b/src/omv/img/rgb2rgb_tab.c new file mode 100644 index 000000000..9b6257904 --- /dev/null +++ b/src/omv/img/rgb2rgb_tab.c @@ -0,0 +1,85 @@ +#include +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 +}; diff --git a/util/gen_rainbow.py b/util/gen_rainbow.py index c7290f35c..8a11023fb 100755 --- a/util/gen_rainbow.py +++ b/util/gen_rainbow.py @@ -1,23 +1,27 @@ -#! /usr/bin/env python -import colorsys +#!/usr/bin/env python +# -*- coding: utf-8 -*- NUM_COL=256 SAT=1.0 VAL=1.0 OFFSET=220 + +import sys, colorsys +sys.stdout.write("#include \n") + 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 | - ((int(g*255)*63/255)&0x3F)<<5 | - ((int(b*255)*31/255)&0x1F) for r,g,b in tup] +col = [(int((((r*255)*31)+127.5)/255)&0x1F)<<11 | + (int((((g*255)*63)+127.5)/255)&0x3F)<<5 | + (int((((b*255)*31)+127.5)/255)&0x1F) for r,g,b in tup] -print \ -"#include \n"\ -"const uint16_t rainbow_table[%d] = {"%(NUM_COL) - -for i in range(0, NUM_COL): - if (i%4)==0 and i != (NUM_COL-1): - if i >0: - print "" - print " ", - print "0x%X,"%((col[i] & 0xff)<<8 |(col[i] & 0xff00) >> 8), -print "\n};" +sys.stdout.write("const uint16_t rainbow_table[%d] = {\n" % NUM_COL) +for i in range(NUM_COL): + if not (i % 8): + sys.stdout.write(" ") + sys.stdout.write("0x%04X" % (((col[i]&0x00ff)<<8)|((col[i]&0xff00)>>8))) + if (i + 1) % 8: + sys.stdout.write(", ") + elif i != (NUM_COL-1): + sys.stdout.write(",\n") + else: + sys.stdout.write("\n};\n") diff --git a/util/gen_rgb2rgb.py b/util/gen_rgb2rgb.py new file mode 100644 index 000000000..9f9f4179d --- /dev/null +++ b/util/gen_rgb2rgb.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys +sys.stdout.write("#include \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")