Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: jdpostct.c

Issue 1939823002: Update to libjpeg_turbo 1.4.90 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@master
Patch Set: Response to comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« jdhuff.c ('K') | « jdphuff.c ('k') | jdsample.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * jdpostct.c 2 * jdpostct.c
3 * 3 *
4 * This file was part of the Independent JPEG Group's software:
4 * Copyright (C) 1994-1996, Thomas G. Lane. 5 * Copyright (C) 1994-1996, Thomas G. Lane.
5 * This file is part of the Independent JPEG Group's software. 6 * It was modified by The libjpeg-turbo Project to include only code relevant
6 * For conditions of distribution and use, see the accompanying README file. 7 * to libjpeg-turbo.
8 * For conditions of distribution and use, see the accompanying README.ijg
9 * file.
7 * 10 *
8 * This file contains the decompression postprocessing controller. 11 * This file contains the decompression postprocessing controller.
9 * This controller manages the upsampling, color conversion, and color 12 * This controller manages the upsampling, color conversion, and color
10 * quantization/reduction steps; specifically, it controls the buffering 13 * quantization/reduction steps; specifically, it controls the buffering
11 * between upsample/color conversion and color quantization/reduction. 14 * between upsample/color conversion and color quantization/reduction.
12 * 15 *
13 * If no color quantization/reduction is required, then this module has no 16 * If no color quantization/reduction is required, then this module has no
14 * work to do, and it just hands off to the upsample/color conversion code. 17 * work to do, and it just hands off to the upsample/color conversion code.
15 * An integrated upsample/convert/quantize process would replace this module 18 * An integrated upsample/convert/quantize process would replace this module
16 * entirely. 19 * entirely.
17 */ 20 */
18 21
19 #define JPEG_INTERNALS 22 #define JPEG_INTERNALS
20 #include "jinclude.h" 23 #include "jinclude.h"
21 #include "jpeglib.h" 24 #include "jpeglib.h"
22 25
23 26
24 /* Private buffer controller object */ 27 /* Private buffer controller object */
25 28
26 typedef struct { 29 typedef struct {
27 struct jpeg_d_post_controller pub; /* public fields */ 30 struct jpeg_d_post_controller pub; /* public fields */
28 31
29 /* Color quantization source buffer: this holds output data from 32 /* Color quantization source buffer: this holds output data from
30 * the upsample/color conversion step to be passed to the quantizer. 33 * the upsample/color conversion step to be passed to the quantizer.
31 * For two-pass color quantization, we need a full-image buffer; 34 * For two-pass color quantization, we need a full-image buffer;
32 * for one-pass operation, a strip buffer is sufficient. 35 * for one-pass operation, a strip buffer is sufficient.
33 */ 36 */
34 jvirt_sarray_ptr whole_image;»/* virtual array, or NULL if one-pass */ 37 jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
35 JSAMPARRAY buffer;» » /* strip buffer, or current strip of virtual */ 38 JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
36 JDIMENSION strip_height;» /* buffer size in rows */ 39 JDIMENSION strip_height; /* buffer size in rows */
37 /* for two-pass mode only: */ 40 /* for two-pass mode only: */
38 JDIMENSION starting_row;» /* row # of first row in current strip */ 41 JDIMENSION starting_row; /* row # of first row in current strip */
39 JDIMENSION next_row;» » /* index of next row to fill/empty in strip */ 42 JDIMENSION next_row; /* index of next row to fill/empty in strip */
40 } my_post_controller; 43 } my_post_controller;
41 44
42 typedef my_post_controller * my_post_ptr; 45 typedef my_post_controller *my_post_ptr;
43 46
44 47
45 /* Forward declarations */ 48 /* Forward declarations */
46 METHODDEF(void) post_process_1pass 49 METHODDEF(void) post_process_1pass
47 » JPP((j_decompress_ptr cinfo, 50 (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
48 » JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 51 JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail,
49 » JDIMENSION in_row_groups_avail, 52 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
50 » JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 53 JDIMENSION out_rows_avail);
51 » JDIMENSION out_rows_avail));
52 #ifdef QUANT_2PASS_SUPPORTED 54 #ifdef QUANT_2PASS_SUPPORTED
53 METHODDEF(void) post_process_prepass 55 METHODDEF(void) post_process_prepass
54 » JPP((j_decompress_ptr cinfo, 56 (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
55 » JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 57 JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail,
56 » JDIMENSION in_row_groups_avail, 58 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
57 » JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 59 JDIMENSION out_rows_avail);
58 » JDIMENSION out_rows_avail));
59 METHODDEF(void) post_process_2pass 60 METHODDEF(void) post_process_2pass
60 » JPP((j_decompress_ptr cinfo, 61 (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
61 » JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 62 JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail,
62 » JDIMENSION in_row_groups_avail, 63 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
63 » JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 64 JDIMENSION out_rows_avail);
64 » JDIMENSION out_rows_avail));
65 #endif 65 #endif
66 66
67 67
68 /* 68 /*
69 * Initialize for a processing pass. 69 * Initialize for a processing pass.
70 */ 70 */
71 71
72 METHODDEF(void) 72 METHODDEF(void)
73 start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode) 73 start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
74 { 74 {
75 my_post_ptr post = (my_post_ptr) cinfo->post; 75 my_post_ptr post = (my_post_ptr) cinfo->post;
76 76
77 switch (pass_mode) { 77 switch (pass_mode) {
78 case JBUF_PASS_THRU: 78 case JBUF_PASS_THRU:
79 if (cinfo->quantize_colors) { 79 if (cinfo->quantize_colors) {
80 /* Single-pass processing with color quantization. */ 80 /* Single-pass processing with color quantization. */
81 post->pub.post_process_data = post_process_1pass; 81 post->pub.post_process_data = post_process_1pass;
82 /* We could be doing buffered-image output before starting a 2-pass 82 /* We could be doing buffered-image output before starting a 2-pass
83 * color quantization; in that case, jinit_d_post_controller did not 83 * color quantization; in that case, jinit_d_post_controller did not
84 * allocate a strip buffer. Use the virtual-array buffer as workspace. 84 * allocate a strip buffer. Use the virtual-array buffer as workspace.
85 */ 85 */
86 if (post->buffer == NULL) { 86 if (post->buffer == NULL) {
87 » post->buffer = (*cinfo->mem->access_virt_sarray) 87 post->buffer = (*cinfo->mem->access_virt_sarray)
88 » ((j_common_ptr) cinfo, post->whole_image, 88 ((j_common_ptr) cinfo, post->whole_image,
89 » (JDIMENSION) 0, post->strip_height, TRUE); 89 (JDIMENSION) 0, post->strip_height, TRUE);
90 } 90 }
91 } else { 91 } else {
92 /* For single-pass processing without color quantization, 92 /* For single-pass processing without color quantization,
93 * I have no work to do; just call the upsampler directly. 93 * I have no work to do; just call the upsampler directly.
94 */ 94 */
95 post->pub.post_process_data = cinfo->upsample->upsample; 95 post->pub.post_process_data = cinfo->upsample->upsample;
96 } 96 }
97 break; 97 break;
98 #ifdef QUANT_2PASS_SUPPORTED 98 #ifdef QUANT_2PASS_SUPPORTED
99 case JBUF_SAVE_AND_PASS: 99 case JBUF_SAVE_AND_PASS:
(...skipping 17 matching lines...) Expand all
117 } 117 }
118 118
119 119
120 /* 120 /*
121 * Process some data in the one-pass (strip buffer) case. 121 * Process some data in the one-pass (strip buffer) case.
122 * This is used for color precision reduction as well as one-pass quantization. 122 * This is used for color precision reduction as well as one-pass quantization.
123 */ 123 */
124 124
125 METHODDEF(void) 125 METHODDEF(void)
126 post_process_1pass (j_decompress_ptr cinfo, 126 post_process_1pass (j_decompress_ptr cinfo,
127 » » JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 127 JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
128 » » JDIMENSION in_row_groups_avail, 128 JDIMENSION in_row_groups_avail,
129 » » JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 129 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
130 » » JDIMENSION out_rows_avail) 130 JDIMENSION out_rows_avail)
131 { 131 {
132 my_post_ptr post = (my_post_ptr) cinfo->post; 132 my_post_ptr post = (my_post_ptr) cinfo->post;
133 JDIMENSION num_rows, max_rows; 133 JDIMENSION num_rows, max_rows;
134 134
135 /* Fill the buffer, but not more than what we can dump out in one go. */ 135 /* Fill the buffer, but not more than what we can dump out in one go. */
136 /* Note we rely on the upsampler to detect bottom of image. */ 136 /* Note we rely on the upsampler to detect bottom of image. */
137 max_rows = out_rows_avail - *out_row_ctr; 137 max_rows = out_rows_avail - *out_row_ctr;
138 if (max_rows > post->strip_height) 138 if (max_rows > post->strip_height)
139 max_rows = post->strip_height; 139 max_rows = post->strip_height;
140 num_rows = 0; 140 num_rows = 0;
141 (*cinfo->upsample->upsample) (cinfo, 141 (*cinfo->upsample->upsample) (cinfo,
142 » » input_buf, in_row_group_ctr, in_row_groups_avail, 142 input_buf, in_row_group_ctr, in_row_groups_avail,
143 » » post->buffer, &num_rows, max_rows); 143 post->buffer, &num_rows, max_rows);
144 /* Quantize and emit data. */ 144 /* Quantize and emit data. */
145 (*cinfo->cquantize->color_quantize) (cinfo, 145 (*cinfo->cquantize->color_quantize) (cinfo,
146 » » post->buffer, output_buf + *out_row_ctr, (int) num_rows); 146 post->buffer, output_buf + *out_row_ctr, (int) num_rows);
147 *out_row_ctr += num_rows; 147 *out_row_ctr += num_rows;
148 } 148 }
149 149
150 150
151 #ifdef QUANT_2PASS_SUPPORTED 151 #ifdef QUANT_2PASS_SUPPORTED
152 152
153 /* 153 /*
154 * Process some data in the first pass of 2-pass quantization. 154 * Process some data in the first pass of 2-pass quantization.
155 */ 155 */
156 156
157 METHODDEF(void) 157 METHODDEF(void)
158 post_process_prepass (j_decompress_ptr cinfo, 158 post_process_prepass (j_decompress_ptr cinfo,
159 » » JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 159 JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
160 » » JDIMENSION in_row_groups_avail, 160 JDIMENSION in_row_groups_avail,
161 » » JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 161 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
162 » » JDIMENSION out_rows_avail) 162 JDIMENSION out_rows_avail)
163 { 163 {
164 my_post_ptr post = (my_post_ptr) cinfo->post; 164 my_post_ptr post = (my_post_ptr) cinfo->post;
165 JDIMENSION old_next_row, num_rows; 165 JDIMENSION old_next_row, num_rows;
166 166
167 /* Reposition virtual buffer if at start of strip. */ 167 /* Reposition virtual buffer if at start of strip. */
168 if (post->next_row == 0) { 168 if (post->next_row == 0) {
169 post->buffer = (*cinfo->mem->access_virt_sarray) 169 post->buffer = (*cinfo->mem->access_virt_sarray)
170 » ((j_common_ptr) cinfo, post->whole_image, 170 ((j_common_ptr) cinfo, post->whole_image,
171 » post->starting_row, post->strip_height, TRUE); 171 post->starting_row, post->strip_height, TRUE);
172 } 172 }
173 173
174 /* Upsample some data (up to a strip height's worth). */ 174 /* Upsample some data (up to a strip height's worth). */
175 old_next_row = post->next_row; 175 old_next_row = post->next_row;
176 (*cinfo->upsample->upsample) (cinfo, 176 (*cinfo->upsample->upsample) (cinfo,
177 » » input_buf, in_row_group_ctr, in_row_groups_avail, 177 input_buf, in_row_group_ctr, in_row_groups_avail,
178 » » post->buffer, &post->next_row, post->strip_height); 178 post->buffer, &post->next_row, post->strip_height);
179 179
180 /* Allow quantizer to scan new data. No data is emitted, */ 180 /* Allow quantizer to scan new data. No data is emitted, */
181 /* but we advance out_row_ctr so outer loop can tell when we're done. */ 181 /* but we advance out_row_ctr so outer loop can tell when we're done. */
182 if (post->next_row > old_next_row) { 182 if (post->next_row > old_next_row) {
183 num_rows = post->next_row - old_next_row; 183 num_rows = post->next_row - old_next_row;
184 (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row, 184 (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
185 » » » » » (JSAMPARRAY) NULL, (int) num_rows); 185 (JSAMPARRAY) NULL, (int) num_rows);
186 *out_row_ctr += num_rows; 186 *out_row_ctr += num_rows;
187 } 187 }
188 188
189 /* Advance if we filled the strip. */ 189 /* Advance if we filled the strip. */
190 if (post->next_row >= post->strip_height) { 190 if (post->next_row >= post->strip_height) {
191 post->starting_row += post->strip_height; 191 post->starting_row += post->strip_height;
192 post->next_row = 0; 192 post->next_row = 0;
193 } 193 }
194 } 194 }
195 195
196 196
197 /* 197 /*
198 * Process some data in the second pass of 2-pass quantization. 198 * Process some data in the second pass of 2-pass quantization.
199 */ 199 */
200 200
201 METHODDEF(void) 201 METHODDEF(void)
202 post_process_2pass (j_decompress_ptr cinfo, 202 post_process_2pass (j_decompress_ptr cinfo,
203 » » JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 203 JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
204 » » JDIMENSION in_row_groups_avail, 204 JDIMENSION in_row_groups_avail,
205 » » JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 205 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
206 » » JDIMENSION out_rows_avail) 206 JDIMENSION out_rows_avail)
207 { 207 {
208 my_post_ptr post = (my_post_ptr) cinfo->post; 208 my_post_ptr post = (my_post_ptr) cinfo->post;
209 JDIMENSION num_rows, max_rows; 209 JDIMENSION num_rows, max_rows;
210 210
211 /* Reposition virtual buffer if at start of strip. */ 211 /* Reposition virtual buffer if at start of strip. */
212 if (post->next_row == 0) { 212 if (post->next_row == 0) {
213 post->buffer = (*cinfo->mem->access_virt_sarray) 213 post->buffer = (*cinfo->mem->access_virt_sarray)
214 » ((j_common_ptr) cinfo, post->whole_image, 214 ((j_common_ptr) cinfo, post->whole_image,
215 » post->starting_row, post->strip_height, FALSE); 215 post->starting_row, post->strip_height, FALSE);
216 } 216 }
217 217
218 /* Determine number of rows to emit. */ 218 /* Determine number of rows to emit. */
219 num_rows = post->strip_height - post->next_row; /* available in strip */ 219 num_rows = post->strip_height - post->next_row; /* available in strip */
220 max_rows = out_rows_avail - *out_row_ctr; /* available in output area */ 220 max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
221 if (num_rows > max_rows) 221 if (num_rows > max_rows)
222 num_rows = max_rows; 222 num_rows = max_rows;
223 /* We have to check bottom of image here, can't depend on upsampler. */ 223 /* We have to check bottom of image here, can't depend on upsampler. */
224 max_rows = cinfo->output_height - post->starting_row; 224 max_rows = cinfo->output_height - post->starting_row;
225 if (num_rows > max_rows) 225 if (num_rows > max_rows)
226 num_rows = max_rows; 226 num_rows = max_rows;
227 227
228 /* Quantize and emit data. */ 228 /* Quantize and emit data. */
229 (*cinfo->cquantize->color_quantize) (cinfo, 229 (*cinfo->cquantize->color_quantize) (cinfo,
230 » » post->buffer + post->next_row, output_buf + *out_row_ctr, 230 post->buffer + post->next_row, output_buf + *out_row_ctr,
231 » » (int) num_rows); 231 (int) num_rows);
232 *out_row_ctr += num_rows; 232 *out_row_ctr += num_rows;
233 233
234 /* Advance if we filled the strip. */ 234 /* Advance if we filled the strip. */
235 post->next_row += num_rows; 235 post->next_row += num_rows;
236 if (post->next_row >= post->strip_height) { 236 if (post->next_row >= post->strip_height) {
237 post->starting_row += post->strip_height; 237 post->starting_row += post->strip_height;
238 post->next_row = 0; 238 post->next_row = 0;
239 } 239 }
240 } 240 }
241 241
242 #endif /* QUANT_2PASS_SUPPORTED */ 242 #endif /* QUANT_2PASS_SUPPORTED */
243 243
244 244
245 /* 245 /*
246 * Initialize postprocessing controller. 246 * Initialize postprocessing controller.
247 */ 247 */
248 248
249 GLOBAL(void) 249 GLOBAL(void)
250 jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer) 250 jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
251 { 251 {
252 my_post_ptr post; 252 my_post_ptr post;
253 253
254 post = (my_post_ptr) 254 post = (my_post_ptr)
255 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 255 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
256 » » » » SIZEOF(my_post_controller)); 256 sizeof(my_post_controller));
257 cinfo->post = (struct jpeg_d_post_controller *) post; 257 cinfo->post = (struct jpeg_d_post_controller *) post;
258 post->pub.start_pass = start_pass_dpost; 258 post->pub.start_pass = start_pass_dpost;
259 post->whole_image = NULL;» /* flag for no virtual arrays */ 259 post->whole_image = NULL; /* flag for no virtual arrays */
260 post->buffer = NULL;» » /* flag for no strip buffer */ 260 post->buffer = NULL; /* flag for no strip buffer */
261 261
262 /* Create the quantization buffer, if needed */ 262 /* Create the quantization buffer, if needed */
263 if (cinfo->quantize_colors) { 263 if (cinfo->quantize_colors) {
264 /* The buffer strip height is max_v_samp_factor, which is typically 264 /* The buffer strip height is max_v_samp_factor, which is typically
265 * an efficient number of rows for upsampling to return. 265 * an efficient number of rows for upsampling to return.
266 * (In the presence of output rescaling, we might want to be smarter?) 266 * (In the presence of output rescaling, we might want to be smarter?)
267 */ 267 */
268 post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor; 268 post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
269 if (need_full_buffer) { 269 if (need_full_buffer) {
270 /* Two-pass color quantization: need full-image storage. */ 270 /* Two-pass color quantization: need full-image storage. */
271 /* We round up the number of rows to a multiple of the strip height. */ 271 /* We round up the number of rows to a multiple of the strip height. */
272 #ifdef QUANT_2PASS_SUPPORTED 272 #ifdef QUANT_2PASS_SUPPORTED
273 post->whole_image = (*cinfo->mem->request_virt_sarray) 273 post->whole_image = (*cinfo->mem->request_virt_sarray)
274 » ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, 274 ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
275 » cinfo->output_width * cinfo->out_color_components, 275 cinfo->output_width * cinfo->out_color_components,
276 » (JDIMENSION) jround_up((long) cinfo->output_height, 276 (JDIMENSION) jround_up((long) cinfo->output_height,
277 » » » » (long) post->strip_height), 277 (long) post->strip_height),
278 » post->strip_height); 278 post->strip_height);
279 #else 279 #else
280 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); 280 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
281 #endif /* QUANT_2PASS_SUPPORTED */ 281 #endif /* QUANT_2PASS_SUPPORTED */
282 } else { 282 } else {
283 /* One-pass color quantization: just make a strip buffer. */ 283 /* One-pass color quantization: just make a strip buffer. */
284 post->buffer = (*cinfo->mem->alloc_sarray) 284 post->buffer = (*cinfo->mem->alloc_sarray)
285 » ((j_common_ptr) cinfo, JPOOL_IMAGE, 285 ((j_common_ptr) cinfo, JPOOL_IMAGE,
286 » cinfo->output_width * cinfo->out_color_components, 286 cinfo->output_width * cinfo->out_color_components,
287 » post->strip_height); 287 post->strip_height);
288 } 288 }
289 } 289 }
290 } 290 }
OLDNEW
« jdhuff.c ('K') | « jdphuff.c ('k') | jdsample.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698