4 * This is the routine that is called to decompress a frame
5 * image data. It is based on the program originally named ljpgtopnm.c.
6 * Major portions taken from the Independent JPEG Group' software, and
7 * from the Cornell lossless JPEG code
10 * $Id: decomp.c,v 1.1 2003/10/21 12:08:53 jpr Exp $
20 DecompressInfo dcInfo;
24 *--------------------------------------------------------------
28 * This is an interface routine to the JPEG library. The
29 * JPEG library calls this routine to "get more data"
32 * Number of bytes actually returned.
37 *--------------------------------------------------------------
39 static void efree(void **ptr)
47 int ReadJpegData (Uchar *buffer, int numBytes)
49 unsigned long size = sizeof(unsigned char);
51 fread(buffer,size,numBytes, JpegInFile);
57 short JPEGLosslessDecodeImage (StreamIN inFile, unsigned short *image16, int depth, int length)
61 MEMSET (&dcInfo, 0, sizeof (dcInfo));
62 inputBufferOffset = 0;
64 /* Allocate input buffer */
65 inputBuffer = (unsigned char*)malloc((size_t)length+5);
66 if (inputBuffer == NULL)
69 /* Read input buffer */
70 ReadJpegData (inputBuffer, length);
71 inputBuffer [length] = EOF;
73 /* Read JPEG File header */
74 ReadFileHeader (&dcInfo);
75 if (dcInfo.error) { efree ((void **)&inputBuffer); return -1; }
77 /* Read the scan header */
78 if (!ReadScanHeader (&dcInfo)) { efree ((void **)&inputBuffer); return -1; }
81 * Decode the image bits stream. Clean up everything when
84 DecoderStructInit (&dcInfo);
86 if (dcInfo.error) { efree ((void **)&inputBuffer); return -1; }
88 HuffDecoderInit (&dcInfo);
90 if (dcInfo.error) { efree ((void **)&inputBuffer); return -1; }
92 DecodeImage (&dcInfo, (unsigned short **) &image16, depth);
94 /* Free input buffer */
95 efree ((void **)&inputBuffer);