Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

param.c

Go to the documentation of this file.
00001 /*===========================================================================*
00002  * param.c                                                                   *
00003  *                                                                           *
00004  *      Procedures to read in parameter file                                 *
00005  *                                                                           *
00006  * EXPORTED PROCEDURES:                                                      *
00007  *      ReadParamFile                                                        *
00008  *      GetNthInputFileName                                                  *
00009  *                                                                           *
00010  *===========================================================================*/
00011 
00012 /*
00013  * Copyright (c) 1995 The Regents of the University of California.
00014  * All rights reserved.
00015  *
00016  * Permission to use, copy, modify, and distribute this software and its
00017  * documentation for any purpose, without fee, and without written agreement is
00018  * hereby granted, provided that the above copyright notice and the following
00019  * two paragraphs appear in all copies of this software.
00020  *
00021  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
00022  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
00023  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
00024  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025  *
00026  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
00027  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00028  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
00029  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
00030  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
00031  */
00032 
00033 /*  
00034  *  $Header: /misc/elrond0/share/cvs/AFNI/src/mpeg_encodedir/param.c,v 1.4 2004/04/02 15:12:40 rwcox Exp $
00035  *  $Log: param.c,v $
00036  *  Revision 1.4  2004/04/02 15:12:40  rwcox
00037  *  Cput
00038  *
00039  *  Revision 1.3  2003/12/23 13:50:08  rwcox
00040  *  Cput
00041  *
00042  *  Revision 1.2  2003/12/03 14:46:14  rwcox
00043  *  Cput
00044  *
00045  *  Revision 1.1  2001/12/17 16:11:55  rwcox
00046  *  Cadd
00047  *
00048  *  Revision 1.38  1995/08/14 22:29:13  smoot
00049  *  cleaned up subcommand for file name generation
00050  *  fixed bug where foo* didnt work as input string
00051  *
00052  *  Revision 1.37  1995/08/07 21:47:01  smoot
00053  *  allows spaces after lines in param files
00054  *  added SIZE == YUV_SIZE for parallel encoding (otherwise you'd have
00055  *  to parse PPM files in the master server... Ick.
00056  *  So we have it specified)
00057  *
00058  *  Revision 1.36  1995/06/26 21:52:52  smoot
00059  *  allow uppercase stdin
00060  *
00061  *  Revision 1.35  1995/06/21 18:35:01  smoot
00062  *  moved TUNE stuff to opts.c
00063  *  Added ability to do:
00064  *  INPUT
00065  *  file.ppm  [1-10]
00066  *  to do 10 copies
00067  *  added CDL = SPECIFICS
00068  *
00069  * Revision 1.34  1995/05/02  01:48:25  eyhung
00070  * deleted some smootisms. fixed framerate settings, added check for
00071  * invalid input range
00072  *
00073  * Revision 1.33  1995/05/02  01:20:10  smoot
00074  * *** empty log message ***
00075  *
00076  * Revision 1.31  1995/03/09  06:22:36  eyhung
00077  * more robust input checking (whitespace at end of input file spec)
00078  *
00079  * Revision 1.30  1995/02/02  01:06:18  eyhung
00080  * Added error checking for JMOVIE and stdin ; deleted smoot's "understand"
00081  * param file ideas.
00082  *
00083  * Revision 1.29  1995/02/01  21:09:59  eyhung
00084  * Finished infinite coding-on-the-fly
00085  *
00086  * Revision 1.28  1995/01/31  22:34:28  eyhung
00087  * Added stdin as a parameter to INPUT_DIR for interactive encoding
00088  *
00089  * Revision 1.27  1995/01/27  21:58:07  eyhung
00090  * Fixed a bug with reading JMOVIES in GetNthInputFileName
00091  *
00092  * Revision 1.26  1995/01/25  23:00:05  smoot
00093  * Checks out Qtable entries
00094  *
00095  * Revision 1.25  1995/01/23  02:09:51  darryl
00096  * removed "PICT_RATE" code
00097  *
00098  * Revision 1.24  1995/01/20  00:07:46  smoot
00099  * requires unistd.c now
00100  *
00101  * Revision 1.23  1995/01/20  00:05:33  smoot
00102  * Added gamma correction option
00103  *
00104  * Revision 1.22  1995/01/19  23:55:55  eyhung
00105  * Fixed up smoot's "style" and made YUV_FORMAT default to EYUV
00106  *
00107  * Revision 1.21  1995/01/19  23:09:03  eyhung
00108  * Changed copyrights
00109  *
00110  * Revision 1.20  1995/01/17  22:04:14  smoot
00111  * Added `commands` to file name listing
00112  *
00113  * Revision 1.19  1995/01/17  06:28:01  eyhung
00114  * StdinUsed added.
00115  *
00116  * Revision 1.18  1995/01/16  09:33:35  eyhung
00117  * Fixed stupid commenting error.
00118  *
00119  * Revision 1.17  1995/01/16  06:07:53  eyhung
00120  * Made it look a little nicer
00121  *
00122  * Revision 1.16  1995/01/13  23:57:25  smoot
00123  * added Y format
00124  *
00125  * Revision 1.15  1995/01/08  06:20:39  eyhung
00126  * *** empty log message ***
00127  *
00128  * Revision 1.14  1995/01/08  06:15:57  eyhung
00129  * *** empty log message ***
00130  *
00131  * Revision 1.13  1995/01/08  05:50:32  eyhung
00132  * Added YUV Format parameter
00133  *
00134  * Revision 1.12  1994/12/16  00:55:30  smoot
00135  * Fixed INPU_FILES bug
00136  *
00137  * Revision 1.11  1994/12/12  23:54:36  smoot
00138  * Fixed GOP-missing error message (GOP to GOP_SIZE)
00139  *
00140  * Revision 1.10  1994/12/07  00:40:36  smoot
00141  * Added seperate P and B search ranges
00142  *
00143  * Revision 1.9  1994/11/18  23:19:22  smoot
00144  * Added USER_DATA parameter
00145  *
00146  * Revision 1.8  1994/11/16  22:33:40  smoot
00147  * Put in ifdef for rsh in param.c
00148  *
00149  * Revision 1.7  1994/11/16  22:25:05  smoot
00150  * Corrected ASPECT_RATIO bug
00151  *
00152  * Revision 1.6  1994/11/14  22:39:26  smoot
00153  * merged specifics and rate control
00154  *
00155  * Revision 1.5  1994/11/01  05:01:41  darryl
00156  *  with rate control changes added
00157  *
00158  * Revision 1.1  1994/09/27  00:16:28  darryl
00159  * Initial revision
00160  *
00161  * Revision 1.4  1994/03/15  00:27:11  keving
00162  * nothing
00163  *
00164  * Revision 1.3  1993/12/22  19:19:01  keving
00165  * nothing
00166  *
00167  * Revision 1.2  1993/07/22  22:23:43  keving
00168  * nothing
00169  *
00170  * Revision 1.1  1993/06/30  20:06:09  keving
00171  * nothing
00172  *
00173  */
00174 
00175 
00176 /*==============*
00177  * HEADER FILES *
00178  *==============*/
00179 
00180 #include "all.h"
00181 #include "mtypes.h"
00182 #include "mpeg.h"
00183 #include "search.h"
00184 #include "prototypes.h"
00185 #include "parallel.h"
00186 #include "param.h"
00187 #include "readframe.h"
00188 #include "fsize.h"
00189 #include "frames.h"
00190 #include "jpeg.h"
00191 #include <string.h>
00192 #include <ctype.h>
00193 #include "rate.h"
00194 #include "opts.h"
00195 #include <stdio.h>  /* RWCox */
00196 
00197 /*===========*
00198  * CONSTANTS *
00199  *===========*/
00200 
00201 #define INPUT_ENTRY_BLOCK_SIZE   128
00202 
00203 #define FIRST_OPTION           0
00204 #define OPTION_GOP             0
00205 #define OPTION_PATTERN         1
00206 #define OPTION_PIXEL           2
00207 #define OPTION_PQSCALE         3
00208 #define OPTION_OUTPUT          4
00209 #define OPTION_RANGE           5
00210 #define OPTION_PSEARCH_ALG     6
00211 #define OPTION_IQSCALE         7
00212 #define OPTION_INPUT_DIR       8
00213 #define OPTION_INPUT_CONVERT   9
00214 #define OPTION_INPUT          10
00215 #define OPTION_BQSCALE        11
00216 #define OPTION_BASE_FORMAT    12
00217 #define OPTION_SPF            13
00218 #define OPTION_BSEARCH_ALG    14
00219 #define OPTION_REF_FRAME      15
00220 #define LAST_OPTION           15
00221 
00222 /* put any non-required options after LAST_OPTION */
00223 #define OPTION_RESIZE         16
00224 #define OPTION_IO_CONVERT     17
00225 #define OPTION_SLAVE_CONVERT  18
00226 #define OPTION_IQTABLE        19
00227 #define OPTION_NIQTABLE       20
00228 #define OPTION_FRAME_RATE     21
00229 #define OPTION_ASPECT_RATIO   22
00230 #define OPTION_YUV_SIZE       23
00231 #define OPTION_SPECIFICS      24
00232 #define OPTION_DEFS_SPECIFICS 25
00233 #define OPTION_BUFFER_SIZE    26
00234 #define OPTION_BIT_RATE       27
00235 #define OPTION_USER_DATA      28
00236 #define OPTION_YUV_FORMAT     29
00237 #define OPTION_GAMMA          30
00238 #define OPTION_PARALLEL       31
00239 
00240 #define NUM_OPTIONS           31
00241 
00242 /*=======================*
00243  * STRUCTURE DEFINITIONS *
00244  *=======================*/
00245 
00246 typedef struct InputFileEntryStruct {
00247     char    left[256];
00248     char    right[256];
00249     boolean glob;           /* if FALSE, left is complete name */
00250     int     startID;
00251     int     endID;
00252     int     skip;
00253     int     numPadding;     /* -1 if there is none */
00254     int     numFiles;
00255     boolean repeat;
00256 } InputFileEntry;
00257 
00258 
00259 /*==================*
00260  * STATIC VARIABLES *
00261  *==================*/
00262 
00263 static InputFileEntry **inputFileEntries;
00264 static int numInputFileEntries = 0;
00265 static int  maxInputFileEntries;
00266 
00267 
00268 /*==================*
00269  * GLOBAL VARIABLES *
00270  *==================*/
00271 
00272 extern char currentPath[MAXPATHLEN];
00273 extern char currentGOPPath[MAXPATHLEN];
00274 extern char currentFramePath[MAXPATHLEN];
00275 char    outputFileName[256];
00276 int     outputWidth, outputHeight;
00277 int numInputFiles = 0;
00278 char inputConversion[1024];
00279 char ioConversion[1024];
00280 char slaveConversion[1024];
00281 char yuvConversion[256];
00282 char specificsFile[256],specificsDefines[1024]="";
00283 boolean GammaCorrection=FALSE;
00284 float   GammaValue;
00285 unsigned char userDataFileName[256]={0};
00286 boolean specificsOn = FALSE;
00287 boolean optionSeen[NUM_OPTIONS+1];
00288 int numMachines;
00289 char    machineName[MAX_MACHINES][256];
00290 char    userName[MAX_MACHINES][256];
00291 char    executable[MAX_MACHINES][1024];
00292 char    remoteParamFile[MAX_MACHINES][1024];
00293 boolean remote[MAX_MACHINES];
00294 boolean stdinUsed = FALSE;
00295 int mult_seq_headers = 0;  /* 0 for none, N for header/N GOPs */
00296 
00297 /*===============================*
00298  * INTERNAL PROCEDURE prototypes *
00299  *===============================*/
00300 static void     ReadInputFileNames _ANSI_ARGS_((FILE *fpointer,
00301                                                 char *endInput));
00302 static void     ReadMachineNames _ANSI_ARGS_((FILE *fpointer));
00303 static int      GetAspectRatio _ANSI_ARGS_((char *p));
00304 static int      GetFrameRate _ANSI_ARGS_((char *p));
00305 
00306 /*=====================*
00307  * EXPORTED PROCEDURES *
00308  *=====================*/
00309 
00310 
00311 /*===========================================================================*
00312  *
00313  * ReadParamFile
00314  *
00315  *      read the parameter file
00316  *      function is ENCODE_FRAMES, COMBINE_GOPS, or COMBINE_FRAMES, and
00317  *          will slightly modify the procedure's behavior as to what it
00318  *          is looking for in the parameter file
00319  *
00320  * RETURNS:     TRUE if the parameter file was read correctly; FALSE if not
00321  *
00322  * SIDE EFFECTS:    sets parameters accordingly, as well as machine info for
00323  *                  parallel execution and input file names
00324  *
00325  *===========================================================================*/
00326 boolean
00327   ReadParamFile(fileName, function)
00328 char *fileName;
00329 int function;
00330 {
00331   FILE *fpointer;
00332   char    input[256];
00333   char    *charPtr;
00334   boolean yuvUsed = FALSE;
00335   static char *optionText[LAST_OPTION+1] = { "GOP_SIZE", "PATTERN", "PIXEL", "PQSCALE",
00336                                              "OUTPUT", "RANGE", "PSEARCH_ALG", "IQSCALE", "INPUT_DIR",
00337                                              "INPUT_CONVERT", "INPUT", "BQSCALE", "BASE_FILE_FORMAT",
00338                                              "SLICES_PER_FRAME", "BSEARCH_ALG", "REFERENCE_FRAME"};
00339   register int index;
00340   register int row, col;
00341 
00342 #undef RWCox
00343 #ifdef RWCox
00344   /* RWCox - modification to read from stdin if fileName is NULL or "-" */
00345   if( fileName == NULL || strcmp(fileName,"-") == 0 ){
00346     fpointer = stdin ;
00347   } else
00348 #endif
00349   if ( (fpointer = fopen(fileName, "r")) == NULL ) {
00350     fprintf(stderr, "Error:  Cannot open parameter file:  %s\n", fileName);
00351     return FALSE;
00352   }
00353 
00354   /* should set defaults */
00355   numInputFiles = 0;
00356   numMachines = 0;
00357   sprintf(currentPath, ".");
00358   sprintf(currentGOPPath, ".");
00359   sprintf(currentFramePath, ".");
00360 #ifndef HPUX
00361   SetRemoteShell("rsh");
00362 #else
00363   SetRemoteShell("remsh");
00364 #endif
00365 
00366   switch(function) {
00367   case ENCODE_FRAMES:
00368     for ( index = FIRST_OPTION; index <= LAST_OPTION; index++ ) {
00369       optionSeen[index] = FALSE;
00370     }
00371     optionSeen[OPTION_IO_CONVERT] = FALSE;
00372     optionSeen[OPTION_SLAVE_CONVERT] = FALSE;
00373     break;
00374   case COMBINE_GOPS:
00375     for ( index = FIRST_OPTION; index <= LAST_OPTION; index++ ) {
00376       optionSeen[index] = TRUE;
00377     }
00378 
00379     optionSeen[OPTION_OUTPUT] = FALSE;
00380     break;
00381   case COMBINE_FRAMES:
00382     for ( index = FIRST_OPTION; index <= LAST_OPTION; index++ ) {
00383       optionSeen[index] = TRUE;
00384     }
00385 
00386     optionSeen[OPTION_GOP] = FALSE;
00387     optionSeen[OPTION_OUTPUT] = FALSE;
00388     break;
00389   }
00390 
00391   for( index=LAST_OPTION+1; index<= NUM_OPTIONS; index++ ) {
00392     optionSeen[index]=FALSE;
00393   }
00394 
00395   while ( fgets(input, 256, fpointer) != NULL ) {
00396     /* skip comments */
00397     if ( input[0] == '#' ) {            
00398       continue;
00399     }
00400 
00401     {
00402       int len = strlen(input);
00403       if (input[len-1] == '\n') {
00404         len--;
00405         input[len] = '\0'; /* get rid of newline */
00406         /* Junk whitespace */
00407         while ((len >= 0) && ((input[len-1] == ' ') || (input[len-1] == '\t'))) {
00408           input[--len] = '\0';
00409         }
00410       }
00411     }
00412 
00413     if (strlen(SkipSpacesTabs(input)) == 0) continue;
00414 
00415     switch(input[0]) {
00416     case 'A':
00417       if ( strncmp(input, "ASPECT_RATIO", 12) == 0 ) {
00418         charPtr = SkipSpacesTabs(&input[12]);
00419         aspectRatio = GetAspectRatio(charPtr);
00420         optionSeen[OPTION_ASPECT_RATIO] = TRUE;
00421       }
00422       break;
00423 
00424     case 'B':
00425       if ( strncmp(input, "BQSCALE", 7) == 0 ) {
00426         charPtr = SkipSpacesTabs(&input[7]);
00427         SetBQScale(atoi(charPtr));
00428         optionSeen[OPTION_BQSCALE] = TRUE;
00429       } else if ( strncmp(input, "BASE_FILE_FORMAT", 16) == 0 ) {
00430         charPtr = SkipSpacesTabs(&input[16]);
00431         SetFileFormat(charPtr);
00432         if ( (strncmp(charPtr,"YUV",3) == 0) || 
00433             (strcmp(charPtr,"Y") == 0) ) {
00434           yuvUsed = TRUE;
00435         }
00436         optionSeen[OPTION_BASE_FORMAT] = TRUE;
00437       } else if ( strncmp(input, "BSEARCH_ALG", 11) == 0 ) {
00438         charPtr = SkipSpacesTabs(&input[11]);
00439         SetBSearchAlg(charPtr);
00440         optionSeen[OPTION_BSEARCH_ALG] = TRUE;
00441       } else if ( strncmp(input, "BIT_RATE", 8) == 0 ) {
00442         charPtr = SkipSpacesTabs(&input[8]);
00443         setBitRate(charPtr);
00444         optionSeen[OPTION_BIT_RATE] = TRUE;
00445       } else if ( strncmp(input, "BUFFER_SIZE", 11) == 0 ) {
00446         charPtr = SkipSpacesTabs(&input[11]);
00447         setBufferSize(charPtr);
00448         optionSeen[OPTION_BUFFER_SIZE] = TRUE;                  
00449       }
00450       break;
00451 
00452     case 'C':
00453       if ( strncmp(input, "CDL_FILE", 8) == 0 ) {
00454         charPtr = SkipSpacesTabs(&input[8]);
00455         strcpy(specificsFile, charPtr);
00456         specificsOn=TRUE;
00457         optionSeen[OPTION_SPECIFICS] = TRUE;
00458       } else if ( strncmp(input, "CDL_DEFINES", 11) == 0 ) {
00459         charPtr = SkipSpacesTabs(&input[11]);
00460         strcpy(specificsDefines, charPtr);
00461         optionSeen[OPTION_DEFS_SPECIFICS] = TRUE;
00462       }
00463       break;
00464 
00465     case 'F':
00466       if ( strncmp(input, "FRAME_INPUT_DIR", 15) == 0 ) {
00467         charPtr = SkipSpacesTabs(&input[15]);
00468         if ( strncmp(charPtr, "stdin", 5) == 0 ||
00469             strncmp(charPtr, "STDIN", 5) == 0 ) {
00470           stdinUsed = TRUE;
00471           numInputFiles = MAXINT;
00472           numInputFileEntries = 1;
00473         }
00474         strcpy(currentFramePath, charPtr);
00475       } else if ( strncmp(input, "FRAME_INPUT", 11) == 0 ) {
00476         if ( function == COMBINE_FRAMES ) {
00477           ReadInputFileNames(fpointer, "FRAME_END_INPUT");
00478         }
00479       } else if ( strncmp(input, "FORCE_I_ALIGN", 13) == 0 ) {
00480         forceIalign = TRUE;
00481       } else if ( strncmp(input, "FORCE_ENCODE_LAST_FRAME", 23) == 0 ) {
00482         forceEncodeLast = TRUE;
00483       } else if ( strncmp(input, "FRAME_RATE", 10) == 0 ) {
00484         charPtr = SkipSpacesTabs(&input[10]);
00485         frameRate = GetFrameRate(charPtr);
00486         frameRateRounded = (int) VidRateNum[frameRate];
00487         if ( (frameRate % 3) == 1) {
00488           frameRateInteger = FALSE;
00489         }
00490         optionSeen[OPTION_FRAME_RATE] = TRUE;
00491       }
00492       break;
00493 
00494     case 'G':
00495       if ( strncmp(input, "GOP_SIZE", 8) == 0 ) {
00496         charPtr = SkipSpacesTabs(&input[8]);
00497         SetGOPSize(atoi(charPtr));
00498         optionSeen[OPTION_GOP] = TRUE;
00499       } else if ( strncmp(input, "GOP_INPUT_DIR", 13) == 0 ) {
00500         charPtr = SkipSpacesTabs(&input[13]);
00501         if ( strncmp(charPtr, "stdin", 5) == 0 ||
00502             strncmp(charPtr, "STDIN", 5) == 0 ) {
00503           stdinUsed = TRUE;
00504           numInputFiles = MAXINT;
00505           numInputFileEntries = 1;
00506         }
00507         strcpy(currentGOPPath, charPtr);
00508       } else if ( strncmp(input, "GOP_INPUT", 9) == 0 ) {
00509         if ( function == COMBINE_GOPS ) {
00510           ReadInputFileNames(fpointer, "GOP_END_INPUT");
00511         }
00512       } else if ( strncmp(input, "GAMMA", 5) == 0) {
00513         charPtr = SkipSpacesTabs(&input[5]);
00514         GammaCorrection = TRUE;
00515         sscanf(charPtr,"%f",&GammaValue);
00516         optionSeen[OPTION_GAMMA] = TRUE;
00517       }
00518       break;
00519 
00520     case 'I':
00521       if ( strncmp(input, "IQSCALE", 7) == 0 ) {
00522         charPtr = SkipSpacesTabs(&input[7]);
00523         SetIQScale(atoi(charPtr));
00524         optionSeen[OPTION_IQSCALE] = TRUE;
00525       } else if ( strncmp(input, "INPUT_DIR", 9) == 0 ) {
00526         charPtr = SkipSpacesTabs(&input[9]);
00527         if ( strncmp(charPtr, "stdin", 5) == 0 ||
00528             strncmp(charPtr, "STDIN", 5) == 0 ) {
00529           stdinUsed = TRUE;
00530           numInputFiles = MAXINT;
00531           numInputFileEntries = 1;
00532         }
00533         strcpy(currentPath, charPtr);
00534         optionSeen[OPTION_INPUT_DIR] = TRUE;
00535       } else if ( strncmp(input, "INPUT_CONVERT", 13) == 0 ) {
00536         charPtr = SkipSpacesTabs(&input[13]);
00537         strcpy(inputConversion, charPtr);
00538         optionSeen[OPTION_INPUT_CONVERT] = TRUE;
00539       } else if ( strcmp(input, "INPUT") == 0 ) { /* yes, strcmp */
00540         if ( function == ENCODE_FRAMES ) {
00541           ReadInputFileNames(fpointer, "END_INPUT");
00542           optionSeen[OPTION_INPUT] = TRUE;
00543         }
00544       } else if ( strncmp(input, "IO_SERVER_CONVERT", 17) == 0 ) {
00545         charPtr = SkipSpacesTabs(&input[17]);
00546         strcpy(ioConversion, charPtr);
00547         optionSeen[OPTION_IO_CONVERT] = TRUE;
00548       } else if ( strncmp(input, "IQTABLE", 7) == 0 ) {
00549         for ( row = 0; row < 8; row ++ ) {
00550           fgets(input, 256, fpointer);
00551           charPtr = input;
00552           if (8!=sscanf(charPtr,"%d %d %d %d %d %d %d %d",
00553                         &qtable[row*8+0],  &qtable[row*8+1],
00554                         &qtable[row*8+2],  &qtable[row*8+3],
00555                         &qtable[row*8+4],  &qtable[row*8+5],
00556                         &qtable[row*8+6],  &qtable[row*8+7])) {
00557             fprintf(stderr, "Line %d of IQTABLE doesn't have 8 elements!\n", row);
00558             exit(1);
00559           }
00560           for ( col = 0; col < 8; col ++ ) {
00561             if ((qtable[row*8+col]<1) || (qtable[row*8+col]>255)) {
00562               fprintf(stderr,
00563                       "Warning:  IQTable Element %1d,%1d (%d) corrected to 1-255.\n",
00564                       row+1, col+1, qtable[row*8+col]);
00565               qtable[row*8+col] = (qtable[row*8+col]<1)?1:255;
00566             }}
00567         }
00568 
00569         if ( qtable[0] != 8 ) {
00570           fprintf(stderr, "Warning:  IQTable Element 1,1 reset to 8, since it must be 8.\n");
00571           qtable[0] = 8;
00572         }
00573         customQtable = qtable;
00574         optionSeen[OPTION_IQTABLE] = TRUE;
00575       } else if ( strncmp(input, "INPUT", 5) == 0 ) { /* handle spaces after input */
00576         log(10.0);
00577         charPtr = SkipSpacesTabs(&input[5]);
00578         if ( function == ENCODE_FRAMES && *charPtr==0) {
00579           ReadInputFileNames(fpointer, "END_INPUT");
00580           optionSeen[OPTION_INPUT] = TRUE;
00581         }
00582       }
00583       break;
00584 
00585     case 'N':
00586       if ( strncmp(input, "NIQTABLE", 8) == 0 ) {
00587         for ( row = 0; row < 8; row ++ ) {
00588           fgets(input, 256, fpointer);
00589           charPtr = input;
00590           if (8!=sscanf(charPtr,"%d %d %d %d %d %d %d %d",
00591                         &niqtable[row*8+0],  &niqtable[row*8+1],
00592                         &niqtable[row*8+2],  &niqtable[row*8+3],
00593                         &niqtable[row*8+4],  &niqtable[row*8+5],
00594                         &niqtable[row*8+6],  &niqtable[row*8+7])) {
00595             fprintf(stderr, "Line %d of NIQTABLE doesn't have 8 elements!\n", row);
00596             exit(1);
00597           }
00598           for ( col = 0; col < 8; col++ ) {
00599             if ((niqtable[row*8+col]<1) || (niqtable[row*8+col]>255)) {
00600               fprintf(stderr,
00601                       "Warning:  NIQTable Element %1d,%1d (%d) corrected to 1-255.\n",
00602                       row+1, col+1, niqtable[row*8+col]);
00603               niqtable[row*8+col]=(niqtable[row*8+col]<1)?1:255;
00604             }}
00605         }
00606 
00607         customNIQtable = niqtable;
00608         optionSeen[OPTION_NIQTABLE] = TRUE;
00609       }
00610       break;
00611 
00612     case 'O':
00613       if ( strncmp(input, "OUTPUT", 6) == 0 ) {
00614         charPtr = SkipSpacesTabs(&input[6]);
00615         if ( whichGOP == -1 ) {
00616           strcpy(outputFileName, charPtr);
00617         } else {
00618           sprintf(outputFileName, "%s.gop.%d",
00619                   charPtr, whichGOP);
00620         }
00621 
00622         optionSeen[OPTION_OUTPUT] = TRUE;
00623       }
00624       break;
00625 
00626     case 'P':
00627       if ( strncmp(input, "PATTERN", 7) == 0 ) {
00628         charPtr = SkipSpacesTabs(&input[7]);
00629         SetFramePattern(charPtr);
00630         optionSeen[OPTION_PATTERN] = TRUE;
00631       } else if ( strncmp(input, "PIXEL", 5) == 0 ) {
00632         charPtr = SkipSpacesTabs(&input[5]);
00633         SetPixelSearch(charPtr);
00634         optionSeen[OPTION_PIXEL] = TRUE;
00635       } else if ( strncmp(input, "PQSCALE", 7) == 0 ) {
00636         charPtr = SkipSpacesTabs(&input[7]);
00637         SetPQScale(atoi(charPtr));
00638         optionSeen[OPTION_PQSCALE] = TRUE;
00639       } else if ( strncmp(input, "PSEARCH_ALG", 11) == 0 ) {
00640         charPtr = SkipSpacesTabs(&input[11]);
00641         SetPSearchAlg(charPtr);
00642         optionSeen[OPTION_PSEARCH_ALG] = TRUE;
00643       } else if ( strncmp(input, "PARALLEL_TEST_FRAMES", 20) == 0 ) {
00644         SetParallelPerfect(FALSE);
00645         charPtr = SkipSpacesTabs(&input[20]);
00646         parallelTestFrames = atoi(charPtr);
00647       } else if ( strncmp(input, "PARALLEL_TIME_CHUNKS", 20) == 0 ) {
00648         SetParallelPerfect(FALSE);
00649         charPtr = SkipSpacesTabs(&input[20]);
00650         parallelTimeChunks = atoi(charPtr);
00651       } else if ( strncmp(input, "PARALLEL_CHUNK_TAPER", 20) == 0 ) {
00652         SetParallelPerfect(FALSE);
00653         parallelTimeChunks = -1;
00654       } else if ( strncmp(input, "PARALLEL_PERFECT", 16) == 0 ) {
00655         SetParallelPerfect(TRUE);
00656       } else if ( strncmp(input, "PARALLEL", 8) == 0 ) {
00657         ReadMachineNames(fpointer);
00658         optionSeen[OPTION_PARALLEL] = TRUE;
00659       }
00660       break;
00661 
00662     case 'R':
00663       if ( strncmp(input, "RANGE", 5) == 0 ) {
00664         int num_ranges=0,a,b;
00665         charPtr = SkipSpacesTabs(&input[5]);
00666         optionSeen[OPTION_RANGE] = TRUE;
00667         num_ranges=sscanf(charPtr,"%d %d",&a,&b);
00668         if (num_ranges==2) {
00669           SetSearchRange(a,b);
00670         } else if (sscanf(charPtr,"%d [%d]",&a,&b)==2) {
00671           SetSearchRange(a,b);
00672         } else SetSearchRange(a,a);
00673       } else if ( strncmp(input, "REFERENCE_FRAME", 15) == 0 ) {
00674         charPtr = SkipSpacesTabs(&input[15]);
00675         SetReferenceFrameType(charPtr);
00676         optionSeen[OPTION_REF_FRAME] = TRUE;
00677       } else if ( strncmp(input, "RSH", 3) == 0 ) {
00678         charPtr = SkipSpacesTabs(&input[3]);
00679         SetRemoteShell(charPtr);
00680       } else if ( strncmp(input, "RESIZE", 6) == 0 ) {
00681         charPtr = SkipSpacesTabs(&input[6]);                    
00682         sscanf(charPtr, "%dx%d", &outputWidth, &outputHeight);
00683         outputWidth &= ~(DCTSIZE * 2 - 1);
00684         outputHeight &= ~(DCTSIZE * 2 - 1);
00685         optionSeen[OPTION_RESIZE] = TRUE;
00686       }
00687       break;
00688 
00689     case 'S':
00690       if ( strncmp(input, "SLICES_PER_FRAME", 16) == 0 ) {
00691         charPtr = SkipSpacesTabs(&input[16]);
00692         SetSlicesPerFrame(atoi(charPtr));
00693         optionSeen[OPTION_SPF] = TRUE;
00694       } else if ( strncmp(input, "SLAVE_CONVERT", 13) == 0 ) {
00695         charPtr = SkipSpacesTabs(&input[13]);
00696         strcpy(slaveConversion, charPtr);
00697         optionSeen[OPTION_SLAVE_CONVERT] = TRUE;
00698       } else if ( strncmp(input, "SPECIFICS_FILE", 14) == 0 ) {
00699         charPtr = SkipSpacesTabs(&input[14]);
00700         strcpy(specificsFile, charPtr);
00701         specificsOn=TRUE;
00702         optionSeen[OPTION_SPECIFICS] = TRUE;
00703       } else if ( strncmp(input, "SPECIFICS_DEFINES", 16) == 0 ) {
00704         charPtr = SkipSpacesTabs(&input[17]);
00705         strcpy(specificsDefines, charPtr);
00706         optionSeen[OPTION_DEFS_SPECIFICS] = TRUE;
00707       } else if (strncmp(input, "SEQUENCE_SIZE", 13) == 0) {
00708         charPtr = SkipSpacesTabs(&input[13]);
00709         mult_seq_headers = atoi(charPtr);
00710       } else if (strncmp(input, "SIZE", 4) == 0 ) {
00711         charPtr = SkipSpacesTabs(&input[4]);
00712         sscanf(charPtr, "%dx%d", &yuvWidth, &yuvHeight);
00713         realWidth = yuvWidth;
00714         realHeight = yuvHeight;
00715         Fsize_Validate(&yuvWidth, &yuvHeight);
00716         optionSeen[OPTION_YUV_SIZE] = TRUE;
00717       }
00718       break;
00719 
00720     case 'T':
00721       if ( strncmp(input, "TUNE", 4) == 0) {
00722         tuneingOn = TRUE;
00723         charPtr = SkipSpacesTabs(&input[4]);
00724         ParseTuneParam(charPtr);
00725       }
00726       break;
00727 
00728     case 'U':
00729       if ( strncmp(input, "USER_DATA", 9) == 0 ) {
00730         charPtr = SkipSpacesTabs(&input[9]);
00731         strcpy(userDataFileName, charPtr);
00732         optionSeen[OPTION_USER_DATA] = TRUE;
00733       }
00734       break;
00735 
00736     case 'Y':
00737       if (strncmp(input, "YUV_SIZE", 8) == 0 ) {
00738         charPtr = SkipSpacesTabs(&input[8]);
00739         sscanf(charPtr, "%dx%d", &yuvWidth, &yuvHeight);
00740         realWidth = yuvWidth;
00741         realHeight = yuvHeight;
00742         Fsize_Validate(&yuvWidth, &yuvHeight);
00743         optionSeen[OPTION_YUV_SIZE] = TRUE;
00744       }
00745       else if (strncmp(input, "Y_SIZE", 6) == 0 ) {
00746         charPtr = SkipSpacesTabs(&input[6]);
00747         sscanf(charPtr, "%dx%d", &yuvWidth, &yuvHeight);
00748         realWidth = yuvWidth;
00749         realHeight = yuvHeight;
00750         Fsize_Validate(&yuvWidth, &yuvHeight);
00751         optionSeen[OPTION_YUV_SIZE] = TRUE;
00752       }
00753       else if ( strncmp(input, "YUV_FORMAT", 10) == 0 ) {
00754         charPtr = SkipSpacesTabs(&input[10]);
00755         strcpy(yuvConversion, charPtr);
00756         optionSeen[OPTION_YUV_FORMAT] = TRUE;
00757       }
00758       break;
00759     }
00760   }
00761 
00762 #ifdef RWCox
00763   if( fpointer != stdin )
00764 #endif
00765   fclose(fpointer);
00766 
00767   for ( index = FIRST_OPTION; index <= LAST_OPTION; index++ ) {
00768     if ( ! optionSeen[index] ) {
00769 
00770       /* INPUT unnecessary when stdin is used */
00771       if ((index == OPTION_INPUT) && stdinUsed) {
00772         continue;
00773       }
00774 
00775       fprintf(stderr, "ERROR:  Missing option '%s'\n", optionText[index]);
00776       exit(1);
00777     }
00778   }
00779 
00780   /* error checking */
00781   if ( yuvUsed ) {
00782 
00783     if (! optionSeen[OPTION_YUV_SIZE]) {
00784       fprintf(stderr, "ERROR:  YUV format used but YUV_SIZE not given\n");
00785       exit(1);
00786     }
00787 
00788     if (! optionSeen[OPTION_YUV_FORMAT]) {
00789       strcpy (yuvConversion, "EYUV");
00790       fprintf(stderr, "WARNING:  YUV format not specified; defaulting to Berkeley YUV (EYUV)\n\n");
00791     }
00792 
00793   }
00794 
00795   if ( stdinUsed && optionSeen[OPTION_PARALLEL] ) {
00796     fprintf(stderr, "ERROR:  stdin reading for parallel execution not enabled yet.\n");
00797     exit(1);
00798   }
00799 
00800 
00801   if ( optionSeen[OPTION_PARALLEL] && !optionSeen[OPTION_YUV_SIZE]) {
00802     fprintf(stderr, "ERROR:  Specify SIZE WxH for parallel encoding\n");
00803     exit(1);
00804   }
00805 
00806   if ( optionSeen[OPTION_IO_CONVERT] != optionSeen[OPTION_SLAVE_CONVERT] ) {
00807     fprintf(stderr, "ERROR:  must have either both IO_SERVER_CONVERT and SLAVE_CONVERT\n");
00808     fprintf(stderr, "        or neither\n");
00809     exit(1);
00810   }
00811 
00812   if ( optionSeen[OPTION_DEFS_SPECIFICS] && !optionSeen[OPTION_SPECIFICS]) {
00813     fprintf(stderr, "ERROR:  does not make sense to define Specifics file options, but no specifics file!\n");
00814     exit(1);
00815   }
00816 
00817   SetIOConvert(optionSeen[OPTION_IO_CONVERT]);
00818 
00819   SetResize(optionSeen[OPTION_RESIZE]);
00820 
00821   if ( function == ENCODE_FRAMES ) {
00822     SetFCode();
00823 
00824     if ( psearchAlg == PSEARCH_TWOLEVEL )
00825       SetPixelSearch("HALF");
00826   }
00827 
00828   return TRUE;
00829 }
00830 
00831 
00832 /*===========================================================================*
00833  *
00834  * GetNthInputFileName
00835  *
00836  *      finds the nth input file name
00837  *
00838  * RETURNS:     name is placed in already allocated fileName string
00839  *
00840  * SIDE EFFECTS:    none
00841  *
00842  *===========================================================================*/
00843 void
00844   GetNthInputFileName(fileName, n)
00845 char *fileName;
00846 int n;
00847 {
00848   static int    lastN = 0, lastMapN = 0, lastSoFar = 0;
00849   int       mapN;
00850   register int index;
00851   int       soFar;
00852   int       loop;
00853   int       numPadding;
00854   char    numBuffer[33];
00855 
00856   if ( stdinUsed ) {
00857     return;
00858   }
00859 
00860   /* assumes n is within bounds 0...numInputFiles-1 */
00861 
00862   if ( n >= lastN ) {
00863     soFar = lastSoFar;
00864     index = lastMapN;
00865   } else {
00866     soFar = 0;
00867     index = 0;
00868   }
00869 
00870   while ( soFar + inputFileEntries[index]->numFiles <= n ) {
00871     soFar +=  inputFileEntries[index]->numFiles;
00872     index++;
00873   }
00874 
00875   mapN = index;
00876 
00877   index = inputFileEntries[mapN]->startID +
00878     inputFileEntries[mapN]->skip*(n-soFar);
00879 
00880   numPadding = inputFileEntries[mapN]->numPadding;
00881 
00882   if ( numPadding != -1 ) {
00883     sprintf(numBuffer, "%32d", index);
00884     for ( loop = 32-numPadding; loop < 32; loop++ ) {
00885       if ( numBuffer[loop] != ' ' ) {
00886         break;
00887       } else {
00888         numBuffer[loop] = '0';
00889       }
00890     }
00891 
00892     if (inputFileEntries[mapN]->repeat != TRUE) {
00893       sprintf(fileName, "%s%s%s",
00894               inputFileEntries[mapN]->left,
00895               &numBuffer[32-numPadding],
00896               inputFileEntries[mapN]->right);
00897     } else {
00898       sprintf(fileName, "%s", inputFileEntries[mapN]->left);
00899     }
00900   } else {
00901     if (inputFileEntries[mapN]->repeat != TRUE) {
00902       sprintf(fileName, "%s%d%s",
00903               inputFileEntries[mapN]->left,
00904               index,
00905               inputFileEntries[mapN]->right);
00906     } else {
00907       sprintf(fileName, "%s", inputFileEntries[mapN]->left);
00908     }
00909   }
00910 
00911   lastN = n;
00912   lastMapN = mapN;
00913   lastSoFar = soFar;
00914 }
00915 
00916 
00917 /*=====================*
00918  * INTERNAL PROCEDURES *
00919  *=====================*/
00920 
00921 /*===========================================================================*
00922  *
00923  * ReadMachineNames
00924  *
00925  *      read a list of machine names for parallel execution
00926  *
00927  * RETURNS:     nothing
00928  *
00929  * SIDE EFFECTS:    machine info updated
00930  *
00931  *===========================================================================*/
00932 static void
00933   ReadMachineNames(fpointer)
00934 FILE *fpointer;
00935 {
00936   char    input[256];
00937   char    *charPtr;
00938 
00939   while ( (fgets(input, 256, fpointer) != NULL) &&
00940          (strncmp(input, "END_PARALLEL", 12) != 0) ) {
00941     if ( input[0] == '#' || input[0] == '\n') {
00942       continue;
00943     }
00944 
00945     if ( strncmp(input, "REMOTE", 6) == 0 ) {
00946       charPtr = SkipSpacesTabs(&input[6]);
00947       remote[numMachines] = TRUE;
00948 
00949       sscanf(charPtr, "%s %s %s %s", machineName[numMachines],
00950              userName[numMachines], executable[numMachines],
00951              remoteParamFile[numMachines]);
00952     } else {
00953       remote[numMachines] = FALSE;
00954 
00955       sscanf(input, "%s %s %s", machineName[numMachines],
00956              userName[numMachines], executable[numMachines]);
00957     }
00958 
00959     numMachines++;
00960   }
00961 }
00962 
00963 
00964 /*===========================================================================*
00965  *
00966  * ReadInputFileNames
00967  *
00968  *      read a list of input file names
00969  *
00970  * RETURNS:     nothing
00971  *
00972  * SIDE EFFECTS:    info stored for retrieval using GetNthInputFileName
00973  *
00974  *===========================================================================*/
00975 static void
00976   ReadInputFileNames(fpointer, endInput)
00977 FILE *fpointer;
00978 char *endInput;
00979 {
00980   char      input[256];
00981   char      left[256], right[256];
00982   char      *globPtr, *charPtr;
00983   char      leftNumText[256], rightNumText[256];
00984   char      skipNumText[256];
00985   int       leftNum, rightNum;
00986   int       skipNum;
00987   boolean   padding;
00988   int       numPadding = 0;
00989   int       length;
00990   char      full_path[MAXPATHLEN + 256];
00991   FILE      *jmovie;
00992 
00993   inputFileEntries = (InputFileEntry **) malloc(INPUT_ENTRY_BLOCK_SIZE*
00994                                                 sizeof(InputFileEntry *));
00995   maxInputFileEntries = INPUT_ENTRY_BLOCK_SIZE;
00996 
00997   length = strlen(endInput);
00998 
00999   /* read input files up until endInput */
01000   while ( (fgets(input, 256, fpointer) != NULL) &&
01001          (strncmp(input, endInput, length) != 0) ) {
01002 
01003     /* if input is coming in via standard input, keep on looping till the 
01004      * endInput string is reached so that the program points to the right 
01005      * place on exit.
01006      */
01007     if ( stdinUsed ) {
01008       continue;
01009     }
01010             
01011     /* ignore comments and newlines */
01012     if ( (input[0] == '#') || (input[0] == '\n') ) { 
01013       continue;
01014     }
01015 
01016     if (input[0] == '`' ) {     /* Recurse for commands */
01017       FILE *fp;
01018       char cmd[300], *start, *end, tmp[300], cdcmd[110];
01019 
01020       start = &input[1];
01021       end = &input[strlen(input)-1];
01022 
01023       while (*end != '`') {
01024         end--;
01025       }
01026 
01027       end--;
01028 
01029       if (optionSeen[OPTION_INPUT_DIR] == TRUE) {
01030         sprintf(cdcmd,"cd %s;",currentPath);
01031       } else {
01032         strcpy(cdcmd,"");
01033       }
01034       strncpy(tmp,start,end-start+1);
01035       sprintf(cmd,"(%s %s)", cdcmd, tmp);
01036 
01037       fp = popen(cmd,"r");
01038       if (fp == NULL) {
01039         fprintf(stderr,"Command failed! Could not open piped command:\n%s\n",cmd);
01040         continue;
01041       }
01042       ReadInputFileNames(fp,"HOPE-THIS_ISNT_A_FILENAME.xyz5555");
01043       continue;
01044     }
01045 
01046 
01047     /* get rid of trailing whitespace including newline */
01048     while (isspace(input[strlen(input)-1])) {
01049       input[strlen(input)-1] = '\0';
01050     }
01051 
01052     if ( numInputFileEntries == maxInputFileEntries ) { /* more space! */
01053       maxInputFileEntries += INPUT_ENTRY_BLOCK_SIZE;
01054       inputFileEntries = (InputFileEntry **) realloc(inputFileEntries,
01055                                                      maxInputFileEntries*
01056                                                      sizeof(InputFileEntry *));
01057     }
01058 
01059     inputFileEntries[numInputFileEntries] = (InputFileEntry *)
01060       malloc(sizeof(InputFileEntry));
01061 
01062     if ( input[strlen(input)-1] == ']' ) {
01063       inputFileEntries[numInputFileEntries]->glob = TRUE;
01064       inputFileEntries[numInputFileEntries]->repeat = FALSE;
01065 
01066       /* star expand */
01067 
01068       globPtr = input;
01069       charPtr = left;
01070       /* copy left of '*' */
01071       while ( (*globPtr != '\0') && (*globPtr != '*') ) {
01072         *charPtr = *globPtr;
01073         charPtr++;
01074         globPtr++;
01075       }
01076       *charPtr = '\0';
01077 
01078       if (*globPtr == '\0') {
01079         fprintf(stderr, "WARNING: expanding non-star regular expression\n");
01080         inputFileEntries[numInputFileEntries]->repeat = TRUE;
01081         globPtr = input;
01082         charPtr = left;
01083         /* recopy left of whitespace */
01084         while ( (*globPtr != '\0') && (*globPtr != '*') && 
01085                 (*globPtr != ' ')  && (*globPtr != '\t')) {
01086           *charPtr = *globPtr;
01087           charPtr++;
01088           globPtr++;
01089         }
01090         *charPtr = '\0';
01091         *right = '\0';
01092       } else {
01093 
01094         globPtr++;
01095         charPtr = right;
01096         /* copy right of '*' */
01097         while ( (*globPtr != '\0') && (*globPtr != ' ') &&
01098                (*globPtr != '\t') ) {
01099           *charPtr = *globPtr;
01100           charPtr++;
01101           globPtr++;
01102         }
01103         *charPtr = '\0';
01104       }
01105       
01106       globPtr = SkipSpacesTabs(globPtr);
01107 
01108       if ( *globPtr != '[' ) {
01109         fprintf(stderr, "ERROR:  Invalid input file expansion expression (no '[')\n");
01110         exit(1);
01111       }
01112 
01113       globPtr++;
01114       charPtr = leftNumText;
01115       /* copy left number */
01116       while ( isdigit(*globPtr) ) {
01117         *charPtr = *globPtr;
01118         charPtr++;
01119         globPtr++;
01120       }
01121       *charPtr = '\0';
01122 
01123       if ( *globPtr != '-' ) {
01124         fprintf(stderr, "ERROR:  Invalid input file expansion expression (no '-')\n");
01125         exit(1);
01126       }
01127 
01128       globPtr++;
01129       charPtr = rightNumText;
01130       /* copy right number */
01131       while ( isdigit(*globPtr) ) {
01132         *charPtr = *globPtr;
01133         charPtr++;
01134         globPtr++;
01135       }
01136       *charPtr = '\0';
01137       if ( atoi(rightNumText) < atoi(leftNumText) ) {
01138         fprintf(stderr, "ERROR:  Beginning of input range is higher than end.\n");
01139         exit(1);
01140       }
01141 
01142 
01143       if ( *globPtr != ']' ) {
01144         if ( *globPtr != '+' ) {
01145           fprintf(stderr, "ERROR:  Invalid input file expansion expression (no ']')\n");
01146           exit(1);
01147         }
01148 
01149         globPtr++;
01150         charPtr = skipNumText;
01151         /* copy skip number */
01152         while ( isdigit(*globPtr) ) {
01153           *charPtr = *globPtr;
01154           charPtr++;
01155           globPtr++;
01156         }
01157         *charPtr = '\0';
01158 
01159         if ( *globPtr != ']' ) {
01160           fprintf(stderr, "ERROR:  Invalid input file expansion expression (no ']')\n");
01161           exit(1);
01162         }
01163 
01164         skipNum = atoi(skipNumText);
01165       } else {
01166         skipNum = 1;
01167       }
01168 
01169       leftNum = atoi(leftNumText);
01170       rightNum = atoi(rightNumText);
01171 
01172       if ( (leftNumText[0] == '0') && (leftNumText[1] != '\0') ) {
01173         padding = TRUE;
01174         numPadding = strlen(leftNumText);
01175       } else {
01176         padding = FALSE;
01177       }
01178 
01179       inputFileEntries[numInputFileEntries]->startID = leftNum;
01180       inputFileEntries[numInputFileEntries]->endID = rightNum;
01181       inputFileEntries[numInputFileEntries]->skip = skipNum;
01182       inputFileEntries[numInputFileEntries]->numFiles = (rightNum-leftNum+1)/skipNum;
01183       strcpy(inputFileEntries[numInputFileEntries]->left, left);
01184       strcpy(inputFileEntries[numInputFileEntries]->right, right);
01185       if ( padding ) {
01186         inputFileEntries[numInputFileEntries]->numPadding = numPadding;
01187       } else {
01188         inputFileEntries[numInputFileEntries]->numPadding = -1;
01189       }
01190     } else {
01191       strcpy(inputFileEntries[numInputFileEntries]->left, input);
01192       if (baseFormat == JMOVIE_FILE_TYPE) {
01193         inputFileEntries[numInputFileEntries]->glob = TRUE;
01194         full_path[0] = '\0';
01195         strcpy(full_path, currentPath);
01196     
01197         if (! stdinUsed) {
01198           strcat(full_path, "/");
01199           strcat(full_path, input);
01200           jmovie = fopen(input, "rb"); 
01201 
01202           if (jmovie == NULL) {
01203             perror (input); 
01204             exit (1);
01205           }
01206 
01207           fseek (jmovie, (8*sizeof(char)), 0);
01208           fseek (jmovie, (2*sizeof(int)), 1);
01209 
01210           if (fread (&(inputFileEntries[numInputFileEntries]->numFiles),
01211                      sizeof(int), 1, jmovie) != 1) {
01212             perror ("Error in reading number of frames in JMOVIE");
01213             exit(1);
01214           }
01215           fclose (jmovie);
01216         }  
01217 
01218         strcpy(inputFileEntries[numInputFileEntries]->right,".jpg");
01219         inputFileEntries[numInputFileEntries]->numPadding = -1;
01220         inputFileEntries[numInputFileEntries]->startID = 1;
01221         inputFileEntries[numInputFileEntries]->endID = (inputFileEntries[numInputFileEntries]->numFiles-1);
01222         inputFileEntries[numInputFileEntries]->skip = 1;
01223         if (! realQuiet) {
01224           fprintf (stdout, "Encoding all %d frames from JMOVIE.\n", inputFileEntries[numInputFileEntries]->endID);
01225         }
01226       } else {
01227         inputFileEntries[numInputFileEntries]->glob = FALSE;
01228         inputFileEntries[numInputFileEntries]->numFiles = 1;
01229         /* fixes a bug from version 1.3: */
01230         inputFileEntries[numInputFileEntries]->numPadding = 0;
01231         /* fixes a bug from version 1.4 */
01232         strcpy(inputFileEntries[numInputFileEntries]->right,"\0");
01233         inputFileEntries[numInputFileEntries]->startID = 0;
01234         inputFileEntries[numInputFileEntries]->endID = 0;
01235         inputFileEntries[numInputFileEntries]->skip = 0;
01236       }
01237     }
01238 
01239     numInputFiles += inputFileEntries[numInputFileEntries]->numFiles;
01240     numInputFileEntries++;
01241   }
01242 }
01243 
01244 
01245 /*===========================================================================*
01246  *
01247  * SkipSpacesTabs
01248  *
01249  *      skip all spaces and tabs
01250  *
01251  * RETURNS:     point to next character not a space or tab
01252  *
01253  * SIDE EFFECTS:    none
01254  *
01255  *===========================================================================*/
01256 char *
01257   SkipSpacesTabs(start)
01258 char *start;
01259 {
01260   while ( (*start == ' ') || (*start == '\t') ) {
01261     start++;
01262   }
01263 
01264   return start;
01265 }
01266 
01267 
01268 /*===========================================================================*
01269  *
01270  * GetFrameRate
01271  *
01272  * take a character string with the input frame rate 
01273  * and return the correct frame rate code for use in the Sequence header
01274  *
01275  * RETURNS: frame rate code as per MPEG-I spec
01276  *
01277  * SIDE EFFECTS:    none
01278  *
01279  *===========================================================================*/
01280 static int
01281   GetFrameRate(p)
01282 char *p;
01283 {
01284   float   rate;
01285   int       thouRate;
01286 
01287   sscanf(p, "%f", &rate);
01288   thouRate = (int)(0.5+1000.0*rate);
01289 
01290   if ( thouRate == 23976 )           return 1;
01291   else if ( thouRate == 24000 )    return 2;
01292   else if ( thouRate == 25000 )    return 3;
01293   else if ( thouRate == 29970 )    return 4;
01294   else if ( thouRate == 30000 )    return 5;
01295   else if ( thouRate == 50000 )    return 6;
01296   else if ( thouRate == 59940 )    return 7;
01297   else if ( thouRate == 60000 )    return 8;
01298   else {
01299     fprintf(stderr,"INVALID FRAME RATE: %s frames/sec\n", p);
01300     exit(1);
01301   }
01302 }
01303 
01304 
01305 /*===========================================================================*
01306  *
01307  * GetAspectRatio
01308  *
01309  * take a character string with the pixel aspect ratio
01310  * and returns the correct aspect ratio code for use in the Sequence header
01311  *
01312  * RETURNS: aspect ratio code as per MPEG-I spec
01313  *
01314  * SIDE EFFECTS:    none
01315  *
01316  *===========================================================================*/
01317 static int
01318   GetAspectRatio(p)
01319 char *p;
01320 {
01321   float   ratio;
01322   int       ttRatio;
01323 
01324   sscanf(p, "%f", &ratio);
01325   ttRatio = (int)(0.5+ratio*10000.0);
01326 
01327   if ( ttRatio == 10000 )          return 1;
01328   else if ( ttRatio ==  6735 )    return 2;
01329   else if ( ttRatio ==  7031 )    return 3;
01330   else if ( ttRatio ==  7615 )    return 4;
01331   else if ( ttRatio ==  8055 )    return 5;
01332   else if ( ttRatio ==  8437 )    return 6;
01333   else if ( ttRatio ==  8935 )    return 7;
01334   else if ( ttRatio ==  9157 )    return 8;
01335   else if ( ttRatio ==  9815 )    return 9;
01336   else if ( ttRatio == 10255 )    return 10;
01337   else if ( ttRatio == 10695 )    return 11;
01338   else if ( ttRatio == 10950 )    return 12;
01339   else if ( ttRatio == 11575 )    return 13;
01340   else if ( ttRatio == 12015 )    return 14;
01341   else {
01342     fprintf(stderr,"INVALID ASPECT RATIO: %s frames/sec\n", p);
01343     exit(1);
01344   }
01345 }
01346 
01347 
01348 
01349 
01350 
01351 
01352 /****************************************************************
01353  *  Jim Boucher's code
01354  *
01355  *
01356  ****************************************************************/
01357 void
01358 JM2JPEG()
01359 {
01360   char full_path[MAXPATHLEN + 256];
01361   char inter_file[MAXPATHLEN +256]; 
01362   int ci;
01363 
01364   for(ci = 0; ci < numInputFileEntries; ci++) {
01365     inter_file[0] = '\0';
01366     full_path[0] = '\0';
01367     strcpy(full_path, currentPath);
01368     
01369     if (! stdinUsed) {
01370       strcat(full_path, "/");
01371       strcat(full_path, inputFileEntries[ci]->left);
01372       strcpy(inter_file,full_path);
01373     
01374       if (! realQuiet) {
01375         fprintf(stdout, "Extracting JPEG's in the JMOVIE from %s\n",full_path);
01376       }
01377     
01378       JMovie2JPEG(full_path,
01379                   inter_file,
01380                   inputFileEntries[ci]->startID, inputFileEntries[ci]->endID);
01381     } else {
01382       fprintf (stderr, "ERROR: JMovie format not supported with stdin yet.\n");
01383       exit(1);
01384     }
01385       
01386   }
01387 }
 

Powered by Plone

This site conforms to the following standards: