New GDISP now supports multiple controllers with different pixel formats.

You can now have a main color display and a secondary monochrome display.
You can now optionally set GDISP_PIXELFORMAT to any color or grayscale format for your application and the driver will internally convert to the display hardware format.
ugfx_release_2.6
inmarket 2013-11-05 19:34:12 +10:00
parent 250adaf028
commit a8e860678d
21 changed files with 442 additions and 108 deletions

View File

@ -524,7 +524,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
bitpos = (6 - 2 * (dx % EINK_PPB));
byte = block->data[dy][dx / EINK_PPB];
byte &= ~(PIXELMASK << bitpos);
if (g->p.color != Black)
if (COLOR2NATIVE(g->p.color) != Black)
byte |= PIXEL_WHITE << bitpos;
else
byte |= PIXEL_BLACK << bitpos;

View File

@ -167,7 +167,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
busmode16(g);
}
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
write_ram16(g, g->p.color);
write_ram16(g, COLOR2NATIVE(g->p.color));
}
LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
busmode8(g);

View File

@ -204,7 +204,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
#endif
}
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
write_data(g, g->p.color);
write_data(g, COLOR2NATIVE(g->p.color));
}
LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
release_bus(g);
@ -225,7 +225,10 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
dummy_read(g);
}
LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
return read_data(g);
uint16_t data;
data = read_data(g);
return NATIVE2COLOR(data);
}
LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
setwritemode(g);

View File

@ -200,7 +200,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
set_viewport(g);
}
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
write_data(g, g->p.color);
write_data(g, COLOR2NATIVE(g->p.color));
}
LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
release_bus(g);
@ -219,7 +219,10 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
dummy_read(g);
}
LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
return read_data(g);
uint16_t data;
data = read_data(g);
return NATIVE2COLOR(data);
}
LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
setwritemode(g);

View File

@ -246,7 +246,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
write_index(g, 0x2C);
}
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
write_data16(g, g->p.color);
write_data16(g, COLOR2NATIVE(g->p.color));
}
LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
release_bus(g);
@ -262,7 +262,10 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
dummy_read(g);
}
LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
return read_data(g);
uint16_t data;
data = read_data(g);
return NATIVE2COLOR(data);
}
LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
setwritemode(g);

View File

@ -211,7 +211,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
set_viewport(g);
}
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
write_data(g, g->p.color);
write_data(g, COLOR2NATIVE(g->p.color));
}
LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
release_bus(g);
@ -226,7 +226,10 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
dummy_read(g);
}
LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
return read_data(g);
uint16_t data;
data = read_data(g);
return NATIVE2COLOR(data);
}
LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
setwritemode(g);

View File

@ -70,8 +70,8 @@
/*===========================================================================*/
// Use the priv pointer itself to save our color. This save allocating ram for it
// and works provided sizeof(color_t) <= sizeof(void *)
#define savecolor(g) (*(color_t *)&g->priv)
// and works provided sizeof(uint16_t) <= sizeof(void *)
#define savecolor(g) (*(uint16_t *)&g->priv)
#define GDISP_FLG_ODDBYTE (GDISP_FLG_DRIVER<<0)
@ -143,14 +143,17 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
g->flags &= ~GDISP_FLG_ODDBYTE;
}
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
uint16_t c;
c = COLOR2NATIVE(g->p.color);
if ((g->flags & GDISP_FLG_ODDBYTE)) {
// Write the pair of pixels to the display
write_data3(g, ((savecolor(g) >> 4) & 0xFF),
(((savecolor(g) << 4) & 0xF0)|((g->p.color >> 8) & 0x0F)),
(g->p.color & 0xFF));
(((savecolor(g) << 4) & 0xF0)|((c >> 8) & 0x0F)),
(c & 0xFF));
g->flags &= ~GDISP_FLG_ODDBYTE;
} else {
savecolor(g) = g->p.color;
savecolor(g) = c;
g->flags |= GDISP_FLG_ODDBYTE;
}
}

View File

@ -111,9 +111,9 @@
#if GDISP_HARDWARE_STREAM_WRITE
typedef struct dvrPriv {
color_t savecolor;
uint16_t savecolor;
#if GDISP_GE8_BROKEN_CONTROLLER
color_t firstcolor;
uint16_t firstcolor;
#endif
} dvrPriv;
#define PRIV ((dvrPriv *)g->priv)
@ -231,20 +231,23 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
g->flags &= ~(GDISP_FLG_ODDBYTE|GDISP_FLG_RUNBYTE);
}
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
uint16_t c;
c = COLOR2NATIVE(g->p.color);
#if GDISP_GE8_BROKEN_CONTROLLER
if (!(g->flags & GDISP_FLG_RUNBYTE)) {
PRIV->firstcolor = g->p.color;
PRIV->firstcolor = c;
g->flags |= GDISP_FLG_RUNBYTE;
}
#endif
if ((g->flags & GDISP_FLG_ODDBYTE)) {
// Write the pair of pixels to the display
write_data3(g, ((PRIV->savecolor >> 4) & 0xFF),
(((PRIV->savecolor << 4) & 0xF0)|((g->p.color >> 8) & 0x0F)),
(g->p.color & 0xFF));
(((PRIV->savecolor << 4) & 0xF0)|((c >> 8) & 0x0F)),
(c & 0xFF));
g->flags &= ~GDISP_FLG_ODDBYTE;
} else {
PRIV->savecolor = g->p.color;
PRIV->savecolor = c;
g->flags |= GDISP_FLG_ODDBYTE;
}
}
@ -284,9 +287,12 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
#if GDISP_HARDWARE_DRAWPIXEL
LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
uint16_t c;
c = COLOR2NATIVE(g->p.color);
acquire_bus(g);
set_viewport(g);
write_data3(g, 0, (g->p.color>>8) & 0x0F, g->p.color & 0xFF);
write_data3(g, 0, (c>>8) & 0x0F, c & 0xFF);
release_bus(g);
}
#endif
@ -295,15 +301,17 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
#if GDISP_HARDWARE_FILLS
LLDSPEC void gdisp_lld_fill_area(GDisplay *g) {
unsigned tuples;
unsigned tuples;
uint16_t c;
tuples = (g->p.cx*g->p.cy+1)>>1; // With an odd sized area we over-print by one pixel.
// This extra pixel overwrites the first pixel (harmless as it is the same colour)
c = COLOR2NATIVE(g->p.color);
acquire_bus(g);
set_viewport(g);
while(tuples--)
write_data3(g, ((g->p.color >> 4) & 0xFF), (((g->p.color << 4) & 0xF0)|((g->p.color >> 8) & 0x0F)), (g->p.color & 0xFF));
write_data3(g, ((c >> 4) & 0xFF), (((c << 4) & 0xF0)|((c >> 8) & 0x0F)), (c & 0xFF));
release_bus(g);
}
#endif
@ -311,7 +319,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
#if GDISP_HARDWARE_BITFILLS
LLDSPEC void gdisp_lld_blit_area(GDisplay *g) {
coord_t lg, x, y;
color_t c1, c2;
uint16_t c1, c2;
unsigned tuples;
const pixel_t *buffer;
#if GDISP_PACKED_PIXELS
@ -328,7 +336,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
acquire_bus(g);
set_viewport(g);
/* to surpress compiler warnings */
/* to suppress compiler warnings */
x = 0;
y = 0;
@ -356,7 +364,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
while(tuples--) {
/* Get a pixel */
c1 = *p++;
c1 = COLOR2NATIVE(*p++);
/* Check for line or buffer wrapping */
if (++x >= g->p.cx) {
@ -369,7 +377,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
}
/* Get the next pixel */
c2 = *p++;
c2 = COLOR2NATIVE(*p++);
/* Check for line or buffer wrapping */
if (++x >= g->p.cx) {
@ -385,7 +393,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
write_data3(g, ((c1 >> 4) & 0xFF), (((c1 << 4) & 0xF0)|((c2 >> 8) & 0x0F)), (c2 & 0xFF));
}
#else
#elif GDISP_PIXELFORMAT == GDISP_LLD_PIXELFORMAT
// Although this controller uses packed pixels, we may have to feed it into
// the controller with different packing to the source bitmap
@ -440,6 +448,9 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
/* Write the pair of pixels to the display */
write_data3(g, ((c1 >> 4) & 0xFF), (((c1 << 4) & 0xF0)|((c2 >> 8) & 0x0F)), (c2 & 0xFF));
}
#else
#error "Packed pixels is broken if you are not running native pixel format"
#endif
/* All done */

View File

@ -184,7 +184,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
set_viewport(g);
}
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
write_data(g, g->p.color);
write_data(g, COLOR2NATIVE(g->p.color));
}
LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
release_bus(g);

View File

@ -221,7 +221,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
set_viewport(g);
}
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
write_data(g, g->p.color);
write_data(g, COLOR2NATIVE(g->p.color));
}
LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
release_bus(g);
@ -240,7 +240,10 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
dummy_read(g);
}
LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
return read_data(g);
uint16_t data;
data = read_data(g);
return NATIVE2COLOR(data);
}
LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
setwritemode(g);

View File

@ -200,7 +200,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
#endif
}
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
write_data(g, g->p.color);
write_data(g, COLOR2NATIVE(g->p.color));
}
LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
release_bus(g);
@ -221,7 +221,10 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
dummy_read(g);
}
LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
return read_data(g);
uint16_t data;
data = read_data(g);
return NATIVE2COLOR(data);
}
LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
setwritemode(g);
@ -231,15 +234,22 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
#if GDISP_HARDWARE_FILLS && defined(GDISP_USE_DMA)
LLDSPEC void gdisp_lld_fill_area(GDisplay *g) {
uint16_t c;
c = COLOR2NATIVE(g->p.color);
acquire_bus(g);
set_viewport(g);
set_cursor(g);
dma_with_noinc(g, &color, g->p.cx*g->p.cy)
dma_with_noinc(g, &c, g->p.cx*g->p.cy)
release_bus(g);
}
#endif
#if GDISP_HARDWARE_BITFILLS && defined(GDISP_USE_DMA)
#if GDISP_PIXELFORMAT != GDISP_LLD_PIXELFORMAT
#error "GDISP: SSD1289: BitBlit is only available in RGB565 pixel format"
#endif
LLDSPEC void gdisp_lld_blit_area(GDisplay *g) {
pixel_t *buffer;
coord_t ycnt;

View File

@ -28,8 +28,11 @@
#define GDISP_HARDWARE_CONTROL TRUE
#if defined(GDISP_USE_DMA)
#define GDISP_HARDWARE_FILLS TRUE
#define GDISP_HARDWARE_BITFILLS TRUE
#define GDISP_HARDWARE_FILLS TRUE
#if !defined(GDISP_PIXELFORMAT) || GDISP_PIXELFORMAT == 0x2565
// Hardware BitBlts are only supported in native pixel format on this controller
#define GDISP_HARDWARE_BITFILLS TRUE
#endif
#endif
#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565

View File

@ -176,7 +176,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
x = g->p.x;
break;
}
if (g->p.color != Black)
if (COLOR2NATIVE(g->p.color) != Black)
RAM(g)[xyaddr(x, y)] |= xybit(y);
else
RAM(g)[xyaddr(x, y)] &= ~xybit(y);

View File

@ -188,7 +188,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
set_viewport(g);
}
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
write_data(g, g->p.color);
write_data(g, COLOR2NATIVE(g->p.color));
}
LLDSPEC void gdisp_lld_write_stop(GDisplay *g) {
release_bus(g);

View File

@ -238,7 +238,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay* g) {
set_viewport(g);
}
LLDSPEC void gdisp_lld_write_color(GDisplay* g) {
write_data(g, g->p.color);
write_data(g, COLOR2NATIVE(g->p.color));
}
LLDSPEC void gdisp_lld_write_stop(GDisplay* g) {
release_bus(g);
@ -257,7 +257,10 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay* g) {
dummy_read(g);
}
LLDSPEC color_t gdisp_lld_read_color(GDisplay* g) {
return read_data(g);
uint16_t data;
data = read_data(g);
return NATIVE2COLOR(data);
}
LLDSPEC void gdisp_lld_read_stop(GDisplay* g) {
setwritemode(g);
@ -267,15 +270,22 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay* g) {
#if GDISP_HARDWARE_FILLS && defined(GDISP_USE_DMA)
LLDSPEC void gdisp_lld_fill_area(GDisplay* g) {
uint16_t c;
c = COLOR2NATIVE(g->p.color);
acquire_bus(g);
set_viewport(g);
set_cursor(g);
dma_with_noinc(g, &g->p.color, g->p.cx * g->p.cy);
dma_with_noinc(g, &c, g->p.cx * g->p.cy);
release_bus(g);
}
#endif
#if GDISP_HARDWARE_BITFILLS && defined(GDISP_USE_DMA)
#if GDISP_PIXELFORMAT != GDISP_LLD_PIXELFORMAT
#error "GDISP: SSD2119: BitBlit is only available in RGB565 pixel format"
#endif
LLDSPEC void gdisp_lld_blit_area(GDisplay* g) {
pixel_t* buffer;
coord_t ynct;

View File

@ -29,7 +29,10 @@
#if defined(GDISP_USE_DMA)
#define GDISP_HARDWARE_FILLS TRUE
#define GDISP_HARDWARE_BITFILLS TRUE
#if !defined(GDISP_PIXELFORMAT) || GDISP_PIXELFORMAT == 0x2565
// Hardware BitBlts are only supported in native pixel format on this controller
#define GDISP_HARDWARE_BITFILLS TRUE
#endif
#endif
#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565

View File

@ -167,7 +167,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
y = g->p.x;
break;
}
if (g->p.color != Black)
if (COLOR2NATIVE(g->p.color) != Black)
RAM(g)[xyaddr(x, y)] |= xybit(y);
else
RAM(g)[xyaddr(x, y)] &= ~xybit(y);

View File

@ -23,9 +23,7 @@
#ifndef GDISP_SCREEN_HEIGHT
#define GDISP_SCREEN_HEIGHT 480
#endif
#if GDISP_PIXELFORMAT != GDISP_PIXELFORMAT_RGB888
#error "GDISP Win32: This driver currently only supports the RGB888 pixel format."
#endif
// Setting this to TRUE delays updating the screen
// to the windows paint routine. Due to the
// drawing lock this does not add as much speed
@ -89,9 +87,6 @@ static HANDLE drawMutex;
#define APP_NAME "uGFX"
#define COLOR2BGR(c) ((((c) & 0xFF)<<16)|((c) & 0xFF00)|(((c)>>16) & 0xFF))
#define BGR2COLOR(c) COLOR2BGR(c)
typedef struct winPriv {
HWND hwnd;
HDC dcBuffer;
@ -291,9 +286,9 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
// Paint the toggle area
#if GINPUT_NEED_TOGGLE
if (ps.rcPaint.bottom >= GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASTOGGLE)) {
pen = CreatePen(PS_SOLID, 1, COLOR2BGR(Black));
hbrOn = CreateSolidBrush(COLOR2BGR(Blue));
hbrOff = CreateSolidBrush(COLOR2BGR(Gray));
pen = CreatePen(PS_SOLID, 1, COLOR2NATIVE(Black));
hbrOn = CreateSolidBrush(COLOR2NATIVE(Blue));
hbrOff = CreateSolidBrush(COLOR2NATIVE(Gray));
old = SelectObject(dc, pen);
MoveToEx(dc, 0, GDISP_SCREEN_HEIGHT, &p);
LineTo(dc, GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT);
@ -519,7 +514,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
COLORREF color;
priv = g->priv;
color = COLOR2BGR(g->p.color);
color = COLOR2NATIVE(g->p.color);
if (!(g->flags & GDISP_FLG_WSTREAM))
BAD_PARAMETER("write_color: not in streaming mode");
@ -667,7 +662,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
}
}
return BGR2COLOR(color);
return NATIVE2COLOR(color);
}
LLDSPEC void gdisp_lld_read_stop(GDisplay *g) {
if (!(g->flags & GDISP_FLG_WSTREAM))
@ -683,7 +678,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
COLORREF color;
priv = g->priv;
color = COLOR2BGR(g->p.color);
color = COLOR2NATIVE(g->p.color);
#if GDISP_NEED_CONTROL
switch(g->g.Orientation) {
@ -742,7 +737,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
COLORREF color;
priv = g->priv;
color = COLOR2BGR(g->p.color);
color = COLOR2NATIVE(g->p.color);
hbr = CreateSolidBrush(color);
#if GDISP_NEED_CONTROL
@ -841,6 +836,10 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
#endif
#if GDISP_HARDWARE_BITFILLS
#if COLOR_SYSTEM != GDISP_COLORSYSTEM_TRUECOLOR || COLOR_TYPE_BITS <= 8
#error "GDISP Win32: This driver's bitblit currently only supports true-color with bit depths > 8 bits."
#endif
LLDSPEC void gdisp_lld_blit_area(GDisplay *g) {
winPriv * priv;
pixel_t * buffer;
@ -855,7 +854,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
memset(&bmpInfo, 0, sizeof(bmpInfo));
bmpInfo.bV4Size = sizeof(bmpInfo);
bmpInfo.bV4Planes = 1;
bmpInfo.bV4BitCount = sizeof(pixel_t)*8;
bmpInfo.bV4BitCount = COLOR_TYPE_BITS;
bmpInfo.bV4AlphaMask = 0;
bmpInfo.bV4RedMask = RGB2COLOR(255,0,0);
bmpInfo.bV4GreenMask = RGB2COLOR(0,255,0);
@ -969,7 +968,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
#endif
ReleaseMutex(drawMutex);
return BGR2COLOR(color);
return NATIVE2COLOR(color);
}
#endif

View File

@ -41,11 +41,19 @@
#define GDISP_HARDWARE_DRAWPIXEL TRUE
#define GDISP_HARDWARE_FILLS TRUE
#define GDISP_HARDWARE_PIXELREAD TRUE
#define GDISP_HARDWARE_BITFILLS TRUE
#define GDISP_HARDWARE_SCROLL TRUE
// Bit-blits on Win32 are currently only supported for True-Color bit-depths greater than 8 bits
// Note: At the time this file is included we have not calculated all our color
// definitions so we need to do this by hand.
#if !defined(GDISP_PIXELFORMAT)
#define GDISP_HARDWARE_BITFILLS TRUE
#elif (GDISP_PIXELFORMAT & 0x2000) && (((GDISP_PIXELFORMAT & 0x0F00)>>8)+((GDISP_PIXELFORMAT & 0x00F0)>>4)+((GDISP_PIXELFORMAT & 0x000F))) > 8
#define GDISP_HARDWARE_BITFILLS TRUE
#endif
#endif
#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB888
#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_BGR888
#endif /* GFX_USE_GDISP */

View File

@ -48,6 +48,9 @@
* @{
*/
#define GDISP_PIXELFORMAT_MONO (GDISP_COLORSYSTEM_GRAYSCALE|0x0001)
#define GDISP_PIXELFORMAT_GRAY4 (GDISP_COLORSYSTEM_GRAYSCALE|0x0002)
#define GDISP_PIXELFORMAT_GRAY16 (GDISP_COLORSYSTEM_GRAYSCALE|0x0004)
#define GDISP_PIXELFORMAT_GRAY256 (GDISP_COLORSYSTEM_GRAYSCALE|0x0008)
#define GDISP_PIXELFORMAT_RGB565 (GDISP_COLORSYSTEM_RGB|0x0565)
#define GDISP_PIXELFORMAT_BGR565 (GDISP_COLORSYSTEM_BGR|0x0565)
#define GDISP_PIXELFORMAT_RGB888 (GDISP_COLORSYSTEM_RGB|0x0888)
@ -132,6 +135,15 @@
* @brief The number of bits in the color type (not necessarily the same as COLOR_BITS).
*/
#define COLOR_TYPE_BITS 16
/**
* @brief Convert a luminance (0 to 255) into a color value.
* @note The word "Luma" is used instead of grey or gray due to the spelling ambiguities of the word grey
* @note This is not a weighted luminance conversion in the color tv style.
* @note @p LUMA2COLOR() uses a linear conversion (0.33R + 0.33G + 0.33B). Note this is different to color
* tv luminance (0.26126R + 0.7152G + 0.0722B), digital tv luminance of (0.299R + 0.587G + 0.114B), or
* @p LUMA_OF() which uses (0.25R + 0.5G + 0.25B).
*/
#define LUMA2COLOR(l) ((color_t)((((l) & 0xF8)<<8) | (((l) & 0xFC)<<3) | (((l) & 0xF8)>>3)))
/**
* @brief Convert red, green, blue (each 0 to 255) into a color value.
*/
@ -141,27 +153,35 @@
*/
#define HTML2COLOR(h) ((color_t)((((h) & 0xF80000)>>8) | (((h) & 0x00FC00)>>5) | (((h) & 0x0000F8)>>3)))
/**
* @brief Extract the red/green/blue component (0 to 255) of a color value.
* @brief Extract the luma/red/green/blue component (0 to 255) of a color value.
* @note This uses quick and dirty bit shifting. If you want more exact colors
* use @p EXACT_RED_OF() etc which uses multiplies and divides. For constant
* colors using @p EXACT_REF_OF() is no more expensive because the compiler
* colors using @p EXACT_RED_OF() is no more expensive because the compiler
* evaluates the arithmetic.
* @note A 5 bit maximum value (0x1F) converts to 0xF8 (slightly off-color)
* @note @p LUMA_OF() returns a roughly weighted luminance (0.25R + 0.5G + 0.25B). Note this is
* different to @p LUMA2COLOR() which uses a linear conversion (0.33R + 0.33G + 0.33B) and
* color tv luminance of (0.26126R + 0.7152G + 0.0722B) and digital tv luminance of (0.299R + 0.587G + 0.114B).
* @note A 5 bit color component maximum value (0x1F) converts to 0xF8 (slightly off-color)
* @{
*/
#define LUMA_OF(c) ((RED_OF(c)+((uint16_t)GREEN_OF(c)<<1)+BLUE_OF(c))>>2)
#define RED_OF(c) (((c) & 0xF800)>>8)
#define GREEN_OF(c) (((c)&0x007E)>>3)
#define BLUE_OF(c) (((c)&0x001F)<<3)
/** @} */
/**
* @brief Extract the exact red/green/blue component (0 to 255) of a color value.
* @brief Extract the exact luma/red/green/blue component (0 to 255) of a color value.
* @note This uses multiplies and divides rather than bit shifting.
* This gives exact equivalent colors at the expense of more cpu intensive
* operations. Note for constants this is no more expensive than @p REF_OF()
* because the compiler evaluates the arithmetic.
* @note A 5 bit maximum value (0x1F) converts to 0xFF ( the true equivalent color)
* @note @p EXACT_LUMA_OF() returns a roughly weighted luminance (0.25R + 0.5G + 0.25B). Note this is
* different to @p LUMA2COLOR() which uses a linear conversion (0.33R + 0.33G + 0.33B) and
* color tv luminance of (0.26126R + 0.7152G + 0.0722B) and digital tv luminance of (0.299R + 0.587G + 0.114B).
* @note A 5 bit color component maximum value (0x1F) converts to 0xFF (the true equivalent color)
* @{
*/
#define EXACT_LUMA_OF(c) ((EXACT_RED_OF(c)+((uint16_t)EXACT_GREEN_OF(c)<<1)+EXACT_BLUE_OF(c))>>2)
#define EXACT_RED_OF(c) (((((c)>>11)&0x1F)*255)/31)
#define EXACT_GREEN_OF(c) (((((c)>>5)&0x3F)*255)/63)
#define EXACT_BLUE_OF(c) (((((c)>>0)&0x1F)*255)/31)
@ -219,61 +239,64 @@
// Calculate RED_OF, GREEN_OF, BLUE_OF and RGB2COLOR
#if COLOR_BITS_R + COLOR_SHIFT_R == 8
#define RED_OF(val) ((val) & (((1<<COLOR_BITS_R)-1) << COLOR_SHIFT_R))
#define RGB2COLOR_R(val) ((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_R))-1))))
#define RED_OF(c) ((c) & (((1<<COLOR_BITS_R)-1) << COLOR_SHIFT_R))
#define RGB2COLOR_R(r) ((COLOR_TYPE)((r) & (0xFF & ~((1<<(8-COLOR_BITS_R))-1))))
#elif COLOR_BITS_R + COLOR_SHIFT_R > 8
#define RED_OF(val) (((val) & (((1<<COLOR_BITS_R)-1) << COLOR_SHIFT_R)) >> (COLOR_BITS_R+COLOR_SHIFT_R-8))
#define RGB2COLOR_R(val) (((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_R))-1)))) << (COLOR_BITS_R+COLOR_SHIFT_R-8))
#define RED_OF(c) (((c) & (((1<<COLOR_BITS_R)-1) << COLOR_SHIFT_R)) >> (COLOR_BITS_R+COLOR_SHIFT_R-8))
#define RGB2COLOR_R(r) (((COLOR_TYPE)((r) & (0xFF & ~((1<<(8-COLOR_BITS_R))-1)))) << (COLOR_BITS_R+COLOR_SHIFT_R-8))
#else // COLOR_BITS_R + COLOR_SHIFT_R < 8
#define RED_OF(val) (((val) & (((1<<COLOR_BITS_R)-1) << COLOR_SHIFT_R)) << (8-(COLOR_BITS_R+COLOR_SHIFT_R)))
#define RGB2COLOR_R(val) (((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_R))-1)))) >> (8-(COLOR_BITS_R+COLOR_SHIFT_R)))
#define RED_OF(c) (((c) & (((1<<COLOR_BITS_R)-1) << COLOR_SHIFT_R)) << (8-(COLOR_BITS_R+COLOR_SHIFT_R)))
#define RGB2COLOR_R(r) (((COLOR_TYPE)((r) & (0xFF & ~((1<<(8-COLOR_BITS_R))-1)))) >> (8-(COLOR_BITS_R+COLOR_SHIFT_R)))
#endif
#if COLOR_BITS_G + COLOR_SHIFT_G == 8
#define GREEN_OF(val) ((val) & (((1<<COLOR_BITS_G)-1) << COLOR_SHIFT_G))
#define RGB2COLOR_G(val) ((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_G))-1))))
#define GREEN_OF(c) ((c) & (((1<<COLOR_BITS_G)-1) << COLOR_SHIFT_G))
#define RGB2COLOR_G(g) ((COLOR_TYPE)((g) & (0xFF & ~((1<<(8-COLOR_BITS_G))-1))))
#elif COLOR_BITS_G + COLOR_SHIFT_G > 8
#define GREEN_OF(val) (((val) & (((1<<COLOR_BITS_G)-1) << COLOR_SHIFT_G)) >> (COLOR_BITS_G+COLOR_SHIFT_G-8))
#define RGB2COLOR_G(val) (((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_G))-1)))) << (COLOR_BITS_G+COLOR_SHIFT_G-8))
#define GREEN_OF(c) (((c) & (((1<<COLOR_BITS_G)-1) << COLOR_SHIFT_G)) >> (COLOR_BITS_G+COLOR_SHIFT_G-8))
#define RGB2COLOR_G(g) (((COLOR_TYPE)((g) & (0xFF & ~((1<<(8-COLOR_BITS_G))-1)))) << (COLOR_BITS_G+COLOR_SHIFT_G-8))
#else // COLOR_BITS_G + COLOR_SHIFT_G < 8
#define GREEN_OF(val) (((val) & (((1<<COLOR_BITS_G)-1) << COLOR_SHIFT_G)) << (8-(COLOR_BITS_G+COLOR_SHIFT_G)))
#define RGB2COLOR_G(val) (((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_G))-1)))) >> (8-(COLOR_BITS_G+COLOR_SHIFT_G)))
#define GREEN_OF(c) (((c) & (((1<<COLOR_BITS_G)-1) << COLOR_SHIFT_G)) << (8-(COLOR_BITS_G+COLOR_SHIFT_G)))
#define RGB2COLOR_G(g) (((COLOR_TYPE)((g) & (0xFF & ~((1<<(8-COLOR_BITS_G))-1)))) >> (8-(COLOR_BITS_G+COLOR_SHIFT_G)))
#endif
#if COLOR_BITS_B + COLOR_SHIFT_B == 8
#define BLUE_OF(val) ((val) & (((1<<COLOR_BITS_B)-1) << COLOR_SHIFT_B))
#define RGB2COLOR_B(val) ((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1))))
#define BLUE_OF(c) ((c) & (((1<<COLOR_BITS_B)-1) << COLOR_SHIFT_B))
#define RGB2COLOR_B(b) ((COLOR_TYPE)((b) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1))))
#elif COLOR_BITS_B + COLOR_SHIFT_B > 8
#define BLUE_OF(val) (((val) & (((1<<COLOR_BITS_B)-1) << COLOR_SHIFT_B)) >> (COLOR_BITS_B+COLOR_SHIFT_B-8))
#define RGB2COLOR_B(val) (((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1)))) << (COLOR_BITS_B+COLOR_SHIFT_B-8))
#define BLUE_OF(c) (((c) & (((1<<COLOR_BITS_B)-1) << COLOR_SHIFT_B)) >> (COLOR_BITS_B+COLOR_SHIFT_B-8))
#define RGB2COLOR_B(b) (((COLOR_TYPE)((b) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1)))) << (COLOR_BITS_B+COLOR_SHIFT_B-8))
#else // COLOR_BITS_B + COLOR_SHIFT_B < 8
#define BLUE_OF(val) (((val) & (((1<<COLOR_BITS_B)-1) << COLOR_SHIFT_B)) << (8-(COLOR_BITS_B+COLOR_SHIFT_B)))
#define RGB2COLOR_B(val) (((COLOR_TYPE)((val) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1)))) >> (8-(COLOR_BITS_B+COLOR_SHIFT_B)))
#define BLUE_OF(c) (((c) & (((1<<COLOR_BITS_B)-1) << COLOR_SHIFT_B)) << (8-(COLOR_BITS_B+COLOR_SHIFT_B)))
#define RGB2COLOR_B(b) (((COLOR_TYPE)((b) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1)))) >> (8-(COLOR_BITS_B+COLOR_SHIFT_B)))
#endif
#define EXACT_RED_OF(val) (((((val)>>COLOR_SHIFT_R)&((1<<COLOR_BITS_R)-1))*255)/((1<<COLOR_BITS_R)-1))
#define EXACT_GREEN_OF(val) (((((val)>>COLOR_SHIFT_G)&((1<<COLOR_BITS_G)-1))*255)/((1<<COLOR_BITS_G)-1))
#define EXACT_BLUE_OF(val) (((((val)>>COLOR_SHIFT_B)&((1<<COLOR_BITS_B)-1))*255)/((1<<COLOR_BITS_B)-1))
#define LUMA_OF(c) ((RED_OF(c)+((uint16_t)GREEN_OF(c)<<1)+BLUE_OF(c))>>2)
#define EXACT_RED_OF(c) (((uint16_t)(((c)>>COLOR_SHIFT_R)&((1<<COLOR_BITS_R)-1))*255)/((1<<COLOR_BITS_R)-1))
#define EXACT_GREEN_OF(c) (((uint16_t)(((c)>>COLOR_SHIFT_G)&((1<<COLOR_BITS_G)-1))*255)/((1<<COLOR_BITS_G)-1))
#define EXACT_BLUE_OF(c) (((uint16_t)(((c)>>COLOR_SHIFT_B)&((1<<COLOR_BITS_B)-1))*255)/((1<<COLOR_BITS_B)-1))
#define EXACT_LUMA_OF(c) ((EXACT_RED_OF(c)+((uint16_t)EXACT_GREEN_OF(c)<<1)+EXACT_BLUE_OF(c))>>2)
#define LUMA2COLOR(l) (RGB2COLOR_R(l) | RGB2COLOR_G(l) | RGB2COLOR_B(l))
#define RGB2COLOR(r,g,b) (RGB2COLOR_R(r) | RGB2COLOR_G(g) | RGB2COLOR_B(b))
// Calculate HTML2COLOR
#if COLOR_BITS_R + COLOR_SHIFT_R == 24
#define HTML2COLOR_R(val) ((val) & ((0xFF & ~((1<<(8-COLOR_BITS_R))-1))<<16))
#define HTML2COLOR_R(h) ((h) & ((0xFF & ~((1<<(8-COLOR_BITS_R))-1))<<16))
#elif COLOR_BITS_R + COLOR_SHIFT_R > 24
#define HTML2COLOR_R(val) (((val) & ((0xFF & ~((1<<(8-COLOR_BITS_R))-1))<<16)) << (COLOR_BITS_R+COLOR_SHIFT_R-24))
#define HTML2COLOR_R(h) (((h) & ((0xFF & ~((1<<(8-COLOR_BITS_R))-1))<<16)) << (COLOR_BITS_R+COLOR_SHIFT_R-24))
#else // COLOR_BITS_R + COLOR_SHIFT_R < 24
#define HTML2COLOR_R(val) (((val) & ((0xFF & ~((1<<(8-COLOR_BITS_R))-1))<<16)) >> (24-(COLOR_BITS_R+COLOR_SHIFT_R)))
#define HTML2COLOR_R(h) (((h) & ((0xFF & ~((1<<(8-COLOR_BITS_R))-1))<<16)) >> (24-(COLOR_BITS_R+COLOR_SHIFT_R)))
#endif
#if COLOR_BITS_G + COLOR_SHIFT_G == 16
#define HTML2COLOR_G(val) ((val) & ((0xFF & ~((1<<(8-COLOR_BITS_G))-1))<<8))
#define HTML2COLOR_G(h) ((h) & ((0xFF & ~((1<<(8-COLOR_BITS_G))-1))<<8))
#elif COLOR_BITS_G + COLOR_SHIFT_G > 16
#define HTML2COLOR_G(val) (((val) & ((0xFF & ~((1<<(8-COLOR_BITS_G))-1))<<8)) << (COLOR_BITS_G+COLOR_SHIFT_G-16))
#define HTML2COLOR_G(h) (((h) & ((0xFF & ~((1<<(8-COLOR_BITS_G))-1))<<8)) << (COLOR_BITS_G+COLOR_SHIFT_G-16))
#else // COLOR_BITS_G + COLOR_SHIFT_G < 16
#define HTML2COLOR_G(val) (((val) & ((0xFF & ~((1<<(8-COLOR_BITS_G))-1))<<8)) >> (16-(COLOR_BITS_G+COLOR_SHIFT_G)))
#define HTML2COLOR_G(h) (((h) & ((0xFF & ~((1<<(8-COLOR_BITS_G))-1))<<8)) >> (16-(COLOR_BITS_G+COLOR_SHIFT_G)))
#endif
#if COLOR_BITS_B + COLOR_SHIFT_B == 8
#define HTML2COLOR_B(val) ((val) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1)))
#define HTML2COLOR_B(h) ((h) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1)))
#elif COLOR_BITS_B + COLOR_SHIFT_B > 8
#define HTML2COLOR_B(val) (((val) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1))) << (COLOR_BITS_B+COLOR_SHIFT_B-8))
#define HTML2COLOR_B(h) (((h) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1))) << (COLOR_BITS_B+COLOR_SHIFT_B-8))
#else // COLOR_BITS_B + COLOR_SHIFT_B < 8
#define HTML2COLOR_B(val) (((val) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1))) >> (8-(COLOR_BITS_B+COLOR_SHIFT_B)))
#define HTML2COLOR_B(h) (((h) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1))) >> (8-(COLOR_BITS_B+COLOR_SHIFT_B)))
#endif
#define HTML2COLOR(h) ((COLOR_TYPE)(HTML2COLOR_R(h) | HTML2COLOR_G(h) | HTML2COLOR_B(h)))
@ -308,25 +331,26 @@
#if COLOR_BITS == 1
#define RGB2COLOR(r,g,b) (((r)|(g)|(b)) ? 1 : 0)
#define LUMA2COLOR(l) ((l) ? 1 : 0)
#define HTML2COLOR(h) ((h) ? 1 : 0)
#define RED_OF(c) ((c) ? 255 : 0)
#define GREEN_OF(c) RED_OF(c)
#define BLUE_OF(c) RED_OF(c)
#define EXACT_RED_OF(val) RED_OF(c)
#define EXACT_GREEN_OF(val) RED_OF(c)
#define EXACT_BLUE_OF(val) RED_OF(c)
#define LUMA_OF(c) ((c) ? 255 : 0)
#define EXACT_LUMA_OF(c) LUMA_OF(c)
#else
// They eye is more sensitive to green
#define RGB2COLOR(r,g,b) ((COLOR_TYPE)(((uint16_t)(r)+(g)+(g)+(b)) >> (10-COLOR_BITS)))
#define LUMA2COLOR(l) ((COLOR_TYPE)((l)>>(8-COLOR_BITS)))
#define HTML2COLOR(h) ((COLOR_TYPE)(((((h)&0xFF0000)>>16)+(((h)&0x00FF00)>>7)+((h)&0x0000FF)) >> (10-COLOR_BITS)))
#define RED_OF(val) (((val) & ((1<<COLOR_BITS)-1)) << (8-COLOR_BITS))
#define GREEN_OF(c) RED_OF(c)
#define BLUE_OF(c) RED_OF(c)
#define EXACT_RED_OF(val) ((((uint16_t)(val) & ((1<<COLOR_BITS)-1))*255)/((1<<COLOR_BITS)-1))
#define EXACT_GREEN_OF(val) EXACT_RED_OF(c)
#define EXACT_BLUE_OF(val) EXACT_RED_OF(c)
#define LUMA_OF(c) (((c) & ((1<<COLOR_BITS)-1)) << (8-COLOR_BITS))
#define EXACT_LUMA_OF(c) ((((uint16_t)(c) & ((1<<COLOR_BITS)-1))*255)/((1<<COLOR_BITS)-1))
#endif
#define RED_OF(c) LUMA_OF(c)
#define GREEN_OF(c) LUMA_OF(c)
#define BLUE_OF(c) LUMA_OF(c)
#define EXACT_RED_OF(c) EXACT_LUMA_OF(c)
#define EXACT_GREEN_OF(c) EXACT_LUMA_OF(c)
#define EXACT_BLUE_OF(c) EXACT_LUMA_OF(c)
//-------------------------
// Palette color system
//-------------------------

View File

@ -651,6 +651,254 @@ struct GDisplay {
void gdispPackPixels(const pixel_t *buf, coord_t cx, coord_t x, coord_t y, color_t color);
#endif
/* Low level driver pixel format information */
//-------------------------
// True-Color color system
//-------------------------
#if GDISP_LLD_PIXELFORMAT & GDISP_COLORSYSTEM_TRUECOLOR
#define LLDCOLOR_SYSTEM GDISP_COLORSYSTEM_TRUECOLOR
// Calculate the number of bits
#define LLDCOLOR_BITS_R ((GDISP_LLD_PIXELFORMAT>>8) & 0x0F)
#define LLDCOLOR_BITS_G ((GDISP_LLD_PIXELFORMAT>>4) & 0x0F)
#define LLDCOLOR_BITS_B ((GDISP_LLD_PIXELFORMAT>>0) & 0x0F)
#define LLDCOLOR_BITS (LLDCOLOR_BITS_R + LLDCOLOR_BITS_G + LLDCOLOR_BITS_B)
// From the number of bits determine COLOR_TYPE, COLOR_TYPE_BITS and masking
#if LLDCOLOR_BITS <= 8
#define LLDCOLOR_TYPE uint8_t
#define LLDCOLOR_TYPE_BITS 8
#elif LLDCOLOR_BITS <= 16
#define LLDCOLOR_TYPE uint16_t
#define LLDCOLOR_TYPE_BITS 16
#elif LLDCOLOR_BITS <= 32
#define LLDCOLOR_TYPE uint32_t
#define LLDCOLOR_TYPE_BITS 32
#else
#error "GDISP: Cannot define low level driver color types with more than 32 bits"
#endif
#if LLDCOLOR_TYPE_BITS == LLDCOLOR_BITS
#define LLDCOLOR_NEEDS_MASK FALSE
#else
#define LLDCOLOR_NEEDS_MASK TRUE
#endif
#define LLDCOLOR_MASK() ((1 << LLDCOLOR_BITS)-1)
// Calculate the component bit shifts
#if (GDISP_LLD_PIXELFORMAT & GDISP_COLORSYSTEM_MASK) == GDISP_COLORSYSTEM_RGB
#define LLDCOLOR_SHIFT_R (LLDCOLOR_BITS_B+LLDCOLOR_BITS_G)
#define LLDCOLOR_SHIFT_G LLDCOLOR_BITS_B
#define LLDCOLOR_SHIFT_B 0
#else
#define LLDCOLOR_SHIFT_B (LLDCOLOR_BITS_R+LLDCOLOR_BITS_G)
#define LLDCOLOR_SHIFT_G LLDCOLOR_BITS_R
#define LLDCOLOR_SHIFT_R 0
#endif
// Calculate LLDRED_OF, LLDGREEN_OF, LLDBLUE_OF and LLDRGB2COLOR
#if LLDCOLOR_BITS_R + LLDCOLOR_SHIFT_R == 8
#define LLDRED_OF(c) ((c) & (((1<<LLDCOLOR_BITS_R)-1) << LLDCOLOR_SHIFT_R))
#define LLDRGB2COLOR_R(r) ((LLDCOLOR_TYPE)((r) & (0xFF & ~((1<<(8-LLDCOLOR_BITS_R))-1))))
#elif LLDCOLOR_BITS_R + LLDCOLOR_SHIFT_R > 8
#define LLDRED_OF(c) (((c) & (((1<<LLDCOLOR_BITS_R)-1) << LLDCOLOR_SHIFT_R)) >> (LLDCOLOR_BITS_R+LLDCOLOR_SHIFT_R-8))
#define LLDRGB2COLOR_R(r) (((LLDCOLOR_TYPE)((r) & (0xFF & ~((1<<(8-LLDCOLOR_BITS_R))-1)))) << (LLDCOLOR_BITS_R+LLDCOLOR_SHIFT_R-8))
#else // LLDCOLOR_BITS_R + LLDCOLOR_SHIFT_R < 8
#define LLDRED_OF(c) (((c) & (((1<<LLDCOLOR_BITS_R)-1) << LLDCOLOR_SHIFT_R)) << (8-(LLDCOLOR_BITS_R+LLDCOLOR_SHIFT_R)))
#define LLDRGB2COLOR_R(r) (((LLDCOLOR_TYPE)((r) & (0xFF & ~((1<<(8-LLDCOLOR_BITS_R))-1)))) >> (8-(LLDCOLOR_BITS_R+LLDCOLOR_SHIFT_R)))
#endif
#if LLDCOLOR_BITS_G + LLDCOLOR_SHIFT_G == 8
#define LLDGREEN_OF(c) ((c) & (((1<<LLDCOLOR_BITS_G)-1) << LLDCOLOR_SHIFT_G))
#define LLDRGB2COLOR_G(g) ((LLDCOLOR_TYPE)((g) & (0xFF & ~((1<<(8-LLDCOLOR_BITS_G))-1))))
#elif LLDCOLOR_BITS_G + LLDCOLOR_SHIFT_G > 8
#define LLDGREEN_OF(c) (((c) & (((1<<LLDCOLOR_BITS_G)-1) << LLDCOLOR_SHIFT_G)) >> (LLDCOLOR_BITS_G+LLDCOLOR_SHIFT_G-8))
#define LLDRGB2COLOR_G(g) (((LLDCOLOR_TYPE)((g) & (0xFF & ~((1<<(8-LLDCOLOR_BITS_G))-1)))) << (LLDCOLOR_BITS_G+LLDCOLOR_SHIFT_G-8))
#else // LLDCOLOR_BITS_G + LLDCOLOR_SHIFT_G < 8
#define LLDGREEN_OF(c) (((c) & (((1<<LLDCOLOR_BITS_G)-1) << LLDCOLOR_SHIFT_G)) << (8-(LLDCOLOR_BITS_G+LLDCOLOR_SHIFT_G)))
#define LLDRGB2COLOR_G(g) (((LLDCOLOR_TYPE)((g) & (0xFF & ~((1<<(8-LLDCOLOR_BITS_G))-1)))) >> (8-(LLDCOLOR_BITS_LLDG+COLOR_SHIFT_G)))
#endif
#if LLDCOLOR_BITS_B + LLDCOLOR_SHIFT_B == 8
#define LLDBLUE_OF(c) ((c) & (((1<<LLDCOLOR_BITS_B)-1) << LLDCOLOR_SHIFT_B))
#define LLDRGB2COLOR_B(b) ((LLDCOLOR_TYPE)((b) & (0xFF & ~((1<<(8-LLDCOLOR_BITS_B))-1))))
#elif LLDCOLOR_BITS_B + LLDCOLOR_SHIFT_B > 8
#define LLDBLUE_OF(c) (((c) & (((1<<LLDCOLOR_BITS_B)-1) << LLDCOLOR_SHIFT_B)) >> (LLDCOLOR_BITS_B+LLDCOLOR_SHIFT_B-8))
#define LLDRGB2COLOR_B(b) (((LLDCOLOR_TYPE)((b) & (0xFF & ~((1<<(8-LLDCOLOR_BITS_B))-1)))) << (LLDCOLOR_BITS_B+LLDCOLOR_SHIFT_B-8))
#else // LLDCOLOR_BITS_B + LLDCOLOR_SHIFT_B < 8
#define LLDBLUE_OF(c) (((c) & (((1<<LLDCOLOR_BITS_B)-1) << LLDCOLOR_SHIFT_B)) << (8-(LLDCOLOR_BITS_B+LLDCOLOR_SHIFT_B)))
#define LLDRGB2COLOR_B(b) (((COLOR_TYPE)((b) & (0xFF & ~((1<<(8-LLDCOLOR_BITS_B))-1)))) >> (8-(LLDCOLOR_BITS_B+LLDCOLOR_SHIFT_B)))
#endif
#define LLDLUMA_OF(c) ((LLDRED_OF(c)+((uint16_t)LLDGREEN_OF(c)<<1)+LLDBLUE_OF(c))>>2)
#define LLDEXACT_RED_OF(c) (((uint16_t)(((c)>>LLDCOLOR_SHIFT_R)&((1<<LLDCOLOR_BITS_R)-1))*255)/((1<<LLDCOLOR_BITS_R)-1))
#define LLDEXACT_GREEN_OF(c) (((uint16_t)(((c)>>LLDCOLOR_SHIFT_G)&((1<<LLDCOLOR_BITS_G)-1))*255)/((1<<LLDCOLOR_BITS_G)-1))
#define LLDEXACT_BLUE_OF(c) (((uint16_t)(((c)>>LLDCOLOR_SHIFT_B)&((1<<LLDCOLOR_BITS_B)-1))*255)/((1<<LLDCOLOR_BITS_B)-1))
#define LLDEXACT_LUMA_OF(c) ((LLDEXACT_RED_OF(c)+((uint16_t)LLDEXACT_GREEN_OF(c)<<1)+LLDEXACT_BLUE_OF(c))>>2)
#define LLDLUMA2COLOR(l) (LLDRGB2COLOR_R(l) | LLDRGB2COLOR_G(l) | LLDRGB2COLOR_B(l))
#define LLDRGB2COLOR(r,g,b) (LLDRGB2COLOR_R(r) | LLDRGB2COLOR_G(g) | LLDRGB2COLOR_B(b))
// Calculate LLDHTML2COLOR
#if LLDCOLOR_BITS_R + LLDCOLOR_SHIFT_R == 24
#define LLDHTML2COLOR_R(h) ((h) & ((0xFF & ~((1<<(8-LLDCOLOR_BITS_R))-1))<<16))
#elif COLOR_BITS_R + COLOR_SHIFT_R > 24
#define LLDHTML2COLOR_R(h) (((h) & ((0xFF & ~((1<<(8-LLDCOLOR_BITS_R))-1))<<16)) << (LLDCOLOR_BITS_R+LLDCOLOR_SHIFT_R-24))
#else // COLOR_BITS_R + COLOR_SHIFT_R < 24
#define LLDHTML2COLOR_R(h) (((h) & ((0xFF & ~((1<<(8-LLDCOLOR_BITS_R))-1))<<16)) >> (24-(LLDCOLOR_BITS_R+LLDCOLOR_SHIFT_R)))
#endif
#if LLDCOLOR_BITS_G + LLDCOLOR_SHIFT_G == 16
#define LLDHTML2COLOR_G(h) ((h) & ((0xFF & ~((1<<(8-LLDCOLOR_BITS_G))-1))<<8))
#elif LLDCOLOR_BITS_G + LLDCOLOR_SHIFT_G > 16
#define LLDHTML2COLOR_G(h) (((h) & ((0xFF & ~((1<<(8-LLDCOLOR_BITS_G))-1))<<8)) << (LLDCOLOR_BITS_G+LLDCOLOR_SHIFT_G-16))
#else // LLDCOLOR_BITS_G + LLDCOLOR_SHIFT_G < 16
#define LLDHTML2COLOR_G(h) (((h) & ((0xFF & ~((1<<(8-LLDCOLOR_BITS_G))-1))<<8)) >> (16-(LLDCOLOR_BITS_G+LLDCOLOR_SHIFT_G)))
#endif
#if LLDCOLOR_BITS_B + LLDCOLOR_SHIFT_B == 8
#define LLDHTML2COLOR_B(h) ((h) & (0xFF & ~((1<<(8-LLDCOLOR_BITS_B))-1)))
#elif LLDCOLOR_BITS_B + LLDCOLOR_SHIFT_B > 8
#define LLDHTML2COLOR_B(h) (((h) & (0xFF & ~((1<<(8-LLDCOLOR_BITS_B))-1))) << (LLDCOLOR_BITS_B+LLDCOLOR_SHIFT_B-8))
#else // LLDCOLOR_BITS_B + LLDCOLOR_SHIFT_B < 8
#define LLDHTML2COLOR_B(h) (((h) & (0xFF & ~((1<<(8-LLDCOLOR_BITS_B))-1))) >> (8-(LLDCOLOR_BITS_B+LLDCOLOR_SHIFT_B)))
#endif
#define LLDHTML2COLOR(h) ((LLDCOLOR_TYPE)(LLDHTML2COLOR_R(h) | LLDHTML2COLOR_G(h) | LLDHTML2COLOR_B(h)))
//-------------------------
// Gray-scale color system
//-------------------------
#elif (GDISP_LLD_PIXELFORMAT & GDISP_COLORSYSTEM_MASK) == GDISP_COLORSYSTEM_GRAYSCALE
#define LLDCOLOR_SYSTEM GDISP_COLORSYSTEM_GRAYSCALE
// Calculate the number of bits and shifts
#define LLDCOLOR_BITS (GDISP_LLD_PIXELFORMAT & 0xFF)
#define LLDCOLOR_BITS_R LLDCOLOR_BITS
#define LLDCOLOR_BITS_G LLDCOLOR_BITS
#define LLDCOLOR_BITS_B LLDCOLOR_BITS
#define LLDCOLOR_SHIFT_R 0
#define LLDCOLOR_SHIFT_G 0
#define LLDCOLOR_SHIFT_B 0
// From the number of bits determine COLOR_TYPE, COLOR_TYPE_BITS and masking
#if LLDCOLOR_BITS <= 8
#define LLDCOLOR_TYPE uint8_t
#define LLDCOLOR_TYPE_BITS 8
#else
#error "GDISP: Cannot define gray-scale low level driver color types with more than 8 bits"
#endif
#if LLDCOLOR_TYPE_BITS == LLDCOLOR_BITS
#define LLDCOLOR_NEEDS_MASK FALSE
#else
#define LLDCOLOR_NEEDS_MASK TRUE
#endif
#define LLDCOLOR_MASK() ((1 << LLDCOLOR_BITS)-1)
#if COLOR_BITS == 1
#define LLDRGB2COLOR(r,g,b) (((r)|(g)|(b)) ? 1 : 0)
#define LLDLUMA2COLOR(l) ((l) ? 1 : 0)
#define LLDHTML2COLOR(h) ((h) ? 1 : 0)
#define LLDLUMA_OF(c) ((c) ? 255 : 0)
#define LLDEXACT_LUMA_OF(c) LLDLUMA_OF(c)
#else
// They eye is more sensitive to green
#define LLDRGB2COLOR(r,g,b) ((LLDCOLOR_TYPE)(((uint16_t)(r)+(g)+(g)+(b)) >> (10-LLDCOLOR_BITS)))
#define LLDLUMA2COLOR(l) ((LLDCOLOR_TYPE)((l)>>(8-LLDCOLOR_BITS)))
#define LLDHTML2COLOR(h) ((LLDCOLOR_TYPE)(((((h)&0xFF0000)>>16)+(((h)&0x00FF00)>>7)+((h)&0x0000FF)) >> (10-LLDCOLOR_BITS)))
#define LLDLUMA_OF(c) (((c) & ((1<<LLDCOLOR_BITS)-1)) << (8-LLDCOLOR_BITS))
#define LLDEXACT_LUMA_OF(c) ((((uint16_t)(c) & ((1<<LLDCOLOR_BITS)-1))*255)/((1<<LLDCOLOR_BITS)-1))
#endif
#define LLDRED_OF(c) LLDLUMA_OF(c)
#define LLDGREEN_OF(c) LLDLUMA_OF(c)
#define LLDBLUE_OF(c) LLDLUMA_OF(c)
#define LLDEXACT_RED_OF(c) LLDEXACT_LUMA_OF(c)
#define LLDEXACT_GREEN_OF(c) LLDEXACT_LUMA_OF(c)
#define LLDEXACT_BLUE_OF(c) LLDEXACT_LUMA_OF(c)
//-------------------------
// Palette color system
//-------------------------
#elif (GDISP_LLD_PIXELFORMAT & GDISP_COLORSYSTEM_MASK) == GDISP_COLORSYSTEM_PALETTE
#define LLDCOLOR_SYSTEM GDISP_COLORSYSTEM_PALETTE
#error "GDISP: A palette color system for low level drivers is not currently supported"
//-------------------------
// Some other color system
//-------------------------
#else
#error "GDISP: Unsupported color system for low level drivers"
#endif
/* Which is the larger color type */
#if COLOR_BITS > LLDCOLOR_BITS
#define LARGER_COLOR_BITS COLOR_BITS
#define LARGER_COLOR_TYPE COLOR_TYPE
#else
#define LARGER_COLOR_BITS LLDCOLOR_BITS
#define LARGER_COLOR_TYPE LLDCOLOR_TYPE
#endif
/**
* @brief Controls color conversion accuracy for a low level driver
* @details Should higher precision be used when converting colors.
* @note Color conversion is only necessary if GDISP_PIXELFORMAT != GDISP_LLD_PIXELFORMAT
* @note It only makes sense to turn this on if you have a high bit depth display but
* are running the application in low bit depths.
* @note To achieve higher color accuracy bit shifting is replaced with multiplies and divides.
*/
#ifndef GDISP_HARDWARE_USE_EXACT_COLOR
#if LLDCOLOR_BITS_R - COLOR_BITS_R >= LLDCOLOR_BITS_R/2 || LLDCOLOR_BITS_G - COLOR_BITS_G >= LLDCOLOR_BITS_G/2 || LLDCOLOR_BITS_B - COLOR_BITS_B >= LLDCOLOR_BITS_B/2
#define GDISP_HARDWARE_USE_EXACT_COLOR TRUE
#else
#define GDISP_HARDWARE_USE_EXACT_COLOR FALSE
#endif
#endif
/* Low level driver pixel format conversion functions */
#if GDISP_PIXELFORMAT == GDISP_LLD_PIXELFORMAT || defined(__DOXYGEN__)
/**
* @brief Convert from a standard color format to the low level driver pixel format
* @note For use only by low level drivers
*/
#define COLOR2NATIVE(c) (c)
/**
* @brief Convert from a low level driver pixel format to the standard color format
* @note For use only by low level drivers
*/
#define NATIVE2COLOR(c) (c)
#else
#if COLOR_SYSTEM == GDISP_COLORSYSTEM_GRAYSCALE || LLDCOLOR_SYSTEM == GDISP_COLORSYSTEM_GRAYSCALE
#if GDISP_HARDWARE_USE_EXACT_COLOR
#define COLOR2NATIVE(c) LLDLUMA2COLOR(EXACT_LUMA_OF(c))
#define NATIVE2COLOR(c) LUMA2COLOR(LLDEXACT_LUMA_OF(c))
#else
#define COLOR2NATIVE(c) LLDLUMA2COLOR(LUMA_OF(c))
#define NATIVE2COLOR(c) LUMA2COLOR(LLDLUMA_OF(c))
#endif
#elif COLOR_SYSTEM == GDISP_COLORSYSTEM_TRUECOLOR && LLDCOLOR_SYSTEM == GDISP_COLORSYSTEM_TRUECOLOR
#if GDISP_HARDWARE_USE_EXACT_COLOR
#define COLOR2NATIVE(c) LLDRGB2COLOR(EXACT_RED_OF(c), EXACT_GREEN_OF(c), EXACT_BLUE_OF(c))
#define NATIVE2COLOR(c) RGB2COLOR(LLDEXACT_RED_OF(c), LLDEXACT_GREEN_OF(c), LLDEXACT_BLUE_OF(c))
#else
#define COLOR2NATIVE(c) LLDRGB2COLOR(RED_OF(c), GREEN_OF(c), BLUE_OF(c))
#define NATIVE2COLOR(c) RGB2COLOR(LLDRED_OF(c), LLDGREEN_OF(c), LLDBLUE_OF(c))
#endif
/*
#elif GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_RGB888 && GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_BGR888
#define COLOR2NATIVE(c) ((LLDCOLOR_TYPE)(((c)&0xFF0000)>>16)|((c)&0x00FF00)|(((c)&0x0000FF)<<16))
#define NATIVE2COLOR(c) ((COLOR_TYPE)(((c)&0xFF0000)>>16)|((c)&0x00FF00)|(((c)&0x0000FF)<<16))
#elif GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_RGB565 && GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_BGR888
#define COLOR2NATIVE(c) ((LLDCOLOR_TYPE)( \
((LARGER_COLOR_TYPE)((c)&(((1<<COLOR_BITS_R)-1)<<COLOR_SHIFT_R))>>(COLOR_BITS_R+COLOR_SHIFT_R-8))| \
((LARGER_COLOR_TYPE)((c)&(((1<<COLOR_BITS_G)-1)<<COLOR_SHIFT_G))<<(16-(COLOR_BITS_G+COLOR_SHIFT_G)))| \
((LARGER_COLOR_TYPE)((c)&(((1<<COLOR_BITS_B)-1)<<COLOR_SHIFT_B))<<(24-(COLOR_BITS_B+COLOR_SHIFT_B)))))
#define NATIVE2COLOR(c) ((COLOR_TYPE)( \
((LARGER_COLOR_TYPE)((c)&0x0000F8)<<COLOR_SHIFT_R)| \
((LARGER_COLOR_TYPE)((c)&0x00FC00)>>(16-(COLOR_BITS_G+COLOR_SHIFT_G)))| \
((LARGER_COLOR_TYPE)((c)&0xF80000)>>(24-(COLOR_BITS_B+COLOR_SHIFT_B)))))
*/
#else
#error "GDISP: This pixel format conversion is not supported yet"
#endif
#endif
#endif /* GFX_USE_GDISP */
#endif /* _GDISP_LLD_H */