OSDN Git Service

add dct hardware with device driver
[fpga-leon-mjpeg/leon-mjpeg.git] / snapgear-2.6-p42 / user / jpeg-6b-host / djpeg.c
1 /*
2  * djpeg.c
3  *
4  * Copyright (C) 1991-1997, Thomas G. Lane.
5  * This file is part of the Independent JPEG Group's software.
6  * For conditions of distribution and use, see the accompanying README file.
7  *
8  * This file contains a command-line user interface for the JPEG decompressor.
9  * It should work on any system with Unix- or MS-DOS-style command lines.
10  *
11  * Two different command line styles are permitted, depending on the
12  * compile-time switch TWO_FILE_COMMANDLINE:
13  *      djpeg [options]  inputfile outputfile
14  *      djpeg [options]  [inputfile]
15  * In the second style, output is always to standard output, which you'd
16  * normally redirect to a file or pipe to some other program.  Input is
17  * either from a named file or from standard input (typically redirected).
18  * The second style is convenient on Unix but is unhelpful on systems that
19  * don't support pipes.  Also, you MUST use the first style if your system
20  * doesn't do binary I/O to stdin/stdout.
21  * To simplify script writing, the "-outfile" switch is provided.  The syntax
22  *      djpeg [options]  -outfile outputfile  inputfile
23  * works regardless of which command line style is used.
24  */
25
26 /* modified by Kenichi Kurimoto 
27  *   for LEON-mjpeg project
28  * 
29  */
30
31 #include "cdjpeg.h"             /* Common decls for cjpeg/djpeg applications */
32 #include "jversion.h"           /* for version message */
33
34 #include <ctype.h>              /* to declare isprint() */
35
36 #ifdef USE_CCOMMAND             /* command-line reader for Macintosh */
37 #ifdef __MWERKS__
38 #include <SIOUX.h>              /* Metrowerks needs this */
39 #include <console.h>            /* ... and this */
40 #endif
41 #ifdef THINK_C
42 #include <console.h>            /* Think declares it here */
43 #endif
44 #endif
45
46
47 /* Create the add-on message string table. */
48
49 #define JMESSAGE(code,string)   string ,
50
51 static const char * const cdjpeg_message_table[] = {
52 #include "cderror.h"
53   NULL
54 };
55
56
57 /*
58  * This list defines the known output image formats
59  * (not all of which need be supported by a given version).
60  * You can change the default output format by defining DEFAULT_FMT;
61  * indeed, you had better do so if you undefine PPM_SUPPORTED.
62  */
63
64 typedef enum {
65         FMT_BMP,                /* BMP format (Windows flavor) */
66         FMT_GIF,                /* GIF format */
67         FMT_OS2,                /* BMP format (OS/2 flavor) */
68         FMT_PPM,                /* PPM/PGM (PBMPLUS formats) */
69         FMT_RLE,                /* RLE format */
70         FMT_TARGA,              /* Targa format */
71         FMT_TIFF                /* TIFF format */
72 } IMAGE_FORMATS;
73
74 #ifndef DEFAULT_FMT             /* so can override from CFLAGS in Makefile */
75 #define DEFAULT_FMT     FMT_PPM
76 #endif
77
78 static IMAGE_FORMATS requested_fmt;
79
80
81 /*
82  * Argument-parsing code.
83  * The switch parser is designed to be useful with DOS-style command line
84  * syntax, ie, intermixed switches and file names, where only the switches
85  * to the left of a given file name affect processing of that file.
86  * The main program in this file doesn't actually use this capability...
87  */
88
89
90 static const char * progname;   /* program name for error messages */
91 static char * outfilename;      /* for -outfile switch */
92
93
94 static int f_num;
95
96
97 LOCAL(void)
98 usage (void)
99 /* complain about bad command line */
100 {
101   fprintf(stderr, "usage: %s [switches] ", progname);
102 #ifdef TWO_FILE_COMMANDLINE
103   fprintf(stderr, "inputfile outputfile\n");
104 #else
105   fprintf(stderr, "[inputfile]\n");
106 #endif
107
108   fprintf(stderr, "Switches (names may be abbreviated):\n");
109   fprintf(stderr, "  -colors N      Reduce image to no more than N colors\n");
110   fprintf(stderr, "  -fast          Fast, low-quality processing\n");
111   fprintf(stderr, "  -grayscale     Force grayscale output\n");
112 #ifdef IDCT_SCALING_SUPPORTED
113   fprintf(stderr, "  -scale M/N     Scale output image by fraction M/N, eg, 1/8\n");
114 #endif
115 #ifdef BMP_SUPPORTED
116   fprintf(stderr, "  -bmp           Select BMP output format (Windows style)%s\n",
117           (DEFAULT_FMT == FMT_BMP ? " (default)" : ""));
118 #endif
119 #ifdef GIF_SUPPORTED
120   fprintf(stderr, "  -gif           Select GIF output format%s\n",
121           (DEFAULT_FMT == FMT_GIF ? " (default)" : ""));
122 #endif
123 #ifdef BMP_SUPPORTED
124   fprintf(stderr, "  -os2           Select BMP output format (OS/2 style)%s\n",
125           (DEFAULT_FMT == FMT_OS2 ? " (default)" : ""));
126 #endif
127 #ifdef PPM_SUPPORTED
128   fprintf(stderr, "  -pnm           Select PBMPLUS (PPM/PGM) output format%s\n",
129           (DEFAULT_FMT == FMT_PPM ? " (default)" : ""));
130 #endif
131 #ifdef RLE_SUPPORTED
132   fprintf(stderr, "  -rle           Select Utah RLE output format%s\n",
133           (DEFAULT_FMT == FMT_RLE ? " (default)" : ""));
134 #endif
135 #ifdef TARGA_SUPPORTED
136   fprintf(stderr, "  -targa         Select Targa output format%s\n",
137           (DEFAULT_FMT == FMT_TARGA ? " (default)" : ""));
138 #endif
139   fprintf(stderr, "Switches for advanced users:\n");
140 #ifdef DCT_ISLOW_SUPPORTED
141   fprintf(stderr, "  -dct int       Use integer DCT method%s\n",
142           (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
143 #endif
144 #ifdef DCT_IFAST_SUPPORTED
145   fprintf(stderr, "  -dct fast      Use fast integer DCT (less accurate)%s\n",
146           (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
147 #endif
148 #ifdef DCT_FLOAT_SUPPORTED
149   fprintf(stderr, "  -dct float     Use floating-point DCT method%s\n",
150           (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
151 #endif
152   fprintf(stderr, "  -dither fs     Use F-S dithering (default)\n");
153   fprintf(stderr, "  -dither none   Don't use dithering in quantization\n");
154   fprintf(stderr, "  -dither ordered  Use ordered dither (medium speed, quality)\n");
155 #ifdef QUANT_2PASS_SUPPORTED
156   fprintf(stderr, "  -map FILE      Map to colors used in named image file\n");
157 #endif
158   fprintf(stderr, "  -nosmooth      Don't use high-quality upsampling\n");
159 #ifdef QUANT_1PASS_SUPPORTED
160   fprintf(stderr, "  -onepass       Use 1-pass quantization (fast, low quality)\n");
161 #endif
162   fprintf(stderr, "  -maxmemory N   Maximum memory to use (in kbytes)\n");
163   fprintf(stderr, "  -outfile name  Specify name for output file\n");
164   fprintf(stderr, "  -verbose  or  -debug   Emit debug output\n");
165   exit(EXIT_FAILURE);
166 }
167
168
169 LOCAL(int)
170 parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
171                 int last_file_arg_seen, boolean for_real)
172 /* Parse optional switches.
173  * Returns argv[] index of first file-name argument (== argc if none).
174  * Any file names with indexes <= last_file_arg_seen are ignored;
175  * they have presumably been processed in a previous iteration.
176  * (Pass 0 for last_file_arg_seen on the first or only iteration.)
177  * for_real is FALSE on the first (dummy) pass; we may skip any expensive
178  * processing.
179  */
180 {
181   int argn;
182   char * arg;
183
184   /* Set up default JPEG parameters. */
185   requested_fmt = DEFAULT_FMT;  /* set default output file format */
186   outfilename = NULL;
187   cinfo->err->trace_level = 0;
188
189   /* Scan command line options, adjust parameters */
190
191   for (argn = 1; argn < argc; argn++) {
192     arg = argv[argn];
193     if (*arg != '-') {
194       /* Not a switch, must be a file name argument */
195       if (argn <= last_file_arg_seen) {
196         outfilename = NULL;     /* -outfile applies to just one input file */
197         continue;               /* ignore this name if previously processed */
198       }
199       break;                    /* else done parsing switches */
200     }
201     arg++;                      /* advance past switch marker character */
202
203     if (keymatch(arg, "bmp", 1)) {
204       /* BMP output format. */
205       requested_fmt = FMT_BMP;
206
207     } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
208                keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) {
209       /* Do color quantization. */
210       int val;
211
212       if (++argn >= argc)       /* advance to next argument */
213         usage();
214       if (sscanf(argv[argn], "%d", &val) != 1)
215         usage();
216       cinfo->desired_number_of_colors = val;
217       cinfo->quantize_colors = TRUE;
218
219     } else if (keymatch(arg, "dct", 2)) {
220       /* Select IDCT algorithm. */
221       if (++argn >= argc)       /* advance to next argument */
222         usage();
223       if (keymatch(argv[argn], "int", 1)) {
224         cinfo->dct_method = JDCT_ISLOW;
225       } else if (keymatch(argv[argn], "fast", 2)) {
226         cinfo->dct_method = JDCT_IFAST;
227       } else if (keymatch(argv[argn], "float", 2)) {
228         cinfo->dct_method = JDCT_FLOAT;
229       } else
230         usage();
231
232     } else if (keymatch(arg, "dither", 2)) {
233       /* Select dithering algorithm. */
234       if (++argn >= argc)       /* advance to next argument */
235         usage();
236       if (keymatch(argv[argn], "fs", 2)) {
237         cinfo->dither_mode = JDITHER_FS;
238       } else if (keymatch(argv[argn], "none", 2)) {
239         cinfo->dither_mode = JDITHER_NONE;
240       } else if (keymatch(argv[argn], "ordered", 2)) {
241         cinfo->dither_mode = JDITHER_ORDERED;
242       } else
243         usage();
244
245     } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
246       /* Enable debug printouts. */
247       /* On first -d, print version identification */
248       static boolean printed_version = FALSE;
249
250       if (! printed_version) {
251         fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n",
252                 JVERSION, JCOPYRIGHT);
253         printed_version = TRUE;
254       }
255       cinfo->err->trace_level++;
256
257     } else if (keymatch(arg, "fast", 1)) {
258       /* Select recommended processing options for quick-and-dirty output. */
259       cinfo->two_pass_quantize = FALSE;
260       cinfo->dither_mode = JDITHER_ORDERED;
261       if (! cinfo->quantize_colors) /* don't override an earlier -colors */
262         cinfo->desired_number_of_colors = 216;
263       cinfo->dct_method = JDCT_FASTEST;
264       cinfo->do_fancy_upsampling = FALSE;
265
266     } else if (keymatch(arg, "gif", 1)) {
267       /* GIF output format. */
268       requested_fmt = FMT_GIF;
269
270     } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
271       /* Force monochrome output. */
272       cinfo->out_color_space = JCS_GRAYSCALE;
273
274     } else if (keymatch(arg, "map", 3)) {
275       /* Quantize to a color map taken from an input file. */
276       if (++argn >= argc)       /* advance to next argument */
277         usage();
278       if (for_real) {           /* too expensive to do twice! */
279 #ifdef QUANT_2PASS_SUPPORTED    /* otherwise can't quantize to supplied map */
280         FILE * mapfile;
281
282         if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
283           fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
284           exit(EXIT_FAILURE);
285         }
286         read_color_map(cinfo, mapfile);
287         fclose(mapfile);
288         cinfo->quantize_colors = TRUE;
289 #else
290         ERREXIT(cinfo, JERR_NOT_COMPILED);
291 #endif
292       }
293
294     } else if (keymatch(arg, "maxmemory", 3)) {
295       /* Maximum memory in Kb (or Mb with 'm'). */
296       long lval;
297       char ch = 'x';
298
299       if (++argn >= argc)       /* advance to next argument */
300         usage();
301       if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
302         usage();
303       if (ch == 'm' || ch == 'M')
304         lval *= 1000L;
305       cinfo->mem->max_memory_to_use = lval * 1000L;
306
307     } else if (keymatch(arg, "nosmooth", 3)) {
308       /* Suppress fancy upsampling */
309       cinfo->do_fancy_upsampling = FALSE;
310
311     } else if (keymatch(arg, "onepass", 3)) {
312       /* Use fast one-pass quantization. */
313       cinfo->two_pass_quantize = FALSE;
314
315     } else if (keymatch(arg, "os2", 3)) {
316       /* BMP output format (OS/2 flavor). */
317       requested_fmt = FMT_OS2;
318
319     } else if (keymatch(arg, "outfile", 4)) {
320       /* Set output file name. */
321       if (++argn >= argc)       /* advance to next argument */
322         usage();
323       outfilename = argv[argn]; /* save it away for later use */
324
325     } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) {
326       /* PPM/PGM output format. */
327       requested_fmt = FMT_PPM;
328
329     } else if (keymatch(arg, "rle", 1)) {
330       /* RLE output format. */
331       requested_fmt = FMT_RLE;
332
333     } else if (keymatch(arg, "scale", 1)) {
334       /* Scale the output image by a fraction M/N. */
335       if (++argn >= argc)       /* advance to next argument */
336         usage();
337       if (sscanf(argv[argn], "%d/%d",
338                  &cinfo->scale_num, &cinfo->scale_denom) != 2)
339         usage();
340
341     } else if (keymatch(arg, "targa", 1)) {
342       /* Targa output format. */
343       requested_fmt = FMT_TARGA;
344
345     } else {
346       usage();                  /* bogus switch */
347     }
348   }
349
350   return argn;                  /* return index of next arg (file name) */
351 }
352
353
354 /*
355  * Marker processor for COM and interesting APPn markers.
356  * This replaces the library's built-in processor, which just skips the marker.
357  * We want to print out the marker as text, to the extent possible.
358  * Note this code relies on a non-suspending data source.
359  */
360
361 LOCAL(unsigned int)
362 jpeg_getc (j_decompress_ptr cinfo)
363 /* Read next byte */
364 {
365   struct jpeg_source_mgr * datasrc = cinfo->src;
366
367   if (datasrc->bytes_in_buffer == 0) {
368     if (! (*datasrc->fill_input_buffer) (cinfo))
369       ERREXIT(cinfo, JERR_CANT_SUSPEND);
370   }
371   datasrc->bytes_in_buffer--;
372   return GETJOCTET(*datasrc->next_input_byte++);
373 }
374
375
376 METHODDEF(boolean)
377 print_text_marker (j_decompress_ptr cinfo)
378 {
379   boolean traceit = (cinfo->err->trace_level >= 1);
380   INT32 length;
381   unsigned int ch;
382   unsigned int lastch = 0;
383
384   length = jpeg_getc(cinfo) << 8;
385   length += jpeg_getc(cinfo);
386   length -= 2;                  /* discount the length word itself */
387
388   if (traceit) {
389     if (cinfo->unread_marker == JPEG_COM)
390       fprintf(stderr, "Comment, length %ld:\n", (long) length);
391     else                        /* assume it is an APPn otherwise */
392       fprintf(stderr, "APP%d, length %ld:\n",
393               cinfo->unread_marker - JPEG_APP0, (long) length);
394   }
395
396   while (--length >= 0) {
397     ch = jpeg_getc(cinfo);
398     if (traceit) {
399       /* Emit the character in a readable form.
400        * Nonprintables are converted to \nnn form,
401        * while \ is converted to \\.
402        * Newlines in CR, CR/LF, or LF form will be printed as one newline.
403        */
404       if (ch == '\r') {
405         fprintf(stderr, "\n");
406       } else if (ch == '\n') {
407         if (lastch != '\r')
408           fprintf(stderr, "\n");
409       } else if (ch == '\\') {
410         fprintf(stderr, "\\\\");
411       } else if (isprint(ch)) {
412         putc(ch, stderr);
413       } else {
414         fprintf(stderr, "\\%03o", ch);
415       }
416       lastch = ch;
417     }
418   }
419
420   if (traceit)
421     fprintf(stderr, "\n");
422
423   return TRUE;
424 }
425
426
427 /*
428  * Add for LEON-mjpeg project
429  */
430 void setup_hardware(j_decompress_ptr cinfo)
431 {
432   JQUANT_TBL *qtbl;
433   jpeg_component_info *compptr;
434   int i,j;
435   int qtbl_no[3];
436
437   if((cinfo->in_yccrgbs = fopen("in_yccrgbs.txt", "w"))==NULL){
438     fprintf(stderr,"in_yccrgbs.txt File open error!\n");
439     exit(1);
440   }
441   if((cinfo->out_yccrgbs = fopen("out_yccrgbs.txt", "w"))==NULL){
442     fprintf(stderr,"out_yccrgbs.txt File open error!\n");
443     exit(1);
444   }
445   if((cinfo->in_upycc = fopen("in_upycc.txt", "w"))==NULL){
446     fprintf(stderr,"in_upycc.txt File open error!\n");
447     exit(1);
448   }
449   if((cinfo->out_upycc = fopen("out_upycc.txt", "w"))==NULL){
450     fprintf(stderr,"out_upycc.txt File open error!\n");
451     exit(1);
452   }
453   if((cinfo->in_dct = fopen("in_dct.txt", "w"))==NULL){
454     fprintf(stderr,"in_dct.txt File open error!\n");
455     exit(1);
456   }
457   if((cinfo->in_quant = fopen("in_quant.txt", "w"))==NULL){
458     fprintf(stderr,"in_quant.txt File open error!\n");
459     exit(1);
460   }
461   if((cinfo->inter_dct = fopen("inter_dct.txt", "w"))==NULL){
462     fprintf(stderr,"inter_dct.txt File open error!\n");
463     exit(1);
464   }
465   if((cinfo->out_dct = fopen("out_dct.txt", "w"))==NULL){
466     fprintf(stderr,"out_dct.txt File open error!\n");
467     exit(1);
468   }
469   if((cinfo->in_2ddct = fopen("in_2ddct.txt", "w"))==NULL){
470     fprintf(stderr,"in_2ddct.txt File open error!\n");
471     exit(1);
472   }
473   if((cinfo->in_2dquant = fopen("in_2dquant.txt", "w"))==NULL){
474     fprintf(stderr,"in_2dquant.txt File open error!\n");
475     exit(1);
476   }
477   if((cinfo->in_qtbl = fopen("in_qtbl.txt", "w"))==NULL){
478     fprintf(stderr,"in_qtbl.txt File open error!\n");
479     exit(1);
480   }
481
482   compptr = cinfo->comp_info;
483   for(j=0;j<3;j++,compptr++){
484     qtbl = cinfo->quant_tbl_ptrs[compptr->quant_tbl_no];
485     for(i=0;i<64;i++){
486       fprintf(cinfo->in_qtbl,"%02x\n",(int)qtbl->quantval[i]);
487      }
488    }
489
490
491
492 }
493
494
495 /*
496  * The main program.
497  */
498
499 int
500 main (int argc, char **argv)
501 {
502   struct jpeg_decompress_struct cinfo;
503   struct jpeg_error_mgr jerr;
504 #ifdef PROGRESS_REPORT
505   struct cdjpeg_progress_mgr progress;
506 #endif
507   int file_index;
508   djpeg_dest_ptr dest_mgr = NULL;
509   FILE * input_file;
510   FILE * output_file;
511   JDIMENSION num_scanlines;
512
513   /* On Mac, fetch a command line. */
514 #ifdef USE_CCOMMAND
515   argc = ccommand(&argv);
516 #endif
517
518   progname = argv[0];
519   if (progname == NULL || progname[0] == 0)
520     progname = "djpeg";         /* in case C library doesn't provide it */
521
522   /* Initialize the JPEG decompression object with default error handling. */
523   cinfo.err = jpeg_std_error(&jerr);
524   jpeg_create_decompress(&cinfo);
525   /* Add some application-specific error messages (from cderror.h) */
526   jerr.addon_message_table = cdjpeg_message_table;
527   jerr.first_addon_message = JMSG_FIRSTADDONCODE;
528   jerr.last_addon_message = JMSG_LASTADDONCODE;
529
530   /* Insert custom marker processor for COM and APP12.
531    * APP12 is used by some digital camera makers for textual info,
532    * so we provide the ability to display it as text.
533    * If you like, additional APPn marker types can be selected for display,
534    * but don't try to override APP0 or APP14 this way (see libjpeg.doc).
535    */
536   jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
537   jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);
538
539   /* Now safe to enable signal catcher. */
540 #ifdef NEED_SIGNAL_CATCHER
541   enable_signal_catcher((j_common_ptr) &cinfo);
542 #endif
543
544   /* Scan command line to find file names. */
545   /* It is convenient to use just one switch-parsing routine, but the switch
546    * values read here are ignored; we will rescan the switches after opening
547    * the input file.
548    * (Exception: tracing level set here controls verbosity for COM markers
549    * found during jpeg_read_header...)
550    */
551
552   file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
553
554 #ifdef TWO_FILE_COMMANDLINE
555   /* Must have either -outfile switch or explicit output file name */
556   if (outfilename == NULL) {
557     if (file_index != argc-2) {
558       fprintf(stderr, "%s: must name one input and one output file\n",
559               progname);
560       usage();
561     }
562     outfilename = argv[file_index+1];
563   } else {
564     if (file_index != argc-1) {
565       fprintf(stderr, "%s: must name one input and one output file\n",
566               progname);
567       usage();
568     }
569   }
570 #else
571   /* Unix style: expect zero or one file name */
572   if (file_index < argc-1) {
573     fprintf(stderr, "%s: only one input file\n", progname);
574     usage();
575   }
576 #endif /* TWO_FILE_COMMANDLINE */
577
578   /* Open the input file. */
579   if (file_index < argc) {
580     if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
581       fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
582       exit(EXIT_FAILURE);
583     }
584   } else {
585     /* default input file is stdin */
586     input_file = read_stdin();
587   }
588
589   /* Open the output file. */
590   if (outfilename != NULL) {
591     if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
592       fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
593       exit(EXIT_FAILURE);
594     }
595   } else {
596     /* default output file is stdout */
597     output_file = write_stdout();
598   }
599
600 #ifdef PROGRESS_REPORT
601   start_progress_monitor((j_common_ptr) &cinfo, &progress);
602 #endif
603
604   /* Specify data source for decompression */
605   jpeg_stdio_src(&cinfo, input_file);
606
607   /*LEON-mjpeg project */
608   for(f_num=0;f_num<1000;f_num++){
609
610   /* Read file header, set default decompression parameters */
611   (void) jpeg_read_header(&cinfo, TRUE);
612
613   /* Adjust default decompression parameters by re-parsing the options */
614   file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
615
616   /* Initialize the output module now to let it override any crucial
617    * option settings (for instance, GIF wants to force color quantization).
618    */
619   switch (requested_fmt) {
620 #ifdef BMP_SUPPORTED
621   case FMT_BMP:
622     dest_mgr = jinit_write_bmp(&cinfo, FALSE);
623     break;
624   case FMT_OS2:
625     dest_mgr = jinit_write_bmp(&cinfo, TRUE);
626     break;
627 #endif
628 #ifdef GIF_SUPPORTED
629   case FMT_GIF:
630     dest_mgr = jinit_write_gif(&cinfo);
631     break;
632 #endif
633 #ifdef PPM_SUPPORTED
634   case FMT_PPM:
635     dest_mgr = jinit_write_ppm(&cinfo);
636     break;
637 #endif
638 #ifdef RLE_SUPPORTED
639   case FMT_RLE:
640     dest_mgr = jinit_write_rle(&cinfo);
641     break;
642 #endif
643 #ifdef TARGA_SUPPORTED
644   case FMT_TARGA:
645     dest_mgr = jinit_write_targa(&cinfo);
646     break;
647 #endif
648   default:
649     ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
650     break;
651   }
652   dest_mgr->output_file = output_file;
653
654   /* Start decompressor */
655   (void) jpeg_start_decompress(&cinfo);
656
657   if(f_num == 0){
658     setup_hardware(&cinfo);
659   }
660
661   /* Write output file header */
662   // (*dest_mgr->start_output) (&cinfo, dest_mgr);
663
664   /* Process data */
665   while (cinfo.output_scanline < cinfo.output_height) {
666     num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
667                                         dest_mgr->buffer_height);
668     //   (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
669   }
670
671 #ifdef PROGRESS_REPORT
672   /* Hack: count final pass as done in case finish_output does an extra pass.
673    * The library won't have updated completed_passes.
674    */
675   progress.pub.completed_passes = progress.pub.total_passes;
676 #endif
677
678   /* Finish decompression and release memory.
679    * I must do it in this order because output module has allocated memory
680    * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.
681    */
682   (*dest_mgr->finish_output) (&cinfo, dest_mgr);
683   (void) jpeg_finish_decompress(&cinfo);
684   }
685   jpeg_destroy_decompress(&cinfo);
686
687   /* Close files, if we opened them */
688   if (input_file != stdin)
689     fclose(input_file);
690   if (output_file != stdout)
691     fclose(output_file);
692
693 #ifdef PROGRESS_REPORT
694   end_progress_monitor((j_common_ptr) &cinfo);
695 #endif
696
697   /* All done. */
698   exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
699   return 0;                     /* suppress no-return-value warnings */
700 }