diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jcprepct.c')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jcprepct.c | 716 |
1 files changed, 358 insertions, 358 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jcprepct.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jcprepct.c index 00101e0..be44cc4 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jcprepct.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jcprepct.c | |||
@@ -1,358 +1,358 @@ | |||
1 | /* | 1 | /* |
2 | * jcprepct.c | 2 | * jcprepct.c |
3 | * | 3 | * |
4 | * Copyright (C) 1994-1996, Thomas G. Lane. | 4 | * Copyright (C) 1994-1996, Thomas G. Lane. |
5 | * This file is part of the Independent JPEG Group's software. | 5 | * This file is part of the Independent JPEG Group's software. |
6 | * For conditions of distribution and use, see the accompanying README file. | 6 | * For conditions of distribution and use, see the accompanying README file. |
7 | * | 7 | * |
8 | * This file contains the compression preprocessing controller. | 8 | * This file contains the compression preprocessing controller. |
9 | * This controller manages the color conversion, downsampling, | 9 | * This controller manages the color conversion, downsampling, |
10 | * and edge expansion steps. | 10 | * and edge expansion steps. |
11 | * | 11 | * |
12 | * Most of the complexity here is associated with buffering input rows | 12 | * Most of the complexity here is associated with buffering input rows |
13 | * as required by the downsampler. See the comments at the head of | 13 | * as required by the downsampler. See the comments at the head of |
14 | * jcsample.c for the downsampler's needs. | 14 | * jcsample.c for the downsampler's needs. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #define JPEG_INTERNALS | 17 | #define JPEG_INTERNALS |
18 | #include "jinclude.h" | 18 | #include "jinclude.h" |
19 | #include "jpeglib.h" | 19 | #include "jpeglib.h" |
20 | 20 | ||
21 | 21 | ||
22 | /* At present, jcsample.c can request context rows only for smoothing. | 22 | /* At present, jcsample.c can request context rows only for smoothing. |
23 | * In the future, we might also need context rows for CCIR601 sampling | 23 | * In the future, we might also need context rows for CCIR601 sampling |
24 | * or other more-complex downsampling procedures. The code to support | 24 | * or other more-complex downsampling procedures. The code to support |
25 | * context rows should be compiled only if needed. | 25 | * context rows should be compiled only if needed. |
26 | */ | 26 | */ |
27 | #ifdef INPUT_SMOOTHING_SUPPORTED | 27 | #ifdef INPUT_SMOOTHING_SUPPORTED |
28 | #define CONTEXT_ROWS_SUPPORTED | 28 | #define CONTEXT_ROWS_SUPPORTED |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | 31 | ||
32 | /* | 32 | /* |
33 | * For the simple (no-context-row) case, we just need to buffer one | 33 | * For the simple (no-context-row) case, we just need to buffer one |
34 | * row group's worth of pixels for the downsampling step. At the bottom of | 34 | * row group's worth of pixels for the downsampling step. At the bottom of |
35 | * the image, we pad to a full row group by replicating the last pixel row. | 35 | * the image, we pad to a full row group by replicating the last pixel row. |
36 | * The downsampler's last output row is then replicated if needed to pad | 36 | * The downsampler's last output row is then replicated if needed to pad |
37 | * out to a full iMCU row. | 37 | * out to a full iMCU row. |
38 | * | 38 | * |
39 | * When providing context rows, we must buffer three row groups' worth of | 39 | * When providing context rows, we must buffer three row groups' worth of |
40 | * pixels. Three row groups are physically allocated, but the row pointer | 40 | * pixels. Three row groups are physically allocated, but the row pointer |
41 | * arrays are made five row groups high, with the extra pointers above and | 41 | * arrays are made five row groups high, with the extra pointers above and |
42 | * below "wrapping around" to point to the last and first real row groups. | 42 | * below "wrapping around" to point to the last and first real row groups. |
43 | * This allows the downsampler to access the proper context rows. | 43 | * This allows the downsampler to access the proper context rows. |
44 | * At the top and bottom of the image, we create dummy context rows by | 44 | * At the top and bottom of the image, we create dummy context rows by |
45 | * copying the first or last real pixel row. This copying could be avoided | 45 | * copying the first or last real pixel row. This copying could be avoided |
46 | * by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the | 46 | * by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the |
47 | * trouble on the compression side. | 47 | * trouble on the compression side. |
48 | */ | 48 | */ |
49 | 49 | ||
50 | 50 | ||
51 | /* Private buffer controller object */ | 51 | /* Private buffer controller object */ |
52 | 52 | ||
53 | typedef struct { | 53 | typedef struct { |
54 | struct jpeg_c_prep_controller pub; /* public fields */ | 54 | struct jpeg_c_prep_controller pub; /* public fields */ |
55 | 55 | ||
56 | /* Downsampling input buffer. This buffer holds color-converted data | 56 | /* Downsampling input buffer. This buffer holds color-converted data |
57 | * until we have enough to do a downsample step. | 57 | * until we have enough to do a downsample step. |
58 | */ | 58 | */ |
59 | JSAMPARRAY color_buf[MAX_COMPONENTS]; | 59 | JSAMPARRAY color_buf[MAX_COMPONENTS]; |
60 | 60 | ||
61 | JDIMENSION rows_to_go; /* counts rows remaining in source image */ | 61 | JDIMENSION rows_to_go; /* counts rows remaining in source image */ |
62 | int next_buf_row; /* index of next row to store in color_buf */ | 62 | int next_buf_row; /* index of next row to store in color_buf */ |
63 | 63 | ||
64 | #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */ | 64 | #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */ |
65 | int this_row_group; /* starting row index of group to process */ | 65 | int this_row_group; /* starting row index of group to process */ |
66 | int next_buf_stop; /* downsample when we reach this index */ | 66 | int next_buf_stop; /* downsample when we reach this index */ |
67 | #endif | 67 | #endif |
68 | } my_prep_controller; | 68 | } my_prep_controller; |
69 | 69 | ||
70 | typedef my_prep_controller * my_prep_ptr; | 70 | typedef my_prep_controller * my_prep_ptr; |
71 | 71 | ||
72 | 72 | ||
73 | /* | 73 | /* |
74 | * Initialize for a processing pass. | 74 | * Initialize for a processing pass. |
75 | */ | 75 | */ |
76 | 76 | ||
77 | METHODDEF(void) | 77 | METHODDEF(void) |
78 | start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode) | 78 | start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode) |
79 | { | 79 | { |
80 | my_prep_ptr prep = (my_prep_ptr) cinfo->prep; | 80 | my_prep_ptr prep = (my_prep_ptr) cinfo->prep; |
81 | 81 | ||
82 | if (pass_mode != JBUF_PASS_THRU) | 82 | if (pass_mode != JBUF_PASS_THRU) |
83 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 83 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); |
84 | 84 | ||
85 | /* Initialize total-height counter for detecting bottom of image */ | 85 | /* Initialize total-height counter for detecting bottom of image */ |
86 | prep->rows_to_go = cinfo->image_height; | 86 | prep->rows_to_go = cinfo->image_height; |
87 | /* Mark the conversion buffer empty */ | 87 | /* Mark the conversion buffer empty */ |
88 | prep->next_buf_row = 0; | 88 | prep->next_buf_row = 0; |
89 | #ifdef CONTEXT_ROWS_SUPPORTED | 89 | #ifdef CONTEXT_ROWS_SUPPORTED |
90 | /* Preset additional state variables for context mode. | 90 | /* Preset additional state variables for context mode. |
91 | * These aren't used in non-context mode, so we needn't test which mode. | 91 | * These aren't used in non-context mode, so we needn't test which mode. |
92 | */ | 92 | */ |
93 | prep->this_row_group = 0; | 93 | prep->this_row_group = 0; |
94 | /* Set next_buf_stop to stop after two row groups have been read in. */ | 94 | /* Set next_buf_stop to stop after two row groups have been read in. */ |
95 | prep->next_buf_stop = 2 * cinfo->max_v_samp_factor; | 95 | prep->next_buf_stop = 2 * cinfo->max_v_samp_factor; |
96 | #endif | 96 | #endif |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | /* | 100 | /* |
101 | * Expand an image vertically from height input_rows to height output_rows, | 101 | * Expand an image vertically from height input_rows to height output_rows, |
102 | * by duplicating the bottom row. | 102 | * by duplicating the bottom row. |
103 | */ | 103 | */ |
104 | 104 | ||
105 | LOCAL(void) | 105 | LOCAL(void) |
106 | expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols, | 106 | expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols, |
107 | int input_rows, int output_rows) | 107 | int input_rows, int output_rows) |
108 | { | 108 | { |
109 | register int row; | 109 | register int row; |
110 | 110 | ||
111 | for (row = input_rows; row < output_rows; row++) { | 111 | for (row = input_rows; row < output_rows; row++) { |
112 | jcopy_sample_rows(image_data, input_rows-1, image_data, row, | 112 | jcopy_sample_rows(image_data, input_rows-1, image_data, row, |
113 | 1, num_cols); | 113 | 1, num_cols); |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | /* | 118 | /* |
119 | * Process some data in the simple no-context case. | 119 | * Process some data in the simple no-context case. |
120 | * | 120 | * |
121 | * Preprocessor output data is counted in "row groups". A row group | 121 | * Preprocessor output data is counted in "row groups". A row group |
122 | * is defined to be v_samp_factor sample rows of each component. | 122 | * is defined to be v_samp_factor sample rows of each component. |
123 | * Downsampling will produce this much data from each max_v_samp_factor | 123 | * Downsampling will produce this much data from each max_v_samp_factor |
124 | * input rows. | 124 | * input rows. |
125 | */ | 125 | */ |
126 | 126 | ||
127 | METHODDEF(void) | 127 | METHODDEF(void) |
128 | pre_process_data (j_compress_ptr cinfo, | 128 | pre_process_data (j_compress_ptr cinfo, |
129 | JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, | 129 | JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, |
130 | JDIMENSION in_rows_avail, | 130 | JDIMENSION in_rows_avail, |
131 | JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, | 131 | JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, |
132 | JDIMENSION out_row_groups_avail) | 132 | JDIMENSION out_row_groups_avail) |
133 | { | 133 | { |
134 | my_prep_ptr prep = (my_prep_ptr) cinfo->prep; | 134 | my_prep_ptr prep = (my_prep_ptr) cinfo->prep; |
135 | int numrows, ci; | 135 | int numrows, ci; |
136 | JDIMENSION inrows; | 136 | JDIMENSION inrows; |
137 | jpeg_component_info * compptr; | 137 | jpeg_component_info * compptr; |
138 | 138 | ||
139 | while (*in_row_ctr < in_rows_avail && | 139 | while (*in_row_ctr < in_rows_avail && |
140 | *out_row_group_ctr < out_row_groups_avail) { | 140 | *out_row_group_ctr < out_row_groups_avail) { |
141 | /* Do color conversion to fill the conversion buffer. */ | 141 | /* Do color conversion to fill the conversion buffer. */ |
142 | inrows = in_rows_avail - *in_row_ctr; | 142 | inrows = in_rows_avail - *in_row_ctr; |
143 | numrows = cinfo->max_v_samp_factor - prep->next_buf_row; | 143 | numrows = cinfo->max_v_samp_factor - prep->next_buf_row; |
144 | numrows = (int) MIN((JDIMENSION) numrows, inrows); | 144 | numrows = (int) MIN((JDIMENSION) numrows, inrows); |
145 | (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, | 145 | (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, |
146 | prep->color_buf, | 146 | prep->color_buf, |
147 | (JDIMENSION) prep->next_buf_row, | 147 | (JDIMENSION) prep->next_buf_row, |
148 | numrows); | 148 | numrows); |
149 | *in_row_ctr += numrows; | 149 | *in_row_ctr += numrows; |
150 | prep->next_buf_row += numrows; | 150 | prep->next_buf_row += numrows; |
151 | prep->rows_to_go -= numrows; | 151 | prep->rows_to_go -= numrows; |
152 | /* If at bottom of image, pad to fill the conversion buffer. */ | 152 | /* If at bottom of image, pad to fill the conversion buffer. */ |
153 | if (prep->rows_to_go == 0 && | 153 | if (prep->rows_to_go == 0 && |
154 | prep->next_buf_row < cinfo->max_v_samp_factor) { | 154 | prep->next_buf_row < cinfo->max_v_samp_factor) { |
155 | for (ci = 0; ci < cinfo->num_components; ci++) { | 155 | for (ci = 0; ci < cinfo->num_components; ci++) { |
156 | expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, | 156 | expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, |
157 | prep->next_buf_row, cinfo->max_v_samp_factor); | 157 | prep->next_buf_row, cinfo->max_v_samp_factor); |
158 | } | 158 | } |
159 | prep->next_buf_row = cinfo->max_v_samp_factor; | 159 | prep->next_buf_row = cinfo->max_v_samp_factor; |
160 | } | 160 | } |
161 | /* If we've filled the conversion buffer, empty it. */ | 161 | /* If we've filled the conversion buffer, empty it. */ |
162 | if (prep->next_buf_row == cinfo->max_v_samp_factor) { | 162 | if (prep->next_buf_row == cinfo->max_v_samp_factor) { |
163 | (*cinfo->downsample->downsample) (cinfo, | 163 | (*cinfo->downsample->downsample) (cinfo, |
164 | prep->color_buf, (JDIMENSION) 0, | 164 | prep->color_buf, (JDIMENSION) 0, |
165 | output_buf, *out_row_group_ctr); | 165 | output_buf, *out_row_group_ctr); |
166 | prep->next_buf_row = 0; | 166 | prep->next_buf_row = 0; |
167 | (*out_row_group_ctr)++; | 167 | (*out_row_group_ctr)++; |
168 | } | 168 | } |
169 | /* If at bottom of image, pad the output to a full iMCU height. | 169 | /* If at bottom of image, pad the output to a full iMCU height. |
170 | * Note we assume the caller is providing a one-iMCU-height output buffer! | 170 | * Note we assume the caller is providing a one-iMCU-height output buffer! |
171 | */ | 171 | */ |
172 | if (prep->rows_to_go == 0 && | 172 | if (prep->rows_to_go == 0 && |
173 | *out_row_group_ctr < out_row_groups_avail) { | 173 | *out_row_group_ctr < out_row_groups_avail) { |
174 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 174 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
175 | ci++, compptr++) { | 175 | ci++, compptr++) { |
176 | numrows = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / | 176 | numrows = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / |
177 | cinfo->min_DCT_v_scaled_size; | 177 | cinfo->min_DCT_v_scaled_size; |
178 | expand_bottom_edge(output_buf[ci], | 178 | expand_bottom_edge(output_buf[ci], |
179 | compptr->width_in_blocks * compptr->DCT_h_scaled_size, | 179 | compptr->width_in_blocks * compptr->DCT_h_scaled_size, |
180 | (int) (*out_row_group_ctr * numrows), | 180 | (int) (*out_row_group_ctr * numrows), |
181 | (int) (out_row_groups_avail * numrows)); | 181 | (int) (out_row_groups_avail * numrows)); |
182 | } | 182 | } |
183 | *out_row_group_ctr = out_row_groups_avail; | 183 | *out_row_group_ctr = out_row_groups_avail; |
184 | break; /* can exit outer loop without test */ | 184 | break; /* can exit outer loop without test */ |
185 | } | 185 | } |
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | #ifdef CONTEXT_ROWS_SUPPORTED | 190 | #ifdef CONTEXT_ROWS_SUPPORTED |
191 | 191 | ||
192 | /* | 192 | /* |
193 | * Process some data in the context case. | 193 | * Process some data in the context case. |
194 | */ | 194 | */ |
195 | 195 | ||
196 | METHODDEF(void) | 196 | METHODDEF(void) |
197 | pre_process_context (j_compress_ptr cinfo, | 197 | pre_process_context (j_compress_ptr cinfo, |
198 | JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, | 198 | JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, |
199 | JDIMENSION in_rows_avail, | 199 | JDIMENSION in_rows_avail, |
200 | JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, | 200 | JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, |
201 | JDIMENSION out_row_groups_avail) | 201 | JDIMENSION out_row_groups_avail) |
202 | { | 202 | { |
203 | my_prep_ptr prep = (my_prep_ptr) cinfo->prep; | 203 | my_prep_ptr prep = (my_prep_ptr) cinfo->prep; |
204 | int numrows, ci; | 204 | int numrows, ci; |
205 | int buf_height = cinfo->max_v_samp_factor * 3; | 205 | int buf_height = cinfo->max_v_samp_factor * 3; |
206 | JDIMENSION inrows; | 206 | JDIMENSION inrows; |
207 | 207 | ||
208 | while (*out_row_group_ctr < out_row_groups_avail) { | 208 | while (*out_row_group_ctr < out_row_groups_avail) { |
209 | if (*in_row_ctr < in_rows_avail) { | 209 | if (*in_row_ctr < in_rows_avail) { |
210 | /* Do color conversion to fill the conversion buffer. */ | 210 | /* Do color conversion to fill the conversion buffer. */ |
211 | inrows = in_rows_avail - *in_row_ctr; | 211 | inrows = in_rows_avail - *in_row_ctr; |
212 | numrows = prep->next_buf_stop - prep->next_buf_row; | 212 | numrows = prep->next_buf_stop - prep->next_buf_row; |
213 | numrows = (int) MIN((JDIMENSION) numrows, inrows); | 213 | numrows = (int) MIN((JDIMENSION) numrows, inrows); |
214 | (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, | 214 | (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, |
215 | prep->color_buf, | 215 | prep->color_buf, |
216 | (JDIMENSION) prep->next_buf_row, | 216 | (JDIMENSION) prep->next_buf_row, |
217 | numrows); | 217 | numrows); |
218 | /* Pad at top of image, if first time through */ | 218 | /* Pad at top of image, if first time through */ |
219 | if (prep->rows_to_go == cinfo->image_height) { | 219 | if (prep->rows_to_go == cinfo->image_height) { |
220 | for (ci = 0; ci < cinfo->num_components; ci++) { | 220 | for (ci = 0; ci < cinfo->num_components; ci++) { |
221 | int row; | 221 | int row; |
222 | for (row = 1; row <= cinfo->max_v_samp_factor; row++) { | 222 | for (row = 1; row <= cinfo->max_v_samp_factor; row++) { |
223 | jcopy_sample_rows(prep->color_buf[ci], 0, | 223 | jcopy_sample_rows(prep->color_buf[ci], 0, |
224 | prep->color_buf[ci], -row, | 224 | prep->color_buf[ci], -row, |
225 | 1, cinfo->image_width); | 225 | 1, cinfo->image_width); |
226 | } | 226 | } |
227 | } | 227 | } |
228 | } | 228 | } |
229 | *in_row_ctr += numrows; | 229 | *in_row_ctr += numrows; |
230 | prep->next_buf_row += numrows; | 230 | prep->next_buf_row += numrows; |
231 | prep->rows_to_go -= numrows; | 231 | prep->rows_to_go -= numrows; |
232 | } else { | 232 | } else { |
233 | /* Return for more data, unless we are at the bottom of the image. */ | 233 | /* Return for more data, unless we are at the bottom of the image. */ |
234 | if (prep->rows_to_go != 0) | 234 | if (prep->rows_to_go != 0) |
235 | break; | 235 | break; |
236 | /* When at bottom of image, pad to fill the conversion buffer. */ | 236 | /* When at bottom of image, pad to fill the conversion buffer. */ |
237 | if (prep->next_buf_row < prep->next_buf_stop) { | 237 | if (prep->next_buf_row < prep->next_buf_stop) { |
238 | for (ci = 0; ci < cinfo->num_components; ci++) { | 238 | for (ci = 0; ci < cinfo->num_components; ci++) { |
239 | expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, | 239 | expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, |
240 | prep->next_buf_row, prep->next_buf_stop); | 240 | prep->next_buf_row, prep->next_buf_stop); |
241 | } | 241 | } |
242 | prep->next_buf_row = prep->next_buf_stop; | 242 | prep->next_buf_row = prep->next_buf_stop; |
243 | } | 243 | } |
244 | } | 244 | } |
245 | /* If we've gotten enough data, downsample a row group. */ | 245 | /* If we've gotten enough data, downsample a row group. */ |
246 | if (prep->next_buf_row == prep->next_buf_stop) { | 246 | if (prep->next_buf_row == prep->next_buf_stop) { |
247 | (*cinfo->downsample->downsample) (cinfo, | 247 | (*cinfo->downsample->downsample) (cinfo, |
248 | prep->color_buf, | 248 | prep->color_buf, |
249 | (JDIMENSION) prep->this_row_group, | 249 | (JDIMENSION) prep->this_row_group, |
250 | output_buf, *out_row_group_ctr); | 250 | output_buf, *out_row_group_ctr); |
251 | (*out_row_group_ctr)++; | 251 | (*out_row_group_ctr)++; |
252 | /* Advance pointers with wraparound as necessary. */ | 252 | /* Advance pointers with wraparound as necessary. */ |
253 | prep->this_row_group += cinfo->max_v_samp_factor; | 253 | prep->this_row_group += cinfo->max_v_samp_factor; |
254 | if (prep->this_row_group >= buf_height) | 254 | if (prep->this_row_group >= buf_height) |
255 | prep->this_row_group = 0; | 255 | prep->this_row_group = 0; |
256 | if (prep->next_buf_row >= buf_height) | 256 | if (prep->next_buf_row >= buf_height) |
257 | prep->next_buf_row = 0; | 257 | prep->next_buf_row = 0; |
258 | prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor; | 258 | prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor; |
259 | } | 259 | } |
260 | } | 260 | } |
261 | } | 261 | } |
262 | 262 | ||
263 | 263 | ||
264 | /* | 264 | /* |
265 | * Create the wrapped-around downsampling input buffer needed for context mode. | 265 | * Create the wrapped-around downsampling input buffer needed for context mode. |
266 | */ | 266 | */ |
267 | 267 | ||
268 | LOCAL(void) | 268 | LOCAL(void) |
269 | create_context_buffer (j_compress_ptr cinfo) | 269 | create_context_buffer (j_compress_ptr cinfo) |
270 | { | 270 | { |
271 | my_prep_ptr prep = (my_prep_ptr) cinfo->prep; | 271 | my_prep_ptr prep = (my_prep_ptr) cinfo->prep; |
272 | int rgroup_height = cinfo->max_v_samp_factor; | 272 | int rgroup_height = cinfo->max_v_samp_factor; |
273 | int ci, i; | 273 | int ci, i; |
274 | jpeg_component_info * compptr; | 274 | jpeg_component_info * compptr; |
275 | JSAMPARRAY true_buffer, fake_buffer; | 275 | JSAMPARRAY true_buffer, fake_buffer; |
276 | 276 | ||
277 | /* Grab enough space for fake row pointers for all the components; | 277 | /* Grab enough space for fake row pointers for all the components; |
278 | * we need five row groups' worth of pointers for each component. | 278 | * we need five row groups' worth of pointers for each component. |
279 | */ | 279 | */ |
280 | fake_buffer = (JSAMPARRAY) | 280 | fake_buffer = (JSAMPARRAY) |
281 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 281 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
282 | (cinfo->num_components * 5 * rgroup_height) * | 282 | (cinfo->num_components * 5 * rgroup_height) * |
283 | SIZEOF(JSAMPROW)); | 283 | SIZEOF(JSAMPROW)); |
284 | 284 | ||
285 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 285 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
286 | ci++, compptr++) { | 286 | ci++, compptr++) { |
287 | /* Allocate the actual buffer space (3 row groups) for this component. | 287 | /* Allocate the actual buffer space (3 row groups) for this component. |
288 | * We make the buffer wide enough to allow the downsampler to edge-expand | 288 | * We make the buffer wide enough to allow the downsampler to edge-expand |
289 | * horizontally within the buffer, if it so chooses. | 289 | * horizontally within the buffer, if it so chooses. |
290 | */ | 290 | */ |
291 | true_buffer = (*cinfo->mem->alloc_sarray) | 291 | true_buffer = (*cinfo->mem->alloc_sarray) |
292 | ((j_common_ptr) cinfo, JPOOL_IMAGE, | 292 | ((j_common_ptr) cinfo, JPOOL_IMAGE, |
293 | (JDIMENSION) (((long) compptr->width_in_blocks * | 293 | (JDIMENSION) (((long) compptr->width_in_blocks * |
294 | cinfo->min_DCT_h_scaled_size * | 294 | cinfo->min_DCT_h_scaled_size * |
295 | cinfo->max_h_samp_factor) / compptr->h_samp_factor), | 295 | cinfo->max_h_samp_factor) / compptr->h_samp_factor), |
296 | (JDIMENSION) (3 * rgroup_height)); | 296 | (JDIMENSION) (3 * rgroup_height)); |
297 | /* Copy true buffer row pointers into the middle of the fake row array */ | 297 | /* Copy true buffer row pointers into the middle of the fake row array */ |
298 | MEMCOPY(fake_buffer + rgroup_height, true_buffer, | 298 | MEMCOPY(fake_buffer + rgroup_height, true_buffer, |
299 | 3 * rgroup_height * SIZEOF(JSAMPROW)); | 299 | 3 * rgroup_height * SIZEOF(JSAMPROW)); |
300 | /* Fill in the above and below wraparound pointers */ | 300 | /* Fill in the above and below wraparound pointers */ |
301 | for (i = 0; i < rgroup_height; i++) { | 301 | for (i = 0; i < rgroup_height; i++) { |
302 | fake_buffer[i] = true_buffer[2 * rgroup_height + i]; | 302 | fake_buffer[i] = true_buffer[2 * rgroup_height + i]; |
303 | fake_buffer[4 * rgroup_height + i] = true_buffer[i]; | 303 | fake_buffer[4 * rgroup_height + i] = true_buffer[i]; |
304 | } | 304 | } |
305 | prep->color_buf[ci] = fake_buffer + rgroup_height; | 305 | prep->color_buf[ci] = fake_buffer + rgroup_height; |
306 | fake_buffer += 5 * rgroup_height; /* point to space for next component */ | 306 | fake_buffer += 5 * rgroup_height; /* point to space for next component */ |
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
310 | #endif /* CONTEXT_ROWS_SUPPORTED */ | 310 | #endif /* CONTEXT_ROWS_SUPPORTED */ |
311 | 311 | ||
312 | 312 | ||
313 | /* | 313 | /* |
314 | * Initialize preprocessing controller. | 314 | * Initialize preprocessing controller. |
315 | */ | 315 | */ |
316 | 316 | ||
317 | GLOBAL(void) | 317 | GLOBAL(void) |
318 | jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer) | 318 | jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer) |
319 | { | 319 | { |
320 | my_prep_ptr prep; | 320 | my_prep_ptr prep; |
321 | int ci; | 321 | int ci; |
322 | jpeg_component_info * compptr; | 322 | jpeg_component_info * compptr; |
323 | 323 | ||
324 | if (need_full_buffer) /* safety check */ | 324 | if (need_full_buffer) /* safety check */ |
325 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 325 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); |
326 | 326 | ||
327 | prep = (my_prep_ptr) | 327 | prep = (my_prep_ptr) |
328 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 328 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
329 | SIZEOF(my_prep_controller)); | 329 | SIZEOF(my_prep_controller)); |
330 | cinfo->prep = (struct jpeg_c_prep_controller *) prep; | 330 | cinfo->prep = (struct jpeg_c_prep_controller *) prep; |
331 | prep->pub.start_pass = start_pass_prep; | 331 | prep->pub.start_pass = start_pass_prep; |
332 | 332 | ||
333 | /* Allocate the color conversion buffer. | 333 | /* Allocate the color conversion buffer. |
334 | * We make the buffer wide enough to allow the downsampler to edge-expand | 334 | * We make the buffer wide enough to allow the downsampler to edge-expand |
335 | * horizontally within the buffer, if it so chooses. | 335 | * horizontally within the buffer, if it so chooses. |
336 | */ | 336 | */ |
337 | if (cinfo->downsample->need_context_rows) { | 337 | if (cinfo->downsample->need_context_rows) { |
338 | /* Set up to provide context rows */ | 338 | /* Set up to provide context rows */ |
339 | #ifdef CONTEXT_ROWS_SUPPORTED | 339 | #ifdef CONTEXT_ROWS_SUPPORTED |
340 | prep->pub.pre_process_data = pre_process_context; | 340 | prep->pub.pre_process_data = pre_process_context; |
341 | create_context_buffer(cinfo); | 341 | create_context_buffer(cinfo); |
342 | #else | 342 | #else |
343 | ERREXIT(cinfo, JERR_NOT_COMPILED); | 343 | ERREXIT(cinfo, JERR_NOT_COMPILED); |
344 | #endif | 344 | #endif |
345 | } else { | 345 | } else { |
346 | /* No context, just make it tall enough for one row group */ | 346 | /* No context, just make it tall enough for one row group */ |
347 | prep->pub.pre_process_data = pre_process_data; | 347 | prep->pub.pre_process_data = pre_process_data; |
348 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 348 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
349 | ci++, compptr++) { | 349 | ci++, compptr++) { |
350 | prep->color_buf[ci] = (*cinfo->mem->alloc_sarray) | 350 | prep->color_buf[ci] = (*cinfo->mem->alloc_sarray) |
351 | ((j_common_ptr) cinfo, JPOOL_IMAGE, | 351 | ((j_common_ptr) cinfo, JPOOL_IMAGE, |
352 | (JDIMENSION) (((long) compptr->width_in_blocks * | 352 | (JDIMENSION) (((long) compptr->width_in_blocks * |
353 | cinfo->min_DCT_h_scaled_size * | 353 | cinfo->min_DCT_h_scaled_size * |
354 | cinfo->max_h_samp_factor) / compptr->h_samp_factor), | 354 | cinfo->max_h_samp_factor) / compptr->h_samp_factor), |
355 | (JDIMENSION) cinfo->max_v_samp_factor); | 355 | (JDIMENSION) cinfo->max_v_samp_factor); |
356 | } | 356 | } |
357 | } | 357 | } |
358 | } | 358 | } |