RA8875 Library with JPEGDecoder

Hello, I want to use the JPEGDecoder library with the Adafruit RA8875 Library. There are a few things in the jpeg decoding function that are not in the RA8875 Library. I don't know if there is an equivalent for the same function in the RA8875 Library. Here are the lines that are not found in the RA8875 Library:


Does anyone know an equivalent for these two functions in the RA8875 Library? Here is the whole program:

#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include "Adafruit_RA8875.h"
#include "Adafruit_SPIDevice.h"
#include "Adafruit_GFX.h"
#include "JPEGDecoder.h"
#include "SD.h" 

#define RA8875_CS 5
#define RA8875_RESET 4

Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);

#define minimum(a,b)     (((a) < (b)) ? (a) : (b))

void renderJPEG(int xpos, int ypos)

    // retrieve infomration about the image
    uint16_t *pImg;
    uint16_t mcu_w = JpegDec.MCUWidth;
    uint16_t mcu_h = JpegDec.MCUHeight;
    uint32_t max_x = JpegDec.width;
    uint32_t max_y = JpegDec.height;

    // Jpeg images are draw as a set of image block (tiles) called Minimum Coding Units (MCUs)
    // Typically these MCUs are 16x16 pixel blocks
    // Determine the width and height of the right and bottom edge image blocks
    uint32_t min_w = minimum(mcu_w, max_x % mcu_w);
    uint32_t min_h = minimum(mcu_h, max_y % mcu_h);

    // save the current image block size
    uint32_t win_w = mcu_w;
    uint32_t win_h = mcu_h;

    // record the current time so we can measure how long it takes to draw an image
    uint32_t drawTime = millis();

    // save the coordinate of the right and bottom edges to assist image cropping
    // to the screen size
    max_x += xpos;
    max_y += ypos;

    // read each MCU block until there are no more
    while ( JpegDec.read()) {

    // save a pointer to the image block
    pImg = JpegDec.pImage;

    // calculate where the image block should be drawn on the screen
    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
    if (mcu_x + mcu_w <= max_x) win_w = mcu_w;
    else win_w = min_w;
    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;

    // draw image block if it will fit on the screen
    if( ( mcu_x + win_w) <= tft.width() && ( mcu_y + win_h) <= tft.height())
        // open a window onto the screen to paint the pixels into
        //tft.setAddrWindow(mcu_x, mcu_y, mcu_x + win_w - 1, mcu_y + win_h - 1);
        tft.setAddrWindow(mcu_x, mcu_y, mcu_x + win_w - 1, mcu_y + win_h - 1);
        // push all the image block pixels to the screen
        while (mcu_pixels--) tft.pushColor(*pImg++); // Send to TFT 16 bits at a time

        // stop drawing blocks if the bottom of the screen has been reached
        // the abort function will close the file
        else if ( ( mcu_y + win_h) >= tft.height()) JpegDec.abort();


    // calculate how long it took to draw the image
    drawTime = millis() - drawTime; // Calculate the time it took

    // print the results to the serial port
    Serial.print  ("Total render time was    : "); Serial.print(drawTime); Serial.println(" ms");


void setup()

    tft.PWM1config(true, RA8875_PWM_CLK_DIV1024);

        Serial.println("arduino.jpg found on SD card.");
        Serial.println("arduino.jpg not found on SD card.");
        while (1);

void loop()