diff --git a/examples/Adafruit_GFX/Huzzah_Jpeg/Huzzah_Jpeg.ino b/examples/Adafruit_GFX/Huzzah_Jpeg/Huzzah_Jpeg.ino index ff8645f..cdde42e 100644 --- a/examples/Adafruit_GFX/Huzzah_Jpeg/Huzzah_Jpeg.ino +++ b/examples/Adafruit_GFX/Huzzah_Jpeg/Huzzah_Jpeg.ino @@ -108,7 +108,7 @@ void setup() void loop() { // Note the / before the SPIFFS file name must be present, this means the file is in - // the root directory of the SPIFFS, e.g. "/Tiger.rjpg" for a file called "Tiger.jpg" + // the root directory of the SPIFFS, e.g. "/Tiger.jpg" for a file called "Tiger.jpg" tft.setRotation(0); // portrait tft.fillScreen(random(0xFFFF)); diff --git a/examples/Adafruit_GFX/Huzzah_Jpeg/JPEG_functions.ino b/examples/Adafruit_GFX/Huzzah_Jpeg/JPEG_functions.ino index ebab0fa..e49a04d 100644 --- a/examples/Adafruit_GFX/Huzzah_Jpeg/JPEG_functions.ino +++ b/examples/Adafruit_GFX/Huzzah_Jpeg/JPEG_functions.ino @@ -82,23 +82,28 @@ void jpegRender(int xpos, int ypos) { int mcu_x = JpegDec.MCUx * mcu_w + xpos; int mcu_y = JpegDec.MCUy * mcu_h + ypos; - // check if the image block size needs to be changed for the right and bottom edges + // check if the image block size needs to be changed for the right edge if (mcu_x + mcu_w <= max_x) win_w = mcu_w; else win_w = min_w; + + // check if the image block size needs to be changed for the bottom edge if (mcu_y + mcu_h <= max_y) win_h = mcu_h; else win_h = min_h; - // calculate how many pixels must be drawn - uint32_t mcu_pixels = win_w * win_h; + // copy pixels into a contiguous block + if (win_w != mcu_w) + { + for (int h = 1; h < win_h-1; h++) + { + memcpy(pImg + h * win_w, pImg + (h + 1) * mcu_w, win_w << 1); + } + } + // draw image MCU block only if it will fit on the screen if ( ( mcu_x + win_w) <= tft.width() && ( mcu_y + win_h) <= tft.height()) - { - // Now set a MCU bounding window on the TFT to push pixels into (x, y, x + width - 1, y + height - 1) - tft.setAddrWindow(mcu_x, mcu_y, mcu_x + win_w - 1, mcu_y + win_h - 1); - - // Write all MCU pixels to the TFT window - while (mcu_pixels--) tft.pushColor(*pImg++); // Send MCU buffer to TFT 16 bits at a time + { + tft.drawRGBBitmap(mcu_x, mcu_y, pImg, win_w, win_h); } // Stop drawing blocks if the bottom of the screen has been reached, diff --git a/examples/Adafruit_GFX/NodeMCU_Jpeg/JPEG_functions.ino b/examples/Adafruit_GFX/NodeMCU_Jpeg/JPEG_functions.ino index d51c6c1..6d3d09c 100644 --- a/examples/Adafruit_GFX/NodeMCU_Jpeg/JPEG_functions.ino +++ b/examples/Adafruit_GFX/NodeMCU_Jpeg/JPEG_functions.ino @@ -82,22 +82,27 @@ void jpegRender(int xpos, int ypos) { int mcu_x = JpegDec.MCUx * mcu_w + xpos; int mcu_y = JpegDec.MCUy * mcu_h + ypos; - // check if the image block size needs to be changed for the right and bottom edges + // check if the image block size needs to be changed for the right edge if (mcu_x + mcu_w <= max_x) win_w = mcu_w; else win_w = min_w; + + // check if the image block size needs to be changed for the bottom edge if (mcu_y + mcu_h <= max_y) win_h = mcu_h; else win_h = min_h; - // calculate how many pixels must be drawn - uint32_t mcu_pixels = win_w * win_h; + // copy pixels into a contiguous block + if (win_w != mcu_w) + { + for (int h = 1; h < win_h-1; h++) + { + memcpy(pImg + h * win_w, pImg + (h + 1) * mcu_w, win_w << 1); + } + } // draw image MCU block only if it will fit on the screen if ( ( mcu_x + win_w) <= tft.width() && ( mcu_y + win_h) <= tft.height()) - { - // Now set a MCU bounding window on the TFT to push pixels into (x, y, x + width - 1, y + height - 1) - tft.setAddrWindow(mcu_x, mcu_y, mcu_x + win_w - 1, mcu_y + win_h - 1); - // Write all MCU pixels to the TFT window - while (mcu_pixels--) tft.pushColor(*pImg++); + { + tft.drawRGBBitmap(mcu_x, mcu_y, pImg, win_w, win_h); } else if ( ( mcu_y + win_h) >= tft.height()) JpegDec.abort(); diff --git a/library.json b/library.json index 5729223..169fef2 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "JPEGDecoder", - "version": "1.7.9", + "version": "1.8.0", "keywords": "jpeg, jpg, decoder, TFT", "description": "A JPEG decoder library, tested on Mega, Due and ESP8266", "repository": diff --git a/library.properties b/library.properties index a9ed9a7..fd9046f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=JPEGDecoder -version=1.7.9 +version=1.8.0 author=Bodmer , Makoto Kurauchi, Rich Geldreich maintainer=Bodmer sentence= Jpeg decoder tested with Arduino Mega, Arduino Due and ESP8266 based NodeMCU 1.0 diff --git a/src/JPEGDecoder.cpp b/src/JPEGDecoder.cpp index 3abf8f1..c2d91d2 100644 --- a/src/JPEGDecoder.cpp +++ b/src/JPEGDecoder.cpp @@ -65,7 +65,7 @@ uint8_t JPEGDecoder::pjpeg_callback(uint8_t* pBuf, uint8_t buf_size, uint8_t *pB uint8_t JPEGDecoder::pjpeg_need_bytes_callback(uint8_t* pBuf, uint8_t buf_size, uint8_t *pBytes_actually_read, void *pCallback_data) { uint n; - pCallback_data; + //pCallback_data; n = jpg_min(g_nInFileSize - g_nInFileOfs, buf_size);