Skip to content

Commit 6a0912b

Browse files
committed
Update for Adafruit_GFX setAddrWindow() parameter change
1 parent 3445d2f commit 6a0912b

File tree

6 files changed

+31
-21
lines changed

6 files changed

+31
-21
lines changed

examples/Adafruit_GFX/Huzzah_Jpeg/Huzzah_Jpeg.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void setup()
108108
void loop()
109109
{
110110
// Note the / before the SPIFFS file name must be present, this means the file is in
111-
// the root directory of the SPIFFS, e.g. "/Tiger.rjpg" for a file called "Tiger.jpg"
111+
// the root directory of the SPIFFS, e.g. "/Tiger.jpg" for a file called "Tiger.jpg"
112112

113113
tft.setRotation(0); // portrait
114114
tft.fillScreen(random(0xFFFF));

examples/Adafruit_GFX/Huzzah_Jpeg/JPEG_functions.ino

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,28 @@ void jpegRender(int xpos, int ypos) {
8282
int mcu_x = JpegDec.MCUx * mcu_w + xpos;
8383
int mcu_y = JpegDec.MCUy * mcu_h + ypos;
8484

85-
// check if the image block size needs to be changed for the right and bottom edges
85+
// check if the image block size needs to be changed for the right edge
8686
if (mcu_x + mcu_w <= max_x) win_w = mcu_w;
8787
else win_w = min_w;
88+
89+
// check if the image block size needs to be changed for the bottom edge
8890
if (mcu_y + mcu_h <= max_y) win_h = mcu_h;
8991
else win_h = min_h;
9092

91-
// calculate how many pixels must be drawn
92-
uint32_t mcu_pixels = win_w * win_h;
93+
// copy pixels into a contiguous block
94+
if (win_w != mcu_w)
95+
{
96+
for (int h = 1; h < win_h-1; h++)
97+
{
98+
memcpy(pImg + h * win_w, pImg + (h + 1) * mcu_w, win_w << 1);
99+
}
100+
}
101+
93102

94103
// draw image MCU block only if it will fit on the screen
95104
if ( ( mcu_x + win_w) <= tft.width() && ( mcu_y + win_h) <= tft.height())
96-
{
97-
// Now set a MCU bounding window on the TFT to push pixels into (x, y, x + width - 1, y + height - 1)
98-
tft.setAddrWindow(mcu_x, mcu_y, mcu_x + win_w - 1, mcu_y + win_h - 1);
99-
100-
// Write all MCU pixels to the TFT window
101-
while (mcu_pixels--) tft.pushColor(*pImg++); // Send MCU buffer to TFT 16 bits at a time
105+
{
106+
tft.drawRGBBitmap(mcu_x, mcu_y, pImg, win_w, win_h);
102107
}
103108

104109
// Stop drawing blocks if the bottom of the screen has been reached,

examples/Adafruit_GFX/NodeMCU_Jpeg/JPEG_functions.ino

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,27 @@ void jpegRender(int xpos, int ypos) {
8282
int mcu_x = JpegDec.MCUx * mcu_w + xpos;
8383
int mcu_y = JpegDec.MCUy * mcu_h + ypos;
8484

85-
// check if the image block size needs to be changed for the right and bottom edges
85+
// check if the image block size needs to be changed for the right edge
8686
if (mcu_x + mcu_w <= max_x) win_w = mcu_w;
8787
else win_w = min_w;
88+
89+
// check if the image block size needs to be changed for the bottom edge
8890
if (mcu_y + mcu_h <= max_y) win_h = mcu_h;
8991
else win_h = min_h;
9092

91-
// calculate how many pixels must be drawn
92-
uint32_t mcu_pixels = win_w * win_h;
93+
// copy pixels into a contiguous block
94+
if (win_w != mcu_w)
95+
{
96+
for (int h = 1; h < win_h-1; h++)
97+
{
98+
memcpy(pImg + h * win_w, pImg + (h + 1) * mcu_w, win_w << 1);
99+
}
100+
}
93101

94102
// draw image MCU block only if it will fit on the screen
95103
if ( ( mcu_x + win_w) <= tft.width() && ( mcu_y + win_h) <= tft.height())
96-
{
97-
// Now set a MCU bounding window on the TFT to push pixels into (x, y, x + width - 1, y + height - 1)
98-
tft.setAddrWindow(mcu_x, mcu_y, mcu_x + win_w - 1, mcu_y + win_h - 1);
99-
// Write all MCU pixels to the TFT window
100-
while (mcu_pixels--) tft.pushColor(*pImg++);
104+
{
105+
tft.drawRGBBitmap(mcu_x, mcu_y, pImg, win_w, win_h);
101106
}
102107

103108
else if ( ( mcu_y + win_h) >= tft.height()) JpegDec.abort();

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "JPEGDecoder",
3-
"version": "1.7.9",
3+
"version": "1.8.0",
44
"keywords": "jpeg, jpg, decoder, TFT",
55
"description": "A JPEG decoder library, tested on Mega, Due and ESP8266",
66
"repository":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=JPEGDecoder
2-
version=1.7.9
2+
version=1.8.0
33
author=Bodmer <bodmer@anola.net>, Makoto Kurauchi, Rich Geldreich
44
maintainer=Bodmer
55
sentence= Jpeg decoder tested with Arduino Mega, Arduino Due and ESP8266 based NodeMCU 1.0

src/JPEGDecoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ uint8_t JPEGDecoder::pjpeg_callback(uint8_t* pBuf, uint8_t buf_size, uint8_t *pB
6565
uint8_t JPEGDecoder::pjpeg_need_bytes_callback(uint8_t* pBuf, uint8_t buf_size, uint8_t *pBytes_actually_read, void *pCallback_data) {
6666
uint n;
6767

68-
pCallback_data;
68+
//pCallback_data;
6969

7070
n = jpg_min(g_nInFileSize - g_nInFileOfs, buf_size);
7171

0 commit comments

Comments
 (0)