]> Creatis software - gdcm.git/blob - src/gdcmJpeg8.cxx
ENH: Minor cleanup, still removing stdio.h and co ...
[gdcm.git] / src / gdcmJpeg8.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmJpeg8.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/10/08 04:52:55 $
7   Version:   $Revision: 1.2 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmFile.h"
19
20 /*
21 DICOM provides a mechanism for supporting the use of JPEG Image Compression 
22 through the Encapsulated Format (see PS 3.3 of the DICOM Standard). 
23 Annex A defines a number of Transfer Syntaxes which reference 
24 the JPEG Standard and provide a number of lossless (bit preserving) 
25 and lossy compression schemes.
26 In order to facilitate interoperability of implementations conforming 
27 to the DICOM Standard which elect to use one or more 
28 of the Transfer Syntaxes for JPEG Image Compression, the following policy is specified:
29
30   Any implementation which conforms to the DICOM Standard and has elected 
31   to support any one of the Transfer Syntaxes for lossless JPEG Image Compression, 
32   shall support the following lossless compression: 
33   The subset (first-order horizontal prediction [Selection Value 1) of JPEG Process 14 
34   (DPCM, non-hierarchical with Huffman coding) (see Annex F of the DICOM Standard).
35
36    Any implementation which conforms to the DICOM Standard and has elected 
37    to support any one of the Transfer Syntaxes for 8-bit lossy JPEG Image Compression, 
38    shall support the JPEG Baseline Compression (coding Process 1).
39
40    Any implementation which conforms to the DICOM Standard and has elected 
41    to support any one of the Transfer Syntaxes for 12-bit lossy JPEG Image Compression, 
42    shall support the JPEG Compression Process 4.
43
44 Note: The DICOM conformance statement shall differentiate between implementations 
45 that can simply receive JPEG encoded images and those that can receive and process 
46 JPEG encoded images (see PS 3.2 of the DICOM Standard).
47
48 The use of the DICOM Encapsulated Format to support JPEG Compressed Pixel Data 
49 implies that the Data Elements which are related to the Native Format Pixel Data encoding
50 (e.g. Bits Allocated, Bits Stored, High Bit, Pixel Representation, Rows, Columns, etc.) 
51 shall contain values which are consistent with the characteristics 
52 of the uncompressed pixel data from which the compressed Data Stream was derived. 
53 The Pixel Data characteristics included in the JPEG Interchange Format 
54 shall be used to decode the compressed data stream.
55
56 Run Length Encoding Compression
57
58 DICOM provides a mechanism for supporting the use of Run Length Encoding (RLE) 
59 Compression which is a byte oriented lossless compression scheme through 
60 the encapsulated Format (see PS 3.3 of this Standard). 
61 Annex G of the DICOM Standard defines RLE Compression and its Transfer Syntax.
62
63 Note: The RLE Compression algorithm described in Annex G 
64 of the DICOM Standard is the compression used in 
65 the TIFF 6.0 specification known as the "PackBits" scheme.
66
67 The use of the DICOM Encapsulated Format to support RLE Compressed Pixel Data 
68 implies that the Data Elements which are related to the Native Format Pixel Data encoding (
69 e.g. Bits Allocated, Bits Stored, High Bit, Pixel Representation, Rows, Columns, etc.) 
70 shall contain values which are consistent with the characteristics 
71 of the uncompressed pixel data from which the compressed data is derived
72 */
73
74 /*
75  * <setjmp.h> is used for the optional error recovery mechanism shown in
76  * the second part of the example.
77  */
78
79 /*
80  * Include file for users of JPEG library.
81  * You will need to have included system headers that define at least
82  * the typedefs FILE and size_t before you can include jpeglib.h.
83  * (stdio.h is sufficient on ANSI-conforming systems.)
84  * You may also wish to include "jerror.h".
85  */
86
87 extern "C" {
88 //#include "stdio.h"
89 #include "src/jpeg/libijg8/jconfig.h"
90 #include "src/jpeg/libijg8/jpeglib.h"
91
92 #include <setjmp.h>
93 }
94
95
96 /******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/
97
98 /* This half of the example shows how to feed data into the JPEG compressor.
99  * We present a minimal version that does not worry about refinements such
100  * as error recovery (the JPEG code will just exit() if it gets an error).
101  */
102
103 /*
104  * IMAGE DATA FORMATS:
105  *
106  * The standard input image format is a rectangular array of pixels, with
107  * each pixel having the same number of "component" values (color channels).
108  * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars).
109  * If you are working with color data, then the color values for each pixel
110  * must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit
111  * RGB color.
112  *
113  * For this example, we'll assume that this data structure matches the way
114  * our application has stored the image in memory, so we can just pass a
115  * pointer to our image buffer.  In particular, let's say that the image is
116  * RGB color and is described by:
117  */
118
119 // FIXME : JPR
120
121 //extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
122 //extern int image_height;       /* Number of rows in image */
123 //extern int image_width;        /* Number of columns in image */
124
125
126
127 /*
128  * Sample routine for JPEG compression.  We assume that the target file name
129  * and a compression quality factor are passed in.
130  */
131
132  /**
133  * \ingroup gdcmFile
134  * \brief   routine for JPEG decompression 
135  * @param fp pointer to an already open file descriptor 
136  *                      8 significant bits per pixel
137  * @param image_buffer Points to array (of R,G,B-order) data to compress
138  * @param quality compression quality
139  * @param image_height Number of rows in image 
140  * @param image_width Number of columns in image
141  * @return 1 on success, 0 on error
142  */
143  
144 bool gdcm_write_JPEG_file (FILE* fp, void*  im_buf, 
145                            int image_width, int image_height, int quality)
146 {
147
148    JSAMPLE* image_buffer = (JSAMPLE*) im_buf;
149
150   /* This struct contains the JPEG compression parameters and pointers to
151    * working space (which is allocated as needed by the JPEG library).
152    * It is possible to have several such structures, representing multiple
153    * compression/decompression processes, in existence at once.  We refer
154    * to any one struct (and its associated working data) as a "JPEG object".
155    */
156   struct jpeg_compress_struct cinfo;
157   /* This struct represents a JPEG error handler.  It is declared separately
158    * because applications often want to supply a specialized error handler
159    * (see the second half of this file for an example).  But here we just
160    * take the easy way out and use the standard error handler, which will
161    * print a message on stderr and call exit() if compression fails.
162    * Note that this struct must live as long as the main JPEG parameter
163    * struct, to avoid dangling-pointer problems.
164    */
165   struct jpeg_error_mgr jerr;
166   /* More stuff */
167   //FILE*  outfile;    /* target FILE* /
168   JSAMPROW row_pointer[1];   /* pointer to JSAMPLE row[s] */
169   int row_stride;            /* physical row width in image buffer */
170
171   /* Step 1: allocate and initialize JPEG compression object */
172
173   /* We have to set up the error handler first, in case the initialization
174    * step fails.  (Unlikely, but it could happen if you are out of memory.)
175    * This routine fills in the contents of struct jerr, and returns jerr's
176    * address which we place into the link field in cinfo.
177    */
178   cinfo.err = jpeg_std_error(&jerr);
179   /* Now we can initialize the JPEG compression object. */
180   jpeg_create_compress(&cinfo);
181
182   /* Step 2: specify data destination (eg, a file) */
183   /* Note: steps 2 and 3 can be done in either order. */
184
185   /* Here we use the library-supplied code to send compressed data to a
186    * stdio stream.  You can also write your own code to do something else.
187    * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
188    * requires it in order to write binary files.
189    */
190  // if ((outfile = fopen(filename, "wb")) == NULL) {
191  //   fprintf(stderr, "can't open %s\n", filename);
192  //   exit(1);
193  //
194  // }
195   jpeg_stdio_dest(&cinfo, fp);
196
197   /* Step 3: set parameters for compression */
198
199   /* First we supply a description of the input image.
200    * Four fields of the cinfo struct must be filled in:
201    */
202   cinfo.image_width = image_width;/* image width and height, in pixels */
203   cinfo.image_height = image_height;
204   cinfo.input_components = 3;     /* # of color components per pixel */
205   cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
206   /* Now use the library's routine to set default compression parameters.
207    * (You must set at least cinfo.in_color_space before calling this,
208    * since the defaults depend on the source color space.)
209    */
210   jpeg_set_defaults(&cinfo);
211   /* Now you can set any non-default parameters you wish to.
212    * Here we just illustrate the use of quality (quantization table) scaling:
213    */
214   jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
215
216   /* Step 4: Start compressor */
217
218   /* TRUE ensures that we will write a complete interchange-JPEG file.
219    * Pass TRUE unless you are very sure of what you're doing.
220    */
221   jpeg_start_compress(&cinfo, TRUE);
222
223   /* Step 5: while (scan lines remain to be written) */
224   /*           jpeg_write_scanlines(...); */
225
226   /* Here we use the library's state variable cinfo.next_scanline as the
227    * loop counter, so that we don't have to keep track ourselves.
228    * To keep things simple, we pass one scanline per call; you can pass
229    * more if you wish, though.
230    */
231   row_stride = image_width * 3;/* JSAMPLEs per row in image_buffer */
232
233   while (cinfo.next_scanline < cinfo.image_height) {
234     /* jpeg_write_scanlines expects an array of pointers to scanlines.
235      * Here the array is only one element long, but you could pass
236      * more than one scanline at a time if that's more convenient.
237      */
238     row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
239
240     (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
241   }
242
243   /* Step 6: Finish compression */
244
245   jpeg_finish_compress(&cinfo);
246   
247   /* After finish_compress, we can close the output file. */
248   
249  // fclose(fp); --> the caller will close (multiframe treatement)
250
251   /* Step 7: release JPEG compression object */
252
253   /* This is an important step since it will release a good deal of memory. */
254   jpeg_destroy_compress(&cinfo);
255
256   /* And we're done! */
257
258   return true; //???
259 }
260
261
262
263 /*
264  * SOME FINE POINTS:
265  *
266  * In the above loop, we ignored the return value of jpeg_write_scanlines,
267  * which is the number of scanlines actually written.  We could get away
268  * with this because we were only relying on the value of cinfo.next_scanline,
269  * which will be incremented correctly.  If you maintain additional loop
270  * variables then you should be careful to increment them properly.
271  * Actually, for output to a stdio stream you needn't worry, because
272  * then jpeg_write_scanlines will write all the lines passed (or else exit
273  * with a fatal error).  Partial writes can only occur if you use a data
274  * destination module that can demand suspension of the compressor.
275  * (If you don't know what that's for, you don't need it.)
276  *
277  * If the compressor requires full-image buffers (for entropy-coding
278  * optimization or a multi-scan JPEG file), it will create temporary
279  * files for anything that doesn't fit within the maximum-memory setting.
280  * (Note that temp files are NOT needed if you use the default parameters.)
281  * On some systems you may need to set up a signal handler to ensure that
282  * temporary files are deleted if the program is interrupted.  See libjpeg.doc.
283  *
284  * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG
285  * files to be compatible with everyone else's.  If you cannot readily read
286  * your data in that order, you'll need an intermediate array to hold the
287  * image.  See rdtarga.c or rdbmp.c for examples of handling bottom-to-top
288  * source data using the JPEG code's internal virtual-array mechanisms.
289  */
290
291
292
293 /******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/
294
295 /* This half of the example shows how to read data from the JPEG decompressor.
296  * It's a bit more refined than the above, in that we show:
297  *   (a) how to modify the JPEG library's standard error-reporting behavior;
298  *   (b) how to allocate workspace using the library's memory manager.
299  *
300  * Just to make this example a little different from the first one, we'll
301  * assume that we do not intend to put the whole image into an in-memory
302  * buffer, but to send it line-by-line someplace else.  We need a one-
303  * scanline-high JSAMPLE array as a work buffer, and we will let the JPEG
304  * memory manager allocate it for us.  This approach is actually quite useful
305  * because we don't need to remember to deallocate the buffer separately: it
306  * will go away automatically when the JPEG object is cleaned up.
307  */
308
309 /*
310  * ERROR HANDLING:
311  *
312  * The JPEG library's standard error handler (jerror.c) is divided into
313  * several "methods" which you can override individually.  This lets you
314  * adjust the behavior without duplicating a lot of code, which you might
315  * have to update with each future release.
316  *
317  * Our example here shows how to override the "error_exit" method so that
318  * control is returned to the library's caller when a fatal error occurs,
319  * rather than calling exit() as the standard error_exit method does.
320  *
321  * We use C's setjmp/longjmp facility to return control.  This means that the
322  * routine which calls the JPEG library must first execute a setjmp() call to
323  * establish the return point.  We want the replacement error_exit to do a
324  * longjmp().  But we need to make the setjmp buffer accessible to the
325  * error_exit routine.  To do this, we make a private extension of the
326  * standard JPEG error handler object.  (If we were using C++, we'd say we
327  * were making a subclass of the regular error handler.)
328  *
329  * Here's the extended error handler struct:
330  */
331
332 //-----------------------------------------------------------------------------
333 struct my_error_mgr {
334    struct jpeg_error_mgr pub; /* "public" fields */
335    jmp_buf setjmp_buffer;     /* for return to caller */
336 };
337
338 //-----------------------------------------------------------------------------
339 typedef struct my_error_mgr* my_error_ptr;
340
341 /*
342  * Here's the routine that will replace the standard error_exit method:
343  */
344 METHODDEF(void) my_error_exit (j_common_ptr cinfo) {
345    /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
346    my_error_ptr myerr = (my_error_ptr) cinfo->err;
347
348    /* Always display the message. */
349    /* We could postpone this until after returning, if we chose. */
350    (*cinfo->err->output_message) (cinfo);
351
352    /* Return control to the setjmp point */
353    longjmp(myerr->setjmp_buffer, 1);
354 }
355
356 //-----------------------------------------------------------------------------
357 /*
358  * Sample routine for JPEG decompression.  We assume that the source file name
359  * is passed in.  We want to return 1 on success, 0 on error.
360  */
361  
362  /**
363  * \ingroup gdcmFile
364  * \brief   routine for JPEG decompression 
365  * @param fp pointer to an already open file descriptor 
366  *                      8 significant bits per pixel
367  * @param image_buffer to receive uncompressed pixels
368  * @return 1 on success, 0 on error
369  */
370  
371 bool gdcmFile::gdcm_read_JPEG_file (FILE* fp, void* image_buffer) {
372    char* pimage;
373
374    /* This struct contains the JPEG decompression parameters and pointers to
375     * working space (which is allocated as needed by the JPEG library).
376     */
377    struct jpeg_decompress_struct cinfo;
378
379    /* -------------- inside, we found :
380     * JDIMENSION image_width;       // input image width 
381     * JDIMENSION image_height;      // input image height 
382     * int input_components;         // nb of color components in input image 
383     * J_COLOR_SPACE in_color_space; // colorspace of input image 
384     * double input_gamma;           // image gamma of input image 
385     * -------------- */
386
387    /* We use our private extension JPEG error handler.
388     * Note that this struct must live as long as the main JPEG parameter
389     * struct, to avoid dangling-pointer problems.
390     */
391    struct my_error_mgr jerr;
392    /* More stuff */
393
394    JSAMPARRAY buffer;/* Output row buffer */
395   
396    // rappel :
397    // ------
398    // typedef unsigned char JSAMPLE;
399    // typedef JSAMPLE FAR *JSAMPROW;/* ptr to one image row of pixel samples. */
400    // typedef JSAMPROW *JSAMPARRAY;/* ptr to some rows (a 2-D sample array) */
401    // typedef JSAMPARRAY *JSAMPIMAGE;/* a 3-D sample array: top index is color */
402
403    int row_stride;/* physical row width in output buffer */
404   
405 #ifdef GDCM_JPG_DEBUG
406    printf("entree dans gdcmFile::gdcm_read_JPEG_file (i.e. 8), depuis gdcmJpeg\n");
407 #endif //GDCM_JPG_DEBUG
408
409    /* In this example we want to open the input file before doing anything else,
410     * so that the setjmp() error recovery below can assume the file is open.
411     * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
412     * requires it in order to read binary files.
413     */
414     
415   /* Step 1: allocate and initialize JPEG decompression object */  
416 #ifdef GDCM_JPG_DEBUG
417   printf("Entree Step 1\n");
418 #endif //GDCM_JPG_DEBUG
419   
420   /* We set up the normal JPEG error routines, then override error_exit. */
421   
422   cinfo.err = jpeg_std_error(&jerr.pub);
423   jerr.pub.error_exit = my_error_exit;
424   
425   /* Establish the setjmp return context for my_error_exit to use. */  
426   if (setjmp(jerr.setjmp_buffer)) {
427     /* If we get here, the JPEG code has signaled an error.
428      * We need to clean up the JPEG object, close the input file, and return.
429      */
430     jpeg_destroy_decompress(&cinfo);
431     return 0;
432   }
433   /* Now we can initialize the JPEG decompression object. */
434   jpeg_create_decompress(&cinfo);
435
436    /* Step 2: specify data source (eg, a file) */
437 #ifdef GDCM_JPG_DEBUG
438   printf("Entree Step 2\n");
439 #endif //GDCM_JPG_DEBUG
440
441    jpeg_stdio_src(&cinfo, fp);
442
443    /* Step 3: read file parameters with jpeg_read_header() */
444 #ifdef GDCM_JPG_DEBUG
445   printf("Entree Step 3\n");
446 #endif //GDCM_JPG_DEBUG
447
448    (void) jpeg_read_header(&cinfo, TRUE);
449    
450    /* We can ignore the return value from jpeg_read_header since
451     *   (a) suspension is not possible with the stdio data source, and
452     *   (b) we passed TRUE to reject a tables-only JPEG file as an error.
453     * See libjpeg.doc for more info.
454     */
455
456 #ifdef GDCM_JPG_DEBUG
457       printf("--------------Header contents :----------------\n");
458       printf("image_width %d image_height %d\n", 
459               cinfo.image_width , cinfo.image_height);
460       printf("bits of precision in image data  %d \n", 
461               cinfo.output_components);
462       printf("nb of color components returned  %d \n", 
463               cinfo.data_precision);
464 #endif //GDCM_JPG_DEBUG
465
466
467    /*
468     * JDIMENSION image_width;       // input image width 
469     * JDIMENSION image_height;      // input image height 
470     * int output_components;        // # of color components returned 
471     * J_COLOR_SPACE in_color_space; // colorspace of input image 
472     * double input_gamma;           // image gamma of input image
473     * int data_precision;           // bits of precision in image data 
474     */
475
476    /* Step 4: set parameters for decompression */
477 #ifdef GDCM_JPG_DEBUG
478   printf("Entree Step 4\n");
479 #endif //GDCM_JPG_DEBUG
480    /* In this example, we don't need to change any of the defaults set by
481     * jpeg_read_header(), so we do nothing here.
482     */
483
484    /* Step 5: Start decompressor */
485 #ifdef GDCM_JPG_DEBUG
486    printf("Entree Step 5\n");
487 #endif //GDCM_JPG_DEBUG
488
489    (void) jpeg_start_decompress(&cinfo);
490    /* We can ignore the return value since suspension is not possible
491     * with the stdio data source.
492     */
493
494    /* We may need to do some setup of our own at this point before reading
495     * the data.  After jpeg_start_decompress() we have the correct scaled
496     * output image dimensions available, as well as the output colormap
497     * if we asked for color quantization.
498     * In this example, we need to make an output work buffer of the right size.
499     */ 
500
501    /* JSAMPLEs per row in output buffer */
502    row_stride = cinfo.output_width * cinfo.output_components;
503   
504 #ifdef GDCM_JPG_DEBUG
505   printf ("cinfo.output_width %d cinfo.output_components %d  row_stride %d\n",
506                       cinfo.output_width, cinfo.output_components,row_stride);
507 #endif //GDCM_JPG_DEBUG
508
509    /* Make a one-row-high sample array that will go away when done with image */
510    buffer = (*cinfo.mem->alloc_sarray)
511             ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
512
513    /* Step 6: while (scan lines remain to be read) */
514 #ifdef GDCM_JPG_DEBUG
515     printf("Entree Step 6\n"); 
516 #endif //GDCM_JPG_DEBUG
517    /*           jpeg_read_scanlines(...); */
518
519    /* Here we use the library's state variable cinfo.output_scanline as the
520     * loop counter, so that we don't have to keep track ourselves.
521     */
522 #ifdef GDCM_JPG_DEBUG
523       printf ("cinfo.output_height %d  cinfo.output_width %d\n",
524                cinfo.output_height,cinfo.output_width);
525 #endif //GDCM_JPG_DEBUG
526    pimage=(char *)image_buffer;
527   
528    while (cinfo.output_scanline < cinfo.output_height) {
529       /* jpeg_read_scanlines expects an array of pointers to scanlines.
530        * Here the array is only one element long, but you could ask for
531        * more than one scanline at a time if that's more convenient.
532        */
533      
534      // l'image est deja allouée (et passée en param)
535      // on ecrit directement les pixels
536      // (on DEVRAIT pouvoir)
537     
538     //(void) jpeg_read_scanlines(&cinfo, pimage, 1);
539     
540      (void) jpeg_read_scanlines(&cinfo, buffer, 1);
541       
542      if ( BITS_IN_JSAMPLE == 8) {
543          memcpy( pimage, buffer[0],row_stride); 
544          pimage+=row_stride;
545      } else {
546          memcpy( pimage, buffer[0],row_stride*2 ); // FIXME : *2  car 16 bits?!?
547          pimage+=row_stride*2;                     // FIXME : *2 car 16 bits?!?     
548      }
549   }
550  
551   /* Step 7: Finish decompression */
552 #ifdef GDCM_JPG_DEBUG
553    printf("Entree Step 7\n");
554 #endif //GDCM_JPG_DEBUG
555
556    (void) jpeg_finish_decompress(&cinfo);
557    
558    /* We can ignore the return value since suspension is not possible
559     * with the stdio data source.
560     */
561
562    /* Step 8: Release JPEG decompression object */
563
564 #ifdef GDCM_JPG_DEBUG
565   printf("Entree Step 8\n");
566 #endif //GDCM_JPG_DEBUG
567
568    /* This is an important step since it will release a good deal of memory. */
569
570    jpeg_destroy_decompress(&cinfo);
571
572    /* After finish_decompress, we can close the input file.
573     * Here we postpone it until after no more JPEG errors are possible,
574     * so as to simplify the setjmp error logic above.  (Actually, I don't
575     * think that jpeg_destroy can do an error exit, but why assume anything...)
576     */
577
578    /* At this point you may want to check to see whether any corrupt-data
579     * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
580     */
581
582    /* And we're done! */
583
584    return(true);
585 }
586
587
588 /*
589  * SOME FINE POINTS:
590  *
591  * In the above code, we ignored the return value of jpeg_read_scanlines,
592  * which is the number of scanlines actually read.  We could get away with
593  * this because we asked for only one line at a time and we weren't using
594  * a suspending data source.  See libjpeg.doc for more info.
595  *
596  * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress();
597  * we should have done it beforehand to ensure that the space would be
598  * counted against the JPEG max_memory setting.  In some systems the above
599  * code would risk an out-of-memory error.  However, in general we don't
600  * know the output image dimensions before jpeg_start_decompress(), unless we
601  * call jpeg_calc_output_dimensions().  See libjpeg.doc for more about this.
602  *
603  * Scanlines are returned in the same order as they appear in the JPEG file,
604  * which is standardly top-to-bottom.  If you must emit data bottom-to-top,
605  * you can use one of the virtual arrays provided by the JPEG memory manager
606  * to invert the data.  See wrbmp.c for an example.
607  *
608  * As with compression, some operating modes may require temporary files.
609  * On some systems you may need to set up a signal handler to ensure that
610  * temporary files are deleted if the program is interrupted.  See libjpeg.doc.
611  */
612  
613 //----------------------------------------------------------------------------