Image Decoders

Microchip Graphics Library

Microchip Graphics Library
Image Decoders

The Image Decoder Library supports the decoding of images in JPEG, BMP, and GIF format in PIC24, dsPIC, and PIC32 devices. This is a supplement to the Graphics Library but could be used without the Graphics Library. It not only supports input data through the Microchip's MDD file system but it can also be configured to support user specific inputs from ROM, external EEPROM, etc. The output can be sent to the Graphics Display through the driver provided with the Graphics Library or to a callback function where user can further render the decoded image (even if Graphics Library is not used). The individual decoders provided uses the stack for the work memory and hence a heap is not required. 

 

Design 

The Image Decoder library includes the following files:

  1. Configuration file
    • ImageDecoderConfig.h
  2. Header files
    • Main Header
      • ImageDecoder.h
    • Individual decoder headers
      • JpegDecoder.h
      • BmpDecoder.h
      • GifDecoder.h
  3. Source files
    • Main Source file
      • ImageDecoder.c
    • Individual Source files
      • JpegDecoder.c
      • BmpDecoder.c
      • GifDecoder.c
  4. Support files
    • jidctint.c
 

This can be diagrammatically explained as below:

The user application interacts with the Image Decoder Library as per the diagram below:

User can use the Graphics Library for output or can provide his/her own output pixel handler callback function. Similarly, user can use MDD file system or provide his/her own input source which implements some specific APIs explained later. 

 

Configuration 

The compile time configurations can be done using the ImageDecoderConfig.h file. This file must be copied into the application folder like the other config files. The options provided are as explained below: 

 

1. Image format support 

The image formats which are not required can be compiled out by commenting out the respective defines. The below section says that GIF support to be excluded.

/* Comment out the image formats which are not required */
#define IMG_SUPPORT_BMP
#define IMG_SUPPORT_JPEG
//#define IMG_SUPPORT_GIF

2. Optimize for Graphics Library 

If user application requires to output the image directly to the display without any double buffering, then the code can be optimized by defining as below:

/* Comment out if output has to be given through a callback function */
/* If defined, the code is optimized to use only the graphics driver, only 16-bit-565-color-format is supported */
#define IMG_USE_ONLY_565_GRAPHICS_DRIVER_FOR_OUTPUT

If either double buffering has to be done or if user specific rendering has to be done, comment out the above mentioned line and provide a callback function to render the pixel values. The callback function will be explained in the API section. If commented out, then the width and height of the display screen has to be provided using the following defines

/* If the above define is commented out (Graphics driver is not included by default), then the below defines has to be set by the user */
#ifndef IMG_USE_ONLY_565_GRAPHICS_DRIVER_FOR_OUTPUT
        #define DISP_HOR_RESOLUTION       320
        #define DISP_VER_RESOLUTION       240
#endif

3. Optimize for MDD file system 

If user application uses only the MDD file system provided by Microchip Technology Inc., the code can be optimized by defining as below:

/* If defined, the code is optimized to use only the MDD file system */
#define IMG_USE_ONLY_MDD_FILE_SYSTEM_FOR_INPUT

If MDD file system is not used or if additional input formats have to be supported, the above define has to be commented out and a structure pointing to the required APIs (IMG_FILE_SYSTEM_API defined in ImageDecoder.h) must be provided by the user. 

4. Loop callback support 

Since decoder takes up significant amount of time decoding an image and user may want to update some information on the display or to send/receive data through communication channel, etc… it is possible to release processing power in the middle of decoding process by calling a callback function provided by the user. The user can do all the housekeeping activities inside the function. This option can be enabled by defining as below:

/* If defined, the a loop callback function is called in every
   decoding loop so that application can do maintenance activities such as
   getting data, updating display, etc... */
#define IMG_SUPPORT_IMAGE_DECODER_LOOP_CALLBACK

The JPEG decoder calls the callback function after every 8x8 pixel block decode while the BMP and GIF decoders calls after every row decode. 

If this support is not required, then this define can be commented out. 

Footprint 

The following are typical values for PIC24 with default compiler configuration. Actual values may vary with various factors such as compiler optimization levels and device used (PIC24/PIC32).

 
RAM (stack) 
ROM
(no compiler optimizations) 
 
Image Decoder Core Code 
30 Bytes 
1 KBytes 
 
Image Types 
 
 
Decode Time (in seconds)
Using 16 MIPS & Compiler Optimization Level 3 
BMP 
1 KBytes 
10 KBytes 
21 
JPEG 
3 KBytes 
13 KBytes 
21 
GIF 
11 KBytes(13 KBytes2
6 KBytes 
21 

(1) Approximate value for average quality image file with a pixel resolution of 320x240. Additional variance in time can be observed due to image quality/image size and file access time. 

(2) GIF code "Crush" optimization (GIF_CRUSH_PREV_SYMBOL_PTR_TABLE) is turned off. This compile switch can be found in GifDecoder.h file. Enabling this will have an additional effect on the GIF decoding time.

Demo Project
Name 
Description 
This demo demonstrates the decoding of images with JPEG and BMP file formats. 
Links
Microchip Graphics Library Version 3.06.02 - October 15, 2012
Copyright © 2012 Microchip Technology, Inc.  All rights reserved