// mpeg2avisve.c
//
// Version 2.1 
// Allgemeines zur Version:
// Die Source basiert auf mpeg2avipx3 Version 0.16B35 (Versionszähler in der global.h)
//
// Entfernt wurden folgende Dateien aus der MPEG2AVILIB,
// da sie nicht in das Projekt eingebunden sind:
//   bbdmux.cpp
//   demuxbuf.cpp
//   demuxbuf.h
//   icm_emul.c
//   idtc.c
//   spatscal.c
//   store.spp
//   storeavi.c
//   subspic.c
//   vobdec.cpp

#include "..\mpeg2avilib\config.h"
#include "..\mpeg2avilib\global.h"
#include "..\mpeg2avilib\mpeg2dec.h"
#include <stdio.h>
//SVE 20.05.2001
#include <direct.h>
//ENDE SVE

void Process_Options _ANSI_ARGS_((int argc, char *argv[]));


void main( int argc, char* argv[] )
{
	InitEngine();
	Process_Options(argc,argv);
	EncodeMpeg2Avi();
}



/* option processing */
void Process_Options(int argc, char *argv[])
{
  int i, LastArg, NextArg;
  int temp;
  int dirSize;

//SVE 20.05.2001 Neue Schalter initialisieren
  m_iDeinterlace=0;
  m_iSharpen=0;
  m_bProcessFilterFile=FALSE;
  m_dSigma=0;
  printf("\nMPEG2AVISVE Version 2.1, released on June 5th 2001,\nbased on %s(MMX) [original code %s].\n",Version,Author);
//SVE ENDE


  /* at least one argument should be present */
  if (argc<2)
  {
    printf("%s(MMX) [original code %s]\n",Version,Author);
    printf("Usage:  mpeg2avi  {options}\n\
Options: -b <file>  input bitstream-file <or> 'streamlist.lst' (see readme) \n\
         -b <file> 0xID [optional] ('ID' = desired stream ID, default=0xE0)\n\
         -f         store/display interlaced video in frame format\n\
                     (if MPEG-2 input & output-mode -o7, -f is REQUIRED)\n\
         -o<n> directory output ( 6:WinGDI 7:AVI(RGB24) 8:AVI(YV12) 9:AVI(YUY2) )\n\
         -q<n>      postfilter quality, -q1 = fast(default), -q0 = HiQ\n\
         -r<n>      Select IDCT function (default='-r1' <32-bit MMX>)\n\
         -@ <lba>   Start DEMUXER at logical block address (VOB input only!)\n\
         -# <a> <b> declare decoding range [#a .. #b] (inclusive)\n\
         -*         print data timestamp (video watermark)\n\
      <options below only affect GDI and AVI output modes (-o6 ... -o9)>\n\
         -s<n>      Use Inverse-Telecine algorithm with frame offset (0..9)\n\
                    (-s0, -s1, -s2, -s3, ..., default is OFF)\n\
         -1 X Y     crop output to <X> * <Y> (crop window is centered)\n\
         -2         downsample output to half-resolution (if both -1 and -2,\n\
                     decoder 1st downsamples frame, then crops it)\n\
         -3X n, -3Y n  adjust aspect-ratio <X> or <Y> direction to n-pixels\n\
         -$ <nnn>   autosplit AVI file after <nnn> megabytes (1024KB chunks)\n\
         -! <nnn>   skip 1 decoded-frame per <nnn> decoded-frames (AVI-only)\n\
         -a         decode video only no audio\n\
         -a0xID     decode video and only audiostream with ID\n\
Examples:  mpeg2avi.exe -b clip04.vob -2 -1 352 240 -3X 320 -3Y 200 -f -o6\n\
           mpeg2avi.exe -b stuff.vob 0xE1 -2 -f0 -s3 -r -o7 output.avi");
    exit(0);
  }

/*         -e  file  enhancement layer bitstream (SNR or Data Partitioning)\n\
         -g         concatenated file format for substitution method (-x)\n\
         -i<n> file information & statistics report  (n: level)\n\

         -c<n> file conformance report (n: level)\n\
          -l  file  file name pattern for lower layer sequence\n\
         -o<n> file output (0:YUV 1:SIF 2:TGA 3:PPM 6:WinGDI 7:AVI 8:AVI*)\n\
         -q         disable warnings to stderr\n\
                   (for spatial scalability)\n\
           -t        enable low level tracing to stdout\n\
         -u  file   print user_data to stdio or file\n\
           -vn       verbose output (n: level)\n\
           -x  file  filename pattern of picture substitution sequence\n\n\
File patterns:  for sequential filenames, \"printf\" style, e.g. rec%%d\n\
                 or rec%%d%%c for fieldwise storage\n\
Levels:        0:none 1:sequence 2:picture 3:slice 4:macroblock 5:block\n\n\
 */

  Output_Type = -1;
  i = 1;

  /* command-line options are proceeded by '-' */

  while(i < argc)
  {
    /* check if this is the last argument */
    LastArg = ((argc-i)==1);

    /* parse ahead to see if another flag immediately follows current
       argument (this is used to tell if a filename is missing) */
    if(!LastArg)
      NextArg = (argv[i+1][0]=='-');
    else
      NextArg = 0;

    /* second character, [1], after '-' is the switch */
    if(argv[i][0]=='-')
    {
      switch(toupper(argv[i][1]))
      {
        /* third character. [2], is the value */

	  case '#':  /* MPEG-decoder frame range limit */
		if ( ( argc - i ) < 2 )
		{
			printf("ERROR: -# must be followed by two parameters [ -# <start> <end>");
			printf("\n  <start> = # of starting frame (0 = first frame)");
			printf("\n    <end> = # of last frame (inclusive)");
			exit( ERROR );
		}

		SETOPT( UserOptFRangeStart, atoi( argv[++i] ) );
		SETOPT( UserOptFRangeEnd, atoi( argv[++i] ) );

		if ( GETOPT( UserOptFRangeStart )< 0 || GETOPT( UserOptFRangeEnd )< 0 
			|| GETOPT( UserOptFRangeStart ) > GETOPT( UserOptFRangeEnd ) )
		{
			fprintf( stderr, "ERROR: FRangeStart(%ld) and FRangeEnd(%ld) value(s) invalid!\n",
				GETOPT( UserOptFRangeStart ), GETOPT( UserOptFRangeEnd ) );
			exit(ERROR);
		}

		break;

	  case '@': /* AVI-writer file-length limit, autosplit */
		if ( !LastArg )
		{
			SETOPT( UserOptVOBStartLBA, atoi( argv[++i] ) );
			if ( GETOPT( UserOptVOBStartLBA ) < 0 )
			{
				fprintf( stderr, "ERROR : '-@ <lba>', lba must be positive!" );
				exit( ERROR );
			}
		}
		else
		{
			fprintf( stderr, "ERROR : '-@ <lba>' requires 1 parameter!" );
			fprintf( stderr, "\n\t<lba> = logical block address (1 block=2048 bytes)");
			fprintf( stderr, "\n\n\tThe demuxer starts decoding at the specified LBA.");
			fprintf( stderr, "\n\tThe starting LBA must contain a SYSTEM HEADER!");
			exit( ERROR );
		}
		break;

	  case '$': /* AVI-writer file-length limit, autosplit */
		if ( !LastArg )
		{
			if ( ( atoi( argv[i+1] ) < 0 ) || ( atoi( argv[i+1] ) > 2047 ) )
			{
				fprintf( stderr, "ERROR : '-$ <nnn>', <nnn> is outside legal range!" );
				fprintf( stderr, "\n\t<nnn> is in units of megabytes (1024KB)" );
				fprintf( stderr, "\n\t<nnn> = 1 ... 2047 ");
				exit( ERROR );
			}
			/* legal value, record it */
			SETOPT(UserOptAVISplitLength, ( atoi( argv[ ++i ] ) << 20 ) );
		}
		else
		{
			fprintf( stderr, "ERROR: must specify a value <nnn> (megabytes) for '-$ <nnn>'");
			fprintf( stderr, "\n\t<nnn> = 1 ... 2047 ");
			exit( ERROR );
		}
		break;

	  case '!': /* AVI/GDI output skip-1-frame per N */
		if ( !LastArg && ( atoi( argv[i+1] ) > 0 ) )
		{
			SETOPT( UserOptAVISkipEvery, atoi( argv[ ++i ] ) );
		}
		else
		{
			fprintf( stderr, "ERROR: must specify a value <nnn> (interval in #frames) for ");
			fprintf( stderr, "\n\t'-!' option.  Every <n>th frame is not written to AVI.");
			fprintf( stderr, "\n\t(the frame is decoded, but not sent to output-routine.");
		}
		break;

	  case '*': /* Print MPEG frame# in upper-left corner of frame */
		SETOPT( UserOptPrintFrameCode, TRUE );
		break;

      case '1': /* output picture cropping, does not adjust aspect-ratio */
		
		/* g_AVIcropX and g_AVIcropY are initialized with default values
		   of _DISABLE_CROP...this value is later converted to *valid*
		   picture co-ordinate(s) in store_avi_gdi() [store.c] */
		if( ( argc - i ) < 2 )  
        {
          printf("ERROR: -1 must be followed by two parameters [ -1 x y ]\n");
          exit(ERROR);
        }

		SETOPT( UserOptCropX, atoi(argv[++i]) );
		SETOPT( UserOptCropY, atoi(argv[++i]) );
		if ( GETOPT( UserOptCropX )<= 0 || GETOPT( UserOptCropY )<= 0 )
		{
			fprintf( stderr, "ERROR: crop value(s) must be positive!\n");
			exit(ERROR);
		}
		break;

      case '2': /* half video resolution */
        g_vHalfResFlag = 1; 
		break;
	  case '3': /* arbitrary aspect-ratio control */
		if ( !LastArg )
		  switch ( toupper( argv[i][2] ) )
		  {
			case 'X' : /* horizontal resolution resizing */
				if ( atoi( argv[ i+1 ] ) <= 0 )
				{
					fprintf( stderr, "\nERROR: downscale size is negative (%d)",
						atoi( argv[ i+1 ] ) );
					exit( ERROR );
				}
				SETOPT( UserOptResizeX,atoi(argv[++i]) );
				break;
			case 'Y' : /* vertical resolution resizing */
				SETOPT( UserOptResizeY,atoi(argv[++i]) );
				break;
			default:
				printf("ERROR: valid options are '-vX <n>' and '-vY <n>'\n");
				printf("       <n>=(output size in pixels, n must be LESS THAN source's size)");
				printf("\nexamples: (MPEG-2 720x480 input)");
				printf("\n  mpeg2avi.exe -b input.vob -3Y 408  (16:9 film-> PC letterbox)");
				printf("\n  mpeg2avi ... -3X 424 -3Y 240 -1 352 240 (16:9 film-> 1/2-res pans&scan)");
				printf("\n  mpeg2avi ... -3X 640 -1 640 480 (4:3 NTSC TV -> PC/VGA 4:3)");
				exit(ERROR);
		} /* end switch */
		else
        {
		  printf("ERROR: valid options are '-vX <n>' and '-vY <n>'\n");
		  printf("       <n>=(output size in pixels, n must be LESS THAN source's size)");
		  printf("\nexamples: (MPEG-2 720x480 input)");
		  printf("\n  mpeg2avi.exe -b input.vob -3Y 408  (16:9 film-> PC letterbox)");
		  printf("\n  mpeg2avi ... -3X 424 -3Y 240 -1 352 240 (16:9 film-> 1/2-res pans&scan)");
		  printf("\n  mpeg2avi ... -3X 640 -1 640 480 (4:3 NTSC TV -> PC/VGA 4:3)");
		  exit(ERROR );
		}

		break;
      case 'B':
        Main_Bitstream_Flag = 1;

        if(NextArg || LastArg)
        {
          printf("ERROR: '-b' must be followed by input file (MPG/VOB), ");
		  printf("or a 'streamlist'.\n\t(The streamlist's extension must == '*.lst')");
		  printf("\n\nExamples : mpeg2avi -b movie_trailer.vob -f -2 -o6");
		  printf("\n  <streamlist>  mpeg2avi -b filelist.lst -f -2 -o6");
		  printf("\n\nSee the sample.lst & readme.txt for more info on streamlists.");
		  exit( ERROR );
		}
        else
		{
          Main_Bitstream_Filename = argv[++i]; 
		  // check for additional parameter, Stream ID?
		  if ( ( argc - i ) > 1 )
		  {	// at least one more parameter!
			  if ( argv[i+1][0] != '-' )
			  {   // get VOBstreamID
				  sscanf( argv[++i], "%X", &temp );
				  if ( temp > 0 && temp < 256 )
					  SETOPT( UserOptVOBStreamID, temp );
			  }
		  }
		}


        break;


      case 'C':

#ifdef VERIFY
        Verify_Flag = atoi(&argv[i][2]); 

        if((Verify_Flag < NO_LAYER) || (Verify_Flag > ALL_LAYERS))
        {
          printf("ERROR: -c level (%d) out of range [%d,%d]\n",
            Verify_Flag, NO_LAYER, ALL_LAYERS);
          exit(ERROR);
        }
#else  /* VERIFY */
        printf("This program not compiled for Verify_Flag option\n");
#endif /* VERIFY */
        break;
//SVE 20.05.2001 Neuer Schalter: -D### = Deinterlace mit Threshold (0-255)
      case 'D':
		  m_iDeinterlace=1;
		  switch(argv[i][2])
		  {
		  case 0:
		  case '1':
			  m_iDeinterlace=1;
			  break;
		  case '2':
			  m_iDeinterlace=2;
			  break;
		  case 'f':
		  case 'F':
			  m_iDeinterlace=3;
			  break;
		  default:	
            printf("ERROR: only -d1 or -d2 allowed\n");
            exit(ERROR);
		  }
		  break;
//SVE ENDE

      case 'E':
        Two_Streams = 1; /* either Data Partitioning (DP) or SNR Scalability enhancment */
	                   
        if(NextArg || LastArg)
        {
          printf("ERROR: -e must be followed by filename\n");
          exit(ERROR);
        }
        else
          Enhancement_Layer_Bitstream_Filename = argv[++i]; 

        break;


      case 'F':
		/* record user's choice regarding frame-rate, overrides _ASK_USER */
		if ( argv[ i ][ 2 ] != 0 ) /* user may not have entered a # */
		{
			SETOPT( UserOptAVIrate, atoi( &argv[i][2]) );
			// g_AVIrate = atoi( &argv[i][2]);
		}
        Frame_Store_Flag = 1;
        break;

      case 'G':
        Big_Picture_Flag = 1;
        break;

//SVE 20.05.2001 Neuer Schalter: -H### = Sharpen mit Angabe der Stärke (0 - 100)
      case 'H':
		  m_iSharpen=1;
		  switch(argv[i][2])
		  {
		  case '1':
			m_iSharpen=1;
			break;
		  case '2':
			m_iSharpen=2;
			break;
		  case '3':
			m_iSharpen=3;
			break;
		  case '4':
			m_iSharpen=4;
			break;
		  case '5':
			m_iSharpen=5;
			break;
		  case '6':
			m_iSharpen=6;
			break;
		  default:	
            printf("ERROR: only -h1 to -h6 allowed\n");
            exit(ERROR);
		  }
		  m_dSigma=5.0;
		  switch(argv[i][3])
		  {
		  case '1':
			m_dSigma=0.5;
			break;
		  case '2':
			m_dSigma=1.0;
			break;
		  case '3':
			m_dSigma=1.5;
			break;
		  case '4':
			m_dSigma=2.0;
			break;
		  case '5':
			m_dSigma=2.5;
			break;
		  case '6':
			m_dSigma=3.0;
			break;
		  case '7':
			m_dSigma=3.5;
			break;
		  case '8':
			m_dSigma=4.0;
			break;
		  case '9':
			m_dSigma=4.5;
			break;
		  }
		  break;
//SVE ENDE

      case 'I':
#ifdef VERIFY
        Stats_Flag = atoi(&argv[i][2]); 
#else /* VERIFY */
        printf("WARNING: This program not compiled for -i option\n");
#endif /* VERIFY */     
        break;
    
      case 'L':  /* spatial scalability flag */
        Spatial_Flag = 1;

       if(NextArg || LastArg)
       {
         printf("ERROR: -l must be followed by filename\n");
         exit(ERROR);
       }
       else
         Lower_Layer_Picture_Filename = argv[++i]; 

        break;

      case 'O':
  
        Output_Type = atoi(&argv[i][2]); 
  
		/* AVI output now defaults to integer IDCT */
		/*if ( Output_Type == 7 )	
			Reference_IDCT_Flag = 1; */

        if((Output_Type==4) || (Output_Type==5) || (Output_Type==6) )
          Output_Picture_Filename[0] = 0; /* no need of filename */
        else if(NextArg || LastArg)  
        {
          printf("ERROR: -o%d must be followed by filename\n", Output_Type );
          exit(ERROR);
        }
        else
		{
        /* filename is separated by space, so it becomes the next argument */
		  strcpy(Output_Directory, argv[++i]);
//SVE 20.05.2001 Verzeichnis erstellen, falls nicht vorhanden
		  if(Output_Directory[strlen(Output_Directory)-1]=='\\')
			  Output_Directory[strlen(Output_Directory)-1]=0;
		  _mkdir(Output_Directory);
		  strcat(Output_Directory,"\\");
//		  dirSize = strlen(Output_Directory);
//		  if (Output_Directory[dirSize - 1] != '\\')
//		  {
//			  Output_Directory[dirSize] = '\\';
//			  Output_Directory[dirSize + 1] = 0;
//		  }
//SVE ENDE
          strcpy(Output_Picture_Filename, Output_Directory); //Output_Directory + "movie.avi"; 
		  strcat(Output_Picture_Filename, "movie.avi");
		}

#ifdef DISPLAY
        if (Output_Type==T_X11HIQ)
        {
          hiQdither = 1;
          Output_Type=T_X11;
        }
#endif /* DISPLAY */
        break;


//SVE 20.05.2001 Neuer Schalter P -> Process FilterFile
      case 'P':
        if(NextArg || LastArg)
        {
          printf("ERROR: -p must be followed by filename\n");
		  exit( ERROR );
        }
		m_bProcessFilterFile=TRUE;
        m_lpProcessFilterFile = argv[++i]; 
        break;
//SVE ENDE

/*      case 'Q':
        Quiet_Flag = 1;
        break;*/

      case 'Q': /* filter quality mode */
		switch( argv[i][2] )
		{
			case '0' :
				g_fastfilter = 0;
				break;
			case '1' :
				g_fastfilter = 1;
				break;
			default:
				fprintf(stderr, "\nERROR: Invalid value (%c) for option -q<n>",
					argv[i][2] );
				fprintf(stderr, "\n    -q0 HiQuality (YUV420 -> RGB24 U/V-pixel interpolation"); 
				fprintf(stderr, "\n                  (for '-2', low-pass FIR filter");
				fprintf(stderr, "\n    -q1 Fast*     (YUV420 -> RGB24 U/V-pixel duplication");
				fprintf(stderr, "\n                  (for '-2', arithmetic average on Y-pixel");
				fprintf(stderr, "\n\n * = DEFAULT, MMX-optimizations available");
				fprintf(stderr, "\n\n     '-3' (aspect ratio) always uses arithmetic pixel averaging");
				
				//fprintf(stderr,   "\n     '-o8' (YV12 AVI mode) non-standard ");
				exit( ERROR );
		}
		break;

      case 'R':	// v0.16B22 let user select from several IDCT functions
		  if ( argv[i][2] != 0 )
			  SETOPT( UserOptIDCT, atoi( &argv[i][2] ) );
		  if ( argv[i][2] == 0 || ( GETOPT(UserOptIDCT) < 0 ) || 
			  ( GETOPT(UserOptIDCT) > 3 ) )
		  {
			fprintf( stderr, "\nERROR: '-r<#>' requires a #!\nChoose an IDCT-function from the table:");
			fprintf( stderr, "\n\n\t  -r0 64-bit D-FPU IDCT (IEEE-1180 compliant)      [ most-accurate ]");
			fprintf( stderr, "\n\n\t* -r1 32-bit MMX32 IDCT (IEEE-1180 compliant)");
			fprintf( stderr, "\n\n\t  -r2 16-bit MMX16 Chen IDCT (not compliant) ");
			fprintf( stderr, "\n\n\t  -r3 16-bit MMX16 AAN IDCT (not compliant)        [ fastest       ]");
//			fprintf( stderr, "\n\n\t( -r4 32-bit INT32 Chen IDCT   *obsolete* ) ");
			fprintf( stderr, "\n\n\t* = DEFAULT");
			fprintf( stderr, "\nMost-accurate IDCT = (-r0)  : Fastest-IDCT = (-r3)" );

			exit( ERROR );
		  }
//          Reference_IDCT_Flag = 1;
        break;

      case 'S':  /* read the user's selection of IVTC start state */
		switch ( argv[i][2] )
		{
		  case '0' :
			SETOPT( UserOptIVTC, 0 );
			break;
		  case '1' :
			SETOPT( UserOptIVTC, 1 );
			break;
		  case '2' :
			SETOPT( UserOptIVTC, 2 );
			break;
		  case '3' :
			SETOPT( UserOptIVTC, 3 );
			break;
		  case '4' :
			SETOPT( UserOptIVTC, 4 );
			break;
		  case '5' :
			SETOPT( UserOptIVTC, 5 );
			break;
		  case '6' :
			SETOPT( UserOptIVTC, 6 );
			break;
		  case '7' :
			SETOPT( UserOptIVTC, 7 );
			break;
		  case '8' :
			SETOPT( UserOptIVTC, 8 );
			break;
		  case '9' :
			SETOPT( UserOptIVTC, 9 );
			break;
		  default :
			  fprintf( stderr, "\nERROR: Invalid IVTC-offset (%c) for option -s!", 
				  argv[i][2] );
			  fprintf( stderr, "  <n> must be between 0..9! (-s0, -s1, -s2, ...)" );
			  fprintf( stderr, "\n  add 'D' for IVTC autoshutdown ( -s0D, -s1D, -s2D, etc.)");
			  fprintf( stderr, "\nTo disable IVTC function, do not include -s<n>");
			  exit( ERROR );
		}

		if ( argv[i][2] ) /* make sure this char isn't NULL, i.e. terminator */
			if ( toupper( argv[i][3] ) == 'D' ) 
				SETOPTAUX( UserOptIVTC, _IVTC_AUTODISABLE );
		break;
      case 'T':
#ifdef TRACE
        Trace_Flag = 1;
#else /* TRACE */
        printf("WARNING: This program not compiled for -t option\n");
#endif /* TRACE */
        break;

      case 'U':
        User_Data_Flag = 1;

      case 'V':
#ifdef VERBOSE
        Verbose_Flag = atoi(&argv[i][2]); 
#else /* VERBOSE */
        printf("This program not compiled for -v option\n");
#endif /* VERBOSE */
        break;


      case 'X':
        Ersatz_Flag = 1;

       if(NextArg || LastArg)
       {
         printf("ERROR: -x must be followed by filename\n"); 
         exit(ERROR);
       }
       else
        Substitute_Picture_Filename = argv[++i]; 

        break;

	  case 'A':
		  if (strlen(argv[i])>2)
		  {
			 sscanf( &argv[i][2], "%X", &temp );
 		     if ( temp > 0 && temp < 256 )
			 {
				 SETOPT( UserOptNoAudioDecoding, temp );
//				 printf("Temp = %d, %s", temp, &argv[i][2]);
			 }
			 else
			 {
				SETOPT( UserOptNoAudioDecoding, 1 );
			 }

			 printf("\n\nstream set to %d", GETOPT(UserOptNoAudioDecoding) );
		  }
		  else
			SETOPT( UserOptNoAudioDecoding, 1 );

		  break;


      default:
        fprintf(stderr,"undefined option -%c ignored. Exiting program\n", 
          argv[i][1]);

        exit(ERROR);
    
      } /* switch() */
    } /* if argv[i][0] == '-' */
    
    i++;

  	/* check for bitstream filename argument (there must always be one, at the very end
	   of the command line arguments */

  } /* while() */


  /* options sense checking */

  if(Main_Bitstream_Flag!=1)
  {
    printf("There must be a main bitstream specified (-b filename)\n");
  }

  /* force display process to show frame pictures */
  if((Output_Type==4 || Output_Type==5) && Frame_Store_Flag)
    Display_Progressive_Flag = 1;
  else
    Display_Progressive_Flag = 0;

#ifdef VERIFY
  /* parse the bitstream, do not actually decode it completely */
  

#if 0
  if(Output_Type==-1)
  {
    Decode_Layer = Verify_Flag;
    printf("FYI: Decoding bitstream elements up to: %s\n", 
      Layer_Table[Decode_Layer]);
  }
  else
#endif
    Decode_Layer = ALL_LAYERS;

#endif /* VERIFY */

  /* no output type specified */
  if(Output_Type==-1)
  {
    Output_Type = 9; 
    Output_Picture_Filename[0] = 0;;
  }


#ifdef DISPLAY
  if (Output_Type==T_X11)
  {
    if(Frame_Store_Flag)
      Display_Progressive_Flag = 1;
    else
      Display_Progressive_Flag = 0;

    Frame_Store_Flag = 1; /* to avoid calling dither() twice */
  }
#endif


}


