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>
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 // for(i=0;i<300000;i++);
367 for(i=0;i<100000;i++);
376 /* complain about bad command line */
378 fprintf(stderr, "usage: %s [switches] ", progname);
379 #ifdef TWO_FILE_COMMANDLINE
380 fprintf(stderr, "inputfile outputfile\n");
382 fprintf(stderr, "[inputfile]\n");
385 fprintf(stderr, "Switches (names may be abbreviated):\n");
386 fprintf(stderr, " -fb_add FramebufferAddress (Hexadecimal number of Framebuffer start address. ex:41a00000) \n");
394 parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
395 int last_file_arg_seen, boolean for_real)
396 /* Parse optional switches.
397 * Returns argv[] index of first file-name argument (== argc if none).
398 * Any file names with indexes <= last_file_arg_seen are ignored;
399 * they have presumably been processed in a previous iteration.
400 * (Pass 0 for last_file_arg_seen on the first or only iteration.)
401 * for_real is FALSE on the first (dummy) pass; we may skip any expensive
408 /* Set up default JPEG parameters. */
409 requested_fmt = DEFAULT_FMT; /* set default output file format */
411 cinfo->err->trace_level = 0;
413 /* Scan command line options, adjust parameters */
415 for (argn = 1; argn < argc; argn++) {
418 /* Not a switch, must be a file name argument */
419 if (argn <= last_file_arg_seen) {
420 outfilename = NULL; /* -outfile applies to just one input file */
421 continue; /* ignore this name if previously processed */
423 break; /* else done parsing switches */
425 arg++; /* advance past switch marker character */
427 if (keymatch(arg, "bmp", 1)) {
428 /* BMP output format. */
429 requested_fmt = FMT_BMP;
431 } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
432 keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) {
433 /* Do color quantization. */
436 if (++argn >= argc) /* advance to next argument */
438 if (sscanf(argv[argn], "%d", &val) != 1)
440 cinfo->desired_number_of_colors = val;
441 cinfo->quantize_colors = TRUE;
443 } else if (keymatch(arg, "dct", 2)) {
444 /* Select IDCT algorithm. */
445 if (++argn >= argc) /* advance to next argument */
447 if (keymatch(argv[argn], "int", 1)) {
448 cinfo->dct_method = JDCT_ISLOW;
449 } else if (keymatch(argv[argn], "fast", 2)) {
450 cinfo->dct_method = JDCT_IFAST;
451 } else if (keymatch(argv[argn], "float", 2)) {
452 cinfo->dct_method = JDCT_FLOAT;
456 } else if (keymatch(arg, "dither", 2)) {
457 /* Select dithering algorithm. */
458 if (++argn >= argc) /* advance to next argument */
460 if (keymatch(argv[argn], "fs", 2)) {
461 cinfo->dither_mode = JDITHER_FS;
462 } else if (keymatch(argv[argn], "none", 2)) {
463 cinfo->dither_mode = JDITHER_NONE;
464 } else if (keymatch(argv[argn], "ordered", 2)) {
465 cinfo->dither_mode = JDITHER_ORDERED;
469 } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
470 /* Enable debug printouts. */
471 /* On first -d, print version identification */
472 static boolean printed_version = FALSE;
474 if (! printed_version) {
475 fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n",
476 JVERSION, JCOPYRIGHT);
477 printed_version = TRUE;
479 cinfo->err->trace_level++;
481 } else if (keymatch(arg, "fast", 1)) {
482 /* Select recommended processing options for quick-and-dirty output. */
483 cinfo->two_pass_quantize = FALSE;
484 cinfo->dither_mode = JDITHER_ORDERED;
485 if (! cinfo->quantize_colors) /* don't override an earlier -colors */
486 cinfo->desired_number_of_colors = 216;
487 cinfo->dct_method = JDCT_FASTEST;
488 cinfo->do_fancy_upsampling = FALSE;
490 } else if (keymatch(arg, "gif", 1)) {
491 /* GIF output format. */
492 requested_fmt = FMT_GIF;
494 } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
495 /* Force monochrome output. */
496 cinfo->out_color_space = JCS_GRAYSCALE;
498 } else if (keymatch(arg, "map", 3)) {
499 /* Quantize to a color map taken from an input file. */
500 if (++argn >= argc) /* advance to next argument */
502 if (for_real) { /* too expensive to do twice! */
503 #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
506 if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
507 fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
510 read_color_map(cinfo, mapfile);
512 cinfo->quantize_colors = TRUE;
514 ERREXIT(cinfo, JERR_NOT_COMPILED);
518 } else if (keymatch(arg, "maxmemory", 3)) {
519 /* Maximum memory in Kb (or Mb with 'm'). */
523 if (++argn >= argc) /* advance to next argument */
525 if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
527 if (ch == 'm' || ch == 'M')
529 cinfo->mem->max_memory_to_use = lval * 1000L;
531 } else if (keymatch(arg, "nosmooth", 3)) {
532 /* Suppress fancy upsampling */
533 cinfo->do_fancy_upsampling = FALSE;
535 } else if (keymatch(arg, "onepass", 3)) {
536 /* Use fast one-pass quantization. */
537 cinfo->two_pass_quantize = FALSE;
539 } else if (keymatch(arg, "os2", 3)) {
540 /* BMP output format (OS/2 flavor). */
541 requested_fmt = FMT_OS2;
543 } else if (keymatch(arg, "outfile", 4)) {
544 /* Set output file name. */
545 if (++argn >= argc) /* advance to next argument */
547 outfilename = argv[argn]; /* save it away for later use */
549 } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) {
550 /* PPM/PGM output format. */
551 requested_fmt = FMT_PPM;
553 } else if (keymatch(arg, "rle", 1)) {
554 /* RLE output format. */
555 requested_fmt = FMT_RLE;
557 } else if (keymatch(arg, "scale", 1)) {
558 /* Scale the output image by a fraction M/N. */
559 if (++argn >= argc) /* advance to next argument */
561 if (sscanf(argv[argn], "%d/%d",
562 &cinfo->scale_num, &cinfo->scale_denom) != 2)
565 } else if (keymatch(arg, "targa", 1)) {
566 /* Targa output format. */
567 requested_fmt = FMT_TARGA;
569 } else if (keymatch(arg, "fb_add", 1)) {
570 /* Set Framebuffer address */
573 if (++argn >= argc) /* advance to next argument */
575 if (sscanf(argv[argn], "%x", &xval) != 1)
577 cinfo->fb_start_add = xval;
580 usage(); /* bogus switch */
584 return argn; /* return index of next arg (file name) */
589 * Marker processor for COM and interesting APPn markers.
590 * This replaces the library's built-in processor, which just skips the marker.
591 * We want to print out the marker as text, to the extent possible.
592 * Note this code relies on a non-suspending data source.
596 jpeg_getc (j_decompress_ptr cinfo)
599 struct jpeg_source_mgr * datasrc = cinfo->src;
601 if (datasrc->bytes_in_buffer == 0) {
602 if (! (*datasrc->fill_input_buffer) (cinfo))
603 ERREXIT(cinfo, JERR_CANT_SUSPEND);
605 datasrc->bytes_in_buffer--;
606 return GETJOCTET(*datasrc->next_input_byte++);
611 print_text_marker (j_decompress_ptr cinfo)
613 boolean traceit = (cinfo->err->trace_level >= 1);
616 unsigned int lastch = 0;
618 length = jpeg_getc(cinfo) << 8;
619 length += jpeg_getc(cinfo);
620 length -= 2; /* discount the length word itself */
623 if (cinfo->unread_marker == JPEG_COM)
624 fprintf(stderr, "Comment, length %ld:\n", (long) length);
625 else /* assume it is an APPn otherwise */
626 fprintf(stderr, "APP%d, length %ld:\n",
627 cinfo->unread_marker - JPEG_APP0, (long) length);
630 while (--length >= 0) {
631 ch = jpeg_getc(cinfo);
633 /* Emit the character in a readable form.
634 * Nonprintables are converted to \nnn form,
635 * while \ is converted to \\.
636 * Newlines in CR, CR/LF, or LF form will be printed as one newline.
639 fprintf(stderr, "\n");
640 } else if (ch == '\n') {
642 fprintf(stderr, "\n");
643 } else if (ch == '\\') {
644 fprintf(stderr, "\\\\");
645 } else if (isprint(ch)) {
648 fprintf(stderr, "\\%03o", ch);
655 fprintf(stderr, "\n");
666 main (int argc, char **argv)
668 struct jpeg_decompress_struct cinfo;
669 struct jpeg_error_mgr jerr;
670 #ifdef PROGRESS_REPORT
671 struct cdjpeg_progress_mgr progress;
674 djpeg_dest_ptr dest_mgr = NULL;
677 JDIMENSION num_scanlines;
679 struct timeval j_50f,j_100f;
683 /* On Mac, fetch a command line. */
685 argc = ccommand(&argv);
689 if (progname == NULL || progname[0] == 0)
690 progname = "djpeg"; /* in case C library doesn't provide it */
692 /* Initialize the JPEG decompression object with default error handling. */
693 cinfo.err = jpeg_std_error(&jerr);
694 jpeg_create_decompress(&cinfo);
695 /* Add some application-specific error messages (from cderror.h) */
696 jerr.addon_message_table = cdjpeg_message_table;
697 jerr.first_addon_message = JMSG_FIRSTADDONCODE;
698 jerr.last_addon_message = JMSG_LASTADDONCODE;
700 /* Insert custom marker processor for COM and APP12.
701 * APP12 is used by some digital camera makers for textual info,
702 * so we provide the ability to display it as text.
703 * If you like, additional APPn marker types can be selected for display,
704 * but don't try to override APP0 or APP14 this way (see libjpeg.doc).
706 jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
707 jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);
709 /* Now safe to enable signal catcher. */
710 #ifdef NEED_SIGNAL_CATCHER
711 enable_signal_catcher((j_common_ptr) &cinfo);
714 /* Scan command line to find file names. */
715 /* It is convenient to use just one switch-parsing routine, but the switch
716 * values read here are ignored; we will rescan the switches after opening
718 * (Exception: tracing level set here controls verbosity for COM markers
719 * found during jpeg_read_header...)
722 file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
724 #ifdef TWO_FILE_COMMANDLINE
725 /* Must have either -outfile switch or explicit output file name */
726 if (outfilename == NULL) {
727 if (file_index != argc-2) {
728 fprintf(stderr, "%s: must name one input and one output file\n",
732 outfilename = argv[file_index+1];
734 if (file_index != argc-1) {
735 fprintf(stderr, "%s: must name one input and one output file\n",
741 /* Unix style: expect zero or one file name */
742 if (file_index < argc-1) {
743 fprintf(stderr, "%s: only one input file\n", progname);
746 #endif /* TWO_FILE_COMMANDLINE */
748 /* Open the input file. */
749 if (file_index < argc) {
750 if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
751 fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
755 /* default input file is stdin */
756 input_file = read_stdin();
759 /* Open the output file. */
760 if (outfilename != NULL) {
761 if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
762 fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
766 /* default output file is stdout */
767 output_file = write_stdout();
770 #ifdef PROGRESS_REPORT
771 start_progress_monitor((j_common_ptr) &cinfo, &progress);
774 /* Specify data source for decompression */
775 jpeg_stdio_src(&cinfo, input_file);
777 /*V1 LEON-mjpeg project */
778 for(f_num=0;f_num<110;f_num++){
781 gettimeofday(&j_50f,NULL);
784 gettimeofday(&j_100f,NULL);
787 /* Read file header, set default decompression parameters */
788 (void) jpeg_read_header(&cinfo, TRUE);
790 /* Adjust default decompression parameters by re-parsing the options */
791 file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
793 /* Initialize the output module now to let it override any crucial
794 * option settings (for instance, GIF wants to force color quantization).
796 switch (requested_fmt) {
799 dest_mgr = jinit_write_bmp(&cinfo, FALSE);
802 dest_mgr = jinit_write_bmp(&cinfo, TRUE);
807 dest_mgr = jinit_write_gif(&cinfo);
812 dest_mgr = jinit_write_ppm(&cinfo);
817 dest_mgr = jinit_write_rle(&cinfo);
820 #ifdef TARGA_SUPPORTED
822 dest_mgr = jinit_write_targa(&cinfo);
826 ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
829 dest_mgr->output_file = output_file;
831 /* Start decompressor */
832 (void) jpeg_start_decompress(&cinfo);
835 setup_hardware(&cinfo);
838 /* Write output file header */
839 // (*dest_mgr->start_output) (&cinfo, dest_mgr);
842 push_mjpegdata(&cinfo);
845 // while (cinfo.output_scanline < cinfo.output_height) {
846 // num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
847 // dest_mgr->buffer_height);
848 // (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
851 #ifdef PROGRESS_REPORT
852 /* Hack: count final pass as done in case finish_output does an extra pass.
853 * The library won't have updated completed_passes.
855 progress.pub.completed_passes = progress.pub.total_passes;
858 /* Finish decompression and release memory.
859 * I must do it in this order because output module has allocated memory
860 * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.
862 (*dest_mgr->finish_output) (&cinfo, dest_mgr);
863 (void) jpeg_finish_decompress(&cinfo);
865 jpeg_destroy_decompress(&cinfo);
867 /* Close files, if we opened them */
868 if (input_file != stdin)
870 if (output_file != stdout)
873 #ifdef PROGRESS_REPORT
874 end_progress_monitor((j_common_ptr) &cinfo);
877 fprintf(stderr, "Frame #50 = %d.%d\n", j_50f.tv_sec,j_50f.tv_usec);
878 fprintf(stderr, "Frame #100 = %d.%d\n", j_100f.tv_sec,j_100f.tv_usec);
880 exe_fps = 50/(((double)j_100f.tv_sec + (double)j_100f.tv_usec / 1e6)
881 -((double)j_50f.tv_sec + (double)j_50f.tv_usec / 1e6));
884 fprintf(stderr, "This program decode %f fps\n", exe_fps);
889 exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
890 return 0; /* suppress no-return-value warnings */