mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
optional 12 bit gfx mode
This commit is contained in:
parent
e2126c3b63
commit
9f061dfe11
@ -41,7 +41,7 @@ info = {
|
|||||||
'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"Bangle.js"\'',
|
'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"Bangle.js"\'',
|
||||||
'DEFINES+=-DCUSTOM_GETBATTERY=jswrap_banglejs_getBattery',
|
'DEFINES+=-DCUSTOM_GETBATTERY=jswrap_banglejs_getBattery',
|
||||||
'DEFINES+=-DDUMP_IGNORE_VARIABLES=\'"g\\0"\'',
|
'DEFINES+=-DDUMP_IGNORE_VARIABLES=\'"g\\0"\'',
|
||||||
'DEFINES+=-DUSE_FONT_6X8 -DGRAPHICS_PALETTED_IMAGES',
|
'DEFINES+=-DUSE_FONT_6X8 -DGRAPHICS_PALETTED_IMAGES -DESPR_GRAPHICS_12BIT -DGRAPHICS_ANTIALIAS',
|
||||||
'DEFINES+=-DNO_DUMP_HARDWARE_INITIALISATION', # don't dump hardware init - not used and saves 1k of flash
|
'DEFINES+=-DNO_DUMP_HARDWARE_INITIALISATION', # don't dump hardware init - not used and saves 1k of flash
|
||||||
'INCLUDE += -I$(ROOT)/libs/banglejs -I$(ROOT)/libs/misc',
|
'INCLUDE += -I$(ROOT)/libs/banglejs -I$(ROOT)/libs/misc',
|
||||||
'WRAPPERSOURCES += libs/banglejs/jswrap_bangle.c',
|
'WRAPPERSOURCES += libs/banglejs/jswrap_bangle.c',
|
||||||
|
|||||||
@ -295,7 +295,22 @@ uint32_t graphicsBlendColor(JsGraphics *gfx, int iamt) {
|
|||||||
unsigned int gi = (bg*(256-amt) + fg*amt) >> 8;
|
unsigned int gi = (bg*(256-amt) + fg*amt) >> 8;
|
||||||
unsigned int bi = (bb*(256-amt) + fb*amt) >> 8;
|
unsigned int bi = (bb*(256-amt) + fb*amt) >> 8;
|
||||||
return (uint16_t)((bi>>3) | (gi>>2)<<5 | (ri>>3)<<11);
|
return (uint16_t)((bi>>3) | (gi>>2)<<5 | (ri>>3)<<11);
|
||||||
}
|
#ifdef ESPR_GRAPHICS_12BIT
|
||||||
|
} else if (gfx->data.bpp==12) { // Blend from bg to fg
|
||||||
|
unsigned int b = gfx->data.bgColor;
|
||||||
|
unsigned int br = (b>>8)&0xF0;
|
||||||
|
unsigned int bg = (b>>4)&0xF0;
|
||||||
|
unsigned int bb = (b<<4)&0xF0;
|
||||||
|
unsigned int f = gfx->data.fgColor;
|
||||||
|
unsigned int fr = (f>>8)&0xF0;
|
||||||
|
unsigned int fg = (f>>4)&0xF0;
|
||||||
|
unsigned int fb = (f<<4)&0xF0;
|
||||||
|
unsigned int ri = (br*(256-amt) + fr*amt) >> 8;
|
||||||
|
unsigned int gi = (bg*(256-amt) + fg*amt) >> 8;
|
||||||
|
unsigned int bi = (bb*(256-amt) + fb*amt) >> 8;
|
||||||
|
return (uint16_t)((bi>>4) | (gi>>4)<<4 | (ri>>4)<<8);
|
||||||
|
#endif
|
||||||
|
} // TODO: 24 bit
|
||||||
return (amt>=128) ? gfx->data.fgColor : gfx->data.bgColor;
|
return (amt>=128) ? gfx->data.fgColor : gfx->data.bgColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,6 +36,14 @@
|
|||||||
#include "vector_font.h"
|
#include "vector_font.h"
|
||||||
|
|
||||||
#ifdef GRAPHICS_PALETTED_IMAGES
|
#ifdef GRAPHICS_PALETTED_IMAGES
|
||||||
|
#ifdef ESPR_GRAPHICS_12BIT
|
||||||
|
#define PALETTE_BPP 12
|
||||||
|
// 16 color 12 bit Web-safe palette
|
||||||
|
const uint16_t PALETTE_4BIT[16] = { 0x0,0x444,0x888,0xbbb,0x963,0x630,0x60,0xa0,0x9f,0xc,0x309,0xf09,0xd00,0xf60,0xff0,0xfff };
|
||||||
|
// 256 color 12 bit Web-safe palette
|
||||||
|
const uint16_t PALETTE_8BIT[256] = { 0x0,0x3,0x6,0x9,0xc,0xf,0x30,0x33,0x36,0x39,0x3c,0x3f,0x60,0x63,0x66,0x69,0x6c,0x6f,0x90,0x93,0x96,0x99,0x9c,0x9f,0xc0,0xc3,0xc6,0xc9,0xcc,0xcf,0xf0,0xf3,0xf6,0xf9,0xfc,0xff,0x300,0x303,0x306,0x309,0x30c,0x30f,0x330,0x333,0x336,0x339,0x33c,0x33f,0x360,0x363,0x366,0x369,0x36c,0x36f,0x390,0x393,0x396,0x399,0x39c,0x39f,0x3c0,0x3c3,0x3c6,0x3c9,0x3cc,0x3cf,0x3f0,0x3f3,0x3f6,0x3f9,0x3fc,0x3ff,0x600,0x603,0x606,0x609,0x60c,0x60f,0x630,0x633,0x636,0x639,0x63c,0x63f,0x660,0x663,0x666,0x669,0x66c,0x66f,0x690,0x693,0x696,0x699,0x69c,0x69f,0x6c0,0x6c3,0x6c6,0x6c9,0x6cc,0x6cf,0x6f0,0x6f3,0x6f6,0x6f9,0x6fc,0x6ff,0x900,0x903,0x906,0x909,0x90c,0x90f,0x930,0x933,0x936,0x939,0x93c,0x93f,0x960,0x963,0x966,0x969,0x96c,0x96f,0x990,0x993,0x996,0x999,0x99c,0x99f,0x9c0,0x9c3,0x9c6,0x9c9,0x9cc,0x9cf,0x9f0,0x9f3,0x9f6,0x9f9,0x9fc,0x9ff,0xc00,0xc03,0xc06,0xc09,0xc0c,0xc0f,0xc30,0xc33,0xc36,0xc39,0xc3c,0xc3f,0xc60,0xc63,0xc66,0xc69,0xc6c,0xc6f,0xc90,0xc93,0xc96,0xc99,0xc9c,0xc9f,0xcc0,0xcc3,0xcc6,0xcc9,0xccc,0xccf,0xcf0,0xcf3,0xcf6,0xcf9,0xcfc,0xcff,0xf00,0xf03,0xf06,0xf09,0xf0c,0xf0f,0xf30,0xf33,0xf36,0xf39,0xf3c,0xf3f,0xf60,0xf63,0xf66,0xf69,0xf6c,0xf6f,0xf90,0xf93,0xf96,0xf99,0xf9c,0xf9f,0xfc0,0xfc3,0xfc6,0xfc9,0xfcc,0xfcf,0xff0,0xff3,0xff6,0xff9,0xffc,0xfff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xfff };
|
||||||
|
#else // default to 16 bit
|
||||||
|
#define PALETTE_BPP 16
|
||||||
// 16 color MAC OS palette
|
// 16 color MAC OS palette
|
||||||
const uint16_t PALETTE_4BIT[16] = { 0x0,0x4228,0x8c51,0xbdd7,0x9b26,0x6180,0x320,0x540,0x4df,0x19,0x3013,0xf813,0xd800,0xfb20,0xffe0,0xffff };
|
const uint16_t PALETTE_4BIT[16] = { 0x0,0x4228,0x8c51,0xbdd7,0x9b26,0x6180,0x320,0x540,0x4df,0x19,0x3013,0xf813,0xd800,0xfb20,0xffe0,0xffff };
|
||||||
// 256 color 16 bit Web-safe palette
|
// 256 color 16 bit Web-safe palette
|
||||||
@ -57,6 +65,7 @@ const uint16_t PALETTE_8BIT[256] = {
|
|||||||
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
|
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
|
||||||
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xffff
|
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xffff
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
// map Mac to web-safe palette. Must be uint16_t because drawImage uses uint16_t* for palette
|
// map Mac to web-safe palette. Must be uint16_t because drawImage uses uint16_t* for palette
|
||||||
const uint16_t PALETTE_4BIT_TO_8BIT[16] = { 0, 43, 129, 172, 121, 78, 12, 18, 23, 4, 39, 183, 144, 192, 210, 215 };
|
const uint16_t PALETTE_4BIT_TO_8BIT[16] = { 0, 43, 129, 172, 121, 78, 12, 18, 23, 4, 39, 183, 144, 192, 210, 215 };
|
||||||
#endif
|
#endif
|
||||||
@ -814,6 +823,10 @@ unsigned int jswrap_graphics_toColor(JsVar *parent, JsVar *r, JsVar *g, JsVar *b
|
|||||||
}
|
}
|
||||||
if (gfx.data.bpp==16) {
|
if (gfx.data.bpp==16) {
|
||||||
color = (unsigned int)((bi>>3) | (gi>>2)<<5 | (ri>>3)<<11);
|
color = (unsigned int)((bi>>3) | (gi>>2)<<5 | (ri>>3)<<11);
|
||||||
|
#ifdef ESPR_GRAPHICS_12BIT
|
||||||
|
} else if (gfx.data.bpp==12) {
|
||||||
|
color = (unsigned int)((bi>>4) | (gi>>4)<<4 | (ri>>4)<<8);
|
||||||
|
#endif
|
||||||
} else if (gfx.data.bpp==32) {
|
} else if (gfx.data.bpp==32) {
|
||||||
color = 0xFF000000 | (unsigned int)(bi | (gi<<8) | (ri<<16));
|
color = 0xFF000000 | (unsigned int)(bi | (gi<<8) | (ri<<16));
|
||||||
} else if (gfx.data.bpp==24) {
|
} else if (gfx.data.bpp==24) {
|
||||||
@ -1907,32 +1920,17 @@ static bool _jswrap_graphics_parseImage(JsGraphics *gfx, JsVar *image, GfxDrawIm
|
|||||||
info->palettePtr = info->_simplePalette;
|
info->palettePtr = info->_simplePalette;
|
||||||
info->paletteMask = 1;
|
info->paletteMask = 1;
|
||||||
#ifdef GRAPHICS_PALETTED_IMAGES
|
#ifdef GRAPHICS_PALETTED_IMAGES
|
||||||
} else if (gfx->data.bpp==16 && info->bpp==2) { // Blend from bg to fg
|
} else if (gfx->data.bpp>8 && info->bpp==2) { // Blend from bg to fg
|
||||||
unsigned int b = gfx->data.bgColor;
|
|
||||||
unsigned int br = (b>>8)&0xF8;
|
|
||||||
unsigned int bg = (b>>3)&0xFC;
|
|
||||||
unsigned int bb = (b<<3)&0xF8;
|
|
||||||
unsigned int f = gfx->data.fgColor;
|
|
||||||
unsigned int fr = (f>>8)&0xF8;
|
|
||||||
unsigned int fg = (f>>3)&0xFC;
|
|
||||||
unsigned int fb = (f<<3)&0xF8;
|
|
||||||
info->_simplePalette[0] = (uint16_t)gfx->data.bgColor;
|
info->_simplePalette[0] = (uint16_t)gfx->data.bgColor;
|
||||||
unsigned int ri,gi,bi;
|
info->_simplePalette[1] = graphicsBlendColor(gfx, 85);
|
||||||
ri = (br*2 + fr)/3;
|
info->_simplePalette[2] = graphicsBlendColor(gfx, 171);
|
||||||
gi = (bg*2 + fg)/3;
|
|
||||||
bi = (bb*2 + fb)/3;
|
|
||||||
info->_simplePalette[1] = (uint16_t)((bi>>3) | (gi>>2)<<5 | (ri>>3)<<11);
|
|
||||||
ri = (br + fr*2)/3;
|
|
||||||
gi = (bg + fg*2)/3;
|
|
||||||
bi = (bb + fb*2)/3;
|
|
||||||
info->_simplePalette[2] = (uint16_t)((bi>>3) | (gi>>2)<<5 | (ri>>3)<<11);
|
|
||||||
info->_simplePalette[3] = (uint16_t)gfx->data.fgColor;
|
info->_simplePalette[3] = (uint16_t)gfx->data.fgColor;
|
||||||
info->palettePtr = info->_simplePalette;
|
info->palettePtr = info->_simplePalette;
|
||||||
info->paletteMask = 3;
|
info->paletteMask = 3;
|
||||||
} else if (gfx->data.bpp==16 && info->bpp==4) { // palette is 16 bits, so don't use it for other things
|
} else if (gfx->data.bpp==PALETTE_BPP && info->bpp==4) { // palette is 16 bits, so don't use it for other things
|
||||||
info->palettePtr = PALETTE_4BIT;
|
info->palettePtr = PALETTE_4BIT;
|
||||||
info->paletteMask = 15;
|
info->paletteMask = 15;
|
||||||
} else if (gfx->data.bpp==16 && info->bpp==8) { // palette is 16 bits, so don't use it for other things
|
} else if (gfx->data.bpp==PALETTE_BPP && info->bpp==8) { // palette is 16 bits, so don't use it for other things
|
||||||
info->palettePtr = PALETTE_8BIT;
|
info->palettePtr = PALETTE_8BIT;
|
||||||
info->paletteMask = 255;
|
info->paletteMask = 255;
|
||||||
} else if (gfx->data.bpp==8 && info->bpp==4) {
|
} else if (gfx->data.bpp==8 && info->bpp==4) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user