@@ -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,
0 commit comments