Mercurial > projects > dwt-mac
comparison dwt/internal/image/JPEGDecoder.d @ 34:5123b17c98ef
Ported dwt.events.*, dwt.graphics.GC, Region, dwt.internal.image.*
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sun, 14 Sep 2008 01:45:57 +0200 |
parents | e831403a80a9 |
children | d8635bb48c7c |
comparison
equal
deleted
inserted
replaced
33:965ac0a77267 | 34:5123b17c98ef |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
10 *******************************************************************************/ | 12 *******************************************************************************/ |
11 module dwt.internal.image; | 13 module dwt.internal.image.JPEGDecoder; |
12 | |
13 import java.io.IOException; | |
14 import java.io.InputStream; | |
15 | 14 |
16 import dwt.DWT; | 15 import dwt.DWT; |
16 import dwt.dwthelper.InputStream; | |
17 import dwt.internal.image.LEDataInputStream; | |
17 import dwt.graphics.ImageData; | 18 import dwt.graphics.ImageData; |
18 import dwt.graphics.ImageLoader; | 19 import dwt.graphics.ImageLoader; |
19 import dwt.graphics.ImageLoaderEvent; | 20 import dwt.graphics.ImageLoaderEvent; |
20 import dwt.graphics.PaletteData; | 21 import dwt.graphics.PaletteData; |
21 import dwt.graphics.RGB; | 22 import dwt.graphics.RGB; |
23 import dwt.dwthelper.utils; | |
24 | |
25 import tango.core.Exception; | |
26 import tango.util.Convert; | |
27 import Math = tango.math.Math; | |
22 | 28 |
23 public class JPEGDecoder { | 29 public class JPEGDecoder { |
24 | 30 |
25 static final int DCTSIZE = 8; | 31 static const int DCTSIZE = 8; |
26 static final int DCTSIZE2 = 64; | 32 static const int DCTSIZE2 = 64; |
27 static final int NUM_QUANT_TBLS = 4; | 33 static const int NUM_QUANT_TBLS = 4; |
28 static final int NUM_HUFF_TBLS = 4; | 34 static const int NUM_HUFF_TBLS = 4; |
29 static final int NUM_ARITH_TBLS = 16; | 35 static const int NUM_ARITH_TBLS = 16; |
30 static final int MAX_COMPS_IN_SCAN = 4; | 36 static const int MAX_COMPS_IN_SCAN = 4; |
31 static final int MAX_COMPONENTS = 10; | 37 static const int MAX_COMPONENTS = 10; |
32 static final int MAX_SAMP_FACTOR = 4; | 38 static const int MAX_SAMP_FACTOR = 4; |
33 static final int D_MAX_BLOCKS_IN_MCU = 10; | 39 static const int D_MAX_BLOCKS_IN_MCU = 10; |
34 static final int HUFF_LOOKAHEAD = 8; | 40 static const int HUFF_LOOKAHEAD = 8; |
35 static final int MAX_Q_COMPS = 4; | 41 static const int MAX_Q_COMPS = 4; |
36 static final int IFAST_SCALE_BITS = 2; | 42 static const int IFAST_SCALE_BITS = 2; |
37 static final int MAXJSAMPLE = 255; | 43 static const int MAXJSAMPLE = 255; |
38 static final int CENTERJSAMPLE = 128; | 44 static const int CENTERJSAMPLE = 128; |
39 static final int MIN_GET_BITS = 32-7; | 45 static const int MIN_GET_BITS = 32-7; |
40 static final int INPUT_BUFFER_SIZE = 4096; | 46 static const int INPUT_BUFFER_SIZE = 4096; |
41 | 47 |
42 static final int SCALEBITS = 16; /* speediest right-shift on some machines */ | 48 static const int SCALEBITS = 16; /* speediest right-shift on some machines */ |
43 static final int ONE_HALF = 1 << (SCALEBITS-1); | 49 static const int ONE_HALF = 1 << (SCALEBITS-1); |
44 | 50 |
45 static final int RGB_RED = 2; /* Offset of Red in an RGB scanline element */ | 51 static const int RGB_RED = 2; /* Offset of Red in an RGB scanline element */ |
46 static final int RGB_GREEN = 1; /* Offset of Green */ | 52 static const int RGB_GREEN = 1; /* Offset of Green */ |
47 static final int RGB_BLUE = 0; /* Offset of Blue */ | 53 static const int RGB_BLUE = 0; /* Offset of Blue */ |
48 static final int RGB_PIXELSIZE = 3; | 54 static const int RGB_PIXELSIZE = 3; |
49 | 55 |
50 static final int JBUF_PASS_THRU = 0; | 56 static const int JBUF_PASS_THRU = 0; |
51 static final int JBUF_SAVE_SOURCE = 1; /* Run source subobject only, save output */ | 57 static const int JBUF_SAVE_SOURCE = 1; /* Run source subobject only, save output */ |
52 static final int JBUF_CRANK_DEST = 2; /* Run dest subobject only, using saved data */ | 58 static const int JBUF_CRANK_DEST = 2; /* Run dest subobject only, using saved data */ |
53 static final int JBUF_SAVE_AND_PASS = 3; | 59 static const int JBUF_SAVE_AND_PASS = 3; |
54 | 60 |
55 static final int JPEG_MAX_DIMENSION = 65500; | 61 static const int JPEG_MAX_DIMENSION = 65500; |
56 static final int BITS_IN_JSAMPLE = 8; | 62 static const int BITS_IN_JSAMPLE = 8; |
57 | 63 |
58 static final int JDITHER_NONE = 0; /* no dithering */ | 64 static const int JDITHER_NONE = 0; /* no dithering */ |
59 static final int JDITHER_ORDERED = 1; /* simple ordered dither */ | 65 static const int JDITHER_ORDERED = 1; /* simple ordered dither */ |
60 static final int JDITHER_FS = 2; | 66 static const int JDITHER_FS = 2; |
61 | 67 |
62 static final int JDCT_ISLOW = 0; /* slow but accurate integer algorithm */ | 68 static const int JDCT_ISLOW = 0; /* slow but accurate integer algorithm */ |
63 static final int JDCT_IFAST = 1; /* faster, less accurate integer method */ | 69 static const int JDCT_IFAST = 1; /* faster, less accurate integer method */ |
64 static final int JDCT_FLOAT = 2; /* floating-point: accurate, fast on fast HW */ | 70 static const int JDCT_FLOAT = 2; /* floating-point: accurate, fast on fast HW */ |
65 static final int JDCT_DEFAULT = JDCT_ISLOW; | 71 static const int JDCT_DEFAULT = JDCT_ISLOW; |
66 | 72 |
67 static final int JCS_UNKNOWN = 0; /* error/unspecified */ | 73 static const int JCS_UNKNOWN = 0; /* error/unspecified */ |
68 static final int JCS_GRAYSCALE = 1; /* monochrome */ | 74 static const int JCS_GRAYSCALE = 1; /* monochrome */ |
69 static final int JCS_RGB = 2; /* red/green/blue */ | 75 static const int JCS_RGB = 2; /* red/green/blue */ |
70 static final int JCS_YCbCr = 3; /* Y/Cb/Cr (also known as YUV) */ | 76 static const int JCS_YCbCr = 3; /* Y/Cb/Cr (also known as YUV) */ |
71 static final int JCS_CMYK = 4; /* C/M/Y/K */ | 77 static const int JCS_CMYK = 4; /* C/M/Y/K */ |
72 static final int JCS_YCCK = 5; /* Y/Cb/Cr/K */ | 78 static const int JCS_YCCK = 5; /* Y/Cb/Cr/K */ |
73 | 79 |
74 static final int SAVED_COEFS = 6; | 80 static const int SAVED_COEFS = 6; |
75 static final int Q01_POS = 1; | 81 static const int Q01_POS = 1; |
76 static final int Q10_POS = 8; | 82 static const int Q10_POS = 8; |
77 static final int Q20_POS = 16; | 83 static const int Q20_POS = 16; |
78 static final int Q11_POS = 9; | 84 static const int Q11_POS = 9; |
79 static final int Q02_POS = 2; | 85 static const int Q02_POS = 2; |
80 | 86 |
81 static final int CTX_PREPARE_FOR_IMCU = 0; /* need to prepare for MCU row */ | 87 static const int CTX_PREPARE_FOR_IMCU = 0; /* need to prepare for MCU row */ |
82 static final int CTX_PROCESS_IMCU = 1; /* feeding iMCU to postprocessor */ | 88 static const int CTX_PROCESS_IMCU = 1; /* feeding iMCU to postprocessor */ |
83 static final int CTX_POSTPONED_ROW = 2; /* feeding postponed row group */ | 89 static const int CTX_POSTPONED_ROW = 2; /* feeding postponed row group */ |
84 | 90 |
85 static final int APP0_DATA_LEN = 14; /* Length of interesting data in APP0 */ | 91 static const int APP0_DATA_LEN = 14; /* Length of interesting data in APP0 */ |
86 static final int APP14_DATA_LEN = 12; /* Length of interesting data in APP14 */ | 92 static const int APP14_DATA_LEN = 12; /* Length of interesting data in APP14 */ |
87 static final int APPN_DATA_LEN = 14; /* Must be the largest of the above!! */ | 93 static const int APPN_DATA_LEN = 14; /* Must be the largest of the above!! */ |
88 | 94 |
89 /* markers */ | 95 /* markers */ |
90 static final int M_SOF0 = 0xc0; | 96 static const int M_SOF0 = 0xc0; |
91 static final int M_SOF1 = 0xc1; | 97 static const int M_SOF1 = 0xc1; |
92 static final int M_SOF2 = 0xc2; | 98 static const int M_SOF2 = 0xc2; |
93 static final int M_SOF3 = 0xc3; | 99 static const int M_SOF3 = 0xc3; |
94 static final int M_SOF5 = 0xc5; | 100 static const int M_SOF5 = 0xc5; |
95 static final int M_SOF6 = 0xc6; | 101 static const int M_SOF6 = 0xc6; |
96 static final int M_SOF7 = 0xc7; | 102 static const int M_SOF7 = 0xc7; |
97 static final int M_JPG = 0xc8; | 103 static const int M_JPG = 0xc8; |
98 static final int M_SOF9 = 0xc9; | 104 static const int M_SOF9 = 0xc9; |
99 static final int M_SOF10 = 0xca; | 105 static const int M_SOF10 = 0xca; |
100 static final int M_SOF11 = 0xcb; | 106 static const int M_SOF11 = 0xcb; |
101 static final int M_SOF13 = 0xcd; | 107 static const int M_SOF13 = 0xcd; |
102 static final int M_SOF14 = 0xce; | 108 static const int M_SOF14 = 0xce; |
103 static final int M_SOF15 = 0xcf; | 109 static const int M_SOF15 = 0xcf; |
104 static final int M_DHT = 0xc4; | 110 static const int M_DHT = 0xc4; |
105 static final int M_DAC = 0xcc; | 111 static const int M_DAC = 0xcc; |
106 static final int M_RST0 = 0xd0; | 112 static const int M_RST0 = 0xd0; |
107 static final int M_RST1 = 0xd1; | 113 static const int M_RST1 = 0xd1; |
108 static final int M_RST2 = 0xd2; | 114 static const int M_RST2 = 0xd2; |
109 static final int M_RST3 = 0xd3; | 115 static const int M_RST3 = 0xd3; |
110 static final int M_RST4 = 0xd4; | 116 static const int M_RST4 = 0xd4; |
111 static final int M_RST5 = 0xd5; | 117 static const int M_RST5 = 0xd5; |
112 static final int M_RST6 = 0xd6; | 118 static const int M_RST6 = 0xd6; |
113 static final int M_RST7 = 0xd7; | 119 static const int M_RST7 = 0xd7; |
114 static final int M_SOI = 0xd8; | 120 static const int M_SOI = 0xd8; |
115 static final int M_EOI = 0xd9; | 121 static const int M_EOI = 0xd9; |
116 static final int M_SOS = 0xda; | 122 static const int M_SOS = 0xda; |
117 static final int M_DQT = 0xdb; | 123 static const int M_DQT = 0xdb; |
118 static final int M_DNL = 0xdc; | 124 static const int M_DNL = 0xdc; |
119 static final int M_DRI = 0xdd; | 125 static const int M_DRI = 0xdd; |
120 static final int M_DHP = 0xde; | 126 static const int M_DHP = 0xde; |
121 static final int M_EXP = 0xdf; | 127 static const int M_EXP = 0xdf; |
122 static final int M_APP0 = 0xe0; | 128 static const int M_APP0 = 0xe0; |
123 static final int M_APP1 = 0xe1; | 129 static const int M_APP1 = 0xe1; |
124 static final int M_APP2 = 0xe2; | 130 static const int M_APP2 = 0xe2; |
125 static final int M_APP3 = 0xe3; | 131 static const int M_APP3 = 0xe3; |
126 static final int M_APP4 = 0xe4; | 132 static const int M_APP4 = 0xe4; |
127 static final int M_APP5 = 0xe5; | 133 static const int M_APP5 = 0xe5; |
128 static final int M_APP6 = 0xe6; | 134 static const int M_APP6 = 0xe6; |
129 static final int M_APP7 = 0xe7; | 135 static const int M_APP7 = 0xe7; |
130 static final int M_APP8 = 0xe8; | 136 static const int M_APP8 = 0xe8; |
131 static final int M_APP9 = 0xe9; | 137 static const int M_APP9 = 0xe9; |
132 static final int M_APP10 = 0xea; | 138 static const int M_APP10 = 0xea; |
133 static final int M_APP11 = 0xeb; | 139 static const int M_APP11 = 0xeb; |
134 static final int M_APP12 = 0xec; | 140 static const int M_APP12 = 0xec; |
135 static final int M_APP13 = 0xed; | 141 static const int M_APP13 = 0xed; |
136 static final int M_APP14 = 0xee; | 142 static const int M_APP14 = 0xee; |
137 static final int M_APP15 = 0xef; | 143 static const int M_APP15 = 0xef; |
138 static final int M_JPG0 = 0xf0; | 144 static const int M_JPG0 = 0xf0; |
139 static final int M_JPG13 = 0xfd; | 145 static const int M_JPG13 = 0xfd; |
140 static final int M_COM = 0xfe; | 146 static const int M_COM = 0xfe; |
141 static final int M_TEM = 0x01; | 147 static const int M_TEM = 0x01; |
142 static final int M_ERROR = 0x100; | 148 static const int M_ERROR = 0x100; |
143 | 149 |
144 /* Values of global_state field (jdapi.c has some dependencies on ordering!) */ | 150 /* Values of global_state field (jdapi.c has some dependencies on ordering!) */ |
145 static final int CSTATE_START = 100; /* after create_compress */ | 151 static const int CSTATE_START = 100; /* after create_compress */ |
146 static final int CSTATE_SCANNING = 101; /* start_compress done, write_scanlines OK */ | 152 static const int CSTATE_SCANNING = 101; /* start_compress done, write_scanlines OK */ |
147 static final int CSTATE_RAW_OK = 102; /* start_compress done, write_raw_data OK */ | 153 static const int CSTATE_RAW_OK = 102; /* start_compress done, write_raw_data OK */ |
148 static final int CSTATE_WRCOEFS = 103; /* jpeg_write_coefficients done */ | 154 static const int CSTATE_WRCOEFS = 103; /* jpeg_write_coefficients done */ |
149 static final int DSTATE_START = 200; /* after create_decompress */ | 155 static const int DSTATE_START = 200; /* after create_decompress */ |
150 static final int DSTATE_INHEADER = 201; /* reading header markers, no SOS yet */ | 156 static const int DSTATE_INHEADER = 201; /* reading header markers, no SOS yet */ |
151 static final int DSTATE_READY = 202; /* found SOS, ready for start_decompress */ | 157 static const int DSTATE_READY = 202; /* found SOS, ready for start_decompress */ |
152 static final int DSTATE_PRELOAD = 203; /* reading multiscan file in start_decompress*/ | 158 static const int DSTATE_PRELOAD = 203; /* reading multiscan file in start_decompress*/ |
153 static final int DSTATE_PRESCAN = 204; /* performing dummy pass for 2-pass quant */ | 159 static const int DSTATE_PRESCAN = 204; /* performing dummy pass for 2-pass quant */ |
154 static final int DSTATE_SCANNING = 205; /* start_decompress done, read_scanlines OK */ | 160 static const int DSTATE_SCANNING = 205; /* start_decompress done, read_scanlines OK */ |
155 static final int DSTATE_RAW_OK = 206; /* start_decompress done, read_raw_data OK */ | 161 static const int DSTATE_RAW_OK = 206; /* start_decompress done, read_raw_data OK */ |
156 static final int DSTATE_BUFIMAGE = 207; /* expecting jpeg_start_output */ | 162 static const int DSTATE_BUFIMAGE = 207; /* expecting jpeg_start_output */ |
157 static final int DSTATE_BUFPOST = 208; /* looking for SOS/EOI in jpeg_finish_output */ | 163 static const int DSTATE_BUFPOST = 208; /* looking for SOS/EOI in jpeg_finish_output */ |
158 static final int DSTATE_RDCOEFS = 209; /* reading file in jpeg_read_coefficients */ | 164 static const int DSTATE_RDCOEFS = 209; /* reading file in jpeg_read_coefficients */ |
159 static final int DSTATE_STOPPING = 210; /* looking for EOI in jpeg_finish_decompress */ | 165 static const int DSTATE_STOPPING = 210; /* looking for EOI in jpeg_finish_decompress */ |
160 | 166 |
161 static final int JPEG_REACHED_SOS = 1; /* Reached start of new scan */ | 167 static const int JPEG_REACHED_SOS = 1; /* Reached start of new scan */ |
162 static final int JPEG_REACHED_EOI = 2; /* Reached end of image */ | 168 static const int JPEG_REACHED_EOI = 2; /* Reached end of image */ |
163 static final int JPEG_ROW_COMPLETED = 3; /* Completed one iMCU row */ | 169 static const int JPEG_ROW_COMPLETED = 3; /* Completed one iMCU row */ |
164 static final int JPEG_SCAN_COMPLETED = 4; /* Completed last iMCU row of a scan */ | 170 static const int JPEG_SCAN_COMPLETED = 4; /* Completed last iMCU row of a scan */ |
165 | 171 |
166 static final int JPEG_SUSPENDED = 0; /* Suspended due to lack of input data */ | 172 static const int JPEG_SUSPENDED = 0; /* Suspended due to lack of input data */ |
167 static final int JPEG_HEADER_OK = 1; /* Found valid image datastream */ | 173 static const int JPEG_HEADER_OK = 1; /* Found valid image datastream */ |
168 static final int JPEG_HEADER_TABLES_ONLY = 2; /* Found valid table-specs-only datastream */ | 174 static const int JPEG_HEADER_TABLES_ONLY = 2; /* Found valid table-specs-only datastream */ |
169 | 175 |
170 /* Function pointers */ | 176 /* Function pointers */ |
171 static final int DECOMPRESS_DATA = 0; | 177 static const int DECOMPRESS_DATA = 0; |
172 static final int DECOMPRESS_SMOOTH_DATA = 1; | 178 static const int DECOMPRESS_SMOOTH_DATA = 1; |
173 static final int DECOMPRESS_ONEPASS = 2; | 179 static const int DECOMPRESS_ONEPASS = 2; |
174 | 180 |
175 static final int CONSUME_DATA = 0; | 181 static const int CONSUME_DATA = 0; |
176 static final int DUMMY_CONSUME_DATA = 1; | 182 static const int DUMMY_CONSUME_DATA = 1; |
177 | 183 |
178 static final int PROCESS_DATA_SIMPLE_MAIN = 0; | 184 static const int PROCESS_DATA_SIMPLE_MAIN = 0; |
179 static final int PROCESS_DATA_CONTEXT_MAIN = 1; | 185 static const int PROCESS_DATA_CONTEXT_MAIN = 1; |
180 static final int PROCESS_DATA_CRANK_POST = 2; | 186 static const int PROCESS_DATA_CRANK_POST = 2; |
181 | 187 |
182 static final int POST_PROCESS_1PASS = 0; | 188 static const int POST_PROCESS_1PASS = 0; |
183 static final int POST_PROCESS_DATA_UPSAMPLE = 1; | 189 static const int POST_PROCESS_DATA_UPSAMPLE = 1; |
184 | 190 |
185 static final int NULL_CONVERT = 0; | 191 static const int NULL_CONVERT = 0; |
186 static final int GRAYSCALE_CONVERT = 1; | 192 static const int GRAYSCALE_CONVERT = 1; |
187 static final int YCC_RGB_CONVERT = 2; | 193 static const int YCC_RGB_CONVERT = 2; |
188 static final int GRAY_RGB_CONVERT = 3; | 194 static const int GRAY_RGB_CONVERT = 3; |
189 static final int YCCK_CMYK_CONVERT = 4; | 195 static const int YCCK_CMYK_CONVERT = 4; |
190 | 196 |
191 static final int NOOP_UPSAMPLE = 0; | 197 static const int NOOP_UPSAMPLE = 0; |
192 static final int FULLSIZE_UPSAMPLE = 1; | 198 static const int FULLSIZE_UPSAMPLE = 1; |
193 static final int H2V1_FANCY_UPSAMPLE = 2; | 199 static const int H2V1_FANCY_UPSAMPLE = 2; |
194 static final int H2V1_UPSAMPLE = 3; | 200 static const int H2V1_UPSAMPLE = 3; |
195 static final int H2V2_FANCY_UPSAMPLE = 4; | 201 static const int H2V2_FANCY_UPSAMPLE = 4; |
196 static final int H2V2_UPSAMPLE = 5; | 202 static const int H2V2_UPSAMPLE = 5; |
197 static final int INT_UPSAMPLE = 6; | 203 static const int INT_UPSAMPLE = 6; |
198 | 204 |
199 static final int INPUT_CONSUME_INPUT = 0; | 205 static const int INPUT_CONSUME_INPUT = 0; |
200 static final int COEF_CONSUME_INPUT = 1; | 206 static const int COEF_CONSUME_INPUT = 1; |
201 | 207 |
202 static int extend_test[] = /* entry n is 2**(n-1) */ | 208 static int extend_test[] = /* entry n is 2**(n-1) */ |
203 { | 209 [ |
204 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, | 210 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, |
205 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 | 211 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 |
206 }; | 212 ]; |
207 | 213 |
208 static int extend_offset[] = /* entry n is (-1 << n) + 1 */ | 214 static int extend_offset[] = /* entry n is (-1 << n) + 1 */ |
209 { | 215 [ |
210 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, | 216 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, |
211 ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, | 217 ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, |
212 ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, | 218 ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, |
213 ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 | 219 ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 |
214 }; | 220 ]; |
215 | 221 |
216 static int jpeg_natural_order[] = { | 222 static int jpeg_natural_order[] = [ |
217 0, 1, 8, 16, 9, 2, 3, 10, | 223 0, 1, 8, 16, 9, 2, 3, 10, |
218 17, 24, 32, 25, 18, 11, 4, 5, | 224 17, 24, 32, 25, 18, 11, 4, 5, |
219 12, 19, 26, 33, 40, 48, 41, 34, | 225 12, 19, 26, 33, 40, 48, 41, 34, |
220 27, 20, 13, 6, 7, 14, 21, 28, | 226 27, 20, 13, 6, 7, 14, 21, 28, |
221 35, 42, 49, 56, 57, 50, 43, 36, | 227 35, 42, 49, 56, 57, 50, 43, 36, |
222 29, 22, 15, 23, 30, 37, 44, 51, | 228 29, 22, 15, 23, 30, 37, 44, 51, |
223 58, 59, 52, 45, 38, 31, 39, 46, | 229 58, 59, 52, 45, 38, 31, 39, 46, |
224 53, 60, 61, 54, 47, 55, 62, 63, | 230 53, 60, 61, 54, 47, 55, 62, 63, |
225 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ | 231 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ |
226 63, 63, 63, 63, 63, 63, 63, 63 | 232 63, 63, 63, 63, 63, 63, 63, 63 |
227 }; | 233 ]; |
228 | 234 |
229 static final class JQUANT_TBL { | 235 static final class JQUANT_TBL { |
230 /* This array gives the coefficient quantizers in natural array order | 236 /* This array gives the coefficient quantizers in natural array order |
231 * (not the zigzag order in which they are stored in a JPEG DQT marker). | 237 * (not the zigzag order in which they are stored in a JPEG DQT marker). |
232 * CAUTION: IJG versions prior to v6a kept this array in zigzag order. | 238 * CAUTION: IJG versions prior to v6a kept this array in zigzag order. |
233 */ | 239 */ |
234 short[] quantval = new short[DCTSIZE2]; /* quantization step for each coefficient */ | 240 short[DCTSIZE2] quantval;// = new short[DCTSIZE2]; /* quantization step for each coefficient */ |
235 /* 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 |
236 * 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. |
237 * 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. |
238 * (See jpeg_suppress_tables for an example.) | 244 * (See jpeg_suppress_tables for an example.) |
239 */ | 245 */ |
240 bool sent_table; /* true when table has been output */ | 246 bool sent_table; /* true when table has been output */ |
241 } | 247 } |
242 | 248 |
243 static final class JHUFF_TBL { | 249 static final class JHUFF_TBL { |
244 /* 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 */ |
245 byte[] 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 */ |
246 /* length k bits; bits[0] is unused */ | 252 /* length k bits; bits[0] is unused */ |
247 byte[] huffval = new byte[256]; /* The symbols, in order of incr code length */ | 253 byte[256] huffval;// = new byte[256]; /* The symbols, in order of incr code length */ |
248 /* 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 |
249 * 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. |
250 * 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. |
251 * (See jpeg_suppress_tables for an example.) | 257 * (See jpeg_suppress_tables for an example.) |
252 */ | 258 */ |
253 bool sent_table; /* true when table has been output */ | 259 bool sent_table; /* true when table has been output */ |
254 } | 260 } |
255 | 261 |
256 static final class bitread_perm_state { /* Bitreading state saved across MCUs */ | 262 static final class bitread_perm_state { /* Bitreading state saved across MCUs */ |
257 int get_buffer; /* current bit-extraction buffer */ | 263 int get_buffer; /* current bit-extraction buffer */ |
258 int bits_left; /* # of unused bits in it */ | 264 int bits_left; /* # of unused bits in it */ |
259 } | 265 } |
260 | 266 |
261 static final class bitread_working_state { /* Bitreading working state within an MCU */ | 267 static final class bitread_working_state { /* Bitreading working state within an MCU */ |
262 /* Current data source location */ | 268 /* Current data source location */ |
263 /* We need a copy, rather than munging the original, in case of suspension */ | 269 /* We need a copy, rather than munging the original, in case of suspension */ |
264 byte[] buffer; /* => next byte to read from source */ | 270 byte[] buffer; /* => next byte to read from source */ |
265 int bytes_offset; | 271 int bytes_offset; |
269 */ | 275 */ |
270 int get_buffer; /* current bit-extraction buffer */ | 276 int get_buffer; /* current bit-extraction buffer */ |
271 int bits_left; /* # of unused bits in it */ | 277 int bits_left; /* # of unused bits in it */ |
272 /* Pointer needed by jpeg_fill_bit_buffer. */ | 278 /* Pointer needed by jpeg_fill_bit_buffer. */ |
273 jpeg_decompress_struct cinfo; /* back link to decompress master record */ | 279 jpeg_decompress_struct cinfo; /* back link to decompress master record */ |
274 } | 280 } |
275 | 281 |
276 static final class savable_state { | 282 static final class savable_state { |
277 int EOBRUN; //Note that this is only used in the progressive case | 283 int EOBRUN; //Note that this is only used in the progressive case |
278 int[] last_dc_val = new int[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ | 284 int[MAX_COMPS_IN_SCAN] last_dc_val;// = new int[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ |
279 } | 285 } |
280 | 286 |
281 static final class d_derived_tbl { | 287 static final class d_derived_tbl { |
282 /* Basic tables: (element [0] of each array is unused) */ | 288 /* Basic tables: (element [0] of each array is unused) */ |
283 int[] maxcode = new int[18]; /* largest code of length k (-1 if none) */ | 289 int[18] maxcode;// = new int[18]; /* largest code of length k (-1 if none) */ |
284 /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */ | 290 /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */ |
285 int[] valoffset = new int[17]; /* huffval[] offset for codes of length k */ | 291 int[17] valoffset;// = new int[17]; /* huffval[] offset for codes of length k */ |
286 /* valoffset[k] = huffval[] index of 1st symbol of code length k, less | 292 /* valoffset[k] = huffval[] index of 1st symbol of code length k, less |
287 * the smallest code of length k; so given a code of length k, the | 293 * the smallest code of length k; so given a code of length k, the |
288 * corresponding symbol is huffval[code + valoffset[k]] | 294 * corresponding symbol is huffval[code + valoffset[k]] |
289 */ | 295 */ |
290 | 296 |
294 /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of | 300 /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of |
295 * the input data stream. If the next Huffman code is no more | 301 * the input data stream. If the next Huffman code is no more |
296 * than HUFF_LOOKAHEAD bits long, we can obtain its length and | 302 * than HUFF_LOOKAHEAD bits long, we can obtain its length and |
297 * the corresponding symbol directly from these tables. | 303 * the corresponding symbol directly from these tables. |
298 */ | 304 */ |
299 int[] look_nbits = new int[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */ | 305 int[1<<HUFF_LOOKAHEAD] look_nbits;// = new int[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */ |
300 byte[] look_sym = new byte[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */ | 306 byte[1<<HUFF_LOOKAHEAD] look_sym;// = new byte[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */ |
301 } | 307 } |
302 | 308 |
303 static final class jpeg_d_coef_controller { | 309 static final class jpeg_d_coef_controller { |
304 int consume_data; | 310 int consume_data; |
305 int decompress_data; | 311 int decompress_data; |
306 | 312 |
307 /* Pointer to array of coefficient virtual arrays, or null if none */ | 313 /* Pointer to array of coefficient virtual arrays, or null if none */ |
308 short[][][] coef_arrays; | 314 short[][][] coef_arrays; |
309 | 315 |
310 /* These variables keep track of the current location of the input side. */ | 316 /* These variables keep track of the current location of the input side. */ |
311 /* cinfo.input_iMCU_row is also used for this. */ | 317 /* cinfo.input_iMCU_row is also used for this. */ |
312 int MCU_ctr; /* counts MCUs processed in current row */ | 318 int MCU_ctr; /* counts MCUs processed in current row */ |
313 int MCU_vert_offset; /* counts MCU rows within iMCU row */ | 319 int MCU_vert_offset; /* counts MCU rows within iMCU row */ |
314 int MCU_rows_per_iMCU_row; /* number of such rows needed */ | 320 int MCU_rows_per_iMCU_row; /* number of such rows needed */ |
322 * this is to keep the module interfaces unchanged when a large coefficient | 328 * this is to keep the module interfaces unchanged when a large coefficient |
323 * buffer is necessary.) | 329 * buffer is necessary.) |
324 * In multi-pass modes, this array points to the current MCU's blocks | 330 * In multi-pass modes, this array points to the current MCU's blocks |
325 * within the virtual arrays; it is used only by the input side. | 331 * within the virtual arrays; it is used only by the input side. |
326 */ | 332 */ |
327 short[][] MCU_buffer = new short[D_MAX_BLOCKS_IN_MCU][]; | 333 short[][D_MAX_BLOCKS_IN_MCU] MCU_buffer;// = new short[D_MAX_BLOCKS_IN_MCU][]; |
328 | 334 |
329 /* In multi-pass modes, we need a virtual block array for each component. */ | 335 /* In multi-pass modes, we need a virtual block array for each component. */ |
330 short[][][][] whole_image = new short[MAX_COMPONENTS][][][]; | 336 short[][][][MAX_COMPONENTS] whole_image;// = new short[MAX_COMPONENTS][][][]; |
331 | 337 |
332 /* When doing block smoothing, we latch coefficient Al values here */ | 338 /* When doing block smoothing, we latch coefficient Al values here */ |
333 int[] coef_bits_latch; | 339 int[] coef_bits_latch; |
334 | 340 |
335 short[] workspace; | 341 short[] workspace; |
336 | 342 |
337 void start_input_pass (jpeg_decompress_struct cinfo) { | 343 void start_input_pass (jpeg_decompress_struct cinfo) { |
338 cinfo.input_iMCU_row = 0; | 344 cinfo.input_iMCU_row = 0; |
339 start_iMCU_row(cinfo); | 345 start_iMCU_row(cinfo); |
340 } | 346 } |
341 | 347 |
342 /* Reset within-iMCU-row counters for a new row (input side) */ | 348 /* Reset within-iMCU-row counters for a new row (input side) */ |
343 void start_iMCU_row (jpeg_decompress_struct cinfo) { | 349 void start_iMCU_row (jpeg_decompress_struct cinfo) { |
344 jpeg_d_coef_controller coef = cinfo.coef; | 350 jpeg_d_coef_controller coef = cinfo.coef; |
345 | 351 |
346 /* In an interleaved scan, an MCU row is the same as an iMCU row. | 352 /* In an interleaved scan, an MCU row is the same as an iMCU row. |
357 } | 363 } |
358 | 364 |
359 coef.MCU_ctr = 0; | 365 coef.MCU_ctr = 0; |
360 coef.MCU_vert_offset = 0; | 366 coef.MCU_vert_offset = 0; |
361 } | 367 } |
362 | 368 |
363 } | 369 } |
364 | 370 |
365 static abstract class jpeg_entropy_decoder { | 371 static abstract class jpeg_entropy_decoder { |
366 abstract void start_pass (jpeg_decompress_struct cinfo); | 372 abstract void start_pass (jpeg_decompress_struct cinfo); |
367 abstract bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data); | 373 abstract bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data); |
368 | 374 |
369 /* This is here to share code between baseline and progressive decoders; */ | 375 /* This is here to share code between baseline and progressive decoders; */ |
370 /* other modules probably should not use it */ | 376 /* other modules probably should not use it */ |
371 bool insufficient_data; /* set true after emitting warning */ | 377 bool insufficient_data; /* set true after emitting warning */ |
372 | 378 |
373 bitread_working_state br_state_local = new bitread_working_state(); | 379 bitread_working_state br_state_local; |
374 savable_state state_local = new savable_state(); | 380 savable_state state_local; |
375 } | 381 public this(){ |
382 br_state_local = new bitread_working_state(); | |
383 state_local = new savable_state(); | |
384 } | |
385 } | |
376 | 386 |
377 static final class huff_entropy_decoder : jpeg_entropy_decoder { | 387 static final class huff_entropy_decoder : jpeg_entropy_decoder { |
378 bitread_perm_state bitstate = new bitread_perm_state(); /* Bit buffer at start of MCU */ | 388 bitread_perm_state bitstate;// = new bitread_perm_state(); /* Bit buffer at start of MCU */ |
379 savable_state saved = new savable_state(); /* Other state at start of MCU */ | 389 savable_state saved;// = new savable_state(); /* Other state at start of MCU */ |
380 | 390 |
381 /* These fields are NOT loaded into local working state. */ | 391 /* These fields are NOT loaded into local working state. */ |
382 int restarts_to_go; /* MCUs left in this restart interval */ | 392 int restarts_to_go; /* MCUs left in this restart interval */ |
383 | 393 |
384 /* Pointers to derived tables (these workspaces have image lifespan) */ | 394 /* Pointers to derived tables (these workspaces have image lifespan) */ |
385 d_derived_tbl[] dc_derived_tbls = new d_derived_tbl[NUM_HUFF_TBLS]; | 395 d_derived_tbl[NUM_HUFF_TBLS] dc_derived_tbls;// = new d_derived_tbl[NUM_HUFF_TBLS]; |
386 d_derived_tbl[] ac_derived_tbls = new d_derived_tbl[NUM_HUFF_TBLS]; | 396 d_derived_tbl[NUM_HUFF_TBLS] ac_derived_tbls;// = new d_derived_tbl[NUM_HUFF_TBLS]; |
387 | 397 |
388 /* Precalculated info set up by start_pass for use in decode_mcu: */ | 398 /* Precalculated info set up by start_pass for use in decode_mcu: */ |
389 | 399 |
390 /* Pointers to derived tables to be used for each block within an MCU */ | 400 /* Pointers to derived tables to be used for each block within an MCU */ |
391 d_derived_tbl[] dc_cur_tbls = new d_derived_tbl[D_MAX_BLOCKS_IN_MCU]; | 401 d_derived_tbl[D_MAX_BLOCKS_IN_MCU] dc_cur_tbls;// = new d_derived_tbl[D_MAX_BLOCKS_IN_MCU]; |
392 d_derived_tbl[] ac_cur_tbls = new d_derived_tbl[D_MAX_BLOCKS_IN_MCU]; | 402 d_derived_tbl[D_MAX_BLOCKS_IN_MCU] ac_cur_tbls;// = new d_derived_tbl[D_MAX_BLOCKS_IN_MCU]; |
393 /* Whether we care about the DC and AC coefficient values for each block */ | 403 /* Whether we care about the DC and AC coefficient values for each block */ |
394 bool[] dc_needed = new bool[D_MAX_BLOCKS_IN_MCU]; | 404 bool[D_MAX_BLOCKS_IN_MCU] dc_needed;// = new bool[D_MAX_BLOCKS_IN_MCU]; |
395 bool[] ac_needed = new bool[D_MAX_BLOCKS_IN_MCU]; | 405 bool[D_MAX_BLOCKS_IN_MCU] ac_needed;// = new bool[D_MAX_BLOCKS_IN_MCU]; |
396 | 406 |
397 void start_pass (jpeg_decompress_struct cinfo) { | 407 public this(){ |
408 bitstate = new bitread_perm_state(); /* Bit buffer at start of MCU */ | |
409 saved = new savable_state(); /* Other state at start of MCU */ | |
410 } | |
411 | |
412 override void start_pass (jpeg_decompress_struct cinfo) { | |
398 start_pass_huff_decoder(cinfo); | 413 start_pass_huff_decoder(cinfo); |
399 } | 414 } |
400 | 415 |
401 bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data) { | 416 override bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data) { |
402 huff_entropy_decoder entropy = this; | 417 huff_entropy_decoder entropy = this; |
403 int blkn; | 418 int blkn; |
404 // BITREAD_STATE_VARS; | 419 // BITREAD_STATE_VARS; |
405 int get_buffer; | 420 int get_buffer; |
406 int bits_left; | 421 int bits_left; |
422 if (! entropy.insufficient_data) { | 437 if (! entropy.insufficient_data) { |
423 | 438 |
424 /* Load up working state */ | 439 /* Load up working state */ |
425 // BITREAD_LOAD_STATE(cinfo,entropy.bitstate); | 440 // BITREAD_LOAD_STATE(cinfo,entropy.bitstate); |
426 br_state.cinfo = cinfo; | 441 br_state.cinfo = cinfo; |
427 br_state.buffer = cinfo.buffer; | 442 br_state.buffer = cinfo.buffer; |
428 br_state.bytes_in_buffer = cinfo.bytes_in_buffer; | 443 br_state.bytes_in_buffer = cinfo.bytes_in_buffer; |
429 br_state.bytes_offset = cinfo.bytes_offset; | 444 br_state.bytes_offset = cinfo.bytes_offset; |
430 get_buffer = entropy.bitstate.get_buffer; | 445 get_buffer = entropy.bitstate.get_buffer; |
431 bits_left = entropy.bitstate.bits_left; | 446 bits_left = entropy.bitstate.bits_left; |
432 | 447 |
433 // ASSIGN_STATE(state, entropy.saved); | 448 // ASSIGN_STATE(state, entropy.saved); |
434 state.last_dc_val[0] = entropy.saved.last_dc_val[0]; | 449 state.last_dc_val[0] = entropy.saved.last_dc_val[0]; |
435 state.last_dc_val[1] = entropy.saved.last_dc_val[1]; | 450 state.last_dc_val[1] = entropy.saved.last_dc_val[1]; |
436 state.last_dc_val[2] = entropy.saved.last_dc_val[2]; | 451 state.last_dc_val[2] = entropy.saved.last_dc_val[2]; |
437 state.last_dc_val[3] = entropy.saved.last_dc_val[3]; | 452 state.last_dc_val[3] = entropy.saved.last_dc_val[3]; |
464 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 479 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
465 } | 480 } |
466 } | 481 } |
467 // look = PEEK_BITS(HUFF_LOOKAHEAD); | 482 // look = PEEK_BITS(HUFF_LOOKAHEAD); |
468 if (nb !is 1) { | 483 if (nb !is 1) { |
469 look = (( (get_buffer >> (bits_left - cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1)); | 484 look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); |
470 if ((nb = dctbl.look_nbits[look]) !is 0) { | 485 if ((nb = dctbl.look_nbits[look]) !is 0) { |
471 // DROP_BITS(nb); | 486 // DROP_BITS(nb); |
472 bits_left -= nb; | 487 bits_left -= nb; |
473 s = dctbl.look_sym[look] & 0xFF; | 488 s = dctbl.look_sym[look] & 0xFF; |
474 } else { | 489 } else { |
487 { | 502 { |
488 if (bits_left < (s)) { | 503 if (bits_left < (s)) { |
489 if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) { | 504 if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) { |
490 return false; | 505 return false; |
491 } | 506 } |
492 get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; | 507 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
493 } | 508 } |
494 } | 509 } |
495 // r = GET_BITS(s); | 510 // r = GET_BITS(s); |
496 r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1)); | 511 r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1)); |
497 // s = HUFF_EXTEND(r, s); | 512 // s = HUFF_EXTEND(r, s); |
510 if (entropy.ac_needed[blkn]) { | 525 if (entropy.ac_needed[blkn]) { |
511 | 526 |
512 /* Section F.2.2.2: decode the AC coefficients */ | 527 /* Section F.2.2.2: decode the AC coefficients */ |
513 /* Since zeroes are skipped, output area must be cleared beforehand */ | 528 /* Since zeroes are skipped, output area must be cleared beforehand */ |
514 for (k = 1; k < DCTSIZE2; k++) { | 529 for (k = 1; k < DCTSIZE2; k++) { |
515 // HUFF_DECODE(s, br_state, actbl, return FALSE, label2); | 530 // HUFF_DECODE(s, br_state, actbl, return FALSE, label2); |
516 { | 531 { |
517 int nb = 0, look; | 532 int nb = 0, look; |
518 if (bits_left < HUFF_LOOKAHEAD) { | 533 if (bits_left < HUFF_LOOKAHEAD) { |
519 if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) { | 534 if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left, 0)) { |
520 return false; | 535 return false; |
521 } | 536 } |
522 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 537 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
523 if (bits_left < HUFF_LOOKAHEAD) { | 538 if (bits_left < HUFF_LOOKAHEAD) { |
524 nb = 1; | 539 nb = 1; |
525 // goto slowlabel; | 540 // goto slowlabel; |
526 if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb)) < 0) { | 541 if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,actbl,nb)) < 0) { |
527 return false; | 542 return false; |
528 } | 543 } |
529 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 544 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
530 } | 545 } |
531 } | 546 } |
532 if (nb !is 1) { | 547 if (nb !is 1) { |
533 // look = PEEK_BITS(HUFF_LOOKAHEAD); | 548 // look = PEEK_BITS(HUFF_LOOKAHEAD); |
534 look = (( (get_buffer >> (bits_left - cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1)); | 549 look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); |
535 if ((nb = actbl.look_nbits[look]) !is 0) { | 550 if ((nb = actbl.look_nbits[look]) !is 0) { |
536 // DROP_BITS(nb); | 551 // DROP_BITS(nb); |
537 bits_left -= (nb); | 552 bits_left -= (nb); |
538 s = actbl.look_sym[look] & 0xFF; | 553 s = actbl.look_sym[look] & 0xFF; |
539 } else { | 554 } else { |
543 return false; | 558 return false; |
544 } | 559 } |
545 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 560 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
546 } | 561 } |
547 } | 562 } |
548 } | 563 } |
549 r = s >> 4; | 564 r = s >> 4; |
550 s &= 15; | 565 s &= 15; |
551 | 566 |
552 if (s !is 0) { | 567 if (s !is 0) { |
553 k += r; | 568 k += r; |
554 // CHECK_BIT_BUFFER(br_state, s, return FALSE); | 569 // CHECK_BIT_BUFFER(br_state, s, return FALSE); |
555 { | 570 { |
556 if (bits_left < (s)) { | 571 if (bits_left < (s)) { |
557 if (!jpeg_fill_bit_buffer(br_state, get_buffer, bits_left, s)) { | 572 if (!jpeg_fill_bit_buffer(br_state, get_buffer, bits_left, s)) { |
558 return false; | 573 return false; |
559 } | 574 } |
560 get_buffer = (br_state).get_buffer; | 575 get_buffer = br_state.get_buffer; |
561 bits_left = (br_state).bits_left; | 576 bits_left = br_state.bits_left; |
562 } | 577 } |
563 } | 578 } |
564 // r = GET_BITS(s); | 579 // r = GET_BITS(s); |
565 r = (((get_buffer >> (bits_left -= (s)))) & ((1 << (s)) - 1)); | 580 r = (((get_buffer >> (bits_left -= (s)))) & ((1 << (s)) - 1)); |
566 // s = HUFF_EXTEND(r, s); | 581 // s = HUFF_EXTEND(r, s); |
602 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 617 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
603 } | 618 } |
604 } | 619 } |
605 if (nb !is 1) { | 620 if (nb !is 1) { |
606 // look = PEEK_BITS(HUFF_LOOKAHEAD); | 621 // look = PEEK_BITS(HUFF_LOOKAHEAD); |
607 look = (( (get_buffer >> (bits_left - cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1)); | 622 look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); |
608 if ((nb = actbl.look_nbits[look]) !is 0) { | 623 if ((nb = actbl.look_nbits[look]) !is 0) { |
609 // DROP_BITS(nb); | 624 // DROP_BITS(nb); |
610 bits_left -= (nb); | 625 bits_left -= (nb); |
611 s = actbl.look_sym[look] & 0xFF; | 626 s = actbl.look_sym[look] & 0xFF; |
612 } else { | 627 } else { |
616 return false; | 631 return false; |
617 } | 632 } |
618 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 633 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
619 } | 634 } |
620 } | 635 } |
621 } | 636 } |
622 r = s >> 4; | 637 r = s >> 4; |
623 s &= 15; | 638 s &= 15; |
624 | 639 |
625 if (s !is 0) { | 640 if (s !is 0) { |
626 k += r; | 641 k += r; |
627 // CHECK_BIT_BUFFER(br_state, s, return FALSE); | 642 // CHECK_BIT_BUFFER(br_state, s, return FALSE); |
628 { | 643 { |
629 if (bits_left < (s)) { | 644 if (bits_left < (s)) { |
630 if (!jpeg_fill_bit_buffer((br_state),get_buffer,bits_left,s)) { | 645 if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) { |
631 return false; | 646 return false; |
632 } | 647 } |
633 get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; | 648 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
634 } | 649 } |
635 } | 650 } |
636 // DROP_BITS(s); | 651 // DROP_BITS(s); |
637 bits_left -= s; | 652 bits_left -= s; |
638 } else { | 653 } else { |
713 entropy.insufficient_data = false; | 728 entropy.insufficient_data = false; |
714 | 729 |
715 /* Initialize restart counter */ | 730 /* Initialize restart counter */ |
716 entropy.restarts_to_go = cinfo.restart_interval; | 731 entropy.restarts_to_go = cinfo.restart_interval; |
717 } | 732 } |
718 | 733 |
719 bool process_restart (jpeg_decompress_struct cinfo) { | 734 bool process_restart (jpeg_decompress_struct cinfo) { |
720 huff_entropy_decoder entropy = this; | 735 huff_entropy_decoder entropy = this; |
721 int ci; | 736 int ci; |
722 | 737 |
723 /* Throw away any unused bits remaining in bit buffer; */ | 738 /* Throw away any unused bits remaining in bit buffer; */ |
745 entropy.insufficient_data = false; | 760 entropy.insufficient_data = false; |
746 | 761 |
747 return true; | 762 return true; |
748 } | 763 } |
749 } | 764 } |
750 | 765 |
751 static final class phuff_entropy_decoder : jpeg_entropy_decoder { | 766 static final class phuff_entropy_decoder : jpeg_entropy_decoder { |
752 | 767 |
753 /* These fields are loaded into local variables at start of each MCU. | 768 /* These fields are loaded into local variables at start of each MCU. |
754 * In case of suspension, we exit WITHOUT updating them. | 769 * In case of suspension, we exit WITHOUT updating them. |
755 */ | 770 */ |
756 bitread_perm_state bitstate = new bitread_perm_state(); /* Bit buffer at start of MCU */ | 771 bitread_perm_state bitstate;// = new bitread_perm_state(); /* Bit buffer at start of MCU */ |
757 savable_state saved = new savable_state(); /* Other state at start of MCU */ | 772 savable_state saved;// = new savable_state(); /* Other state at start of MCU */ |
758 | 773 |
759 /* These fields are NOT loaded into local working state. */ | 774 /* These fields are NOT loaded into local working state. */ |
760 int restarts_to_go; /* MCUs left in this restart interval */ | 775 int restarts_to_go; /* MCUs left in this restart interval */ |
761 | 776 |
762 /* Pointers to derived tables (these workspaces have image lifespan) */ | 777 /* Pointers to derived tables (these workspaces have image lifespan) */ |
763 d_derived_tbl[] derived_tbls = new d_derived_tbl[NUM_HUFF_TBLS]; | 778 d_derived_tbl[NUM_HUFF_TBLS] derived_tbls;// = new d_derived_tbl[NUM_HUFF_TBLS]; |
764 | 779 |
765 d_derived_tbl ac_derived_tbl; /* active table during an AC scan */ | 780 d_derived_tbl ac_derived_tbl; /* active table during an AC scan */ |
766 | 781 |
767 int[] newnz_pos = new int[DCTSIZE2]; | 782 int[DCTSIZE2] newnz_pos;// = new int[DCTSIZE2]; |
768 | 783 |
769 void start_pass (jpeg_decompress_struct cinfo) { | 784 public this(){ |
785 bitstate = new bitread_perm_state(); /* Bit buffer at start of MCU */ | |
786 saved = new savable_state(); /* Other state at start of MCU */ | |
787 } | |
788 | |
789 override void start_pass (jpeg_decompress_struct cinfo) { | |
770 start_pass_phuff_decoder(cinfo); | 790 start_pass_phuff_decoder(cinfo); |
771 } | 791 } |
772 | 792 |
773 bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data) { | 793 override bool decode_mcu (jpeg_decompress_struct cinfo, short[][] MCU_data) { |
774 bool is_DC_band = (cinfo.Ss is 0); | 794 bool is_DC_band = (cinfo.Ss is 0); |
775 if (cinfo.Ah is 0) { | 795 if (cinfo.Ah is 0) { |
776 if (is_DC_band) | 796 if (is_DC_band) |
777 return decode_mcu_DC_first(cinfo, MCU_data); | 797 return decode_mcu_DC_first(cinfo, MCU_data); |
778 else | 798 else |
782 return decode_mcu_DC_refine(cinfo, MCU_data); | 802 return decode_mcu_DC_refine(cinfo, MCU_data); |
783 else | 803 else |
784 return decode_mcu_AC_refine(cinfo, MCU_data); | 804 return decode_mcu_AC_refine(cinfo, MCU_data); |
785 } | 805 } |
786 } | 806 } |
787 | 807 |
788 bool decode_mcu_DC_refine (jpeg_decompress_struct cinfo, short[][] MCU_data) { | 808 bool decode_mcu_DC_refine (jpeg_decompress_struct cinfo, short[][] MCU_data) { |
789 phuff_entropy_decoder entropy = this; | 809 phuff_entropy_decoder entropy = this; |
790 int p1 = 1 << cinfo.Al; /* 1 in the bit position being coded */ | 810 int p1 = 1 << cinfo.Al; /* 1 in the bit position being coded */ |
791 int blkn; | 811 int blkn; |
792 short[] block; | 812 short[] block; |
793 // BITREAD_STATE_VARS; | 813 // BITREAD_STATE_VARS; |
794 int get_buffer; | 814 int get_buffer; |
795 int bits_left; | 815 int bits_left; |
796 // bitread_working_state br_state = new bitread_working_state(); | 816 // bitread_working_state br_state = new bitread_working_state(); |
797 bitread_working_state br_state = br_state_local; | 817 bitread_working_state br_state = br_state_local; |
798 | 818 |
799 /* Process restart marker if needed; may have to suspend */ | 819 /* Process restart marker if needed; may have to suspend */ |
800 if (cinfo.restart_interval !is 0) { | 820 if (cinfo.restart_interval !is 0) { |
801 if (entropy.restarts_to_go is 0) | 821 if (entropy.restarts_to_go is 0) |
802 if (! process_restart(cinfo)) | 822 if (! process_restart(cinfo)) |
803 return false; | 823 return false; |
808 */ | 828 */ |
809 | 829 |
810 /* Load up working state */ | 830 /* Load up working state */ |
811 // BITREAD_LOAD_STATE(cinfo,entropy.bitstate); | 831 // BITREAD_LOAD_STATE(cinfo,entropy.bitstate); |
812 br_state.cinfo = cinfo; | 832 br_state.cinfo = cinfo; |
813 br_state.buffer = cinfo.buffer; | 833 br_state.buffer = cinfo.buffer; |
814 br_state.bytes_in_buffer = cinfo.bytes_in_buffer; | 834 br_state.bytes_in_buffer = cinfo.bytes_in_buffer; |
815 br_state.bytes_offset = cinfo.bytes_offset; | 835 br_state.bytes_offset = cinfo.bytes_offset; |
816 get_buffer = entropy.bitstate.get_buffer; | 836 get_buffer = entropy.bitstate.get_buffer; |
817 bits_left = entropy.bitstate.bits_left; | 837 bits_left = entropy.bitstate.bits_left; |
818 | 838 |
819 /* Outer loop handles each block in the MCU */ | 839 /* Outer loop handles each block in the MCU */ |
820 | 840 |
821 for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) { | 841 for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) { |
822 block = MCU_data[blkn]; | 842 block = MCU_data[blkn]; |
823 | 843 |
826 { | 846 { |
827 if (bits_left < (1)) { | 847 if (bits_left < (1)) { |
828 if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) { | 848 if (!jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) { |
829 return false; | 849 return false; |
830 } | 850 } |
831 get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; | 851 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
832 } | 852 } |
833 } | 853 } |
834 // if (GET_BITS(1)) | 854 // if (GET_BITS(1)) |
835 if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) !is 0) | 855 if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) !is 0) |
836 block[0] |= p1; | 856 block[0] |= p1; |
842 cinfo.buffer = br_state.buffer; | 862 cinfo.buffer = br_state.buffer; |
843 cinfo.bytes_in_buffer = br_state.bytes_in_buffer; | 863 cinfo.bytes_in_buffer = br_state.bytes_in_buffer; |
844 cinfo.bytes_offset = br_state.bytes_offset; | 864 cinfo.bytes_offset = br_state.bytes_offset; |
845 entropy.bitstate.get_buffer = get_buffer; | 865 entropy.bitstate.get_buffer = get_buffer; |
846 entropy.bitstate.bits_left = bits_left; | 866 entropy.bitstate.bits_left = bits_left; |
847 | 867 |
848 /* Account for restart interval (no-op if not using restarts) */ | 868 /* Account for restart interval (no-op if not using restarts) */ |
849 entropy.restarts_to_go--; | 869 entropy.restarts_to_go--; |
850 | 870 |
851 return true; | 871 return true; |
852 | 872 |
853 } | 873 } |
854 | 874 |
855 bool decode_mcu_AC_refine (jpeg_decompress_struct cinfo, short[][] MCU_data) { | 875 bool decode_mcu_AC_refine (jpeg_decompress_struct cinfo, short[][] MCU_data) { |
856 phuff_entropy_decoder entropy = this; | 876 phuff_entropy_decoder entropy = this; |
857 int Se = cinfo.Se; | 877 int Se = cinfo.Se; |
858 int p1 = 1 << cinfo.Al; /* 1 in the bit position being coded */ | 878 int p1 = 1 << cinfo.Al; /* 1 in the bit position being coded */ |
859 int m1 = (-1) << cinfo.Al; /* -1 in the bit position being coded */ | 879 int m1 = (-1) << cinfo.Al; /* -1 in the bit position being coded */ |
864 // BITREAD_STATE_VARS; | 884 // BITREAD_STATE_VARS; |
865 int get_buffer; | 885 int get_buffer; |
866 int bits_left; | 886 int bits_left; |
867 // bitread_working_state br_state = new bitread_working_state(); | 887 // bitread_working_state br_state = new bitread_working_state(); |
868 bitread_working_state br_state = br_state_local; | 888 bitread_working_state br_state = br_state_local; |
869 | 889 |
870 d_derived_tbl tbl; | 890 d_derived_tbl tbl; |
871 int num_newnz; | 891 int num_newnz; |
872 int[] newnz_pos = entropy.newnz_pos; | 892 int[] newnz_pos = entropy.newnz_pos; |
873 | 893 |
874 /* Process restart marker if needed; may have to suspend */ | 894 /* Process restart marker if needed; may have to suspend */ |
883 if (! entropy.insufficient_data) { | 903 if (! entropy.insufficient_data) { |
884 | 904 |
885 /* Load up working state */ | 905 /* Load up working state */ |
886 // BITREAD_LOAD_STATE(cinfo,entropy.bitstate); | 906 // BITREAD_LOAD_STATE(cinfo,entropy.bitstate); |
887 br_state.cinfo = cinfo; | 907 br_state.cinfo = cinfo; |
888 br_state.buffer = cinfo.buffer; | 908 br_state.buffer = cinfo.buffer; |
889 br_state.bytes_in_buffer = cinfo.bytes_in_buffer; | 909 br_state.bytes_in_buffer = cinfo.bytes_in_buffer; |
890 br_state.bytes_offset = cinfo.bytes_offset; | 910 br_state.bytes_offset = cinfo.bytes_offset; |
891 get_buffer = entropy.bitstate.get_buffer; | 911 get_buffer = entropy.bitstate.get_buffer; |
892 bits_left = entropy.bitstate.bits_left; | 912 bits_left = entropy.bitstate.bits_left; |
893 | 913 |
894 EOBRUN = entropy.saved.EOBRUN; /* only part of saved state we need */ | 914 EOBRUN = entropy.saved.EOBRUN; /* only part of saved state we need */ |
895 | 915 |
896 /* There is always only one block per MCU */ | 916 /* There is always only one block per MCU */ |
897 block = MCU_data[0]; | 917 block = MCU_data[0]; |
898 tbl = entropy.ac_derived_tbl; | 918 tbl = entropy.ac_derived_tbl; |
921 | 941 |
922 return false; | 942 return false; |
923 } | 943 } |
924 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 944 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
925 if (bits_left < HUFF_LOOKAHEAD) { | 945 if (bits_left < HUFF_LOOKAHEAD) { |
926 nb = 1; | 946 nb = 1; |
927 // goto slowlabel; | 947 // goto slowlabel; |
928 if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) { | 948 if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) { |
929 // failaction; | 949 // failaction; |
930 while (num_newnz > 0) | 950 while (num_newnz > 0) |
931 block[newnz_pos[--num_newnz]] = 0; | 951 block[newnz_pos[--num_newnz]] = 0; |
935 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 955 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
936 } | 956 } |
937 } | 957 } |
938 if (nb !is 1) { | 958 if (nb !is 1) { |
939 // look = PEEK_BITS(HUFF_LOOKAHEAD); | 959 // look = PEEK_BITS(HUFF_LOOKAHEAD); |
940 look = (( (get_buffer >> (bits_left - cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1)); | 960 look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); |
941 if ((nb = tbl.look_nbits[look]) !is 0) { | 961 if ((nb = tbl.look_nbits[look]) !is 0) { |
942 // DROP_BITS(nb); | 962 // DROP_BITS(nb); |
943 bits_left -= nb; | 963 bits_left -= nb; |
944 s = tbl.look_sym[look] & 0xFF; | 964 s = tbl.look_sym[look] & 0xFF; |
945 } else { | 965 } else { |
946 nb = HUFF_LOOKAHEAD+1; | 966 nb = HUFF_LOOKAHEAD+1; |
947 // slowlabel: | 967 // slowlabel: |
948 if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) { | 968 if ((s=jpeg_huff_decode(br_state,get_buffer,bits_left,tbl,nb)) < 0) { |
949 // failaction; | 969 // failaction; |
950 while (num_newnz > 0) | 970 while (num_newnz > 0) |
951 block[newnz_pos[--num_newnz]] = 0; | 971 block[newnz_pos[--num_newnz]] = 0; |
952 | 972 |
953 return false; | 973 return false; |
957 } | 977 } |
958 } | 978 } |
959 r = s >> 4; | 979 r = s >> 4; |
960 s &= 15; | 980 s &= 15; |
961 if (s !is 0) { | 981 if (s !is 0) { |
962 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 */ |
963 // WARNMS(cinfo, JWRN_HUFF_BAD_CODE); | 983 // WARNMS(cinfo, JWRN_HUFF_BAD_CODE); |
964 } | 984 } |
965 // CHECK_BIT_BUFFER(br_state, 1, goto undoit); | 985 // CHECK_BIT_BUFFER(br_state, 1, goto undoit); |
966 { | 986 { |
967 if (bits_left < (1)) { | 987 if (bits_left < (1)) { |
970 while (num_newnz > 0) | 990 while (num_newnz > 0) |
971 block[newnz_pos[--num_newnz]] = 0; | 991 block[newnz_pos[--num_newnz]] = 0; |
972 | 992 |
973 return false; | 993 return false; |
974 } | 994 } |
975 get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; | 995 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
976 } | 996 } |
977 } | 997 } |
978 // if (GET_BITS(1)) | 998 // if (GET_BITS(1)) |
979 if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) !is 0) | 999 if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) !is 0) |
980 s = p1; /* newly nonzero coef is positive */ | 1000 s = p1; /* newly nonzero coef is positive */ |
992 while (num_newnz > 0) | 1012 while (num_newnz > 0) |
993 block[newnz_pos[--num_newnz]] = 0; | 1013 block[newnz_pos[--num_newnz]] = 0; |
994 | 1014 |
995 return false; | 1015 return false; |
996 } | 1016 } |
997 get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; | 1017 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
998 } | 1018 } |
999 } | 1019 } |
1000 // r = GET_BITS(r); | 1020 // r = GET_BITS(r); |
1001 r = (( (get_buffer >> (bits_left -= (r)))) & ((1<<(r))-1)); | 1021 r = (( (get_buffer >> (bits_left -= (r)))) & ((1<<(r))-1)); |
1002 EOBRUN += r; | 1022 EOBRUN += r; |
1021 while (num_newnz > 0) | 1041 while (num_newnz > 0) |
1022 block[newnz_pos[--num_newnz]] = 0; | 1042 block[newnz_pos[--num_newnz]] = 0; |
1023 | 1043 |
1024 return false; | 1044 return false; |
1025 } | 1045 } |
1026 get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; | 1046 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
1027 } | 1047 } |
1028 } | 1048 } |
1029 // if (GET_BITS(1)) { | 1049 // if (GET_BITS(1)) { |
1030 if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) !is 0) { | 1050 if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) !is 0) { |
1031 if ((thiscoef[thiscoef_offset] & p1) is 0) { /* do nothing if already set it */ | 1051 if ((thiscoef[thiscoef_offset] & p1) is 0) { /* do nothing if already set it */ |
1066 if (bits_left < (1)) { | 1086 if (bits_left < (1)) { |
1067 if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) { | 1087 if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,1)) { |
1068 // failaction; | 1088 // failaction; |
1069 while (num_newnz > 0) | 1089 while (num_newnz > 0) |
1070 block[newnz_pos[--num_newnz]] = 0; | 1090 block[newnz_pos[--num_newnz]] = 0; |
1071 | 1091 |
1072 return false; | 1092 return false; |
1073 } | 1093 } |
1074 get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; | 1094 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
1075 } | 1095 } |
1076 } | 1096 } |
1077 // if (GET_BITS(1)) { | 1097 // if (GET_BITS(1)) { |
1078 if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) !is 0) { | 1098 if ((( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)) !is 0) { |
1079 if ((thiscoef[thiscoef_offset] & p1) is 0) { /* do nothing if already changed it */ | 1099 if ((thiscoef[thiscoef_offset] & p1) is 0) { /* do nothing if already changed it */ |
1094 cinfo.buffer = br_state.buffer; | 1114 cinfo.buffer = br_state.buffer; |
1095 cinfo.bytes_in_buffer = br_state.bytes_in_buffer; | 1115 cinfo.bytes_in_buffer = br_state.bytes_in_buffer; |
1096 cinfo.bytes_offset = br_state.bytes_offset; | 1116 cinfo.bytes_offset = br_state.bytes_offset; |
1097 entropy.bitstate.get_buffer = get_buffer; | 1117 entropy.bitstate.get_buffer = get_buffer; |
1098 entropy.bitstate.bits_left = bits_left; | 1118 entropy.bitstate.bits_left = bits_left; |
1099 | 1119 |
1100 entropy.saved.EOBRUN = EOBRUN; /* only part of saved state we need */ | 1120 entropy.saved.EOBRUN = EOBRUN; /* only part of saved state we need */ |
1101 } | 1121 } |
1102 | 1122 |
1103 /* Account for restart interval (no-op if not using restarts) */ | 1123 /* Account for restart interval (no-op if not using restarts) */ |
1104 entropy.restarts_to_go--; | 1124 entropy.restarts_to_go--; |
1110 // while (num_newnz > 0) | 1130 // while (num_newnz > 0) |
1111 // (*block)[newnz_pos[--num_newnz]] = 0; | 1131 // (*block)[newnz_pos[--num_newnz]] = 0; |
1112 // | 1132 // |
1113 // return false; | 1133 // return false; |
1114 | 1134 |
1115 } | 1135 } |
1116 | 1136 |
1117 bool decode_mcu_AC_first (jpeg_decompress_struct cinfo, short[][] MCU_data) { | 1137 bool decode_mcu_AC_first (jpeg_decompress_struct cinfo, short[][] MCU_data) { |
1118 phuff_entropy_decoder entropy = this; | 1138 phuff_entropy_decoder entropy = this; |
1119 int Se = cinfo.Se; | 1139 int Se = cinfo.Se; |
1120 int Al = cinfo.Al; | 1140 int Al = cinfo.Al; |
1121 int s = 0, k, r; | 1141 int s = 0, k, r; |
1124 // BITREAD_STATE_VARS; | 1144 // BITREAD_STATE_VARS; |
1125 int get_buffer; | 1145 int get_buffer; |
1126 int bits_left; | 1146 int bits_left; |
1127 // bitread_working_state br_state = new bitread_working_state(); | 1147 // bitread_working_state br_state = new bitread_working_state(); |
1128 bitread_working_state br_state = br_state_local; | 1148 bitread_working_state br_state = br_state_local; |
1129 | 1149 |
1130 d_derived_tbl tbl; | 1150 d_derived_tbl tbl; |
1131 | 1151 |
1132 /* Process restart marker if needed; may have to suspend */ | 1152 /* Process restart marker if needed; may have to suspend */ |
1133 if (cinfo.restart_interval !is 0) { | 1153 if (cinfo.restart_interval !is 0) { |
1134 if (entropy.restarts_to_go is 0) | 1154 if (entropy.restarts_to_go is 0) |
1151 if (EOBRUN > 0) /* if it's a band of zeroes... */ | 1171 if (EOBRUN > 0) /* if it's a band of zeroes... */ |
1152 EOBRUN--; /* ...process it now (we do nothing) */ | 1172 EOBRUN--; /* ...process it now (we do nothing) */ |
1153 else { | 1173 else { |
1154 // BITREAD_LOAD_STATE(cinfo,entropy.bitstate); | 1174 // BITREAD_LOAD_STATE(cinfo,entropy.bitstate); |
1155 br_state.cinfo = cinfo; | 1175 br_state.cinfo = cinfo; |
1156 br_state.buffer = cinfo.buffer; | 1176 br_state.buffer = cinfo.buffer; |
1157 br_state.bytes_in_buffer = cinfo.bytes_in_buffer; | 1177 br_state.bytes_in_buffer = cinfo.bytes_in_buffer; |
1158 br_state.bytes_offset = cinfo.bytes_offset; | 1178 br_state.bytes_offset = cinfo.bytes_offset; |
1159 get_buffer = entropy.bitstate.get_buffer; | 1179 get_buffer = entropy.bitstate.get_buffer; |
1160 bits_left = entropy.bitstate.bits_left; | 1180 bits_left = entropy.bitstate.bits_left; |
1161 | 1181 |
1162 block = MCU_data[0]; | 1182 block = MCU_data[0]; |
1163 tbl = entropy.ac_derived_tbl; | 1183 tbl = entropy.ac_derived_tbl; |
1164 | 1184 |
1165 for (k = cinfo.Ss; k <= Se; k++) { | 1185 for (k = cinfo.Ss; k <= Se; k++) { |
1166 // HUFF_DECODE(s, br_state, tbl, return FALSE, label2); | 1186 // HUFF_DECODE(s, br_state, tbl, return FALSE, label2); |
1180 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 1200 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
1181 } | 1201 } |
1182 } | 1202 } |
1183 if (nb !is 1) { | 1203 if (nb !is 1) { |
1184 // look = PEEK_BITS(HUFF_LOOKAHEAD); | 1204 // look = PEEK_BITS(HUFF_LOOKAHEAD); |
1185 look = (( (get_buffer >> (bits_left - cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1)); | 1205 look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); |
1186 | 1206 |
1187 if ((nb = tbl.look_nbits[look]) !is 0) { | 1207 if ((nb = tbl.look_nbits[look]) !is 0) { |
1188 // DROP_BITS(nb); | 1208 // DROP_BITS(nb); |
1189 bits_left -= nb; | 1209 bits_left -= nb; |
1190 s = tbl.look_sym[look] & 0xFF; | 1210 s = tbl.look_sym[look] & 0xFF; |
1206 { | 1226 { |
1207 if (bits_left < (s)) { | 1227 if (bits_left < (s)) { |
1208 if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) { | 1228 if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) { |
1209 return false; | 1229 return false; |
1210 } | 1230 } |
1211 get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; | 1231 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
1212 } | 1232 } |
1213 } | 1233 } |
1214 // r = GET_BITS(s); | 1234 // r = GET_BITS(s); |
1215 r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1)); | 1235 r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1)); |
1216 // s = HUFF_EXTEND(r, s); | 1236 // s = HUFF_EXTEND(r, s); |
1220 } else { | 1240 } else { |
1221 if (r is 15) { /* ZRL */ | 1241 if (r is 15) { /* ZRL */ |
1222 k += 15; /* skip 15 zeroes in band */ | 1242 k += 15; /* skip 15 zeroes in band */ |
1223 } else { /* EOBr, run length is 2^r + appended bits */ | 1243 } else { /* EOBr, run length is 2^r + appended bits */ |
1224 EOBRUN = 1 << r; | 1244 EOBRUN = 1 << r; |
1225 if (r !is 0) { /* EOBr, r > 0 */ | 1245 if (r !is 0) { /* EOBr, r > 0 */ |
1226 // CHECK_BIT_BUFFER(br_state, r, return FALSE); | 1246 // CHECK_BIT_BUFFER(br_state, r, return FALSE); |
1227 { | 1247 { |
1228 if (bits_left < (r)) { | 1248 if (bits_left < (r)) { |
1229 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)) { |
1230 return false; | 1250 return false; |
1231 } | 1251 } |
1232 get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; | 1252 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
1233 } | 1253 } |
1234 } | 1254 } |
1235 // r = GET_BITS(r); | 1255 // r = GET_BITS(r); |
1236 r = (( (get_buffer >> (bits_left -= (r)))) & ((1<<(r))-1)); | 1256 r = (( (get_buffer >> (bits_left -= (r)))) & ((1<<(r))-1)); |
1237 EOBRUN += r; | 1257 EOBRUN += r; |
1257 /* Account for restart interval (no-op if not using restarts) */ | 1277 /* Account for restart interval (no-op if not using restarts) */ |
1258 entropy.restarts_to_go--; | 1278 entropy.restarts_to_go--; |
1259 | 1279 |
1260 return true; | 1280 return true; |
1261 } | 1281 } |
1262 | 1282 |
1263 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) { |
1264 phuff_entropy_decoder entropy = this; | 1284 phuff_entropy_decoder entropy = this; |
1265 int Al = cinfo.Al; | 1285 int Al = cinfo.Al; |
1266 int s = 0, r; | 1286 int s = 0, r; |
1267 int blkn, ci; | 1287 int blkn, ci; |
1268 short[] block; | 1288 short[] block; |
1269 // BITREAD_STATE_VARS; | 1289 // BITREAD_STATE_VARS; |
1270 int get_buffer; | 1290 int get_buffer; |
1271 int bits_left; | 1291 int bits_left; |
1272 // bitread_working_state br_state = new bitread_working_state(); | 1292 // bitread_working_state br_state = new bitread_working_state(); |
1273 bitread_working_state br_state = br_state_local; | 1293 bitread_working_state br_state = br_state_local; |
1274 | 1294 |
1275 // savable_state state = new savable_state(); | 1295 // savable_state state = new savable_state(); |
1276 savable_state state = state_local; | 1296 savable_state state = state_local; |
1277 d_derived_tbl tbl; | 1297 d_derived_tbl tbl; |
1278 jpeg_component_info compptr; | 1298 jpeg_component_info compptr; |
1279 | 1299 |
1290 if (! entropy.insufficient_data) { | 1310 if (! entropy.insufficient_data) { |
1291 | 1311 |
1292 /* Load up working state */ | 1312 /* Load up working state */ |
1293 // BITREAD_LOAD_STATE(cinfo,entropy.bitstate); | 1313 // BITREAD_LOAD_STATE(cinfo,entropy.bitstate); |
1294 br_state.cinfo = cinfo; | 1314 br_state.cinfo = cinfo; |
1295 br_state.buffer = cinfo.buffer; | 1315 br_state.buffer = cinfo.buffer; |
1296 br_state.bytes_in_buffer = cinfo.bytes_in_buffer; | 1316 br_state.bytes_in_buffer = cinfo.bytes_in_buffer; |
1297 br_state.bytes_offset = cinfo.bytes_offset; | 1317 br_state.bytes_offset = cinfo.bytes_offset; |
1298 get_buffer = entropy.bitstate.get_buffer; | 1318 get_buffer = entropy.bitstate.get_buffer; |
1299 bits_left = entropy.bitstate.bits_left; | 1319 bits_left = entropy.bitstate.bits_left; |
1300 | 1320 |
1301 // ASSIGN_STATE(state, entropy.saved); | 1321 // ASSIGN_STATE(state, entropy.saved); |
1302 state.EOBRUN = entropy.saved.EOBRUN; | 1322 state.EOBRUN = entropy.saved.EOBRUN; |
1303 state.last_dc_val[0] = entropy.saved.last_dc_val[0]; | 1323 state.last_dc_val[0] = entropy.saved.last_dc_val[0]; |
1304 state.last_dc_val[1] = entropy.saved.last_dc_val[1]; | 1324 state.last_dc_val[1] = entropy.saved.last_dc_val[1]; |
1305 state.last_dc_val[2] = entropy.saved.last_dc_val[2]; | 1325 state.last_dc_val[2] = entropy.saved.last_dc_val[2]; |
1306 state.last_dc_val[3] = entropy.saved.last_dc_val[3]; | 1326 state.last_dc_val[3] = entropy.saved.last_dc_val[3]; |
1307 | 1327 |
1308 /* Outer loop handles each block in the MCU */ | 1328 /* Outer loop handles each block in the MCU */ |
1309 | 1329 |
1310 for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) { | 1330 for (blkn = 0; blkn < cinfo.blocks_in_MCU; blkn++) { |
1311 block = MCU_data[blkn]; | 1331 block = MCU_data[blkn]; |
1312 ci = cinfo.MCU_membership[blkn]; | 1332 ci = cinfo.MCU_membership[blkn]; |
1333 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; | 1353 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
1334 } | 1354 } |
1335 } | 1355 } |
1336 if (nb !is 1) { | 1356 if (nb !is 1) { |
1337 // look = PEEK_BITS(HUFF_LOOKAHEAD); | 1357 // look = PEEK_BITS(HUFF_LOOKAHEAD); |
1338 look = (( (get_buffer >> (bits_left - cast(HUFF_LOOKAHEAD)))) & ((1<<cast(HUFF_LOOKAHEAD))-1)); | 1358 look = (( (get_buffer >> (bits_left - (HUFF_LOOKAHEAD)))) & ((1<<(HUFF_LOOKAHEAD))-1)); |
1339 | 1359 |
1340 if ((nb = tbl.look_nbits[look]) !is 0) { | 1360 if ((nb = tbl.look_nbits[look]) !is 0) { |
1341 // DROP_BITS(nb); | 1361 // DROP_BITS(nb); |
1342 bits_left -= nb; | 1362 bits_left -= nb; |
1343 s = tbl.look_sym[look] & 0xFF; | 1363 s = tbl.look_sym[look] & 0xFF; |
1356 { | 1376 { |
1357 if (bits_left < (s)) { | 1377 if (bits_left < (s)) { |
1358 if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) { | 1378 if (! jpeg_fill_bit_buffer(br_state,get_buffer,bits_left,s)) { |
1359 return false; | 1379 return false; |
1360 } | 1380 } |
1361 get_buffer = (br_state).get_buffer; bits_left = (br_state).bits_left; | 1381 get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; |
1362 } | 1382 } |
1363 } | 1383 } |
1364 // r = GET_BITS(s); | 1384 // r = GET_BITS(s); |
1365 r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1)); | 1385 r = (( (get_buffer >> (bits_left -= (s)))) & ((1<<(s))-1)); |
1366 // s = HUFF_EXTEND(r, s); | 1386 // s = HUFF_EXTEND(r, s); |
1392 /* Account for restart interval (no-op if not using restarts) */ | 1412 /* Account for restart interval (no-op if not using restarts) */ |
1393 entropy.restarts_to_go--; | 1413 entropy.restarts_to_go--; |
1394 | 1414 |
1395 return true; | 1415 return true; |
1396 } | 1416 } |
1397 | 1417 |
1398 bool process_restart (jpeg_decompress_struct cinfo) { | 1418 bool process_restart (jpeg_decompress_struct cinfo) { |
1399 phuff_entropy_decoder entropy = this; | 1419 phuff_entropy_decoder entropy = this; |
1400 int ci; | 1420 int ci; |
1401 | 1421 |
1402 /* Throw away any unused bits remaining in bit buffer; */ | 1422 /* Throw away any unused bits remaining in bit buffer; */ |
1529 /* Initialize restart counter */ | 1549 /* Initialize restart counter */ |
1530 entropy.restarts_to_go = cinfo.restart_interval; | 1550 entropy.restarts_to_go = cinfo.restart_interval; |
1531 } | 1551 } |
1532 | 1552 |
1533 } | 1553 } |
1534 | 1554 |
1535 static final class jpeg_component_info { | 1555 static final class jpeg_component_info { |
1536 /* These values are fixed over the whole image. */ | 1556 /* These values are fixed over the whole image. */ |
1537 /* For compression, they must be supplied by parameter setup; */ | 1557 /* For compression, they must be supplied by parameter setup; */ |
1538 /* for decompression, they are read from the SOF marker. */ | 1558 /* for decompression, they are read from the SOF marker. */ |
1539 int component_id; /* identifier for this component (0..255) */ | 1559 int component_id; /* identifier for this component (0..255) */ |
1545 /* For compression, they must be supplied by parameter setup; */ | 1565 /* For compression, they must be supplied by parameter setup; */ |
1546 /* for decompression, they are read from the SOS marker. */ | 1566 /* for decompression, they are read from the SOS marker. */ |
1547 /* The decompressor output side may not use these variables. */ | 1567 /* The decompressor output side may not use these variables. */ |
1548 int dc_tbl_no; /* DC entropy table selector (0..3) */ | 1568 int dc_tbl_no; /* DC entropy table selector (0..3) */ |
1549 int ac_tbl_no; /* AC entropy table selector (0..3) */ | 1569 int ac_tbl_no; /* AC entropy table selector (0..3) */ |
1550 | 1570 |
1551 /* Remaining fields should be treated as private by applications. */ | 1571 /* Remaining fields should be treated as private by applications. */ |
1552 | 1572 |
1553 /* These values are computed during compression or decompression startup: */ | 1573 /* These values are computed during compression or decompression startup: */ |
1554 /* Component's size in DCT blocks. | 1574 /* Component's size in DCT blocks. |
1555 * Any dummy blocks added to complete an MCU are not counted; therefore | 1575 * Any dummy blocks added to complete an MCU are not counted; therefore |
1556 * these values do not depend on whether a scan is interleaved or not. | 1576 * these values do not depend on whether a scan is interleaved or not. |
1557 */ | 1577 */ |
1574 int downsampled_height; /* actual height in samples */ | 1594 int downsampled_height; /* actual height in samples */ |
1575 /* 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 |
1576 * components will be ignored (eg grayscale output from YCbCr image), | 1596 * components will be ignored (eg grayscale output from YCbCr image), |
1577 * we can skip most computations for the unused components. | 1597 * we can skip most computations for the unused components. |
1578 */ | 1598 */ |
1579 bool component_needed; /* do we need the value of this component? */ | 1599 bool component_needed; /* do we need the value of this component? */ |
1580 | 1600 |
1581 /* These values are computed before starting a scan of the component. */ | 1601 /* These values are computed before starting a scan of the component. */ |
1582 /* The decompressor output side may not use these variables. */ | 1602 /* The decompressor output side may not use these variables. */ |
1583 int MCU_width; /* number of blocks per MCU, horizontally */ | 1603 int MCU_width; /* number of blocks per MCU, horizontally */ |
1584 int MCU_height; /* number of blocks per MCU, vertically */ | 1604 int MCU_height; /* number of blocks per MCU, vertically */ |
1594 JQUANT_TBL quant_table; | 1614 JQUANT_TBL quant_table; |
1595 | 1615 |
1596 /* Private per-component storage for DCT or IDCT subsystem. */ | 1616 /* Private per-component storage for DCT or IDCT subsystem. */ |
1597 int[] dct_table; | 1617 int[] dct_table; |
1598 } | 1618 } |
1599 | 1619 |
1600 static final class jpeg_color_quantizer { | 1620 static final class jpeg_color_quantizer { |
1601 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo, bool is_pre_scan)); | 1621 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo, bool is_pre_scan)); |
1602 // JMETHOD(void, color_quantize, (j_decompress_ptr cinfo, | 1622 // JMETHOD(void, color_quantize, (j_decompress_ptr cinfo, |
1603 // JSAMPARRAY input_buf, JSAMPARRAY output_buf, | 1623 // JSAMPARRAY input_buf, JSAMPARRAY output_buf, |
1604 // int num_rows)); | 1624 // int num_rows)); |
1605 // JMETHOD(void, finish_pass, (j_decompress_ptr cinfo)); | 1625 // JMETHOD(void, finish_pass, (j_decompress_ptr cinfo)); |
1606 // JMETHOD(void, new_color_map, (j_decompress_ptr cinfo)); | 1626 // JMETHOD(void, new_color_map, (j_decompress_ptr cinfo)); |
1607 | 1627 |
1608 /* Initially allocated colormap is saved here */ | 1628 /* Initially allocated colormap is saved here */ |
1609 int[][] sv_colormap; /* The color map as a 2-D pixel array */ | 1629 int[][] sv_colormap; /* The color map as a 2-D pixel array */ |
1610 int sv_actual; /* number of entries in use */ | 1630 int sv_actual; /* number of entries in use */ |
1611 | 1631 |
1612 int[][] colorindex; /* Precomputed mapping for speed */ | 1632 int[][] colorindex; /* Precomputed mapping for speed */ |
1613 /* 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, |
1614 * premultiplied as described above. Since colormap indexes must fit into | 1634 * premultiplied as described above. Since colormap indexes must fit into |
1615 * JSAMPLEs, the entries of this array will too. | 1635 * JSAMPLEs, the entries of this array will too. |
1616 */ | 1636 */ |
1617 bool is_padded; /* is the colorindex padded for odither? */ | 1637 bool is_padded; /* is the colorindex padded for odither? */ |
1618 | 1638 |
1619 int[] 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 */ |
1620 | 1640 |
1621 /* Variables for ordered dithering */ | 1641 /* Variables for ordered dithering */ |
1622 int row_index; /* cur row's vertical index in dither matrix */ | 1642 int row_index; /* cur row's vertical index in dither matrix */ |
1623 // 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 */ |
1624 | 1644 |
1625 /* Variables for Floyd-Steinberg dithering */ | 1645 /* Variables for Floyd-Steinberg dithering */ |
1626 // FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */ | 1646 // FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */ |
1627 bool on_odd_row; | 1647 bool on_odd_row; |
1628 | 1648 |
1629 void start_pass (jpeg_decompress_struct cinfo, bool is_pre_scan) { | 1649 void start_pass (jpeg_decompress_struct cinfo, bool is_pre_scan) { |
1630 error(); | 1650 error(); |
1631 } | 1651 } |
1632 } | 1652 } |
1633 | 1653 |
1634 static final class jpeg_upsampler { | 1654 static final class jpeg_upsampler { |
1635 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); | 1655 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); |
1636 // JMETHOD(void, upsample, (j_decompress_ptr cinfo, | 1656 // JMETHOD(void, upsample, (j_decompress_ptr cinfo, |
1637 // JSAMPIMAGE input_buf, | 1657 // JSAMPIMAGE input_buf, |
1638 // JDIMENSION *in_row_group_ctr, | 1658 // JDIMENSION *in_row_group_ctr, |
1639 // JDIMENSION in_row_groups_avail, | 1659 // JDIMENSION in_row_groups_avail, |
1640 // JSAMPARRAY output_buf, | 1660 // JSAMPARRAY output_buf, |
1641 // JDIMENSION *out_row_ctr, | 1661 // JDIMENSION *out_row_ctr, |
1642 // JDIMENSION out_rows_avail)); | 1662 // JDIMENSION out_rows_avail)); |
1643 | 1663 |
1644 bool need_context_rows; /* TRUE if need rows above & below */ | 1664 bool need_context_rows; /* TRUE if need rows above & below */ |
1645 | 1665 |
1646 /* Color conversion buffer. When using separate upsampling and color | 1666 /* Color conversion buffer. When using separate upsampling and color |
1647 * conversion steps, this buffer holds one upsampled row group until it | 1667 * conversion steps, this buffer holds one upsampled row group until it |
1648 * has been color converted and output. | 1668 * has been color converted and output. |
1649 * 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, |
1650 * ie do not need rescaling. The corresponding entry of color_buf[] is | 1670 * ie do not need rescaling. The corresponding entry of color_buf[] is |
1651 * simply set to point to the input data array, thereby avoiding copying. | 1671 * simply set to point to the input data array, thereby avoiding copying. |
1652 */ | 1672 */ |
1653 byte[][][] color_buf = new byte[MAX_COMPONENTS][][]; | 1673 byte[][][MAX_COMPONENTS] color_buf;// = new byte[MAX_COMPONENTS][][]; |
1654 int[] color_buf_offset = new int[MAX_COMPONENTS]; | 1674 int[MAX_COMPONENTS] color_buf_offset;// = new int[MAX_COMPONENTS]; |
1655 | 1675 |
1656 /* Per-component upsampling method pointers */ | 1676 /* Per-component upsampling method pointers */ |
1657 int[] methods = new int[MAX_COMPONENTS]; | 1677 int[MAX_COMPONENTS] methods;// = new int[MAX_COMPONENTS]; |
1658 | 1678 |
1659 int next_row_out; /* counts rows emitted from color_buf */ | 1679 int next_row_out; /* counts rows emitted from color_buf */ |
1660 int rows_to_go; /* counts rows remaining in image */ | 1680 int rows_to_go; /* counts rows remaining in image */ |
1661 | 1681 |
1662 /* Height of an input row group for each component. */ | 1682 /* Height of an input row group for each component. */ |
1663 int[] rowgroup_height = new int[MAX_COMPONENTS]; | 1683 int[MAX_COMPONENTS] rowgroup_height;// = new int[MAX_COMPONENTS]; |
1664 | 1684 |
1665 /* These arrays save pixel expansion factors so that int_expand need not | 1685 /* These arrays save pixel expansion factors so that int_expand need not |
1666 * recompute them each time. They are unused for other upsampling methods. | 1686 * recompute them each time. They are unused for other upsampling methods. |
1667 */ | 1687 */ |
1668 byte[] h_expand = new byte[MAX_COMPONENTS]; | 1688 byte[MAX_COMPONENTS] h_expand;// = new byte[MAX_COMPONENTS]; |
1669 byte[] v_expand = new byte[MAX_COMPONENTS]; | 1689 byte[MAX_COMPONENTS] v_expand;// = new byte[MAX_COMPONENTS]; |
1670 | 1690 |
1671 void start_pass (jpeg_decompress_struct cinfo) { | 1691 void start_pass (jpeg_decompress_struct cinfo) { |
1672 jpeg_upsampler upsample = cinfo.upsample; | 1692 jpeg_upsampler upsample = cinfo.upsample; |
1673 | 1693 |
1674 /* Mark the conversion buffer empty */ | 1694 /* Mark the conversion buffer empty */ |
1675 upsample.next_row_out = cinfo.max_v_samp_factor; | 1695 upsample.next_row_out = cinfo.max_v_samp_factor; |
1676 /* Initialize total-height counter for detecting bottom of image */ | 1696 /* Initialize total-height counter for detecting bottom of image */ |
1677 upsample.rows_to_go = cinfo.output_height; | 1697 upsample.rows_to_go = cinfo.output_height; |
1678 } | 1698 } |
1679 | 1699 |
1680 } | 1700 } |
1681 | 1701 |
1682 static final class jpeg_marker_reader { | 1702 static final class jpeg_marker_reader { |
1683 /* Read a restart marker --- exported for use by entropy decoder only */ | 1703 /* Read a restart marker --- exported for use by entropy decoder only */ |
1684 // jpeg_marker_parser_method read_restart_marker; | 1704 // jpeg_marker_parser_method read_restart_marker; |
1685 | 1705 |
1686 /* State of marker reader --- nominally internal, but applications | 1706 /* State of marker reader --- nominally internal, but applications |
1687 * supplying COM or APPn handlers might like to know the state. | 1707 * supplying COM or APPn handlers might like to know the state. |
1688 */ | 1708 */ |
1689 bool saw_SOI; /* found SOI? */ | 1709 bool saw_SOI; /* found SOI? */ |
1690 bool saw_SOF; /* found SOF? */ | 1710 bool saw_SOF; /* found SOF? */ |
1691 int next_restart_num; /* next restart number expected (0-7) */ | 1711 int next_restart_num; /* next restart number expected (0-7) */ |
1692 int discarded_bytes; /* # of bytes skipped looking for a marker */ | 1712 int discarded_bytes; /* # of bytes skipped looking for a marker */ |
1693 | 1713 |
1694 /* Application-overridable marker processing methods */ | 1714 /* Application-overridable marker processing methods */ |
1695 // jpeg_marker_parser_method process_COM; | 1715 // jpeg_marker_parser_method process_COM; |
1696 // jpeg_marker_parser_method process_APPn[16]; | 1716 // jpeg_marker_parser_method process_APPn[16]; |
1697 | 1717 |
1698 /* Limit on marker data length to save for each marker type */ | 1718 /* Limit on marker data length to save for each marker type */ |
1699 int length_limit_COM; | 1719 int length_limit_COM; |
1700 int[] length_limit_APPn = new int[16]; | 1720 int[16] length_limit_APPn;// = new int[16]; |
1701 | 1721 |
1702 /* Status of COM/APPn marker saving */ | 1722 /* Status of COM/APPn marker saving */ |
1703 // jpeg_marker_reader cur_marker; /* null if not processing a marker */ | 1723 // jpeg_marker_reader cur_marker; /* null if not processing a marker */ |
1704 // int bytes_read; /* data bytes read so far in marker */ | 1724 // int bytes_read; /* data bytes read so far in marker */ |
1705 /* Note: cur_marker is not linked into marker_list until it's all read. */ | 1725 /* Note: cur_marker is not linked into marker_list until it's all read. */ |
1706 } | 1726 } |
1707 | 1727 |
1708 | 1728 |
1709 static final class jpeg_d_main_controller { | 1729 static final class jpeg_d_main_controller { |
1710 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); | 1730 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); |
1711 int process_data; | 1731 int process_data; |
1712 | 1732 |
1713 /* Pointer to allocated workspace (M or M+2 row groups). */ | 1733 /* Pointer to allocated workspace (M or M+2 row groups). */ |
1714 byte[][][] buffer = new byte[MAX_COMPONENTS][][]; | 1734 byte[][][MAX_COMPONENTS] buffer;// = new byte[MAX_COMPONENTS][][]; |
1715 int[] buffer_offset = new int[MAX_COMPONENTS]; | 1735 int[MAX_COMPONENTS] buffer_offset;// = new int[MAX_COMPONENTS]; |
1716 | 1736 |
1717 bool buffer_full; /* Have we gotten an iMCU row from decoder? */ | 1737 bool buffer_full; /* Have we gotten an iMCU row from decoder? */ |
1718 int[] 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 */ |
1719 | 1739 |
1720 /* Remaining fields are only used in the context case. */ | 1740 /* Remaining fields are only used in the context case. */ |
1721 | 1741 |
1722 /* These are the master pointers to the funny-order pointer lists. */ | 1742 /* These are the master pointers to the funny-order pointer lists. */ |
1723 byte[][][][] xbuffer = new byte[2][][][]; /* pointers to weird pointer lists */ | 1743 byte[][][][2] xbuffer;// = new byte[2][][][]; /* pointers to weird pointer lists */ |
1724 int[][] xbuffer_offset = new int[2][]; | 1744 int[][2] xbuffer_offset;// = new int[2][]; |
1725 | 1745 |
1726 int whichptr; /* indicates which pointer set is now in use */ | 1746 int whichptr; /* indicates which pointer set is now in use */ |
1727 int context_state; /* process_data state machine status */ | 1747 int context_state; /* process_data state machine status */ |
1728 int rowgroups_avail; /* row groups available to postprocessor */ | 1748 int rowgroups_avail; /* row groups available to postprocessor */ |
1729 int iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */ | 1749 int iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */ |
1730 | 1750 |
1731 void start_pass (jpeg_decompress_struct cinfo, int pass_mode) { | 1751 void start_pass (jpeg_decompress_struct cinfo, int pass_mode) { |
1732 jpeg_d_main_controller main = cinfo.main; | 1752 jpeg_d_main_controller main = cinfo.main; |
1733 | 1753 |
1734 switch (pass_mode) { | 1754 switch (pass_mode) { |
1735 case JBUF_PASS_THRU: | 1755 case JBUF_PASS_THRU: |
1756 error(); | 1776 error(); |
1757 // ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 1777 // ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); |
1758 break; | 1778 break; |
1759 } | 1779 } |
1760 } | 1780 } |
1761 | 1781 |
1762 } | 1782 } |
1763 | 1783 |
1764 static final class jpeg_decomp_master { | 1784 static final class jpeg_decomp_master { |
1765 // JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo)); | 1785 // JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo)); |
1766 // JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo)); | 1786 // JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo)); |
1776 * in case we need to switch modes. | 1796 * in case we need to switch modes. |
1777 */ | 1797 */ |
1778 jpeg_color_quantizer quantizer_1pass; | 1798 jpeg_color_quantizer quantizer_1pass; |
1779 jpeg_color_quantizer quantizer_2pass; | 1799 jpeg_color_quantizer quantizer_2pass; |
1780 } | 1800 } |
1781 | 1801 |
1782 static final class jpeg_inverse_dct { | 1802 static final class jpeg_inverse_dct { |
1783 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); | 1803 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); |
1784 // /* It is useful to allow each component to have a separate IDCT method. */ | 1804 // /* It is useful to allow each component to have a separate IDCT method. */ |
1785 // inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS]; | 1805 // inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS]; |
1786 int[] cur_method = new int[MAX_COMPONENTS]; | 1806 int[MAX_COMPONENTS] cur_method;// = new int[MAX_COMPONENTS]; |
1787 | 1807 |
1788 void start_pass (jpeg_decompress_struct cinfo) { | 1808 void start_pass (jpeg_decompress_struct cinfo) { |
1789 jpeg_inverse_dct idct = cinfo.idct; | 1809 jpeg_inverse_dct idct = cinfo.idct; |
1790 int ci, i; | 1810 int ci, i; |
1791 jpeg_component_info compptr; | 1811 jpeg_component_info compptr; |
1792 int method = 0; | 1812 int method = 0; |
1891 // 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | 1911 // 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, |
1892 // 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, | 1912 // 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, |
1893 // 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 | 1913 // 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 |
1894 // }; | 1914 // }; |
1895 // SHIFT_TEMPS | 1915 // SHIFT_TEMPS |
1896 // | 1916 // |
1897 // for (i = 0; i < DCTSIZE2; i++) { | 1917 // for (i = 0; i < DCTSIZE2; i++) { |
1898 // ifmtbl[i] = DESCALE(MULTIPLY16V16( qtbl.quantval[i], aanscales[i]), CONST_BITS-IFAST_SCALE_BITS); | 1918 // ifmtbl[i] = DESCALE(MULTIPLY16V16( qtbl.quantval[i], aanscales[i]), CONST_BITS-IFAST_SCALE_BITS); |
1899 // } | 1919 // } |
1900 // } | 1920 // } |
1901 // break; | 1921 // break; |
1916 // }; | 1936 // }; |
1917 // | 1937 // |
1918 // i = 0; | 1938 // i = 0; |
1919 // for (row = 0; row < DCTSIZE; row++) { | 1939 // for (row = 0; row < DCTSIZE; row++) { |
1920 // for (col = 0; col < DCTSIZE; col++) { | 1940 // for (col = 0; col < DCTSIZE; col++) { |
1921 // fmtbl[i] = cast(FLOAT_MULT_TYPE) | 1941 // fmtbl[i] = (FLOAT_MULT_TYPE) |
1922 // (cast(double) qtbl.quantval[i] * | 1942 // ((double) qtbl.quantval[i] * |
1923 // aanscalefactor[row] * aanscalefactor[col]); | 1943 // aanscalefactor[row] * aanscalefactor[col]); |
1924 // i++; | 1944 // i++; |
1925 // } | 1945 // } |
1926 // } | 1946 // } |
1927 // } | 1947 // } |
1933 break; | 1953 break; |
1934 } | 1954 } |
1935 } | 1955 } |
1936 } | 1956 } |
1937 } | 1957 } |
1938 | 1958 |
1939 static final class jpeg_input_controller { | 1959 static final class jpeg_input_controller { |
1940 int consume_input; | 1960 int consume_input; |
1941 bool has_multiple_scans; /* True if file has multiple scans */ | 1961 bool has_multiple_scans; /* True if file has multiple scans */ |
1942 bool eoi_reached; | 1962 bool eoi_reached; |
1943 | 1963 |
1944 bool inheaders; /* true until first SOS is reached */ | 1964 bool inheaders; /* true until first SOS is reached */ |
1945 } | 1965 } |
1946 | 1966 |
1947 static final class jpeg_color_deconverter { | 1967 static final class jpeg_color_deconverter { |
1948 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); | 1968 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); |
1949 int color_convert; | 1969 int color_convert; |
1950 | 1970 |
1951 /* Private state for YCC.RGB conversion */ | 1971 /* Private state for YCC.RGB conversion */ |
1952 int[] Cr_r_tab; /* => table for Cr to R conversion */ | 1972 int[] Cr_r_tab; /* => table for Cr to R conversion */ |
1953 int[] Cb_b_tab; /* => table for Cb to B conversion */ | 1973 int[] Cb_b_tab; /* => table for Cb to B conversion */ |
1954 int[] Cr_g_tab; /* => table for Cr to G conversion */ | 1974 int[] Cr_g_tab; /* => table for Cr to G conversion */ |
1955 int[] Cb_g_tab; /* => table for Cb to G conversion */ | 1975 int[] Cb_g_tab; /* => table for Cb to G conversion */ |
1956 | 1976 |
1957 void start_pass (jpeg_decompress_struct cinfo) { | 1977 void start_pass (jpeg_decompress_struct cinfo) { |
1958 /* no work needed */ | 1978 /* no work needed */ |
1959 } | 1979 } |
1960 | 1980 |
1961 } | 1981 } |
1962 | 1982 |
1963 static final class jpeg_d_post_controller { | 1983 static final class jpeg_d_post_controller { |
1964 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); | 1984 // JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); |
1965 int post_process_data; | 1985 int post_process_data; |
1966 | 1986 |
1967 /* Color quantization source buffer: this holds output data from | 1987 /* Color quantization source buffer: this holds output data from |
1968 * the upsample/color conversion step to be passed to the quantizer. | 1988 * the upsample/color conversion step to be passed to the quantizer. |
1969 * For two-pass color quantization, we need a full-image buffer; | 1989 * For two-pass color quantization, we need a full-image buffer; |
1970 * for one-pass operation, a strip buffer is sufficient. | 1990 * for one-pass operation, a strip buffer is sufficient. |
1971 */ | 1991 */ |
1973 int[][] buffer; /* strip buffer, or current strip of virtual */ | 1993 int[][] buffer; /* strip buffer, or current strip of virtual */ |
1974 int strip_height; /* buffer size in rows */ | 1994 int strip_height; /* buffer size in rows */ |
1975 /* for two-pass mode only: */ | 1995 /* for two-pass mode only: */ |
1976 int starting_row; /* row # of first row in current strip */ | 1996 int starting_row; /* row # of first row in current strip */ |
1977 int next_row; /* index of next row to fill/empty in strip */ | 1997 int next_row; /* index of next row to fill/empty in strip */ |
1978 | 1998 |
1979 void start_pass (jpeg_decompress_struct cinfo, int pass_mode) { | 1999 void start_pass (jpeg_decompress_struct cinfo, int pass_mode) { |
1980 jpeg_d_post_controller post = cinfo.post; | 2000 jpeg_d_post_controller post = cinfo.post; |
1981 | 2001 |
1982 switch (pass_mode) { | 2002 switch (pass_mode) { |
1983 case JBUF_PASS_THRU: | 2003 case JBUF_PASS_THRU: |
1990 // * allocate a strip buffer. Use the virtual-array buffer as workspace. | 2010 // * allocate a strip buffer. Use the virtual-array buffer as workspace. |
1991 // */ | 2011 // */ |
1992 // if (post.buffer is null) { | 2012 // if (post.buffer is null) { |
1993 // post.buffer = (*cinfo.mem.access_virt_sarray) | 2013 // post.buffer = (*cinfo.mem.access_virt_sarray) |
1994 // ((j_common_ptr) cinfo, post.whole_image, | 2014 // ((j_common_ptr) cinfo, post.whole_image, |
1995 // cast(JDIMENSION) 0, post.strip_height, TRUE); | 2015 // (JDIMENSION) 0, post.strip_height, TRUE); |
1996 // } | 2016 // } |
1997 } else { | 2017 } else { |
1998 /* For single-pass processing without color quantization, | 2018 /* For single-pass processing without color quantization, |
1999 * I have no work to do; just call the upsampler directly. | 2019 * I have no work to do; just call the upsampler directly. |
2000 */ | 2020 */ |
2022 } | 2042 } |
2023 post.starting_row = post.next_row = 0; | 2043 post.starting_row = post.next_row = 0; |
2024 } | 2044 } |
2025 | 2045 |
2026 } | 2046 } |
2027 | 2047 |
2028 static final class jpeg_decompress_struct { | 2048 static final class jpeg_decompress_struct { |
2029 // jpeg_error_mgr * err; /* Error handler module */\ | 2049 // jpeg_error_mgr * err; /* Error handler module */\ |
2030 // struct jpeg_memory_mgr * mem; /* Memory manager module */\ | 2050 // struct jpeg_memory_mgr * mem; /* Memory manager module */\ |
2031 // struct jpeg_progress_mgr * progress; /* Progress monitor, or null if none */\ | 2051 // struct jpeg_progress_mgr * progress; /* Progress monitor, or null if none */\ |
2032 // void * client_data; /* Available for use by application */\ | 2052 // void * client_data; /* Available for use by application */\ |
2033 bool is_decompressor; /* So common code can tell which is which */ | 2053 bool is_decompressor; /* So common code can tell which is which */ |
2034 int global_state; /* For checking call sequence validity */ | 2054 int global_state; /* For checking call sequence validity */ |
2035 | 2055 |
2036 // /* Source of compressed data */ | 2056 // /* Source of compressed data */ |
2037 // struct jpeg_source_mgr * src; | 2057 // struct jpeg_source_mgr * src; |
2038 InputStream inputStream; | 2058 InputStream inputStream; |
2058 | 2078 |
2059 int scale_num, scale_denom; /* fraction by which to scale image */ | 2079 int scale_num, scale_denom; /* fraction by which to scale image */ |
2060 | 2080 |
2061 double output_gamma; /* image gamma wanted in output */ | 2081 double output_gamma; /* image gamma wanted in output */ |
2062 | 2082 |
2063 bool buffered_image; /* true=multiple output passes */ | 2083 bool buffered_image; /* true=multiple output passes */ |
2064 bool raw_data_out; /* true=downsampled data wanted */ | 2084 bool raw_data_out; /* true=downsampled data wanted */ |
2065 | 2085 |
2066 int dct_method; /* IDCT algorithm selector */ | 2086 int dct_method; /* IDCT algorithm selector */ |
2067 bool do_fancy_upsampling; /* true=apply fancy upsampling */ | 2087 bool do_fancy_upsampling; /* true=apply fancy upsampling */ |
2068 bool do_block_smoothing; /* true=apply interblock smoothing */ | 2088 bool do_block_smoothing; /* true=apply interblock smoothing */ |
2069 | 2089 |
2070 bool quantize_colors; /* true=colormapped output wanted */ | 2090 bool quantize_colors; /* true=colormapped output wanted */ |
2071 /* the following are ignored if not quantize_colors: */ | 2091 /* the following are ignored if not quantize_colors: */ |
2072 int dither_mode; /* type of color dithering to use */ | 2092 int dither_mode; /* type of color dithering to use */ |
2073 bool two_pass_quantize; /* true=use two-pass color quantization */ | 2093 bool two_pass_quantize; /* true=use two-pass color quantization */ |
2074 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 */ |
2075 /* these are significant only in buffered-image mode: */ | 2095 /* these are significant only in buffered-image mode: */ |
2076 bool enable_1pass_quant; /* enable future use of 1-pass quantizer */ | 2096 bool enable_1pass_quant; /* enable future use of 1-pass quantizer */ |
2077 bool enable_external_quant;/* enable future use of external colormap */ | 2097 bool enable_external_quant;/* enable future use of external colormap */ |
2078 bool enable_2pass_quant; /* enable future use of 2-pass quantizer */ | 2098 bool enable_2pass_quant; /* enable future use of 2-pass quantizer */ |
2079 | 2099 |
2080 /* Description of actual output image that will be returned to application. | 2100 /* Description of actual output image that will be returned to application. |
2081 * These fields are computed by jpeg_start_decompress(). | 2101 * These fields are computed by jpeg_start_decompress(). |
2082 * 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 |
2083 * in advance of calling jpeg_start_decompress(). | 2103 * in advance of calling jpeg_start_decompress(). |
2086 int output_width; /* scaled image width */ | 2106 int output_width; /* scaled image width */ |
2087 int output_height; /* scaled image height */ | 2107 int output_height; /* scaled image height */ |
2088 int out_color_components; /* # of color components in out_color_space */ | 2108 int out_color_components; /* # of color components in out_color_space */ |
2089 int output_components; /* # of color components returned */ | 2109 int output_components; /* # of color components returned */ |
2090 /* output_components is 1 (a colormap index) when quantizing colors; | 2110 /* output_components is 1 (a colormap index) when quantizing colors; |
2091 * otherwise it opEquals out_color_components. | 2111 * otherwise it equals out_color_components. |
2092 */ | 2112 */ |
2093 int rec_outbuf_height; /* min recommended height of scanline buffer */ | 2113 int rec_outbuf_height; /* min recommended height of scanline buffer */ |
2094 /* If the buffer passed to jpeg_read_scanlines() is less than this many rows | 2114 /* If the buffer passed to jpeg_read_scanlines() is less than this many rows |
2095 * high, space and time will be wasted due to unnecessary data copying. | 2115 * high, space and time will be wasted due to unnecessary data copying. |
2096 * Usually rec_outbuf_height will be 1 or 2, at most 4. | 2116 * Usually rec_outbuf_height will be 1 or 2, at most 4. |
2144 | 2164 |
2145 /* Quantization and Huffman tables are carried forward across input | 2165 /* Quantization and Huffman tables are carried forward across input |
2146 * datastreams when processing abbreviated JPEG datastreams. | 2166 * datastreams when processing abbreviated JPEG datastreams. |
2147 */ | 2167 */ |
2148 | 2168 |
2149 JQUANT_TBL[] quant_tbl_ptrs = new JQUANT_TBL[NUM_QUANT_TBLS]; | 2169 JQUANT_TBL[NUM_QUANT_TBLS] quant_tbl_ptrs;// = new JQUANT_TBL[NUM_QUANT_TBLS]; |
2150 /* ptrs to coefficient quantization tables, or null if not defined */ | 2170 /* ptrs to coefficient quantization tables, or null if not defined */ |
2151 | 2171 |
2152 JHUFF_TBL[] dc_huff_tbl_ptrs = new JHUFF_TBL[NUM_HUFF_TBLS]; | 2172 JHUFF_TBL[NUM_HUFF_TBLS] dc_huff_tbl_ptrs;// = new JHUFF_TBL[NUM_HUFF_TBLS]; |
2153 JHUFF_TBL[] ac_huff_tbl_ptrs = new JHUFF_TBL[NUM_HUFF_TBLS]; | 2173 JHUFF_TBL[NUM_HUFF_TBLS] ac_huff_tbl_ptrs;// = new JHUFF_TBL[NUM_HUFF_TBLS]; |
2154 /* ptrs to Huffman coding tables, or null if not defined */ | 2174 /* ptrs to Huffman coding tables, or null if not defined */ |
2155 | 2175 |
2156 /* These parameters are never carried across datastreams, since they | 2176 /* These parameters are never carried across datastreams, since they |
2157 * are given in SOF/SOS markers or defined to be reset by SOI. | 2177 * are given in SOF/SOS markers or defined to be reset by SOI. |
2158 */ | 2178 */ |
2160 int data_precision; /* bits of precision in image data */ | 2180 int data_precision; /* bits of precision in image data */ |
2161 | 2181 |
2162 jpeg_component_info[] comp_info; | 2182 jpeg_component_info[] comp_info; |
2163 /* comp_info[i] describes component that appears i'th in SOF */ | 2183 /* comp_info[i] describes component that appears i'th in SOF */ |
2164 | 2184 |
2165 bool progressive_mode; /* true if SOFn specifies progressive mode */ | 2185 bool progressive_mode; /* true if SOFn specifies progressive mode */ |
2166 bool arith_code; /* true=arithmetic coding, false=Huffman */ | 2186 bool arith_code; /* true=arithmetic coding, false=Huffman */ |
2167 | 2187 |
2168 byte[] 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 */ |
2169 byte[] 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 */ |
2170 byte[] 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 */ |
2171 | 2191 |
2172 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 */ |
2173 | 2193 |
2174 /* These fields record data obtained from optional markers recognized by | 2194 /* These fields record data obtained from optional markers recognized by |
2175 * the JPEG library. | 2195 * the JPEG library. |
2176 */ | 2196 */ |
2177 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 */ |
2178 /* 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: */ |
2179 byte JFIF_major_version; /* JFIF version number */ | 2199 byte JFIF_major_version; /* JFIF version number */ |
2180 byte JFIF_minor_version; | 2200 byte JFIF_minor_version; |
2181 byte density_unit; /* JFIF code for pixel size units */ | 2201 byte density_unit; /* JFIF code for pixel size units */ |
2182 short X_density; /* Horizontal pixel density */ | 2202 short X_density; /* Horizontal pixel density */ |
2183 short Y_density; /* Vertical pixel density */ | 2203 short Y_density; /* Vertical pixel density */ |
2184 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 */ |
2185 byte Adobe_transform; /* Color transform code from Adobe marker */ | 2205 byte Adobe_transform; /* Color transform code from Adobe marker */ |
2186 | 2206 |
2187 bool CCIR601_sampling; /* true=first samples are cosited */ | 2207 bool CCIR601_sampling; /* true=first samples are cosited */ |
2188 | 2208 |
2189 /* 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 |
2190 * 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 |
2191 * can be saved in a list for examination by the application. | 2211 * can be saved in a list for examination by the application. |
2192 */ | 2212 */ |
2220 * These fields are valid during any one scan. | 2240 * These fields are valid during any one scan. |
2221 * They describe the components and MCUs actually appearing in the scan. | 2241 * They describe the components and MCUs actually appearing in the scan. |
2222 * Note that the decompressor output side must not use these fields. | 2242 * Note that the decompressor output side must not use these fields. |
2223 */ | 2243 */ |
2224 int comps_in_scan; /* # of JPEG components in this scan */ | 2244 int comps_in_scan; /* # of JPEG components in this scan */ |
2225 jpeg_component_info[] cur_comp_info = new jpeg_component_info[MAX_COMPS_IN_SCAN]; | 2245 jpeg_component_info[MAX_COMPS_IN_SCAN] cur_comp_info;// = new jpeg_component_info[MAX_COMPS_IN_SCAN]; |
2226 /* *cur_comp_info[i] describes component that appears i'th in SOS */ | 2246 /* *cur_comp_info[i] describes component that appears i'th in SOS */ |
2227 | 2247 |
2228 int MCUs_per_row; /* # of MCUs across the image */ | 2248 int MCUs_per_row; /* # of MCUs across the image */ |
2229 int MCU_rows_in_scan; /* # of MCU rows in the image */ | 2249 int MCU_rows_in_scan; /* # of MCU rows in the image */ |
2230 | 2250 |
2231 int blocks_in_MCU; /* # of DCT blocks per MCU */ | 2251 int blocks_in_MCU; /* # of DCT blocks per MCU */ |
2232 int[] MCU_membership = new int[D_MAX_BLOCKS_IN_MCU]; | 2252 int[D_MAX_BLOCKS_IN_MCU] MCU_membership;// = new int[D_MAX_BLOCKS_IN_MCU]; |
2233 /* MCU_membership[i] is index in cur_comp_info of component owning */ | 2253 /* MCU_membership[i] is index in cur_comp_info of component owning */ |
2234 /* i'th block in an MCU */ | 2254 /* i'th block in an MCU */ |
2235 | 2255 |
2236 int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ | 2256 int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ |
2237 | 2257 |
2238 /* This field is shared between entropy decoder and marker parser. | 2258 /* This field is shared between entropy decoder and marker parser. |
2239 * It is either zero or the code of a JPEG marker that has been | 2259 * It is either zero or the code of a JPEG marker that has been |
2240 * read from the data source, but has not yet been processed. | 2260 * read from the data source, but has not yet been processed. |
2241 */ | 2261 */ |
2242 int unread_marker; | 2262 int unread_marker; |
2243 | 2263 |
2244 int[] workspace = new int[DCTSIZE2]; | 2264 int[DCTSIZE2] workspace;// = new int[DCTSIZE2]; |
2245 int[] row_ctr = new int[1]; | 2265 int[1] row_ctr;// = new int[1]; |
2246 | 2266 |
2247 /* | 2267 /* |
2248 * Links to decompression subobjects (methods, private variables of modules) | 2268 * Links to decompression subobjects (methods, private variables of modules) |
2249 */ | 2269 */ |
2250 jpeg_decomp_master master; | 2270 jpeg_decomp_master master; |
2314 //#ifdef BLOCK_SMOOTHING_SUPPORTED | 2334 //#ifdef BLOCK_SMOOTHING_SUPPORTED |
2315 /* If block smoothing could be used, need a bigger window */ | 2335 /* If block smoothing could be used, need a bigger window */ |
2316 if (cinfo.progressive_mode) | 2336 if (cinfo.progressive_mode) |
2317 access_rows *= 3; | 2337 access_rows *= 3; |
2318 //#endif | 2338 //#endif |
2319 coef.whole_image[ci] = | 2339 coef.whole_image[ci] = |
2320 new short | 2340 new short[][][]( |
2321 [cast(int)jround_up( compptr.height_in_blocks, compptr.v_samp_factor)] | 2341 cast(int)jround_up( compptr.height_in_blocks, compptr.v_samp_factor), |
2322 [cast(int)jround_up( compptr.width_in_blocks, compptr.h_samp_factor)] | 2342 cast(int)jround_up( compptr.width_in_blocks, compptr.h_samp_factor), |
2323 [DCTSIZE2]; | 2343 DCTSIZE2 |
2344 ); | |
2324 } | 2345 } |
2325 // coef.consume_data = consume_data; | 2346 // coef.consume_data = consume_data; |
2326 coef.decompress_data = DECOMPRESS_DATA; | 2347 coef.decompress_data = DECOMPRESS_DATA; |
2327 coef.coef_arrays = coef.whole_image[0]; /* link to virtual arrays */ | 2348 coef.coef_arrays = coef.whole_image[0]; /* link to virtual arrays */ |
2328 // #else | 2349 // #else |
2329 // ERREXIT(cinfo, JERR_NOT_COMPILED); | 2350 // ERREXIT(cinfo, JERR_NOT_COMPILED); |
2330 // #endif | 2351 // #endif |
2331 } else { | 2352 } else { |
2332 /* We only need a single-MCU buffer. */ | 2353 /* We only need a single-MCU buffer. */ |
2333 coef.MCU_buffer = new short[D_MAX_BLOCKS_IN_MCU][DCTSIZE2]; | 2354 foreach( inout el; coef.MCU_buffer ){ |
2355 el = new short[](DCTSIZE2); | |
2356 } | |
2334 // coef.consume_data = dummy_consume_data; | 2357 // coef.consume_data = dummy_consume_data; |
2335 coef.decompress_data = DECOMPRESS_ONEPASS; | 2358 coef.decompress_data = DECOMPRESS_ONEPASS; |
2336 coef.coef_arrays = null; /* flag for no virtual arrays */ | 2359 coef.coef_arrays = null; /* flag for no virtual arrays */ |
2337 } | 2360 } |
2338 } | 2361 } |
2678 // /* We round up the number of rows to a multiple of the strip height. */ | 2701 // /* We round up the number of rows to a multiple of the strip height. */ |
2679 //#ifdef QUANT_2PASS_SUPPORTED | 2702 //#ifdef QUANT_2PASS_SUPPORTED |
2680 // post.whole_image = (*cinfo.mem.request_virt_sarray) | 2703 // post.whole_image = (*cinfo.mem.request_virt_sarray) |
2681 // ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, | 2704 // ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, |
2682 // cinfo.output_width * cinfo.out_color_components, | 2705 // cinfo.output_width * cinfo.out_color_components, |
2683 // cast(JDIMENSION) jround_up(cast(long) cinfo.output_height, | 2706 // (JDIMENSION) jround_up(cast(long) cinfo.output_height, |
2684 // cast(long) post.strip_height), | 2707 // cast(long) post.strip_height), |
2685 // post.strip_height); | 2708 // post.strip_height); |
2686 //#else | 2709 //#else |
2687 // ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 2710 // ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); |
2688 //#endif /* QUANT_2PASS_SUPPORTED */ | 2711 //#endif /* QUANT_2PASS_SUPPORTED */ |
2707 jpeg_d_main_controller main = cinfo.main; | 2730 jpeg_d_main_controller main = cinfo.main; |
2708 int ci, i, rgroup; | 2731 int ci, i, rgroup; |
2709 int M = cinfo.min_DCT_scaled_size; | 2732 int M = cinfo.min_DCT_scaled_size; |
2710 jpeg_component_info compptr; | 2733 jpeg_component_info compptr; |
2711 byte[][] buf, xbuf0, xbuf1; | 2734 byte[][] buf, xbuf0, xbuf1; |
2712 | 2735 |
2713 for (ci = 0; ci < cinfo.num_components; ci++) { | 2736 for (ci = 0; ci < cinfo.num_components; ci++) { |
2714 compptr = cinfo.comp_info[ci]; | 2737 compptr = cinfo.comp_info[ci]; |
2715 rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / | 2738 rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / |
2716 cinfo.min_DCT_scaled_size; /* height of a row group of component */ | 2739 cinfo.min_DCT_scaled_size; /* height of a row group of component */ |
2717 xbuf0 = main.xbuffer[0][ci]; | 2740 xbuf0 = main.xbuffer[0][ci]; |
2751 byte[][] xbuf; | 2774 byte[][] xbuf; |
2752 | 2775 |
2753 /* Get top-level space for component array pointers. | 2776 /* Get top-level space for component array pointers. |
2754 * We alloc both arrays with one call to save a few cycles. | 2777 * We alloc both arrays with one call to save a few cycles. |
2755 */ | 2778 */ |
2756 main.xbuffer[0] = new byte[cinfo.num_components][][]; | 2779 main.xbuffer[0] = new byte[][][](cinfo.num_components); |
2757 main.xbuffer[1] = new byte[cinfo.num_components][][]; | 2780 main.xbuffer[1] = new byte[][][](cinfo.num_components); |
2758 main.xbuffer_offset[0] = new int[cinfo.num_components]; | 2781 main.xbuffer_offset[0] = new int[](cinfo.num_components); |
2759 main.xbuffer_offset[1] = new int[cinfo.num_components]; | 2782 main.xbuffer_offset[1] = new int[](cinfo.num_components); |
2760 | 2783 |
2761 for (ci = 0; ci < cinfo.num_components; ci++) { | 2784 for (ci = 0; ci < cinfo.num_components; ci++) { |
2762 compptr = cinfo.comp_info[ci]; | 2785 compptr = cinfo.comp_info[ci]; |
2763 rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / cinfo.min_DCT_scaled_size; /* height of a row group of component */ | 2786 rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / cinfo.min_DCT_scaled_size; /* height of a row group of component */ |
2764 /* Get space for pointer lists --- M+4 row groups in each list. | 2787 /* Get space for pointer lists --- M+4 row groups in each list. |
2765 * We alloc both pointer lists with one call to save a few cycles. | 2788 * We alloc both pointer lists with one call to save a few cycles. |
2766 */ | 2789 */ |
2767 xbuf = new byte[2 * (rgroup * (M + 4))][]; | 2790 xbuf = new byte[][](2 * (rgroup * (M + 4))); |
2768 int offset = rgroup; | 2791 int offset = rgroup; |
2769 main.xbuffer_offset[0][ci] = offset; | 2792 main.xbuffer_offset[0][ci] = offset; |
2770 main.xbuffer[0][ci] = xbuf; | 2793 main.xbuffer[0][ci] = xbuf; |
2771 offset += rgroup * (M + 4); | 2794 offset += rgroup * (M + 4); |
2772 main.xbuffer_offset[1][ci] = offset; | 2795 main.xbuffer_offset[1][ci] = offset; |
2800 } | 2823 } |
2801 | 2824 |
2802 for (ci = 0; ci < cinfo.num_components; ci++) { | 2825 for (ci = 0; ci < cinfo.num_components; ci++) { |
2803 compptr = cinfo.comp_info[ci]; | 2826 compptr = cinfo.comp_info[ci]; |
2804 rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / cinfo.min_DCT_scaled_size; /* height of a row group of component */ | 2827 rgroup = (compptr.v_samp_factor * compptr.DCT_scaled_size) / cinfo.min_DCT_scaled_size; /* height of a row group of component */ |
2805 main.buffer[ci] = new byte[rgroup * ngroups][compptr.width_in_blocks * compptr.DCT_scaled_size]; | 2828 main.buffer[ci] = new byte[][]( rgroup * ngroups, compptr.width_in_blocks * compptr.DCT_scaled_size ); |
2806 } | 2829 } |
2807 } | 2830 } |
2808 | 2831 |
2809 static long jround_up (long a, long b) | 2832 static long jround_up (long a, long b) |
2810 /* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */ | 2833 /* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */ |
2879 upsample.v_expand[ci] = cast(byte) (v_out_group / v_in_group); | 2902 upsample.v_expand[ci] = cast(byte) (v_out_group / v_in_group); |
2880 } else | 2903 } else |
2881 error(); | 2904 error(); |
2882 // ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); | 2905 // ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); |
2883 if (need_buffer) { | 2906 if (need_buffer) { |
2884 upsample.color_buf[ci] = new byte[cinfo.max_v_samp_factor] | 2907 upsample.color_buf[ci] = new byte[][]( cinfo.max_v_samp_factor, |
2885 [cast(int) jround_up(cinfo.output_width, cinfo.max_h_samp_factor)]; | 2908 cast(int) jround_up(cinfo.output_width, cinfo.max_h_samp_factor)); |
2886 } | 2909 } |
2887 } | 2910 } |
2888 } | 2911 } |
2889 | 2912 |
2890 static void jinit_phuff_decoder (jpeg_decompress_struct cinfo) { | 2913 static void jinit_phuff_decoder (jpeg_decompress_struct cinfo) { |
2893 | 2916 |
2894 cinfo.entropy = new phuff_entropy_decoder(); | 2917 cinfo.entropy = new phuff_entropy_decoder(); |
2895 // entropy.pub.start_pass = start_pass_phuff_decoder; | 2918 // entropy.pub.start_pass = start_pass_phuff_decoder; |
2896 | 2919 |
2897 /* Create progression status table */ | 2920 /* Create progression status table */ |
2898 cinfo.coef_bits = new int[cinfo.num_components][DCTSIZE2]; | 2921 cinfo.coef_bits = new int[][]( cinfo.num_components, DCTSIZE2 ); |
2899 coef_bit_ptr = cinfo.coef_bits; | 2922 coef_bit_ptr = cinfo.coef_bits; |
2900 for (ci = 0; ci < cinfo.num_components; ci++) | 2923 for (ci = 0; ci < cinfo.num_components; ci++) |
2901 for (i = 0; i < DCTSIZE2; i++) | 2924 for (i = 0; i < DCTSIZE2; i++) |
2902 coef_bit_ptr[ci][i] = -1; | 2925 coef_bit_ptr[ci][i] = -1; |
2903 } | 2926 } |
2904 | 2927 |
2905 | 2928 |
2944 byte[] range_limit = cinfo.sample_range_limit; | 2967 byte[] range_limit = cinfo.sample_range_limit; |
2945 int range_limit_offset = cinfo.sample_range_limit_offset + CENTERJSAMPLE; | 2968 int range_limit_offset = cinfo.sample_range_limit_offset + CENTERJSAMPLE; |
2946 int ctr; | 2969 int ctr; |
2947 int[] workspace = cinfo.workspace; /* buffers data between passes */ | 2970 int[] workspace = cinfo.workspace; /* buffers data between passes */ |
2948 // SHIFT_TEMPS | 2971 // SHIFT_TEMPS |
2949 | 2972 |
2950 /* Pass 1: process columns from input, store into work array. */ | 2973 /* Pass 1: process columns from input, store into work array. */ |
2951 /* Note results are scaled up by sqrt(8) compared to a true IDCT; */ | 2974 /* Note results are scaled up by sqrt(8) compared to a true IDCT; */ |
2952 /* furthermore, we scale the results by 2**PASS1_BITS. */ | 2975 /* furthermore, we scale the results by 2**PASS1_BITS. */ |
2953 | 2976 |
2954 inptr = coef_block; | 2977 inptr = coef_block; |
2955 quantptr = compptr.dct_table; | 2978 quantptr = compptr.dct_table; |
2956 wsptr = workspace; | 2979 wsptr = workspace; |
2957 int inptr_offset = 0, quantptr_offset = 0, wsptr_offset = 0; | 2980 int inptr_offset = 0, quantptr_offset = 0, wsptr_offset = 0; |
2958 for (ctr = DCTSIZE; ctr > 0; ctr--) { | 2981 for (ctr = DCTSIZE; ctr > 0; ctr--) { |
2962 * the AC terms are zero. In that case each output is equal to the | 2985 * the AC terms are zero. In that case each output is equal to the |
2963 * DC coefficient (with scale factor as needed). | 2986 * DC coefficient (with scale factor as needed). |
2964 * With typical images and quantization tables, half or more of the | 2987 * With typical images and quantization tables, half or more of the |
2965 * column DCT calculations can be simplified this way. | 2988 * column DCT calculations can be simplified this way. |
2966 */ | 2989 */ |
2967 | 2990 |
2968 if (inptr[DCTSIZE*1+inptr_offset] is 0 && inptr[DCTSIZE*2+inptr_offset] is 0 && | 2991 if (inptr[DCTSIZE*1+inptr_offset] is 0 && inptr[DCTSIZE*2+inptr_offset] is 0 && |
2969 inptr[DCTSIZE*3+inptr_offset] is 0 && inptr[DCTSIZE*4+inptr_offset] is 0 && | 2992 inptr[DCTSIZE*3+inptr_offset] is 0 && inptr[DCTSIZE*4+inptr_offset] is 0 && |
2970 inptr[DCTSIZE*5+inptr_offset] is 0 && inptr[DCTSIZE*6+inptr_offset] is 0 && | 2993 inptr[DCTSIZE*5+inptr_offset] is 0 && inptr[DCTSIZE*6+inptr_offset] is 0 && |
2971 inptr[DCTSIZE*7+inptr_offset] is 0) | 2994 inptr[DCTSIZE*7+inptr_offset] is 0) |
2972 { | 2995 { |
2973 /* AC terms all zero */ | 2996 /* AC terms all zero */ |
2974 int dcval = ((inptr[DCTSIZE*0+inptr_offset]) * quantptr[DCTSIZE*0+quantptr_offset]) << PASS1_BITS; | 2997 int dcval = ((inptr[DCTSIZE*0+inptr_offset]) * quantptr[DCTSIZE*0+quantptr_offset]) << PASS1_BITS; |
2975 | 2998 |
2976 wsptr[DCTSIZE*0+wsptr_offset] = dcval; | 2999 wsptr[DCTSIZE*0+wsptr_offset] = dcval; |
2977 wsptr[DCTSIZE*1+wsptr_offset] = dcval; | 3000 wsptr[DCTSIZE*1+wsptr_offset] = dcval; |
2978 wsptr[DCTSIZE*2+wsptr_offset] = dcval; | 3001 wsptr[DCTSIZE*2+wsptr_offset] = dcval; |
2979 wsptr[DCTSIZE*3+wsptr_offset] = dcval; | 3002 wsptr[DCTSIZE*3+wsptr_offset] = dcval; |
2980 wsptr[DCTSIZE*4+wsptr_offset] = dcval; | 3003 wsptr[DCTSIZE*4+wsptr_offset] = dcval; |
2981 wsptr[DCTSIZE*5+wsptr_offset] = dcval; | 3004 wsptr[DCTSIZE*5+wsptr_offset] = dcval; |
2982 wsptr[DCTSIZE*6+wsptr_offset] = dcval; | 3005 wsptr[DCTSIZE*6+wsptr_offset] = dcval; |
2983 wsptr[DCTSIZE*7+wsptr_offset] = dcval; | 3006 wsptr[DCTSIZE*7+wsptr_offset] = dcval; |
2984 | 3007 |
2985 inptr_offset++; /* advance pointers to next column */ | 3008 inptr_offset++; /* advance pointers to next column */ |
2986 quantptr_offset++; | 3009 quantptr_offset++; |
2987 wsptr_offset++; | 3010 wsptr_offset++; |
2988 continue; | 3011 continue; |
2989 } | 3012 } |
2990 | 3013 |
2991 /* Even part: reverse the even part of the forward DCT. */ | 3014 /* Even part: reverse the even part of the forward DCT. */ |
2992 /* The rotator is sqrt(2)*c(-6). */ | 3015 /* The rotator is sqrt(2)*c(-6). */ |
2993 | 3016 |
2994 z2 = ((inptr[DCTSIZE*2+inptr_offset]) * quantptr[DCTSIZE*2+quantptr_offset]); | 3017 z2 = ((inptr[DCTSIZE*2+inptr_offset]) * quantptr[DCTSIZE*2+quantptr_offset]); |
2995 z3 = ((inptr[DCTSIZE*6+inptr_offset]) * quantptr[DCTSIZE*6+quantptr_offset]); | 3018 z3 = ((inptr[DCTSIZE*6+inptr_offset]) * quantptr[DCTSIZE*6+quantptr_offset]); |
2996 | 3019 |
2997 z1 = ((z2 + z3) * 4433/*FIX_0_541196100*/); | 3020 z1 = ((z2 + z3) * 4433/*FIX_0_541196100*/); |
2998 tmp2 = z1 + (z3 * - 15137/*FIX_1_847759065*/); | 3021 tmp2 = z1 + (z3 * - 15137/*FIX_1_847759065*/); |
2999 tmp3 = z1 + (z2 * 6270/*FIX_0_765366865*/); | 3022 tmp3 = z1 + (z2 * 6270/*FIX_0_765366865*/); |
3000 | 3023 |
3001 z2 = ((inptr[DCTSIZE*0+inptr_offset]) * quantptr[DCTSIZE*0+quantptr_offset]); | 3024 z2 = ((inptr[DCTSIZE*0+inptr_offset]) * quantptr[DCTSIZE*0+quantptr_offset]); |
3002 z3 = ((inptr[DCTSIZE*4+inptr_offset]) * quantptr[DCTSIZE*4+quantptr_offset]); | 3025 z3 = ((inptr[DCTSIZE*4+inptr_offset]) * quantptr[DCTSIZE*4+quantptr_offset]); |
3003 | 3026 |
3004 tmp0 = (z2 + z3) << CONST_BITS; | 3027 tmp0 = (z2 + z3) << CONST_BITS; |
3005 tmp1 = (z2 - z3) << CONST_BITS; | 3028 tmp1 = (z2 - z3) << CONST_BITS; |
3006 | 3029 |
3007 tmp10 = tmp0 + tmp3; | 3030 tmp10 = tmp0 + tmp3; |
3008 tmp13 = tmp0 - tmp3; | 3031 tmp13 = tmp0 - tmp3; |
3009 tmp11 = tmp1 + tmp2; | 3032 tmp11 = tmp1 + tmp2; |
3010 tmp12 = tmp1 - tmp2; | 3033 tmp12 = tmp1 - tmp2; |
3011 | 3034 |
3012 /* Odd part per figure 8; the matrix is unitary and hence its | 3035 /* Odd part per figure 8; the matrix is unitary and hence its |
3013 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. | 3036 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. |
3014 */ | 3037 */ |
3015 | 3038 |
3016 tmp0 = ((inptr[DCTSIZE*7+inptr_offset]) * quantptr[DCTSIZE*7+quantptr_offset]); | 3039 tmp0 = ((inptr[DCTSIZE*7+inptr_offset]) * quantptr[DCTSIZE*7+quantptr_offset]); |
3017 tmp1 = ((inptr[DCTSIZE*5+inptr_offset]) * quantptr[DCTSIZE*5+quantptr_offset]); | 3040 tmp1 = ((inptr[DCTSIZE*5+inptr_offset]) * quantptr[DCTSIZE*5+quantptr_offset]); |
3018 tmp2 = ((inptr[DCTSIZE*3+inptr_offset]) * quantptr[DCTSIZE*3+quantptr_offset]); | 3041 tmp2 = ((inptr[DCTSIZE*3+inptr_offset]) * quantptr[DCTSIZE*3+quantptr_offset]); |
3019 tmp3 = ((inptr[DCTSIZE*1+inptr_offset]) * quantptr[DCTSIZE*1+quantptr_offset]); | 3042 tmp3 = ((inptr[DCTSIZE*1+inptr_offset]) * quantptr[DCTSIZE*1+quantptr_offset]); |
3020 | 3043 |
3021 z1 = tmp0 + tmp3; | 3044 z1 = tmp0 + tmp3; |
3022 z2 = tmp1 + tmp2; | 3045 z2 = tmp1 + tmp2; |
3023 z3 = tmp0 + tmp2; | 3046 z3 = tmp0 + tmp2; |
3024 z4 = tmp1 + tmp3; | 3047 z4 = tmp1 + tmp3; |
3025 z5 = ((z3 + z4) * 9633/*FIX_1_175875602*/); /* sqrt(2) * c3 */ | 3048 z5 = ((z3 + z4) * 9633/*FIX_1_175875602*/); /* sqrt(2) * c3 */ |
3026 | 3049 |
3027 tmp0 = (tmp0 * 2446/*FIX_0_298631336*/); /* sqrt(2) * (-c1+c3+c5-c7) */ | 3050 tmp0 = (tmp0 * 2446/*FIX_0_298631336*/); /* sqrt(2) * (-c1+c3+c5-c7) */ |
3028 tmp1 = (tmp1 * 16819/*FIX_2_053119869*/); /* sqrt(2) * ( c1+c3-c5+c7) */ | 3051 tmp1 = (tmp1 * 16819/*FIX_2_053119869*/); /* sqrt(2) * ( c1+c3-c5+c7) */ |
3029 tmp2 = (tmp2 * 25172/*FIX_3_072711026*/); /* sqrt(2) * ( c1+c3+c5-c7) */ | 3052 tmp2 = (tmp2 * 25172/*FIX_3_072711026*/); /* sqrt(2) * ( c1+c3+c5-c7) */ |
3030 tmp3 = (tmp3 * 12299/*FIX_1_501321110*/); /* sqrt(2) * ( c1+c3-c5-c7) */ | 3053 tmp3 = (tmp3 * 12299/*FIX_1_501321110*/); /* sqrt(2) * ( c1+c3-c5-c7) */ |
3031 z1 = (z1 * - 7373/*FIX_0_899976223*/); /* sqrt(2) * (c7-c3) */ | 3054 z1 = (z1 * - 7373/*FIX_0_899976223*/); /* sqrt(2) * (c7-c3) */ |
3032 z2 = (z2 * - 20995/*FIX_2_562915447*/); /* sqrt(2) * (-c1-c3) */ | 3055 z2 = (z2 * - 20995/*FIX_2_562915447*/); /* sqrt(2) * (-c1-c3) */ |
3033 z3 = (z3 * - 16069/*FIX_1_961570560*/); /* sqrt(2) * (-c3-c5) */ | 3056 z3 = (z3 * - 16069/*FIX_1_961570560*/); /* sqrt(2) * (-c3-c5) */ |
3034 z4 = (z4 * - 3196/*FIX_0_390180644*/); /* sqrt(2) * (c5-c3) */ | 3057 z4 = (z4 * - 3196/*FIX_0_390180644*/); /* sqrt(2) * (c5-c3) */ |
3035 | 3058 |
3036 z3 += z5; | 3059 z3 += z5; |
3037 z4 += z5; | 3060 z4 += z5; |
3038 | 3061 |
3039 tmp0 += z1 + z3; | 3062 tmp0 += z1 + z3; |
3040 tmp1 += z2 + z4; | 3063 tmp1 += z2 + z4; |
3041 tmp2 += z2 + z3; | 3064 tmp2 += z2 + z3; |
3042 tmp3 += z1 + z4; | 3065 tmp3 += z1 + z4; |
3043 | 3066 |
3044 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ | 3067 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ |
3045 | 3068 |
3046 // #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) | 3069 // #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) |
3047 wsptr[DCTSIZE*0+wsptr_offset] = (((tmp10 + tmp3) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); | 3070 wsptr[DCTSIZE*0+wsptr_offset] = (((tmp10 + tmp3) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); |
3048 wsptr[DCTSIZE*7+wsptr_offset] = (((tmp10 - tmp3) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); | 3071 wsptr[DCTSIZE*7+wsptr_offset] = (((tmp10 - tmp3) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); |
3049 wsptr[DCTSIZE*1+wsptr_offset] = (((tmp11 + tmp2) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); | 3072 wsptr[DCTSIZE*1+wsptr_offset] = (((tmp11 + tmp2) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); |
3050 wsptr[DCTSIZE*6+wsptr_offset] = (((tmp11 - tmp2) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); | 3073 wsptr[DCTSIZE*6+wsptr_offset] = (((tmp11 - tmp2) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); |
3051 wsptr[DCTSIZE*2+wsptr_offset] = (((tmp12 + tmp1) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); | 3074 wsptr[DCTSIZE*2+wsptr_offset] = (((tmp12 + tmp1) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); |
3052 wsptr[DCTSIZE*5+wsptr_offset] = (((tmp12 - tmp1) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); | 3075 wsptr[DCTSIZE*5+wsptr_offset] = (((tmp12 - tmp1) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); |
3053 wsptr[DCTSIZE*3+wsptr_offset] = (((tmp13 + tmp0) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); | 3076 wsptr[DCTSIZE*3+wsptr_offset] = (((tmp13 + tmp0) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); |
3054 wsptr[DCTSIZE*4+wsptr_offset] = (((tmp13 - tmp0) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); | 3077 wsptr[DCTSIZE*4+wsptr_offset] = (((tmp13 - tmp0) + (1 << ((CONST_BITS-PASS1_BITS)-1))) >> (CONST_BITS-PASS1_BITS)); |
3055 | 3078 |
3056 inptr_offset++; /* advance pointers to next column */ | 3079 inptr_offset++; /* advance pointers to next column */ |
3057 quantptr_offset++; | 3080 quantptr_offset++; |
3058 wsptr_offset++; | 3081 wsptr_offset++; |
3059 } | 3082 } |
3060 | 3083 |
3061 | 3084 |
3062 /* Pass 2: process rows from work array, store into output array. */ | 3085 /* Pass 2: process rows from work array, store into output array. */ |
3063 /* Note that we must descale the results by a factor of 8 is 2**3, */ | 3086 /* Note that we must descale the results by a factor of 8 is 2**3, */ |
3064 /* and also undo the PASS1_BITS scaling. */ | 3087 /* and also undo the PASS1_BITS scaling. */ |
3065 | 3088 |
3066 int outptr_offset = 0; | 3089 int outptr_offset = 0; |
3074 * the simplification applies less often (typically 5% to 10% of the time). | 3097 * the simplification applies less often (typically 5% to 10% of the time). |
3075 * On machines with very fast multiplication, it's possible that the | 3098 * On machines with very fast multiplication, it's possible that the |
3076 * test takes more time than it's worth. In that case this section | 3099 * test takes more time than it's worth. In that case this section |
3077 * may be commented out. | 3100 * may be commented out. |
3078 */ | 3101 */ |
3079 | 3102 |
3080 //#ifndef NO_ZERO_ROW_TEST | 3103 //#ifndef NO_ZERO_ROW_TEST |
3081 if (wsptr[1+wsptr_offset] is 0 && wsptr[2+wsptr_offset] is 0 && wsptr[3+wsptr_offset] is 0 && wsptr[4+wsptr_offset] is 0 && | 3104 if (wsptr[1+wsptr_offset] is 0 && wsptr[2+wsptr_offset] is 0 && wsptr[3+wsptr_offset] is 0 && wsptr[4+wsptr_offset] is 0 && |
3082 wsptr[5+wsptr_offset] is 0 && wsptr[6+wsptr_offset] is 0 && wsptr[7+wsptr_offset] is 0) | 3105 wsptr[5+wsptr_offset] is 0 && wsptr[6+wsptr_offset] is 0 && wsptr[7+wsptr_offset] is 0) |
3083 { | 3106 { |
3084 /* AC terms all zero */ | 3107 /* AC terms all zero */ |
3085 // #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) | 3108 // #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) |
3086 byte dcval = range_limit[range_limit_offset + ((((wsptr[0+wsptr_offset]) + (1 << ((PASS1_BITS+3)-1))) >> PASS1_BITS+3) | 3109 byte dcval = range_limit[range_limit_offset + ((((wsptr[0+wsptr_offset]) + (1 << ((PASS1_BITS+3)-1))) >> PASS1_BITS+3) |
3087 & RANGE_MASK)]; | 3110 & RANGE_MASK)]; |
3088 | 3111 |
3089 outptr[0+outptr_offset] = dcval; | 3112 outptr[0+outptr_offset] = dcval; |
3090 outptr[1+outptr_offset] = dcval; | 3113 outptr[1+outptr_offset] = dcval; |
3091 outptr[2+outptr_offset] = dcval; | 3114 outptr[2+outptr_offset] = dcval; |
3092 outptr[3+outptr_offset] = dcval; | 3115 outptr[3+outptr_offset] = dcval; |
3093 outptr[4+outptr_offset] = dcval; | 3116 outptr[4+outptr_offset] = dcval; |
3097 | 3120 |
3098 wsptr_offset += DCTSIZE; /* advance pointer to next row */ | 3121 wsptr_offset += DCTSIZE; /* advance pointer to next row */ |
3099 continue; | 3122 continue; |
3100 } | 3123 } |
3101 //#endif | 3124 //#endif |
3102 | 3125 |
3103 /* Even part: reverse the even part of the forward DCT. */ | 3126 /* Even part: reverse the even part of the forward DCT. */ |
3104 /* The rotator is sqrt(2)*c(-6). */ | 3127 /* The rotator is sqrt(2)*c(-6). */ |
3105 | 3128 |
3106 z2 = wsptr[2+wsptr_offset]; | 3129 z2 = wsptr[2+wsptr_offset]; |
3107 z3 = wsptr[6+wsptr_offset]; | 3130 z3 = wsptr[6+wsptr_offset]; |
3108 | 3131 |
3109 z1 = ((z2 + z3) * 4433/*FIX_0_541196100*/); | 3132 z1 = ((z2 + z3) * 4433/*FIX_0_541196100*/); |
3110 tmp2 = z1 + (z3 * - 15137/*FIX_1_847759065*/); | 3133 tmp2 = z1 + (z3 * - 15137/*FIX_1_847759065*/); |
3111 tmp3 = z1 + (z2 * 6270/*FIX_0_765366865*/); | 3134 tmp3 = z1 + (z2 * 6270/*FIX_0_765366865*/); |
3112 | 3135 |
3113 tmp0 = (wsptr[0+wsptr_offset] + wsptr[4+wsptr_offset]) << CONST_BITS; | 3136 tmp0 = (wsptr[0+wsptr_offset] + wsptr[4+wsptr_offset]) << CONST_BITS; |
3114 tmp1 = (wsptr[0+wsptr_offset] - wsptr[4+wsptr_offset]) << CONST_BITS; | 3137 tmp1 = (wsptr[0+wsptr_offset] - wsptr[4+wsptr_offset]) << CONST_BITS; |
3115 | 3138 |
3116 tmp10 = tmp0 + tmp3; | 3139 tmp10 = tmp0 + tmp3; |
3117 tmp13 = tmp0 - tmp3; | 3140 tmp13 = tmp0 - tmp3; |
3118 tmp11 = tmp1 + tmp2; | 3141 tmp11 = tmp1 + tmp2; |
3119 tmp12 = tmp1 - tmp2; | 3142 tmp12 = tmp1 - tmp2; |
3120 | 3143 |
3121 /* Odd part per figure 8; the matrix is unitary and hence its | 3144 /* Odd part per figure 8; the matrix is unitary and hence its |
3122 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. | 3145 * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. |
3123 */ | 3146 */ |
3124 | 3147 |
3125 tmp0 = wsptr[7+wsptr_offset]; | 3148 tmp0 = wsptr[7+wsptr_offset]; |
3126 tmp1 = wsptr[5+wsptr_offset]; | 3149 tmp1 = wsptr[5+wsptr_offset]; |
3127 tmp2 = wsptr[3+wsptr_offset]; | 3150 tmp2 = wsptr[3+wsptr_offset]; |
3128 tmp3 = wsptr[1+wsptr_offset]; | 3151 tmp3 = wsptr[1+wsptr_offset]; |
3129 | 3152 |
3130 z1 = tmp0 + tmp3; | 3153 z1 = tmp0 + tmp3; |
3131 z2 = tmp1 + tmp2; | 3154 z2 = tmp1 + tmp2; |
3132 z3 = tmp0 + tmp2; | 3155 z3 = tmp0 + tmp2; |
3133 z4 = tmp1 + tmp3; | 3156 z4 = tmp1 + tmp3; |
3134 z5 = ((z3 + z4) * 9633/*FIX_1_175875602*/); /* sqrt(2) * c3 */ | 3157 z5 = ((z3 + z4) * 9633/*FIX_1_175875602*/); /* sqrt(2) * c3 */ |
3135 | 3158 |
3136 tmp0 = (tmp0 * 2446/*FIX_0_298631336*/); /* sqrt(2) * (-c1+c3+c5-c7) */ | 3159 tmp0 = (tmp0 * 2446/*FIX_0_298631336*/); /* sqrt(2) * (-c1+c3+c5-c7) */ |
3137 tmp1 = (tmp1 * 16819/*FIX_2_053119869*/); /* sqrt(2) * ( c1+c3-c5+c7) */ | 3160 tmp1 = (tmp1 * 16819/*FIX_2_053119869*/); /* sqrt(2) * ( c1+c3-c5+c7) */ |
3138 tmp2 = (tmp2 * 25172/*FIX_3_072711026*/); /* sqrt(2) * ( c1+c3+c5-c7) */ | 3161 tmp2 = (tmp2 * 25172/*FIX_3_072711026*/); /* sqrt(2) * ( c1+c3+c5-c7) */ |
3139 tmp3 = (tmp3 * 12299/*FIX_1_501321110*/); /* sqrt(2) * ( c1+c3-c5-c7) */ | 3162 tmp3 = (tmp3 * 12299/*FIX_1_501321110*/); /* sqrt(2) * ( c1+c3-c5-c7) */ |
3140 z1 = (z1 * - 7373/*FIX_0_899976223*/); /* sqrt(2) * (c7-c3) */ | 3163 z1 = (z1 * - 7373/*FIX_0_899976223*/); /* sqrt(2) * (c7-c3) */ |
3141 z2 = (z2 * - 20995/*FIX_2_562915447*/); /* sqrt(2) * (-c1-c3) */ | 3164 z2 = (z2 * - 20995/*FIX_2_562915447*/); /* sqrt(2) * (-c1-c3) */ |
3142 z3 = (z3 * - 16069/*FIX_1_961570560*/); /* sqrt(2) * (-c3-c5) */ | 3165 z3 = (z3 * - 16069/*FIX_1_961570560*/); /* sqrt(2) * (-c3-c5) */ |
3143 z4 = (z4 * - 3196/*FIX_0_390180644*/); /* sqrt(2) * (c5-c3) */ | 3166 z4 = (z4 * - 3196/*FIX_0_390180644*/); /* sqrt(2) * (c5-c3) */ |
3144 | 3167 |
3145 z3 += z5; | 3168 z3 += z5; |
3146 z4 += z5; | 3169 z4 += z5; |
3147 | 3170 |
3148 tmp0 += z1 + z3; | 3171 tmp0 += z1 + z3; |
3149 tmp1 += z2 + z4; | 3172 tmp1 += z2 + z4; |
3150 tmp2 += z2 + z3; | 3173 tmp2 += z2 + z3; |
3151 tmp3 += z1 + z4; | 3174 tmp3 += z1 + z4; |
3152 | 3175 |
3153 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ | 3176 /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ |
3154 | 3177 |
3155 | 3178 |
3156 // #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) | 3179 // #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) |
3157 outptr[0+outptr_offset] = range_limit[range_limit_offset + ((((tmp10 + tmp3) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >> | 3180 outptr[0+outptr_offset] = range_limit[range_limit_offset + ((((tmp10 + tmp3) + (1 << ((CONST_BITS+PASS1_BITS+3)-1))) >> |
3158 CONST_BITS+PASS1_BITS+3) | 3181 CONST_BITS+PASS1_BITS+3) |
3159 & RANGE_MASK)]; | 3182 & RANGE_MASK)]; |
3490 start_output_pass (cinfo); | 3513 start_output_pass (cinfo); |
3491 if (! cinfo.raw_data_out) { | 3514 if (! cinfo.raw_data_out) { |
3492 if (! master.using_merged_upsample) | 3515 if (! master.using_merged_upsample) |
3493 cinfo.cconvert.start_pass (cinfo); | 3516 cinfo.cconvert.start_pass (cinfo); |
3494 cinfo.upsample.start_pass (cinfo); | 3517 cinfo.upsample.start_pass (cinfo); |
3495 if (cinfo.quantize_colors) | 3518 if (cinfo.quantize_colors) |
3496 cinfo.cquantize.start_pass (cinfo, master.is_dummy_pass); | 3519 cinfo.cquantize.start_pass (cinfo, master.is_dummy_pass); |
3497 cinfo.post.start_pass (cinfo, (master.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); | 3520 cinfo.post.start_pass (cinfo, (master.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); |
3498 cinfo.main.start_pass (cinfo, JBUF_PASS_THRU); | 3521 cinfo.main.start_pass (cinfo, JBUF_PASS_THRU); |
3499 } | 3522 } |
3500 } | 3523 } |
3515 | 3538 |
3516 | 3539 |
3517 static bool jpeg_resync_to_restart (jpeg_decompress_struct cinfo, int desired) { | 3540 static bool jpeg_resync_to_restart (jpeg_decompress_struct cinfo, int desired) { |
3518 int marker = cinfo.unread_marker; | 3541 int marker = cinfo.unread_marker; |
3519 int action = 1; | 3542 int action = 1; |
3520 | 3543 |
3521 /* Always put up a warning. */ | 3544 /* Always put up a warning. */ |
3522 // WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired); | 3545 // WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired); |
3523 | 3546 |
3524 /* Outer loop handles repeated decision after scanning forward. */ | 3547 /* Outer loop handles repeated decision after scanning forward. */ |
3525 for (;;) { | 3548 for (;;) { |
3526 if (marker < M_SOF0) | 3549 if (marker < M_SOF0) |
3527 action = 2; /* invalid marker */ | 3550 action = 2; /* invalid marker */ |
3528 else if (marker < M_RST0 || marker > M_RST7) | 3551 else if (marker < M_RST0 || marker > M_RST7) |
3549 break; | 3572 break; |
3550 case 3: | 3573 case 3: |
3551 /* Return without advancing past this marker. */ | 3574 /* Return without advancing past this marker. */ |
3552 /* Entropy decoder will be forced to process an empty segment. */ | 3575 /* Entropy decoder will be forced to process an empty segment. */ |
3553 return true; | 3576 return true; |
3577 default: | |
3554 } | 3578 } |
3555 } /* end loop */ | 3579 } /* end loop */ |
3556 } | 3580 } |
3557 | 3581 |
3558 static bool read_restart_marker (jpeg_decompress_struct cinfo) { | 3582 static bool read_restart_marker (jpeg_decompress_struct cinfo) { |
3661 state.bytes_offset = bytes_offset; | 3685 state.bytes_offset = bytes_offset; |
3662 state.get_buffer = get_buffer; | 3686 state.get_buffer = get_buffer; |
3663 state.bits_left = bits_left; | 3687 state.bits_left = bits_left; |
3664 | 3688 |
3665 return true; | 3689 return true; |
3666 | 3690 |
3667 } | 3691 } |
3668 } | 3692 } |
3669 | 3693 |
3670 /* OK, load c into get_buffer */ | 3694 /* OK, load c into get_buffer */ |
3671 get_buffer = (get_buffer << 8) | c; | 3695 get_buffer = (get_buffer << 8) | c; |
3711 /* bits long, so fetch that many bits in one swoop. */ | 3735 /* bits long, so fetch that many bits in one swoop. */ |
3712 | 3736 |
3713 // CHECK_BIT_BUFFER(*state, l, return -1); | 3737 // CHECK_BIT_BUFFER(*state, l, return -1); |
3714 { | 3738 { |
3715 if (bits_left < (l)) { | 3739 if (bits_left < (l)) { |
3716 if (! jpeg_fill_bit_buffer(state,get_buffer,bits_left,l)) { | 3740 if (! jpeg_fill_bit_buffer(state,get_buffer,bits_left,l)) { |
3717 return -1; | 3741 return -1; |
3718 } | 3742 } |
3719 get_buffer = (state).get_buffer; bits_left = (state).bits_left; | 3743 get_buffer = state.get_buffer; bits_left = state.bits_left; |
3720 } | 3744 } |
3721 } | 3745 } |
3722 // code = GET_BITS(l); | 3746 // code = GET_BITS(l); |
3723 code = (( (get_buffer >> (bits_left -= (l)))) & ((1<<(l))-1)); | 3747 code = (( (get_buffer >> (bits_left -= (l)))) & ((1<<(l))-1)); |
3724 | 3748 |
3728 while (code > htbl.maxcode[l]) { | 3752 while (code > htbl.maxcode[l]) { |
3729 code <<= 1; | 3753 code <<= 1; |
3730 // CHECK_BIT_BUFFER(*state, 1, return -1); | 3754 // CHECK_BIT_BUFFER(*state, 1, return -1); |
3731 { | 3755 { |
3732 if (bits_left < (1)) { | 3756 if (bits_left < (1)) { |
3733 if (! jpeg_fill_bit_buffer(state,get_buffer,bits_left,1)) { | 3757 if (! jpeg_fill_bit_buffer(state,get_buffer,bits_left,1)) { |
3734 return -1; | 3758 return -1; |
3735 } | 3759 } |
3736 get_buffer = (state).get_buffer; bits_left = (state).bits_left; | 3760 get_buffer = state.get_buffer; bits_left = state.bits_left; |
3737 } | 3761 } |
3738 } | 3762 } |
3739 // code |= GET_BITS(1); | 3763 // code |= GET_BITS(1); |
3740 code |= (( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)); | 3764 code |= (( (get_buffer >> (bits_left -= (1)))) & ((1<<(1))-1)); |
3741 l++; | 3765 l++; |
4247 /* Still need to process last row group of this iMCU row, */ | 4271 /* Still need to process last row group of this iMCU row, */ |
4248 /* which is saved at index M+1 of the other xbuffer */ | 4272 /* which is saved at index M+1 of the other xbuffer */ |
4249 main.rowgroup_ctr[0] = (cinfo.min_DCT_scaled_size + 1); | 4273 main.rowgroup_ctr[0] = (cinfo.min_DCT_scaled_size + 1); |
4250 main.rowgroups_avail = (cinfo.min_DCT_scaled_size + 2); | 4274 main.rowgroups_avail = (cinfo.min_DCT_scaled_size + 2); |
4251 main.context_state = CTX_POSTPONED_ROW; | 4275 main.context_state = CTX_POSTPONED_ROW; |
4276 default: | |
4252 } | 4277 } |
4253 } | 4278 } |
4254 | 4279 |
4255 static void process_data_simple_main (jpeg_decompress_struct cinfo, byte[][] output_buf, int[] out_row_ctr, int out_rows_avail) { | 4280 static void process_data_simple_main (jpeg_decompress_struct cinfo, byte[][] output_buf, int[] out_row_ctr, int out_rows_avail) { |
4256 jpeg_d_main_controller main = cinfo.main; | 4281 jpeg_d_main_controller main = cinfo.main; |
4264 result = decompress_data(cinfo, main.buffer, main.buffer_offset); | 4289 result = decompress_data(cinfo, main.buffer, main.buffer_offset); |
4265 break; | 4290 break; |
4266 case DECOMPRESS_SMOOTH_DATA: | 4291 case DECOMPRESS_SMOOTH_DATA: |
4267 result = decompress_smooth_data(cinfo, main.buffer, main.buffer_offset); | 4292 result = decompress_smooth_data(cinfo, main.buffer, main.buffer_offset); |
4268 break; | 4293 break; |
4269 case DECOMPRESS_ONEPASS: | 4294 case DECOMPRESS_ONEPASS: |
4270 result = decompress_onepass(cinfo, main.buffer, main.buffer_offset); | 4295 result = decompress_onepass(cinfo, main.buffer, main.buffer_offset); |
4271 break; | 4296 break; |
4272 default: result = 0; | 4297 default: result = 0; |
4273 } | 4298 } |
4274 if (result is 0) | 4299 if (result is 0) |
4349 // cinfo.progress.pass_limit = cast(long) cinfo.output_height; | 4374 // cinfo.progress.pass_limit = cast(long) cinfo.output_height; |
4350 // (*cinfo.progress.progress_monitor) ((j_common_ptr) cinfo); | 4375 // (*cinfo.progress.progress_monitor) ((j_common_ptr) cinfo); |
4351 // } | 4376 // } |
4352 // /* Process some data */ | 4377 // /* Process some data */ |
4353 // last_scanline = cinfo.output_scanline; | 4378 // last_scanline = cinfo.output_scanline; |
4354 // (*cinfo.main.process_data) (cinfo, cast(JSAMPARRAY) NULL, | 4379 // (*cinfo.main.process_data) (cinfo, (JSAMPARRAY) NULL, |
4355 // &cinfo.output_scanline, cast(JDIMENSION) 0); | 4380 // &cinfo.output_scanline, (JDIMENSION) 0); |
4356 // if (cinfo.output_scanline is last_scanline) | 4381 // if (cinfo.output_scanline is last_scanline) |
4357 // return FALSE; /* No progress made, must suspend */ | 4382 // return FALSE; /* No progress made, must suspend */ |
4358 // } | 4383 // } |
4359 // /* Finish up dummy pass, and set up for another one */ | 4384 // /* Finish up dummy pass, and set up for another one */ |
4360 // (*cinfo.master.finish_output_pass) (cinfo); | 4385 // (*cinfo.master.finish_output_pass) (cinfo); |
4383 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4408 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4384 length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; | 4409 length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; |
4385 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4410 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4386 length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4411 length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4387 length -= 2; | 4412 length -= 2; |
4388 | 4413 |
4389 while (length > 16) { | 4414 while (length > 16) { |
4390 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4415 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4391 index = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4416 index = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4392 | 4417 |
4393 // TRACEMS1(cinfo, 1, JTRC_DHT, index); | 4418 // TRACEMS1(cinfo, 1, JTRC_DHT, index); |
4394 | 4419 |
4395 bits[0] = 0; | 4420 bits[0] = 0; |
4396 count = 0; | 4421 count = 0; |
4397 for (i = 1; i <= 16; i++) { | 4422 for (i = 1; i <= 16; i++) { |
4398 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4423 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4399 bits[i] = cinfo.buffer[cinfo.bytes_offset++]; | 4424 bits[i] = cinfo.buffer[cinfo.bytes_offset++]; |
4421 huffval[i] = cinfo.buffer[cinfo.bytes_offset++]; | 4446 huffval[i] = cinfo.buffer[cinfo.bytes_offset++]; |
4422 } | 4447 } |
4423 | 4448 |
4424 length -= count; | 4449 length -= count; |
4425 | 4450 |
4426 if ((index & 0x10) !is 0) { /* AC table definition */ | 4451 if ((index & 0x10) !is 0) { /* AC table definition */ |
4427 index -= 0x10; | 4452 index -= 0x10; |
4428 htblptr = cinfo.ac_huff_tbl_ptrs[index] = new JHUFF_TBL(); | 4453 htblptr = cinfo.ac_huff_tbl_ptrs[index] = new JHUFF_TBL(); |
4429 } else { /* DC table definition */ | 4454 } else { /* DC table definition */ |
4430 htblptr = cinfo.dc_huff_tbl_ptrs[index] = new JHUFF_TBL(); | 4455 htblptr = cinfo.dc_huff_tbl_ptrs[index] = new JHUFF_TBL(); |
4431 } | 4456 } |
4469 // TRACEMS2(cinfo, 1, JTRC_DQT, n, prec); | 4494 // TRACEMS2(cinfo, 1, JTRC_DQT, n, prec); |
4470 | 4495 |
4471 if (n >= NUM_QUANT_TBLS) | 4496 if (n >= NUM_QUANT_TBLS) |
4472 error(); | 4497 error(); |
4473 // ERREXIT1(cinfo, JERR_DQT_INDEX, n); | 4498 // ERREXIT1(cinfo, JERR_DQT_INDEX, n); |
4474 | 4499 |
4475 if (cinfo.quant_tbl_ptrs[n] is null) | 4500 if (cinfo.quant_tbl_ptrs[n] is null) |
4476 cinfo.quant_tbl_ptrs[n] = new JQUANT_TBL(); | 4501 cinfo.quant_tbl_ptrs[n] = new JQUANT_TBL(); |
4477 quant_ptr = cinfo.quant_tbl_ptrs[n]; | 4502 quant_ptr = cinfo.quant_tbl_ptrs[n]; |
4478 | 4503 |
4479 for (i = 0; i < DCTSIZE2; i++) { | 4504 for (i = 0; i < DCTSIZE2; i++) { |
4519 | 4544 |
4520 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4545 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4521 length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; | 4546 length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; |
4522 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4547 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4523 length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4548 length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4524 | 4549 |
4525 if (length !is 4) | 4550 if (length !is 4) |
4526 error(); | 4551 error(); |
4527 // ERREXIT(cinfo, JERR_BAD_LENGTH); | 4552 // ERREXIT(cinfo, JERR_BAD_LENGTH); |
4528 | 4553 |
4529 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4554 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4546 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4571 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4547 length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; | 4572 length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; |
4548 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4573 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4549 length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4574 length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4550 length -= 2; | 4575 length -= 2; |
4551 | 4576 |
4552 while (length > 0) { | 4577 while (length > 0) { |
4553 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4578 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4554 index = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4579 index = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4555 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4580 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4556 val = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4581 val = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4614 for (i = 0; i < n; i++) { | 4639 for (i = 0; i < n; i++) { |
4615 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4640 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4616 cc = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4641 cc = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4617 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4642 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4618 c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4643 c = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4619 | 4644 |
4620 for (ci = 0; ci < cinfo.num_components; ci++) { | 4645 for (ci = 0; ci < cinfo.num_components; ci++) { |
4621 compptr = cinfo.comp_info[ci]; | 4646 compptr = cinfo.comp_info[ci]; |
4622 if (cc is compptr.component_id) | 4647 if (cc is compptr.component_id) |
4623 break; | 4648 break; |
4624 } | 4649 } |
4628 // ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc); | 4653 // ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc); |
4629 | 4654 |
4630 cinfo.cur_comp_info[i] = compptr; | 4655 cinfo.cur_comp_info[i] = compptr; |
4631 compptr.dc_tbl_no = (c >> 4) & 15; | 4656 compptr.dc_tbl_no = (c >> 4) & 15; |
4632 compptr.ac_tbl_no = (c ) & 15; | 4657 compptr.ac_tbl_no = (c ) & 15; |
4633 | 4658 |
4634 // TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc, compptr.dc_tbl_no, compptr.ac_tbl_no); | 4659 // TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc, compptr.dc_tbl_no, compptr.ac_tbl_no); |
4635 } | 4660 } |
4636 | 4661 |
4637 /* Collect the additional scan parameters Ss, Se, Ah/Al. */ | 4662 /* Collect the additional scan parameters Ss, Se, Ah/Al. */ |
4638 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4663 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4679 | 4704 |
4680 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4705 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4681 cinfo.image_width = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; | 4706 cinfo.image_width = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; |
4682 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4707 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4683 cinfo.image_width |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4708 cinfo.image_width |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4684 | 4709 |
4685 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4710 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4686 cinfo.num_components = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4711 cinfo.num_components = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4687 | 4712 |
4688 length -= 8; | 4713 length -= 8; |
4689 | 4714 |
4706 error(); | 4731 error(); |
4707 // ERREXIT(cinfo, JERR_BAD_LENGTH); | 4732 // ERREXIT(cinfo, JERR_BAD_LENGTH); |
4708 | 4733 |
4709 if (cinfo.comp_info is null) /* do only once, even if suspend */ | 4734 if (cinfo.comp_info is null) /* do only once, even if suspend */ |
4710 cinfo.comp_info = new jpeg_component_info[cinfo.num_components]; | 4735 cinfo.comp_info = new jpeg_component_info[cinfo.num_components]; |
4711 | 4736 |
4712 for (ci = 0; ci < cinfo.num_components; ci++) { | 4737 for (ci = 0; ci < cinfo.num_components; ci++) { |
4713 jpeg_component_info compptr = cinfo.comp_info[ci] = new jpeg_component_info(); | 4738 jpeg_component_info compptr = cinfo.comp_info[ci] = new jpeg_component_info(); |
4714 compptr.component_index = ci; | 4739 compptr.component_index = ci; |
4715 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 4740 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
4716 compptr.component_id = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 4741 compptr.component_id = cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
4754 case H2V1_FANCY_UPSAMPLE: h2v1_fancy_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; | 4779 case H2V1_FANCY_UPSAMPLE: h2v1_fancy_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; |
4755 case H2V1_UPSAMPLE: h2v1_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; | 4780 case H2V1_UPSAMPLE: h2v1_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; |
4756 case H2V2_FANCY_UPSAMPLE: h2v2_fancy_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; | 4781 case H2V2_FANCY_UPSAMPLE: h2v2_fancy_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; |
4757 case H2V2_UPSAMPLE: h2v2_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; | 4782 case H2V2_UPSAMPLE: h2v2_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; |
4758 case INT_UPSAMPLE: int_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; | 4783 case INT_UPSAMPLE: int_upsample(cinfo, compptr, input_buf[ci], offset, upsample.color_buf, upsample.color_buf_offset, ci); break; |
4784 default: | |
4759 } | 4785 } |
4760 } | 4786 } |
4761 upsample.next_row_out = 0; | 4787 upsample.next_row_out = 0; |
4762 } | 4788 } |
4763 | 4789 |
4766 /* How many we have in the buffer: */ | 4792 /* How many we have in the buffer: */ |
4767 num_rows = (cinfo.max_v_samp_factor - upsample.next_row_out); | 4793 num_rows = (cinfo.max_v_samp_factor - upsample.next_row_out); |
4768 /* Not more than the distance to the end of the image. Need this test | 4794 /* Not more than the distance to the end of the image. Need this test |
4769 * in case the image height is not a multiple of max_v_samp_factor: | 4795 * in case the image height is not a multiple of max_v_samp_factor: |
4770 */ | 4796 */ |
4771 if (num_rows > upsample.rows_to_go) | 4797 if (num_rows > upsample.rows_to_go) |
4772 num_rows = upsample.rows_to_go; | 4798 num_rows = upsample.rows_to_go; |
4773 /* And not more than what the client can accept: */ | 4799 /* And not more than what the client can accept: */ |
4774 out_rows_avail -= out_row_ctr[0]; | 4800 out_rows_avail -= out_row_ctr[0]; |
4775 if (num_rows > out_rows_avail) | 4801 if (num_rows > out_rows_avail) |
4776 num_rows = out_rows_avail; | 4802 num_rows = out_rows_avail; |
4779 case NULL_CONVERT: null_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break; | 4805 case NULL_CONVERT: null_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break; |
4780 case GRAYSCALE_CONVERT: grayscale_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break; | 4806 case GRAYSCALE_CONVERT: grayscale_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break; |
4781 case YCC_RGB_CONVERT: ycc_rgb_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break; | 4807 case YCC_RGB_CONVERT: ycc_rgb_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break; |
4782 case GRAY_RGB_CONVERT: gray_rgb_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break; | 4808 case GRAY_RGB_CONVERT: gray_rgb_convert (cinfo, upsample.color_buf, upsample.color_buf_offset, upsample.next_row_out, output_buf, out_row_ctr[0], num_rows); break; |
4783 case YCCK_CMYK_CONVERT: error(); break; | 4809 case YCCK_CMYK_CONVERT: error(); break; |
4810 default: | |
4784 } | 4811 } |
4785 | 4812 |
4786 /* Adjust counts */ | 4813 /* Adjust counts */ |
4787 out_row_ctr[0] += num_rows; | 4814 out_row_ctr[0] += num_rows; |
4788 upsample.rows_to_go -= num_rows; | 4815 upsample.rows_to_go -= num_rows; |
4790 /* When the buffer is emptied, declare this input row group consumed */ | 4817 /* When the buffer is emptied, declare this input row group consumed */ |
4791 if (upsample.next_row_out >= cinfo.max_v_samp_factor) { | 4818 if (upsample.next_row_out >= cinfo.max_v_samp_factor) { |
4792 in_row_group_ctr[0]++; | 4819 in_row_group_ctr[0]++; |
4793 } | 4820 } |
4794 } | 4821 } |
4795 | 4822 |
4796 static void noop_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, | 4823 static void noop_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, |
4797 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) | 4824 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) |
4798 { | 4825 { |
4799 output_data_ptr[output_data_index] = null; /* safety check */ | 4826 output_data_ptr[output_data_index] = null; /* safety check */ |
4800 } | 4827 } |
4801 | 4828 |
4802 static void fullsize_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, | 4829 static void fullsize_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, |
4803 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) | 4830 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) |
4804 { | 4831 { |
4805 output_data_ptr[output_data_index] = input_data; | 4832 output_data_ptr[output_data_index] = input_data; |
4806 output_data_offset[output_data_index] = input_data_offset; | 4833 output_data_offset[output_data_index] = input_data_offset; |
4807 } | 4834 } |
4808 | 4835 |
4809 static void h2v1_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, | 4836 static void h2v1_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, |
4810 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) | 4837 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) |
4811 { | 4838 { |
4812 byte[][] output_data = output_data_ptr[output_data_index]; | 4839 byte[][] output_data = output_data_ptr[output_data_index]; |
4813 byte[] inptr, outptr; | 4840 byte[] inptr, outptr; |
4826 outptr[outptr_offset++] = invalue; | 4853 outptr[outptr_offset++] = invalue; |
4827 outptr[outptr_offset++] = invalue; | 4854 outptr[outptr_offset++] = invalue; |
4828 } | 4855 } |
4829 } | 4856 } |
4830 } | 4857 } |
4831 | 4858 |
4832 static void h2v2_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, | 4859 static void h2v2_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, |
4833 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) | 4860 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) |
4834 { | 4861 { |
4835 byte[][] output_data = output_data_ptr[output_data_index]; | 4862 byte[][] output_data = output_data_ptr[output_data_index]; |
4836 byte[] inptr, outptr; | 4863 byte[] inptr, outptr; |
4853 jcopy_sample_rows(output_data, outrow, output_data, outrow+1, 1, cinfo.output_width); | 4880 jcopy_sample_rows(output_data, outrow, output_data, outrow+1, 1, cinfo.output_width); |
4854 inrow++; | 4881 inrow++; |
4855 outrow += 2; | 4882 outrow += 2; |
4856 } | 4883 } |
4857 } | 4884 } |
4858 | 4885 |
4859 static void h2v1_fancy_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, | 4886 static void h2v1_fancy_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, |
4860 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) | 4887 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) |
4861 { | 4888 { |
4862 byte[][] output_data = output_data_ptr[output_data_index]; | 4889 byte[][] output_data = output_data_ptr[output_data_index]; |
4863 byte[] inptr, outptr; | 4890 byte[] inptr, outptr; |
4864 int invalue; | 4891 int invalue; |
4865 int colctr; | 4892 int colctr; |
4866 int inrow; | 4893 int inrow; |
4867 output_data_offset[output_data_index] = 0; | 4894 output_data_offset[output_data_index] = 0; |
4868 | 4895 |
4869 for (inrow = 0; inrow < cinfo.max_v_samp_factor; inrow++) { | 4896 for (inrow = 0; inrow < cinfo.max_v_samp_factor; inrow++) { |
4870 inptr = input_data[inrow+input_data_offset]; | 4897 inptr = input_data[inrow+input_data_offset]; |
4871 outptr = output_data[inrow]; | 4898 outptr = output_data[inrow]; |
4886 invalue = (inptr[inptr_offset] & 0xFF); | 4913 invalue = (inptr[inptr_offset] & 0xFF); |
4887 outptr[outptr_offset++] = cast(byte) ((invalue * 3 + (inptr[inptr_offset-1] & 0xFF) + 1) >> 2); | 4914 outptr[outptr_offset++] = cast(byte) ((invalue * 3 + (inptr[inptr_offset-1] & 0xFF) + 1) >> 2); |
4888 outptr[outptr_offset++] = cast(byte) invalue; | 4915 outptr[outptr_offset++] = cast(byte) invalue; |
4889 } | 4916 } |
4890 } | 4917 } |
4891 | 4918 |
4892 static void h2v2_fancy_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, | 4919 static void h2v2_fancy_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, |
4893 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) | 4920 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) |
4894 { | 4921 { |
4895 byte[][] output_data = output_data_ptr[output_data_index]; | 4922 byte[][] output_data = output_data_ptr[output_data_index]; |
4896 byte[] inptr0, inptr1, outptr; | 4923 byte[] inptr0, inptr1, outptr; |
4907 if (v is 0) /* next nearest is row above */ | 4934 if (v is 0) /* next nearest is row above */ |
4908 inptr1 = input_data[inrow-1+input_data_offset]; | 4935 inptr1 = input_data[inrow-1+input_data_offset]; |
4909 else /* next nearest is row below */ | 4936 else /* next nearest is row below */ |
4910 inptr1 = input_data[inrow+1+input_data_offset]; | 4937 inptr1 = input_data[inrow+1+input_data_offset]; |
4911 outptr = output_data[outrow++]; | 4938 outptr = output_data[outrow++]; |
4912 | 4939 |
4913 int inptr0_offset = 0, inptr1_offset = 0, outptr_offset = 0; | 4940 int inptr0_offset = 0, inptr1_offset = 0, outptr_offset = 0; |
4914 | 4941 |
4915 /* Special case for first column */ | 4942 /* Special case for first column */ |
4916 thiscolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); | 4943 thiscolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); |
4917 nextcolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); | 4944 nextcolsum = (inptr0[inptr0_offset++] & 0xFF) * 3 + (inptr1[inptr1_offset++] & 0xFF); |
4933 outptr[outptr_offset++] = cast(byte) ((thiscolsum * 4 + 7) >> 4); | 4960 outptr[outptr_offset++] = cast(byte) ((thiscolsum * 4 + 7) >> 4); |
4934 } | 4961 } |
4935 inrow++; | 4962 inrow++; |
4936 } | 4963 } |
4937 } | 4964 } |
4938 | 4965 |
4939 static void int_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, | 4966 static void int_upsample (jpeg_decompress_struct cinfo, jpeg_component_info compptr, |
4940 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) | 4967 byte[][] input_data, int input_data_offset, byte[][][] output_data_ptr, int[] output_data_offset, int output_data_index) |
4941 { | 4968 { |
4942 jpeg_upsampler upsample = cinfo.upsample; | 4969 jpeg_upsampler upsample = cinfo.upsample; |
4943 byte[][] output_data = output_data_ptr[output_data_index]; | 4970 byte[][] output_data = output_data_ptr[output_data_index]; |
4946 int h; | 4973 int h; |
4947 int outend; | 4974 int outend; |
4948 int h_expand, v_expand; | 4975 int h_expand, v_expand; |
4949 int inrow, outrow; | 4976 int inrow, outrow; |
4950 output_data_offset[output_data_index] = 0; | 4977 output_data_offset[output_data_index] = 0; |
4951 | 4978 |
4952 h_expand = upsample.h_expand[compptr.component_index]; | 4979 h_expand = upsample.h_expand[compptr.component_index]; |
4953 v_expand = upsample.v_expand[compptr.component_index]; | 4980 v_expand = upsample.v_expand[compptr.component_index]; |
4954 | 4981 |
4955 inrow = outrow = 0; | 4982 inrow = outrow = 0; |
4956 while (outrow < cinfo.max_v_samp_factor) { | 4983 while (outrow < cinfo.max_v_samp_factor) { |
4993 int offset = 0; | 5020 int offset = 0; |
4994 switch (ci) { | 5021 switch (ci) { |
4995 case 2: offset = RGB_BLUE; break; | 5022 case 2: offset = RGB_BLUE; break; |
4996 case 1: offset = RGB_GREEN; break; | 5023 case 1: offset = RGB_GREEN; break; |
4997 case 0: offset = RGB_RED; break; | 5024 case 0: offset = RGB_RED; break; |
5025 default: | |
4998 } | 5026 } |
4999 int outptr_offset = offset, inptr_offset = 0; | 5027 int outptr_offset = offset, inptr_offset = 0; |
5000 for (count = num_cols; count > 0; count--) { | 5028 for (count = num_cols; count > 0; count--) { |
5001 outptr[outptr_offset] = inptr[inptr_offset++]; /* needn't bother with GETJSAMPLE() here */ | 5029 outptr[outptr_offset] = inptr[inptr_offset++]; /* needn't bother with GETJSAMPLE() here */ |
5002 outptr_offset += num_components; | 5030 outptr_offset += num_components; |
5004 } | 5032 } |
5005 input_row++; | 5033 input_row++; |
5006 output_buf_offset++; | 5034 output_buf_offset++; |
5007 } | 5035 } |
5008 } | 5036 } |
5009 | 5037 |
5010 static void grayscale_convert (jpeg_decompress_struct cinfo, | 5038 static void grayscale_convert (jpeg_decompress_struct cinfo, |
5011 byte[][][] input_buf, int[] input_buf_offset, int input_row, | 5039 byte[][][] input_buf, int[] input_buf_offset, int input_row, |
5012 byte[][] output_buf, int output_buf_offset, int num_rows) | 5040 byte[][] output_buf, int output_buf_offset, int num_rows) |
5013 { | 5041 { |
5014 jcopy_sample_rows(input_buf[0], input_row+input_buf_offset[0], output_buf, output_buf_offset, | 5042 jcopy_sample_rows(input_buf[0], input_row+input_buf_offset[0], output_buf, output_buf_offset, |
5032 outptr[RGB_RED+outptr_offset] = outptr[RGB_GREEN+outptr_offset] = outptr[RGB_BLUE+outptr_offset] = inptr[col]; | 5060 outptr[RGB_RED+outptr_offset] = outptr[RGB_GREEN+outptr_offset] = outptr[RGB_BLUE+outptr_offset] = inptr[col]; |
5033 outptr_offset += RGB_PIXELSIZE; | 5061 outptr_offset += RGB_PIXELSIZE; |
5034 } | 5062 } |
5035 } | 5063 } |
5036 } | 5064 } |
5037 | 5065 |
5038 static void ycc_rgb_convert (jpeg_decompress_struct cinfo, | 5066 static void ycc_rgb_convert (jpeg_decompress_struct cinfo, |
5039 byte[][][] input_buf, int[] input_buf_offset, int input_row, | 5067 byte[][][] input_buf, int[] input_buf_offset, int input_row, |
5040 byte[][] output_buf, int output_buf_offset, int num_rows) | 5068 byte[][] output_buf, int output_buf_offset, int num_rows) |
5041 { | 5069 { |
5042 jpeg_color_deconverter cconvert = cinfo.cconvert; | 5070 jpeg_color_deconverter cconvert = cinfo.cconvert; |
5107 length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; | 5135 length = (cinfo.buffer[cinfo.bytes_offset++] & 0xFF) << 8; |
5108 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); | 5136 if (cinfo.bytes_offset is cinfo.bytes_in_buffer) fill_input_buffer(cinfo); |
5109 length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; | 5137 length |= cinfo.buffer[cinfo.bytes_offset++] & 0xFF; |
5110 | 5138 |
5111 length -= 2; | 5139 length -= 2; |
5112 | 5140 |
5113 // TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo.unread_marker, cast(int) length); | 5141 // TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo.unread_marker, cast(int) length); |
5114 | 5142 |
5115 if (length > 0) { | 5143 if (length > 0) { |
5116 skip_input_data (cinfo, length); | 5144 skip_input_data (cinfo, length); |
5117 } | 5145 } |
5118 | 5146 |
5119 return true; | 5147 return true; |
5120 } | 5148 } |
5121 | 5149 |
5122 static bool get_interesting_appn (jpeg_decompress_struct cinfo) | 5150 static bool get_interesting_appn (jpeg_decompress_struct cinfo) |
5123 /* Process an APP0 or APP14 marker without saving it */ | 5151 /* Process an APP0 or APP14 marker without saving it */ |
5207 if (((data[12] & 0xFF) | (data[13]) & 0xFF) !is 0) { | 5235 if (((data[12] & 0xFF) | (data[13]) & 0xFF) !is 0) { |
5208 // TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, | 5236 // TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, |
5209 // GETJOCTET(data[12]), GETJOCTET(data[13])); | 5237 // GETJOCTET(data[12]), GETJOCTET(data[13])); |
5210 } | 5238 } |
5211 totallen -= APP0_DATA_LEN; | 5239 totallen -= APP0_DATA_LEN; |
5212 if (totallen != ((data[12] & 0xFF) * (data[13] & 0xFF) * 3)) { | 5240 if (totallen !is ((data[12] & 0xFF) * (data[13] & 0xFF) * 3)) { |
5213 // TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, cast(int) totallen); | 5241 // TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, cast(int) totallen); |
5214 } | 5242 } |
5215 } else if (datalen >= 6 && | 5243 } else if (datalen >= 6 && |
5216 (data[0] & 0xFF) is 0x4A && | 5244 (data[0] & 0xFF) is 0x4A && |
5217 (data[1] & 0xFF) is 0x46 && | 5245 (data[1] & 0xFF) is 0x46 && |
5272 } | 5300 } |
5273 } | 5301 } |
5274 | 5302 |
5275 static bool get_soi (jpeg_decompress_struct cinfo) /* Process an SOI marker */ { | 5303 static bool get_soi (jpeg_decompress_struct cinfo) /* Process an SOI marker */ { |
5276 int i; | 5304 int i; |
5277 | 5305 |
5278 // TRACEMS(cinfo, 1, JTRC_SOI); | 5306 // TRACEMS(cinfo, 1, JTRC_SOI); |
5279 | 5307 |
5280 if (cinfo.marker.saw_SOI) | 5308 if (cinfo.marker.saw_SOI) |
5281 error(); | 5309 error(); |
5282 // ERREXIT(cinfo, JERR_SOI_DUPLICATE); | 5310 // ERREXIT(cinfo, JERR_SOI_DUPLICATE); |
5463 retcode = JPEG_HEADER_TABLES_ONLY; | 5491 retcode = JPEG_HEADER_TABLES_ONLY; |
5464 break; | 5492 break; |
5465 case JPEG_SUSPENDED: | 5493 case JPEG_SUSPENDED: |
5466 /* no work */ | 5494 /* no work */ |
5467 break; | 5495 break; |
5496 default: | |
5468 } | 5497 } |
5469 | 5498 |
5470 return retcode; | 5499 return retcode; |
5471 } | 5500 } |
5472 | 5501 |
5543 case INPUT_CONSUME_INPUT: | 5572 case INPUT_CONSUME_INPUT: |
5544 return consume_markers(cinfo); | 5573 return consume_markers(cinfo); |
5545 default: | 5574 default: |
5546 error(); | 5575 error(); |
5547 } | 5576 } |
5548 return 0; | 5577 return 0; |
5549 } | 5578 } |
5550 | 5579 |
5551 static bool fill_input_buffer(jpeg_decompress_struct cinfo) { | 5580 static bool fill_input_buffer(jpeg_decompress_struct cinfo) { |
5552 try { | 5581 try { |
5553 InputStream inputStream = cinfo.inputStream; | 5582 InputStream inputStream = cinfo.inputStream; |
5699 case M_SOS: | 5728 case M_SOS: |
5700 if (! get_sos(cinfo)) | 5729 if (! get_sos(cinfo)) |
5701 return JPEG_SUSPENDED; | 5730 return JPEG_SUSPENDED; |
5702 cinfo.unread_marker = 0; /* processed the marker */ | 5731 cinfo.unread_marker = 0; /* processed the marker */ |
5703 return JPEG_REACHED_SOS; | 5732 return JPEG_REACHED_SOS; |
5704 | 5733 |
5705 case M_EOI: | 5734 case M_EOI: |
5706 // TRACEMS(cinfo, 1, JTRC_EOI); | 5735 // TRACEMS(cinfo, 1, JTRC_EOI); |
5707 cinfo.unread_marker = 0; /* processed the marker */ | 5736 cinfo.unread_marker = 0; /* processed the marker */ |
5708 return JPEG_REACHED_EOI; | 5737 return JPEG_REACHED_EOI; |
5709 | 5738 |
5710 case M_DAC: | 5739 case M_DAC: |
5711 if (! get_dac(cinfo)) | 5740 if (! get_dac(cinfo)) |
5712 return JPEG_SUSPENDED; | 5741 return JPEG_SUSPENDED; |
5713 break; | 5742 break; |
5714 | 5743 |
5715 case M_DHT: | 5744 case M_DHT: |
5716 if (! get_dht(cinfo)) | 5745 if (! get_dht(cinfo)) |
5717 return JPEG_SUSPENDED; | 5746 return JPEG_SUSPENDED; |
5718 break; | 5747 break; |
5719 | 5748 |
5720 case M_DQT: | 5749 case M_DQT: |
5721 if (! get_dqt(cinfo)) | 5750 if (! get_dqt(cinfo)) |
5722 return JPEG_SUSPENDED; | 5751 return JPEG_SUSPENDED; |
5723 break; | 5752 break; |
5724 | 5753 |
5725 case M_DRI: | 5754 case M_DRI: |
5726 if (! get_dri(cinfo)) | 5755 if (! get_dri(cinfo)) |
5727 return JPEG_SUSPENDED; | 5756 return JPEG_SUSPENDED; |
5728 break; | 5757 break; |
5729 | 5758 |
5730 case M_APP0: | 5759 case M_APP0: |
5731 case M_APP1: | 5760 case M_APP1: |
5732 case M_APP2: | 5761 case M_APP2: |
5733 case M_APP3: | 5762 case M_APP3: |
5734 case M_APP4: | 5763 case M_APP4: |
5744 case M_APP14: | 5773 case M_APP14: |
5745 case M_APP15: | 5774 case M_APP15: |
5746 if (! process_APPn(cinfo.unread_marker - M_APP0, cinfo)) | 5775 if (! process_APPn(cinfo.unread_marker - M_APP0, cinfo)) |
5747 return JPEG_SUSPENDED; | 5776 return JPEG_SUSPENDED; |
5748 break; | 5777 break; |
5749 | 5778 |
5750 case M_COM: | 5779 case M_COM: |
5751 if (! process_COM(cinfo)) | 5780 if (! process_COM(cinfo)) |
5752 return JPEG_SUSPENDED; | 5781 return JPEG_SUSPENDED; |
5753 break; | 5782 break; |
5754 | 5783 |
5802 error(); | 5831 error(); |
5803 // ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); | 5832 // ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); |
5804 | 5833 |
5805 /* For now, precision must match compiled-in value... */ | 5834 /* For now, precision must match compiled-in value... */ |
5806 if (cinfo.data_precision !is BITS_IN_JSAMPLE) | 5835 if (cinfo.data_precision !is BITS_IN_JSAMPLE) |
5807 error(" [data precision=" + cinfo.data_precision + "]"); | 5836 error(" [data precision=" ~ to!(String)(cinfo.data_precision) ~ "]"); |
5808 // ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo.data_precision); | 5837 // ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo.data_precision); |
5809 | 5838 |
5810 /* Check that number of components won't exceed internal array sizes */ | 5839 /* Check that number of components won't exceed internal array sizes */ |
5811 if (cinfo.num_components > MAX_COMPONENTS) | 5840 if (cinfo.num_components > MAX_COMPONENTS) |
5812 error(); | 5841 error(); |
5865 /* Do computations that are needed before processing a JPEG scan */ | 5894 /* Do computations that are needed before processing a JPEG scan */ |
5866 /* cinfo.comps_in_scan and cinfo.cur_comp_info[] were set from SOS marker */ | 5895 /* cinfo.comps_in_scan and cinfo.cur_comp_info[] were set from SOS marker */ |
5867 { | 5896 { |
5868 int ci, mcublks, tmp = 0; | 5897 int ci, mcublks, tmp = 0; |
5869 jpeg_component_info compptr; | 5898 jpeg_component_info compptr; |
5870 | 5899 |
5871 if (cinfo.comps_in_scan is 1) { | 5900 if (cinfo.comps_in_scan is 1) { |
5872 | 5901 |
5873 /* Noninterleaved (single-component) scan */ | 5902 /* Noninterleaved (single-component) scan */ |
5874 compptr = cinfo.cur_comp_info[0]; | 5903 compptr = cinfo.cur_comp_info[0]; |
5875 | 5904 |
5876 /* Overall image size in MCUs */ | 5905 /* Overall image size in MCUs */ |
5877 cinfo.MCUs_per_row = compptr.width_in_blocks; | 5906 cinfo.MCUs_per_row = compptr.width_in_blocks; |
5878 cinfo.MCU_rows_in_scan = compptr.height_in_blocks; | 5907 cinfo.MCU_rows_in_scan = compptr.height_in_blocks; |
5879 | 5908 |
5880 /* For noninterleaved scan, always one block per MCU */ | 5909 /* For noninterleaved scan, always one block per MCU */ |
5881 compptr.MCU_width = 1; | 5910 compptr.MCU_width = 1; |
5882 compptr.MCU_height = 1; | 5911 compptr.MCU_height = 1; |
5883 compptr.MCU_blocks = 1; | 5912 compptr.MCU_blocks = 1; |
5884 compptr.MCU_sample_width = compptr.DCT_scaled_size; | 5913 compptr.MCU_sample_width = compptr.DCT_scaled_size; |
5887 * as the number of block rows present in the last iMCU row. | 5916 * as the number of block rows present in the last iMCU row. |
5888 */ | 5917 */ |
5889 tmp = (compptr.height_in_blocks % compptr.v_samp_factor); | 5918 tmp = (compptr.height_in_blocks % compptr.v_samp_factor); |
5890 if (tmp is 0) tmp = compptr.v_samp_factor; | 5919 if (tmp is 0) tmp = compptr.v_samp_factor; |
5891 compptr.last_row_height = tmp; | 5920 compptr.last_row_height = tmp; |
5892 | 5921 |
5893 /* Prepare array describing MCU composition */ | 5922 /* Prepare array describing MCU composition */ |
5894 cinfo.blocks_in_MCU = 1; | 5923 cinfo.blocks_in_MCU = 1; |
5895 cinfo.MCU_membership[0] = 0; | 5924 cinfo.MCU_membership[0] = 0; |
5896 | 5925 |
5897 } else { | 5926 } else { |
5898 | 5927 |
5899 /* Interleaved (multi-component) scan */ | 5928 /* Interleaved (multi-component) scan */ |
5900 if (cinfo.comps_in_scan <= 0 || cinfo.comps_in_scan > MAX_COMPS_IN_SCAN) | 5929 if (cinfo.comps_in_scan <= 0 || cinfo.comps_in_scan > MAX_COMPS_IN_SCAN) |
5901 error(); | 5930 error(); |
5902 // ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo.comps_in_scan, MAX_COMPS_IN_SCAN); | 5931 // ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo.comps_in_scan, MAX_COMPS_IN_SCAN); |
5903 | 5932 |
5904 /* Overall image size in MCUs */ | 5933 /* Overall image size in MCUs */ |
5905 cinfo.MCUs_per_row = cast(int)jdiv_round_up( cinfo.image_width, (cinfo.max_h_samp_factor*DCTSIZE)); | 5934 cinfo.MCUs_per_row = cast(int)jdiv_round_up( cinfo.image_width, (cinfo.max_h_samp_factor*DCTSIZE)); |
5906 cinfo.MCU_rows_in_scan = cast(int)jdiv_round_up( cinfo.image_height, (cinfo.max_v_samp_factor*DCTSIZE)); | 5935 cinfo.MCU_rows_in_scan = cast(int)jdiv_round_up( cinfo.image_height, (cinfo.max_v_samp_factor*DCTSIZE)); |
5907 | 5936 |
5908 cinfo.blocks_in_MCU = 0; | 5937 cinfo.blocks_in_MCU = 0; |
5909 | 5938 |
5910 for (ci = 0; ci < cinfo.comps_in_scan; ci++) { | 5939 for (ci = 0; ci < cinfo.comps_in_scan; ci++) { |
5911 compptr = cinfo.cur_comp_info[ci]; | 5940 compptr = cinfo.cur_comp_info[ci]; |
5912 /* Sampling factors give # of blocks of component in each MCU */ | 5941 /* Sampling factors give # of blocks of component in each MCU */ |
5913 compptr.MCU_width = compptr.h_samp_factor; | 5942 compptr.MCU_width = compptr.h_samp_factor; |
5914 compptr.MCU_height = compptr.v_samp_factor; | 5943 compptr.MCU_height = compptr.v_samp_factor; |
5928 // ERREXIT(cinfo, JERR_BAD_MCU_SIZE); | 5957 // ERREXIT(cinfo, JERR_BAD_MCU_SIZE); |
5929 while (mcublks-- > 0) { | 5958 while (mcublks-- > 0) { |
5930 cinfo.MCU_membership[cinfo.blocks_in_MCU++] = ci; | 5959 cinfo.MCU_membership[cinfo.blocks_in_MCU++] = ci; |
5931 } | 5960 } |
5932 } | 5961 } |
5933 | 5962 |
5934 } | 5963 } |
5935 } | 5964 } |
5936 | 5965 |
5937 static void latch_quant_tables (jpeg_decompress_struct cinfo) { | 5966 static void latch_quant_tables (jpeg_decompress_struct cinfo) { |
5938 int ci, qtblno; | 5967 int ci, qtblno; |
5978 error(); | 6007 error(); |
5979 // ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno); | 6008 // ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno); |
5980 | 6009 |
5981 /* Allocate a workspace if we haven't already done so. */ | 6010 /* Allocate a workspace if we haven't already done so. */ |
5982 dtbl.pub = htbl; /* fill in back link */ | 6011 dtbl.pub = htbl; /* fill in back link */ |
5983 | 6012 |
5984 /* Figure C.1: make table of Huffman code length for each symbol */ | 6013 /* Figure C.1: make table of Huffman code length for each symbol */ |
5985 | 6014 |
5986 p = 0; | 6015 p = 0; |
5987 for (l = 1; l <= 16; l++) { | 6016 for (l = 1; l <= 16; l++) { |
5988 i = htbl.bits[l] & 0xFF; | 6017 i = htbl.bits[l] & 0xFF; |
5992 while (i-- !is 0) | 6021 while (i-- !is 0) |
5993 huffsize[p++] = cast(byte) l; | 6022 huffsize[p++] = cast(byte) l; |
5994 } | 6023 } |
5995 huffsize[p] = 0; | 6024 huffsize[p] = 0; |
5996 numsymbols = p; | 6025 numsymbols = p; |
5997 | 6026 |
5998 /* Figure C.2: generate the codes themselves */ | 6027 /* Figure C.2: generate the codes themselves */ |
5999 /* We also validate that the counts represent a legal Huffman code tree. */ | 6028 /* We also validate that the counts represent a legal Huffman code tree. */ |
6000 | 6029 |
6001 code = 0; | 6030 code = 0; |
6002 si = huffsize[0]; | 6031 si = huffsize[0]; |
6003 p = 0; | 6032 p = 0; |
6004 while ((huffsize[p]) !is 0) { | 6033 while ( huffsize[p] !is 0) { |
6005 while (( huffsize[p]) is si) { | 6034 while (( huffsize[p]) is si) { |
6006 huffcode[p++] = code; | 6035 huffcode[p++] = code; |
6007 code++; | 6036 code++; |
6008 } | 6037 } |
6009 /* code is now 1 more than the last code used for codelength si; but | 6038 /* code is now 1 more than the last code used for codelength si; but |
6125 cinfo.output_scan_number = cinfo.input_scan_number; | 6154 cinfo.output_scan_number = cinfo.input_scan_number; |
6126 } | 6155 } |
6127 break; | 6156 break; |
6128 case JPEG_SUSPENDED: | 6157 case JPEG_SUSPENDED: |
6129 break; | 6158 break; |
6159 default: | |
6130 } | 6160 } |
6131 | 6161 |
6132 return val; | 6162 return val; |
6133 } | 6163 } |
6134 | 6164 |
6139 switch (cinfo.num_components) { | 6169 switch (cinfo.num_components) { |
6140 case 1: | 6170 case 1: |
6141 cinfo.jpeg_color_space = JCS_GRAYSCALE; | 6171 cinfo.jpeg_color_space = JCS_GRAYSCALE; |
6142 cinfo.out_color_space = JCS_GRAYSCALE; | 6172 cinfo.out_color_space = JCS_GRAYSCALE; |
6143 break; | 6173 break; |
6144 | 6174 |
6145 case 3: | 6175 case 3: |
6146 if (cinfo.saw_JFIF_marker) { | 6176 if (cinfo.saw_JFIF_marker) { |
6147 cinfo.jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */ | 6177 cinfo.jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */ |
6148 } else if (cinfo.saw_Adobe_marker) { | 6178 } else if (cinfo.saw_Adobe_marker) { |
6149 switch (cinfo.Adobe_transform) { | 6179 switch (cinfo.Adobe_transform) { |
6151 cinfo.jpeg_color_space = JCS_RGB; | 6181 cinfo.jpeg_color_space = JCS_RGB; |
6152 break; | 6182 break; |
6153 case 1: | 6183 case 1: |
6154 cinfo.jpeg_color_space = JCS_YCbCr; | 6184 cinfo.jpeg_color_space = JCS_YCbCr; |
6155 break; | 6185 break; |
6156 default: | 6186 default: |
6157 // WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo.Adobe_transform); | 6187 // WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo.Adobe_transform); |
6158 cinfo.jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ | 6188 cinfo.jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ |
6159 break; | 6189 break; |
6160 } | 6190 } |
6161 } else { | 6191 } else { |
6162 /* Saw no special markers, try to guess from the component IDs */ | 6192 /* Saw no special markers, try to guess from the component IDs */ |
6163 int cid0 = cinfo.comp_info[0].component_id; | 6193 int cid0 = cinfo.comp_info[0].component_id; |
6164 int cid1 = cinfo.comp_info[1].component_id; | 6194 int cid1 = cinfo.comp_info[1].component_id; |
6165 int cid2 = cinfo.comp_info[2].component_id; | 6195 int cid2 = cinfo.comp_info[2].component_id; |
6166 | 6196 |
6167 if (cid0 is 1 && cid1 is 2 && cid2 is 3) | 6197 if (cid0 is 1 && cid1 is 2 && cid2 is 3) |
6168 cinfo.jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */ | 6198 cinfo.jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */ |
6169 else if (cid0 is 82 && cid1 is 71 && cid2 is 66) | 6199 else if (cid0 is 82 && cid1 is 71 && cid2 is 66) |
6170 cinfo.jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */ | 6200 cinfo.jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */ |
6171 else { | 6201 else { |
6174 } | 6204 } |
6175 } | 6205 } |
6176 /* Always guess RGB is proper output colorspace. */ | 6206 /* Always guess RGB is proper output colorspace. */ |
6177 cinfo.out_color_space = JCS_RGB; | 6207 cinfo.out_color_space = JCS_RGB; |
6178 break; | 6208 break; |
6179 | 6209 |
6180 case 4: | 6210 case 4: |
6181 if (cinfo.saw_Adobe_marker) { | 6211 if (cinfo.saw_Adobe_marker) { |
6182 switch (cinfo.Adobe_transform) { | 6212 switch (cinfo.Adobe_transform) { |
6183 case 0: | 6213 case 0: |
6184 cinfo.jpeg_color_space = JCS_CMYK; | 6214 cinfo.jpeg_color_space = JCS_CMYK; |
6195 /* No special markers, assume straight CMYK. */ | 6225 /* No special markers, assume straight CMYK. */ |
6196 cinfo.jpeg_color_space = JCS_CMYK; | 6226 cinfo.jpeg_color_space = JCS_CMYK; |
6197 } | 6227 } |
6198 cinfo.out_color_space = JCS_CMYK; | 6228 cinfo.out_color_space = JCS_CMYK; |
6199 break; | 6229 break; |
6200 | 6230 |
6201 default: | 6231 default: |
6202 cinfo.jpeg_color_space = JCS_UNKNOWN; | 6232 cinfo.jpeg_color_space = JCS_UNKNOWN; |
6203 cinfo.out_color_space = JCS_UNKNOWN; | 6233 cinfo.out_color_space = JCS_UNKNOWN; |
6204 break; | 6234 break; |
6205 } | 6235 } |
6305 return (buffer[0] & 0xFF) is 0xFF && (buffer[1] & 0xFF) is M_SOI; | 6335 return (buffer[0] & 0xFF) is 0xFF && (buffer[1] & 0xFF) is M_SOI; |
6306 } catch (Exception e) { | 6336 } catch (Exception e) { |
6307 return false; | 6337 return false; |
6308 } | 6338 } |
6309 } | 6339 } |
6310 | 6340 |
6311 static ImageData[] loadFromByteStream(InputStream inputStream, ImageLoader loader) { | 6341 static ImageData[] loadFromByteStream(InputStream inputStream, ImageLoader loader) { |
6312 jpeg_decompress_struct cinfo = new jpeg_decompress_struct(); | 6342 jpeg_decompress_struct cinfo = new jpeg_decompress_struct(); |
6313 cinfo.inputStream = inputStream; | 6343 cinfo.inputStream = inputStream; |
6314 jpeg_create_decompress(cinfo); | 6344 jpeg_create_decompress(cinfo); |
6315 jpeg_read_header(cinfo, true); | 6345 jpeg_read_header(cinfo, true); |
6330 default: | 6360 default: |
6331 error(); | 6361 error(); |
6332 } | 6362 } |
6333 int scanlinePad = 4; | 6363 int scanlinePad = 4; |
6334 int row_stride = (((cinfo.output_width * cinfo.out_color_components * 8 + 7) / 8) + (scanlinePad - 1)) / scanlinePad * scanlinePad; | 6364 int row_stride = (((cinfo.output_width * cinfo.out_color_components * 8 + 7) / 8) + (scanlinePad - 1)) / scanlinePad * scanlinePad; |
6335 byte[][] buffer = new byte[1][row_stride]; | 6365 byte[][] buffer = new byte[][]( 1, row_stride ); |
6336 byte[] data = new byte[row_stride * cinfo.output_height]; | 6366 byte[] data = new byte[row_stride * cinfo.output_height]; |
6337 ImageData imageData = ImageData.internal_new( | 6367 ImageData imageData = ImageData.internal_new( |
6338 cinfo.output_width, cinfo.output_height, palette.isDirect ? 24 : 8, palette, scanlinePad, data, | 6368 cinfo.output_width, cinfo.output_height, palette.isDirect ? 24 : 8, palette, scanlinePad, data, |
6339 0, null, null, -1, -1, DWT.IMAGE_JPEG, 0, 0, 0, 0); | 6369 0, null, null, -1, -1, DWT.IMAGE_JPEG, 0, 0, 0, 0); |
6340 if (cinfo.buffered_image) { | 6370 if (cinfo.buffered_image) { |
6357 System.arraycopy(buffer[0], 0, data, offset, row_stride); | 6387 System.arraycopy(buffer[0], 0, data, offset, row_stride); |
6358 } | 6388 } |
6359 } | 6389 } |
6360 jpeg_finish_decompress(cinfo); | 6390 jpeg_finish_decompress(cinfo); |
6361 jpeg_destroy_decompress(cinfo); | 6391 jpeg_destroy_decompress(cinfo); |
6362 return new ImageData[]{imageData}; | 6392 return [imageData]; |
6363 } | 6393 } |
6364 | 6394 |
6365 } | 6395 } |