~ubuntu-branches/ubuntu/saucy/libjpeg-turbo/saucy-security

« back to all changes in this revision

Viewing changes to cjpeg.c

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2013-07-28 16:52:51 UTC
  • mfrom: (1.1.3) (9.1.1 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130728165251-7vg6wszhm941kdej
Tags: 1.3.0-0ubuntu1
* New upstream release.
  - drop debian/patches/branch-updates.diff
  - refresh tjunittest.patch (now renamed to install-tjunittest.patch)
* Update debian/control:
  - add myself to Uploaders.
* Update debian/copyright:
  - add RSA Data Security copyright (md5).
* Update debian/libturbojpeg.install:
  - install libturbojpeg.so.0* (needed by tjunittest and tjbench).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * cjpeg.c
3
3
 *
 
4
 * This file was part of the Independent JPEG Group's software:
4
5
 * Copyright (C) 1991-1998, Thomas G. Lane.
5
 
 * Modified 2003-2008 by Guido Vollbeding.
6
 
 * Copyright (C) 2010, D. R. Commander.
7
 
 * This file is part of the Independent JPEG Group's software.
 
6
 * Modified 2003-2011 by Guido Vollbeding.
 
7
 * Modifications:
 
8
 * Copyright (C) 2010, 2013, D. R. Commander.
8
9
 * For conditions of distribution and use, see the accompanying README file.
9
10
 *
10
11
 * This file contains a command-line user interface for the JPEG compressor.
138
139
 
139
140
static const char * progname;   /* program name for error messages */
140
141
static char * outfilename;      /* for -outfile switch */
 
142
boolean memdst;  /* for -memdst switch */
141
143
 
142
144
 
143
145
LOCAL(void)
154
156
  fprintf(stderr, "Switches (names may be abbreviated):\n");
155
157
  fprintf(stderr, "  -quality N[,...]   Compression quality (0..100; 5-95 is useful range)\n");
156
158
  fprintf(stderr, "  -grayscale     Create monochrome JPEG file\n");
 
159
  fprintf(stderr, "  -rgb           Create RGB JPEG file\n");
157
160
#ifdef ENTROPY_OPT_SUPPORTED
158
161
  fprintf(stderr, "  -optimize      Optimize Huffman table (smaller file, but slow compression)\n");
159
162
#endif
185
188
#endif
186
189
  fprintf(stderr, "  -maxmemory N   Maximum memory to use (in kbytes)\n");
187
190
  fprintf(stderr, "  -outfile name  Specify name for output file\n");
 
191
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
 
192
  fprintf(stderr, "  -memdst        Compress to memory instead of file (useful for benchmarking)\n");
 
193
#endif
188
194
  fprintf(stderr, "  -verbose  or  -debug   Emit debug output\n");
189
195
  fprintf(stderr, "Switches for wizards:\n");
190
196
  fprintf(stderr, "  -baseline      Force baseline quantization tables\n");
226
232
  simple_progressive = FALSE;
227
233
  is_targa = FALSE;
228
234
  outfilename = NULL;
 
235
  memdst = FALSE;
229
236
  cinfo->err->trace_level = 0;
230
237
 
231
238
  /* Scan command line options, adjust parameters */
278
285
        fprintf(stderr, "%s version %s (build %s)\n",
279
286
                PACKAGE_NAME, VERSION, BUILD);
280
287
        fprintf(stderr, "%s\n\n", JCOPYRIGHT);
281
 
        fprintf(stderr, "Emulating The Independent JPEG Group's libjpeg, version %s\n\n",
 
288
        fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
282
289
                JVERSION);
283
290
        printed_version = TRUE;
284
291
      }
288
295
      /* Force a monochrome JPEG file to be generated. */
289
296
      jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
290
297
 
 
298
    } else if (keymatch(arg, "rgb", 3)) {
 
299
      /* Force an RGB JPEG file to be generated. */
 
300
      jpeg_set_colorspace(cinfo, JCS_RGB);
 
301
 
291
302
    } else if (keymatch(arg, "maxmemory", 3)) {
292
303
      /* Maximum memory in Kb (or Mb with 'm'). */
293
304
      long lval;
306
317
#ifdef ENTROPY_OPT_SUPPORTED
307
318
      cinfo->optimize_coding = TRUE;
308
319
#else
309
 
      fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
 
320
      fprintf(stderr, "%s: sorry, entropy optimization was not compiled in\n",
310
321
              progname);
311
322
      exit(EXIT_FAILURE);
312
323
#endif
323
334
      simple_progressive = TRUE;
324
335
      /* We must postpone execution until num_components is known. */
325
336
#else
326
 
      fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
 
337
      fprintf(stderr, "%s: sorry, progressive output was not compiled in\n",
327
338
              progname);
328
339
      exit(EXIT_FAILURE);
329
340
#endif
330
341
 
 
342
    } else if (keymatch(arg, "memdst", 2)) {
 
343
      /* Use in-memory destination manager */
 
344
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
 
345
      memdst = TRUE;
 
346
#else
 
347
      fprintf(stderr, "%s: sorry, in-memory destination manager was not compiled in\n",
 
348
              progname);
 
349
      exit(EXIT_FAILURE);
 
350
#endif
 
351
 
331
352
    } else if (keymatch(arg, "quality", 1)) {
332
353
      /* Quality ratings (quantization table scaling factors). */
333
354
      if (++argn >= argc)       /* advance to next argument */
388
409
      scansarg = argv[argn];
389
410
      /* We must postpone reading the file in case -progressive appears. */
390
411
#else
391
 
      fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
 
412
      fprintf(stderr, "%s: sorry, multi-scan output was not compiled in\n",
392
413
              progname);
393
414
      exit(EXIT_FAILURE);
394
415
#endif
467
488
  int file_index;
468
489
  cjpeg_source_ptr src_mgr;
469
490
  FILE * input_file;
470
 
  FILE * output_file;
 
491
  FILE * output_file = NULL;
 
492
  unsigned char *outbuffer = NULL;
 
493
  unsigned long outsize = 0;
471
494
  JDIMENSION num_scanlines;
472
495
 
473
496
  /* On Mac, fetch a command line. */
510
533
  file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
511
534
 
512
535
#ifdef TWO_FILE_COMMANDLINE
513
 
  /* Must have either -outfile switch or explicit output file name */
514
 
  if (outfilename == NULL) {
515
 
    if (file_index != argc-2) {
516
 
      fprintf(stderr, "%s: must name one input and one output file\n",
517
 
              progname);
518
 
      usage();
519
 
    }
520
 
    outfilename = argv[file_index+1];
521
 
  } else {
522
 
    if (file_index != argc-1) {
523
 
      fprintf(stderr, "%s: must name one input and one output file\n",
524
 
              progname);
525
 
      usage();
 
536
  if (!memdst) {
 
537
    /* Must have either -outfile switch or explicit output file name */
 
538
    if (outfilename == NULL) {
 
539
      if (file_index != argc-2) {
 
540
        fprintf(stderr, "%s: must name one input and one output file\n",
 
541
                progname);
 
542
        usage();
 
543
      }
 
544
      outfilename = argv[file_index+1];
 
545
    } else {
 
546
      if (file_index != argc-1) {
 
547
        fprintf(stderr, "%s: must name one input and one output file\n",
 
548
                progname);
 
549
        usage();
 
550
      }
526
551
    }
527
552
  }
528
553
#else
550
575
      fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
551
576
      exit(EXIT_FAILURE);
552
577
    }
553
 
  } else {
 
578
  } else if (!memdst) {
554
579
    /* default output file is stdout */
555
580
    output_file = write_stdout();
556
581
  }
573
598
  file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
574
599
 
575
600
  /* Specify data destination for compression */
576
 
  jpeg_stdio_dest(&cinfo, output_file);
 
601
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
 
602
  if (memdst)
 
603
    jpeg_mem_dest(&cinfo, &outbuffer, &outsize);
 
604
  else
 
605
#endif
 
606
    jpeg_stdio_dest(&cinfo, output_file);
577
607
 
578
608
  /* Start compressor */
579
609
  jpeg_start_compress(&cinfo, TRUE);
592
622
  /* Close files, if we opened them */
593
623
  if (input_file != stdin)
594
624
    fclose(input_file);
595
 
  if (output_file != stdout)
 
625
  if (output_file != stdout && output_file != NULL)
596
626
    fclose(output_file);
597
627
 
598
628
#ifdef PROGRESS_REPORT
599
629
  end_progress_monitor((j_common_ptr) &cinfo);
600
630
#endif
601
631
 
 
632
  if (memdst) {
 
633
    fprintf(stderr, "Compressed size:  %lu bytes\n", outsize);
 
634
    if (outbuffer != NULL)
 
635
      free(outbuffer);
 
636
  }
 
637
 
602
638
  /* All done. */
603
639
  exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
604
640
  return 0;                     /* suppress no-return-value warnings */