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

« back to all changes in this revision

Viewing changes to djpeg.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
 * djpeg.c
3
3
 *
 
4
 * This file was part of the Independent JPEG Group's software:
4
5
 * Copyright (C) 1991-1997, Thomas G. Lane.
5
 
 * Copyright (C) 2010-2011, D. R. Commander.
6
 
 * This file is part of the Independent JPEG Group's software.
 
6
 * Modifications:
 
7
 * Copyright (C) 2010-2011, 2013, D. R. Commander.
7
8
 * For conditions of distribution and use, see the accompanying README file.
8
9
 *
9
10
 * This file contains a command-line user interface for the JPEG decompressor.
86
87
 
87
88
static const char * progname;   /* program name for error messages */
88
89
static char * outfilename;      /* for -outfile switch */
 
90
boolean memsrc;  /* for -memsrc switch */
 
91
#define INPUT_BUF_SIZE  4096
89
92
 
90
93
 
91
94
LOCAL(void)
156
159
#endif
157
160
  fprintf(stderr, "  -maxmemory N   Maximum memory to use (in kbytes)\n");
158
161
  fprintf(stderr, "  -outfile name  Specify name for output file\n");
 
162
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
 
163
  fprintf(stderr, "  -memsrc        Load input file into memory before decompressing\n");
 
164
#endif
 
165
 
159
166
  fprintf(stderr, "  -verbose  or  -debug   Emit debug output\n");
160
167
  exit(EXIT_FAILURE);
161
168
}
179
186
  /* Set up default JPEG parameters. */
180
187
  requested_fmt = DEFAULT_FMT;  /* set default output file format */
181
188
  outfilename = NULL;
 
189
  memsrc = FALSE;
182
190
  cinfo->err->trace_level = 0;
183
191
 
184
192
  /* Scan command line options, adjust parameters */
246
254
        fprintf(stderr, "%s version %s (build %s)\n",
247
255
                PACKAGE_NAME, VERSION, BUILD);
248
256
        fprintf(stderr, "%s\n\n", JCOPYRIGHT);
249
 
        fprintf(stderr, "Emulating The Independent JPEG Group's libjpeg, version %s\n\n",
 
257
        fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
250
258
                JVERSION);
251
259
        printed_version = TRUE;
252
260
      }
324
332
        usage();
325
333
      outfilename = argv[argn]; /* save it away for later use */
326
334
 
 
335
    } else if (keymatch(arg, "memsrc", 2)) {
 
336
      /* Use in-memory source manager */
 
337
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
 
338
      memsrc = TRUE;
 
339
#else
 
340
      fprintf(stderr, "%s: sorry, in-memory source manager was not compiled in\n",
 
341
              progname);
 
342
      exit(EXIT_FAILURE);
 
343
#endif
 
344
 
327
345
    } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) {
328
346
      /* PPM/PGM output format. */
329
347
      requested_fmt = FMT_PPM;
442
460
  djpeg_dest_ptr dest_mgr = NULL;
443
461
  FILE * input_file;
444
462
  FILE * output_file;
 
463
  unsigned char *inbuffer = NULL;
 
464
  unsigned long insize = 0;
445
465
  JDIMENSION num_scanlines;
446
466
 
447
467
  /* On Mac, fetch a command line. */
536
556
#endif
537
557
 
538
558
  /* Specify data source for decompression */
539
 
  jpeg_stdio_src(&cinfo, input_file);
 
559
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
 
560
  if (memsrc) {
 
561
    size_t nbytes;
 
562
    do {
 
563
      inbuffer = (unsigned char *)realloc(inbuffer, insize + INPUT_BUF_SIZE);
 
564
      if (inbuffer == NULL) {
 
565
        fprintf(stderr, "%s: memory allocation failure\n", progname);
 
566
        exit(EXIT_FAILURE);
 
567
      }
 
568
      nbytes = JFREAD(input_file, &inbuffer[insize], INPUT_BUF_SIZE);
 
569
      if (nbytes < 0) {
 
570
        if (file_index < argc)
 
571
          fprintf(stderr, "%s: can't read from %s\n", progname,
 
572
                  argv[file_index]);
 
573
        else
 
574
          fprintf(stderr, "%s: can't read from stdin\n", progname);
 
575
      }
 
576
      insize += (unsigned long)nbytes;
 
577
    } while (nbytes == INPUT_BUF_SIZE);
 
578
    fprintf(stderr, "Compressed size:  %lu bytes\n", insize);
 
579
    jpeg_mem_src(&cinfo, inbuffer, insize);
 
580
  } else
 
581
#endif
 
582
    jpeg_stdio_src(&cinfo, input_file);
540
583
 
541
584
  /* Read file header, set default decompression parameters */
542
585
  (void) jpeg_read_header(&cinfo, TRUE);
620
663
  end_progress_monitor((j_common_ptr) &cinfo);
621
664
#endif
622
665
 
 
666
  if (memsrc && inbuffer != NULL)
 
667
    free(inbuffer);
 
668
 
623
669
  /* All done. */
624
670
  exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
625
671
  return 0;                     /* suppress no-return-value warnings */