Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

403 lines
15 KiB

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