3 * This software is modified from djpeg.c
9 * Copyright (C) 1991-1997, Thomas G. Lane.
10 * This file is part of the Independent JPEG Group's software.
11 * For conditions of distribution and use, see the accompanying README file.
13 * This file contains a command-line user interface for the JPEG decompressor.
14 * It should work on any system with Unix- or MS-DOS-style command lines.
16 * Two different command line styles are permitted, depending on the
17 * compile-time switch TWO_FILE_COMMANDLINE:
18 * djpeg [options] inputfile outputfile
19 * djpeg [options] [inputfile]
20 * In the second style, output is always to standard output, which you'd
21 * normally redirect to a file or pipe to some other program. Input is
22 * either from a named file or from standard input (typically redirected).
23 * The second style is convenient on Unix but is unhelpful on systems that
24 * don't support pipes. Also, you MUST use the first style if your system
25 * doesn't do binary I/O to stdin/stdout.
26 * To simplify script writing, the "-outfile" switch is provided. The syntax
27 * djpeg [options] -outfile outputfile inputfile
28 * works regardless of which command line style is used.
31 #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
32 #include "jversion.h" /* for version message */
34 #include <ctype.h> /* to declare isprint() */
36 #ifdef USE_CCOMMAND /* command-line reader for Macintosh */
38 #include <SIOUX.h> /* Metrowerks needs this */
39 #include <console.h> /* ... and this */
42 #include <console.h> /* Think declares it here */
48 /* Create the add-on message string table. */
50 #define JMESSAGE(code,string) string ,
52 static const char * const cdjpeg_message_table[] = {
57 /* Add for LEON MJPEG project */
62 #include <sys/ioctl.h>
66 static int markflag=0;
69 * This list defines the known output image formats
70 * (not all of which need be supported by a given version).
71 * You can change the default output format by defining DEFAULT_FMT;
72 * indeed, you had better do so if you undefine PPM_SUPPORTED.
76 FMT_BMP, /* BMP format (Windows flavor) */
77 FMT_GIF, /* GIF format */
78 FMT_OS2, /* BMP format (OS/2 flavor) */
79 FMT_PPM, /* PPM/PGM (PBMPLUS formats) */
80 FMT_RLE, /* RLE format */
81 FMT_TARGA, /* Targa format */
82 FMT_TIFF /* TIFF format */
85 #ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */
86 #define DEFAULT_FMT FMT_PPM
89 static IMAGE_FORMATS requested_fmt;
93 * Argument-parsing code.
94 * The switch parser is designed to be useful with DOS-style command line
95 * syntax, ie, intermixed switches and file names, where only the switches
96 * to the left of a given file name affect processing of that file.
97 * The main program in this file doesn't actually use this capability...
101 static const char * progname; /* program name for error messages */
102 static char * outfilename; /* for -outfile switch */
104 //#define MAKESTMT(stuff) do { stuff } while (0)
106 #define INPUT_VARS(cinfo) \
107 struct jpeg_source_mgr * datasrc = (cinfo)->src; \
108 const JOCTET * next_input_byte = datasrc->next_input_byte; \
109 size_t bytes_in_buffer = datasrc->bytes_in_buffer
111 /* Reload the local copies --- used only in MAKE_BYTE_AVAIL */
112 #define INPUT_RELOAD(cinfo) \
113 ( next_input_byte = datasrc->next_input_byte, \
114 bytes_in_buffer = datasrc->bytes_in_buffer )
116 /* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available.
117 * Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
118 * but we must reload the local copies after a successful fill.
120 #define MAKE_BYTE_AVAIL(cinfo,action) \
121 if (bytes_in_buffer == 0) { \
122 if (! (*datasrc->fill_input_buffer) (cinfo)) \
124 INPUT_RELOAD(cinfo); \
126 #define INPUT_4BYTES(cinfo, V, action) \
127 MAKESTMT(MAKE_BYTE_AVAIL(cinfo,action); \
129 V = ((unsigned int) GETJOCTET(*next_input_byte++))<<24; \
130 MAKE_BYTE_AVAIL(cinfo,action); \
132 V += ((unsigned int)GETJOCTET(*next_input_byte++))<<16; \
133 MAKE_BYTE_AVAIL(cinfo,action); \
135 V += ((unsigned int)GETJOCTET(*next_input_byte++))<<8; \
136 MAKE_BYTE_AVAIL(cinfo,action); \
138 V += ((unsigned int)GETJOCTET(*next_input_byte++)) ; )
142 * Add for LEON-mjpeg project
144 void setup_hardware(j_decompress_ptr cinfo)
146 // int xres,yres,vbpp,line_len,yfac;
148 unsigned int xmcumax,ymcumax,incaddmcuy,size, incaddy, incadd;
149 int i, j, samp_f, incaddmcux;
150 jpeg_component_info *compptr;
155 struct ioctl_cmdreg regset;
156 struct ioctl_cmdq ioctl_dataq;
157 struct ioctl_offdata offdata;
158 struct ioctl_cmdd datad;
159 unsigned int toregister, cadd;
161 /** V1 framebuffer & motionJPEG support **/
162 if(!(cinfo->fd_framebuffer = open( "/dev/fb0", O_RDWR))){
163 fprintf(stderr,"Framebuffer open error!\n");
167 fprintf(stderr,"Framebuffer was opened successfully\n");
170 if(ioctl(cinfo->fd_framebuffer, FBIOGET_FSCREENINFO, &(cinfo->fb_finfo))){
171 fprintf(stderr,"Framebuffer fixed information get error\n");
174 if(ioctl(cinfo->fd_framebuffer, FBIOGET_VSCREENINFO, &(cinfo->fb_vinfo))){
175 fprintf(stderr, "Framebuffer variable information get error\n");
179 fprintf(stderr, "Framebuffer xsize:%d, ysize:%d, vbpp:%d\n",
180 cinfo->fb_vinfo.xres, cinfo->fb_vinfo.yres, cinfo->fb_vinfo.bits_per_pixel);
182 if(cinfo->fb_vinfo.xres % 16 != 0 || cinfo->fb_vinfo.yres % 16 != 0){
183 fprintf(stderr, "This system support only multiple of 16 X,Y size Framebuffer.\n");
186 if(cinfo->fb_vinfo.bits_per_pixel != 16){
187 fprintf(stderr, "This system support only 16 bits per pixel Framebuffer\n");
190 screensize = cinfo->fb_vinfo.xres * cinfo->fb_vinfo.yres * cinfo->fb_vinfo.bits_per_pixel / 8;
191 cinfo->fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE, MAP_SHARED,cinfo->fd_framebuffer,0);
192 if((int)(cinfo->fbptr) == -1){
193 fprintf(stderr, "Can't get memory map of framebuffer device\n");
196 cinfo->fb_yinc = cinfo->fb_vinfo.bits_per_pixel / 8;
199 printf("setting up hardware\n");
200 cinfo->dev_fd = open("/dev/kmjpeg", O_RDWR);
201 if(cinfo->dev_fd == -1){
202 printf("kmjpeg device file open error\n");
205 regset.fb = cinfo->fb_start_add;
206 xmcumax = cinfo->image_width / 16 -1;
207 ymcumax = cinfo->image_height /16 -1;
208 incaddmcuy = (cinfo->fb_vinfo.xres - (xmcumax +1)*16 )* 2 + 4;
211 fprintf(stderr, "xmcumax = %d, ymcumax = %d, incaddmcuy = %x\n",xmcumax,ymcumax,incaddmcuy);
214 compptr = cinfo->comp_info;
215 for(j=0;j<3;j++,compptr++){
216 h_samp[j] = compptr->h_samp_factor;
217 v_samp[j] = compptr->v_samp_factor;
218 qtbl_no[j] = compptr->quant_tbl_no;
219 printf("h_samp = %d, v_samp = %d, quant table no =%d\n", h_samp[j],v_samp[j],qtbl_no[j]);
222 if(!((h_samp[0] == 2) && (v_samp[0]==2))){
223 printf("this mjpeg file is not 4:1:1 4:2:2\n");
226 if((h_samp[1]==1) && (v_samp[1]==1) && (h_samp[2]==1) && (v_samp[2]==1)){
228 printf("this mjpeg file is 4:1:1\n");
229 }else if((h_samp[1]==1) && (v_samp[1]==2) && (h_samp[2]==1) && (v_samp[2]==2)){
231 printf("this mjpeg file is 4:2:2\n");
233 printf("this mjpeg file is not 4:1:1, 4:2:2\n");
238 size = (unsigned int) ((samp_f <<22) | (ymcumax <<17) | (xmcumax <<11) | incaddmcuy) ;
239 regset.size_info = size;
241 incaddy = cinfo->fb_vinfo.xres * 2 - 28;
242 incaddmcux = -1 *(15 * cinfo->fb_vinfo.xres * 2 - 4);
244 incadd = (unsigned int)((incaddy <<16) |(incaddmcux & 0x0000ffff));
245 regset.incadd = incadd;
248 fprintf(stderr, "ioctl fb_start_add = %x, size_info = %x, incadd = %x\n",regset.fb, regset.size_info, regset.incadd );
249 for(i=0;i<10000;i++);
252 ioctl(cinfo->dev_fd, IOCTL_REGSET, ®set);
254 /* call ioctl for ioremap */
255 ioctl(cinfo->dev_fd, IOCTL_MAP);
258 fprintf(stderr, "Start writing quant table into hardware SRAM\n");
260 compptr = cinfo->comp_info;
261 for(j=0;j<3;j++,compptr++){
262 qtbl = cinfo->quant_tbl_ptrs[qtbl_no[j]];
264 // printf(".%x.",(int)qtbl->quantval[i]);
265 ioctl_dataq.quant[j*64+i] = qtbl->quantval[i];
268 ioctl(cinfo->dev_fd, IOCTL_QTBL, &ioctl_dataq);
272 fprintf(stderr, "Start writing DCCache value into hardware SRAM\n");
276 // printf("DCcache id = %d\n", j);
278 // printf("address=%x, nbits=%d, sym=%x\n", i, cinfo->harddc8nbits[j][i], cinfo->harddc8sym[j][i]);
279 toregister = ((cinfo->harddc8nbits[j][i] & 0x0000000f)<<4) | (cinfo->harddc8sym[j][i] & 0x0000000f);
281 offdata.offset[i%128] = cadd;
282 offdata.data[i%128] = toregister;
283 // printf("offset=%x, data=%x\n",offdata.offset[i%128], offdata.data[i%128]);
285 ioctl(cinfo->dev_fd, IOCTL_DCCACHE, &offdata);
290 memset(&offdata, 0, sizeof(offdata));
293 // printf("ACcache id = %d\n", j);
295 // printf("address=%x, nbits=%d, sym=%x\n", i, cinfo->hardac8nbits[j][i], cinfo->hardac8sym[j][i]);
296 toregister = ((cinfo->hardac8nbits[j][i] & 0x0000000f)<<8) | (cinfo->hardac8sym[j][i] & 0x000000ff);
298 offdata.offset[i%128] = cadd;
299 offdata.data[i%128] = toregister;
300 // printf("offset=%x, data=%x\n", offdata.offset[i%128], offdata.data[i%128]);
302 ioctl(cinfo->dev_fd, IOCTL_ACCACHE, &offdata);
307 printf("maxcodemem\n");
311 datad.data[j+i*32]=cinfo->maxcodemem[i][j];
313 datad.data[j+i*32]= 0;
317 ioctl(cinfo->dev_fd, IOCTL_MAXC, &datad);
319 printf("valoffset\n");
323 datad.data[j+i*32]=cinfo->offsetmem[i][j];
325 datad.data[j+i*32]=0;
329 ioctl(cinfo->dev_fd, IOCTL_OFFS, &datad);
332 printf("huffvalmem\n");
336 offdata.offset[j%128] = j+i*256;
337 offdata.data[j%128] = cinfo->huffvalmem[i][j];
339 ioctl(cinfo->dev_fd, IOCTL_HUFFV, &offdata);
344 /*call ioctl for iounmap */
345 ioctl(cinfo->dev_fd, IOCTL_UNMAP);
346 printf(" end of setup hardware\n");
349 push_mjpegdata(j_decompress_ptr cinfo){
351 struct ioctl_cmdwrite scandata;
353 unsigned int putdata;
355 fprintf(stderr,"function : push_mjpegdata is starting\n");
356 memset(&scandata, 0, sizeof(scandata));
359 // if(f_num == 200)break;
361 INPUT_4BYTES(cinfo, mjdata, exit(0));
362 scandata.fourbdata[i] = mjdata;
363 // fprintf(stderr,"%08X\n",mjdata);
365 ioctl(cinfo->dev_fd, IOCTL_WRITE, &scandata);
366 if(mjdata == 0xd9ffd9ff){
367 jpeg_destroy_decompress(cinfo);
370 // for(i=0;i<100000;i++);
379 /* complain about bad command line */
381 fprintf(stderr, "usage: %s [switches] ", progname);
382 #ifdef TWO_FILE_COMMANDLINE
383 fprintf(stderr, "inputfile outputfile\n");
385 fprintf(stderr, "[inputfile]\n");
388 fprintf(stderr, "Switches (names may be abbreviated):\n");
389 fprintf(stderr, " -fb_add FramebufferAddress (Hexadecimal number of Framebuffer start address. ex:41a00000) \n");
397 parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
398 int last_file_arg_seen, boolean for_real)
399 /* Parse optional switches.
400 * Returns argv[] index of first file-name argument (== argc if none).
401 * Any file names with indexes <= last_file_arg_seen are ignored;
402 * they have presumably been processed in a previous iteration.
403 * (Pass 0 for last_file_arg_seen on the first or only iteration.)
404 * for_real is FALSE on the first (dummy) pass; we may skip any expensive
411 /* Set up default JPEG parameters. */
412 requested_fmt = DEFAULT_FMT; /* set default output file format */
414 cinfo->err->trace_level = 0;
416 /* Scan command line options, adjust parameters */
418 for (argn = 1; argn < argc; argn++) {
421 /* Not a switch, must be a file name argument */
422 if (argn <= last_file_arg_seen) {
423 outfilename = NULL; /* -outfile applies to just one input file */
424 continue; /* ignore this name if previously processed */
426 break; /* else done parsing switches */
428 arg++; /* advance past switch marker character */
430 if (keymatch(arg, "bmp", 1)) {
431 /* BMP output format. */
432 requested_fmt = FMT_BMP;
434 } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
435 keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) {
436 /* Do color quantization. */
439 if (++argn >= argc) /* advance to next argument */
441 if (sscanf(argv[argn], "%d", &val) != 1)
443 cinfo->desired_number_of_colors = val;
444 cinfo->quantize_colors = TRUE;
446 } else if (keymatch(arg, "dct", 2)) {
447 /* Select IDCT algorithm. */
448 if (++argn >= argc) /* advance to next argument */
450 if (keymatch(argv[argn], "int", 1)) {
451 cinfo->dct_method = JDCT_ISLOW;
452 } else if (keymatch(argv[argn], "fast", 2)) {
453 cinfo->dct_method = JDCT_IFAST;
454 } else if (keymatch(argv[argn], "float", 2)) {
455 cinfo->dct_method = JDCT_FLOAT;
459 } else if (keymatch(arg, "dither", 2)) {
460 /* Select dithering algorithm. */
461 if (++argn >= argc) /* advance to next argument */
463 if (keymatch(argv[argn], "fs", 2)) {
464 cinfo->dither_mode = JDITHER_FS;
465 } else if (keymatch(argv[argn], "none", 2)) {
466 cinfo->dither_mode = JDITHER_NONE;
467 } else if (keymatch(argv[argn], "ordered", 2)) {
468 cinfo->dither_mode = JDITHER_ORDERED;
472 } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
473 /* Enable debug printouts. */
474 /* On first -d, print version identification */
475 static boolean printed_version = FALSE;
477 if (! printed_version) {
478 fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n",
479 JVERSION, JCOPYRIGHT);
480 printed_version = TRUE;
482 cinfo->err->trace_level++;
484 } else if (keymatch(arg, "fast", 1)) {
485 /* Select recommended processing options for quick-and-dirty output. */
486 cinfo->two_pass_quantize = FALSE;
487 cinfo->dither_mode = JDITHER_ORDERED;
488 if (! cinfo->quantize_colors) /* don't override an earlier -colors */
489 cinfo->desired_number_of_colors = 216;
490 cinfo->dct_method = JDCT_FASTEST;
491 cinfo->do_fancy_upsampling = FALSE;
493 } else if (keymatch(arg, "gif", 1)) {
494 /* GIF output format. */
495 requested_fmt = FMT_GIF;
497 } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
498 /* Force monochrome output. */
499 cinfo->out_color_space = JCS_GRAYSCALE;
501 } else if (keymatch(arg, "map", 3)) {
502 /* Quantize to a color map taken from an input file. */
503 if (++argn >= argc) /* advance to next argument */
505 if (for_real) { /* too expensive to do twice! */
506 #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
509 if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
510 fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
513 read_color_map(cinfo, mapfile);
515 cinfo->quantize_colors = TRUE;
517 ERREXIT(cinfo, JERR_NOT_COMPILED);
521 } else if (keymatch(arg, "maxmemory", 3)) {
522 /* Maximum memory in Kb (or Mb with 'm'). */
526 if (++argn >= argc) /* advance to next argument */
528 if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
530 if (ch == 'm' || ch == 'M')
532 cinfo->mem->max_memory_to_use = lval * 1000L;
534 } else if (keymatch(arg, "nosmooth", 3)) {
535 /* Suppress fancy upsampling */
536 cinfo->do_fancy_upsampling = FALSE;
538 } else if (keymatch(arg, "onepass", 3)) {
539 /* Use fast one-pass quantization. */
540 cinfo->two_pass_quantize = FALSE;
542 } else if (keymatch(arg, "os2", 3)) {
543 /* BMP output format (OS/2 flavor). */
544 requested_fmt = FMT_OS2;
546 } else if (keymatch(arg, "outfile", 4)) {
547 /* Set output file name. */
548 if (++argn >= argc) /* advance to next argument */
550 outfilename = argv[argn]; /* save it away for later use */
552 } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) {
553 /* PPM/PGM output format. */
554 requested_fmt = FMT_PPM;
556 } else if (keymatch(arg, "rle", 1)) {
557 /* RLE output format. */
558 requested_fmt = FMT_RLE;
560 } else if (keymatch(arg, "scale", 1)) {
561 /* Scale the output image by a fraction M/N. */
562 if (++argn >= argc) /* advance to next argument */
564 if (sscanf(argv[argn], "%d/%d",
565 &cinfo->scale_num, &cinfo->scale_denom) != 2)
568 } else if (keymatch(arg, "targa", 1)) {
569 /* Targa output format. */
570 requested_fmt = FMT_TARGA;
572 } else if (keymatch(arg, "fb_add", 1)) {
573 /* Set Framebuffer address */
576 if (++argn >= argc) /* advance to next argument */
578 if (sscanf(argv[argn], "%x", &xval) != 1)
580 cinfo->fb_start_add = xval;
583 usage(); /* bogus switch */
587 return argn; /* return index of next arg (file name) */
592 * Marker processor for COM and interesting APPn markers.
593 * This replaces the library's built-in processor, which just skips the marker.
594 * We want to print out the marker as text, to the extent possible.
595 * Note this code relies on a non-suspending data source.
599 jpeg_getc (j_decompress_ptr cinfo)
602 struct jpeg_source_mgr * datasrc = cinfo->src;
604 if (datasrc->bytes_in_buffer == 0) {
605 if (! (*datasrc->fill_input_buffer) (cinfo))
606 ERREXIT(cinfo, JERR_CANT_SUSPEND);
608 datasrc->bytes_in_buffer--;
609 return GETJOCTET(*datasrc->next_input_byte++);
614 print_text_marker (j_decompress_ptr cinfo)
616 boolean traceit = (cinfo->err->trace_level >= 1);
619 unsigned int lastch = 0;
621 length = jpeg_getc(cinfo) << 8;
622 length += jpeg_getc(cinfo);
623 length -= 2; /* discount the length word itself */
626 if (cinfo->unread_marker == JPEG_COM)
627 fprintf(stderr, "Comment, length %ld:\n", (long) length);
628 else /* assume it is an APPn otherwise */
629 fprintf(stderr, "APP%d, length %ld:\n",
630 cinfo->unread_marker - JPEG_APP0, (long) length);
633 while (--length >= 0) {
634 ch = jpeg_getc(cinfo);
636 /* Emit the character in a readable form.
637 * Nonprintables are converted to \nnn form,
638 * while \ is converted to \\.
639 * Newlines in CR, CR/LF, or LF form will be printed as one newline.
642 fprintf(stderr, "\n");
643 } else if (ch == '\n') {
645 fprintf(stderr, "\n");
646 } else if (ch == '\\') {
647 fprintf(stderr, "\\\\");
648 } else if (isprint(ch)) {
651 fprintf(stderr, "\\%03o", ch);
658 fprintf(stderr, "\n");
669 main (int argc, char **argv)
671 struct jpeg_decompress_struct cinfo;
672 struct jpeg_error_mgr jerr;
673 #ifdef PROGRESS_REPORT
674 struct cdjpeg_progress_mgr progress;
677 djpeg_dest_ptr dest_mgr = NULL;
680 JDIMENSION num_scanlines;
682 struct timeval j_50f,j_100f;
686 /* On Mac, fetch a command line. */
688 argc = ccommand(&argv);
692 if (progname == NULL || progname[0] == 0)
693 progname = "djpeg"; /* in case C library doesn't provide it */
695 /* Initialize the JPEG decompression object with default error handling. */
696 cinfo.err = jpeg_std_error(&jerr);
697 jpeg_create_decompress(&cinfo);
698 /* Add some application-specific error messages (from cderror.h) */
699 jerr.addon_message_table = cdjpeg_message_table;
700 jerr.first_addon_message = JMSG_FIRSTADDONCODE;
701 jerr.last_addon_message = JMSG_LASTADDONCODE;
703 /* Insert custom marker processor for COM and APP12.
704 * APP12 is used by some digital camera makers for textual info,
705 * so we provide the ability to display it as text.
706 * If you like, additional APPn marker types can be selected for display,
707 * but don't try to override APP0 or APP14 this way (see libjpeg.doc).
709 jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
710 jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);
712 /* Now safe to enable signal catcher. */
713 #ifdef NEED_SIGNAL_CATCHER
714 enable_signal_catcher((j_common_ptr) &cinfo);
717 /* Scan command line to find file names. */
718 /* It is convenient to use just one switch-parsing routine, but the switch
719 * values read here are ignored; we will rescan the switches after opening
721 * (Exception: tracing level set here controls verbosity for COM markers
722 * found during jpeg_read_header...)
725 file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
727 #ifdef TWO_FILE_COMMANDLINE
728 /* Must have either -outfile switch or explicit output file name */
729 if (outfilename == NULL) {
730 if (file_index != argc-2) {
731 fprintf(stderr, "%s: must name one input and one output file\n",
735 outfilename = argv[file_index+1];
737 if (file_index != argc-1) {
738 fprintf(stderr, "%s: must name one input and one output file\n",
744 /* Unix style: expect zero or one file name */
745 if (file_index < argc-1) {
746 fprintf(stderr, "%s: only one input file\n", progname);
749 #endif /* TWO_FILE_COMMANDLINE */
751 /* Open the input file. */
752 if (file_index < argc) {
753 if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
754 fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
758 /* default input file is stdin */
759 input_file = read_stdin();
762 /* Open the output file. */
763 if (outfilename != NULL) {
764 if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
765 fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
769 /* default output file is stdout */
770 output_file = write_stdout();
773 #ifdef PROGRESS_REPORT
774 start_progress_monitor((j_common_ptr) &cinfo, &progress);
777 /* Specify data source for decompression */
778 jpeg_stdio_src(&cinfo, input_file);
780 /*V1 LEON-mjpeg project */
781 for(f_num=0;f_num<110;f_num++){
784 gettimeofday(&j_50f,NULL);
787 gettimeofday(&j_100f,NULL);
790 /* Read file header, set default decompression parameters */
791 (void) jpeg_read_header(&cinfo, TRUE);
793 /* Adjust default decompression parameters by re-parsing the options */
794 file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
796 /* Initialize the output module now to let it override any crucial
797 * option settings (for instance, GIF wants to force color quantization).
799 switch (requested_fmt) {
802 dest_mgr = jinit_write_bmp(&cinfo, FALSE);
805 dest_mgr = jinit_write_bmp(&cinfo, TRUE);
810 dest_mgr = jinit_write_gif(&cinfo);
815 dest_mgr = jinit_write_ppm(&cinfo);
820 dest_mgr = jinit_write_rle(&cinfo);
823 #ifdef TARGA_SUPPORTED
825 dest_mgr = jinit_write_targa(&cinfo);
829 ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
832 dest_mgr->output_file = output_file;
834 /* Start decompressor */
835 (void) jpeg_start_decompress(&cinfo);
838 setup_hardware(&cinfo);
841 /* Write output file header */
842 // (*dest_mgr->start_output) (&cinfo, dest_mgr);
845 push_mjpegdata(&cinfo);
848 // while (cinfo.output_scanline < cinfo.output_height) {
849 // num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
850 // dest_mgr->buffer_height);
851 // (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
854 #ifdef PROGRESS_REPORT
855 /* Hack: count final pass as done in case finish_output does an extra pass.
856 * The library won't have updated completed_passes.
858 progress.pub.completed_passes = progress.pub.total_passes;
861 /* Finish decompression and release memory.
862 * I must do it in this order because output module has allocated memory
863 * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.
865 (*dest_mgr->finish_output) (&cinfo, dest_mgr);
866 (void) jpeg_finish_decompress(&cinfo);
868 jpeg_destroy_decompress(&cinfo);
870 /* Close files, if we opened them */
871 if (input_file != stdin)
873 if (output_file != stdout)
876 #ifdef PROGRESS_REPORT
877 end_progress_monitor((j_common_ptr) &cinfo);
880 fprintf(stderr, "Frame #50 = %d.%d\n", j_50f.tv_sec,j_50f.tv_usec);
881 fprintf(stderr, "Frame #100 = %d.%d\n", j_100f.tv_sec,j_100f.tv_usec);
883 exe_fps = 50/(((double)j_100f.tv_sec + (double)j_100f.tv_usec / 1e6)
884 -((double)j_50f.tv_sec + (double)j_50f.tv_usec / 1e6));
887 fprintf(stderr, "This program decode %f fps\n", exe_fps);
892 exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
893 return 0; /* suppress no-return-value warnings */