From 647a19c4c4481267a832daf0e6cc59441324881f Mon Sep 17 00:00:00 2001 From: Thomas Ballmann Date: Sat, 26 Dec 2020 11:39:49 +0100 Subject: [PATCH] #54 refactor image decoder --- lib/image/{imageJPEG.cpp => format/JPEG.cpp} | 16 +++------------- lib/image/{imageJPEG.h => format/JPEG.h} | 2 -- lib/image/{imagePNG.cpp => format/PNG.cpp} | 3 +-- lib/image/{imagePNG.h => format/PNG.h} | 0 lib/image/image.cpp | 10 ++++++---- 5 files changed, 10 insertions(+), 21 deletions(-) rename lib/image/{imageJPEG.cpp => format/JPEG.cpp} (92%) rename lib/image/{imageJPEG.h => format/JPEG.h} (75%) rename lib/image/{imagePNG.cpp => format/PNG.cpp} (94%) rename lib/image/{imagePNG.h => format/PNG.h} (100%) diff --git a/lib/image/imageJPEG.cpp b/lib/image/format/JPEG.cpp similarity index 92% rename from lib/image/imageJPEG.cpp rename to lib/image/format/JPEG.cpp index cbac16c..ab08ea2 100644 --- a/lib/image/imageJPEG.cpp +++ b/lib/image/format/JPEG.cpp @@ -1,7 +1,7 @@ #include #include #include -#include "imageJPEG.h" +#include "JPEG.h" #include "display.h" File tmpFileBuffer; @@ -13,11 +13,6 @@ int16_t *blockDelta; uint16_t displayWidth; uint16_t blockDeltaSize; -// TODO uint32_t auf uint16_t ändern um speicher zu sparen -// https://os.mbed.com/handbook/C-Data-Types#integer-data-types -// image size limit prüfen damit alles in ein int16_t passt ! -// dann ist genug speicher da :D - #define minimum(a, b) (((a) < (b)) ? (a) : (b)) void setupImageJPEG() @@ -28,14 +23,10 @@ void setupImageJPEG() displayWidth = displayGetWidth(); blockDeltaSize = BLOCK_SIZE * displayWidth + 1; blockDelta = new int16_t[blockDeltaSize]; - - Serial.println(sizeof(blockDelta[0]) * blockDeltaSize); } void jpegOpenFramebuffer() { - displayOpen(); - SPIFFS.remove("/tmp.jpeg"); tmpFileBuffer = SPIFFS.open("/tmp.jpeg", FILE_WRITE); @@ -171,10 +162,9 @@ void jpegFlushFramebuffer() // print information about the image to the serial port //jpegInfo(); - // TODO use display size - if (JpegDec.width > 800 || JpegDec.height > 480) + if (JpegDec.width > displayGetWidth() || JpegDec.height > displayGetHeight()) { - Serial.println("image to big! skip rendering"); + Serial.println("image resolution to big! skip rendering"); } else { diff --git a/lib/image/imageJPEG.h b/lib/image/format/JPEG.h similarity index 75% rename from lib/image/imageJPEG.h rename to lib/image/format/JPEG.h index 449d0c1..1369689 100644 --- a/lib/image/imageJPEG.h +++ b/lib/image/format/JPEG.h @@ -4,9 +4,7 @@ #include "image.h" extern structImageProcess ImageProcess; -// @see http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html const char ImageHeaderJPEG[] = "\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46\x00"; -// FF E0 00 10 4A 46 , 49 46 00 void setupImageJPEG(); void jpegOpenFramebuffer(); diff --git a/lib/image/imagePNG.cpp b/lib/image/format/PNG.cpp similarity index 94% rename from lib/image/imagePNG.cpp rename to lib/image/format/PNG.cpp index 718e05d..aabbbe5 100644 --- a/lib/image/imagePNG.cpp +++ b/lib/image/format/PNG.cpp @@ -1,5 +1,5 @@ #include -#include "imagePNG.h" +#include "PNG.h" #include "pngle.h" #include "display.h" @@ -20,7 +20,6 @@ void setupImagePNG() void pngOpenFramebuffer() { - displayOpen(); pngle_reset(pngle); } diff --git a/lib/image/imagePNG.h b/lib/image/format/PNG.h similarity index 100% rename from lib/image/imagePNG.h rename to lib/image/format/PNG.h diff --git a/lib/image/image.cpp b/lib/image/image.cpp index b831cb6..4e5272a 100644 --- a/lib/image/image.cpp +++ b/lib/image/image.cpp @@ -1,6 +1,6 @@ #include "image.h" -#include "imagePNG.h" -#include "imageJPEG.h" +#include "format/JPEG.h" +#include "format/PNG.h" #include "display.h" structImageProcess ImageProcess; @@ -18,6 +18,7 @@ void setupImage() ditheringNextRowDelta = new int16_t[ditheringBufferSize]; setupImageJPEG(); + //setupImagePNG(); } void ImageNew(int x, int y, int w, int h, bool dithering) @@ -39,7 +40,7 @@ void ImageWriteBuffer(uint8_t buff[], size_t c) // initial detect format if (ImageProcess.format == 0) { - if (memcmp(buff, ImageHeaderPNG, sizeof(ImageHeaderPNG) - 1) == 0) + if (memcmp(buff, ImageHeaderPNG, sizeof(ImageHeaderPNG) - 1) == 0 && false) { Serial.println(" image format: PNG"); ImageProcess.format = 3; @@ -151,5 +152,6 @@ void ImageProcessPixel(uint16_t x, uint16_t y, uint8_t rgba[4]) } } - displayWritePixel(ImageProcess.x + x, ImageProcess.y + y, blackOrWhite); + GFXcanvas1 *displayCanvas; + displayCanvas->drawPixel(ImageProcess.x + x, ImageProcess.y + y, (uint16_t)blackOrWhite); } \ No newline at end of file