From c00f513be7f87db33dfe7cf8f1a5ca61062390c7 Mon Sep 17 00:00:00 2001 From: philippe44 Date: Wed, 26 Feb 2020 23:48:18 -0800 Subject: [PATCH] forgot a few backports - release --- components/display/core/gds_draw.c | 44 +-------------------------- components/display/core/gds_draw.h | 5 --- components/display/core/gds_image.c | 9 ++++-- components/display/core/gds_private.h | 2 +- 4 files changed, 8 insertions(+), 52 deletions(-) diff --git a/components/display/core/gds_draw.c b/components/display/core/gds_draw.c index f22d1d00..60467a33 100644 --- a/components/display/core/gds_draw.c +++ b/components/display/core/gds_draw.c @@ -268,46 +268,4 @@ void GDS_DrawBitmapCBR(struct GDS_Device* Device, uint8_t *Data, int Width, int } Device->Dirty = true; -} - -/**************************************************************************************** - * Simply draw a RGB565 image - * monoschrome (0.2125 * color.r) + (0.7154 * color.g) + (0.0721 * color.b) - * grayscale (0.3 * R) + (0.59 * G) + (0.11 * B) ) - */ -void GDS_DrawRGB16( struct GDS_Device* Device, int x, int y, int Width, int Height, int RGB_Mode, uint16_t **Image ) { - if (Device->DrawRGB16) { - Device->DrawRGB16( Device, x, y, Width, Height, RGB_Mode, Image ); - } else { - int Scale = Device->Depth < 5 ? 5 - Device->Depth : 0; - switch(RGB_Mode) { - case GDS_RGB565: - for (int c = 0; c < Width; c++) { - for (int r = 0; r < Height; r++) { - int pixel = Image[r][c]; - pixel = ((pixel & 0x1f) * 11 + ((((pixel >> 5) & 0x3f) * 59) >> 1) + (pixel >> 11) * 30) / 100; - GDS_DrawPixel( Device, c + x, r + y, pixel >> Scale); - } - } - break; - case GDS_RGB555: - for (int c = 0; c < Width; c++) { - for (int r = 0; r < Height; r++) { - int pixel = Image[r][c]; - pixel = ((pixel & 0x1f) * 11 + ((pixel >> 5) & 0x1f) * 59 + (pixel >> 10) * 30) / 100; - GDS_DrawPixel( Device, c + x, r + y, pixel >> Scale); - } - } - break; - case GDS_RGB444: - for (int c = 0; c < Width; c++) { - for (int r = 0; r < Height; r++) { - int pixel = Image[r][c]; - pixel = (pixel & 0x0f) * 11 + ((pixel >> 4) & 0x0f) * 59 + (pixel >> 8) * 30; - GDS_DrawPixel( Device, c + x, r + y, pixel >> (Scale - 1)); - } - } - break; - } - } -} +} \ No newline at end of file diff --git a/components/display/core/gds_draw.h b/components/display/core/gds_draw.h index 9daf654a..e98f958c 100644 --- a/components/display/core/gds_draw.h +++ b/components/display/core/gds_draw.h @@ -9,10 +9,6 @@ extern "C" { #endif -struct GDS_Device; - -enum { GDS_RGB565, GDS_RGB555, GDS_RGB444 }; - #ifndef _GDS_PRIVATE_H_ void IRAM_ATTR GDS_DrawPixelFast( struct GDS_Device* Device, int X, int Y, int Color ); void IRAM_ATTR GDS_DrawPixel( struct GDS_Device* Device, int X, int Y, int Color ); @@ -21,7 +17,6 @@ void GDS_DrawHLine( struct GDS_Device* Device, int x, int y, int Width, int Colo void GDS_DrawVLine( struct GDS_Device* Device, int x, int y, int Height, int Color ); void GDS_DrawLine( struct GDS_Device* Device, int x0, int y0, int x1, int y1, int Color ); void GDS_DrawBox( struct GDS_Device* Device, int x1, int y1, int x2, int y2, int Color, bool Fill ); -void GDS_DrawRGB16( struct GDS_Device* Device, int x, int y, int Width, int Height, int RGB_Mode, uint16_t **Image ); // draw a bitmap with source 1-bit depth organized in column and col0 = bit7 of byte 0 void GDS_DrawBitmapCBR( struct GDS_Device* Device, uint8_t *Data, int Width, int Height, int Color); diff --git a/components/display/core/gds_image.c b/components/display/core/gds_image.c index 0500ac1a..e7d4dac7 100644 --- a/components/display/core/gds_image.c +++ b/components/display/core/gds_image.c @@ -90,10 +90,13 @@ static uint16_t* DecodeJPEG(uint8_t *Source, int *Width, int *Height, float Scal Decoder.scale = Scale; if (Res == JDR_OK && !SizeOnly) { - // ready to decode + // find the scaling factor Context.OutData = malloc(Decoder.width * Decoder.height * sizeof(uint16_t)); - uint8_t N = 0, iScale = 1.0 / Scale; - while (iScale >>= 1) N++; + uint8_t N = 0, ScaleInt = ceil(1.0 / Scale); + ScaleInt--; ScaleInt |= ScaleInt >> 1; ScaleInt |= ScaleInt >> 2; ScaleInt++; + while (ScaleInt >>= 1) N++; + + // ready to decode if (Context.OutData) { Context.Width = Decoder.width / (1 << N); Context.Height = Decoder.height / (1 << N); diff --git a/components/display/core/gds_private.h b/components/display/core/gds_private.h index bc883009..60893be5 100644 --- a/components/display/core/gds_private.h +++ b/components/display/core/gds_private.h @@ -105,7 +105,7 @@ struct GDS_Device { void (*DrawPixelFast)( struct GDS_Device* Device, int X, int Y, int Color ); void (*DrawBitmapCBR)(struct GDS_Device* Device, uint8_t *Data, int Width, int Height, int Color ); // may provide for optimization - void (*DrawRGB16)( struct GDS_Device* Device, int x, int y, int Width, int Height, int RGB_Mode, uint16_t **Image ); + void (*DrawRGB16)( struct GDS_Device* Device, int x, int y, int Width, int Height, int RGB_Mode, uint16_t *Image ); void (*ClearWindow)( struct GDS_Device* Device, int x1, int y1, int x2, int y2, int Color ); // interface-specific methods