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