Overview
The jpgdec library allows you to decode JPEG images from files or memory buffers. It supports standard JPEG features including multiple color spaces, downscaling, and both basic and extended decoding modes.Before using jpgdec functions, you must load the SYSMODULE_JPGDEC system module using
sysModuleLoad().Error Codes
| Code | Value | Description |
|---|---|---|
JPGDEC_ERROR_OK | 0x00 | Operation successful |
JPGDEC_ERROR_HEADER | 0x80611101 | Invalid JPEG header |
JPGDEC_ERROR_STREAM_FORMAT | 0x80611102 | Invalid stream format |
JPGDEC_ERROR_ARG | 0x80611103 | Invalid argument |
JPGDEC_ERROR_SEQ | 0x80611104 | Invalid sequence |
JPGDEC_ERROR_BUSY | 0x80611105 | Decoder is busy |
JPGDEC_ERROR_FATAL | 0x80611106 | Fatal error |
JPGDEC_ERROR_OPEN_FILE | 0x80611107 | Failed to open file |
JPGDEC_ERROR_SPU_UNSUPPORT | 0x80611108 | SPU acceleration unsupported |
JPGDEC_ERROR_CB_PARAM | 0x80611109 | Invalid callback parameter |
Color Spaces
Supported color space formats for JPEG decoding.
JPGDEC_GRAYSCALE(1) - Grayscale outputJPGDEC_RGB(2) - RGB color outputJPGDEC_YCBCR(3) - YCbCr color outputJPGDEC_RGBA(10) - RGBA color outputJPGDEC_UPSTREAM(11) - Upstream formatJPGDEC_ARGB(20) - ARGB color output
Stream Selection
Input source selection for JPEG data.
JPGDEC_FILE(0) - Decode from fileJPGDEC_BUFFER(1) - Decode from memory buffer
Core Functions
jpgDecCreate
Pointer to receive the decoder handle.
Input parameters for decoder creation.
Enable SPU acceleration (JPGDEC_SPU_THREAD_ENABLE or JPGDEC_SPU_THREAD_DISABLE).
PPU thread priority.
SPU thread priority (if SPU enabled).
Custom memory allocation function (optional, can be NULL).
Argument passed to malloc function.
Custom memory free function (optional, can be NULL).
Argument passed to free function.
Output parameters from decoder creation.
Decoder library version.
JPGDEC_ERROR_OK on success, error code otherwise.
jpgDecOpen
Decoder handle from jpgDecCreate.
Pointer to receive the stream subhandle.
Source configuration for the JPEG data.
Input stream selection (JPGDEC_FILE or JPGDEC_BUFFER).
File path (if stream_sel is JPGDEC_FILE).
Offset in file to start reading.
Size of JPEG data in file.
Pointer to JPEG data in memory (if stream_sel is JPGDEC_BUFFER).
Size of JPEG data in memory.
Enable SPU acceleration for this stream.
Information about the opened stream.
Amount of memory allocated for initialization.
JPGDEC_ERROR_OK on success, error code otherwise.
jpgDecReadHeader
Decoder handle.
Stream subhandle from jpgDecOpen.
JPGDEC_ERROR_OK on success, error code otherwise.
jpgDecSetParameter
Decoder handle.
Stream subhandle.
Input decoding parameters.
Pointer to command variable for decoder control (can be NULL).
Downscaling factor (1, 2, 4, or 8).
Quality mode (JPGDEC_QUALITY or JPGDEC_FAST).
Output scanline order (JPGDEC_TOP_TO_BOTTOM or JPGDEC_BOTTOM_TO_TOP).
Desired output color space.
Alpha value for RGBA/ARGB output (0-255).
Output parameters after configuration.
Width of output in bytes (including padding).
Output image width in pixels.
Output image height in pixels.
Number of output color components.
Actual output mode being used.
Actual output color space.
Actual downscale factor being used.
Memory required for decoding.
JPGDEC_ERROR_OK on success, error code otherwise.
jpgDecDecodeData
Decoder handle.
Stream subhandle.
Pointer to output buffer for decoded image data.
Data control parameters.
Bytes per line in output buffer (for custom stride).
JPGDEC_ERROR_OK on success, error code otherwise.
jpgDecClose
Decoder handle.
Stream subhandle to close.
JPGDEC_ERROR_OK on success, error code otherwise.
jpgDecDestroy
Decoder handle to destroy.
JPGDEC_ERROR_OK on success, error code otherwise.
Helper Functions
jpgLoadFromFile
Path to the JPEG file.
JPGDEC_ERROR_OK on success, error code otherwise.
jpgLoadFromBuffer
Pointer to JPEG data in memory.
Size of JPEG data in bytes.
Pointer to receive the decoded image data (same structure as jpgLoadFromFile).
JPGDEC_ERROR_OK on success, error code otherwise.
Usage Example
Simple Usage Example
For basic use cases, the helper functions provide a simpler interface:Extended API
The jpgdec library also provides extended functions for advanced use cases:jpgDecExtOpen()- Opens a stream with callback support for streaming datajpgDecExtReadHeader()- Reads header with extended informationjpgDecExtSetParameter()- Sets parameters with extended options (MCU mode, line mode)jpgDecExtDecodeData()- Decodes with display callback support for progressive rendering