home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR2 / DVPG30FS.ZIP / JPEGDATA.H < prev    next >
Text File  |  1993-08-22  |  42KB  |  968 lines

  1. /*
  2.  * modified by Eric P for different decompress struct
  3.  */
  4.  
  5. /*
  6.  * jpegdata.h
  7.  *
  8.  * Copyright (C) 1991, 1992, 1993, Thomas G. Lane.
  9.  * This file is part of the Independent JPEG Group's software.
  10.  * For conditions of distribution and use, see the accompanying README file.
  11.  *
  12.  * This file defines shared data structures for the various JPEG modules.
  13.  */
  14.  
  15.  
  16. /*
  17.  * You might need to change some of the following declarations if you are
  18.  * using the JPEG software within a surrounding application program
  19.  * or porting it to an unusual system.
  20.  */
  21.  
  22.  
  23. /* If the source or destination of image data is not to be stdio streams,
  24.  * these types may need work.  You can replace them with some kind of
  25.  * pointer or indicator that is useful to you, or just ignore 'em.
  26.  * Note that the user interface and the various jrdxxx/jwrxxx modules
  27.  * will also need work for non-stdio input/output.
  28.  */
  29.  
  30. typedef FILE * JFILEREF;    /* source or dest of JPEG-compressed data */
  31.  
  32. typedef FILE * IFILEREF;    /* source or dest of non-JPEG image data */
  33.  
  34.  
  35. /* These defines are used in all function definitions and extern declarations.
  36.  * You could modify them if you need to change function linkage conventions,
  37.  * as is shown below for use with C++.  Another application would be to make
  38.  * all functions global for use with code profilers that require it.
  39.  * NOTE: the C++ test does the right thing if you are reading this include
  40.  * file in a C++ application to link to JPEG code that's been compiled with a
  41.  * regular C compiler.  I'm not sure it works if you try to compile the JPEG
  42.  * code with C++.
  43.  */
  44.  
  45. #define METHODDEF static    /* a function called through method pointers */
  46. #define LOCAL      static    /* a function used only in its module */
  47. #define GLOBAL            /* a function referenced thru EXTERNs */
  48. #ifdef __cplusplus
  49. #define EXTERN      extern "C"    /* a reference to a GLOBAL function */
  50. #else
  51. #define EXTERN      extern    /* a reference to a GLOBAL function */
  52. #endif
  53.  
  54.  
  55. /* Here is the pseudo-keyword for declaring pointers that must be "far"
  56.  * on 80x86 machines.  Most of the specialized coding for 80x86 is handled
  57.  * by just saying "FAR *" where such a pointer is needed.  In a few places
  58.  * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
  59.  */
  60.  
  61. #ifdef NEED_FAR_POINTERS
  62. #define FAR  far
  63. #else
  64. #define FAR
  65. #endif
  66.  
  67.  
  68.  
  69. /* The remaining declarations are not system-dependent, we hope. */
  70.  
  71.  
  72. /*
  73.  * NOTE: if you have an ancient, strict-K&R C compiler, it may choke on the
  74.  * similarly-named fields in Compress_info_struct and Decompress_info_struct.
  75.  * If this happens, you can get around it by rearranging the two structs so
  76.  * that the similarly-named fields appear first and in the same order in
  77.  * each struct.  Since such compilers are now pretty rare, we haven't done
  78.  * this in the portable code, preferring to maintain a logical ordering.
  79.  */
  80.  
  81.  
  82.  
  83. /* This macro is used to declare a "method", that is, a function pointer. */
  84. /* We want to supply prototype parameters if the compiler can cope. */
  85. /* Note that the arglist parameter must be parenthesized! */
  86.  
  87. #ifdef PROTO
  88. #define METHOD(type,methodname,arglist)  type (*methodname) arglist
  89. #else
  90. #define METHOD(type,methodname,arglist)  type (*methodname) ()
  91. #endif
  92.  
  93. /* Forward references to lists of method pointers */
  94. typedef struct External_methods_struct * external_methods_ptr;
  95. typedef struct Compress_methods_struct * compress_methods_ptr;
  96. typedef struct Decompress_methods_struct * decompress_methods_ptr;
  97.  
  98.  
  99. /* Data structures for images containing either samples or coefficients. */
  100. /* Note that the topmost (leftmost) index is always color component. */
  101. /* On 80x86 machines, the image arrays are too big for near pointers, */
  102. /* but the pointer arrays can fit in near memory. */
  103.  
  104. typedef JSAMPLE FAR *JSAMPROW;    /* ptr to one image row of pixel samples. */
  105. typedef JSAMPROW *JSAMPARRAY;    /* ptr to some rows (a 2-D sample array) */
  106. typedef JSAMPARRAY *JSAMPIMAGE;    /* a 3-D sample array: top index is color */
  107.  
  108.  
  109. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  110. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  111.  
  112. typedef JCOEF JBLOCK[DCTSIZE2];    /* one block of coefficients */
  113. typedef JBLOCK FAR *JBLOCKROW;    /* pointer to one row of coefficient blocks */
  114. typedef JBLOCKROW *JBLOCKARRAY;        /* a 2-D array of coefficient blocks */
  115. typedef JBLOCKARRAY *JBLOCKIMAGE;    /* a 3-D array of coefficient blocks */
  116.  
  117. typedef JCOEF FAR *JCOEFPTR;    /* useful in a couple of places */
  118.  
  119.  
  120. /* The input and output data of the DCT transform subroutines are of
  121.  * the following type, which need not be the same as JCOEF.
  122.  * For example, on a machine with fast floating point, it might make sense
  123.  * to recode the DCT routines to use floating point; then DCTELEM would be
  124.  * 'float' or 'double'.
  125.  */
  126.  
  127. typedef JCOEF DCTELEM;
  128. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  129.  
  130.  
  131. /* Types for JPEG compression parameters and working tables. */
  132.  
  133.  
  134. typedef enum {            /* defines known color spaces */
  135.     CS_UNKNOWN,        /* error/unspecified */
  136.     CS_GRAYSCALE,        /* monochrome (only 1 component) */
  137.     CS_RGB,            /* red/green/blue */
  138.     CS_YCbCr,        /* Y/Cb/Cr (also known as YUV) */
  139.     CS_YIQ,            /* Y/I/Q */
  140.     CS_CMYK            /* C/M/Y/K */
  141. } COLOR_SPACE;
  142.  
  143.  
  144. typedef struct {        /* Basic info about one component */
  145.   /* These values are fixed over the whole image */
  146.   /* For compression, they must be supplied by the user interface; */
  147.   /* for decompression, they are read from the SOF marker. */
  148.     short component_id;    /* identifier for this component (0..255) */
  149.     short component_index;    /* its index in SOF or cinfo->comp_info[] */
  150.     short h_samp_factor;    /* horizontal sampling factor (1..4) */
  151.     short v_samp_factor;    /* vertical sampling factor (1..4) */
  152.     short quant_tbl_no;    /* quantization table selector (0..3) */
  153.   /* These values may vary between scans */
  154.   /* For compression, they must be supplied by the user interface; */
  155.   /* for decompression, they are read from the SOS marker. */
  156.     short dc_tbl_no;    /* DC entropy table selector (0..3) */
  157.     short ac_tbl_no;    /* AC entropy table selector (0..3) */
  158.   /* These values are computed during compression or decompression startup */
  159.     long true_comp_width;    /* component's image width in samples */
  160.     long true_comp_height;    /* component's image height in samples */
  161.     /* the above are the logical dimensions of the downsampled image */
  162.   /* These values are computed before starting a scan of the component */
  163.     short MCU_width;    /* number of blocks per MCU, horizontally */
  164.     short MCU_height;    /* number of blocks per MCU, vertically */
  165.     short MCU_blocks;    /* MCU_width * MCU_height */
  166.     long downsampled_width;    /* image width in samples, after expansion */
  167.     long downsampled_height; /* image height in samples, after expansion */
  168.     /* the above are the true_comp_xxx values rounded up to multiples of */
  169.     /* the MCU dimensions; these are the working dimensions of the array */
  170.     /* as it is passed through the DCT or IDCT step.  NOTE: these values */
  171.     /* differ depending on whether the component is interleaved or not!! */
  172.   /* This flag is used only for decompression.  In cases where some of the */
  173.   /* components will be ignored (eg grayscale output from YCbCr image), */
  174.   /* we can skip IDCT etc. computations for the unused components. */
  175.     boolean component_needed; /* do we need the value of this component? */
  176. } jpeg_component_info;
  177.  
  178.  
  179. /* DCT coefficient quantization tables.
  180.  * For 8-bit precision, 'INT16' should be good enough for quantization values;
  181.  * for more precision, we go for the full 16 bits.  'INT16' provides a useful
  182.  * speedup on many machines (multiplication & division of JCOEFs by
  183.  * quantization values is a significant chunk of the runtime).
  184.  * Note: the values in a QUANT_TBL are always given in zigzag order.
  185.  */
  186. #ifdef EIGHT_BIT_SAMPLES
  187. typedef INT16 QUANT_VAL;    /* element of a quantization table */
  188. #else
  189. typedef UINT16 QUANT_VAL;    /* element of a quantization table */
  190. #endif
  191. typedef QUANT_VAL QUANT_TBL[DCTSIZE2];    /* A quantization table */
  192. typedef QUANT_VAL * QUANT_TBL_PTR;    /* pointer to same */
  193.  
  194.  
  195. /* Huffman coding tables.
  196.  */
  197.  
  198. #define HUFF_LOOKAHEAD    8    /* # of bits of lookahead */
  199.  
  200. typedef struct {
  201.   /* These two fields directly represent the contents of a JPEG DHT marker */
  202.     UINT8 bits[17];        /* bits[k] = # of symbols with codes of */
  203.                 /* length k bits; bits[0] is unused */
  204.     UINT8 huffval[256];    /* The symbols, in order of incr code length */
  205.   /* This field is used only during compression.  It's initialized FALSE when
  206.    * the table is created, and set TRUE when it's been output to the file.
  207.    */
  208.     boolean sent_table;    /* TRUE when table has been output */
  209.   /* The remaining fields are computed from the above to allow more efficient
  210.    * coding and decoding.  These fields should be considered private to the
  211.    * Huffman compression & decompression modules.  We use a union since only
  212.    * one set of fields is needed at a time.
  213.    */
  214.     union {
  215.       struct {        /* encoding tables: */
  216.         UINT16 ehufco[256];    /* code for each symbol */
  217.         char ehufsi[256];    /* length of code for each symbol */
  218.       } enc;
  219.       struct {        /* decoding tables: */
  220.         /* Basic tables: (element [0] of each array is unused) */
  221.         INT32 mincode[17];    /* smallest code of length k */
  222.         INT32 maxcode[18];    /* largest code of length k (-1 if none) */
  223.         /* (maxcode[17] is a sentinel to ensure huff_DECODE terminates) */
  224.         int valptr[17];    /* huffval[] index of 1st symbol of length k */
  225.         /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of
  226.          * the input data stream.  If the next Huffman code is no more
  227.          * than HUFF_LOOKAHEAD bits long, we can obtain its length and
  228.          * the corresponding symbol directly from these tables.
  229.          */
  230.         int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  231.         UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  232.       } dec;
  233.     } priv;
  234. } HUFF_TBL;
  235.  
  236.  
  237. #define NUM_QUANT_TBLS      4    /* quantization tables are numbered 0..3 */
  238. #define NUM_HUFF_TBLS       4    /* Huffman tables are numbered 0..3 */
  239. #define NUM_ARITH_TBLS      16    /* arith-coding tables are numbered 0..15 */
  240. #define MAX_COMPS_IN_SCAN   4    /* JPEG limit on # of components in one scan */
  241. #define MAX_SAMP_FACTOR     4    /* JPEG limit on sampling factors */
  242. #define MAX_BLOCKS_IN_MCU   10    /* JPEG limit on # of blocks in an MCU */
  243.  
  244.  
  245. /* Working data for compression */
  246.  
  247. struct Compress_info_struct {
  248. /*
  249.  * All of these fields shall be established by the user interface before
  250.  * calling jpeg_compress, or by the input_init or c_ui_method_selection
  251.  * methods.
  252.  * Most parameters can be set to reasonable defaults by j_c_defaults.
  253.  * Note that the UI must supply the storage for the main methods struct,
  254.  * though it sets only a few of the methods there.
  255.  */
  256.     compress_methods_ptr methods; /* Points to list of methods to use */
  257.  
  258.     external_methods_ptr emethods; /* Points to list of methods to use */
  259.  
  260.     IFILEREF input_file;    /* tells input routines where to read image */
  261.     JFILEREF output_file;    /* tells output routines where to write JPEG */
  262.  
  263.     long image_width;    /* input image width */
  264.     long image_height;    /* input image height */
  265.     short input_components;    /* # of color components in input image */
  266.  
  267.     short data_precision;    /* bits of precision in image data */
  268.  
  269.     COLOR_SPACE in_color_space; /* colorspace of input file */
  270.     COLOR_SPACE jpeg_color_space; /* colorspace of JPEG file */
  271.  
  272.     double input_gamma;    /* image gamma of input file */
  273.  
  274.     boolean write_JFIF_header; /* should a JFIF marker be written? */
  275.     /* These three values are not used by the JPEG code, only copied */
  276.     /* into the JFIF APP0 marker.  density_unit can be 0 for unknown, */
  277.     /* 1 for dots/inch, or 2 for dots/cm.  Note that the pixel aspect */
  278.     /* ratio is defined by X_density/Y_density even when density_unit=0. */
  279.     UINT8 density_unit;    /* JFIF code for pixel size units */
  280.     UINT16 X_density;    /* Horizontal pixel density */
  281.     UINT16 Y_density;    /* Vertical pixel density */
  282.  
  283.     char * comment_text;    /* Text for COM block, or NULL for no COM */
  284.     /* note: JPEG library will not free() the comment string, */
  285.     /* unless you allocate it via alloc_small(). */
  286.  
  287.     short num_components;    /* # of color components in JPEG image */
  288.     jpeg_component_info * comp_info;
  289.     /* comp_info[i] describes component that appears i'th in SOF */
  290.  
  291.     QUANT_TBL_PTR quant_tbl_ptrs[NUM_QUANT_TBLS];
  292.     /* ptrs to coefficient quantization tables, or NULL if not defined */
  293.  
  294.     HUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  295.     HUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  296.     /* ptrs to Huffman coding tables, or NULL if not defined */
  297.  
  298.     UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arithmetic-coding tables */
  299.     UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arithmetic-coding tables */
  300.     UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arithmetic-coding tables */
  301.  
  302.     boolean arith_code;    /* TRUE=arithmetic coding, FALSE=Huffman */
  303.     boolean interleave;    /* TRUE=interleaved output, FALSE=not */
  304.     boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  305.     boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  306.     int smoothing_factor;    /* 1..100, or 0 for no input smoothing */
  307.  
  308.     /* The restart interval can be specified in absolute MCUs by setting
  309.      * restart_interval, or in MCU rows by setting restart_in_rows
  310.      * (in which case the correct restart_interval will be figured
  311.      * for each scan).
  312.      */
  313.     UINT16 restart_interval;/* MCUs per restart interval, or 0 for no restart */
  314.     int restart_in_rows;    /* if > 0, MCU rows per restart interval */
  315.  
  316. /*
  317.  * These fields are computed during jpeg_compress startup
  318.  */
  319.     short max_h_samp_factor; /* largest h_samp_factor */
  320.     short max_v_samp_factor; /* largest v_samp_factor */
  321.  
  322. /*
  323.  * These fields may be useful for progress monitoring
  324.  */
  325.  
  326.     int total_passes;    /* number of passes expected */
  327.     int completed_passes;    /* number of passes completed so far */
  328.  
  329. /*
  330.  * These fields are valid during any one scan
  331.  */
  332.     short comps_in_scan;    /* # of JPEG components output this time */
  333.     jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  334.     /* *cur_comp_info[i] describes component that appears i'th in SOS */
  335.  
  336.     long MCUs_per_row;    /* # of MCUs across the image */
  337.     long MCU_rows_in_scan;    /* # of MCU rows in the image */
  338.  
  339.     short blocks_in_MCU;    /* # of DCT blocks per MCU */
  340.     short MCU_membership[MAX_BLOCKS_IN_MCU];
  341.     /* MCU_membership[i] is index in cur_comp_info of component owning */
  342.     /* i'th block in an MCU */
  343.  
  344.     /* these fields are private data for the entropy encoder */
  345.     JCOEF last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each comp */
  346.     JCOEF last_dc_diff[MAX_COMPS_IN_SCAN]; /* last DC diff for each comp */
  347.     UINT16 restarts_to_go;    /* MCUs left in this restart interval */
  348.     short next_restart_num;    /* # of next RSTn marker (0..7) */
  349. };
  350.  
  351. typedef struct Compress_info_struct * compress_info_ptr;
  352.  
  353.  
  354. /* Working data for decompression */
  355.  
  356. struct Decompress_info_struct {
  357. /*
  358.  * These fields shall be established by the user interface before
  359.  * calling jpeg_decompress.
  360.  * Most parameters can be set to reasonable defaults by j_d_defaults.
  361.  * Note that the UI must supply the storage for the main methods struct,
  362.  * though it sets only a few of the methods there.
  363.  */
  364.     decompress_methods_ptr methods; /* Points to list of methods to use */
  365.  
  366.     external_methods_ptr emethods; /* Points to list of methods to use */
  367.  
  368.     JFILEREF input_file;    /* tells input routines where to read JPEG */
  369.     IFILEREF output_file;    /* tells output routines where to write image */
  370.  
  371.     /* these can be set at d_ui_method_selection time: */
  372.  
  373.     COLOR_SPACE out_color_space; /* colorspace of output */
  374.  
  375.     double output_gamma;    /* image gamma wanted in output */
  376.  
  377. boolean color_map_present;        /* T if a color map format is being read - added by Eric P */
  378.  
  379.     boolean quantize_colors; /* T if output is a colormapped format */
  380.     /* the following are ignored if not quantize_colors: */
  381.     boolean two_pass_quantize;    /* use two-pass color quantization? */
  382.     boolean use_dithering;        /* want color dithering? */
  383.     int desired_number_of_colors;    /* max number of colors to use */
  384.  
  385.     boolean do_block_smoothing; /* T = apply cross-block smoothing */
  386.     boolean do_pixel_smoothing; /* T = apply post-upsampling smoothing */
  387.  
  388. /*
  389.  * These fields are used for efficient buffering of data between read_jpeg_data
  390.  * and the entropy decoding object.  By using a shared buffer, we avoid copying
  391.  * data and eliminate the need for an "unget" operation at the end of a scan.
  392.  * The actual source of the data is known only to read_jpeg_data; see the
  393.  * JGETC macro, below.
  394.  * Note: the user interface is expected to allocate the input_buffer and
  395.  * initialize bytes_in_buffer to 0.  Also, for JFIF/raw-JPEG input, the UI
  396.  * actually supplies the read_jpeg_data method.  This is all handled by
  397.  * j_d_defaults in a typical implementation.
  398.  */
  399.     char * input_buffer;    /* start of buffer (private to input code) */
  400.     char * next_input_byte;    /* => next byte to read from buffer */
  401.     int bytes_in_buffer;    /* # of bytes remaining in buffer */
  402.  
  403. /*
  404.  * These fields are set by read_file_header or read_scan_header
  405.  */
  406.     long image_width;    /* overall image width */
  407.     long image_height;    /* overall image height */
  408.  
  409.     short data_precision;    /* bits of precision in image data */
  410.  
  411.     COLOR_SPACE jpeg_color_space; /* colorspace of JPEG file */
  412.  
  413.         /* These three values are not used by the JPEG code, merely copied */
  414.     /* from the JFIF APP0 marker (if any). */
  415.     UINT8 density_unit;    /* JFIF code for pixel size units */
  416.     UINT16 X_density;    /* Horizontal pixel density */
  417.     UINT16 Y_density;    /* Vertical pixel density */
  418.  
  419.     short num_components;    /* # of color components in JPEG image */
  420.     jpeg_component_info * comp_info;
  421.     /* comp_info[i] describes component that appears i'th in SOF */
  422.  
  423.     QUANT_TBL_PTR quant_tbl_ptrs[NUM_QUANT_TBLS];
  424.     /* ptrs to coefficient quantization tables, or NULL if not defined */
  425.  
  426.     HUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  427.     HUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  428.     /* ptrs to Huffman coding tables, or NULL if not defined */
  429.  
  430.     UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  431.     UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  432.     UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  433.  
  434.     boolean arith_code;    /* TRUE=arithmetic coding, FALSE=Huffman */
  435.     boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  436.  
  437.     UINT16 restart_interval;/* MCUs per restart interval, or 0 for no restart */
  438.  
  439. /*
  440.  * These fields are computed during jpeg_decompress startup
  441.  */
  442.     short max_h_samp_factor; /* largest h_samp_factor */
  443.     short max_v_samp_factor; /* largest v_samp_factor */
  444.  
  445.     short color_out_comps;    /* # of color components output by color_convert */
  446.                 /* (need not match num_components) */
  447.     short final_out_comps;    /* # of color components sent to put_pixel_rows */
  448.     /* (1 when quantizing colors, else same as color_out_comps) */
  449.  
  450.     JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  451.  
  452. /*
  453.  * When quantizing colors, the color quantizer leaves a pointer to the output
  454.  * colormap in these fields.  The colormap is valid from the time put_color_map
  455.  * is called (must be before any put_pixel_rows calls) until shutdown (more
  456.  * specifically, until free_all is called to release memory).
  457.  */
  458.     int actual_number_of_colors; /* actual number of entries */
  459.     JSAMPARRAY colormap;    /* NULL if not valid */
  460.     /* map has color_out_comps rows * actual_number_of_colors columns */
  461.  
  462. /*
  463.  * These fields may be useful for progress monitoring
  464.  */
  465.  
  466.     int total_passes;    /* number of passes expected */
  467.     int completed_passes;    /* number of passes completed so far */
  468.  
  469. /*
  470.  * These fields are valid during any one scan
  471.  */
  472.     short comps_in_scan;    /* # of JPEG components input this time */
  473.     jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  474.     /* *cur_comp_info[i] describes component that appears i'th in SOS */
  475.  
  476.     long MCUs_per_row;    /* # of MCUs across the image */
  477.     long MCU_rows_in_scan;    /* # of MCU rows in the image */
  478.  
  479.     short blocks_in_MCU;    /* # of DCT blocks per MCU */
  480.     short MCU_membership[MAX_BLOCKS_IN_MCU];
  481.     /* MCU_membership[i] is index in cur_comp_info of component owning */
  482.     /* i'th block in an MCU */
  483.  
  484.     /* these fields are private data for the entropy encoder */
  485.     JCOEF last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each comp */
  486.     JCOEF last_dc_diff[MAX_COMPS_IN_SCAN]; /* last DC diff for each comp */
  487.     UINT16 restarts_to_go;    /* MCUs left in this restart interval */
  488.     short next_restart_num;    /* # of next RSTn marker (0..7) */
  489. };
  490.  
  491. typedef struct Decompress_info_struct * decompress_info_ptr;
  492.  
  493.  
  494. /* Macros for reading data from the decompression input buffer */
  495.  
  496. #ifdef CHAR_IS_UNSIGNED
  497. #define JGETC(cinfo)    ( --(cinfo)->bytes_in_buffer < 0 ? \
  498.              (*(cinfo)->methods->read_jpeg_data) (cinfo) : \
  499.              (int) (*(cinfo)->next_input_byte++) )
  500. #else
  501. #define JGETC(cinfo)    ( --(cinfo)->bytes_in_buffer < 0 ? \
  502.              (*(cinfo)->methods->read_jpeg_data) (cinfo) : \
  503.              (int) (*(cinfo)->next_input_byte++) & 0xFF )
  504. #endif
  505.  
  506. #define JUNGETC(ch,cinfo)  ((cinfo)->bytes_in_buffer++, \
  507.                 *(--((cinfo)->next_input_byte)) = (char) (ch))
  508.  
  509. #define MIN_UNGET    4    /* may always do at least 4 JUNGETCs */
  510.  
  511.  
  512. /* A virtual image has a control block whose contents are private to the
  513.  * memory manager module (and may differ between managers).  The rest of the
  514.  * code only refers to virtual images by these pointer types, and never
  515.  * dereferences the pointer.
  516.  */
  517.  
  518. typedef struct big_sarray_control * big_sarray_ptr;
  519. typedef struct big_barray_control * big_barray_ptr;
  520.  
  521. /* Although a real ANSI C compiler can deal perfectly well with pointers to
  522.  * unspecified structures (see "incomplete types" in the spec), a few pre-ANSI
  523.  * and pseudo-ANSI compilers get confused.  To keep one of these bozos happy,
  524.  * add -DINCOMPLETE_TYPES_BROKEN to CFLAGS in your Makefile.  Then we will
  525.  * pseudo-define the structs as containing a single "dummy" field.
  526.  * The memory managers #define AM_MEMORY_MANAGER before including this file,
  527.  * so that they can make their own definitions of the structs.
  528.  */
  529.  
  530. #ifdef INCOMPLETE_TYPES_BROKEN
  531. #ifndef AM_MEMORY_MANAGER
  532. struct big_sarray_control { long dummy; };
  533. struct big_barray_control { long dummy; };
  534. #endif
  535. #endif
  536.  
  537.  
  538. /* Method types that need typedefs */
  539.  
  540. typedef METHOD(void, MCU_output_method_ptr, (compress_info_ptr cinfo,
  541.                          JBLOCK *MCU_data));
  542. typedef METHOD(void, MCU_output_caller_ptr, (compress_info_ptr cinfo,
  543.                          MCU_output_method_ptr output_method));
  544. typedef METHOD(void, downsample_ptr, (compress_info_ptr cinfo,
  545.                       int which_component,
  546.                       long input_cols, int input_rows,
  547.                       long output_cols, int output_rows,
  548.                       JSAMPARRAY above,
  549.                       JSAMPARRAY input_data,
  550.                       JSAMPARRAY below,
  551.                       JSAMPARRAY output_data));
  552. typedef METHOD(void, upsample_ptr, (decompress_info_ptr cinfo,
  553.                     int which_component,
  554.                     long input_cols, int input_rows,
  555.                     long output_cols, int output_rows,
  556.                     JSAMPARRAY above,
  557.                     JSAMPARRAY input_data,
  558.                     JSAMPARRAY below,
  559.                     JSAMPARRAY output_data));
  560. typedef METHOD(void, quantize_method_ptr, (decompress_info_ptr cinfo,
  561.                        int num_rows,
  562.                        JSAMPIMAGE input_data,
  563.                        JSAMPARRAY output_workspace));
  564. typedef METHOD(void, quantize_caller_ptr, (decompress_info_ptr cinfo,
  565.                        quantize_method_ptr quantize_method));
  566.  
  567.  
  568. /* These structs contain function pointers for the various JPEG methods. */
  569.  
  570. /* Routines to be provided by the surrounding application, rather than the
  571.  * portable JPEG code proper.  These are the same for compression and
  572.  * decompression.
  573.  */
  574.  
  575. struct External_methods_struct {
  576.     /* User interface: error exit and trace message routines */
  577.     /* NOTE: the string msgtext parameters will eventually be replaced
  578.      * by an enumerated-type code so that non-English error messages
  579.      * can be substituted easily.  This will not be done until all the
  580.      * code is in place, so that we know what messages are needed.
  581.      */
  582.     METHOD(void, error_exit, (const char *msgtext));
  583.     METHOD(void, trace_message, (const char *msgtext));
  584.  
  585.     /* Working data for error/trace facility */
  586.     /* See macros below for the usage of these variables */
  587.     int trace_level;    /* level of detail of tracing messages */
  588.     /* Use level 0 for important warning messages (nonfatal errors) */
  589.     /* Use levels 1, 2, 3 for successively more detailed trace options */
  590.  
  591.     /* For recoverable corrupt-data errors, we emit a warning message and
  592.      * keep going.  A surrounding application can check for bad data by
  593.      * seeing if num_warnings is nonzero at the end of processing.
  594.      */
  595.     long num_warnings;    /* number of corrupt-data warnings */
  596.     int first_warning_level; /* trace level for first warning */
  597.     int more_warning_level;    /* trace level for subsequent warnings */
  598.  
  599.     int message_parm[8];    /* store numeric parms for messages here */
  600.  
  601.     /* Memory management */
  602.     /* NB: alloc routines never return NULL. They exit to */
  603.     /* error_exit if not successful. */
  604.     METHOD(void *, alloc_small, (size_t sizeofobject));
  605.     METHOD(void, free_small, (void *ptr));
  606.     METHOD(void FAR *, alloc_medium, (size_t sizeofobject));
  607.     METHOD(void, free_medium, (void FAR *ptr));
  608.     METHOD(JSAMPARRAY, alloc_small_sarray, (long samplesperrow,
  609.                         long numrows));
  610.     METHOD(void, free_small_sarray, (JSAMPARRAY ptr));
  611.     METHOD(JBLOCKARRAY, alloc_small_barray, (long blocksperrow,
  612.                          long numrows));
  613.     METHOD(void, free_small_barray, (JBLOCKARRAY ptr));
  614.     METHOD(big_sarray_ptr, request_big_sarray, (long samplesperrow,
  615.                             long numrows,
  616.                             long unitheight));
  617.     METHOD(big_barray_ptr, request_big_barray, (long blocksperrow,
  618.                             long numrows,
  619.                             long unitheight));
  620.     METHOD(void, alloc_big_arrays, (long extra_small_samples,
  621.                     long extra_small_blocks,
  622.                     long extra_medium_space));
  623.     METHOD(JSAMPARRAY, access_big_sarray, (big_sarray_ptr ptr,
  624.                            long start_row,
  625.                            boolean writable));
  626.     METHOD(JBLOCKARRAY, access_big_barray, (big_barray_ptr ptr,
  627.                         long start_row,
  628.                         boolean writable));
  629.     METHOD(void, free_big_sarray, (big_sarray_ptr ptr));
  630.     METHOD(void, free_big_barray, (big_barray_ptr ptr));
  631.     METHOD(void, free_all, (void));
  632.  
  633.     long max_memory_to_use;    /* maximum amount of memory to use */
  634. };
  635.  
  636. /* Macros to simplify using the error and trace message stuff */
  637. /* The first parameter is generally cinfo->emethods */
  638.  
  639. /* Fatal errors (print message and exit) */
  640. #define ERREXIT(emeth,msg)        ((*(emeth)->error_exit) (msg))
  641. #define ERREXIT1(emeth,msg,p1)        ((emeth)->message_parm[0] = (p1), \
  642.                      (*(emeth)->error_exit) (msg))
  643. #define ERREXIT2(emeth,msg,p1,p2)    ((emeth)->message_parm[0] = (p1), \
  644.                      (emeth)->message_parm[1] = (p2), \
  645.                      (*(emeth)->error_exit) (msg))
  646. #define ERREXIT3(emeth,msg,p1,p2,p3)    ((emeth)->message_parm[0] = (p1), \
  647.                      (emeth)->message_parm[1] = (p2), \
  648.                      (emeth)->message_parm[2] = (p3), \
  649.                      (*(emeth)->error_exit) (msg))
  650. #define ERREXIT4(emeth,msg,p1,p2,p3,p4) ((emeth)->message_parm[0] = (p1), \
  651.                      (emeth)->message_parm[1] = (p2), \
  652.                      (emeth)->message_parm[2] = (p3), \
  653.                      (emeth)->message_parm[3] = (p4), \
  654.                      (*(emeth)->error_exit) (msg))
  655.  
  656. #define MAKESTMT(stuff)        do { stuff } while (0)
  657.  
  658. /* Nonfatal errors (we'll keep going, but the data is probably corrupt) */
  659. /* Note that warning count is incremented as a side-effect! */
  660. #define WARNMS(emeth,msg)    \
  661.   MAKESTMT( if ((emeth)->trace_level >= ((emeth)->num_warnings++ ? \
  662.         (emeth)->more_warning_level : (emeth)->first_warning_level)){ \
  663.         (*(emeth)->trace_message) (msg); } )
  664. #define WARNMS1(emeth,msg,p1)    \
  665.   MAKESTMT( if ((emeth)->trace_level >= ((emeth)->num_warnings++ ? \
  666.         (emeth)->more_warning_level : (emeth)->first_warning_level)){ \
  667.         (emeth)->message_parm[0] = (p1); \
  668.         (*(emeth)->trace_message) (msg); } )
  669. #define WARNMS2(emeth,msg,p1,p2)    \
  670.   MAKESTMT( if ((emeth)->trace_level >= ((emeth)->num_warnings++ ? \
  671.         (emeth)->more_warning_level : (emeth)->first_warning_level)){ \
  672.         (emeth)->message_parm[0] = (p1); \
  673.         (emeth)->message_parm[1] = (p2); \
  674.         (*(emeth)->trace_message) (msg); } )
  675.  
  676. /* Informational/debugging messages */
  677. #define TRACEMS(emeth,lvl,msg)    \
  678.   MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  679.         (*(emeth)->trace_message) (msg); } )
  680. #define TRACEMS1(emeth,lvl,msg,p1)    \
  681.   MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  682.         (emeth)->message_parm[0] = (p1); \
  683.         (*(emeth)->trace_message) (msg); } )
  684. #define TRACEMS2(emeth,lvl,msg,p1,p2)    \
  685.   MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  686.         (emeth)->message_parm[0] = (p1); \
  687.         (emeth)->message_parm[1] = (p2); \
  688.         (*(emeth)->trace_message) (msg); } )
  689. #define TRACEMS3(emeth,lvl,msg,p1,p2,p3)    \
  690.   MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  691.         int * _mp = (emeth)->message_parm; \
  692.         *_mp++ = (p1); *_mp++ = (p2); *_mp = (p3); \
  693.         (*(emeth)->trace_message) (msg); } )
  694. #define TRACEMS4(emeth,lvl,msg,p1,p2,p3,p4)    \
  695.   MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  696.         int * _mp = (emeth)->message_parm; \
  697.         *_mp++ = (p1); *_mp++ = (p2); *_mp++ = (p3); *_mp = (p4); \
  698.         (*(emeth)->trace_message) (msg); } )
  699. #define TRACEMS8(emeth,lvl,msg,p1,p2,p3,p4,p5,p6,p7,p8)    \
  700.   MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  701.         int * _mp = (emeth)->message_parm; \
  702.         *_mp++ = (p1); *_mp++ = (p2); *_mp++ = (p3); *_mp++ = (p4); \
  703.         *_mp++ = (p5); *_mp++ = (p6); *_mp++ = (p7); *_mp = (p8); \
  704.         (*(emeth)->trace_message) (msg); } )
  705.  
  706.  
  707. /* Methods used during JPEG compression. */
  708.  
  709. struct Compress_methods_struct {
  710.     /* Hook for user interface to get control after input_init */
  711.     METHOD(void, c_ui_method_selection, (compress_info_ptr cinfo));
  712.     /* Hook for user interface to do progress monitoring */
  713.     METHOD(void, progress_monitor, (compress_info_ptr cinfo,
  714.                     long loopcounter, long looplimit));
  715.     /* Input image reading & conversion to standard form */
  716.     METHOD(void, input_init, (compress_info_ptr cinfo));
  717.     METHOD(void, get_input_row, (compress_info_ptr cinfo,
  718.                      JSAMPARRAY pixel_row));
  719.     METHOD(void, input_term, (compress_info_ptr cinfo));
  720.     /* Color space and gamma conversion */
  721.     METHOD(void, colorin_init, (compress_info_ptr cinfo));
  722.     METHOD(void, get_sample_rows, (compress_info_ptr cinfo,
  723.                        int rows_to_read,
  724.                        JSAMPIMAGE image_data));
  725.     METHOD(void, colorin_term, (compress_info_ptr cinfo));
  726.     /* Expand picture data at edges */
  727.     METHOD(void, edge_expand, (compress_info_ptr cinfo,
  728.                    long input_cols, int input_rows,
  729.                    long output_cols, int output_rows,
  730.                    JSAMPIMAGE image_data));
  731.     /* Downsample pixel values of a single component */
  732.     /* There can be a different downsample method for each component */
  733.     METHOD(void, downsample_init, (compress_info_ptr cinfo));
  734.     downsample_ptr downsample[MAX_COMPS_IN_SCAN];
  735.     METHOD(void, downsample_term, (compress_info_ptr cinfo));
  736.     /* Extract samples in MCU order, process & hand off to output_method */
  737.     /* The input is always exactly N MCU rows worth of data */
  738.     METHOD(void, extract_init, (compress_info_ptr cinfo));
  739.     METHOD(void, extract_MCUs, (compress_info_ptr cinfo,
  740.                      JSAMPIMAGE image_data,
  741.                     int num_mcu_rows,
  742.                     MCU_output_method_ptr output_method));
  743.     METHOD(void, extract_term, (compress_info_ptr cinfo));
  744.     /* Entropy encoding parameter optimization */
  745.     METHOD(void, entropy_optimize, (compress_info_ptr cinfo,
  746.                     MCU_output_caller_ptr source_method));
  747.     /* Entropy encoding */
  748.     METHOD(void, entropy_encode_init, (compress_info_ptr cinfo));
  749.     METHOD(void, entropy_encode, (compress_info_ptr cinfo,
  750.                       JBLOCK *MCU_data));
  751.     METHOD(void, entropy_encode_term, (compress_info_ptr cinfo));
  752.     /* JPEG file header construction */
  753.     METHOD(void, write_file_header, (compress_info_ptr cinfo));
  754.     METHOD(void, write_scan_header, (compress_info_ptr cinfo));
  755.     METHOD(void, write_jpeg_data, (compress_info_ptr cinfo,
  756.                        char *dataptr,
  757.                        int datacount));
  758.     METHOD(void, write_scan_trailer, (compress_info_ptr cinfo));
  759.     METHOD(void, write_file_trailer, (compress_info_ptr cinfo));
  760.     /* Pipeline control */
  761.     METHOD(void, c_pipeline_controller, (compress_info_ptr cinfo));
  762.     METHOD(void, entropy_output, (compress_info_ptr cinfo,
  763.                       char *dataptr,
  764.                       int datacount));
  765.     /* Overall control */
  766.     METHOD(void, c_per_scan_method_selection, (compress_info_ptr cinfo));
  767. };
  768.  
  769. /* Methods used during JPEG decompression. */
  770.  
  771. struct Decompress_methods_struct {
  772.     /* Hook for user interface to get control after reading file header */
  773.     METHOD(void, d_ui_method_selection, (decompress_info_ptr cinfo));
  774.     /* Hook for user interface to process comment blocks */
  775.     METHOD(void, process_comment, (decompress_info_ptr cinfo,
  776.                        long comment_length));
  777.     /* Hook for user interface to do progress monitoring */
  778.     METHOD(void, progress_monitor, (decompress_info_ptr cinfo,
  779.                     long loopcounter, long looplimit));
  780.     /* JPEG file scanning */
  781.     METHOD(void, read_file_header, (decompress_info_ptr cinfo));
  782.     METHOD(boolean, read_scan_header, (decompress_info_ptr cinfo));
  783.     METHOD(int, read_jpeg_data, (decompress_info_ptr cinfo));
  784. METHOD(void, get_input_row, (decompress_info_ptr cinfo,
  785.                   JSAMPIMAGE pixel_row));
  786.     METHOD(void, resync_to_restart, (decompress_info_ptr cinfo,
  787.                      int marker));
  788.     METHOD(void, read_scan_trailer, (decompress_info_ptr cinfo));
  789.     METHOD(void, read_file_trailer, (decompress_info_ptr cinfo));
  790.     /* Entropy decoding */
  791.     METHOD(void, entropy_decode_init, (decompress_info_ptr cinfo));
  792.     METHOD(void, entropy_decode, (decompress_info_ptr cinfo,
  793.                       JBLOCKROW *MCU_data));
  794.     METHOD(void, entropy_decode_term, (decompress_info_ptr cinfo));
  795.     /* MCU disassembly: fetch MCUs from entropy_decode, build coef array */
  796.     /* The reverse_DCT step is in the same module for symmetry reasons */
  797.     METHOD(void, disassemble_init, (decompress_info_ptr cinfo));
  798.     METHOD(void, disassemble_MCU, (decompress_info_ptr cinfo,
  799.                        JBLOCKIMAGE image_data));
  800.     METHOD(void, reverse_DCT, (decompress_info_ptr cinfo,
  801.                    JBLOCKIMAGE coeff_data,
  802.                    JSAMPIMAGE output_data, int start_row));
  803.     METHOD(void, disassemble_term, (decompress_info_ptr cinfo));
  804.     /* Cross-block smoothing */
  805.     METHOD(void, smooth_coefficients, (decompress_info_ptr cinfo,
  806.                        jpeg_component_info *compptr,
  807.                        JBLOCKROW above,
  808.                         JBLOCKROW currow,
  809.                        JBLOCKROW below,
  810.                        JBLOCKROW output));
  811.     /* Upsample pixel values of a single component */
  812.     /* There can be a different upsample method for each component */
  813.     METHOD(void, upsample_init, (decompress_info_ptr cinfo));
  814.     upsample_ptr upsample[MAX_COMPS_IN_SCAN];
  815.     METHOD(void, upsample_term, (decompress_info_ptr cinfo));
  816.     /* Color space and gamma conversion */
  817.     METHOD(void, colorout_init, (decompress_info_ptr cinfo));
  818.     METHOD(void, color_convert, (decompress_info_ptr cinfo,
  819.                      int num_rows, long num_cols,
  820.                      JSAMPIMAGE input_data,
  821.                      JSAMPIMAGE output_data));
  822.     METHOD(void, colorout_term, (decompress_info_ptr cinfo));
  823.     /* Color quantization */
  824.     METHOD(void, color_quant_init, (decompress_info_ptr cinfo));
  825.     METHOD(void, color_quantize, (decompress_info_ptr cinfo,
  826.                       int num_rows,
  827.                       JSAMPIMAGE input_data,
  828.                       JSAMPARRAY output_data));
  829.     METHOD(void, color_quant_prescan, (decompress_info_ptr cinfo,
  830.                        int num_rows,
  831.                        JSAMPIMAGE image_data,
  832.                        JSAMPARRAY workspace));
  833.     METHOD(void, color_quant_doit, (decompress_info_ptr cinfo,
  834.                     quantize_caller_ptr source_method));
  835.     METHOD(void, color_quant_term, (decompress_info_ptr cinfo));
  836.     /* Output image writing */
  837.     METHOD(void, output_init, (decompress_info_ptr cinfo));
  838.     METHOD(void, put_color_map, (decompress_info_ptr cinfo,
  839.                      int num_colors, JSAMPARRAY colormap));
  840.     METHOD(void, put_pixel_rows, (decompress_info_ptr cinfo,
  841.                       int num_rows,
  842.                       JSAMPIMAGE pixel_data));
  843.     METHOD(void, output_term, (decompress_info_ptr cinfo));
  844.     /* Pipeline control */
  845.     METHOD(void, d_pipeline_controller, (decompress_info_ptr cinfo));
  846.     /* Overall control */
  847.     METHOD(void, d_per_scan_method_selection, (decompress_info_ptr cinfo));
  848. };
  849.  
  850.  
  851. /* External declarations for routines that aren't called via method ptrs. */
  852. /* Note: use "j" as first char of names to minimize namespace pollution. */
  853. /* The PP macro hides prototype parameters from compilers that can't cope. */
  854.  
  855. #ifdef PROTO
  856. #define PP(arglist)    arglist
  857. #else
  858. #define PP(arglist)    ()
  859. #endif
  860.  
  861.  
  862. /* main entry for compression */
  863. EXTERN void jpeg_compress PP((compress_info_ptr cinfo));
  864.  
  865. /* default parameter setup for compression */
  866. EXTERN void j_c_defaults PP((compress_info_ptr cinfo, int quality,
  867.                  boolean force_baseline));
  868. EXTERN void j_monochrome_default PP((compress_info_ptr cinfo));
  869. EXTERN void j_set_quality PP((compress_info_ptr cinfo, int quality,
  870.                   boolean force_baseline));
  871. /* advanced compression parameter setup aids */
  872. EXTERN void j_add_quant_table PP((compress_info_ptr cinfo, int which_tbl,
  873.                   const QUANT_VAL *basic_table,
  874.                   int scale_factor, boolean force_baseline));
  875. EXTERN int j_quality_scaling PP((int quality));
  876.  
  877. /* main entry for decompression */
  878. EXTERN void jpeg_decompress PP((decompress_info_ptr cinfo));
  879.  
  880. /* default parameter setup for decompression */
  881. EXTERN void j_d_defaults PP((decompress_info_ptr cinfo,
  882.                  boolean standard_buffering));
  883.  
  884. /* forward DCT */
  885. EXTERN void j_fwd_dct PP((DCTBLOCK data));
  886. /* inverse DCT */
  887. EXTERN void near j_rev_dct PP((DCTBLOCK data));
  888.  
  889. /* utility routines in jutils.c */
  890. EXTERN long jround_up PP((long a, long b));
  891. EXTERN void jcopy_sample_rows PP((JSAMPARRAY input_array, int source_row,
  892.                   JSAMPARRAY output_array, int dest_row,
  893.                   int num_rows, long num_cols));
  894. EXTERN void jcopy_block_row PP((JBLOCKROW input_row, JBLOCKROW output_row,
  895.                 long num_blocks));
  896. EXTERN void jzero_far PP((void FAR * target, size_t bytestozero));
  897.  
  898. /* method selection routines for compression modules */
  899. EXTERN void jselcpipeline PP((compress_info_ptr cinfo)); /* jcpipe.c */
  900. EXTERN void jselchuffman PP((compress_info_ptr cinfo)); /* jchuff.c */
  901. EXTERN void jselcarithmetic PP((compress_info_ptr cinfo)); /* jcarith.c */
  902. EXTERN void jselexpand PP((compress_info_ptr cinfo)); /* jcexpand.c */
  903. EXTERN void jseldownsample PP((compress_info_ptr cinfo)); /* jcsample.c */
  904. EXTERN void jselcmcu PP((compress_info_ptr cinfo)); /* jcmcu.c */
  905. EXTERN void jselccolor PP((compress_info_ptr cinfo));    /* jccolor.c */
  906. /* The user interface should call one of these to select input format: */
  907. EXTERN void jselrgif PP((compress_info_ptr cinfo)); /* jrdgif.c */
  908. EXTERN void jselrppm PP((compress_info_ptr cinfo)); /* jrdppm.c */
  909. EXTERN void jselrrle PP((compress_info_ptr cinfo)); /* jrdrle.c */
  910. EXTERN void jselrtarga PP((compress_info_ptr cinfo)); /* jrdtarga.c */
  911. /* and one of these to select output header format: */
  912. EXTERN void jselwjfif PP((compress_info_ptr cinfo)); /* jwrjfif.c */
  913.  
  914. /* method selection routines for decompression modules */
  915. EXTERN void jseldpipeline PP((decompress_info_ptr cinfo)); /* jdpipe.c */
  916. EXTERN void jseldhuffman PP((decompress_info_ptr cinfo)); /* jdhuff.c */
  917. EXTERN void jseldarithmetic PP((decompress_info_ptr cinfo)); /* jdarith.c */
  918. EXTERN void jseldmcu PP((decompress_info_ptr cinfo)); /* jdmcu.c */
  919. EXTERN void jselbsmooth PP((decompress_info_ptr cinfo)); /* jbsmooth.c */
  920. EXTERN void jselupsample PP((decompress_info_ptr cinfo)); /* jdsample.c */
  921. EXTERN void jseldcolor PP((decompress_info_ptr cinfo));    /* jdcolor.c */
  922. EXTERN void jsel1quantize PP((decompress_info_ptr cinfo)); /* jquant1.c */
  923. EXTERN void jsel2quantize PP((decompress_info_ptr cinfo)); /* jquant2.c */
  924. /* The user interface should call one of these to select input format: */
  925. EXTERN void jselrjfif PP((decompress_info_ptr cinfo)); /* jrdjfif.c */
  926. /* and one of these to select output image format: */
  927. EXTERN void jselwgif PP((decompress_info_ptr cinfo)); /* jwrgif.c */
  928. EXTERN void jselwppm PP((decompress_info_ptr cinfo)); /* jwrppm.c */
  929. EXTERN void jselwrle PP((decompress_info_ptr cinfo)); /* jwrrle.c */
  930. EXTERN void jselwtarga PP((decompress_info_ptr cinfo)); /* jwrtarga.c */
  931.  
  932. /* method selection routines for system-dependent modules */
  933. EXTERN void jselerror PP((external_methods_ptr emethods)); /* jerror.c */
  934. EXTERN void jselmemmgr PP((external_methods_ptr emethods)); /* jmemmgr.c */
  935.  
  936.  
  937. /* We assume that right shift corresponds to signed division by 2 with
  938.  * rounding towards minus infinity.  This is correct for typical "arithmetic
  939.  * shift" instructions that shift in copies of the sign bit.  But some
  940.  * C compilers implement >> with an unsigned shift.  For these machines you
  941.  * must define RIGHT_SHIFT_IS_UNSIGNED.
  942.  * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
  943.  * It is only applied with constant shift counts.  SHIFT_TEMPS must be
  944.  * included in the variables of any routine using RIGHT_SHIFT.
  945.  */
  946.  
  947. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  948. #define SHIFT_TEMPS    INT32 shift_temp;
  949. #define RIGHT_SHIFT(x,shft)  \
  950.     ((shift_temp = (x)) < 0 ? \
  951.      (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  952.      (shift_temp >> (shft)))
  953. #else
  954. #define SHIFT_TEMPS
  955. #define RIGHT_SHIFT(x,shft)    ((x) >> (shft))
  956. #endif
  957.  
  958.  
  959. /* Miscellaneous useful macros */
  960.  
  961. #undef MAX
  962. #define MAX(a,b)    ((a) > (b) ? (a) : (b))
  963. #undef MIN
  964. #define MIN(a,b)    ((a) < (b) ? (a) : (b))
  965.  
  966.  
  967. #define RST0    0xD0        /* RST0 marker code */
  968.