home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / compresn / jpegv3sr / jddeflts.c < prev    next >
C/C++ Source or Header  |  1992-03-02  |  6KB  |  155 lines

  1. /*
  2.  * jddeflts.c
  3.  *
  4.  * Copyright (C) 1991, 1992, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains optional default-setting code for the JPEG decompressor.
  9.  * User interfaces do not have to use this file, but those that don't use it
  10.  * must know more about the innards of the JPEG code.
  11.  */
  12.  
  13. #include "jinclude.h"
  14.  
  15.  
  16. /* Default do-nothing progress monitoring routine.
  17.  * This can be overridden by a user interface that wishes to
  18.  * provide progress monitoring; just set methods->progress_monitor
  19.  * after j_d_defaults is done.  The routine will be called periodically
  20.  * during the decompression process.
  21.  *
  22.  * During any one pass, loopcounter increases from 0 up to (not including)
  23.  * looplimit; the step size is not necessarily 1.  Both the step size and
  24.  * the limit may differ between passes.  The expected total number of passes
  25.  * is in cinfo->total_passes, and the number of passes already completed is
  26.  * in cinfo->completed_passes.  Thus the fraction of work completed may be
  27.  * estimated as
  28.  *        completed_passes + (loopcounter/looplimit)
  29.  *        ------------------------------------------
  30.  *                total_passes
  31.  * ignoring the fact that the passes may not be equal amounts of work.
  32.  *
  33.  * When decompressing, the total_passes figure is an estimate that may be
  34.  * on the high side; completed_passes will jump by more than one if some
  35.  * passes are skipped.
  36.  */
  37.  
  38. METHODDEF void
  39. progress_monitor (decompress_info_ptr cinfo, long loopcounter, long looplimit)
  40. {
  41.   /* do nothing */
  42. }
  43.  
  44.  
  45. /*
  46.  * Reload the input buffer after it's been emptied, and return the next byte.
  47.  * See the JGETC macro for calling conditions.
  48.  *
  49.  * This routine can be overridden by the system-dependent user interface,
  50.  * in case the data source is not a stdio stream or some other special
  51.  * condition applies.  Note, however, that this capability only applies for
  52.  * JFIF or similar serial-access JPEG file formats.  The input file control
  53.  * module for a random-access format such as TIFF/JPEG would most likely
  54.  * override the read_jpeg_data method with its own routine.
  55.  */
  56.  
  57. METHODDEF int
  58. read_jpeg_data (decompress_info_ptr cinfo)
  59. {
  60.   cinfo->next_input_byte = cinfo->input_buffer + MIN_UNGET;
  61.  
  62.   cinfo->bytes_in_buffer = (int) JFREAD(cinfo->input_file,
  63.                     cinfo->next_input_byte,
  64.                     JPEG_BUF_SIZE);
  65.   
  66.   if (cinfo->bytes_in_buffer <= 0)
  67.     ERREXIT(cinfo->emethods, "Unexpected EOF in JPEG file");
  68.  
  69.   return JGETC(cinfo);
  70. }
  71.  
  72.  
  73.  
  74. /* Default parameter setup for decompression.
  75.  *
  76.  * User interfaces that don't choose to use this routine must do their
  77.  * own setup of all these parameters.  Alternately, you can call this
  78.  * to establish defaults and then alter parameters selectively.  This
  79.  * is the recommended approach since, if we add any new parameters,
  80.  * your code will still work (they'll be set to reasonable defaults).
  81.  *
  82.  * standard_buffering should be TRUE to cause an input buffer to be allocated
  83.  * (the normal case); if FALSE, the user interface must provide a buffer.
  84.  * This option is most useful in the case that the buffer must not be freed
  85.  * at the end of an image.  (For example, when reading a sequence of images
  86.  * from a single file, the remaining data in the buffer represents the
  87.  * start of the next image and mustn't be discarded.)  To handle this,
  88.  * allocate the input buffer yourself at startup, WITHOUT using alloc_small
  89.  * (probably a direct call to malloc() instead).  Then pass FALSE on each
  90.  * call to j_d_defaults to ensure the buffer state is not modified.
  91.  *
  92.  * If the source of the JPEG data is not a stdio stream, override the
  93.  * read_jpeg_data method with your own routine after calling j_d_defaults.
  94.  * You can still use the standard buffer if it's appropriate.
  95.  *
  96.  * CAUTION: if you want to decompress multiple images per run, it's necessary
  97.  * to call j_d_defaults before *each* call to jpeg_decompress, since subsidiary
  98.  * structures like the quantization tables are automatically freed during
  99.  * cleanup.
  100.  */
  101.  
  102. GLOBAL void
  103. j_d_defaults (decompress_info_ptr cinfo, boolean standard_buffering)
  104. /* NB: the external methods must already be set up. */
  105. {
  106.   short i;
  107.  
  108.   /* Initialize pointers as needed to mark stuff unallocated. */
  109.   /* Outer application may fill in default tables for abbreviated files... */
  110.   cinfo->comp_info = NULL;
  111.   for (i = 0; i < NUM_QUANT_TBLS; i++)
  112.     cinfo->quant_tbl_ptrs[i] = NULL;
  113.   for (i = 0; i < NUM_HUFF_TBLS; i++) {
  114.     cinfo->dc_huff_tbl_ptrs[i] = NULL;
  115.     cinfo->ac_huff_tbl_ptrs[i] = NULL;
  116.   }
  117.   cinfo->colormap = NULL;
  118.  
  119.   /* Default to RGB output */
  120.   /* UI can override by changing out_color_space */
  121.   cinfo->out_color_space = CS_RGB;
  122.   cinfo->jpeg_color_space = CS_UNKNOWN;
  123.   /* Setting any other value in jpeg_color_space overrides heuristics in */
  124.   /* jrdjfif.c.  That might be useful when reading non-JFIF JPEG files, */
  125.   /* but ordinarily the UI shouldn't change it. */
  126.   
  127.   /* Default to no gamma correction of output */
  128.   cinfo->output_gamma = 1.0;
  129.   
  130.   /* Default to no color quantization */
  131.   cinfo->quantize_colors = FALSE;
  132.   /* but set reasonable default parameters for quantization, */
  133.   /* so that turning on quantize_colors is sufficient to do something useful */
  134.   cinfo->two_pass_quantize = TRUE;
  135.   cinfo->use_dithering = TRUE;
  136.   cinfo->desired_number_of_colors = 256;
  137.   
  138.   /* Default to no smoothing */
  139.   cinfo->do_block_smoothing = FALSE;
  140.   cinfo->do_pixel_smoothing = FALSE;
  141.   
  142.   /* Allocate memory for input buffer, unless outer application provides it. */
  143.   if (standard_buffering) {
  144.     cinfo->input_buffer = (char *) (*cinfo->emethods->alloc_small)
  145.                     ((size_t) (JPEG_BUF_SIZE + MIN_UNGET));
  146.     cinfo->bytes_in_buffer = 0;    /* initialize buffer to empty */
  147.   }
  148.  
  149.   /* Install standard buffer-reloading method (outer code may override). */
  150.   cinfo->methods->read_jpeg_data = read_jpeg_data;
  151.  
  152.   /* Install default do-nothing progress monitoring method. */
  153.   cinfo->methods->progress_monitor = progress_monitor;
  154. }
  155.