ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/freemol/trunk/src/mpeg_encode/src/param.c
Revision: 69
Committed: Mon Dec 15 00:03:56 2008 UTC (13 years, 6 months ago) by wdelano
File size: 41297 byte(s)
Log Message:
stdin redirection
Line User Rev File contents
1 wdelano 22 /*===========================================================================*
2     * param.c *
3     * *
4     * Procedures to read in parameter file *
5     * *
6     * EXPORTED PROCEDURES: *
7     * ReadParamFile *
8     * GetNthInputFileName *
9     * *
10     *===========================================================================*/
11    
12     /*
13     * Copyright (c) 1995 The Regents of the University of California.
14     * All rights reserved.
15     *
16     * Permission to use, copy, modify, and distribute this software and its
17     * documentation for any purpose, without fee, and without written agreement is
18     * hereby granted, provided that the above copyright notice and the following
19     * two paragraphs appear in all copies of this software.
20     *
21     * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
22     * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
23     * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
24     * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25     *
26     * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
27     * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
28     * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
29     * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
30     * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
31     */
32    
33     /*
34     * $Header: /n/picasso/project/mpeg/mpeg_dist/mpeg_encode/RCS/param.c,v 1.38 1995/08/14 22:29:13 smoot Exp smoot $
35     * $Log: param.c,v $
36     * Revision 1.38 1995/08/14 22:29:13 smoot
37     * cleaned up subcommand for file name generation
38     * fixed bug where foo* didnt work as input string
39     *
40     * Revision 1.37 1995/08/07 21:47:01 smoot
41     * allows spaces after lines in param files
42     * added SIZE == YUV_SIZE for parallel encoding (otherwise you'd have
43     * to parse PPM files in the master server... Ick.
44     * So we have it specified)
45     *
46     * Revision 1.36 1995/06/26 21:52:52 smoot
47     * allow uppercase stdin
48     *
49     * Revision 1.35 1995/06/21 18:35:01 smoot
50     * moved TUNE stuff to opts.c
51     * Added ability to do:
52     * INPUT
53     * file.ppm [1-10]
54     * to do 10 copies
55     * added CDL = SPECIFICS
56     *
57     * Revision 1.34 1995/05/02 01:48:25 eyhung
58     * deleted some smootisms. fixed framerate settings, added check for
59     * invalid input range
60     *
61     * Revision 1.33 1995/05/02 01:20:10 smoot
62     * *** empty log message ***
63     *
64     * Revision 1.31 1995/03/09 06:22:36 eyhung
65     * more robust input checking (whitespace at end of input file spec)
66     *
67     * Revision 1.30 1995/02/02 01:06:18 eyhung
68     * Added error checking for JMOVIE and stdin ; deleted smoot's "understand"
69     * param file ideas.
70     *
71     * Revision 1.29 1995/02/01 21:09:59 eyhung
72     * Finished infinite coding-on-the-fly
73     *
74     * Revision 1.28 1995/01/31 22:34:28 eyhung
75     * Added stdin as a parameter to INPUT_DIR for interactive encoding
76     *
77     * Revision 1.27 1995/01/27 21:58:07 eyhung
78     * Fixed a bug with reading JMOVIES in GetNthInputFileName
79     *
80     * Revision 1.26 1995/01/25 23:00:05 smoot
81     * Checks out Qtable entries
82     *
83     * Revision 1.25 1995/01/23 02:09:51 darryl
84     * removed "PICT_RATE" code
85     *
86     * Revision 1.24 1995/01/20 00:07:46 smoot
87     * requires unistd.c now
88     *
89     * Revision 1.23 1995/01/20 00:05:33 smoot
90     * Added gamma correction option
91     *
92     * Revision 1.22 1995/01/19 23:55:55 eyhung
93     * Fixed up smoot's "style" and made YUV_FORMAT default to EYUV
94     *
95     * Revision 1.21 1995/01/19 23:09:03 eyhung
96     * Changed copyrights
97     *
98     * Revision 1.20 1995/01/17 22:04:14 smoot
99     * Added `commands` to file name listing
100     *
101     * Revision 1.19 1995/01/17 06:28:01 eyhung
102     * StdinUsed added.
103     *
104     * Revision 1.18 1995/01/16 09:33:35 eyhung
105     * Fixed stupid commenting error.
106     *
107     * Revision 1.17 1995/01/16 06:07:53 eyhung
108     * Made it look a little nicer
109     *
110     * Revision 1.16 1995/01/13 23:57:25 smoot
111     * added Y format
112     *
113     * Revision 1.15 1995/01/08 06:20:39 eyhung
114     * *** empty log message ***
115     *
116     * Revision 1.14 1995/01/08 06:15:57 eyhung
117     * *** empty log message ***
118     *
119     * Revision 1.13 1995/01/08 05:50:32 eyhung
120     * Added YUV Format parameter
121     *
122     * Revision 1.12 1994/12/16 00:55:30 smoot
123     * Fixed INPU_FILES bug
124     *
125     * Revision 1.11 1994/12/12 23:54:36 smoot
126     * Fixed GOP-missing error message (GOP to GOP_SIZE)
127     *
128     * Revision 1.10 1994/12/07 00:40:36 smoot
129     * Added seperate P and B search ranges
130     *
131     * Revision 1.9 1994/11/18 23:19:22 smoot
132     * Added USER_DATA parameter
133     *
134     * Revision 1.8 1994/11/16 22:33:40 smoot
135     * Put in ifdef for rsh in param.c
136     *
137     * Revision 1.7 1994/11/16 22:25:05 smoot
138     * Corrected ASPECT_RATIO bug
139     *
140     * Revision 1.6 1994/11/14 22:39:26 smoot
141     * merged specifics and rate control
142     *
143     * Revision 1.5 1994/11/01 05:01:41 darryl
144     * with rate control changes added
145     *
146     * Revision 1.1 1994/09/27 00:16:28 darryl
147     * Initial revision
148     *
149     * Revision 1.4 1994/03/15 00:27:11 keving
150     * nothing
151     *
152     * Revision 1.3 1993/12/22 19:19:01 keving
153     * nothing
154     *
155     * Revision 1.2 1993/07/22 22:23:43 keving
156     * nothing
157     *
158     * Revision 1.1 1993/06/30 20:06:09 keving
159     * nothing
160     *
161     */
162    
163    
164     /*==============*
165     * HEADER FILES *
166     *==============*/
167    
168     #include "all.h"
169     #include "mtypes.h"
170     #include "mpeg.h"
171     #include "search.h"
172     #include "prototypes.h"
173     #include "parallel.h"
174     #include "param.h"
175     #include "readframe.h"
176     #include "fsize.h"
177     #include "frames.h"
178     #include "jpeg.h"
179     #include <string.h>
180     #include <ctype.h>
181     #include "rate.h"
182     #include "opts.h"
183    
184     /*===========*
185     * CONSTANTS *
186     *===========*/
187    
188     #define INPUT_ENTRY_BLOCK_SIZE 128
189    
190     #define FIRST_OPTION 0
191     #define OPTION_GOP 0
192     #define OPTION_PATTERN 1
193     #define OPTION_PIXEL 2
194     #define OPTION_PQSCALE 3
195     #define OPTION_OUTPUT 4
196     #define OPTION_RANGE 5
197     #define OPTION_PSEARCH_ALG 6
198     #define OPTION_IQSCALE 7
199     #define OPTION_INPUT_DIR 8
200     #define OPTION_INPUT_CONVERT 9
201     #define OPTION_INPUT 10
202     #define OPTION_BQSCALE 11
203     #define OPTION_BASE_FORMAT 12
204     #define OPTION_SPF 13
205     #define OPTION_BSEARCH_ALG 14
206     #define OPTION_REF_FRAME 15
207     #define LAST_OPTION 15
208    
209     /* put any non-required options after LAST_OPTION */
210     #define OPTION_RESIZE 16
211     #define OPTION_IO_CONVERT 17
212     #define OPTION_SLAVE_CONVERT 18
213     #define OPTION_IQTABLE 19
214     #define OPTION_NIQTABLE 20
215     #define OPTION_FRAME_RATE 21
216     #define OPTION_ASPECT_RATIO 22
217     #define OPTION_YUV_SIZE 23
218     #define OPTION_SPECIFICS 24
219     #define OPTION_DEFS_SPECIFICS 25
220     #define OPTION_BUFFER_SIZE 26
221     #define OPTION_BIT_RATE 27
222     #define OPTION_USER_DATA 28
223     #define OPTION_YUV_FORMAT 29
224     #define OPTION_GAMMA 30
225     #define OPTION_PARALLEL 31
226    
227     #define NUM_OPTIONS 31
228    
229     /*=======================*
230     * STRUCTURE DEFINITIONS *
231     *=======================*/
232    
233     typedef struct InputFileEntryStruct {
234     char left[256];
235     char right[256];
236     boolean glob; /* if FALSE, left is complete name */
237     int startID;
238     int endID;
239     int skip;
240     int numPadding; /* -1 if there is none */
241     int numFiles;
242     boolean repeat;
243     } InputFileEntry;
244    
245    
246     /*==================*
247     * STATIC VARIABLES *
248     *==================*/
249    
250     static InputFileEntry **inputFileEntries;
251     static int numInputFileEntries = 0;
252     static int maxInputFileEntries;
253    
254    
255     /*==================*
256     * GLOBAL VARIABLES *
257     *==================*/
258    
259     extern char currentPath[MAXPATHLEN];
260     extern char currentGOPPath[MAXPATHLEN];
261     extern char currentFramePath[MAXPATHLEN];
262     char outputFileName[256];
263     int outputWidth, outputHeight;
264     int numInputFiles = 0;
265     char inputConversion[1024];
266     char ioConversion[1024];
267     char slaveConversion[1024];
268     char yuvConversion[256];
269     char specificsFile[256],specificsDefines[1024]="";
270     boolean GammaCorrection=FALSE;
271     float GammaValue;
272     unsigned char userDataFileName[256]={0};
273     boolean specificsOn = FALSE;
274     boolean optionSeen[NUM_OPTIONS+1];
275     int numMachines;
276     char machineName[MAX_MACHINES][256];
277     char userName[MAX_MACHINES][256];
278     char executable[MAX_MACHINES][1024];
279     char remoteParamFile[MAX_MACHINES][1024];
280     boolean remote[MAX_MACHINES];
281     boolean stdinUsed = FALSE;
282     int mult_seq_headers = 0; /* 0 for none, N for header/N GOPs */
283    
284     /*===============================*
285     * INTERNAL PROCEDURE prototypes *
286     *===============================*/
287     static void ReadInputFileNames _ANSI_ARGS_((FILE *fpointer,
288     char *endInput));
289     static void ReadMachineNames _ANSI_ARGS_((FILE *fpointer));
290     static int GetAspectRatio _ANSI_ARGS_((char *p));
291     static int GetFrameRate _ANSI_ARGS_((char *p));
292    
293     /*=====================*
294     * EXPORTED PROCEDURES *
295     *=====================*/
296    
297    
298     /*===========================================================================*
299     *
300     * ReadParamFile
301     *
302     * read the parameter file
303     * function is ENCODE_FRAMES, COMBINE_GOPS, or COMBINE_FRAMES, and
304     * will slightly modify the procedure's behavior as to what it
305     * is looking for in the parameter file
306     *
307     * RETURNS: TRUE if the parameter file was read correctly; FALSE if not
308     *
309     * SIDE EFFECTS: sets parameters accordingly, as well as machine info for
310     * parallel execution and input file names
311     *
312     *===========================================================================*/
313     boolean
314     ReadParamFile(fileName, function)
315     char *fileName;
316     int function;
317     {
318     FILE *fpointer;
319     char input[256];
320     char *charPtr;
321     boolean yuvUsed = FALSE;
322     static char *optionText[LAST_OPTION+1] = { "GOP_SIZE", "PATTERN", "PIXEL", "PQSCALE",
323     "OUTPUT", "RANGE", "PSEARCH_ALG", "IQSCALE", "INPUT_DIR",
324     "INPUT_CONVERT", "INPUT", "BQSCALE", "BASE_FILE_FORMAT",
325     "SLICES_PER_FRAME", "BSEARCH_ALG", "REFERENCE_FRAME"};
326     register int index;
327     register int row, col;
328 wdelano 69
329     /* WLD */
330     if(fileName) {
331     if ( (fpointer = fopen(fileName, "r")) == NULL ) {
332     fprintf(stderr, "Error: Cannot open parameter file: %s\n", fileName);
333     return FALSE;
334     }
335     } else {
336     fpointer = stdin;
337 wdelano 22 }
338 wdelano 69 /* WLD END */
339 wdelano 22
340     /* should set defaults */
341     numInputFiles = 0;
342     numMachines = 0;
343     sprintf(currentPath, ".");
344     sprintf(currentGOPPath, ".");
345     sprintf(currentFramePath, ".");
346     #ifndef HPUX
347     SetRemoteShell("rsh");
348     #else
349     SetRemoteShell("remsh");
350     #endif
351    
352     switch(function) {
353     case ENCODE_FRAMES:
354     for ( index = FIRST_OPTION; index <= LAST_OPTION; index++ ) {
355     optionSeen[index] = FALSE;
356     }
357     optionSeen[OPTION_IO_CONVERT] = FALSE;
358     optionSeen[OPTION_SLAVE_CONVERT] = FALSE;
359     break;
360     case COMBINE_GOPS:
361     for ( index = FIRST_OPTION; index <= LAST_OPTION; index++ ) {
362     optionSeen[index] = TRUE;
363     }
364    
365     optionSeen[OPTION_OUTPUT] = FALSE;
366     break;
367     case COMBINE_FRAMES:
368     for ( index = FIRST_OPTION; index <= LAST_OPTION; index++ ) {
369     optionSeen[index] = TRUE;
370     }
371    
372     optionSeen[OPTION_GOP] = FALSE;
373     optionSeen[OPTION_OUTPUT] = FALSE;
374     break;
375     }
376    
377     for( index=LAST_OPTION+1; index<= NUM_OPTIONS; index++ ) {
378     optionSeen[index]=FALSE;
379     }
380    
381     while ( fgets(input, 256, fpointer) != NULL ) {
382     /* skip comments */
383     if ( input[0] == '#' ) {
384     continue;
385     }
386    
387     {
388     int len = strlen(input);
389     if (input[len-1] == '\n') {
390     len--;
391     input[len] = '\0'; /* get rid of newline */
392     /* Junk whitespace */
393     while ((len >= 0) && ((input[len-1] == ' ') || (input[len-1] == '\t'))) {
394     input[--len] = '\0';
395     }
396     }
397     }
398    
399     if (strlen(SkipSpacesTabs(input)) == 0) continue;
400    
401     switch(input[0]) {
402     case 'A':
403     if ( strncmp(input, "ASPECT_RATIO", 12) == 0 ) {
404     charPtr = SkipSpacesTabs(&input[12]);
405     aspectRatio = GetAspectRatio(charPtr);
406     optionSeen[OPTION_ASPECT_RATIO] = TRUE;
407     }
408     break;
409    
410     case 'B':
411     if ( strncmp(input, "BQSCALE", 7) == 0 ) {
412     charPtr = SkipSpacesTabs(&input[7]);
413     SetBQScale(atoi(charPtr));
414     optionSeen[OPTION_BQSCALE] = TRUE;
415     } else if ( strncmp(input, "BASE_FILE_FORMAT", 16) == 0 ) {
416     charPtr = SkipSpacesTabs(&input[16]);
417     SetFileFormat(charPtr);
418     if ( (strncmp(charPtr,"YUV",3) == 0) ||
419     (strcmp(charPtr,"Y") == 0) ) {
420     yuvUsed = TRUE;
421     }
422     optionSeen[OPTION_BASE_FORMAT] = TRUE;
423     } else if ( strncmp(input, "BSEARCH_ALG", 11) == 0 ) {
424     charPtr = SkipSpacesTabs(&input[11]);
425     SetBSearchAlg(charPtr);
426     optionSeen[OPTION_BSEARCH_ALG] = TRUE;
427     } else if ( strncmp(input, "BIT_RATE", 8) == 0 ) {
428     charPtr = SkipSpacesTabs(&input[8]);
429     setBitRate(charPtr);
430     optionSeen[OPTION_BIT_RATE] = TRUE;
431     } else if ( strncmp(input, "BUFFER_SIZE", 11) == 0 ) {
432     charPtr = SkipSpacesTabs(&input[11]);
433     setBufferSize(charPtr);
434     optionSeen[OPTION_BUFFER_SIZE] = TRUE;
435     }
436     break;
437    
438     case 'C':
439     if ( strncmp(input, "CDL_FILE", 8) == 0 ) {
440     charPtr = SkipSpacesTabs(&input[8]);
441     strcpy(specificsFile, charPtr);
442     specificsOn=TRUE;
443     optionSeen[OPTION_SPECIFICS] = TRUE;
444     } else if ( strncmp(input, "CDL_DEFINES", 11) == 0 ) {
445     charPtr = SkipSpacesTabs(&input[11]);
446     strcpy(specificsDefines, charPtr);
447     optionSeen[OPTION_DEFS_SPECIFICS] = TRUE;
448     }
449     break;
450    
451     case 'F':
452     if ( strncmp(input, "FRAME_INPUT_DIR", 15) == 0 ) {
453     charPtr = SkipSpacesTabs(&input[15]);
454     if ( strncmp(charPtr, "stdin", 5) == 0 ||
455     strncmp(charPtr, "STDIN", 5) == 0 ) {
456     stdinUsed = TRUE;
457     numInputFiles = MAXINT;
458     numInputFileEntries = 1;
459     }
460     strcpy(currentFramePath, charPtr);
461     } else if ( strncmp(input, "FRAME_INPUT", 11) == 0 ) {
462     if ( function == COMBINE_FRAMES ) {
463     ReadInputFileNames(fpointer, "FRAME_END_INPUT");
464     }
465     } else if ( strncmp(input, "FORCE_I_ALIGN", 13) == 0 ) {
466     forceIalign = TRUE;
467     } else if ( strncmp(input, "FORCE_ENCODE_LAST_FRAME", 23) == 0 ) {
468     forceEncodeLast = TRUE;
469     } else if ( strncmp(input, "FRAME_RATE", 10) == 0 ) {
470     charPtr = SkipSpacesTabs(&input[10]);
471     frameRate = GetFrameRate(charPtr);
472     frameRateRounded = (int) VidRateNum[frameRate];
473     if ( (frameRate % 3) == 1) {
474     frameRateInteger = FALSE;
475     }
476     optionSeen[OPTION_FRAME_RATE] = TRUE;
477     }
478     break;
479    
480     case 'G':
481     if ( strncmp(input, "GOP_SIZE", 8) == 0 ) {
482     charPtr = SkipSpacesTabs(&input[8]);
483     SetGOPSize(atoi(charPtr));
484     optionSeen[OPTION_GOP] = TRUE;
485     } else if ( strncmp(input, "GOP_INPUT_DIR", 13) == 0 ) {
486     charPtr = SkipSpacesTabs(&input[13]);
487     if ( strncmp(charPtr, "stdin", 5) == 0 ||
488     strncmp(charPtr, "STDIN", 5) == 0 ) {
489     stdinUsed = TRUE;
490     numInputFiles = MAXINT;
491     numInputFileEntries = 1;
492     }
493     strcpy(currentGOPPath, charPtr);
494     } else if ( strncmp(input, "GOP_INPUT", 9) == 0 ) {
495     if ( function == COMBINE_GOPS ) {
496     ReadInputFileNames(fpointer, "GOP_END_INPUT");
497     }
498     } else if ( strncmp(input, "GAMMA", 5) == 0) {
499     charPtr = SkipSpacesTabs(&input[5]);
500     GammaCorrection = TRUE;
501     sscanf(charPtr,"%f",&GammaValue);
502     optionSeen[OPTION_GAMMA] = TRUE;
503     }
504     break;
505    
506     case 'I':
507     if ( strncmp(input, "IQSCALE", 7) == 0 ) {
508     charPtr = SkipSpacesTabs(&input[7]);
509     SetIQScale(atoi(charPtr));
510     optionSeen[OPTION_IQSCALE] = TRUE;
511     } else if ( strncmp(input, "INPUT_DIR", 9) == 0 ) {
512     charPtr = SkipSpacesTabs(&input[9]);
513     if ( strncmp(charPtr, "stdin", 5) == 0 ||
514     strncmp(charPtr, "STDIN", 5) == 0 ) {
515     stdinUsed = TRUE;
516     numInputFiles = MAXINT;
517     numInputFileEntries = 1;
518     }
519     strcpy(currentPath, charPtr);
520     optionSeen[OPTION_INPUT_DIR] = TRUE;
521     } else if ( strncmp(input, "INPUT_CONVERT", 13) == 0 ) {
522     charPtr = SkipSpacesTabs(&input[13]);
523     strcpy(inputConversion, charPtr);
524     optionSeen[OPTION_INPUT_CONVERT] = TRUE;
525     } else if ( strcmp(input, "INPUT") == 0 ) { /* yes, strcmp */
526     if ( function == ENCODE_FRAMES ) {
527     ReadInputFileNames(fpointer, "END_INPUT");
528     optionSeen[OPTION_INPUT] = TRUE;
529     }
530     } else if ( strncmp(input, "IO_SERVER_CONVERT", 17) == 0 ) {
531     charPtr = SkipSpacesTabs(&input[17]);
532     strcpy(ioConversion, charPtr);
533     optionSeen[OPTION_IO_CONVERT] = TRUE;
534     } else if ( strncmp(input, "IQTABLE", 7) == 0 ) {
535     for ( row = 0; row < 8; row ++ ) {
536     fgets(input, 256, fpointer);
537     charPtr = input;
538     if (8!=sscanf(charPtr,"%d %d %d %d %d %d %d %d",
539     &qtable[row*8+0], &qtable[row*8+1],
540     &qtable[row*8+2], &qtable[row*8+3],
541     &qtable[row*8+4], &qtable[row*8+5],
542     &qtable[row*8+6], &qtable[row*8+7])) {
543     fprintf(stderr, "Line %d of IQTABLE doesn't have 8 elements!\n", row);
544     exit(1);
545     }
546     for ( col = 0; col < 8; col ++ ) {
547     if ((qtable[row*8+col]<1) || (qtable[row*8+col]>255)) {
548     fprintf(stderr,
549     "Warning: IQTable Element %1d,%1d (%d) corrected to 1-255.\n",
550     row+1, col+1, qtable[row*8+col]);
551     qtable[row*8+col] = (qtable[row*8+col]<1)?1:255;
552     }}
553     }
554    
555     if ( qtable[0] != 8 ) {
556     fprintf(stderr, "Warning: IQTable Element 1,1 reset to 8, since it must be 8.\n");
557     qtable[0] = 8;
558     }
559     customQtable = qtable;
560     optionSeen[OPTION_IQTABLE] = TRUE;
561     } else if ( strncmp(input, "INPUT", 5) == 0 ) { /* handle spaces after input */
562     log(10.0);
563     charPtr = SkipSpacesTabs(&input[5]);
564     if ( function == ENCODE_FRAMES && *charPtr==0) {
565     ReadInputFileNames(fpointer, "END_INPUT");
566     optionSeen[OPTION_INPUT] = TRUE;
567     }
568     }
569     break;
570    
571     case 'N':
572     if ( strncmp(input, "NIQTABLE", 8) == 0 ) {
573     for ( row = 0; row < 8; row ++ ) {
574     fgets(input, 256, fpointer);
575     charPtr = input;
576     if (8!=sscanf(charPtr,"%d %d %d %d %d %d %d %d",
577     &niqtable[row*8+0], &niqtable[row*8+1],
578     &niqtable[row*8+2], &niqtable[row*8+3],
579     &niqtable[row*8+4], &niqtable[row*8+5],
580     &niqtable[row*8+6], &niqtable[row*8+7])) {
581     fprintf(stderr, "Line %d of NIQTABLE doesn't have 8 elements!\n", row);
582     exit(1);
583     }
584     for ( col = 0; col < 8; col++ ) {
585     if ((niqtable[row*8+col]<1) || (niqtable[row*8+col]>255)) {
586     fprintf(stderr,
587     "Warning: NIQTable Element %1d,%1d (%d) corrected to 1-255.\n",
588     row+1, col+1, niqtable[row*8+col]);
589     niqtable[row*8+col]=(niqtable[row*8+col]<1)?1:255;
590     }}
591     }
592    
593     customNIQtable = niqtable;
594     optionSeen[OPTION_NIQTABLE] = TRUE;
595     }
596     break;
597    
598     case 'O':
599     if ( strncmp(input, "OUTPUT", 6) == 0 ) {
600     charPtr = SkipSpacesTabs(&input[6]);
601     if ( whichGOP == -1 ) {
602     strcpy(outputFileName, charPtr);
603     } else {
604     sprintf(outputFileName, "%s.gop.%d",
605     charPtr, whichGOP);
606     }
607    
608     optionSeen[OPTION_OUTPUT] = TRUE;
609     }
610     break;
611    
612     case 'P':
613     if ( strncmp(input, "PATTERN", 7) == 0 ) {
614     charPtr = SkipSpacesTabs(&input[7]);
615     SetFramePattern(charPtr);
616     optionSeen[OPTION_PATTERN] = TRUE;
617     } else if ( strncmp(input, "PIXEL", 5) == 0 ) {
618     charPtr = SkipSpacesTabs(&input[5]);
619     SetPixelSearch(charPtr);
620     optionSeen[OPTION_PIXEL] = TRUE;
621     } else if ( strncmp(input, "PQSCALE", 7) == 0 ) {
622     charPtr = SkipSpacesTabs(&input[7]);
623     SetPQScale(atoi(charPtr));
624     optionSeen[OPTION_PQSCALE] = TRUE;
625     } else if ( strncmp(input, "PSEARCH_ALG", 11) == 0 ) {
626     charPtr = SkipSpacesTabs(&input[11]);
627     SetPSearchAlg(charPtr);
628     optionSeen[OPTION_PSEARCH_ALG] = TRUE;
629     } else if ( strncmp(input, "PARALLEL_TEST_FRAMES", 20) == 0 ) {
630     SetParallelPerfect(FALSE);
631     charPtr = SkipSpacesTabs(&input[20]);
632     parallelTestFrames = atoi(charPtr);
633     } else if ( strncmp(input, "PARALLEL_TIME_CHUNKS", 20) == 0 ) {
634     SetParallelPerfect(FALSE);
635     charPtr = SkipSpacesTabs(&input[20]);
636     parallelTimeChunks = atoi(charPtr);
637     } else if ( strncmp(input, "PARALLEL_CHUNK_TAPER", 20) == 0 ) {
638     SetParallelPerfect(FALSE);
639     parallelTimeChunks = -1;
640     } else if ( strncmp(input, "PARALLEL_PERFECT", 16) == 0 ) {
641     SetParallelPerfect(TRUE);
642     } else if ( strncmp(input, "PARALLEL", 8) == 0 ) {
643     ReadMachineNames(fpointer);
644     optionSeen[OPTION_PARALLEL] = TRUE;
645     }
646     break;
647    
648     case 'R':
649     if ( strncmp(input, "RANGE", 5) == 0 ) {
650     int num_ranges=0,a,b;
651     charPtr = SkipSpacesTabs(&input[5]);
652     optionSeen[OPTION_RANGE] = TRUE;
653     num_ranges=sscanf(charPtr,"%d %d",&a,&b);
654     if (num_ranges==2) {
655     SetSearchRange(a,b);
656     } else if (sscanf(charPtr,"%d [%d]",&a,&b)==2) {
657     SetSearchRange(a,b);
658     } else SetSearchRange(a,a);
659     } else if ( strncmp(input, "REFERENCE_FRAME", 15) == 0 ) {
660     charPtr = SkipSpacesTabs(&input[15]);
661     SetReferenceFrameType(charPtr);
662     optionSeen[OPTION_REF_FRAME] = TRUE;
663     } else if ( strncmp(input, "RSH", 3) == 0 ) {
664     charPtr = SkipSpacesTabs(&input[3]);
665     SetRemoteShell(charPtr);
666     } else if ( strncmp(input, "RESIZE", 6) == 0 ) {
667     charPtr = SkipSpacesTabs(&input[6]);
668     sscanf(charPtr, "%dx%d", &outputWidth, &outputHeight);
669     outputWidth &= ~(DCTSIZE * 2 - 1);
670     outputHeight &= ~(DCTSIZE * 2 - 1);
671     optionSeen[OPTION_RESIZE] = TRUE;
672     }
673     break;
674    
675     case 'S':
676     if ( strncmp(input, "SLICES_PER_FRAME", 16) == 0 ) {
677     charPtr = SkipSpacesTabs(&input[16]);
678     SetSlicesPerFrame(atoi(charPtr));
679     optionSeen[OPTION_SPF] = TRUE;
680     } else if ( strncmp(input, "SLAVE_CONVERT", 13) == 0 ) {
681     charPtr = SkipSpacesTabs(&input[13]);
682     strcpy(slaveConversion, charPtr);
683     optionSeen[OPTION_SLAVE_CONVERT] = TRUE;
684     } else if ( strncmp(input, "SPECIFICS_FILE", 14) == 0 ) {
685     charPtr = SkipSpacesTabs(&input[14]);
686     strcpy(specificsFile, charPtr);
687     specificsOn=TRUE;
688     optionSeen[OPTION_SPECIFICS] = TRUE;
689     } else if ( strncmp(input, "SPECIFICS_DEFINES", 16) == 0 ) {
690     charPtr = SkipSpacesTabs(&input[17]);
691     strcpy(specificsDefines, charPtr);
692     optionSeen[OPTION_DEFS_SPECIFICS] = TRUE;
693     } else if (strncmp(input, "SEQUENCE_SIZE", 13) == 0) {
694     charPtr = SkipSpacesTabs(&input[13]);
695     mult_seq_headers = atoi(charPtr);
696     } else if (strncmp(input, "SIZE", 4) == 0 ) {
697     charPtr = SkipSpacesTabs(&input[4]);
698     sscanf(charPtr, "%dx%d", &yuvWidth, &yuvHeight);
699     realWidth = yuvWidth;
700     realHeight = yuvHeight;
701     Fsize_Validate(&yuvWidth, &yuvHeight);
702     optionSeen[OPTION_YUV_SIZE] = TRUE;
703     }
704     break;
705    
706     case 'T':
707     if ( strncmp(input, "TUNE", 4) == 0) {
708     tuneingOn = TRUE;
709     charPtr = SkipSpacesTabs(&input[4]);
710     ParseTuneParam(charPtr);
711     }
712     break;
713    
714     case 'U':
715     if ( strncmp(input, "USER_DATA", 9) == 0 ) {
716     charPtr = SkipSpacesTabs(&input[9]);
717     strcpy(userDataFileName, charPtr);
718     optionSeen[OPTION_USER_DATA] = TRUE;
719     }
720     break;
721    
722     case 'Y':
723     if (strncmp(input, "YUV_SIZE", 8) == 0 ) {
724     charPtr = SkipSpacesTabs(&input[8]);
725     sscanf(charPtr, "%dx%d", &yuvWidth, &yuvHeight);
726     realWidth = yuvWidth;
727     realHeight = yuvHeight;
728     Fsize_Validate(&yuvWidth, &yuvHeight);
729     optionSeen[OPTION_YUV_SIZE] = TRUE;
730     }
731     else if (strncmp(input, "Y_SIZE", 6) == 0 ) {
732     charPtr = SkipSpacesTabs(&input[6]);
733     sscanf(charPtr, "%dx%d", &yuvWidth, &yuvHeight);
734     realWidth = yuvWidth;
735     realHeight = yuvHeight;
736     Fsize_Validate(&yuvWidth, &yuvHeight);
737     optionSeen[OPTION_YUV_SIZE] = TRUE;
738     }
739     else if ( strncmp(input, "YUV_FORMAT", 10) == 0 ) {
740     charPtr = SkipSpacesTabs(&input[10]);
741     strcpy(yuvConversion, charPtr);
742     optionSeen[OPTION_YUV_FORMAT] = TRUE;
743     }
744     break;
745     }
746     }
747    
748 wdelano 69 /* WLD */
749     if(fpointer != stdin) {
750     fclose(fpointer);
751     }
752     /* WLD END */
753 wdelano 22
754     for ( index = FIRST_OPTION; index <= LAST_OPTION; index++ ) {
755     if ( ! optionSeen[index] ) {
756    
757     /* INPUT unnecessary when stdin is used */
758     if ((index == OPTION_INPUT) && stdinUsed) {
759     continue;
760     }
761    
762     fprintf(stderr, "ERROR: Missing option '%s'\n", optionText[index]);
763     exit(1);
764     }
765     }
766    
767     /* error checking */
768     if ( yuvUsed ) {
769    
770     if (! optionSeen[OPTION_YUV_SIZE]) {
771     fprintf(stderr, "ERROR: YUV format used but YUV_SIZE not given\n");
772     exit(1);
773     }
774    
775     if (! optionSeen[OPTION_YUV_FORMAT]) {
776     strcpy (yuvConversion, "EYUV");
777     fprintf(stderr, "WARNING: YUV format not specified; defaulting to Berkeley YUV (EYUV)\n\n");
778     }
779    
780     }
781    
782     if ( stdinUsed && optionSeen[OPTION_PARALLEL] ) {
783     fprintf(stderr, "ERROR: stdin reading for parallel execution not enabled yet.\n");
784     exit(1);
785     }
786    
787    
788     if ( optionSeen[OPTION_PARALLEL] && !optionSeen[OPTION_YUV_SIZE]) {
789     fprintf(stderr, "ERROR: Specify SIZE WxH for parallel encoding\n");
790     exit(1);
791     }
792    
793     if ( optionSeen[OPTION_IO_CONVERT] != optionSeen[OPTION_SLAVE_CONVERT] ) {
794     fprintf(stderr, "ERROR: must have either both IO_SERVER_CONVERT and SLAVE_CONVERT\n");
795     fprintf(stderr, " or neither\n");
796     exit(1);
797     }
798    
799     if ( optionSeen[OPTION_DEFS_SPECIFICS] && !optionSeen[OPTION_SPECIFICS]) {
800     fprintf(stderr, "ERROR: does not make sense to define Specifics file options, but no specifics file!\n");
801     exit(1);
802     }
803    
804     SetIOConvert(optionSeen[OPTION_IO_CONVERT]);
805    
806     SetResize(optionSeen[OPTION_RESIZE]);
807    
808     if ( function == ENCODE_FRAMES ) {
809     SetFCode();
810    
811     if ( psearchAlg == PSEARCH_TWOLEVEL )
812     SetPixelSearch("HALF");
813     }
814    
815     return TRUE;
816     }
817    
818    
819     /*===========================================================================*
820     *
821     * GetNthInputFileName
822     *
823     * finds the nth input file name
824     *
825     * RETURNS: name is placed in already allocated fileName string
826     *
827     * SIDE EFFECTS: none
828     *
829     *===========================================================================*/
830     void
831     GetNthInputFileName(fileName, n)
832     char *fileName;
833     int n;
834     {
835     static int lastN = 0, lastMapN = 0, lastSoFar = 0;
836     int mapN;
837     register int index;
838     int soFar;
839     int loop;
840     int numPadding;
841     char numBuffer[33];
842    
843     if ( stdinUsed ) {
844     return;
845     }
846    
847     /* assumes n is within bounds 0...numInputFiles-1 */
848    
849     if ( n >= lastN ) {
850     soFar = lastSoFar;
851     index = lastMapN;
852     } else {
853     soFar = 0;
854     index = 0;
855     }
856    
857     while ( soFar + inputFileEntries[index]->numFiles <= n ) {
858     soFar += inputFileEntries[index]->numFiles;
859     index++;
860     }
861    
862     mapN = index;
863    
864     index = inputFileEntries[mapN]->startID +
865     inputFileEntries[mapN]->skip*(n-soFar);
866    
867     numPadding = inputFileEntries[mapN]->numPadding;
868    
869     if ( numPadding != -1 ) {
870     sprintf(numBuffer, "%32d", index);
871     for ( loop = 32-numPadding; loop < 32; loop++ ) {
872     if ( numBuffer[loop] != ' ' ) {
873     break;
874     } else {
875     numBuffer[loop] = '0';
876     }
877     }
878    
879     if (inputFileEntries[mapN]->repeat != TRUE) {
880     sprintf(fileName, "%s%s%s",
881     inputFileEntries[mapN]->left,
882     &numBuffer[32-numPadding],
883     inputFileEntries[mapN]->right);
884     } else {
885     sprintf(fileName, "%s", inputFileEntries[mapN]->left);
886     }
887     } else {
888     if (inputFileEntries[mapN]->repeat != TRUE) {
889     sprintf(fileName, "%s%d%s",
890     inputFileEntries[mapN]->left,
891     index,
892     inputFileEntries[mapN]->right);
893     } else {
894     sprintf(fileName, "%s", inputFileEntries[mapN]->left);
895     }
896     }
897    
898     lastN = n;
899     lastMapN = mapN;
900     lastSoFar = soFar;
901     }
902    
903    
904     /*=====================*
905     * INTERNAL PROCEDURES *
906     *=====================*/
907    
908     /*===========================================================================*
909     *
910     * ReadMachineNames
911     *
912     * read a list of machine names for parallel execution
913     *
914     * RETURNS: nothing
915     *
916     * SIDE EFFECTS: machine info updated
917     *
918     *===========================================================================*/
919     static void
920     ReadMachineNames(fpointer)
921     FILE *fpointer;
922     {
923     char input[256];
924     char *charPtr;
925    
926     while ( (fgets(input, 256, fpointer) != NULL) &&
927     (strncmp(input, "END_PARALLEL", 12) != 0) ) {
928     if ( input[0] == '#' || input[0] == '\n') {
929     continue;
930     }
931    
932     if ( strncmp(input, "REMOTE", 6) == 0 ) {
933     charPtr = SkipSpacesTabs(&input[6]);
934     remote[numMachines] = TRUE;
935    
936     sscanf(charPtr, "%s %s %s %s", machineName[numMachines],
937     userName[numMachines], executable[numMachines],
938     remoteParamFile[numMachines]);
939     } else {
940     remote[numMachines] = FALSE;
941    
942     sscanf(input, "%s %s %s", machineName[numMachines],
943     userName[numMachines], executable[numMachines]);
944     }
945    
946     numMachines++;
947     }
948     }
949    
950    
951     /*===========================================================================*
952     *
953     * ReadInputFileNames
954     *
955     * read a list of input file names
956     *
957     * RETURNS: nothing
958     *
959     * SIDE EFFECTS: info stored for retrieval using GetNthInputFileName
960     *
961     *===========================================================================*/
962     static void
963     ReadInputFileNames(fpointer, endInput)
964     FILE *fpointer;
965     char *endInput;
966     {
967     char input[256];
968     char left[256], right[256];
969     char *globPtr, *charPtr;
970     char leftNumText[256], rightNumText[256];
971     char skipNumText[256];
972     int leftNum, rightNum;
973     int skipNum;
974     boolean padding;
975     int numPadding = 0;
976     int length;
977     char full_path[MAXPATHLEN + 256];
978     FILE *jmovie;
979    
980     inputFileEntries = (InputFileEntry **) malloc(INPUT_ENTRY_BLOCK_SIZE*
981     sizeof(InputFileEntry *));
982     maxInputFileEntries = INPUT_ENTRY_BLOCK_SIZE;
983    
984     length = strlen(endInput);
985    
986     /* read input files up until endInput */
987     while ( (fgets(input, 256, fpointer) != NULL) &&
988     (strncmp(input, endInput, length) != 0) ) {
989    
990     /* if input is coming in via standard input, keep on looping till the
991     * endInput string is reached so that the program points to the right
992     * place on exit.
993     */
994     if ( stdinUsed ) {
995     continue;
996     }
997    
998     /* ignore comments and newlines */
999     if ( (input[0] == '#') || (input[0] == '\n') ) {
1000     continue;
1001     }
1002    
1003     if (input[0] == '`' ) { /* Recurse for commands */
1004     FILE *fp;
1005     char cmd[300], *start, *end, tmp[300], cdcmd[110];
1006    
1007     start = &input[1];
1008     end = &input[strlen(input)-1];
1009    
1010     while (*end != '`') {
1011     end--;
1012     }
1013    
1014     end--;
1015    
1016     if (optionSeen[OPTION_INPUT_DIR] == TRUE) {
1017     sprintf(cdcmd,"cd %s;",currentPath);
1018     } else {
1019     strcpy(cdcmd,"");
1020     }
1021     strncpy(tmp,start,end-start+1);
1022     sprintf(cmd,"(%s %s)", cdcmd, tmp);
1023    
1024     fp = popen(cmd,"r");
1025     if (fp == NULL) {
1026     fprintf(stderr,"Command failed! Could not open piped command:\n%s\n",cmd);
1027     continue;
1028     }
1029     ReadInputFileNames(fp,"HOPE-THIS_ISNT_A_FILENAME.xyz5555");
1030     continue;
1031     }
1032    
1033    
1034     /* get rid of trailing whitespace including newline */
1035     while (isspace(input[strlen(input)-1])) {
1036     input[strlen(input)-1] = '\0';
1037     }
1038    
1039     if ( numInputFileEntries == maxInputFileEntries ) { /* more space! */
1040     maxInputFileEntries += INPUT_ENTRY_BLOCK_SIZE;
1041     inputFileEntries = (InputFileEntry **) realloc(inputFileEntries,
1042     maxInputFileEntries*
1043     sizeof(InputFileEntry *));
1044     }
1045    
1046     inputFileEntries[numInputFileEntries] = (InputFileEntry *)
1047     malloc(sizeof(InputFileEntry));
1048    
1049     if ( input[strlen(input)-1] == ']' ) {
1050     inputFileEntries[numInputFileEntries]->glob = TRUE;
1051     inputFileEntries[numInputFileEntries]->repeat = FALSE;
1052    
1053     /* star expand */
1054    
1055     globPtr = input;
1056     charPtr = left;
1057     /* copy left of '*' */
1058     while ( (*globPtr != '\0') && (*globPtr != '*') ) {
1059     *charPtr = *globPtr;
1060     charPtr++;
1061     globPtr++;
1062     }
1063     *charPtr = '\0';
1064    
1065     if (*globPtr == '\0') {
1066     fprintf(stderr, "WARNING: expanding non-star regular expression\n");
1067     inputFileEntries[numInputFileEntries]->repeat = TRUE;
1068     globPtr = input;
1069     charPtr = left;
1070     /* recopy left of whitespace */
1071     while ( (*globPtr != '\0') && (*globPtr != '*') &&
1072     (*globPtr != ' ') && (*globPtr != '\t')) {
1073     *charPtr = *globPtr;
1074     charPtr++;
1075     globPtr++;
1076     }
1077     *charPtr = '\0';
1078     *right = '\0';
1079     } else {
1080    
1081     globPtr++;
1082     charPtr = right;
1083     /* copy right of '*' */
1084     while ( (*globPtr != '\0') && (*globPtr != ' ') &&
1085     (*globPtr != '\t') ) {
1086     *charPtr = *globPtr;
1087     charPtr++;
1088     globPtr++;
1089     }
1090     *charPtr = '\0';
1091     }
1092    
1093     globPtr = SkipSpacesTabs(globPtr);
1094    
1095     if ( *globPtr != '[' ) {
1096     fprintf(stderr, "ERROR: Invalid input file expansion expression (no '[')\n");
1097     exit(1);
1098     }
1099    
1100     globPtr++;
1101     charPtr = leftNumText;
1102     /* copy left number */
1103     while ( isdigit(*globPtr) ) {
1104     *charPtr = *globPtr;
1105     charPtr++;
1106     globPtr++;
1107     }
1108     *charPtr = '\0';
1109    
1110     if ( *globPtr != '-' ) {
1111     fprintf(stderr, "ERROR: Invalid input file expansion expression (no '-')\n");
1112     exit(1);
1113     }
1114    
1115     globPtr++;
1116     charPtr = rightNumText;
1117     /* copy right number */
1118     while ( isdigit(*globPtr) ) {
1119     *charPtr = *globPtr;
1120     charPtr++;
1121     globPtr++;
1122     }
1123     *charPtr = '\0';
1124     if ( atoi(rightNumText) < atoi(leftNumText) ) {
1125     fprintf(stderr, "ERROR: Beginning of input range is higher than end.\n");
1126     exit(1);
1127     }
1128    
1129    
1130     if ( *globPtr != ']' ) {
1131     if ( *globPtr != '+' ) {
1132     fprintf(stderr, "ERROR: Invalid input file expansion expression (no ']')\n");
1133     exit(1);
1134     }
1135    
1136     globPtr++;
1137     charPtr = skipNumText;
1138     /* copy skip number */
1139     while ( isdigit(*globPtr) ) {
1140     *charPtr = *globPtr;
1141     charPtr++;
1142     globPtr++;
1143     }
1144     *charPtr = '\0';
1145    
1146     if ( *globPtr != ']' ) {
1147     fprintf(stderr, "ERROR: Invalid input file expansion expression (no ']')\n");
1148     exit(1);
1149     }
1150    
1151     skipNum = atoi(skipNumText);
1152     } else {
1153     skipNum = 1;
1154     }
1155    
1156     leftNum = atoi(leftNumText);
1157     rightNum = atoi(rightNumText);
1158    
1159     if ( (leftNumText[0] == '0') && (leftNumText[1] != '\0') ) {
1160     padding = TRUE;
1161     numPadding = strlen(leftNumText);
1162     } else {
1163     padding = FALSE;
1164     }
1165    
1166     inputFileEntries[numInputFileEntries]->startID = leftNum;
1167     inputFileEntries[numInputFileEntries]->endID = rightNum;
1168     inputFileEntries[numInputFileEntries]->skip = skipNum;
1169     inputFileEntries[numInputFileEntries]->numFiles = (rightNum-leftNum+1)/skipNum;
1170     strcpy(inputFileEntries[numInputFileEntries]->left, left);
1171     strcpy(inputFileEntries[numInputFileEntries]->right, right);
1172     if ( padding ) {
1173     inputFileEntries[numInputFileEntries]->numPadding = numPadding;
1174     } else {
1175     inputFileEntries[numInputFileEntries]->numPadding = -1;
1176     }
1177     } else {
1178     strcpy(inputFileEntries[numInputFileEntries]->left, input);
1179     if (baseFormat == JMOVIE_FILE_TYPE) {
1180     inputFileEntries[numInputFileEntries]->glob = TRUE;
1181     full_path[0] = '\0';
1182     strcpy(full_path, currentPath);
1183    
1184     if (! stdinUsed) {
1185     strcat(full_path, "/");
1186     strcat(full_path, input);
1187     jmovie = fopen(input, "rb");
1188    
1189     if (jmovie == NULL) {
1190     perror (input);
1191     exit (1);
1192     }
1193    
1194     fseek (jmovie, (8*sizeof(char)), 0);
1195     fseek (jmovie, (2*sizeof(int)), 1);
1196    
1197     if (fread (&(inputFileEntries[numInputFileEntries]->numFiles),
1198     sizeof(int), 1, jmovie) != 1) {
1199     perror ("Error in reading number of frames in JMOVIE");
1200     exit(1);
1201     }
1202     fclose (jmovie);
1203     }
1204    
1205     strcpy(inputFileEntries[numInputFileEntries]->right,".jpg");
1206     inputFileEntries[numInputFileEntries]->numPadding = -1;
1207     inputFileEntries[numInputFileEntries]->startID = 1;
1208     inputFileEntries[numInputFileEntries]->endID = (inputFileEntries[numInputFileEntries]->numFiles-1);
1209     inputFileEntries[numInputFileEntries]->skip = 1;
1210     if (! realQuiet) {
1211     fprintf (stdout, "Encoding all %d frames from JMOVIE.\n", inputFileEntries[numInputFileEntries]->endID);
1212     }
1213     } else {
1214     inputFileEntries[numInputFileEntries]->glob = FALSE;
1215     inputFileEntries[numInputFileEntries]->numFiles = 1;
1216     /* fixes a bug from version 1.3: */
1217     inputFileEntries[numInputFileEntries]->numPadding = 0;
1218     /* fixes a bug from version 1.4 */
1219     strcpy(inputFileEntries[numInputFileEntries]->right,"\0");
1220     inputFileEntries[numInputFileEntries]->startID = 0;
1221     inputFileEntries[numInputFileEntries]->endID = 0;
1222     inputFileEntries[numInputFileEntries]->skip = 0;
1223     }
1224     }
1225    
1226     numInputFiles += inputFileEntries[numInputFileEntries]->numFiles;
1227     numInputFileEntries++;
1228     }
1229     }
1230    
1231    
1232     /*===========================================================================*
1233     *
1234     * SkipSpacesTabs
1235     *
1236     * skip all spaces and tabs
1237     *
1238     * RETURNS: point to next character not a space or tab
1239     *
1240     * SIDE EFFECTS: none
1241     *
1242     *===========================================================================*/
1243     char *
1244     SkipSpacesTabs(start)
1245     char *start;
1246     {
1247     while ( (*start == ' ') || (*start == '\t') ) {
1248     start++;
1249     }
1250    
1251     return start;
1252     }
1253    
1254    
1255     /*===========================================================================*
1256     *
1257     * GetFrameRate
1258     *
1259     * take a character string with the input frame rate
1260     * and return the correct frame rate code for use in the Sequence header
1261     *
1262     * RETURNS: frame rate code as per MPEG-I spec
1263     *
1264     * SIDE EFFECTS: none
1265     *
1266     *===========================================================================*/
1267     static int
1268     GetFrameRate(p)
1269     char *p;
1270     {
1271     float rate;
1272     int thouRate;
1273    
1274     sscanf(p, "%f", &rate);
1275     thouRate = (int)(0.5+1000.0*rate);
1276    
1277     if ( thouRate == 23976 ) return 1;
1278     else if ( thouRate == 24000 ) return 2;
1279     else if ( thouRate == 25000 ) return 3;
1280     else if ( thouRate == 29970 ) return 4;
1281     else if ( thouRate == 30000 ) return 5;
1282     else if ( thouRate == 50000 ) return 6;
1283     else if ( thouRate == 59940 ) return 7;
1284     else if ( thouRate == 60000 ) return 8;
1285     else {
1286     fprintf(stderr,"INVALID FRAME RATE: %s frames/sec\n", p);
1287     exit(1);
1288     }
1289     }
1290    
1291    
1292     /*===========================================================================*
1293     *
1294     * GetAspectRatio
1295     *
1296     * take a character string with the pixel aspect ratio
1297     * and returns the correct aspect ratio code for use in the Sequence header
1298     *
1299     * RETURNS: aspect ratio code as per MPEG-I spec
1300     *
1301     * SIDE EFFECTS: none
1302     *
1303     *===========================================================================*/
1304     static int
1305     GetAspectRatio(p)
1306     char *p;
1307     {
1308     float ratio;
1309     int ttRatio;
1310    
1311     sscanf(p, "%f", &ratio);
1312     ttRatio = (int)(0.5+ratio*10000.0);
1313    
1314     if ( ttRatio == 10000 ) return 1;
1315     else if ( ttRatio == 6735 ) return 2;
1316     else if ( ttRatio == 7031 ) return 3;
1317     else if ( ttRatio == 7615 ) return 4;
1318     else if ( ttRatio == 8055 ) return 5;
1319     else if ( ttRatio == 8437 ) return 6;
1320     else if ( ttRatio == 8935 ) return 7;
1321     else if ( ttRatio == 9157 ) return 8;
1322     else if ( ttRatio == 9815 ) return 9;
1323     else if ( ttRatio == 10255 ) return 10;
1324     else if ( ttRatio == 10695 ) return 11;
1325     else if ( ttRatio == 10950 ) return 12;
1326     else if ( ttRatio == 11575 ) return 13;
1327     else if ( ttRatio == 12015 ) return 14;
1328     else {
1329     fprintf(stderr,"INVALID ASPECT RATIO: %s frames/sec\n", p);
1330     exit(1);
1331     }
1332     }
1333    
1334    
1335    
1336    
1337    
1338    
1339     /****************************************************************
1340     * Jim Boucher's code
1341     *
1342     *
1343     ****************************************************************/
1344     void
1345     JM2JPEG()
1346     {
1347     char full_path[MAXPATHLEN + 256];
1348     char inter_file[MAXPATHLEN +256];
1349     int ci;
1350    
1351     for(ci = 0; ci < numInputFileEntries; ci++) {
1352     inter_file[0] = '\0';
1353     full_path[0] = '\0';
1354     strcpy(full_path, currentPath);
1355    
1356     if (! stdinUsed) {
1357     strcat(full_path, "/");
1358     strcat(full_path, inputFileEntries[ci]->left);
1359     strcpy(inter_file,full_path);
1360    
1361     if (! realQuiet) {
1362     fprintf(stdout, "Extracting JPEG's in the JMOVIE from %s\n",full_path);
1363     }
1364    
1365     JMovie2JPEG(full_path,
1366     inter_file,
1367     inputFileEntries[ci]->startID, inputFileEntries[ci]->endID);
1368     } else {
1369     fprintf (stderr, "ERROR: JMovie format not supported with stdin yet.\n");
1370     exit(1);
1371     }
1372    
1373     }
1374     }