~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to packages/base/pasjpeg/cjpeg.pas

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2005-05-30 11:59:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050530115910-x5pbzm4qqta4i94h
Tags: 2.0.0-2
debian/fp-compiler.postinst.in: forgot to reapply the patch that
correctly creates the slave link to pc(1).  (Closes: #310907)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
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. }
20
20
 
21
21
{$I jconfig.inc}
22
 
 
 
22
{$undef PPM_SUPPORTED}
23
23
 
24
24
uses
25
25
  jmorecfg,
26
 
  cdjpeg,               { Common decls for cjpeg/djpeg applications }
 
26
  cdjpeg,               { Common decls for cjpeg/djpeg applications }
27
27
  {jversion,}           { for version message }
28
28
  jpeglib,
29
29
 
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}
37
36
  {cderror,}
38
37
  jdeferr;
64
63
 
65
64
 
66
65
var
67
 
 is_targa : boolean;    { records user -targa switch }
 
66
 is_targa : boolean;    { records user -targa switch }
68
67
 
69
68
function GetFirstChar(cinfo : j_compress_ptr;
70
69
                      fptr : fileptr) : char;
74
73
  if JFREAD(fptr, @c, 1) <> 1 then
75
74
    ERREXIT(j_common_ptr(cinfo), JERR_INPUT_EMPTY);
76
75
 
 
76
{$ifndef delphi_stream}
77
77
  Seek(fptr^, 0);        { Nomssi: probably not portable }
 
78
{$else}
 
79
  Fptr^.Seek(0,0);
 
80
{$endif}
78
81
  if (IOresult <> 0) then
79
82
    ERREXIT(j_common_ptr(cinfo), JERR_UNGETC_FAILED);
80
83
  GetFirstChar := c;
99
102
 
100
103
  c := GetFirstChar(cinfo, @infile);
101
104
 
102
 
  select_file_type := NIL;      { suppress compiler warnings }
 
105
  select_file_type := NIL;      { suppress compiler warnings }
103
106
  case c of
104
107
{$ifdef BMP_SUPPORTED}
105
108
  'B': select_file_type := jinit_read_bmp(cinfo);
130
133
 
131
134
 
132
135
var
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 }
135
138
 
136
139
 
137
140
{LOCAL}
202
205
 
203
206
{LOCAL}
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).
220
223
  value : int;
221
224
  code : integer;
222
225
var
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. }
246
249
 
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
268
271
      begin
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 }
271
274
      end;
272
 
      break;                    { else done parsing switches }
 
275
      break;                    { else done parsing switches }
273
276
    end;
274
 
    {Inc(arg);                  - advance past switch marker character }
 
277
    {Inc(arg);                  - advance past switch marker character }
275
278
 
276
279
    if (keymatch(arg, '-arithmetic', 2)) then
277
280
    begin
296
299
    begin
297
300
      { Select DCT algorithm. }
298
301
      Inc(argn);
299
 
      if (argn >= argc) then    { advance to next argument }
300
 
        usage;
 
302
      if (argn >= argc) then    { advance to next argument }
 
303
        usage;
301
304
      if (keymatch(ParamStr(argn), 'int', 1)) then
302
305
      begin
303
 
        cinfo^.dct_method := JDCT_ISLOW;
 
306
        cinfo^.dct_method := JDCT_ISLOW;
304
307
      end
305
308
      else
306
309
        if (keymatch(ParamStr(argn), 'fast', 2)) then
307
310
        begin
308
 
          cinfo^.dct_method := JDCT_IFAST;
 
311
          cinfo^.dct_method := JDCT_IFAST;
309
312
        end
310
313
        else
311
314
          if (keymatch(ParamStr(argn), 'float', 2)) then
312
315
          begin
313
 
            cinfo^.dct_method := JDCT_FLOAT;
 
316
            cinfo^.dct_method := JDCT_FLOAT;
314
317
          end
315
318
          else
316
 
            usage;
 
319
            usage;
317
320
 
318
321
    end
319
322
    else
324
327
 
325
328
        if (not printed_version) then
326
329
        begin
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;
331
334
        end;
332
335
        Inc(cinfo^.err^.trace_level);
333
336
 
345
348
          ch := 'x';
346
349
 
347
350
          Inc(argn);
348
 
          if (argn >= argc) then        { advance to next argument }
349
 
            usage;
 
351
          if (argn >= argc) then        { advance to next argument }
 
352
            usage;
350
353
 
351
354
          arg := ParamStr(argn);
352
355
          if (length(arg) > 1) and (arg[length(arg)] in ['m','M']) then
356
359
          end;
357
360
          Val(arg, lval, code);
358
361
          if (code <> 1) then
359
 
            usage;
 
362
            usage;
360
363
          if (ch = 'm') or (ch = 'M') then
361
 
            lval := lval * long(1000);
 
364
            lval := lval * long(1000);
362
365
          cinfo^.mem^.max_memory_to_use := lval * long(1000);
363
366
 
364
367
        end
379
382
            begin
380
383
              { Set output file name. }
381
384
              Inc(argn);
382
 
              if (argn >= argc) then    { advance to next argument }
383
 
                usage;
384
 
              outfilename := ParamStr(argn);    { save it away for later use }
 
385
              if (argn >= argc) then    { advance to next argument }
 
386
                usage;
 
387
              outfilename := ParamStr(argn);    { save it away for later use }
385
388
 
386
389
            end
387
390
            else
402
405
                begin
403
406
                  { Quality factor (quantization table scaling factor). }
404
407
                  Inc(argn);
405
 
                  if (argn >= argc) then        { advance to next argument }
406
 
                    usage;
 
408
                  if (argn >= argc) then        { advance to next argument }
 
409
                    usage;
407
410
                  Val(ParamStr(argn), quality, code);
408
411
                  if code <> 0 then
409
 
                    usage;
 
412
                    usage;
410
413
 
411
414
                  { Change scale factor in case -qtables is present. }
412
415
                  q_scale_factor := jpeg_quality_scaling(quality);
417
420
                  begin
418
421
                    { Quantization table slot numbers. }
419
422
                    Inc(argn);
420
 
                    if (argn >= argc) then      { advance to next argument }
421
 
                      usage;
 
423
                    if (argn >= argc) then      { advance to next argument }
 
424
                      usage;
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
430
433
                    begin
431
434
                      { Quantization tables fetched from file. }
432
435
                      Inc(argn);
433
 
                      if (argn >= argc) then    { advance to next argument }
434
 
                        usage;
 
436
                      if (argn >= argc) then    { advance to next argument }
 
437
                        usage;
435
438
                      qtablefile := ParamStr(argn);
436
439
                      { We postpone actually reading the file in case -quality comes later. }
437
440
 
443
446
                        ch := 'x';
444
447
 
445
448
                        Inc(argn);
446
 
                        if (argn >= argc) then  { advance to next argument }
447
 
                          usage;
 
449
                        if (argn >= argc) then  { advance to next argument }
 
450
                          usage;
448
451
 
449
452
                        arg := ParamStr(argn);
450
453
                        if (length(arg) > 1) and (arg[length(arg)] in ['b','B']) then
455
458
 
456
459
                        Val(arg, lval, Code);
457
460
                        if (code <> 1) then
458
 
                          usage;
 
461
                          usage;
459
462
                        if (lval < 0) or (lval > long(65535)) then
460
 
                          usage;
 
463
                          usage;
461
464
                        if (ch = 'b') or (ch = 'B') then
462
465
                        begin
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 }
465
468
                        end
466
469
                        else
467
470
                        begin
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 }
470
473
                        end;
471
474
                      end
472
475
                      else
474
477
                        begin
475
478
                          { Set sampling factors. }
476
479
                          Inc(argn);
477
 
                          if (argn >= argc) then        { advance to next argument }
478
 
                            usage;
 
480
                          if (argn >= argc) then        { advance to next argument }
 
481
                            usage;
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}
490
493
                            Inc(argn);
491
 
                            if (argn >= argc) then      { advance to next argument }
492
 
                              usage;
 
494
                            if (argn >= argc) then      { advance to next argument }
 
495
                              usage;
493
496
                            scansarg := ParamStr(argn);
494
497
                            { We must postpone reading the file in case -progressive appears. }
495
498
                      {$else}
504
507
                              { Set input smoothing factor. }
505
508
 
506
509
                              Inc(argn);
507
 
                              if (argn >= argc) then    { advance to next argument }
508
 
                                usage;
 
510
                              if (argn >= argc) then    { advance to next argument }
 
511
                                usage;
509
512
                              Val(ParamStr(argn), value, code);
510
513
                              if (value < 0) or (value > 100)
511
514
                                 or (code <> 0) then
512
 
                                usage;
 
515
                                usage;
513
516
                              cinfo^.smoothing_factor := value;
514
517
 
515
518
                            end
522
525
                              end
523
526
                              else
524
527
                              begin
525
 
                                usage;                  { bogus switch }
 
528
                                usage;                  { bogus switch }
526
529
                              end;
527
530
  end;
528
531
 
536
539
    jpeg_set_quality(cinfo, quality, force_baseline);
537
540
 
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
542
 
        usage;
 
544
                              q_scale_factor, force_baseline)) then
 
545
        usage;
543
546
 
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
546
 
        usage;
 
549
        usage;
547
550
 
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
550
 
        usage;
 
553
        usage;
551
554
{$ENDIF}
552
555
 
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);
556
559
{$endif}
557
560
 
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
562
 
        usage;
 
565
        usage;
563
566
{$endif}
564
567
{$ENDIF}
565
568
  end;
566
569
 
567
 
  parse_switches := argn;       { return index of next arg (file name) }
 
570
  parse_switches := argn;       { return index of next arg (file name) }
568
571
end;
569
572
 
570
573