]> Creatis software - gdcm.git/blob - src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c
ENH: This lib was leaking like crazy...
[gdcm.git] / src / gdcmmpeg2 / src / mpeg2dec / mpeg2dec.c
1
2 /* mpeg2dec.c, main(), initialization, option processing                    */
3
4 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
5
6 /*
7  * Disclaimer of Warranty
8  *
9  * These software programs are available to the user without any license fee or
10  * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
11  * any and all warranties, whether express, implied, or statuary, including any
12  * implied warranties or merchantability or of fitness for a particular
13  * purpose.  In no event shall the copyright-holder be liable for any
14  * incidental, punitive, or consequential damages of any kind whatsoever
15  * arising from the use of these programs.
16  *
17  * This disclaimer of warranty extends to the user of these programs and user's
18  * customers, employees, agents, transferees, successors, and assigns.
19  *
20  * The MPEG Software Simulation Group does not represent or warrant that the
21  * programs furnished hereunder are free of infringement of any third-party
22  * patents.
23  *
24  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
25  * are subject to royalty fees to patent holders.  Many of these patents are
26  * general enough such that they are unavoidable regardless of implementation
27  * design.
28  *
29  */
30
31 #include <stdlib.h>
32 #include <ctype.h>
33 #include <fcntl.h>
34
35 #define GLOBAL
36 #include "config.h"
37 #include "global.h"
38
39 /* private prototypes */
40 static int  video_sequence _ANSI_ARGS_((int *framenum));
41 static int  Decode_Bitstream _ANSI_ARGS_((void));
42 static int  Headers _ANSI_ARGS_((void));
43 static void Initialize_Sequence _ANSI_ARGS_((void));
44 static void Initialize_Decoder _ANSI_ARGS_((void));
45 static void DeInitialize_Decoder _ANSI_ARGS_((void));
46 static void Deinitialize_Sequence _ANSI_ARGS_((void));
47 static void Process_Options _ANSI_ARGS_((int argc, char *argv[]));
48
49
50 #if OLD
51 static int  Get_Val _ANSI_ARGS_((char *argv[]));
52 #endif
53
54 /* #define DEBUG */
55
56 static void Clear_Options();
57 #ifdef DEBUG
58 static void Print_Options();
59 #endif
60
61
62 int my_open(char *filename)
63 {
64   return open(filename,O_RDONLY|O_BINARY);
65 }
66
67 off_t my_seek(int infile, off_t offset,int whence)
68 {
69   return lseek(infile, offset, whence);
70 }
71 ssize_t my_read(int infile,void *buf,size_t count)
72 {
73   return read(infile,buf,count);
74 }
75 int my_close(int infile)
76 {
77   return close(infile);
78 }
79
80 int my_fopenr(const char *path, const char *mode, istream *os)
81 {
82   FILE *fd = fopen(path, mode);
83   if(fd)
84     {
85     os->InFd = fd;
86     return 1; //success
87     }
88   else
89     os->InFd = NULL;
90   return 0;
91 }
92
93 int my_fopen(const char *path, const char *mode, ostream *os)
94 {
95   FILE *fd = fopen(path, mode);
96   if(fd)
97     {
98     os->OutFd = fd;
99     return 1; //success
100     }
101   else
102     os->OutFd = NULL;
103   return 0;
104 }
105
106 int my_fseek(ostream *stream, long offset, int whence)
107 {
108   return fseek(stream->OutFd, offset, whence);
109 }
110 int my_fseekr(istream *stream, long offset, int whence)
111 {
112   return fseek(stream->InFd, offset, whence);
113 }
114
115 size_t my_fread(void *ptr, size_t size, size_t nmemb, istream *stream)
116 {
117   return fread(ptr, size, nmemb, stream->InFd);
118 }
119
120 size_t my_fwrite(const void *ptr, size_t size, size_t nmemb, ostream *stream)
121 {
122   return fwrite(ptr, size, nmemb, stream->OutFd);
123 }
124
125 int my_fcloser(istream *fp)
126 {
127   return fclose(fp->InFd);
128 }
129 int my_fclose(ostream *fp)
130 {
131   return fclose(fp->OutFd);
132 }
133 #include <stdarg.h>
134
135 int my_printf(const char *format, ...)
136 {
137   //return printf(format, ...);
138   va_list argptr;
139   int ret;
140
141   va_start(argptr, format);
142   ret = vprintf(format, argptr);
143   va_end(argptr);
144
145   return ret;
146 }
147
148 int my_sprintf(char *str, const char *format, ...)
149 {
150   //return sprintf(str, format, ...);
151   va_list argptr;
152   int ret;
153
154   va_start(argptr, format);
155   ret = vsprintf(str,format, argptr);
156   va_end(argptr);
157
158   return ret;
159 }
160
161 int my_fprintf(const char *format, ...)
162 {
163   //return fprintf(stderr, format, ...);
164   va_list argptr;
165   int ret;
166
167   va_start(argptr, format);
168   ret = vfprintf(stderr,format, argptr);
169   va_end(argptr);
170
171   return ret;
172 }
173 void my_exit(int status)
174 {
175   exit(status);
176 }
177
178
179 #define GDCM_BUILD_MPEG2DEC
180
181 #ifdef GDCM_BUILD_MPEG2DEC
182 int main(argc,argv)
183 int argc;
184 char *argv[];
185 {
186   int ret, code;
187   base.open_stream = my_open;
188   base.seek_stream = my_seek;
189   base.read_stream = my_read;
190   base.close_stream = my_close;
191
192   Clear_Options();
193
194   /* decode command line arguments */
195   Process_Options(argc,argv);
196
197 #ifdef DEBUG
198   Print_Options();
199 #endif
200
201   ld = &base; /* select base layer context */
202
203   /* open MPEG base layer bitstream file(s) */
204   /* NOTE: this is either a base layer stream or a spatial enhancement stream */
205 /*  if ((base.Infile=open(Main_Bitstream_Filename,O_RDONLY|O_BINARY))<0) */
206   base.Infile = ld->open_stream(Main_Bitstream_Filename);
207   if( base.Infile < 0 )
208   {
209     fprintf(stderr,"Base layer input file %s not found\n", Main_Bitstream_Filename);
210     exit(1);
211   }
212
213
214   if(base.Infile != 0)
215   {
216     Initialize_Buffer(); 
217   
218     if(Show_Bits(8)==0x47)
219     {
220       sprintf(Error_Text,"Decoder currently does not parse transport streams\n");
221       Error(Error_Text);
222     }
223
224     next_start_code();
225     code = Show_Bits(32);
226
227     switch(code)
228     {
229     case SEQUENCE_HEADER_CODE:
230       break;
231     case PACK_START_CODE:
232       System_Stream_Flag = 1;
233     case VIDEO_ELEMENTARY_STREAM:
234       System_Stream_Flag = 1;
235       break;
236     default:
237       sprintf(Error_Text,"Unable to recognize stream type\n");
238       Error(Error_Text);
239       break;
240     }
241
242     /*lseek(base.Infile, 0l, SEEK_SET);*/
243     ld->seek_stream(base.Infile,0l,SEEK_SET);
244     Initialize_Buffer(); 
245   }
246
247   if(base.Infile!=0)
248   {
249     /*lseek(base.Infile, 0l, SEEK_SET);*/
250     ld->seek_stream(base.Infile,0l,SEEK_SET);
251   }
252
253   Initialize_Buffer(); 
254
255   if(Two_Streams)
256   {
257     ld = &enhan; /* select enhancement layer context */
258
259     /*if ((enhan.Infile = open(Enhancement_Layer_Bitstream_Filename,O_RDONLY|O_BINARY))<0)*/
260     enhan.Infile = ld->open_stream(Enhancement_Layer_Bitstream_Filename);
261     if (enhan.Infile<0)
262     {
263       sprintf(Error_Text,"enhancment layer bitstream file %s not found\n",
264         Enhancement_Layer_Bitstream_Filename);
265
266       Error(Error_Text);
267     }
268
269     Initialize_Buffer();
270     ld = &base;
271   }
272
273   Initialize_Decoder();
274
275   ret = Decode_Bitstream();
276
277   /*close(base.Infile);*/
278   ld->close_stream(base.Infile);
279
280   if (Two_Streams)
281     /*close(enhan.Infile);*/
282     ld->close_stream(enhan.Infile);
283
284   DeInitialize_Decoder();
285
286   return ret;
287 }
288 #endif /*GDCM_BUILD_MPEG2DEC*/
289
290 /* IMPLEMENTATION specific routines */
291 static void Initialize_Decoder()
292 {
293   int i;
294
295   /* Clip table */
296   if (!(Clip=(unsigned char *)malloc(1024)))
297     Error("Clip[] malloc failed\n");
298
299   Clip += 384;
300
301   for (i=-384; i<640; i++)
302     Clip[i] = (i<0) ? 0 : ((i>255) ? 255 : i);
303
304   /* IDCT */
305   if (Reference_IDCT_Flag)
306     Initialize_Reference_IDCT();
307   else
308     Initialize_Fast_IDCT();
309
310 }
311
312 static void DeInitialize_Decoder()
313 {
314   free(Clip-384); // WTF !!!
315 }
316
317 /* mostly IMPLEMENTAION specific rouintes */
318 static void Initialize_Sequence()
319 {
320   int cc, size;
321   static int Table_6_20[3] = {6,8,12};
322
323   /* check scalability mode of enhancement layer */
324   if (Two_Streams && (enhan.scalable_mode!=SC_SNR) && (base.scalable_mode!=SC_DP))
325     Error("unsupported scalability mode\n");
326
327   /* force MPEG-1 parameters for proper decoder behavior */
328   /* see ISO/IEC 13818-2 section D.9.14 */
329   if (!base.MPEG2_Flag)
330   {
331     progressive_sequence = 1;
332     progressive_frame = 1;
333     picture_structure = FRAME_PICTURE;
334     frame_pred_frame_dct = 1;
335     chroma_format = CHROMA420;
336     matrix_coefficients = 5;
337   }
338
339   /* round to nearest multiple of coded macroblocks */
340   /* ISO/IEC 13818-2 section 6.3.3 sequence_header() */
341   mb_width = (horizontal_size+15)/16;
342   mb_height = (base.MPEG2_Flag && !progressive_sequence) ? 2*((vertical_size+31)/32)
343                                         : (vertical_size+15)/16;
344
345   Coded_Picture_Width = 16*mb_width;
346   Coded_Picture_Height = 16*mb_height;
347
348   /* ISO/IEC 13818-2 sections 6.1.1.8, 6.1.1.9, and 6.1.1.10 */
349   Chroma_Width = (chroma_format==CHROMA444) ? Coded_Picture_Width
350                                            : Coded_Picture_Width>>1;
351   Chroma_Height = (chroma_format!=CHROMA420) ? Coded_Picture_Height
352                                             : Coded_Picture_Height>>1;
353   
354   /* derived based on Table 6-20 in ISO/IEC 13818-2 section 6.3.17 */
355   block_count = Table_6_20[chroma_format-1];
356
357   for (cc=0; cc<3; cc++)
358   {
359     if (cc==0)
360       size = Coded_Picture_Width*Coded_Picture_Height;
361     else
362       size = Chroma_Width*Chroma_Height;
363
364     if (!(backward_reference_frame[cc] = (unsigned char *)malloc(size)))
365       Error("backward_reference_frame[] malloc failed\n");
366
367     if (!(forward_reference_frame[cc] = (unsigned char *)malloc(size)))
368       Error("forward_reference_frame[] malloc failed\n");
369
370     if (!(auxframe[cc] = (unsigned char *)malloc(size)))
371       Error("auxframe[] malloc failed\n");
372
373     if(Ersatz_Flag)
374       if (!(substitute_frame[cc] = (unsigned char *)malloc(size)))
375         Error("substitute_frame[] malloc failed\n");
376
377
378     if (base.scalable_mode==SC_SPAT)
379     {
380       /* this assumes lower layer is 4:2:0 */
381       if (!(llframe0[cc] = (unsigned char *)malloc((lower_layer_prediction_horizontal_size*lower_layer_prediction_vertical_size)/(cc?4:1))))
382         Error("llframe0 malloc failed\n");
383       if (!(llframe1[cc] = (unsigned char *)malloc((lower_layer_prediction_horizontal_size*lower_layer_prediction_vertical_size)/(cc?4:1))))
384         Error("llframe1 malloc failed\n");
385     }
386   }
387
388   /* SCALABILITY: Spatial */
389   if (base.scalable_mode==SC_SPAT)
390   {
391     if (!(lltmp = (short *)malloc(lower_layer_prediction_horizontal_size*((lower_layer_prediction_vertical_size*vertical_subsampling_factor_n)/vertical_subsampling_factor_m)*sizeof(short))))
392       Error("lltmp malloc failed\n");
393   }
394
395 #ifdef DISPLAY
396   if (Output_Type==T_X11)
397   {
398     Initialize_Display_Process("");
399     Initialize_Dither_Matrix();
400   }
401 #endif /* DISPLAY */
402
403 }
404
405 void Error(text)
406 char *text;
407 {
408   fprintf(stderr,text);
409   exit(1);
410 }
411
412 /* Trace_Flag output */
413 void Print_Bits(code,bits,len)
414 int code,bits,len;
415 {
416   int i;
417   for (i=0; i<len; i++)
418     printf("%d",(code>>(bits-1-i))&1);
419 }
420
421
422
423 /* option processing */
424 static void Process_Options(argc,argv)
425 int argc;                  /* argument count  */
426 char *argv[];              /* argument vector */
427 {
428   int i, LastArg, NextArg;
429
430   /* at least one argument should be present */
431   if (argc<2)
432   {
433     printf("\n%s, %s\n",Version,Author);
434     printf("Usage:  mpeg2decode {options}\n"
435 "Options: -b  file  main bitstream (base or spatial enhancement layer)\n"
436 "         -cn file  conformance report (n: level)\n"
437 "         -e  file  enhancement layer bitstream (SNR or Data Partitioning)\n"
438 "         -f        store/display interlaced video in frame format\n"
439 "         -g        concatenated file format for substitution method (-x)\n"
440 "         -in file  information & statistics report  (n: level)\n"
441 "         -l  file  file name pattern for lower layer sequence\n"
442 "                   (for spatial scalability)\n"
443 "         -on file  output format (0:YUV 1:SIF 2:TGA 3:PPM 4:X11 5:X11HiQ)\n"
444 "         -q        disable warnings to stderr\n"
445 "         -r        use double precision reference IDCT\n"
446 "         -t        enable low level tracing to stdout\n"
447 "         -u  file  print user_data to stdio or file\n"
448 "         -vn       verbose output (n: level)\n"
449 "         -x  file  filename pattern of picture substitution sequence\n\n"
450 "File patterns:  for sequential filenames, \"printf\" style, e.g. rec%%d\n"
451 "                 or rec%%d%%c for fieldwise storage\n"
452 "Levels:        0:none 1:sequence 2:picture 3:slice 4:macroblock 5:block\n\n"
453 "Example:       mpeg2decode -b bitstream.mpg -f -r -o0 rec%%d\n"
454 "         \n");
455     exit(0);
456   }
457
458
459   Output_Type = -1;
460   i = 1;
461
462   /* command-line options are proceeded by '-' */
463
464   while(i < argc)
465   {
466     /* check if this is the last argument */
467     LastArg = ((argc-i)==1);
468
469     /* parse ahead to see if another flag immediately follows current
470        argument (this is used to tell if a filename is missing) */
471     if(!LastArg)
472       NextArg = (argv[i+1][0]=='-');
473     else
474       NextArg = 0;
475
476     /* second character, [1], after '-' is the switch */
477     if(argv[i][0]=='-')
478     {
479       switch(toupper(argv[i][1]))
480       {
481         /* third character. [2], is the value */
482       case 'B':
483         Main_Bitstream_Flag = 1;
484
485         if(NextArg || LastArg)
486         {
487           printf("ERROR: -b must be followed the main bitstream filename\n");
488         }
489         else
490           Main_Bitstream_Filename = argv[++i]; 
491
492         break;
493
494
495       case 'C':
496
497 #ifdef VERIFY
498         Verify_Flag = atoi(&argv[i][2]); 
499
500         if((Verify_Flag < NO_LAYER) || (Verify_Flag > ALL_LAYERS))
501         {
502           printf("ERROR: -c level (%d) out of range [%d,%d]\n",
503             Verify_Flag, NO_LAYER, ALL_LAYERS);
504           exit(ERROR);
505         }
506 #else  /* VERIFY */
507         printf("This program not compiled for Verify_Flag option\n");
508 #endif /* VERIFY */
509         break;
510
511       case 'E':
512         Two_Streams = 1; /* either Data Partitioning (DP) or SNR Scalability enhancment */
513                    
514         if(NextArg || LastArg)
515         {
516           printf("ERROR: -e must be followed by filename\n");
517           exit(ERROR);
518         }
519         else
520           Enhancement_Layer_Bitstream_Filename = argv[++i]; 
521
522         break;
523
524
525       case 'F':
526         Frame_Store_Flag = 1;
527         break;
528
529       case 'G':
530         Big_Picture_Flag = 1;
531         break;
532
533
534       case 'I':
535 #ifdef VERIFY
536         Stats_Flag = atoi(&argv[i][2]); 
537 #else /* VERIFY */
538         printf("WARNING: This program not compiled for -i option\n");
539 #endif /* VERIFY */     
540         break;
541     
542       case 'L':  /* spatial scalability flag */
543         Spatial_Flag = 1;
544
545        if(NextArg || LastArg)
546        {
547          printf("ERROR: -l must be followed by filename\n");
548          exit(ERROR);
549        }
550        else
551          Lower_Layer_Picture_Filename = argv[++i]; 
552
553         break;
554
555       case 'O':
556   
557         Output_Type = atoi(&argv[i][2]); 
558   
559         if((Output_Type==4) || (Output_Type==5))
560           Output_Picture_Filename = "";  /* no need of filename */
561         else if(NextArg || LastArg)  
562         {
563           printf("ERROR: -o must be followed by filename\n");
564           exit(ERROR);
565         }
566         else
567         /* filename is separated by space, so it becomes the next argument */
568           Output_Picture_Filename = argv[++i]; 
569
570 #ifdef DISPLAY
571         if (Output_Type==T_X11HIQ)
572         {
573           hiQdither = 1;
574           Output_Type=T_X11;
575         }
576 #endif /* DISPLAY */
577         break;
578
579       case 'Q':
580         Quiet_Flag = 1;
581         break;
582
583       case 'R':
584         Reference_IDCT_Flag = 1;
585         break;
586     
587       case 'T':
588 #ifdef TRACE
589         Trace_Flag = 1;
590 #else /* TRACE */
591         printf("WARNING: This program not compiled for -t option\n");
592 #endif /* TRACE */
593         break;
594
595       case 'U':
596         User_Data_Flag = 1;
597
598       case 'V':
599 #ifdef VERBOSE
600         Verbose_Flag = atoi(&argv[i][2]); 
601 #else /* VERBOSE */
602         printf("This program not compiled for -v option\n");
603 #endif /* VERBOSE */
604         break;
605
606
607       case 'X':
608         Ersatz_Flag = 1;
609
610        if(NextArg || LastArg)
611        {
612          printf("ERROR: -x must be followed by filename\n"); 
613          exit(ERROR);
614        }
615        else
616         Substitute_Picture_Filename = argv[++i]; 
617
618         break;
619
620
621
622       default:
623         fprintf(stderr,"undefined option -%c ignored. Exiting program\n", 
624           argv[i][1]);
625
626         exit(ERROR);
627     
628       } /* switch() */
629     } /* if argv[i][0] == '-' */
630     
631     i++;
632
633     /* check for bitstream filename argument (there must always be one, at the very end
634      of the command line arguments */
635
636   } /* while() */
637
638
639   /* options sense checking */
640
641   if(Main_Bitstream_Flag!=1)
642   {
643     printf("There must be a main bitstream specified (-b filename)\n");
644   }
645
646   /* force display process to show frame pictures */
647   if((Output_Type==4 || Output_Type==5) && Frame_Store_Flag)
648     Display_Progressive_Flag = 1;
649   else
650     Display_Progressive_Flag = 0;
651
652 #ifdef VERIFY
653   /* parse the bitstream, do not actually decode it completely */
654   
655
656 #if 0
657   if(Output_Type==-1)
658   {
659     Decode_Layer = Verify_Flag;
660     printf("FYI: Decoding bitstream elements up to: %s\n", 
661       Layer_Table[Decode_Layer]);
662   }
663   else
664 #endif
665     Decode_Layer = ALL_LAYERS;
666
667 #endif /* VERIFY */
668
669   /* no output type specified */
670   if(Output_Type==-1)
671   {
672     Output_Type = 9; 
673     Output_Picture_Filename = "";
674   }
675
676
677 #ifdef DISPLAY
678   if (Output_Type==T_X11)
679   {
680     if(Frame_Store_Flag)
681       Display_Progressive_Flag = 1;
682     else
683       Display_Progressive_Flag = 0;
684
685     Frame_Store_Flag = 1; /* to avoid calling dither() twice */
686   }
687 #endif
688
689
690 }
691
692
693 #ifdef OLD
694 /* 
695    this is an old routine used to convert command line arguments
696    into integers 
697 */
698 static int Get_Val(argv)
699 char *argv[];
700 {
701   int val;
702
703   if (sscanf(argv[1]+2,"%d",&val)!=1)
704     return 0;
705
706   while (isdigit(argv[1][2]))
707     argv[1]++;
708
709   return val;
710 }
711 #endif
712
713
714
715 static int Headers()
716 {
717   int ret;
718
719   ld = &base;
720   
721
722   /* return when end of sequence (0) or picture
723      header has been parsed (1) */
724
725   ret = Get_Hdr();
726
727
728   if (Two_Streams)
729   {
730     ld = &enhan;
731     if (Get_Hdr()!=ret && !Quiet_Flag)
732       fprintf(stderr,"streams out of sync\n");
733     ld = &base;
734   }
735
736   return ret;
737 }
738
739
740
741 static int Decode_Bitstream()
742 {
743   int ret;
744   int Bitstream_Framenum;
745
746   Bitstream_Framenum = 0;
747
748   for(;;)
749   {
750
751 #ifdef VERIFY
752     Clear_Verify_Headers();
753 #endif /* VERIFY */
754
755     ret = Headers();
756     
757     if(ret==1)
758     {
759       ret = video_sequence(&Bitstream_Framenum);
760     }
761     else
762       return(ret);
763   }
764
765 }
766
767
768 static void Deinitialize_Sequence()
769 {
770   int i;
771
772   /* First clenup the static buffer in store.c */
773   FreeStaticBuffer();
774
775   /* clear flags */
776   base.MPEG2_Flag=0;
777
778   for(i=0;i<3;i++)
779   {
780     free(backward_reference_frame[i]);
781     free(forward_reference_frame[i]);
782     free(auxframe[i]);
783
784     if (base.scalable_mode==SC_SPAT)
785     {
786      free(llframe0[i]);
787      free(llframe1[i]);
788     }
789   }
790
791   if (base.scalable_mode==SC_SPAT)
792     free(lltmp);
793
794 #ifdef DISPLAY
795   if (Output_Type==T_X11) 
796     Terminate_Display_Process();
797 #endif
798 }
799
800
801 static int video_sequence(Bitstream_Framenumber)
802 int *Bitstream_Framenumber;
803 {
804   int Bitstream_Framenum;
805   int Sequence_Framenum;
806   int Return_Value;
807
808   Bitstream_Framenum = *Bitstream_Framenumber;
809   Sequence_Framenum=0;
810
811   Initialize_Sequence();
812
813   /* decode picture whose header has already been parsed in 
814      Decode_Bitstream() */
815
816
817   Decode_Picture(Bitstream_Framenum, Sequence_Framenum);
818
819   /* update picture numbers */
820   if (!Second_Field)
821   {
822     Bitstream_Framenum++;
823     Sequence_Framenum++;
824   }
825
826   /* loop through the rest of the pictures in the sequence */
827   while ((Return_Value=Headers()))
828   {
829     Decode_Picture(Bitstream_Framenum, Sequence_Framenum);
830
831     if (!Second_Field)
832     {
833       Bitstream_Framenum++;
834       Sequence_Framenum++;
835     }
836   }
837
838   /* put last frame */
839   if (Sequence_Framenum!=0)
840   {
841     Output_Last_Frame_of_Sequence(Bitstream_Framenum);
842   }
843
844   Deinitialize_Sequence();
845
846 #ifdef VERIFY
847     Clear_Verify_Headers();
848 #endif /* VERIFY */
849
850   *Bitstream_Framenumber = Bitstream_Framenum;
851   return(Return_Value);
852 }
853
854
855
856 static void Clear_Options()
857 {
858   Verbose_Flag = 0;
859   Output_Type = 0;
860   Output_Picture_Filename = " ";
861   hiQdither  = 0;
862   Output_Type = 0;
863   Frame_Store_Flag = 0;
864   Spatial_Flag = 0;
865   Lower_Layer_Picture_Filename = " ";
866   Reference_IDCT_Flag = 0;
867   Trace_Flag = 0;
868   Quiet_Flag = 0;
869   Ersatz_Flag = 0;
870   Substitute_Picture_Filename  = " ";
871   Two_Streams = 0;
872   Enhancement_Layer_Bitstream_Filename = " ";
873   Big_Picture_Flag = 0;
874   Main_Bitstream_Flag = 0;
875   Main_Bitstream_Filename = " ";
876   Verify_Flag = 0;
877   Stats_Flag  = 0;
878   User_Data_Flag = 0; 
879 }
880
881
882 #ifdef DEBUG
883 static void Print_Options()
884 {
885   
886   printf("Verbose_Flag                         = %d\n", Verbose_Flag);
887   printf("Output_Type                          = %d\n", Output_Type);
888   printf("Output_Picture_Filename              = %s\n", Output_Picture_Filename);
889   printf("hiQdither                            = %d\n", hiQdither);
890   printf("Output_Type                          = %d\n", Output_Type);
891   printf("Frame_Store_Flag                     = %d\n", Frame_Store_Flag);
892   printf("Spatial_Flag                         = %d\n", Spatial_Flag);
893   printf("Lower_Layer_Picture_Filename         = %s\n", Lower_Layer_Picture_Filename);
894   printf("Reference_IDCT_Flag                  = %d\n", Reference_IDCT_Flag);
895   printf("Trace_Flag                           = %d\n", Trace_Flag);
896   printf("Quiet_Flag                           = %d\n", Quiet_Flag);
897   printf("Ersatz_Flag                          = %d\n", Ersatz_Flag);
898   printf("Substitute_Picture_Filename          = %s\n", Substitute_Picture_Filename);
899   printf("Two_Streams                          = %d\n", Two_Streams);
900   printf("Enhancement_Layer_Bitstream_Filename = %s\n", Enhancement_Layer_Bitstream_Filename);
901   printf("Big_Picture_Flag                     = %d\n", Big_Picture_Flag);
902   printf("Main_Bitstream_Flag                  = %d\n", Main_Bitstream_Flag);
903   printf("Main_Bitstream_Filename              = %s\n", Main_Bitstream_Filename);
904   printf("Verify_Flag                          = %d\n", Verify_Flag);
905   printf("Stats_Flag                           = %d\n", Stats_Flag);
906   printf("User_Data_Flag                       = %d\n", User_Data_Flag);
907
908 }
909 #endif
910