diff --git a/ChangeLog b/ChangeLog index 861636107..c86d85821 100644 --- a/ChangeLog +++ b/ChangeLog @@ -68,6 +68,7 @@ In SAVE_ON_FLASH builds (Microbit 1) remove getSerial, Math.LN*/LOG*SQRT* constants, passwords, Serial/I2C/SPI.find, Date.toUTCString ESP32: add setIP and setAPIP Graphics.wrapString fix issue with missing final char if immediately after a '.' or other char we can split after (#2572) + Graphics: g.dump/asBMP can now output 16 bit images 2v24 : Bangle.js2: Add 'Bangle.touchRd()', 'Bangle.touchWr()' Bangle.js2: After Bangle.showTestScreen, put Bangle.js into a hard off state (not soft off) diff --git a/libs/graphics/jswrap_graphics.c b/libs/graphics/jswrap_graphics.c index 455d23d3c..ee4815dac 100644 --- a/libs/graphics/jswrap_graphics.c +++ b/libs/graphics/jswrap_graphics.c @@ -4145,64 +4145,93 @@ JsVar *jswrap_graphics_asBMP_X(JsVar *parent, bool printBase64) { int rowstride = (((width*bpp)+31) >> 5) << 2; // padded to 32 bits // palette length (byte size is 3x this) int paletteEntries = hasPalette?(1<>8); // plus 2 more bytes for size - imgPtr[10]=(unsigned char)headerLen; - // maybe we want the InfoHeader, not BITMAPCOREHEADER (http://www.ece.ualberta.ca/~elliott/ee552/studentAppNotes/2003_w/misc/bmp_file_format/bmp_file_format.htm) - // Chrome doesn't like 16 bit BMPs in this format - // BITMAPCOREHEADER - imgPtr[14]=12; // sizeof(BITMAPCOREHEADER) + imgPtr[3]=(unsigned char)(fileSize>>8); + imgPtr[4]=(unsigned char)(fileSize>>16); + imgPtr[5]=(unsigned char)(fileSize>>24); + imgPtr[10]=(unsigned char)headerLen; // data offset + // size in here imgPtr[18]=(unsigned char)width; imgPtr[19]=(unsigned char)(width>>8); - imgPtr[20]=(unsigned char)height; - imgPtr[21]=(unsigned char)(height>>8); - imgPtr[22]=1; // color planes, should be 1 - imgPtr[24]=(unsigned char)bpp; // bpp - if (hasPalette) { - // palette starts at 26 - if (bpp==1) { - // first is white(?) - imgPtr[26]=255; - imgPtr[27]=255; - imgPtr[28]=255; - } else { - if (realBPP==3) { - for (int i=0;i>3)&0xFC); - imgPtr[28 + (i*3)] = (unsigned char)((p>>8)&0xF8); - } - } else if (realBPP==8) { - for (int i=0;i<255;i++) { - int p = PALETTE_8BIT[i]; - imgPtr[26 + (i*3)] = (unsigned char)((p<<3)&0xF8); - imgPtr[27 + (i*3)] = (unsigned char)((p>>3)&0xFC); - imgPtr[28 + (i*3)] = (unsigned char)((p>>8)&0xF8); - } -#endif - } else { // otherwise default to greyscale - for (int i=0;i<(1<>8); + imgPtr[h+12]=1; // planes + imgPtr[h+14]=16; // bits + imgPtr[h+16]=3; // compression BI_BITFIELDS + uint32_t size = height*rowstride; + imgPtr[h+20]=(unsigned char)(size); + imgPtr[h+21]=(unsigned char)(size>>8); + imgPtr[h+22]=(unsigned char)(size>>16); + imgPtr[h+23]=(unsigned char)(size>>24); + //imgPtr[h+40]=0x00;//R + imgPtr[h+41]=0xF8; + imgPtr[h+44]=0xE0;//G + imgPtr[h+45]=0x07; + imgPtr[h+48]=0x1F;//B + //imgPtr[h+49]=0x00; + } else { + // BITMAPCOREHEADER + imgPtr[14]=12; // sizeof(BITMAPCOREHEADER) + imgPtr[20]=(unsigned char)height; + imgPtr[21]=(unsigned char)(height>>8); + imgPtr[22]=1; // color planes, should be 1 + imgPtr[24]=(unsigned char)bpp; // bpp + if (hasPalette) { + // palette starts at 26 + if (bpp==1) { + // first is white(?) + imgPtr[26]=255; + imgPtr[27]=255; + imgPtr[28]=255; + } else { + if (realBPP==3) { + for (int i=0;i>3)&0xFC); + imgPtr[28 + (i*3)] = (unsigned char)((p>>8)&0xF8); + } + } else if (realBPP==8) { + for (int i=0;i<255;i++) { + int p = PALETTE_8BIT[i]; + imgPtr[26 + (i*3)] = (unsigned char)((p<<3)&0xF8); + imgPtr[27 + (i*3)] = (unsigned char)((p>>3)&0xFC); + imgPtr[28 + (i*3)] = (unsigned char)((p>>8)&0xF8); + } + #endif + } else { // otherwise default to greyscale + for (int i=0;i<(1<2) { + jshKickWatchDog(); // uploading can take a while bool isLastRow = y==0; int count = isLastRow ? idx : (idx-(idx%3)); JsVar *view = jsvNewArrayBufferFromString(imgData, (unsigned int)count); // create an arraybuffer - this means we can pass to btoa with zero allocations diff --git a/libs/graphics/lcd_fsmc.c b/libs/graphics/lcd_fsmc.c index 17db17532..d5d0d133d 100644 --- a/libs/graphics/lcd_fsmc.c +++ b/libs/graphics/lcd_fsmc.c @@ -1772,7 +1772,8 @@ void lcdFillRect_FSMC(JsGraphics *gfx, int x1, int y1, int x2, int y2, unsigned unsigned int lcdGetPixel_FSMC(JsGraphics *gfx, int x, int y) { lcdSetCursor(gfx,x,y); - lcdSetWrite(); // ? + LCD_WR_REG(0x2E); // start read + LCD_RD_Data(); // dummy read return LCD_RD_Data(); }