Game Development Reference
In-Depth Information
7 Having read all the scan lines, we can finish the decompression.
8 Finally, we destroy the decompressor, which releases any allocated
memory.
There are many details that you need to be aware of if you intend to write
your own code and you would be advised to read the IPG docs carefully.
Alternatively, you could simply take the code presented here and use it
directly. It doesn't give you as much control, but it will load most Jpeg files
and return an RGB buffer.
BYTE *CJpeg::Load(CString fileName, UINT &width, UINT &height)
{
// basic code from IJG Jpeg Code v6 example.c
width=0;
height=0;
// This struct contains the JPEG decompression parameters and
// pointers to working space (which is allocated as needed by
// the JPEG library).
struct jpeg_decompress_struct cinfo;
// We use our private extension JPEG error handler.
// Note that this struct must live as long as the main JPEG
// parameter struct, to avoid dangling-pointer problems.
struct my_error_mgr jerr;
FILE * infile=NULL;
// source file
JSAMPARRAY buffer;
// Output row buffer
int row_stride;
// physical row width in output buffer
char buf[250];
// In this example we want to open the input file before doing
//anything else, so that the setjmp() error recovery below can
//assume the file is open.
//VERY IMPORTANT: use ”b” option to fopen() if you
//are on a machine that requires it in order to read binary files.
if ((infile = fopen(fileName, ”rb”)) == NULL) {
TRACE(”CJpeg::Load>> Can't open jpeg file”);
return NULL;
}
Search Nedrilad ::




Custom Search