From 9be4593d81fd37bc72fb8e3726f8bda669717556 Mon Sep 17 00:00:00 2001 From: philippe44 Date: Mon, 12 Sep 2022 14:16:02 -0700 Subject: [PATCH] Tweak for JPEG - release --- components/display/core/gds_image.c | 6 +++++- components/squeezelite/displayer.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/components/display/core/gds_image.c b/components/display/core/gds_image.c index f47e3383..1302301c 100644 --- a/components/display/core/gds_image.c +++ b/components/display/core/gds_image.c @@ -24,6 +24,7 @@ typedef struct { const unsigned char *InData; // Pointer to jpeg data int InPos; // Current position in jpeg data int Width, Height; + uint32_t Pixels; uint8_t Mode; union { void *OutData; @@ -142,6 +143,8 @@ static unsigned OutHandlerDirect(JDEC *Decoder, void *Bitmap, JRECT *Frame) { JpegCtx *Context = (JpegCtx*) Decoder->device; uint8_t *Pixels = (uint8_t*) Bitmap; int Shift = 8 - Context->Depth; + + Context->Pixels += (Frame->bottom - Frame->top + 1) * (Frame->right - Frame->left + 1); \ // decoded image is RGB888, shift only make sense for grayscale if (Context->Mode == GDS_RGB888) { @@ -418,10 +421,11 @@ bool GDS_DrawJPEG(struct GDS_Device* Device, uint8_t *Source, int x, int y, int Context.XMin = x - Context.XOfs; Context.YMin = y - Context.YOfs; Context.Mode = Device->Mode; + Context.Pixels = 0; // do decompress & draw Res = jd_decomp(&Decoder, OutHandlerDirect, N); - if (Res == JDR_OK) { + if (Res == JDR_OK && Context.Pixels == Context.Width * Context.Height) { Device->Dirty = true; Ret = true; } else { diff --git a/components/squeezelite/displayer.c b/components/squeezelite/displayer.c index 23a425ee..c77ca426 100644 --- a/components/squeezelite/displayer.c +++ b/components/squeezelite/displayer.c @@ -891,7 +891,11 @@ static void grfa_handler(u8_t *data, int len) { artwork.size += size; if (artwork.size == length) { GDS_ClearWindow(display, artwork.x, artwork.y, -1, -1, GDS_COLOR_BLACK); - GDS_DrawJPEG(display, artwork.data, artwork.x, artwork.y, artwork.y < displayer.height ? (GDS_IMAGE_RIGHT | GDS_IMAGE_TOP) : GDS_IMAGE_CENTER); + xSemaphoreTake(displayer.mutex, portMAX_DELAY); + for (int i = 0; i < 2 && !GDS_DrawJPEG(display, artwork.data, artwork.x, artwork.y, artwork.y < displayer.height ? (GDS_IMAGE_RIGHT | GDS_IMAGE_TOP) : GDS_IMAGE_CENTER); i++) { + LOG_WARN("JPEG decoding error, pass %d", i+1); + } + xSemaphoreGive(displayer.mutex); free(artwork.data); artwork.data = NULL; }