Skip to content

Commit

Permalink
Update for Adafruit_GFX setAddrWindow() parameter change
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodmer committed Feb 9, 2019
1 parent 3445d2f commit 6a0912b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/Adafruit_GFX/Huzzah_Jpeg/Huzzah_Jpeg.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
23 changes: 14 additions & 9 deletions examples/Adafruit_GFX/Huzzah_Jpeg/JPEG_functions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 13 additions & 8 deletions examples/Adafruit_GFX/NodeMCU_Jpeg/JPEG_functions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -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":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=JPEGDecoder
version=1.7.9
version=1.8.0
author=Bodmer <[email protected]>, Makoto Kurauchi, Rich Geldreich
maintainer=Bodmer
sentence= Jpeg decoder tested with Arduino Mega, Arduino Due and ESP8266 based NodeMCU 1.0
Expand Down
2 changes: 1 addition & 1 deletion src/JPEGDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6a0912b

Please sign in to comment.