7
7
{ Two different command line styles are permitted, depending on the
8
8
compile-time switch TWO_FILE_COMMANDLINE:
9
cjpeg [options] inputfile outputfile
10
cjpeg [options] [inputfile]
9
cjpeg [options] inputfile outputfile
10
cjpeg [options] [inputfile]
11
11
In the second style, output is always to standard output, which you'd
12
12
normally redirect to a file or pipe to some other program. Input is
13
13
either from a named file or from standard input (typically redirected).
15
15
don't support pipes. Also, you MUST use the first style if your system
16
16
doesn't do binary I/O to stdin/stdout.
17
17
To simplify script writing, the "-outfile" switch is provided. The syntax
18
cjpeg [options] -outfile outputfile inputfile
18
cjpeg [options] -outfile outputfile inputfile
19
19
works regardless of which command line style is used. }
22
{$undef PPM_SUPPORTED}
26
cdjpeg, { Common decls for cjpeg/djpeg applications }
26
cdjpeg, { Common decls for cjpeg/djpeg applications }
27
27
{jversion,} { for version message }
32
32
JcAPImin, JcAPIstd, JcParam,
33
33
{$ifdef TARGA_SUPPORTED} rdtarga, {$endif}
34
34
{$ifdef BMP_SUPPORTED} rdbmp, {$endif}
35
{$ifdef PPM_SUPPORTED} rdppm, {$endif}
36
35
{$ifdef EXT_SWITCH} rdswitch, {$endif}
74
73
if JFREAD(fptr, @c, 1) <> 1 then
75
74
ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EMPTY);
76
{$ifndef delphi_stream}
77
77
Seek(fptr^, 0); { Nomssi: probably not portable }
78
81
if (IOresult <> 0) then
79
82
ERREXIT(j_common_ptr(cinfo), JERR_UNGETC_FAILED);
100
103
c := GetFirstChar(cinfo, @infile);
102
select_file_type := NIL; { suppress compiler warnings }
105
select_file_type := NIL; { suppress compiler warnings }
104
107
{$ifdef BMP_SUPPORTED}
105
108
'B': select_file_type := jinit_read_bmp(cinfo);
133
progname, { program name for error messages }
134
outfilename : string[79]; { for -outfile switch }
136
progname, { program name for error messages }
137
outfilename : string[79]; { for -outfile switch }
204
207
function parse_switches (cinfo : j_compress_ptr;
205
last_file_arg_seen : int;
208
last_file_arg_seen : int;
206
209
for_real : boolean) : int;
207
210
{ Parse optional switches.
208
211
Returns argv[] index of first file-name argument (== argc if none).
223
quality : int; { -quality parameter }
224
q_scale_factor : int; { scaling percentage for -qtables }
226
quality : int; { -quality parameter }
227
q_scale_factor : int; { scaling percentage for -qtables }
225
228
force_baseline : boolean;
226
229
simple_progressive : boolean;
227
230
qtablefile, { saves -qtables filename if any }
244
247
{ Note that default -quality level need not, and does not,
245
248
match the default scaling for an explicit -qtables argument. }
247
quality := 75; { default -quality value }
248
q_scale_factor := 100; { default to no scaling for -qtables }
249
force_baseline := FALSE; { by default, allow 16-bit quantizers }
250
quality := 75; { default -quality value }
251
q_scale_factor := 100; { default to no scaling for -qtables }
252
force_baseline := FALSE; { by default, allow 16-bit quantizers }
250
253
simple_progressive := FALSE;
251
254
is_targa := FALSE;
252
255
outfilename := '';
266
269
{ Not a switch, must be a file name argument }
267
270
if (argn <= last_file_arg_seen) then
269
outfilename := ''; { -outfile applies to just one input file }
270
continue; { ignore this name if previously processed }
272
outfilename := ''; { -outfile applies to just one input file }
273
continue; { ignore this name if previously processed }
272
break; { else done parsing switches }
275
break; { else done parsing switches }
274
{Inc(arg); - advance past switch marker character }
277
{Inc(arg); - advance past switch marker character }
276
279
if (keymatch(arg, '-arithmetic', 2)) then
297
300
{ Select DCT algorithm. }
299
if (argn >= argc) then { advance to next argument }
302
if (argn >= argc) then { advance to next argument }
301
304
if (keymatch(ParamStr(argn), 'int', 1)) then
303
cinfo^.dct_method := JDCT_ISLOW;
306
cinfo^.dct_method := JDCT_ISLOW;
306
309
if (keymatch(ParamStr(argn), 'fast', 2)) then
308
cinfo^.dct_method := JDCT_IFAST;
311
cinfo^.dct_method := JDCT_IFAST;
311
314
if (keymatch(ParamStr(argn), 'float', 2)) then
313
cinfo^.dct_method := JDCT_FLOAT;
316
cinfo^.dct_method := JDCT_FLOAT;
325
328
if (not printed_version) then
327
WriteLn(output, 'Independent JPEG Group''s CJPEG, version ', JVERSION);
330
WriteLn(output, 'Independent JPEG Group''s CJPEG, version ', JVERSION);
328
331
WriteLn(output, JCOPYRIGHT);
329
332
WriteLn(output, JNOTICE);
330
printed_version := TRUE;
333
printed_version := TRUE;
332
335
Inc(cinfo^.err^.trace_level);
380
383
{ Set output file name. }
382
if (argn >= argc) then { advance to next argument }
384
outfilename := ParamStr(argn); { save it away for later use }
385
if (argn >= argc) then { advance to next argument }
387
outfilename := ParamStr(argn); { save it away for later use }
403
406
{ Quality factor (quantization table scaling factor). }
405
if (argn >= argc) then { advance to next argument }
408
if (argn >= argc) then { advance to next argument }
407
410
Val(ParamStr(argn), quality, code);
408
411
if code <> 0 then
411
414
{ Change scale factor in case -qtables is present. }
412
415
q_scale_factor := jpeg_quality_scaling(quality);
418
421
{ Quantization table slot numbers. }
420
if (argn >= argc) then { advance to next argument }
423
if (argn >= argc) then { advance to next argument }
422
425
qslotsarg := ParamStr(argn);
423
426
{ Must delay setting qslots until after we have processed any
424
427
colorspace-determining switches, since jpeg_set_colorspace sets
431
434
{ Quantization tables fetched from file. }
433
if (argn >= argc) then { advance to next argument }
436
if (argn >= argc) then { advance to next argument }
435
438
qtablefile := ParamStr(argn);
436
439
{ We postpone actually reading the file in case -quality comes later. }
456
459
Val(arg, lval, Code);
457
460
if (code <> 1) then
459
462
if (lval < 0) or (lval > long(65535)) then
461
464
if (ch = 'b') or (ch = 'B') then
463
cinfo^.restart_interval := uInt (lval);
464
cinfo^.restart_in_rows := 0; { else prior '-restart n' overrides me }
466
cinfo^.restart_interval := uInt (lval);
467
cinfo^.restart_in_rows := 0; { else prior '-restart n' overrides me }
468
cinfo^.restart_in_rows := int (lval);
469
{ restart_interval will be computed during startup }
471
cinfo^.restart_in_rows := int (lval);
472
{ restart_interval will be computed during startup }
475
478
{ Set sampling factors. }
477
if (argn >= argc) then { advance to next argument }
480
if (argn >= argc) then { advance to next argument }
479
482
samplearg := ParamStr(argn);
480
483
{ Must delay setting sample factors until after we have processed any
481
484
colorspace-determining switches, since jpeg_set_colorspace sets
488
491
{ Set scan script. }
489
492
{$ifdef C_MULTISCAN_FILES_SUPPORTED}
491
if (argn >= argc) then { advance to next argument }
494
if (argn >= argc) then { advance to next argument }
493
496
scansarg := ParamStr(argn);
494
497
{ We must postpone reading the file in case -progressive appears. }
504
507
{ Set input smoothing factor. }
507
if (argn >= argc) then { advance to next argument }
510
if (argn >= argc) then { advance to next argument }
509
512
Val(ParamStr(argn), value, code);
510
513
if (value < 0) or (value > 100)
511
514
or (code <> 0) then
513
516
cinfo^.smoothing_factor := value;
536
539
jpeg_set_quality(cinfo, quality, force_baseline);
538
541
{$IFDEF EXT_SWITCH}
539
if (qtablefile <> '') then { process -qtables if it was present }
542
if (qtablefile <> '') then { process -qtables if it was present }
540
543
if (not read_quant_tables(cinfo, qtablefile,
541
q_scale_factor, force_baseline)) then
544
q_scale_factor, force_baseline)) then
544
if (qslotsarg <> '') then { process -qslots if it was present }
547
if (qslotsarg <> '') then { process -qslots if it was present }
545
548
if (not set_quant_slots(cinfo, qslotsarg)) then
548
if (samplearg <> '') then { process -sample if it was present }
551
if (samplearg <> '') then { process -sample if it was present }
549
552
if (not set_sample_factors(cinfo, samplearg)) then
553
556
{$ifdef C_PROGRESSIVE_SUPPORTED}
554
if (simple_progressive) then { process -progressive; -scans can override }
557
if (simple_progressive) then { process -progressive; -scans can override }
555
558
jpeg_simple_progression(cinfo);
558
561
{$IFDEF EXT_SWITCH}
559
562
{$ifdef C_MULTISCAN_FILES_SUPPORTED}
560
if (scansarg <> '') then { process -scans if it was present }
563
if (scansarg <> '') then { process -scans if it was present }
561
564
if (not read_scan_script(cinfo, scansarg)) then
567
parse_switches := argn; { return index of next arg (file name) }
570
parse_switches := argn; { return index of next arg (file name) }