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