gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Announcements And Comments > JPEG Decompression Library

#12284 - Burton Radons - Thu Nov 06, 2003 3:04 pm

http://members.shaw.ca/burton-radons/gba-jpeg.zip

I've updated my JPEG decompression library. It now has no external dependencies (no memmove, malloc, or free), and no longer uses any permanent IWRAM. Instead, it loads the necessary functions into IWRAM just before using them, so that you can waste permanent IWRAM storage on tasks which are called constantly.

In case you follow this forum but not graphics: this is a small JPEG decompression library written from scratch for portable devices. It takes 7120 bytes of ROM space, no permanent IWRAM space, and has no external dependencies. It takes less memory, is faster than, and is much smaller than jpeglib.

The only thing in the archive is a C and H file. Just compile it normally; it does use GCC extensions, but otherwise it should take any level of warnings. Here's a usage sample:

Code:

REG_DISPCNT = 3 | (1 << (8 + 2)); /* Enable mode 3 and turn on background 2. */
REG_BG2CNT = 0; /* Clear all BG2 parameters. */
/* data should point to a regular JPEG file. */
JPEG_DecompressImage (data, VideoBuffer, 240, 160);


gba-image_jpeg.h is fairly configurable and has details on resource usage and limitations. The code is in the public domain.

(Edit: Updated to fix where it loads into IWRAM and to exploit an allowance in JPEG baseline decoding to save 2576 bytes of stack space).

(Edit: Updated to compile with the strictest warnings possible, -ansi -pedantic. It should now work on any C compiler. Also, stack space usage is now locked, exploiting a restriction in the JPEG specification. I also tweaked a limitation that had resulted in this code not being baseline-compliant.)

(Edit: Added assertion tests, which are stubs in embedded environs and fprintf to stderr if JPEG_DEBUG is set. Also, I made some changes to allow it to compile as C++.