### Implement File Close Callback Source: https://github.com/bitbank2/jpegdec/wiki/Home Example implementation of a file close callback using static_cast to convert a void pointer back to a File class instance for the Arduino SD library. ```C++ void JPEGCloseFile(void *pHandle) { File *f = static_cast(pHandle); if (f != NULL) f->close(); } ``` -------------------------------- ### Getting JPEG Image Information (C++) Source: https://context7.com/bitbank2/jpegdec/llms.txt Shows how to extract metadata from a JPEG image after opening it with `openRAM()` or `openFLASH()`. Provides access to dimensions, bits per pixel, subsampling, orientation, JPEG type, and error codes via getter methods. ```cpp #include JPEGDEC jpeg; // Error messages const char *errorMessages[] = { "Success", "Invalid parameter", "Decode error", "Unsupported feature", "Invalid file", "Memory error" }; void analyzeJPEG(uint8_t *data, int size) { if (jpeg.openRAM(data, size, NULL)) { // NULL callback for info only Serial.println("=== JPEG Image Info ==="); Serial.printf("Dimensions: %d x %d pixels\n", jpeg.getWidth(), jpeg.getHeight()); Serial.printf("Bits per pixel: %d\n", jpeg.getBpp()); Serial.printf("Color subsampling: 0x%02x\n", jpeg.getSubSample()); Serial.printf("Orientation: %d\n", jpeg.getOrientation()); Serial.printf("JPEG type: %s\n", jpeg.getJPEGType() == JPEG_MODE_PROGRESSIVE ? "Progressive" : "Baseline"); if (jpeg.hasThumb()) { Serial.printf("Thumbnail: %d x %d\n", jpeg.getThumbWidth(), jpeg.getThumbHeight()); } else { Serial.println("No embedded thumbnail"); } jpeg.close(); } else { int err = jpeg.getLastError(); Serial.printf("Failed to open: %s (error %d)\n", errorMessages[err], err); } } ``` -------------------------------- ### Open JPEG from FLASH Memory Source: https://github.com/bitbank2/jpegdec/blob/master/examples/M5Stack/README.md Opens a JPEG image from FLASH memory for decoding. This snippet demonstrates how to load JPEG data from a byte array stored in FLASH memory and initiate the decoding process using the JPEGDraw callback function. It includes commented-out examples for different image files. ```C++ if (jpeg.openFLASH((uint8_t *)thumb_test, sizeof(thumb_test), JPEGDraw)) //if (jpeg.openFLASH((uint8_t *)ncc1701, sizeof(ncc1701), JPEGDraw)) //if (jpeg.openFLASH((uint8_t *)batman, sizeof(batman), JPEGDraw)) ``` -------------------------------- ### JPEGDEC Initialization Methods Source: https://github.com/bitbank2/jpegdec/wiki/Home Methods to initialize the JPEG decoder using different data sources. ```APIDOC ## OPEN [openRAM, openFLASH, open] ### Description Initializes the JPEG decoder with image data from RAM, FLASH, or a file stream. Returns 1 on success, 0 on failure. ### Parameters #### Request Body - **pData** (uint8_t*) - Required for RAM/FLASH - Pointer to image data - **iDataSize** (int) - Required for RAM/FLASH - Size of data in bytes - **szFilename** (char*) - Required for open() - Path to the file - **pfnDraw** (JPEG_DRAW_CALLBACK*) - Required - Callback function for drawing pixels ### Response - **Success** (int) - 1 if successful, 0 otherwise. ``` -------------------------------- ### Decode JPEG from File System Source: https://context7.com/bitbank2/jpegdec/llms.txt Illustrates how to use custom file I/O callbacks to decode JPEG images from storage media like SD cards or SPIFFS. ```cpp #include #include JPEGDEC jpeg; File jpegFile; void *myOpen(const char *filename, int32_t *size) { jpegFile = SD.open(filename); if (jpegFile) { *size = jpegFile.size(); return &jpegFile; } return NULL; } void myClose(void *handle) { if (jpegFile) jpegFile.close(); } int32_t myRead(JPEGFILE *handle, uint8_t *buffer, int32_t length) { return ((File *)handle->fHandle)->read(buffer, length); } int32_t mySeek(JPEGFILE *handle, int32_t position) { return ((File *)handle->fHandle)->seek(position); } int JPEGDraw(JPEGDRAW *pDraw) { tft.drawRGBBitmap(pDraw->x, pDraw->y, pDraw->pPixels, pDraw->iWidth, pDraw->iHeight); return 1; } void displayFromSD(const char *filename) { if (jpeg.open(filename, myOpen, myClose, myRead, mySeek, JPEGDraw)) { jpeg.decode(0, 0, 0); jpeg.close(); } } ``` -------------------------------- ### JPEGDEC Configuration Methods Source: https://github.com/bitbank2/jpegdec/wiki/Home Shows how to configure the JPEGDEC decoder's behavior, including setting the pixel output format, maximum output size per draw call, and defining a crop area for decoding. ```C++ void setPixelType(int iPixelType); void setMaxOutputSize(int iMCUs); void setCropArea(int x, int y, int w, int h); ``` -------------------------------- ### JPEGDEC Open Methods Source: https://github.com/bitbank2/jpegdec/wiki/Home Demonstrates the different ways to open a JPEG image using the JPEGDEC class: from RAM, from FLASH, or from a file. These methods initialize the decoder and parse image header information. ```C++ int openRAM(uint8_t *pData, int iDataSize, JPEG_DRAW_CALLBACK *pfnDraw); int openFLASH(uint8_t *pData, int iDataSize, JPEG_DRAW_CALLBACK *pfnDraw); int open(char *szFilename, JPEG_OPEN_CALLBACK *pfnOpen, JPEG_CLOSE_CALLBACK *pfnClose, JPEG_READ_CALLBACK *pfnRead, JPEG_SEEK_CALLBACK *pfnSeek, JPEG_DRAW_CALLBACK *pfnDraw); ``` -------------------------------- ### Pure C API for JPEG Decoding Source: https://context7.com/bitbank2/jpegdec/llms.txt Illustrates using the JPEGDEC library in a pure C environment without Arduino specifics. It includes opening a JPEG from a file, setting up a framebuffer, and decoding the image using C-style functions prefixed with `JPEG_`. ```c #include #include #include #include "JPEGDEC.h" #include "jpeg.inl" JPEGIMAGE jpg; uint8_t *frameBuffer; int bufferPitch; int JPEGDraw(JPEGDRAW *pDraw) { for (int y = 0; y < pDraw->iHeight; y++) { uint16_t *src = &pDraw->pPixels[y * pDraw->iWidth]; uint16_t *dst = (uint16_t *)&frameBuffer[(pDraw->y + y) * bufferPitch + pDraw->x * 2]; memcpy(dst, src, pDraw->iWidth * 2); } return 1; } int main(int argc, char *argv[]) { int rc; // Open from file (Linux) rc = JPEG_openFile(&jpg, "input.jpg", JPEGDraw); if (!rc) { printf("Error: %d\n", JPEG_getLastError(&jpg)); return -1; } printf("Image: %d x %d\n", JPEG_getWidth(&jpg), JPEG_getHeight(&jpg)); // Allocate framebuffer bufferPitch = jpg.iWidth * 2; frameBuffer = (uint8_t *)malloc(bufferPitch * jpg.iHeight); // Decode with optional scaling JPEG_setFramebuffer(&jpg, frameBuffer); jpg.ucPixelType = RGB565_LITTLE_ENDIAN; if (JPEG_decode(&jpg, 0, 0, JPEG_SCALE_HALF)) { printf("Decoded successfully\n"); } JPEG_close(&jpg); free(frameBuffer); return 0; } ``` -------------------------------- ### Setting Maximum Output Size per Callback in C++ Source: https://context7.com/bitbank2/jpegdec/llms.txt Shows how to use `setMaxOutputSize()` to control the number of MCUs (Minimum Coded Units) processed in each draw callback. This is useful for managing memory usage and synchronizing with display hardware like DMA buffers. ```cpp #include JPEGDEC jpeg; int JPEGDraw(JPEGDRAW *pDraw) { // With setMaxOutputSize(1), each callback receives exactly 1 MCU // MCU size depends on subsampling: 8x8, 16x8, 8x16, or 16x16 pixels Serial.printf("Block at (%d,%d) size %dx%d\n", pDraw->x, pDraw->y, pDraw->iWidth, pDraw->iHeight); lcd.setAddrWindow(pDraw->x, pDraw->y, pDraw->iWidth, pDraw->iHeight); lcd.pushPixels(pDraw->pPixels, pDraw->iWidth * pDraw->iHeight); return 1; } void setup() { if (jpeg.openFLASH((uint8_t *)image, sizeof(image), JPEGDraw)) { // Limit to 4 MCUs per callback (useful for limited DMA buffers) jpeg.setMaxOutputSize(4); jpeg.decode(0, 0, 0); jpeg.close(); } } ``` -------------------------------- ### Define File System Callback Prototypes Source: https://github.com/bitbank2/jpegdec/wiki/Home Defines the function prototypes required for handling file operations (open, close, read, seek) when decoding JPEG images from a file system. ```C typedef void * (JPEG_OPEN_CALLBACK)(char *szFilename, int32_t *pFileSize); typedef void (JPEG_CLOSE_CALLBACK)(void *pHandle); typedef int32_t (JPEG_READ_CALLBACK)(JPEGFILE *pFile, uint8_t *pBuf, int32_t iLen); typedef int32_t (JPEG_SEEK_CALLBACK)(JPEGFILE *pFile, int32_t iPosition); ``` -------------------------------- ### Configure JPEG Pixel Output Format Source: https://context7.com/bitbank2/jpegdec/llms.txt Shows how to set the output pixel format using setPixelType. This must be called after opening the JPEG file and before decoding to ensure the data format matches the display requirements. ```cpp #include JPEGDEC jpeg; int JPEGDraw(JPEGDRAW *pDraw) { lcd.pushPixels(pDraw->pPixels, pDraw->iWidth * pDraw->iHeight); return 1; } void setup() { if (jpeg.openFLASH((uint8_t *)image, sizeof(image), JPEGDraw)) { jpeg.setPixelType(RGB565_BIG_ENDIAN); jpeg.decode(0, 0, 0); jpeg.close(); } } ``` -------------------------------- ### Perform Efficient JPEG Downscaling Source: https://context7.com/bitbank2/jpegdec/llms.txt Demonstrates how to use JPEG_SCALE constants to downscale images during the decoding process. This is highly efficient for fitting large images onto smaller displays by scaling during the DCT phase. ```cpp #include #include "large_photo.h" JPEGDEC jpeg; int JPEGDraw(JPEGDRAW *pDraw) { lcd.setAddrWindow(pDraw->x, pDraw->y, pDraw->iWidth, pDraw->iHeight); lcd.pushPixels(pDraw->pPixels, pDraw->iWidth * pDraw->iHeight); return 1; } void displayScaled() { if (jpeg.openFLASH((uint8_t *)large_photo, sizeof(large_photo), JPEGDraw)) { int w = jpeg.getWidth(); int h = jpeg.getHeight(); int options = 0; if (w > lcd.width() * 4 || h > lcd.height() * 4) { options = JPEG_SCALE_EIGHTH; w /= 8; h /= 8; } else if (w > lcd.width() * 2 || h > lcd.height() * 2) { options = JPEG_SCALE_QUARTER; w /= 4; h /= 4; } else if (w > lcd.width() || h > lcd.height()) { options = JPEG_SCALE_HALF; w /= 2; h /= 2; } int xoff = (lcd.width() - w) / 2; int yoff = (lcd.height() - h) / 2; jpeg.setPixelType(RGB565_BIG_ENDIAN); jpeg.decode(xoff, yoff, options); jpeg.close(); } } ``` -------------------------------- ### Using User Pointer for Context in C++ Source: https://context7.com/bitbank2/jpegdec/llms.txt Demonstrates passing custom data (like display handles or framebuffers) to the draw callback using `setUserPointer()`. The `pUser` field in `JPEGDRAW` provides access to this context, enabling dynamic rendering based on external data. ```cpp #include JPEGDEC jpeg; // Custom context structure typedef struct { void *displayHandle; int offsetX; int offsetY; uint8_t *frameBuffer; int bufferPitch; } DrawContext; int JPEGDraw(JPEGDRAW *pDraw) { DrawContext *ctx = (DrawContext *)pDraw->pUser; // Use context to access display or buffer int destX = pDraw->x + ctx->offsetX; int destY = pDraw->y + ctx->offsetY; // Copy pixels to framebuffer for (int y = 0; y < pDraw->iHeight; y++) { uint16_t *src = &pDraw->pPixels[y * pDraw->iWidth]; uint16_t *dst = (uint16_t *)&ctx->frameBuffer[(destY + y) * ctx->bufferPitch + destX * 2]; memcpy(dst, src, pDraw->iWidth * 2); } return 1; } void decodeWithContext() { DrawContext ctx; ctx.offsetX = 10; ctx.offsetY = 20; ctx.frameBuffer = displayBuffer; // Assuming displayBuffer is globally defined ctx.bufferPitch = SCREEN_WIDTH * 2; // Assuming SCREEN_WIDTH is globally defined if (jpeg.openFLASH((uint8_t *)image, sizeof(image), JPEGDraw)) { jpeg.setUserPointer(&ctx); // Pass context to callback jpeg.decode(0, 0, 0); jpeg.close(); } } ``` -------------------------------- ### Floyd-Steinberg Dithering for E-Paper Displays (C++) Source: https://context7.com/bitbank2/jpegdec/llms.txt Implements Floyd-Steinberg dithering for high-quality output on e-paper displays using the `decodeDither()` method. Requires an external buffer and integrates with FastEPD library. Supports different dithering levels (1, 2, or 4 bits). ```cpp #include #include #include "photo.h" JPEGDEC jpg; FASTEPD epaper; int JPEGDraw(JPEGDRAW *pDraw) { uint8_t *pBuffer = epaper.currentBuffer(); int shift = (jpg.getPixelType() == ONE_BIT_DITHERED) ? 3 : 1; int pitch = epaper.width() >> shift; for (int y = 0; y < pDraw->iHeight; y++) { uint8_t *d = &pBuffer[((pDraw->y + y) * pitch) + (pDraw->x >> shift)]; uint8_t *s = (uint8_t *)pDraw->pPixels + (y * (pDraw->iWidth >> shift)); memcpy(d, s, pDraw->iWidth >> shift); } return 1; } void displayDithered() { epaper.initPanel(BB_PANEL_M5PAPERS3); epaper.fillScreen(BBEP_WHITE); if (jpg.openFLASH((uint8_t *)photo, sizeof(photo), JPEGDraw)) { // Choose dithering level jpg.setPixelType(FOUR_BIT_DITHERED); // or ONE_BIT_DITHERED, TWO_BIT_DITHERED int w = jpg.getWidth(); int h = jpg.getHeight(); // Allocate dither buffer: width * 16 bytes uint8_t *pDither = (uint8_t *)malloc(w * 16); // Center image int xoff = (epaper.width() - w) / 2; int yoff = (epaper.height() - h) / 2; // Use decodeDither() instead of decode() jpg.decodeDither(xoff, yoff, pDither, 0); jpg.close(); free(pDither); epaper.fullUpdate(true); } } ``` -------------------------------- ### JPEGDEC Decode Methods Source: https://github.com/bitbank2/jpegdec/wiki/Home Illustrates the decoding capabilities of the JPEGDEC class. Includes standard decoding with offsets and options, and dithered decoding which requires a user-provided buffer. ```C++ int decode(int x_offset, int y_offset, int option_bits); int decodeDither(uint8_t *pDither, int iOptions); ``` -------------------------------- ### JPEGDEC Configuration and Metadata Source: https://github.com/bitbank2/jpegdec/wiki/Home Methods to retrieve image properties and configure decoder settings. ```APIDOC ## GET/SET [getWidth, getHeight, setPixelType, setCropArea] ### Description Utility methods to query image dimensions, check for thumbnails, and configure output pixel formats or cropping. ### Parameters #### Request Body - **iPixelType** (int) - Required for setPixelType - Format like RGB565_LITTLE_ENDIAN - **x, y, w, h** (int) - Required for setCropArea - Define the rectangular crop region ### Response - **Result** (int/bool) - Returns requested metadata or status. ``` -------------------------------- ### Decode Cropped JPEG Regions Source: https://context7.com/bitbank2/jpegdec/llms.txt Explains how to use setCropArea to decode only a specific portion of an image. The library automatically aligns the crop boundaries to MCU blocks, and getCropArea can be used to retrieve the actual dimensions used. ```cpp #include #include "large_image.h" JPEGDEC jpeg; int JPEGDraw(JPEGDRAW *pDraw) { lcd.setAddrWindow(pDraw->x, pDraw->y, pDraw->iWidth, pDraw->iHeight); lcd.pushPixels(pDraw->pPixels, pDraw->iWidth * pDraw->iHeight); return 1; } void displayCropped() { if (jpeg.openFLASH((uint8_t *)large_image, sizeof(large_image), JPEGDraw)) { jpeg.setPixelType(RGB565_BIG_ENDIAN); jpeg.setCropArea(120, 65, 119, 110); int x, y, cx, cy; jpeg.getCropArea(&x, &y, &cx, &cy); int xoff = (lcd.width() - cx) / 2; int yoff = (lcd.height() - cy) / 2; jpeg.decode(xoff, yoff, 0); jpeg.close(); } } ``` -------------------------------- ### Decoding Exif Thumbnails from JPEG (C++) Source: https://context7.com/bitbank2/jpegdec/llms.txt Demonstrates how to detect and decode embedded Exif thumbnails from JPEG images using `hasThumb()`, `getThumbWidth()`, `getThumbHeight()`, and `decode()` with the `JPEG_EXIF_THUMBNAIL` option. Falls back to decoding the main image if no thumbnail is found. ```cpp #include #include "photo_with_thumbnail.h" JPEGDEC jpeg; int JPEGDraw(JPEGDRAW *pDraw) { lcd.drawRGBBitmap(pDraw->x, pDraw->y, pDraw->pPixels, pDraw->iWidth, pDraw->iHeight); return 1; } void displayThumbnail() { if (jpeg.openFLASH((uint8_t *)photo_with_thumbnail, sizeof(photo_with_thumbnail), JPEGDraw)) { Serial.printf("Main image: %d x %d\n", jpeg.getWidth(), jpeg.getHeight()); if (jpeg.hasThumb()) { Serial.printf("Thumbnail: %d x %d\n", jpeg.getThumbWidth(), jpeg.getThumbHeight()); // Decode thumbnail instead of main image jpeg.decode(0, 0, JPEG_EXIF_THUMBNAIL); } else { Serial.println("No thumbnail found, decoding main image"); jpeg.decode(0, 0, 0); } jpeg.close(); } } ``` -------------------------------- ### Method: decode() (Exif Thumbnails) Source: https://context7.com/bitbank2/jpegdec/llms.txt Extracts and decodes embedded Exif thumbnails from a JPEG file. ```APIDOC ## decode() (Exif Thumbnails) ### Description Decodes the embedded thumbnail found within the Exif metadata of a JPEG image. ### Parameters #### Path Parameters - **x** (int) - Required - X-coordinate offset. - **y** (int) - Required - Y-coordinate offset. - **options** (int) - Required - Use JPEG_EXIF_THUMBNAIL to target the thumbnail. ### Request Example ```cpp if (jpeg.hasThumb()) { jpeg.decode(0, 0, JPEG_EXIF_THUMBNAIL); } ``` ``` -------------------------------- ### Metadata Retrieval Methods Source: https://context7.com/bitbank2/jpegdec/llms.txt Methods to retrieve information about a JPEG image after opening it. ```APIDOC ## Metadata Retrieval ### Description Retrieve technical metadata from an opened JPEG file. ### Methods - **getWidth()** (int) - Returns image width. - **getHeight()** (int) - Returns image height. - **getBpp()** (int) - Returns bits per pixel. - **getSubSample()** (int) - Returns color subsampling info. - **getOrientation()** (int) - Returns EXIF orientation. - **getJPEGType()** (int) - Returns mode (Baseline or Progressive). - **getLastError()** (int) - Returns the last error code. ### Response Example ```cpp Serial.printf("Dimensions: %d x %d pixels\n", jpeg.getWidth(), jpeg.getHeight()); ``` ``` -------------------------------- ### Method: decodeDither() Source: https://context7.com/bitbank2/jpegdec/llms.txt Decodes a JPEG image using Floyd-Steinberg dithering, which is optimized for e-paper displays. Requires a pre-allocated buffer for the dithering algorithm. ```APIDOC ## decodeDither() ### Description Decodes a JPEG image with dithering applied. This is specifically useful for displays with limited color depth like e-paper. ### Parameters #### Path Parameters - **x** (int) - Required - X-coordinate offset for drawing. - **y** (int) - Required - Y-coordinate offset for drawing. - **pDither** (uint8_t*) - Required - Pointer to a buffer of size (width * 16) bytes. - **options** (int) - Required - Reserved for future use, pass 0. ### Request Example ```cpp uint8_t *pDither = (uint8_t *)malloc(w * 16); jpg.decodeDither(xoff, yoff, pDither, 0); free(pDither); ``` ``` -------------------------------- ### Register JPEGDEC Component in CMake Source: https://github.com/bitbank2/jpegdec/blob/master/CMakeLists.txt This snippet defines the source files and required dependencies for the JPEGDEC library. It uses the idf_component_register function to include necessary DSP and Arduino-ESP32 components. ```cmake set(srcs "src/JPEGDEC.cpp" "src/jpeg.inl" "src/s3_simd_420.S" "src/s3_simd_444.S" "src/s3_simd_dequant.S" ) idf_component_register(SRCS ${srcs} REQUIRES "esp-dsp arduino-esp32" INCLUDE_DIRS "src/." ) project(jpegdec) ``` -------------------------------- ### Decode JPEG from RAM Buffer Source: https://context7.com/bitbank2/jpegdec/llms.txt Shows how to decode a JPEG image stored in a dynamic RAM buffer. This is useful for images received over network or loaded from external sources at runtime. ```cpp #include JPEGDEC jpeg; int JPEGDraw(JPEGDRAW *pDraw) { lcd.setAddrWindow(pDraw->x, pDraw->y, pDraw->iWidth, pDraw->iHeight); lcd.pushPixels((uint16_t *)pDraw->pPixels, pDraw->iWidth * pDraw->iHeight); return 1; } void displayImage(uint8_t *buffer, int size) { if (jpeg.openRAM(buffer, size, JPEGDraw)) { jpeg.setPixelType(RGB565_BIG_ENDIAN); jpeg.decode(0, 0, 0); jpeg.close(); } } ``` -------------------------------- ### JPEGDEC Decoding Methods Source: https://github.com/bitbank2/jpegdec/wiki/Home Methods to process and render the loaded JPEG image. ```APIDOC ## EXECUTE [decode, decodeDither] ### Description Decodes the loaded image. decode() performs standard rendering, while decodeDither() supports dithered output formats. ### Parameters #### Request Body - **x_offset** (int) - Required - X coordinate for drawing - **y_offset** (int) - Required - Y coordinate for drawing - **option_bits** (int) - Optional - Scaling options (e.g., JPEG_SCALE_HALF) - **pDither** (uint8_t*) - Required for decodeDither - Pointer to RAM buffer ### Response - **Success** (int) - 1 if successful, 0 otherwise. ``` -------------------------------- ### Decode JPEG from FLASH Memory Source: https://context7.com/bitbank2/jpegdec/llms.txt Demonstrates how to decode a JPEG image stored in program memory (FLASH). This method is ideal for static images compiled directly into the firmware. ```cpp #include #include "my_image.h" JPEGDEC jpeg; int JPEGDraw(JPEGDRAW *pDraw) { lcd.setAddrWindow(pDraw->x, pDraw->y, pDraw->iWidth, pDraw->iHeight); lcd.pushPixels(pDraw->pPixels, pDraw->iWidth * pDraw->iHeight); return 1; } void setup() { if (jpeg.openFLASH((uint8_t *)my_image, sizeof(my_image), JPEGDraw)) { Serial.printf("Image size: %d x %d\n", jpeg.getWidth(), jpeg.getHeight()); jpeg.decode(0, 0, 0); jpeg.close(); } } ``` -------------------------------- ### Display Bitmap on M5Stack LCD Source: https://github.com/bitbank2/jpegdec/blob/master/examples/M5Stack/README.md Draws a bitmap image onto the M5Stack LCD. This function is a modified version of the adafruit_gfx_demo's JPEGDraw function, adapted for M5Stack devices. It takes coordinates, dimensions, and pixel data as input. ```C++ M5.Lcd.drawBitmap((int16_t)pDraw->x, (int16_t)pDraw->y, (int16_t)pDraw->iWidth, (int16_t)pDraw->iHeight, pDraw->pPixels); ``` -------------------------------- ### Define JPEG Draw Callback and Structure Source: https://github.com/bitbank2/jpegdec/wiki/Home Defines the function prototype for the JPEG draw callback and the JPEGDRAW structure used to pass pixel data and metadata to the display driver. ```C typedef void (JPEG_DRAW_CALLBACK)(JPEGDRAW *pDraw); typedef struct jpeg_draw_tag { int x, y; int iWidth, iHeight; int iBpp; uint16_t *pPixels; void *pUser; } JPEGDRAW; ``` -------------------------------- ### JPEGDEC Image Information Methods Source: https://github.com/bitbank2/jpegdec/wiki/Home Provides methods to retrieve essential information about the decoded JPEG image, such as its dimensions, bits per pixel, subsampling information, and thumbnail status. ```C++ int getWidth(); int getHeight(); int getBpp(); int getSubSample(); int hasThumb(); int getThumbWidth(); int getThumbHeight(); ``` -------------------------------- ### JPEGDEC Class Definition Source: https://github.com/bitbank2/jpegdec/wiki/Home This snippet shows the public interface of the JPEGDEC class, including methods for opening, closing, decoding, and retrieving image information. It also details private members. ```C++ class JPEGDEC { public: int openRAM(uint8_t *pData, int iDataSize, JPEG_DRAW_CALLBACK *pfnDraw); int openFLASH(uint8_t *pData, int iDataSize, JPEG_DRAW_CALLBACK *pfnDraw); int open(char *szFilename, JPEG_OPEN_CALLBACK *pfnOpen, JPEG_CLOSE_CALLBACK *pfnClose, JPEG_READ_CALLBACK *pfnRead, JPEG_SEEK_CALLBACK *pfnSeek, JPEG_DRAW_CALLBACK *pfnDraw); void close(); int decode(int x_offset, int y_offset, int option_bits); int decodeDither(uint8_t *pDither, int iOptions); int getWidth(); int getHeight(); int getBpp(); int getSubSample(); int hasThumb(); int getThumbWidth(); int getThumbHeight(); int getLastError(); void setPixelType(int iPixelType); // defaults to RGB565 little-endian void setMaxOutputSize(int iMCUs); void setCropArea(int x, int y, int w, int h); void getCropArea(int *x, int *y, int *w, int *h); private: JPEGIMAGE _jpeg; }; ``` -------------------------------- ### JPEGDEC Error Handling and Utility Source: https://github.com/bitbank2/jpegdec/wiki/Home Includes methods for retrieving the last error code and for closing the image decoder. The close method is effective for file-based images but has no effect on memory-based images. ```C++ int getLastError(); void close(); ``` -------------------------------- ### JPEG Decode with Thumbnail Check Source: https://github.com/bitbank2/jpegdec/blob/master/examples/M5Stack/README.md Decodes a JPEG image, conditionally handling thumbnails. This code checks if the JPEG object has a thumbnail and calls the appropriate decode routine based on its presence. It allows decoding either the thumbnail or the main image with specified options. ```C++ if (jpeg.hasThumb()) { jpeg.decode(iCenterX[i], iCenterY[i], JPEG_EXIF_THUMBNAIL | iOption[i]); } else { jpeg.decode(iCenterX[i], iCenterY[i], iOption[i]); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.