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