home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR2 / DVPG30FS.ZIP / JDMASTER.C < prev    next >
C/C++ Source or Header  |  1993-02-19  |  6KB  |  177 lines

  1. /*
  2.  * jdmaster.c
  3.  *
  4.  * Copyright (C) 1991, 1992, 1993, 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 the main control for the JPEG decompressor.
  9.  * The system-dependent (user interface) code should call jpeg_decompress()
  10.  * after doing appropriate setup of the decompress_info_struct parameter.
  11.  */
  12.  
  13. #include "jinclude.h"
  14.  
  15.  
  16. METHODDEF void
  17. d_per_scan_method_selection (decompress_info_ptr cinfo)
  18. /* Central point for per-scan method selection */
  19. {
  20.   /* MCU disassembly */
  21.   jseldmcu(cinfo);
  22.   /* Upsampling of pixels */
  23.   jselupsample(cinfo);
  24. }
  25.  
  26.  
  27. LOCAL void
  28. d_initial_method_selection (decompress_info_ptr cinfo)
  29. /* Central point for initial method selection (after reading file header) */
  30. {
  31.   /* JPEG file scanning method selection is already done. */
  32.   /* So is output file format selection (both are done by user interface). */
  33.  
  34.   /* Gamma and color space conversion */
  35.   /* NB: this may change the component_needed flags */
  36.   jseldcolor(cinfo);
  37.  
  38.   /* Color quantization selection rules */
  39. #ifdef QUANT_1PASS_SUPPORTED
  40. #ifdef QUANT_2PASS_SUPPORTED
  41.   /* We have both, check for conditions in which 1-pass should be used */
  42.   if (cinfo->num_components != 3 || cinfo->jpeg_color_space != CS_YCbCr)
  43.     cinfo->two_pass_quantize = FALSE; /* 2-pass only handles YCbCr input */
  44.   if (cinfo->out_color_space == CS_GRAYSCALE)
  45.     cinfo->two_pass_quantize = FALSE; /* Should use 1-pass for grayscale out */
  46. #else /* not QUANT_2PASS_SUPPORTED */
  47.   cinfo->two_pass_quantize = FALSE; /* only have 1-pass */
  48. #endif
  49. #else /* not QUANT_1PASS_SUPPORTED */
  50. #ifdef QUANT_2PASS_SUPPORTED
  51.   cinfo->two_pass_quantize = TRUE; /* only have 2-pass */
  52. #else /* not QUANT_2PASS_SUPPORTED */
  53.   if (cinfo->quantize_colors) {
  54.     ERREXIT(cinfo->emethods, "Color quantization was not compiled");
  55.   }
  56. #endif
  57. #endif
  58.  
  59. #ifdef QUANT_1PASS_SUPPORTED
  60.   jsel1quantize(cinfo);
  61. #endif
  62. #ifdef QUANT_2PASS_SUPPORTED
  63.   jsel2quantize(cinfo);
  64. #endif
  65.  
  66.   /* Cross-block smoothing */
  67. #ifdef BLOCK_SMOOTHING_SUPPORTED
  68.   jselbsmooth(cinfo);
  69. #else
  70.   cinfo->do_block_smoothing = FALSE;
  71. #endif
  72.  
  73.   /* Entropy decoding: either Huffman or arithmetic coding. */
  74. #ifdef D_ARITH_CODING_SUPPORTED
  75.   jseldarithmetic(cinfo);
  76. #else
  77.   if (cinfo->arith_code) {
  78.     ERREXIT(cinfo->emethods, "Arithmetic coding not supported");
  79.   }
  80. #endif
  81.   jseldhuffman(cinfo);
  82.  
  83.   /* Pipeline control */
  84.   jseldpipeline(cinfo);
  85.   /* Overall control (that's me!) */
  86.   cinfo->methods->d_per_scan_method_selection = d_per_scan_method_selection;
  87. }
  88.  
  89.  
  90. LOCAL void
  91. initial_setup (decompress_info_ptr cinfo)
  92. /* Do computations that are needed before initial method selection */
  93. {
  94.   short ci;
  95.   jpeg_component_info *compptr;
  96.  
  97.   /* Compute maximum sampling factors; check factor validity */
  98.   cinfo->max_h_samp_factor = 1;
  99.   cinfo->max_v_samp_factor = 1;
  100.   for (ci = 0; ci < cinfo->num_components; ci++) {
  101.     compptr = &cinfo->comp_info[ci];
  102.     if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  103.     compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  104.       ERREXIT(cinfo->emethods, "Bogus sampling factors");
  105.     cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  106.                    compptr->h_samp_factor);
  107.     cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  108.                    compptr->v_samp_factor);
  109.  
  110.   }
  111.  
  112.   /* Compute logical downsampled dimensions of components */
  113.   for (ci = 0; ci < cinfo->num_components; ci++) {
  114.     compptr = &cinfo->comp_info[ci];
  115.     compptr->true_comp_width = (cinfo->image_width * compptr->h_samp_factor
  116.                 + cinfo->max_h_samp_factor - 1)
  117.                 / cinfo->max_h_samp_factor;
  118.     compptr->true_comp_height = (cinfo->image_height * compptr->v_samp_factor
  119.                  + cinfo->max_v_samp_factor - 1)
  120.                  / cinfo->max_v_samp_factor;
  121.   }
  122. }
  123.  
  124.  
  125. /*
  126.  * This is the main entry point to the JPEG decompressor.
  127.  */
  128.  
  129.  
  130. GLOBAL void
  131. jpeg_decompress (decompress_info_ptr cinfo)
  132. {
  133.   /* Init pass counts to 0 --- total_passes is adjusted in method selection */
  134.   cinfo->total_passes = 0;
  135.   cinfo->completed_passes = 0;
  136.  
  137.   /* Read the JPEG file header markers; everything up through the first SOS
  138.    * marker is read now.  NOTE: the user interface must have initialized the
  139.    * read_file_header method pointer (eg, by calling jselrjfif or jselrtiff).
  140.    * The other file reading methods (read_scan_header etc.) were probably
  141.    * set at the same time, but could be set up by read_file_header itself.
  142.    */
  143.   (*cinfo->methods->read_file_header) (cinfo);
  144.   if (! ((*cinfo->methods->read_scan_header) (cinfo)))
  145.     ERREXIT(cinfo->emethods, "Empty JPEG file");
  146.  
  147.   /* Give UI a chance to adjust decompression parameters and select */
  148.   /* output file format based on info from file header. */
  149.   (*cinfo->methods->d_ui_method_selection) (cinfo);
  150.  
  151.   /* Now select methods for decompression steps. */
  152.   initial_setup(cinfo);
  153.   d_initial_method_selection(cinfo);
  154.  
  155.   /* Initialize the output file & other modules as needed */
  156.   /* (modules needing per-scan init are called by pipeline controller) */
  157.  
  158.   (*cinfo->methods->output_init) (cinfo);
  159.   (*cinfo->methods->colorout_init) (cinfo);
  160.   if (cinfo->quantize_colors)
  161.     (*cinfo->methods->color_quant_init) (cinfo);
  162.  
  163.   /* And let the pipeline controller do the rest. */
  164.   (*cinfo->methods->d_pipeline_controller) (cinfo);
  165.  
  166.   /* Finish output file, release working storage, etc */
  167.   if (cinfo->quantize_colors)
  168.     (*cinfo->methods->color_quant_term) (cinfo);
  169.   (*cinfo->methods->colorout_term) (cinfo);
  170.   (*cinfo->methods->output_term) (cinfo);
  171.   (*cinfo->methods->read_file_trailer) (cinfo);
  172.  
  173.   (*cinfo->emethods->free_all) ();
  174.  
  175.   /* My, that was easy, wasn't it? */
  176. }
  177.