home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / jlib / jpegint.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  14.2 KB  |  354 lines

  1. //-------------------------------------------------------------------------//
  2. //          Windows Graphics Programming: Win32 GDI and DirectDraw         //
  3. //                        ISBN  0-13-086985-6                              //
  4. //                                                                         //
  5. //  Modified by: Yuan, Feng                             www.fengyuan.com   //
  6. //  Changes    : C++, exception, in-memory source, BGR byte order          //
  7. //  Version    : 1.00.000, May 31, 2000                                    //
  8. //-------------------------------------------------------------------------//
  9.  
  10. /*
  11.  * jpegint.h
  12.  *
  13.  * Copyright (C) 1991-1997, Thomas G. Lane.
  14.  * This file is part of the Independent JPEG Group's software.
  15.  * For conditions of distribution and use, see the accompanying README file.
  16.  *
  17.  * This file provides common declarations for the various JPEG modules.
  18.  * These declarations are considered internal to the JPEG library; most
  19.  * applications using the library shouldn't need to include this file.
  20.  */
  21.  
  22.  
  23. /* Declarations for both compression & decompression */
  24.  
  25. typedef enum {            /* Operating modes for buffer controllers */
  26.     JBUF_PASS_THRU,        /* Plain stripwise operation */
  27.     /* Remaining modes require a full-image buffer to have been created */
  28.     JBUF_SAVE_SOURCE,    /* Run source subobject only, save output */
  29.     JBUF_CRANK_DEST,    /* Run dest subobject only, using saved data */
  30.     JBUF_SAVE_AND_PASS    /* Run both subobjects, save output */
  31. } J_BUF_MODE;
  32.  
  33. /* Values of global_state field (jdapi.c has some dependencies on ordering!) */
  34. #define CSTATE_START    100    /* after create_compress */
  35. #define CSTATE_SCANNING    101    /* start_compress done, write_scanlines OK */
  36. #define CSTATE_RAW_OK    102    /* start_compress done, write_raw_data OK */
  37. #define CSTATE_WRCOEFS    103    /* jpeg_write_coefficients done */
  38. #define DSTATE_START    200    /* after create_decompress */
  39. #define DSTATE_INHEADER    201    /* reading header markers, no SOS yet */
  40. #define DSTATE_READY    202    /* found SOS, ready for start_decompress */
  41. #define DSTATE_PRELOAD    203    /* reading multiscan file in start_decompress*/
  42. #define DSTATE_PRESCAN    204    /* performing dummy pass for 2-pass quant */
  43. #define DSTATE_SCANNING    205    /* start_decompress done, read_scanlines OK */
  44. #define DSTATE_RAW_OK    206    /* start_decompress done, read_raw_data OK */
  45. #define DSTATE_BUFIMAGE    207    /* expecting jpeg_start_output */
  46. #define DSTATE_BUFPOST    208    /* looking for SOS/EOI in jpeg_finish_output */
  47. #define DSTATE_RDCOEFS    209    /* reading file in jpeg_read_coefficients */
  48. #define DSTATE_STOPPING    210    /* looking for EOI in jpeg_finish_decompress */
  49.  
  50.  
  51. /* Declarations for compression modules */
  52.  
  53. /* Master control module */
  54. struct jpeg_comp_master {
  55.   JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  56.   JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  57.   JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  58.  
  59.   /* State variables made visible to other modules */
  60.   boolean call_pass_startup;    /* True if pass_startup must be called */
  61.   boolean is_last_pass;        /* True during last pass */
  62. };
  63.  
  64. /* Main buffer control (downsampled-data buffer) */
  65. struct jpeg_c_main_controller {
  66.   JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  67.   JMETHOD(void, process_data, (j_compress_ptr cinfo,
  68.                    JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  69.                    JDIMENSION in_rows_avail));
  70. };
  71.  
  72. /* Compression preprocessing (downsampling input buffer control) */
  73. struct jpeg_c_prep_controller {
  74.   JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  75.   JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  76.                    JSAMPARRAY input_buf,
  77.                    JDIMENSION *in_row_ctr,
  78.                    JDIMENSION in_rows_avail,
  79.                    JSAMPIMAGE output_buf,
  80.                    JDIMENSION *out_row_group_ctr,
  81.                    JDIMENSION out_row_groups_avail));
  82. };
  83.  
  84. /* Coefficient buffer control */
  85. struct jpeg_c_coef_controller {
  86.   JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  87.   JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  88.                    JSAMPIMAGE input_buf));
  89. };
  90.  
  91. /* Colorspace conversion */
  92. struct jpeg_color_converter {
  93.   JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  94.   JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  95.                 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  96.                 JDIMENSION output_row, int num_rows));
  97. };
  98.  
  99. /* Downsampling */
  100. struct jpeg_downsampler {
  101.   JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  102.   JMETHOD(void, downsample, (j_compress_ptr cinfo,
  103.                  JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  104.                  JSAMPIMAGE output_buf,
  105.                  JDIMENSION out_row_group_index));
  106.  
  107.   boolean need_context_rows;    /* TRUE if need rows above & below */
  108. };
  109.  
  110. /* Forward DCT (also controls coefficient quantization) */
  111. struct jpeg_forward_dct {
  112.   JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  113.   /* perhaps this should be an array??? */
  114.   JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  115.                   jpeg_component_info * compptr,
  116.                   JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  117.                   JDIMENSION start_row, JDIMENSION start_col,
  118.                   JDIMENSION num_blocks));
  119. };
  120.  
  121. /* Entropy encoding */
  122. struct jpeg_entropy_encoder {
  123.   JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  124.   JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  125.   JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  126. };
  127.  
  128. /* Marker writing */
  129. struct jpeg_marker_writer {
  130.   JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  131.   JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  132.   JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  133.   JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  134.   JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  135.   /* These routines are exported to allow insertion of extra markers */
  136.   /* Probably only COM and APPn markers should be written this way */
  137.   JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  138.                       unsigned int datalen));
  139.   JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  140. };
  141.  
  142.  
  143. /* Declarations for decompression modules */
  144.  
  145. /* Master control module */
  146. struct jpeg_decomp_master {
  147.   JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  148.   JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  149.  
  150.   /* State variables made visible to other modules */
  151.   boolean is_dummy_pass;    /* True during 1st pass for 2-pass quant */
  152. };
  153.  
  154. /* Input control module */
  155. struct jpeg_input_controller {
  156.   JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  157.   JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  158.   JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  159.   JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  160.  
  161.   /* State variables made visible to other modules */
  162.   boolean has_multiple_scans;    /* True if file has multiple scans */
  163.   boolean eoi_reached;        /* True when EOI has been consumed */
  164. };
  165.  
  166. /* Main buffer control (downsampled-data buffer) */
  167. struct jpeg_d_main_controller {
  168.   JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  169.   JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  170.                    JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  171.                    JDIMENSION out_rows_avail));
  172. };
  173.  
  174. /* Coefficient buffer control */
  175. struct jpeg_d_coef_controller {
  176.   JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  177.   JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  178.   JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  179.   JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  180.                  JSAMPIMAGE output_buf));
  181.   /* Pointer to array of coefficient virtual arrays, or NULL if none */
  182.   jvirt_barray_ptr *coef_arrays;
  183. };
  184.  
  185. /* Decompression postprocessing (color quantization buffer control) */
  186. struct jpeg_d_post_controller {
  187.   JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  188.   JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  189.                     JSAMPIMAGE input_buf,
  190.                     JDIMENSION *in_row_group_ctr,
  191.                     JDIMENSION in_row_groups_avail,
  192.                     JSAMPARRAY output_buf,
  193.                     JDIMENSION *out_row_ctr,
  194.                     JDIMENSION out_rows_avail));
  195. };
  196.  
  197. /* Marker reading & parsing */
  198. struct jpeg_marker_reader {
  199.   JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  200.   /* Read markers until SOS or EOI.
  201.    * Returns same codes as are defined for jpeg_consume_input:
  202.    * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
  203.    */
  204.   JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  205.   /* Read a restart marker --- exported for use by entropy decoder only */
  206.   jpeg_marker_parser_method read_restart_marker;
  207.  
  208.   /* State of marker reader --- nominally internal, but applications
  209.    * supplying COM or APPn handlers might like to know the state.
  210.    */
  211.   boolean saw_SOI;        /* found SOI? */
  212.   boolean saw_SOF;        /* found SOF? */
  213.   int next_restart_num;        /* next restart number expected (0-7) */
  214.   unsigned int discarded_bytes;    /* # of bytes skipped looking for a marker */
  215. };
  216.  
  217. /* Entropy decoding */
  218. struct jpeg_entropy_decoder {
  219.   JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  220.   JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  221.                 JBLOCKROW *MCU_data));
  222.  
  223.   /* This is here to share code between baseline and progressive decoders; */
  224.   /* other modules probably should not use it */
  225.   boolean insufficient_data;    /* set TRUE after emitting warning */
  226. };
  227.  
  228. /* Inverse DCT (also performs dequantization) */
  229. typedef JMETHOD(void, inverse_DCT_method_ptr,
  230.         (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  231.          JCOEFPTR coef_block,
  232.          JSAMPARRAY output_buf, JDIMENSION output_col));
  233.  
  234. struct jpeg_inverse_dct {
  235.   JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  236.   /* It is useful to allow each component to have a separate IDCT method. */
  237.   inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  238. };
  239.  
  240. /* Upsampling (note that upsampler must also call color converter) */
  241. struct jpeg_upsampler {
  242.   JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  243.   JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  244.                JSAMPIMAGE input_buf,
  245.                JDIMENSION *in_row_group_ctr,
  246.                JDIMENSION in_row_groups_avail,
  247.                JSAMPARRAY output_buf,
  248.                JDIMENSION *out_row_ctr,
  249.                JDIMENSION out_rows_avail));
  250.  
  251.   boolean need_context_rows;    /* TRUE if need rows above & below */
  252. };
  253.  
  254. /* Colorspace conversion */
  255. struct jpeg_color_deconverter {
  256.   JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  257.   JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  258.                 JSAMPIMAGE input_buf, JDIMENSION input_row,
  259.                 JSAMPARRAY output_buf, int num_rows));
  260. };
  261.  
  262. /* Color quantization or color precision reduction */
  263. struct jpeg_color_quantizer {
  264.   JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  265.   JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  266.                  JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  267.                  int num_rows));
  268.   JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  269.   JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  270. };
  271.  
  272.  
  273. /* Miscellaneous useful macros */
  274.  
  275. #undef MAX
  276. #define MAX(a,b)    ((a) > (b) ? (a) : (b))
  277. #undef MIN
  278. #define MIN(a,b)    ((a) < (b) ? (a) : (b))
  279.  
  280.  
  281. /* We assume that right shift corresponds to signed division by 2 with
  282.  * rounding towards minus infinity.  This is correct for typical "arithmetic
  283.  * shift" instructions that shift in copies of the sign bit.  But some
  284.  * C compilers implement >> with an unsigned shift.  For these machines you
  285.  * must define RIGHT_SHIFT_IS_UNSIGNED.
  286.  * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
  287.  * It is only applied with constant shift counts.  SHIFT_TEMPS must be
  288.  * included in the variables of any routine using RIGHT_SHIFT.
  289.  */
  290.  
  291. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  292. #define SHIFT_TEMPS    INT32 shift_temp;
  293. #define RIGHT_SHIFT(x,shft)  \
  294.     ((shift_temp = (x)) < 0 ? \
  295.      (shift_temp >> (shft)) | ((~((long) 0)) << (32-(shft))) : \
  296.      (shift_temp >> (shft)))
  297. #else
  298. #define SHIFT_TEMPS
  299. #define RIGHT_SHIFT(x,shft)    ((x) >> (shft))
  300. #endif
  301.  
  302.  
  303.  
  304. /* Compression module initialization routines */
  305. void jinit_compress_master (j_compress_ptr cinfo);
  306. void jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only);
  307. void jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer);
  308. void jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer);
  309. void jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer);
  310. void jinit_color_converter (j_compress_ptr cinfo);
  311. void jinit_downsampler (j_compress_ptr cinfo);
  312. void jinit_forward_dct (j_compress_ptr cinfo);
  313. void jinit_huff_encoder (j_compress_ptr cinfo);
  314. void jinit_phuff_encoder (j_compress_ptr cinfo);
  315. void jinit_marker_writer (j_compress_ptr cinfo);
  316. /* Decompression module initialization routines */
  317. void jinit_master_decompress (j_decompress_ptr cinfo);
  318. void jinit_d_main_controller (j_decompress_ptr cinfo,
  319.                       boolean need_full_buffer);
  320. void jinit_d_coef_controller (j_decompress_ptr cinfo,
  321.                       boolean need_full_buffer);
  322. void jinit_d_post_controller (j_decompress_ptr cinfo,
  323.                       boolean need_full_buffer);
  324. void jinit_input_controller (j_decompress_ptr cinfo);
  325. void jinit_marker_reader (j_decompress_ptr cinfo);
  326. void jinit_huff_decoder (j_decompress_ptr cinfo);
  327. void jinit_phuff_decoder (j_decompress_ptr cinfo);
  328. void jinit_inverse_dct (j_decompress_ptr cinfo);
  329. void jinit_upsampler (j_decompress_ptr cinfo);
  330. void jinit_color_deconverter (j_decompress_ptr cinfo);
  331. void jinit_1pass_quantizer (j_decompress_ptr cinfo);
  332. void jinit_2pass_quantizer (j_decompress_ptr cinfo);
  333. void jinit_merged_upsampler (j_decompress_ptr cinfo);
  334. /* Memory manager initialization */
  335. void jinit_memory_mgr (j_common_ptr cinfo);
  336.  
  337. /* Utility routines in jutils.c */
  338. long jdiv_round_up (long a, long b);
  339. long jround_up (long a, long b);
  340. void jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  341.                     JSAMPARRAY output_array, int dest_row,
  342.                     int num_rows, JDIMENSION num_cols);
  343. void jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  344.                   JDIMENSION num_blocks);
  345.  
  346. #define jzero_far(target, bytestozero) memset(target, 0, bytestozero)
  347.  
  348. /* Constant tables in jutils.c */
  349. #if 0                /* This table is not actually needed in v6a */
  350. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  351. #endif
  352. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  353.  
  354.