Trinity Desktop Environment Packaging
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.

402 lines
16KB

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