Mercurial > projects > dwt-linux
comparison dwt/internal/image/JPEGDecoder.d @ 259:c0d810de7093
Update SWT 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 29 Jun 2008 14:33:38 +0200 |
parents | ce446666f5a2 |
children |
comparison
equal
deleted
inserted
replaced
257:cc1d3de0e80b | 259:c0d810de7093 |
---|---|
241 /* This field is used only during compression. It's initialized false when | 241 /* This field is used only during compression. It's initialized false when |
242 * the table is created, and set true when it's been output to the file. | 242 * the table is created, and set true when it's been output to the file. |
243 * You could suppress output of a table by setting this to true. | 243 * You could suppress output of a table by setting this to true. |
244 * (See jpeg_suppress_tables for an example.) | 244 * (See jpeg_suppress_tables for an example.) |
245 */ | 245 */ |
246 bool sent_table; /* true when table has been output */ | 246 bool sent_table; /* true when table has been output */ |
247 } | 247 } |
248 | 248 |
249 static final class JHUFF_TBL { | 249 static final class JHUFF_TBL { |
250 /* These two fields directly represent the contents of a JPEG DHT marker */ | 250 /* These two fields directly represent the contents of a JPEG DHT marker */ |
251 byte[17] bits;// = new byte[17]; /* bits[k] = # of symbols with codes of */ | 251 byte[17] bits;// = new byte[17]; /* bits[k] = # of symbols with codes of */ |
254 /* This field is used only during compression. It's initialized false when | 254 /* This field is used only during compression. It's initialized false when |
255 * the table is created, and set true when it's been output to the file. | 255 * the table is created, and set true when it's been output to the file. |
256 * You could suppress output of a table by setting this to true. | 256 * You could suppress output of a table by setting this to true. |
257 * (See jpeg_suppress_tables for an example.) | 257 * (See jpeg_suppress_tables for an example.) |
258 */ | 258 */ |
259 bool sent_table; /* true when table has been output */ | 259 bool sent_table; /* true when table has been output */ |
260 } | 260 } |
261 | 261 |
262 static final class bitread_perm_state { /* Bitreading state saved across MCUs */ | 262 static final class bitread_perm_state { /* Bitreading state saved across MCUs */ |
263 int get_buffer; /* current bit-extraction buffer */ | 263 int get_buffer; /* current bit-extraction buffer */ |
264 int bits_left; /* # of unused bits in it */ | 264 int bits_left; /* # of unused bits in it */ |
372 abstract void start_pass (jpeg_decompress_struct cinfo); | 372 abstract void start_pass (jpeg_decompress_struct cinfo); |
373 abstract bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data); | 373 abstract bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data); |
374 | 374 |
375 /* This is here to share code between baseline and progressive decoders; */ | 375 /* This is here to share code between baseline and progressive decoders; */ |
376 /* other modules probably should not use it */ | 376 /* other modules probably should not use it */ |
377 bool insufficient_data; /* set true after emitting warning */ | 377 bool insufficient_data; /* set true after emitting warning */ |
378 | 378 |
379 bitread_working_state br_state_local; | 379 bitread_working_state br_state_local; |
380 savable_state state_local; | 380 savable_state state_local; |
381 public this(){ | 381 public this(){ |
382 br_state_local = new bitread_working_state(); | 382 br_state_local = new bitread_working_state(); |
977 } | 977 } |
978 } | 978 } |
979 r = s >> 4; | 979 r = s >> 4; |
980 s &= 15; | 980 s &= 15; |
981 if (s !is 0) { | 981 if (s !is 0) { |
982 if (s !is 1) { /* size of new coef should always be 1 */ | 982 if (s !is 1) { /* size of new coef should always be 1 */ |
983 // WARNMS(cinfo, JWRN_HUFF_BAD_CODE); | 983 // WARNMS(cinfo, JWRN_HUFF_BAD_CODE); |
984 } | 984 } |
985 // CHECK_BIT_BUFFER(br_state, 1, goto undoit); | 985 // CHECK_BIT_BUFFER(br_state, 1, goto undoit); |
986 { | 986 { |
987 if (bits_left < (1)) { | 987 if (bits_left < (1)) { |
1240 } else { | 1240 } else { |
1241 if (r is 15) { /* ZRL */ | 1241 if (r is 15) { /* ZRL */ |
1242 k += 15; /* skip 15 zeroes in band */ | 1242 k += 15; /* skip 15 zeroes in band */ |
1243 } else { /* EOBr, run length is 2^r + appended bits */ | 1243 } else { /* EOBr, run length is 2^r + appended bits */ |
1244 EOBRUN = 1 << r; | 1244 EOBRUN = 1 << r; |
1245 if (r !is 0) { /* EOBr, r > 0 */ | 1245 if (r !is 0) { /* EOBr, r > 0 */ |
1246 // CHECK_BIT_BUFFER(br_state, r, return FALSE); | 1246 // CHECK_BIT_BUFFER(br_state, r, return FALSE); |
1247 { | 1247 { |
1248 if (bits_left < (r)) { | 1248 if (bits_left < (r)) { |
1249 if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,r)) { | 1249 if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,r)) { |
1250 return false; | 1250 return false; |
1278 entropy.restarts_to_go--; | 1278 entropy.restarts_to_go--; |
1279 | 1279 |
1280 return true; | 1280 return true; |
1281 } | 1281 } |
1282 | 1282 |
1283 bool decode_mcu_DC_first (jpeg_decompress_struct cinfo, short[][] MCU_data) { | 1283 bool decode_mcu_DC_first (jpeg_decompress_struct cinfo, short[][] MCU_data) { |
1284 phuff_entropy_decoder entropy = this; | 1284 phuff_entropy_decoder entropy = this; |
1285 int Al = cinfo.Al; | 1285 int Al = cinfo.Al; |
1286 int s = 0, r; | 1286 int s = 0, r; |
1287 int blkn, ci; | 1287 int blkn, ci; |
1288 short[] block; | 1288 short[] block; |
1594 int downsampled_height; /* actual height in samples */ | 1594 int downsampled_height; /* actual height in samples */ |
1595 /* This flag is used only for decompression. In cases where some of the | 1595 /* This flag is used only for decompression. In cases where some of the |
1596 * components will be ignored (eg grayscale output from YCbCr image), | 1596 * components will be ignored (eg grayscale output from YCbCr image), |
1597 * we can skip most computations for the unused components. | 1597 * we can skip most computations for the unused components. |
1598 */ | 1598 */ |
1599 bool component_needed; /* do we need the value of this component? */ | 1599 bool component_needed; /* do we need the value of this component? */ |
1600 | 1600 |
1601 /* These values are computed before starting a scan of the component. */ | 1601 /* These values are computed before starting a scan of the component. */ |
1602 /* The decompressor output side may not use these variables. */ | 1602 /* The decompressor output side may not use these variables. */ |
1603 int MCU_width; /* number of blocks per MCU, horizontally */ | 1603 int MCU_width; /* number of blocks per MCU, horizontally */ |
1604 int MCU_height; /* number of blocks per MCU, vertically */ | 1604 int MCU_height; /* number of blocks per MCU, vertically */ |
1632 int[][] colorindex; /* Precomputed mapping for speed */ | 1632 int[][] colorindex; /* Precomputed mapping for speed */ |
1633 /* colorindex[i][j] = index of color closest to pixel value j in component i, | 1633 /* colorindex[i][j] = index of color closest to pixel value j in component i, |
1634 * premultiplied as described above. Since colormap indexes must fit into | 1634 * premultiplied as described above. Since colormap indexes must fit into |
1635 * JSAMPLEs, the entries of this array will too. | 1635 * JSAMPLEs, the entries of this array will too. |
1636 */ | 1636 */ |
1637 bool is_padded; /* is the colorindex padded for odither? */ | 1637 bool is_padded; /* is the colorindex padded for odither? */ |
1638 | 1638 |
1639 int[MAX_Q_COMPS] Ncolors;// = new int [MAX_Q_COMPS]; /* # of values alloced to each component */ | 1639 int[MAX_Q_COMPS] Ncolors;// = new int [MAX_Q_COMPS]; /* # of values alloced to each component */ |
1640 | 1640 |
1641 /* Variables for ordered dithering */ | 1641 /* Variables for ordered dithering */ |
1642 int row_index; /* cur row's vertical index in dither matrix */ | 1642 int row_index; /* cur row's vertical index in dither matrix */ |
1643 // ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */ | 1643 // ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */ |
1644 | 1644 |
1645 /* Variables for Floyd-Steinberg dithering */ | 1645 /* Variables for Floyd-Steinberg dithering */ |
1646 // FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */ | 1646 // FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */ |
1647 bool on_odd_row; | 1647 bool on_odd_row; |
1648 | 1648 |
1649 void start_pass (jpeg_decompress_struct cinfo, bool is_pre_scan) { | 1649 void start_pass (jpeg_decompress_struct cinfo, bool is_pre_scan) { |
1650 error(); | 1650 error(); |
1651 } | 1651 } |
1652 } | 1652 } |
1659 // JDIMENSION in_row_groups_avail, | 1659 // JDIMENSION in_row_groups_avail, |
1660 // JSAMPARRAY output_buf, | 1660 // JSAMPARRAY output_buf, |
1661 // JDIMENSION *out_row_ctr, | 1661 // JDIMENSION *out_row_ctr, |
1662 // JDIMENSION out_rows_avail)); | 1662 // JDIMENSION out_rows_avail)); |
1663 | 1663 |
1664 bool need_context_rows; /* TRUE if need rows above & below */ | 1664 bool need_context_rows; /* TRUE if need rows above & below */ |
1665 | 1665 |
1666 /* Color conversion buffer. When using separate upsampling and color | 1666 /* Color conversion buffer. When using separate upsampling and color |
1667 * conversion steps, this buffer holds one upsampled row group until it | 1667 * conversion steps, this buffer holds one upsampled row group until it |
1668 * has been color converted and output. | 1668 * has been color converted and output. |
1669 * Note: we do not allocate any storage for component(s) which are full-size, | 1669 * Note: we do not allocate any storage for component(s) which are full-size, |
1704 // jpeg_marker_parser_method read_restart_marker; | 1704 // jpeg_marker_parser_method read_restart_marker; |
1705 | 1705 |
1706 /* State of marker reader --- nominally internal, but applications | 1706 /* State of marker reader --- nominally internal, but applications |
1707 * supplying COM or APPn handlers might like to know the state. | 1707 * supplying COM or APPn handlers might like to know the state. |
1708 */ | 1708 */ |
1709 bool saw_SOI; /* found SOI? */ | 1709 bool saw_SOI; /* found SOI? */ |
1710 bool saw_SOF; /* found SOF? */ | 1710 bool saw_SOF; /* found SOF? */ |
1711 int next_restart_num; /* next restart number expected (0-7) */ | 1711 int next_restart_num; /* next restart number expected (0-7) */ |
1712 int discarded_bytes; /* # of bytes skipped looking for a marker */ | 1712 int discarded_bytes; /* # of bytes skipped looking for a marker */ |
1713 | 1713 |
1714 /* Application-overridable marker processing methods */ | 1714 /* Application-overridable marker processing methods */ |
1715 // jpeg_marker_parser_method process_COM; | 1715 // jpeg_marker_parser_method process_COM; |
1732 | 1732 |
1733 /* Pointer to allocated workspace (M or M+2 row groups). */ | 1733 /* Pointer to allocated workspace (M or M+2 row groups). */ |
1734 byte[][][MAX_COMPONENTS] buffer;// = new byte[MAX_COMPONENTS][][]; | 1734 byte[][][MAX_COMPONENTS] buffer;// = new byte[MAX_COMPONENTS][][]; |
1735 int[MAX_COMPONENTS] buffer_offset;// = new int[MAX_COMPONENTS]; | 1735 int[MAX_COMPONENTS] buffer_offset;// = new int[MAX_COMPONENTS]; |
1736 | 1736 |
1737 bool buffer_full; /* Have we gotten an iMCU row from decoder? */ | 1737 bool buffer_full; /* Have we gotten an iMCU row from decoder? */ |
1738 int[1] rowgroup_ctr;// = new int[1]; /* counts row groups output to postprocessor */ | 1738 int[1] rowgroup_ctr;// = new int[1]; /* counts row groups output to postprocessor */ |
1739 | 1739 |
1740 /* Remaining fields are only used in the context case. */ | 1740 /* Remaining fields are only used in the context case. */ |
1741 | 1741 |
1742 /* These are the master pointers to the funny-order pointer lists. */ | 1742 /* These are the master pointers to the funny-order pointer lists. */ |
1956 } | 1956 } |
1957 } | 1957 } |
1958 | 1958 |
1959 static final class jpeg_input_controller { | 1959 static final class jpeg_input_controller { |
1960 int consume_input; | 1960 int consume_input; |
1961 bool has_multiple_scans; /* True if file has multiple scans */ | 1961 bool has_multiple_scans; /* True if file has multiple scans */ |
1962 bool eoi_reached; | 1962 bool eoi_reached; |
1963 | 1963 |
1964 bool inheaders; /* true until first SOS is reached */ | 1964 bool inheaders; /* true until first SOS is reached */ |
1965 } | 1965 } |
1966 | 1966 |
1967 static final class jpeg_color_deconverter { | 1967 static final class jpeg_color_deconverter { |
1968 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); | 1968 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); |
1969 int color_convert; | 1969 int color_convert; |
2048 static final class jpeg_decompress_struct { | 2048 static final class jpeg_decompress_struct { |
2049 // jpeg_error_mgr * err; /* Error handler module */\ | 2049 // jpeg_error_mgr * err; /* Error handler module */\ |
2050 // struct jpeg_memory_mgr * mem; /* Memory manager module */\ | 2050 // struct jpeg_memory_mgr * mem; /* Memory manager module */\ |
2051 // struct jpeg_progress_mgr * progress; /* Progress monitor, or null if none */\ | 2051 // struct jpeg_progress_mgr * progress; /* Progress monitor, or null if none */\ |
2052 // void * client_data; /* Available for use by application */\ | 2052 // void * client_data; /* Available for use by application */\ |
2053 bool is_decompressor; /* So common code can tell which is which */ | 2053 bool is_decompressor; /* So common code can tell which is which */ |
2054 int global_state; /* For checking call sequence validity */ | 2054 int global_state; /* For checking call sequence validity */ |
2055 | 2055 |
2056 // /* Source of compressed data */ | 2056 // /* Source of compressed data */ |
2057 // struct jpeg_source_mgr * src; | 2057 // struct jpeg_source_mgr * src; |
2058 InputStream inputStream; | 2058 InputStream inputStream; |
2078 | 2078 |
2079 int scale_num, scale_denom; /* fraction by which to scale image */ | 2079 int scale_num, scale_denom; /* fraction by which to scale image */ |
2080 | 2080 |
2081 double output_gamma; /* image gamma wanted in output */ | 2081 double output_gamma; /* image gamma wanted in output */ |
2082 | 2082 |
2083 bool buffered_image; /* true=multiple output passes */ | 2083 bool buffered_image; /* true=multiple output passes */ |
2084 bool raw_data_out; /* true=downsampled data wanted */ | 2084 bool raw_data_out; /* true=downsampled data wanted */ |
2085 | 2085 |
2086 int dct_method; /* IDCT algorithm selector */ | 2086 int dct_method; /* IDCT algorithm selector */ |
2087 bool do_fancy_upsampling; /* true=apply fancy upsampling */ | 2087 bool do_fancy_upsampling; /* true=apply fancy upsampling */ |
2088 bool do_block_smoothing; /* true=apply interblock smoothing */ | 2088 bool do_block_smoothing; /* true=apply interblock smoothing */ |
2089 | 2089 |
2090 bool quantize_colors; /* true=colormapped output wanted */ | 2090 bool quantize_colors; /* true=colormapped output wanted */ |
2091 /* the following are ignored if not quantize_colors: */ | 2091 /* the following are ignored if not quantize_colors: */ |
2092 int dither_mode; /* type of color dithering to use */ | 2092 int dither_mode; /* type of color dithering to use */ |
2093 bool two_pass_quantize; /* true=use two-pass color quantization */ | 2093 bool two_pass_quantize; /* true=use two-pass color quantization */ |
2094 int desired_number_of_colors; /* max # colors to use in created colormap */ | 2094 int desired_number_of_colors; /* max # colors to use in created colormap */ |
2095 /* these are significant only in buffered-image mode: */ | 2095 /* these are significant only in buffered-image mode: */ |
2096 bool enable_1pass_quant; /* enable future use of 1-pass quantizer */ | 2096 bool enable_1pass_quant; /* enable future use of 1-pass quantizer */ |
2097 bool enable_external_quant;/* enable future use of external colormap */ | 2097 bool enable_external_quant;/* enable future use of external colormap */ |
2098 bool enable_2pass_quant; /* enable future use of 2-pass quantizer */ | 2098 bool enable_2pass_quant; /* enable future use of 2-pass quantizer */ |
2099 | 2099 |
2100 /* Description of actual output image that will be returned to application. | 2100 /* Description of actual output image that will be returned to application. |
2101 * These fields are computed by jpeg_start_decompress(). | 2101 * These fields are computed by jpeg_start_decompress(). |
2102 * You can also use jpeg_calc_output_dimensions() to determine these values | 2102 * You can also use jpeg_calc_output_dimensions() to determine these values |
2103 * in advance of calling jpeg_start_decompress(). | 2103 * in advance of calling jpeg_start_decompress(). |
2180 int data_precision; /* bits of precision in image data */ | 2180 int data_precision; /* bits of precision in image data */ |
2181 | 2181 |
2182 jpeg_component_info[] comp_info; | 2182 jpeg_component_info[] comp_info; |
2183 /* comp_info[i] describes component that appears i'th in SOF */ | 2183 /* comp_info[i] describes component that appears i'th in SOF */ |
2184 | 2184 |
2185 bool progressive_mode; /* true if SOFn specifies progressive mode */ | 2185 bool progressive_mode; /* true if SOFn specifies progressive mode */ |
2186 bool arith_code; /* true=arithmetic coding, false=Huffman */ | 2186 bool arith_code; /* true=arithmetic coding, false=Huffman */ |
2187 | 2187 |
2188 byte[NUM_ARITH_TBLS] arith_dc_L;// = new byte[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ | 2188 byte[NUM_ARITH_TBLS] arith_dc_L;// = new byte[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ |
2189 byte[NUM_ARITH_TBLS] arith_dc_U;// = new byte[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ | 2189 byte[NUM_ARITH_TBLS] arith_dc_U;// = new byte[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ |
2190 byte[NUM_ARITH_TBLS] arith_ac_K;// = new byte[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ | 2190 byte[NUM_ARITH_TBLS] arith_ac_K;// = new byte[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ |
2191 | 2191 |
2192 int restart_interval; /* MCUs per restart interval, or 0 for no restart */ | 2192 int restart_interval; /* MCUs per restart interval, or 0 for no restart */ |
2193 | 2193 |
2194 /* These fields record data obtained from optional markers recognized by | 2194 /* These fields record data obtained from optional markers recognized by |
2195 * the JPEG library. | 2195 * the JPEG library. |
2196 */ | 2196 */ |
2197 bool saw_JFIF_marker; /* true iff a JFIF APP0 marker was found */ | 2197 bool saw_JFIF_marker; /* true iff a JFIF APP0 marker was found */ |
2198 /* Data copied from JFIF marker; only valid if saw_JFIF_marker is true: */ | 2198 /* Data copied from JFIF marker; only valid if saw_JFIF_marker is true: */ |
2199 byte JFIF_major_version; /* JFIF version number */ | 2199 byte JFIF_major_version; /* JFIF version number */ |
2200 byte JFIF_minor_version; | 2200 byte JFIF_minor_version; |
2201 byte density_unit; /* JFIF code for pixel size units */ | 2201 byte density_unit; /* JFIF code for pixel size units */ |
2202 short X_density; /* Horizontal pixel density */ | 2202 short X_density; /* Horizontal pixel density */ |
2203 short Y_density; /* Vertical pixel density */ | 2203 short Y_density; /* Vertical pixel density */ |
2204 bool saw_Adobe_marker; /* true iff an Adobe APP14 marker was found */ | 2204 bool saw_Adobe_marker; /* true iff an Adobe APP14 marker was found */ |
2205 byte Adobe_transform; /* Color transform code from Adobe marker */ | 2205 byte Adobe_transform; /* Color transform code from Adobe marker */ |
2206 | 2206 |
2207 bool CCIR601_sampling; /* true=first samples are cosited */ | 2207 bool CCIR601_sampling; /* true=first samples are cosited */ |
2208 | 2208 |
2209 /* Aside from the specific data retained from APPn markers known to the | 2209 /* Aside from the specific data retained from APPn markers known to the |
2210 * library, the uninterpreted contents of any or all APPn and COM markers | 2210 * library, the uninterpreted contents of any or all APPn and COM markers |
2211 * can be saved in a list for examination by the application. | 2211 * can be saved in a list for examination by the application. |
2212 */ | 2212 */ |
4446 huffval[i] = cinfo.buffer[cinfo.bytes_offset++]; | 4446 huffval[i] = cinfo.buffer[cinfo.bytes_offset++]; |
4447 } | 4447 } |
4448 | 4448 |
4449 length -= count; | 4449 length -= count; |
4450 | 4450 |
4451 if ((index & 0x10) !is 0) { /* AC table definition */ | 4451 if ((index & 0x10) !is 0) { /* AC table definition */ |
4452 index -= 0x10; | 4452 index -= 0x10; |
4453 htblptr = cinfo.ac_huff_tbl_ptrs[index] = new JHUFF_TBL(); | 4453 htblptr = cinfo.ac_huff_tbl_ptrs[index] = new JHUFF_TBL(); |
4454 } else { /* DC table definition */ | 4454 } else { /* DC table definition */ |
4455 htblptr = cinfo.dc_huff_tbl_ptrs[index] = new JHUFF_TBL(); | 4455 htblptr = cinfo.dc_huff_tbl_ptrs[index] = new JHUFF_TBL(); |
4456 } | 4456 } |
5235 if (((data[12] & 0xFF) | (data[13]) & 0xFF) !is 0) { | 5235 if (((data[12] & 0xFF) | (data[13]) & 0xFF) !is 0) { |
5236 // TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, | 5236 // TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, |
5237 // GETJOCTET(data[12]), GETJOCTET(data[13])); | 5237 // GETJOCTET(data[12]), GETJOCTET(data[13])); |
5238 } | 5238 } |
5239 totallen -= APP0_DATA_LEN; | 5239 totallen -= APP0_DATA_LEN; |
5240 if (totallen !is ((data[12] & 0xFF) * (data[13] & 0xFF) * 3)) { | 5240 if (totallen !is ((data[12] & 0xFF) * (data[13] & 0xFF) * 3)) { |
5241 // TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, cast(int) totallen); | 5241 // TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, cast(int) totallen); |
5242 } | 5242 } |
5243 } else if (datalen >= 6 && | 5243 } else if (datalen >= 6 && |
5244 (data[0] & 0xFF) is 0x4A && | 5244 (data[0] & 0xFF) is 0x4A && |
5245 (data[1] & 0xFF) is 0x46 && | 5245 (data[1] & 0xFF) is 0x46 && |