@@ -111,18 +111,13 @@ void Image::readBmpHeader(uint8_t *buf, bitmapHeader *_h)
111111 {
112112 uint32_t c = READ32 (paletteRGB + (i << 2 ));
113113
114- #if defined(ARDUINO_INKPLATECOLOR)
115- c = c >> 8 ;
116- palette[i >> 1 ] |= findClosestPalette (c) << (i & 1 ? 0 : 4 );
117- ditherPalette[i] = c;
118- #else
114+
119115 uint8_t r = (c & 0xFF000000 ) >> 24 ;
120116 uint8_t g = (c & 0x00FF0000 ) >> 16 ;
121117 uint8_t b = (c & 0x0000FF00 ) >> 8 ;
122118
123119 palette[i >> 1 ] |= RGB3BIT (r, g, b) << (i & 1 ? 0 : 4 );
124120 ditherPalette[i] = RGB8BIT (r, g, b);
125- #endif
126121 }
127122 }
128123};
@@ -327,28 +322,32 @@ void Image::displayBmpLine(int16_t x, int16_t y, bitmapHeader *bmpHeader, bool d
327322 int16_t h = bmpHeader->height ;
328323 int8_t c = bmpHeader->color ;
329324
325+
330326 for (int j = 0 ; j < w; ++j)
331327 {
332328 switch (c)
333329 {
334-
335330 case 1 : {
336-
337331 _inkplate->drawPixel (x + j, (h - y - 1 ),
338- (invert ^ (palette[0 ] > palette[1 ])) ^ !!(pixelBuffer[j >> 3 ] & (1 << (7 - (j & 7 )))));
332+ (invert ^ (palette[0 ] > palette[1 ])) ^ !!(pixelBuffer[j >> 3 ] & (1 << (7 - (j & 7 )))));
333+
339334 break ;
340335 }
341336
342337 case 4 : {
343- uint8_t px = pixelBuffer[j >> 1 ] & (j & 1 ? 0x0F : 0xF0 ) >> (j & 1 ? 0 : 4 );
338+ uint8_t px = ( pixelBuffer[j >> 1 ] & (j & 1 ? 0x0F : 0xF0 ) ) >> (j & 1 ? 0 : 4 );
344339 uint8_t val;
345340
346341 if (dither)
347342 val = ditherGetPixelBmp (px, j, y, w, 1 );
348343 else
349- {
350- val = palette[px >> 1 ] & (px & 1 ? 0x0F : 0xF0 ) >> (px & 1 ? 0 : 4 );
351- }
344+ val = (palette[px >> 1 ] & (px & 1 ? 0x0F : 0xF0 )) >> (px & 1 ? 0 : 4 );
345+
346+ if (invert)
347+ val = val ^ 1 ;
348+
349+ if (_inkplate->getDisplayMode () == INKPLATE_1BIT)
350+ val = (~val >> 2 ) & 1 ;
352351
353352 _inkplate->drawPixel (x + j, (h - y - 1 ), val);
354353 break ;
@@ -361,17 +360,20 @@ void Image::displayBmpLine(int16_t x, int16_t y, bitmapHeader *bmpHeader, bool d
361360 if (dither)
362361 val = ditherGetPixelBmp (px, j, y, w, 1 );
363362 else
364- {
365- val = palette[px >> 1 ] & (px & 1 ? 0x0F : 0xF0 ) >> (px & 1 ? 0 : 4 );
366- }
363+ val = (palette[px >> 1 ] & (px & 1 ? 0x0F : 0xF0 )) >> (px & 1 ? 0 : 4 );
364+
365+ if (invert)
366+ val = val ^ 1 ;
367+
368+ if (_inkplate->getDisplayMode () == INKPLATE_1BIT)
369+ val = (~val >> 2 ) & 1 ;
367370
368371 _inkplate->drawPixel (x + j, (h - y - 1 ), val);
369372 break ;
370373 }
371374
372375 case 16 : {
373376 uint16_t px = ((uint16_t )pixelBuffer[(j << 1 ) | 1 ] << 8 ) | pixelBuffer[(j << 1 )];
374-
375377 uint8_t r = (px & 0x7C00 ) >> 7 ;
376378 uint8_t g = (px & 0x3E0 ) >> 2 ;
377379 uint8_t b = (px & 0x1F ) << 3 ;
@@ -381,15 +383,18 @@ void Image::displayBmpLine(int16_t x, int16_t y, bitmapHeader *bmpHeader, bool d
381383 if (dither)
382384 val = ditherGetPixelBmp (RGB8BIT (r, g, b), j, y, w, 0 );
383385 else
384- {
385386 val = RGB3BIT (r, g, b);
386- }
387387
388- val = RGB3BIT (r, g, b);
388+ if (invert)
389+ val = val ^ 1 ;
390+
391+ if (_inkplate->getDisplayMode () == INKPLATE_1BIT)
392+ val = (~val >> 2 ) & 1 ;
389393
390394 _inkplate->drawPixel (x + j, (h - y - 1 ), val);
391395 break ;
392396 }
397+
393398 case 24 : {
394399 uint32_t b = pixelBuffer[j * 3 ];
395400 uint32_t g = pixelBuffer[j * 3 + 1 ];
@@ -400,12 +405,18 @@ void Image::displayBmpLine(int16_t x, int16_t y, bitmapHeader *bmpHeader, bool d
400405 if (dither)
401406 val = ditherGetPixelBmp (RGB8BIT (r, g, b), j, y, w, 0 );
402407 else
403- {
404408 val = RGB3BIT (r, g, b);
405- }
409+
410+ if (invert)
411+ val = val ^ 1 ;
412+
413+ if (_inkplate->getDisplayMode () == INKPLATE_1BIT)
414+ val = (~val >> 2 ) & 1 ;
415+
406416 _inkplate->drawPixel (x + j, (h - y - 1 ), val);
407417 break ;
408418 }
419+
409420 case 32 : {
410421 uint8_t b = pixelBuffer[j * 4 ];
411422 uint8_t g = pixelBuffer[j * 4 + 1 ];
@@ -414,16 +425,16 @@ void Image::displayBmpLine(int16_t x, int16_t y, bitmapHeader *bmpHeader, bool d
414425 uint8_t val;
415426
416427 if (dither)
417-
418428 val = ditherGetPixelBmp (RGB8BIT (r, g, b), j, y, w, 0 );
419429 else
420- {
421-
422430 val = RGB3BIT (r, g, b);
423- }
424431
425432 if (invert)
426433 val = 7 - val;
434+
435+ if (_inkplate->getDisplayMode () == INKPLATE_1BIT)
436+ val = (~val >> 2 ) & 1 ;
437+
427438 _inkplate->drawPixel (x + j, (h - y - 1 ), val);
428439 break ;
429440 }
@@ -432,6 +443,8 @@ void Image::displayBmpLine(int16_t x, int16_t y, bitmapHeader *bmpHeader, bool d
432443 ditherSwap (w);
433444}
434445
446+
447+
435448/* *
436449 * @brief drawBmpFromWebAtPosition function draws bitmap image from web at
437450 * screen position
0 commit comments