/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-2026, 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 row group's |
45 | | * worth of components for the downsampling step. At the bottom of the image, |
46 | | * we pad to a full row group by replicating the last component row(s). The |
47 | | * downsampler's last output row is then replicated if needed to pad out to a |
48 | | * full iMCU row. |
49 | | * |
50 | | * When providing context rows, we must buffer three row groups' worth of |
51 | | * components. 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. At the top |
55 | | * and bottom of the image, we create dummy context rows by copying the first |
56 | | * or last real component row(s). This copying could be avoided by pointer |
57 | | * hacking, as is done in jdmainct.c, but it doesn't seem worth the trouble on |
58 | | * 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 | 93.5k | { |
91 | 93.5k | my_prep_ptr prep = (my_prep_ptr)cinfo->prep; |
92 | | |
93 | 93.5k | 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 | 93.5k | prep->rows_to_go = cinfo->image_height; |
98 | | /* Mark the conversion buffer empty */ |
99 | 93.5k | prep->next_buf_row = 0; |
100 | 93.5k | #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 | 93.5k | prep->this_row_group = 0; |
105 | | /* Set next_buf_stop to stop after two row groups have been read in. */ |
106 | 93.5k | prep->next_buf_stop = 2 * cinfo->max_v_samp_factor; |
107 | 93.5k | #endif |
108 | 93.5k | } jcprepct-8.c:start_pass_prep Line | Count | Source | 90 | 44.8k | { | 91 | 44.8k | my_prep_ptr prep = (my_prep_ptr)cinfo->prep; | 92 | | | 93 | 44.8k | 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 | 44.8k | prep->rows_to_go = cinfo->image_height; | 98 | | /* Mark the conversion buffer empty */ | 99 | 44.8k | prep->next_buf_row = 0; | 100 | 44.8k | #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 | 44.8k | prep->this_row_group = 0; | 105 | | /* Set next_buf_stop to stop after two row groups have been read in. */ | 106 | 44.8k | prep->next_buf_stop = 2 * cinfo->max_v_samp_factor; | 107 | 44.8k | #endif | 108 | 44.8k | } |
jcprepct-12.c:start_pass_prep Line | Count | Source | 90 | 37.4k | { | 91 | 37.4k | my_prep_ptr prep = (my_prep_ptr)cinfo->prep; | 92 | | | 93 | 37.4k | 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 | 37.4k | prep->rows_to_go = cinfo->image_height; | 98 | | /* Mark the conversion buffer empty */ | 99 | 37.4k | prep->next_buf_row = 0; | 100 | 37.4k | #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 | 37.4k | prep->this_row_group = 0; | 105 | | /* Set next_buf_stop to stop after two row groups have been read in. */ | 106 | 37.4k | prep->next_buf_stop = 2 * cinfo->max_v_samp_factor; | 107 | 37.4k | #endif | 108 | 37.4k | } |
jcprepct-16.c:start_pass_prep Line | Count | Source | 90 | 11.2k | { | 91 | 11.2k | my_prep_ptr prep = (my_prep_ptr)cinfo->prep; | 92 | | | 93 | 11.2k | 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 | 11.2k | prep->rows_to_go = cinfo->image_height; | 98 | | /* Mark the conversion buffer empty */ | 99 | 11.2k | prep->next_buf_row = 0; | 100 | 11.2k | #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 | 11.2k | prep->this_row_group = 0; | 105 | | /* Set next_buf_stop to stop after two row groups have been read in. */ | 106 | 11.2k | prep->next_buf_stop = 2 * cinfo->max_v_samp_factor; | 107 | 11.2k | #endif | 108 | 11.2k | } |
|
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 | 159k | { |
120 | 159k | register int row; |
121 | | |
122 | 978k | for (row = input_rows; row < output_rows; row++) { |
123 | 819k | _jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1, |
124 | 819k | num_cols); |
125 | 819k | } |
126 | 159k | } jcprepct-8.c:expand_bottom_edge Line | Count | Source | 119 | 83.1k | { | 120 | 83.1k | register int row; | 121 | | | 122 | 504k | for (row = input_rows; row < output_rows; row++) { | 123 | 421k | _jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1, | 124 | 421k | num_cols); | 125 | 421k | } | 126 | 83.1k | } |
jcprepct-12.c:expand_bottom_edge Line | Count | Source | 119 | 76.4k | { | 120 | 76.4k | register int row; | 121 | | | 122 | 474k | for (row = input_rows; row < output_rows; row++) { | 123 | 397k | _jcopy_sample_rows(image_data, input_rows - 1, image_data, row, 1, | 124 | 397k | num_cols); | 125 | 397k | } | 126 | 76.4k | } |
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 | 111M | { |
144 | 111M | my_prep_ptr prep = (my_prep_ptr)cinfo->prep; |
145 | 111M | int numrows, ci; |
146 | 111M | JDIMENSION inrows; |
147 | 111M | jpeg_component_info *compptr; |
148 | 111M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
149 | | |
150 | 341M | while (*in_row_ctr < in_rows_avail && |
151 | 337M | *out_row_group_ctr < out_row_groups_avail) { |
152 | | /* Do color conversion to fill the conversion buffer. */ |
153 | 230M | inrows = in_rows_avail - *in_row_ctr; |
154 | 230M | numrows = cinfo->max_v_samp_factor - prep->next_buf_row; |
155 | 230M | numrows = (int)MIN((JDIMENSION)numrows, inrows); |
156 | | #ifdef WITH_PROFILE |
157 | | cinfo->master->start = getTime(); |
158 | | #endif |
159 | 230M | (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr, |
160 | 230M | prep->color_buf, |
161 | 230M | (JDIMENSION)prep->next_buf_row, |
162 | 230M | 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 | 230M | *in_row_ctr += numrows; |
169 | 230M | prep->next_buf_row += numrows; |
170 | 230M | prep->rows_to_go -= numrows; |
171 | | /* If at bottom of image, pad to fill the conversion buffer. */ |
172 | 230M | if (prep->rows_to_go == 0 && |
173 | 88.7k | prep->next_buf_row < cinfo->max_v_samp_factor) { |
174 | 35.8k | for (ci = 0; ci < cinfo->num_components; ci++) { |
175 | 27.8k | expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, |
176 | 27.8k | prep->next_buf_row, cinfo->max_v_samp_factor); |
177 | 27.8k | } |
178 | 8.00k | prep->next_buf_row = cinfo->max_v_samp_factor; |
179 | 8.00k | } |
180 | | /* If we've filled the conversion buffer, empty it. */ |
181 | 230M | if (prep->next_buf_row == cinfo->max_v_samp_factor) { |
182 | | #ifdef WITH_PROFILE |
183 | | cinfo->master->start = getTime(); |
184 | | #endif |
185 | 228M | (*cinfo->downsample->_downsample) (cinfo, |
186 | 228M | prep->color_buf, (JDIMENSION)0, |
187 | 228M | 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 | 228M | prep->next_buf_row = 0; |
194 | 228M | (*out_row_group_ctr)++; |
195 | 228M | } |
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 | 230M | if (prep->rows_to_go == 0 && *out_row_group_ctr < out_row_groups_avail) { |
200 | 170k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
201 | 123k | ci++, compptr++) { |
202 | 123k | expand_bottom_edge(output_buf[ci], |
203 | 123k | compptr->width_in_blocks * data_unit, |
204 | 123k | (int)(*out_row_group_ctr * compptr->v_samp_factor), |
205 | 123k | (int)(out_row_groups_avail * compptr->v_samp_factor)); |
206 | 123k | } |
207 | 47.3k | *out_row_group_ctr = out_row_groups_avail; |
208 | 47.3k | break; /* can exit outer loop without test */ |
209 | 47.3k | } |
210 | 230M | } |
211 | 111M | } jcprepct-8.c:pre_process_data Line | Count | Source | 143 | 41.4M | { | 144 | 41.4M | my_prep_ptr prep = (my_prep_ptr)cinfo->prep; | 145 | 41.4M | int numrows, ci; | 146 | 41.4M | JDIMENSION inrows; | 147 | 41.4M | jpeg_component_info *compptr; | 148 | 41.4M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 149 | | | 150 | 133M | while (*in_row_ctr < in_rows_avail && | 151 | 129M | *out_row_group_ctr < out_row_groups_avail) { | 152 | | /* Do color conversion to fill the conversion buffer. */ | 153 | 91.9M | inrows = in_rows_avail - *in_row_ctr; | 154 | 91.9M | numrows = cinfo->max_v_samp_factor - prep->next_buf_row; | 155 | 91.9M | numrows = (int)MIN((JDIMENSION)numrows, inrows); | 156 | | #ifdef WITH_PROFILE | 157 | | cinfo->master->start = getTime(); | 158 | | #endif | 159 | 91.9M | (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr, | 160 | 91.9M | prep->color_buf, | 161 | 91.9M | (JDIMENSION)prep->next_buf_row, | 162 | 91.9M | 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 | 91.9M | *in_row_ctr += numrows; | 169 | 91.9M | prep->next_buf_row += numrows; | 170 | 91.9M | prep->rows_to_go -= numrows; | 171 | | /* If at bottom of image, pad to fill the conversion buffer. */ | 172 | 91.9M | if (prep->rows_to_go == 0 && | 173 | 40.1k | prep->next_buf_row < cinfo->max_v_samp_factor) { | 174 | 17.3k | for (ci = 0; ci < cinfo->num_components; ci++) { | 175 | 13.4k | expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, | 176 | 13.4k | prep->next_buf_row, cinfo->max_v_samp_factor); | 177 | 13.4k | } | 178 | 3.88k | prep->next_buf_row = cinfo->max_v_samp_factor; | 179 | 3.88k | } | 180 | | /* If we've filled the conversion buffer, empty it. */ | 181 | 91.9M | if (prep->next_buf_row == cinfo->max_v_samp_factor) { | 182 | | #ifdef WITH_PROFILE | 183 | | cinfo->master->start = getTime(); | 184 | | #endif | 185 | 90.2M | (*cinfo->downsample->_downsample) (cinfo, | 186 | 90.2M | prep->color_buf, (JDIMENSION)0, | 187 | 90.2M | 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 | 90.2M | prep->next_buf_row = 0; | 194 | 90.2M | (*out_row_group_ctr)++; | 195 | 90.2M | } | 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 | 91.9M | if (prep->rows_to_go == 0 && *out_row_group_ctr < out_row_groups_avail) { | 200 | 85.0k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 201 | 61.4k | ci++, compptr++) { | 202 | 61.4k | expand_bottom_edge(output_buf[ci], | 203 | 61.4k | compptr->width_in_blocks * data_unit, | 204 | 61.4k | (int)(*out_row_group_ctr * compptr->v_samp_factor), | 205 | 61.4k | (int)(out_row_groups_avail * compptr->v_samp_factor)); | 206 | 61.4k | } | 207 | 23.5k | *out_row_group_ctr = out_row_groups_avail; | 208 | 23.5k | break; /* can exit outer loop without test */ | 209 | 23.5k | } | 210 | 91.9M | } | 211 | 41.4M | } |
jcprepct-12.c:pre_process_data Line | Count | Source | 143 | 39.5M | { | 144 | 39.5M | my_prep_ptr prep = (my_prep_ptr)cinfo->prep; | 145 | 39.5M | int numrows, ci; | 146 | 39.5M | JDIMENSION inrows; | 147 | 39.5M | jpeg_component_info *compptr; | 148 | 39.5M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 149 | | | 150 | 148M | while (*in_row_ctr < in_rows_avail && | 151 | 148M | *out_row_group_ctr < out_row_groups_avail) { | 152 | | /* Do color conversion to fill the conversion buffer. */ | 153 | 108M | inrows = in_rows_avail - *in_row_ctr; | 154 | 108M | numrows = cinfo->max_v_samp_factor - prep->next_buf_row; | 155 | 108M | numrows = (int)MIN((JDIMENSION)numrows, inrows); | 156 | | #ifdef WITH_PROFILE | 157 | | cinfo->master->start = getTime(); | 158 | | #endif | 159 | 108M | (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr, | 160 | 108M | prep->color_buf, | 161 | 108M | (JDIMENSION)prep->next_buf_row, | 162 | 108M | 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 | 108M | *in_row_ctr += numrows; | 169 | 108M | prep->next_buf_row += numrows; | 170 | 108M | prep->rows_to_go -= numrows; | 171 | | /* If at bottom of image, pad to fill the conversion buffer. */ | 172 | 108M | if (prep->rows_to_go == 0 && | 173 | 37.4k | prep->next_buf_row < cinfo->max_v_samp_factor) { | 174 | 18.5k | for (ci = 0; ci < cinfo->num_components; ci++) { | 175 | 14.3k | expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, | 176 | 14.3k | prep->next_buf_row, cinfo->max_v_samp_factor); | 177 | 14.3k | } | 178 | 4.11k | prep->next_buf_row = cinfo->max_v_samp_factor; | 179 | 4.11k | } | 180 | | /* If we've filled the conversion buffer, empty it. */ | 181 | 108M | if (prep->next_buf_row == cinfo->max_v_samp_factor) { | 182 | | #ifdef WITH_PROFILE | 183 | | cinfo->master->start = getTime(); | 184 | | #endif | 185 | 108M | (*cinfo->downsample->_downsample) (cinfo, | 186 | 108M | prep->color_buf, (JDIMENSION)0, | 187 | 108M | 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 | 108M | prep->next_buf_row = 0; | 194 | 108M | (*out_row_group_ctr)++; | 195 | 108M | } | 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 | 108M | if (prep->rows_to_go == 0 && *out_row_group_ctr < out_row_groups_avail) { | 200 | 85.7k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 201 | 62.0k | ci++, compptr++) { | 202 | 62.0k | expand_bottom_edge(output_buf[ci], | 203 | 62.0k | compptr->width_in_blocks * data_unit, | 204 | 62.0k | (int)(*out_row_group_ctr * compptr->v_samp_factor), | 205 | 62.0k | (int)(out_row_groups_avail * compptr->v_samp_factor)); | 206 | 62.0k | } | 207 | 23.7k | *out_row_group_ctr = out_row_groups_avail; | 208 | 23.7k | break; /* can exit outer loop without test */ | 209 | 23.7k | } | 210 | 108M | } | 211 | 39.5M | } |
jcprepct-16.c:pre_process_data Line | Count | Source | 143 | 30.1M | { | 144 | 30.1M | my_prep_ptr prep = (my_prep_ptr)cinfo->prep; | 145 | 30.1M | int numrows, ci; | 146 | 30.1M | JDIMENSION inrows; | 147 | 30.1M | jpeg_component_info *compptr; | 148 | 30.1M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 149 | | | 150 | 60.2M | while (*in_row_ctr < in_rows_avail && | 151 | 60.2M | *out_row_group_ctr < out_row_groups_avail) { | 152 | | /* Do color conversion to fill the conversion buffer. */ | 153 | 30.1M | inrows = in_rows_avail - *in_row_ctr; | 154 | 30.1M | numrows = cinfo->max_v_samp_factor - prep->next_buf_row; | 155 | 30.1M | numrows = (int)MIN((JDIMENSION)numrows, inrows); | 156 | | #ifdef WITH_PROFILE | 157 | | cinfo->master->start = getTime(); | 158 | | #endif | 159 | 30.1M | (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr, | 160 | 30.1M | prep->color_buf, | 161 | 30.1M | (JDIMENSION)prep->next_buf_row, | 162 | 30.1M | 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 | 30.1M | *in_row_ctr += numrows; | 169 | 30.1M | prep->next_buf_row += numrows; | 170 | 30.1M | prep->rows_to_go -= numrows; | 171 | | /* If at bottom of image, pad to fill the conversion buffer. */ | 172 | 30.1M | if (prep->rows_to_go == 0 && | 173 | 11.2k | 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 | 30.1M | if (prep->next_buf_row == cinfo->max_v_samp_factor) { | 182 | | #ifdef WITH_PROFILE | 183 | | cinfo->master->start = getTime(); | 184 | | #endif | 185 | 30.1M | (*cinfo->downsample->_downsample) (cinfo, | 186 | 30.1M | prep->color_buf, (JDIMENSION)0, | 187 | 30.1M | 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 | 30.1M | prep->next_buf_row = 0; | 194 | 30.1M | (*out_row_group_ctr)++; | 195 | 30.1M | } | 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 | 30.1M | 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 | 30.1M | } | 211 | 30.1M | } |
|
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 | 3.99M | { |
226 | 3.99M | my_prep_ptr prep = (my_prep_ptr)cinfo->prep; |
227 | 3.99M | int numrows, ci; |
228 | 3.99M | int buf_height = cinfo->max_v_samp_factor * 3; |
229 | 3.99M | JDIMENSION inrows; |
230 | | |
231 | 7.73M | while (*out_row_group_ctr < out_row_groups_avail) { |
232 | 7.48M | if (*in_row_ctr < in_rows_avail) { |
233 | | /* Do color conversion to fill the conversion buffer. */ |
234 | 3.74M | inrows = in_rows_avail - *in_row_ctr; |
235 | 3.74M | numrows = prep->next_buf_stop - prep->next_buf_row; |
236 | 3.74M | numrows = (int)MIN((JDIMENSION)numrows, inrows); |
237 | | #ifdef WITH_PROFILE |
238 | | cinfo->master->start = getTime(); |
239 | | #endif |
240 | 3.74M | (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr, |
241 | 3.74M | prep->color_buf, |
242 | 3.74M | (JDIMENSION)prep->next_buf_row, |
243 | 3.74M | 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 | 3.74M | if (prep->rows_to_go == cinfo->image_height) { |
251 | 3.78k | for (ci = 0; ci < cinfo->num_components; ci++) { |
252 | 2.61k | int row; |
253 | 7.37k | for (row = 1; row <= cinfo->max_v_samp_factor; row++) { |
254 | 4.76k | _jcopy_sample_rows(prep->color_buf[ci], 0, prep->color_buf[ci], |
255 | 4.76k | -row, 1, cinfo->image_width); |
256 | 4.76k | } |
257 | 2.61k | } |
258 | 1.17k | } |
259 | 3.74M | *in_row_ctr += numrows; |
260 | 3.74M | prep->next_buf_row += numrows; |
261 | 3.74M | prep->rows_to_go -= numrows; |
262 | 3.74M | } else { |
263 | | /* Return for more data, unless we are at the bottom of the image. */ |
264 | 3.74M | if (prep->rows_to_go != 0) |
265 | 3.74M | break; |
266 | | /* When at bottom of image, pad to fill the conversion buffer. */ |
267 | 3.43k | if (prep->next_buf_row < prep->next_buf_stop) { |
268 | 11.5k | for (ci = 0; ci < cinfo->num_components; ci++) { |
269 | 8.12k | expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, |
270 | 8.12k | prep->next_buf_row, prep->next_buf_stop); |
271 | 8.12k | } |
272 | 3.43k | prep->next_buf_row = prep->next_buf_stop; |
273 | 3.43k | } |
274 | 3.43k | } |
275 | | /* If we've gotten enough data, downsample a row group. */ |
276 | 3.74M | if (prep->next_buf_row == prep->next_buf_stop) { |
277 | | #ifdef WITH_PROFILE |
278 | | cinfo->master->start = getTime(); |
279 | | #endif |
280 | 2.01M | (*cinfo->downsample->_downsample) (cinfo, prep->color_buf, |
281 | 2.01M | (JDIMENSION)prep->this_row_group, |
282 | 2.01M | 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 | 2.01M | (*out_row_group_ctr)++; |
289 | | /* Advance pointers with wraparound as necessary. */ |
290 | 2.01M | prep->this_row_group += cinfo->max_v_samp_factor; |
291 | 2.01M | if (prep->this_row_group >= buf_height) |
292 | 672k | prep->this_row_group = 0; |
293 | 2.01M | if (prep->next_buf_row >= buf_height) |
294 | 673k | prep->next_buf_row = 0; |
295 | 2.01M | prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor; |
296 | 2.01M | } |
297 | 3.74M | } |
298 | 3.99M | } jcprepct-8.c:pre_process_context Line | Count | Source | 225 | 3.99M | { | 226 | 3.99M | my_prep_ptr prep = (my_prep_ptr)cinfo->prep; | 227 | 3.99M | int numrows, ci; | 228 | 3.99M | int buf_height = cinfo->max_v_samp_factor * 3; | 229 | 3.99M | JDIMENSION inrows; | 230 | | | 231 | 7.73M | while (*out_row_group_ctr < out_row_groups_avail) { | 232 | 7.48M | if (*in_row_ctr < in_rows_avail) { | 233 | | /* Do color conversion to fill the conversion buffer. */ | 234 | 3.74M | inrows = in_rows_avail - *in_row_ctr; | 235 | 3.74M | numrows = prep->next_buf_stop - prep->next_buf_row; | 236 | 3.74M | numrows = (int)MIN((JDIMENSION)numrows, inrows); | 237 | | #ifdef WITH_PROFILE | 238 | | cinfo->master->start = getTime(); | 239 | | #endif | 240 | 3.74M | (*cinfo->cconvert->_color_convert) (cinfo, input_buf + *in_row_ctr, | 241 | 3.74M | prep->color_buf, | 242 | 3.74M | (JDIMENSION)prep->next_buf_row, | 243 | 3.74M | 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 | 3.74M | if (prep->rows_to_go == cinfo->image_height) { | 251 | 3.78k | for (ci = 0; ci < cinfo->num_components; ci++) { | 252 | 2.61k | int row; | 253 | 7.37k | for (row = 1; row <= cinfo->max_v_samp_factor; row++) { | 254 | 4.76k | _jcopy_sample_rows(prep->color_buf[ci], 0, prep->color_buf[ci], | 255 | 4.76k | -row, 1, cinfo->image_width); | 256 | 4.76k | } | 257 | 2.61k | } | 258 | 1.17k | } | 259 | 3.74M | *in_row_ctr += numrows; | 260 | 3.74M | prep->next_buf_row += numrows; | 261 | 3.74M | prep->rows_to_go -= numrows; | 262 | 3.74M | } else { | 263 | | /* Return for more data, unless we are at the bottom of the image. */ | 264 | 3.74M | if (prep->rows_to_go != 0) | 265 | 3.74M | break; | 266 | | /* When at bottom of image, pad to fill the conversion buffer. */ | 267 | 3.43k | if (prep->next_buf_row < prep->next_buf_stop) { | 268 | 11.5k | for (ci = 0; ci < cinfo->num_components; ci++) { | 269 | 8.12k | expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, | 270 | 8.12k | prep->next_buf_row, prep->next_buf_stop); | 271 | 8.12k | } | 272 | 3.43k | prep->next_buf_row = prep->next_buf_stop; | 273 | 3.43k | } | 274 | 3.43k | } | 275 | | /* If we've gotten enough data, downsample a row group. */ | 276 | 3.74M | if (prep->next_buf_row == prep->next_buf_stop) { | 277 | | #ifdef WITH_PROFILE | 278 | | cinfo->master->start = getTime(); | 279 | | #endif | 280 | 2.01M | (*cinfo->downsample->_downsample) (cinfo, prep->color_buf, | 281 | 2.01M | (JDIMENSION)prep->this_row_group, | 282 | 2.01M | 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 | 2.01M | (*out_row_group_ctr)++; | 289 | | /* Advance pointers with wraparound as necessary. */ | 290 | 2.01M | prep->this_row_group += cinfo->max_v_samp_factor; | 291 | 2.01M | if (prep->this_row_group >= buf_height) | 292 | 672k | prep->this_row_group = 0; | 293 | 2.01M | if (prep->next_buf_row >= buf_height) | 294 | 673k | prep->next_buf_row = 0; | 295 | 2.01M | prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor; | 296 | 2.01M | } | 297 | 3.74M | } | 298 | 3.99M | } |
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 | 2.66k | { |
308 | 2.66k | my_prep_ptr prep = (my_prep_ptr)cinfo->prep; |
309 | 2.66k | int rgroup_height = cinfo->max_v_samp_factor; |
310 | 2.66k | int ci, i; |
311 | 2.66k | jpeg_component_info *compptr; |
312 | 2.66k | _JSAMPARRAY true_buffer, fake_buffer; |
313 | 2.66k | 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 | 2.66k | fake_buffer = (_JSAMPARRAY) |
319 | 2.66k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
320 | 2.66k | (cinfo->num_components * 5 * rgroup_height) * |
321 | 2.66k | sizeof(_JSAMPROW)); |
322 | | |
323 | 8.81k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
324 | 6.15k | 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 | 6.15k | true_buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) |
330 | 6.15k | ((j_common_ptr)cinfo, JPOOL_IMAGE, |
331 | 6.15k | (JDIMENSION)(((long)compptr->width_in_blocks * data_unit * |
332 | 6.15k | cinfo->max_h_samp_factor) / compptr->h_samp_factor), |
333 | 6.15k | (JDIMENSION)(3 * rgroup_height)); |
334 | | /* Copy true buffer row pointers into the middle of the fake row array */ |
335 | 6.15k | memcpy(fake_buffer + rgroup_height, true_buffer, |
336 | 6.15k | 3 * rgroup_height * sizeof(_JSAMPROW)); |
337 | | /* Fill in the above and below wraparound pointers */ |
338 | 17.5k | for (i = 0; i < rgroup_height; i++) { |
339 | 11.3k | fake_buffer[i] = true_buffer[2 * rgroup_height + i]; |
340 | 11.3k | fake_buffer[4 * rgroup_height + i] = true_buffer[i]; |
341 | 11.3k | } |
342 | 6.15k | prep->color_buf[ci] = fake_buffer + rgroup_height; |
343 | 6.15k | fake_buffer += 5 * rgroup_height; /* point to space for next component */ |
344 | 6.15k | } |
345 | 2.66k | } jcprepct-8.c:create_context_buffer Line | Count | Source | 307 | 2.66k | { | 308 | 2.66k | my_prep_ptr prep = (my_prep_ptr)cinfo->prep; | 309 | 2.66k | int rgroup_height = cinfo->max_v_samp_factor; | 310 | 2.66k | int ci, i; | 311 | 2.66k | jpeg_component_info *compptr; | 312 | 2.66k | _JSAMPARRAY true_buffer, fake_buffer; | 313 | 2.66k | 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 | 2.66k | fake_buffer = (_JSAMPARRAY) | 319 | 2.66k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 320 | 2.66k | (cinfo->num_components * 5 * rgroup_height) * | 321 | 2.66k | sizeof(_JSAMPROW)); | 322 | | | 323 | 8.81k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 324 | 6.15k | 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 | 6.15k | true_buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 330 | 6.15k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 331 | 6.15k | (JDIMENSION)(((long)compptr->width_in_blocks * data_unit * | 332 | 6.15k | cinfo->max_h_samp_factor) / compptr->h_samp_factor), | 333 | 6.15k | (JDIMENSION)(3 * rgroup_height)); | 334 | | /* Copy true buffer row pointers into the middle of the fake row array */ | 335 | 6.15k | memcpy(fake_buffer + rgroup_height, true_buffer, | 336 | 6.15k | 3 * rgroup_height * sizeof(_JSAMPROW)); | 337 | | /* Fill in the above and below wraparound pointers */ | 338 | 17.5k | for (i = 0; i < rgroup_height; i++) { | 339 | 11.3k | fake_buffer[i] = true_buffer[2 * rgroup_height + i]; | 340 | 11.3k | fake_buffer[4 * rgroup_height + i] = true_buffer[i]; | 341 | 11.3k | } | 342 | 6.15k | prep->color_buf[ci] = fake_buffer + rgroup_height; | 343 | 6.15k | fake_buffer += 5 * rgroup_height; /* point to space for next component */ | 344 | 6.15k | } | 345 | 2.66k | } |
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 | 93.5k | { |
357 | 93.5k | my_prep_ptr prep; |
358 | 93.5k | int ci; |
359 | 93.5k | jpeg_component_info *compptr; |
360 | 93.5k | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
361 | | |
362 | 93.5k | #ifdef C_LOSSLESS_SUPPORTED |
363 | 93.5k | if (cinfo->master->lossless) { |
364 | | #if BITS_IN_JSAMPLE == 8 |
365 | 12.9k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
366 | | #else |
367 | 22.1k | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
368 | 22.1k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) |
369 | 0 | #endif |
370 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
371 | 35.1k | } else |
372 | 58.3k | #endif |
373 | 58.3k | { |
374 | 58.3k | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
375 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
376 | 58.3k | } |
377 | | |
378 | 93.5k | if (need_full_buffer) /* safety check */ |
379 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); |
380 | | |
381 | 93.5k | prep = (my_prep_ptr) |
382 | 93.5k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
383 | 93.5k | sizeof(my_prep_controller)); |
384 | 93.5k | cinfo->prep = (struct jpeg_c_prep_controller *)prep; |
385 | 93.5k | 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 | 93.5k | if (cinfo->downsample->need_context_rows) { |
392 | | /* Set up to provide context rows */ |
393 | 2.66k | #ifdef CONTEXT_ROWS_SUPPORTED |
394 | 2.66k | prep->pub._pre_process_data = pre_process_context; |
395 | 2.66k | create_context_buffer(cinfo); |
396 | | #else |
397 | | ERREXIT(cinfo, JERR_NOT_COMPILED); |
398 | | #endif |
399 | 90.8k | } else { |
400 | | /* No context, just make it tall enough for one row group */ |
401 | 90.8k | prep->pub._pre_process_data = pre_process_data; |
402 | 332k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
403 | 241k | ci++, compptr++) { |
404 | 241k | prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) |
405 | 241k | ((j_common_ptr)cinfo, JPOOL_IMAGE, |
406 | 241k | (JDIMENSION)(((long)compptr->width_in_blocks * data_unit * |
407 | 241k | cinfo->max_h_samp_factor) / compptr->h_samp_factor), |
408 | 241k | (JDIMENSION)cinfo->max_v_samp_factor); |
409 | 241k | } |
410 | 90.8k | } |
411 | 93.5k | } Line | Count | Source | 356 | 44.8k | { | 357 | 44.8k | my_prep_ptr prep; | 358 | 44.8k | int ci; | 359 | 44.8k | jpeg_component_info *compptr; | 360 | 44.8k | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 361 | | | 362 | 44.8k | #ifdef C_LOSSLESS_SUPPORTED | 363 | 44.8k | if (cinfo->master->lossless) { | 364 | 12.9k | #if BITS_IN_JSAMPLE == 8 | 365 | 12.9k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 366 | | #else | 367 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 368 | | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 369 | | #endif | 370 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 371 | 12.9k | } else | 372 | 31.8k | #endif | 373 | 31.8k | { | 374 | 31.8k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 375 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 376 | 31.8k | } | 377 | | | 378 | 44.8k | if (need_full_buffer) /* safety check */ | 379 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 380 | | | 381 | 44.8k | prep = (my_prep_ptr) | 382 | 44.8k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 383 | 44.8k | sizeof(my_prep_controller)); | 384 | 44.8k | cinfo->prep = (struct jpeg_c_prep_controller *)prep; | 385 | 44.8k | 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 | 44.8k | if (cinfo->downsample->need_context_rows) { | 392 | | /* Set up to provide context rows */ | 393 | 2.66k | #ifdef CONTEXT_ROWS_SUPPORTED | 394 | 2.66k | prep->pub._pre_process_data = pre_process_context; | 395 | 2.66k | create_context_buffer(cinfo); | 396 | | #else | 397 | | ERREXIT(cinfo, JERR_NOT_COMPILED); | 398 | | #endif | 399 | 42.1k | } else { | 400 | | /* No context, just make it tall enough for one row group */ | 401 | 42.1k | prep->pub._pre_process_data = pre_process_data; | 402 | 152k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 403 | 110k | ci++, compptr++) { | 404 | 110k | prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 405 | 110k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 406 | 110k | (JDIMENSION)(((long)compptr->width_in_blocks * data_unit * | 407 | 110k | cinfo->max_h_samp_factor) / compptr->h_samp_factor), | 408 | 110k | (JDIMENSION)cinfo->max_v_samp_factor); | 409 | 110k | } | 410 | 42.1k | } | 411 | 44.8k | } |
j12init_c_prep_controller Line | Count | Source | 356 | 37.4k | { | 357 | 37.4k | my_prep_ptr prep; | 358 | 37.4k | int ci; | 359 | 37.4k | jpeg_component_info *compptr; | 360 | 37.4k | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 361 | | | 362 | 37.4k | #ifdef C_LOSSLESS_SUPPORTED | 363 | 37.4k | 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 | 10.9k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 368 | 10.9k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 369 | 0 | #endif | 370 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 371 | 10.9k | } else | 372 | 26.4k | #endif | 373 | 26.4k | { | 374 | 26.4k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 375 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 376 | 26.4k | } | 377 | | | 378 | 37.4k | if (need_full_buffer) /* safety check */ | 379 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 380 | | | 381 | 37.4k | prep = (my_prep_ptr) | 382 | 37.4k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 383 | 37.4k | sizeof(my_prep_controller)); | 384 | 37.4k | cinfo->prep = (struct jpeg_c_prep_controller *)prep; | 385 | 37.4k | 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 | 37.4k | 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 | 37.4k | } else { | 400 | | /* No context, just make it tall enough for one row group */ | 401 | 37.4k | prep->pub._pre_process_data = pre_process_data; | 402 | 136k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 403 | 99.2k | ci++, compptr++) { | 404 | 99.2k | prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 405 | 99.2k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 406 | 99.2k | (JDIMENSION)(((long)compptr->width_in_blocks * data_unit * | 407 | 99.2k | cinfo->max_h_samp_factor) / compptr->h_samp_factor), | 408 | 99.2k | (JDIMENSION)cinfo->max_v_samp_factor); | 409 | 99.2k | } | 410 | 37.4k | } | 411 | 37.4k | } |
j16init_c_prep_controller Line | Count | Source | 356 | 11.2k | { | 357 | 11.2k | my_prep_ptr prep; | 358 | 11.2k | int ci; | 359 | 11.2k | jpeg_component_info *compptr; | 360 | 11.2k | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 361 | | | 362 | 11.2k | #ifdef C_LOSSLESS_SUPPORTED | 363 | 11.2k | 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 | 11.2k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 368 | 11.2k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 369 | 0 | #endif | 370 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 371 | 11.2k | } 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 | 11.2k | if (need_full_buffer) /* safety check */ | 379 | 0 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 380 | | | 381 | 11.2k | prep = (my_prep_ptr) | 382 | 11.2k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 383 | 11.2k | sizeof(my_prep_controller)); | 384 | 11.2k | cinfo->prep = (struct jpeg_c_prep_controller *)prep; | 385 | 11.2k | 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 | 11.2k | 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 | 11.2k | } else { | 400 | | /* No context, just make it tall enough for one row group */ | 401 | 11.2k | prep->pub._pre_process_data = pre_process_data; | 402 | 42.9k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 403 | 31.7k | ci++, compptr++) { | 404 | 31.7k | prep->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) | 405 | 31.7k | ((j_common_ptr)cinfo, JPOOL_IMAGE, | 406 | 31.7k | (JDIMENSION)(((long)compptr->width_in_blocks * data_unit * | 407 | 31.7k | cinfo->max_h_samp_factor) / compptr->h_samp_factor), | 408 | 31.7k | (JDIMENSION)cinfo->max_v_samp_factor); | 409 | 31.7k | } | 410 | 11.2k | } | 411 | 11.2k | } |
|
412 | | |
413 | | #endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */ |