| OLD | NEW |
| 1 /* | 1 /* |
| 2 * jcprepct.c | 2 * jcprepct.c |
| 3 * | 3 * |
| 4 * This file is part of the Independent JPEG Group's software: |
| 4 * Copyright (C) 1994-1996, Thomas G. Lane. | 5 * Copyright (C) 1994-1996, Thomas G. Lane. |
| 5 * This file is part of the Independent JPEG Group's software. | 6 * It was modified by The libjpeg-turbo Project to include only code relevant |
| 6 * For conditions of distribution and use, see the accompanying README file. | 7 * to libjpeg-turbo. |
| 8 * For conditions of distribution and use, see the accompanying README.ijg |
| 9 * file. |
| 7 * | 10 * |
| 8 * This file contains the compression preprocessing controller. | 11 * This file contains the compression preprocessing controller. |
| 9 * This controller manages the color conversion, downsampling, | 12 * This controller manages the color conversion, downsampling, |
| 10 * and edge expansion steps. | 13 * and edge expansion steps. |
| 11 * | 14 * |
| 12 * Most of the complexity here is associated with buffering input rows | 15 * Most of the complexity here is associated with buffering input rows |
| 13 * as required by the downsampler. See the comments at the head of | 16 * as required by the downsampler. See the comments at the head of |
| 14 * jcsample.c for the downsampler's needs. | 17 * jcsample.c for the downsampler's needs. |
| 15 */ | 18 */ |
| 16 | 19 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 /* Private buffer controller object */ | 54 /* Private buffer controller object */ |
| 52 | 55 |
| 53 typedef struct { | 56 typedef struct { |
| 54 struct jpeg_c_prep_controller pub; /* public fields */ | 57 struct jpeg_c_prep_controller pub; /* public fields */ |
| 55 | 58 |
| 56 /* Downsampling input buffer. This buffer holds color-converted data | 59 /* Downsampling input buffer. This buffer holds color-converted data |
| 57 * until we have enough to do a downsample step. | 60 * until we have enough to do a downsample step. |
| 58 */ | 61 */ |
| 59 JSAMPARRAY color_buf[MAX_COMPONENTS]; | 62 JSAMPARRAY color_buf[MAX_COMPONENTS]; |
| 60 | 63 |
| 61 JDIMENSION rows_to_go;» /* counts rows remaining in source image */ | 64 JDIMENSION rows_to_go; /* counts rows remaining in source image */ |
| 62 int next_buf_row;» » /* index of next row to store in color_buf */ | 65 int next_buf_row; /* index of next row to store in color_buf */ |
| 63 | 66 |
| 64 #ifdef CONTEXT_ROWS_SUPPORTED» /* only needed for context case */ | 67 #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */ |
| 65 int this_row_group;» » /* starting row index of group to process */ | 68 int this_row_group; /* starting row index of group to process */ |
| 66 int next_buf_stop;» » /* downsample when we reach this index */ | 69 int next_buf_stop; /* downsample when we reach this index */ |
| 67 #endif | 70 #endif |
| 68 } my_prep_controller; | 71 } my_prep_controller; |
| 69 | 72 |
| 70 typedef my_prep_controller * my_prep_ptr; | 73 typedef my_prep_controller *my_prep_ptr; |
| 71 | 74 |
| 72 | 75 |
| 73 /* | 76 /* |
| 74 * Initialize for a processing pass. | 77 * Initialize for a processing pass. |
| 75 */ | 78 */ |
| 76 | 79 |
| 77 METHODDEF(void) | 80 METHODDEF(void) |
| 78 start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode) | 81 start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode) |
| 79 { | 82 { |
| 80 my_prep_ptr prep = (my_prep_ptr) cinfo->prep; | 83 my_prep_ptr prep = (my_prep_ptr) cinfo->prep; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 97 } | 100 } |
| 98 | 101 |
| 99 | 102 |
| 100 /* | 103 /* |
| 101 * Expand an image vertically from height input_rows to height output_rows, | 104 * Expand an image vertically from height input_rows to height output_rows, |
| 102 * by duplicating the bottom row. | 105 * by duplicating the bottom row. |
| 103 */ | 106 */ |
| 104 | 107 |
| 105 LOCAL(void) | 108 LOCAL(void) |
| 106 expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols, | 109 expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols, |
| 107 » » int input_rows, int output_rows) | 110 int input_rows, int output_rows) |
| 108 { | 111 { |
| 109 register int row; | 112 register int row; |
| 110 | 113 |
| 111 for (row = input_rows; row < output_rows; row++) { | 114 for (row = input_rows; row < output_rows; row++) { |
| 112 jcopy_sample_rows(image_data, input_rows-1, image_data, row, | 115 jcopy_sample_rows(image_data, input_rows-1, image_data, row, |
| 113 » » 1, num_cols); | 116 1, num_cols); |
| 114 } | 117 } |
| 115 } | 118 } |
| 116 | 119 |
| 117 | 120 |
| 118 /* | 121 /* |
| 119 * Process some data in the simple no-context case. | 122 * Process some data in the simple no-context case. |
| 120 * | 123 * |
| 121 * Preprocessor output data is counted in "row groups". A row group | 124 * Preprocessor output data is counted in "row groups". A row group |
| 122 * is defined to be v_samp_factor sample rows of each component. | 125 * is defined to be v_samp_factor sample rows of each component. |
| 123 * Downsampling will produce this much data from each max_v_samp_factor | 126 * Downsampling will produce this much data from each max_v_samp_factor |
| 124 * input rows. | 127 * input rows. |
| 125 */ | 128 */ |
| 126 | 129 |
| 127 METHODDEF(void) | 130 METHODDEF(void) |
| 128 pre_process_data (j_compress_ptr cinfo, | 131 pre_process_data (j_compress_ptr cinfo, |
| 129 » » JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, | 132 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, |
| 130 » » JDIMENSION in_rows_avail, | 133 JDIMENSION in_rows_avail, |
| 131 » » JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, | 134 JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, |
| 132 » » JDIMENSION out_row_groups_avail) | 135 JDIMENSION out_row_groups_avail) |
| 133 { | 136 { |
| 134 my_prep_ptr prep = (my_prep_ptr) cinfo->prep; | 137 my_prep_ptr prep = (my_prep_ptr) cinfo->prep; |
| 135 int numrows, ci; | 138 int numrows, ci; |
| 136 JDIMENSION inrows; | 139 JDIMENSION inrows; |
| 137 jpeg_component_info * compptr; | 140 jpeg_component_info *compptr; |
| 138 | 141 |
| 139 while (*in_row_ctr < in_rows_avail && | 142 while (*in_row_ctr < in_rows_avail && |
| 140 » *out_row_group_ctr < out_row_groups_avail) { | 143 *out_row_group_ctr < out_row_groups_avail) { |
| 141 /* Do color conversion to fill the conversion buffer. */ | 144 /* Do color conversion to fill the conversion buffer. */ |
| 142 inrows = in_rows_avail - *in_row_ctr; | 145 inrows = in_rows_avail - *in_row_ctr; |
| 143 numrows = cinfo->max_v_samp_factor - prep->next_buf_row; | 146 numrows = cinfo->max_v_samp_factor - prep->next_buf_row; |
| 144 numrows = (int) MIN((JDIMENSION) numrows, inrows); | 147 numrows = (int) MIN((JDIMENSION) numrows, inrows); |
| 145 (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, | 148 (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, |
| 146 » » » » prep->color_buf, | 149 prep->color_buf, |
| 147 » » » » (JDIMENSION) prep->next_buf_row, | 150 (JDIMENSION) prep->next_buf_row, |
| 148 » » » » numrows); | 151 numrows); |
| 149 *in_row_ctr += numrows; | 152 *in_row_ctr += numrows; |
| 150 prep->next_buf_row += numrows; | 153 prep->next_buf_row += numrows; |
| 151 prep->rows_to_go -= numrows; | 154 prep->rows_to_go -= numrows; |
| 152 /* If at bottom of image, pad to fill the conversion buffer. */ | 155 /* If at bottom of image, pad to fill the conversion buffer. */ |
| 153 if (prep->rows_to_go == 0 && | 156 if (prep->rows_to_go == 0 && |
| 154 » prep->next_buf_row < cinfo->max_v_samp_factor) { | 157 prep->next_buf_row < cinfo->max_v_samp_factor) { |
| 155 for (ci = 0; ci < cinfo->num_components; ci++) { | 158 for (ci = 0; ci < cinfo->num_components; ci++) { |
| 156 » expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, | 159 expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, |
| 157 » » » prep->next_buf_row, cinfo->max_v_samp_factor); | 160 prep->next_buf_row, cinfo->max_v_samp_factor); |
| 158 } | 161 } |
| 159 prep->next_buf_row = cinfo->max_v_samp_factor; | 162 prep->next_buf_row = cinfo->max_v_samp_factor; |
| 160 } | 163 } |
| 161 /* If we've filled the conversion buffer, empty it. */ | 164 /* If we've filled the conversion buffer, empty it. */ |
| 162 if (prep->next_buf_row == cinfo->max_v_samp_factor) { | 165 if (prep->next_buf_row == cinfo->max_v_samp_factor) { |
| 163 (*cinfo->downsample->downsample) (cinfo, | 166 (*cinfo->downsample->downsample) (cinfo, |
| 164 » » » » » prep->color_buf, (JDIMENSION) 0, | 167 prep->color_buf, (JDIMENSION) 0, |
| 165 » » » » » output_buf, *out_row_group_ctr); | 168 output_buf, *out_row_group_ctr); |
| 166 prep->next_buf_row = 0; | 169 prep->next_buf_row = 0; |
| 167 (*out_row_group_ctr)++; | 170 (*out_row_group_ctr)++; |
| 168 } | 171 } |
| 169 /* If at bottom of image, pad the output to a full iMCU height. | 172 /* If at bottom of image, pad the output to a full iMCU height. |
| 170 * Note we assume the caller is providing a one-iMCU-height output buffer! | 173 * Note we assume the caller is providing a one-iMCU-height output buffer! |
| 171 */ | 174 */ |
| 172 if (prep->rows_to_go == 0 && | 175 if (prep->rows_to_go == 0 && |
| 173 » *out_row_group_ctr < out_row_groups_avail) { | 176 *out_row_group_ctr < out_row_groups_avail) { |
| 174 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 177 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 175 » ci++, compptr++) { | 178 ci++, compptr++) { |
| 176 » expand_bottom_edge(output_buf[ci], | 179 expand_bottom_edge(output_buf[ci], |
| 177 » » » compptr->width_in_blocks * DCTSIZE, | 180 compptr->width_in_blocks * DCTSIZE, |
| 178 » » » (int) (*out_row_group_ctr * compptr->v_samp_factor), | 181 (int) (*out_row_group_ctr * compptr->v_samp_factor), |
| 179 » » » (int) (out_row_groups_avail * compptr->v_samp_factor)
); | 182 (int) (out_row_groups_avail * compptr->v_samp_factor)
); |
| 180 } | 183 } |
| 181 *out_row_group_ctr = out_row_groups_avail; | 184 *out_row_group_ctr = out_row_groups_avail; |
| 182 break;» » » /* can exit outer loop without test */ | 185 break; /* can exit outer loop without test */ |
| 183 } | 186 } |
| 184 } | 187 } |
| 185 } | 188 } |
| 186 | 189 |
| 187 | 190 |
| 188 #ifdef CONTEXT_ROWS_SUPPORTED | 191 #ifdef CONTEXT_ROWS_SUPPORTED |
| 189 | 192 |
| 190 /* | 193 /* |
| 191 * Process some data in the context case. | 194 * Process some data in the context case. |
| 192 */ | 195 */ |
| 193 | 196 |
| 194 METHODDEF(void) | 197 METHODDEF(void) |
| 195 pre_process_context (j_compress_ptr cinfo, | 198 pre_process_context (j_compress_ptr cinfo, |
| 196 » » JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, | 199 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, |
| 197 » » JDIMENSION in_rows_avail, | 200 JDIMENSION in_rows_avail, |
| 198 » » JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, | 201 JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, |
| 199 » » JDIMENSION out_row_groups_avail) | 202 JDIMENSION out_row_groups_avail) |
| 200 { | 203 { |
| 201 my_prep_ptr prep = (my_prep_ptr) cinfo->prep; | 204 my_prep_ptr prep = (my_prep_ptr) cinfo->prep; |
| 202 int numrows, ci; | 205 int numrows, ci; |
| 203 int buf_height = cinfo->max_v_samp_factor * 3; | 206 int buf_height = cinfo->max_v_samp_factor * 3; |
| 204 JDIMENSION inrows; | 207 JDIMENSION inrows; |
| 205 | 208 |
| 206 while (*out_row_group_ctr < out_row_groups_avail) { | 209 while (*out_row_group_ctr < out_row_groups_avail) { |
| 207 if (*in_row_ctr < in_rows_avail) { | 210 if (*in_row_ctr < in_rows_avail) { |
| 208 /* Do color conversion to fill the conversion buffer. */ | 211 /* Do color conversion to fill the conversion buffer. */ |
| 209 inrows = in_rows_avail - *in_row_ctr; | 212 inrows = in_rows_avail - *in_row_ctr; |
| 210 numrows = prep->next_buf_stop - prep->next_buf_row; | 213 numrows = prep->next_buf_stop - prep->next_buf_row; |
| 211 numrows = (int) MIN((JDIMENSION) numrows, inrows); | 214 numrows = (int) MIN((JDIMENSION) numrows, inrows); |
| 212 (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, | 215 (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, |
| 213 » » » » » prep->color_buf, | 216 prep->color_buf, |
| 214 » » » » » (JDIMENSION) prep->next_buf_row, | 217 (JDIMENSION) prep->next_buf_row, |
| 215 » » » » » numrows); | 218 numrows); |
| 216 /* Pad at top of image, if first time through */ | 219 /* Pad at top of image, if first time through */ |
| 217 if (prep->rows_to_go == cinfo->image_height) { | 220 if (prep->rows_to_go == cinfo->image_height) { |
| 218 » for (ci = 0; ci < cinfo->num_components; ci++) { | 221 for (ci = 0; ci < cinfo->num_components; ci++) { |
| 219 » int row; | 222 int row; |
| 220 » for (row = 1; row <= cinfo->max_v_samp_factor; row++) { | 223 for (row = 1; row <= cinfo->max_v_samp_factor; row++) { |
| 221 » jcopy_sample_rows(prep->color_buf[ci], 0, | 224 jcopy_sample_rows(prep->color_buf[ci], 0, |
| 222 » » » prep->color_buf[ci], -row, | 225 prep->color_buf[ci], -row, |
| 223 » » » 1, cinfo->image_width); | 226 1, cinfo->image_width); |
| 224 » } | 227 } |
| 225 » } | 228 } |
| 226 } | 229 } |
| 227 *in_row_ctr += numrows; | 230 *in_row_ctr += numrows; |
| 228 prep->next_buf_row += numrows; | 231 prep->next_buf_row += numrows; |
| 229 prep->rows_to_go -= numrows; | 232 prep->rows_to_go -= numrows; |
| 230 } else { | 233 } else { |
| 231 /* Return for more data, unless we are at the bottom of the image. */ | 234 /* Return for more data, unless we are at the bottom of the image. */ |
| 232 if (prep->rows_to_go != 0) | 235 if (prep->rows_to_go != 0) |
| 233 » break; | 236 break; |
| 234 /* When at bottom of image, pad to fill the conversion buffer. */ | 237 /* When at bottom of image, pad to fill the conversion buffer. */ |
| 235 if (prep->next_buf_row < prep->next_buf_stop) { | 238 if (prep->next_buf_row < prep->next_buf_stop) { |
| 236 » for (ci = 0; ci < cinfo->num_components; ci++) { | 239 for (ci = 0; ci < cinfo->num_components; ci++) { |
| 237 » expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, | 240 expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, |
| 238 » » » prep->next_buf_row, prep->next_buf_stop); | 241 prep->next_buf_row, prep->next_buf_stop); |
| 239 » } | 242 } |
| 240 » prep->next_buf_row = prep->next_buf_stop; | 243 prep->next_buf_row = prep->next_buf_stop; |
| 241 } | 244 } |
| 242 } | 245 } |
| 243 /* If we've gotten enough data, downsample a row group. */ | 246 /* If we've gotten enough data, downsample a row group. */ |
| 244 if (prep->next_buf_row == prep->next_buf_stop) { | 247 if (prep->next_buf_row == prep->next_buf_stop) { |
| 245 (*cinfo->downsample->downsample) (cinfo, | 248 (*cinfo->downsample->downsample) (cinfo, |
| 246 » » » » » prep->color_buf, | 249 prep->color_buf, |
| 247 » » » » » (JDIMENSION) prep->this_row_group, | 250 (JDIMENSION) prep->this_row_group, |
| 248 » » » » » output_buf, *out_row_group_ctr); | 251 output_buf, *out_row_group_ctr); |
| 249 (*out_row_group_ctr)++; | 252 (*out_row_group_ctr)++; |
| 250 /* Advance pointers with wraparound as necessary. */ | 253 /* Advance pointers with wraparound as necessary. */ |
| 251 prep->this_row_group += cinfo->max_v_samp_factor; | 254 prep->this_row_group += cinfo->max_v_samp_factor; |
| 252 if (prep->this_row_group >= buf_height) | 255 if (prep->this_row_group >= buf_height) |
| 253 » prep->this_row_group = 0; | 256 prep->this_row_group = 0; |
| 254 if (prep->next_buf_row >= buf_height) | 257 if (prep->next_buf_row >= buf_height) |
| 255 » prep->next_buf_row = 0; | 258 prep->next_buf_row = 0; |
| 256 prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor; | 259 prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor; |
| 257 } | 260 } |
| 258 } | 261 } |
| 259 } | 262 } |
| 260 | 263 |
| 261 | 264 |
| 262 /* | 265 /* |
| 263 * Create the wrapped-around downsampling input buffer needed for context mode. | 266 * Create the wrapped-around downsampling input buffer needed for context mode. |
| 264 */ | 267 */ |
| 265 | 268 |
| 266 LOCAL(void) | 269 LOCAL(void) |
| 267 create_context_buffer (j_compress_ptr cinfo) | 270 create_context_buffer (j_compress_ptr cinfo) |
| 268 { | 271 { |
| 269 my_prep_ptr prep = (my_prep_ptr) cinfo->prep; | 272 my_prep_ptr prep = (my_prep_ptr) cinfo->prep; |
| 270 int rgroup_height = cinfo->max_v_samp_factor; | 273 int rgroup_height = cinfo->max_v_samp_factor; |
| 271 int ci, i; | 274 int ci, i; |
| 272 jpeg_component_info * compptr; | 275 jpeg_component_info *compptr; |
| 273 JSAMPARRAY true_buffer, fake_buffer; | 276 JSAMPARRAY true_buffer, fake_buffer; |
| 274 | 277 |
| 275 /* Grab enough space for fake row pointers for all the components; | 278 /* Grab enough space for fake row pointers for all the components; |
| 276 * we need five row groups' worth of pointers for each component. | 279 * we need five row groups' worth of pointers for each component. |
| 277 */ | 280 */ |
| 278 fake_buffer = (JSAMPARRAY) | 281 fake_buffer = (JSAMPARRAY) |
| 279 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 282 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
| 280 » » » » (cinfo->num_components * 5 * rgroup_height) * | 283 (cinfo->num_components * 5 * rgroup_height) * |
| 281 » » » » SIZEOF(JSAMPROW)); | 284 sizeof(JSAMPROW)); |
| 282 | 285 |
| 283 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 286 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 284 ci++, compptr++) { | 287 ci++, compptr++) { |
| 285 /* Allocate the actual buffer space (3 row groups) for this component. | 288 /* Allocate the actual buffer space (3 row groups) for this component. |
| 286 * We make the buffer wide enough to allow the downsampler to edge-expand | 289 * We make the buffer wide enough to allow the downsampler to edge-expand |
| 287 * horizontally within the buffer, if it so chooses. | 290 * horizontally within the buffer, if it so chooses. |
| 288 */ | 291 */ |
| 289 true_buffer = (*cinfo->mem->alloc_sarray) | 292 true_buffer = (*cinfo->mem->alloc_sarray) |
| 290 ((j_common_ptr) cinfo, JPOOL_IMAGE, | 293 ((j_common_ptr) cinfo, JPOOL_IMAGE, |
| 291 (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE * | 294 (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE * |
| 292 » » cinfo->max_h_samp_factor) / compptr->h_samp_factor), | 295 cinfo->max_h_samp_factor) / compptr->h_samp_factor), |
| 293 (JDIMENSION) (3 * rgroup_height)); | 296 (JDIMENSION) (3 * rgroup_height)); |
| 294 /* Copy true buffer row pointers into the middle of the fake row array */ | 297 /* Copy true buffer row pointers into the middle of the fake row array */ |
| 295 MEMCOPY(fake_buffer + rgroup_height, true_buffer, | 298 MEMCOPY(fake_buffer + rgroup_height, true_buffer, |
| 296 » 3 * rgroup_height * SIZEOF(JSAMPROW)); | 299 3 * rgroup_height * sizeof(JSAMPROW)); |
| 297 /* Fill in the above and below wraparound pointers */ | 300 /* Fill in the above and below wraparound pointers */ |
| 298 for (i = 0; i < rgroup_height; i++) { | 301 for (i = 0; i < rgroup_height; i++) { |
| 299 fake_buffer[i] = true_buffer[2 * rgroup_height + i]; | 302 fake_buffer[i] = true_buffer[2 * rgroup_height + i]; |
| 300 fake_buffer[4 * rgroup_height + i] = true_buffer[i]; | 303 fake_buffer[4 * rgroup_height + i] = true_buffer[i]; |
| 301 } | 304 } |
| 302 prep->color_buf[ci] = fake_buffer + rgroup_height; | 305 prep->color_buf[ci] = fake_buffer + rgroup_height; |
| 303 fake_buffer += 5 * rgroup_height; /* point to space for next component */ | 306 fake_buffer += 5 * rgroup_height; /* point to space for next component */ |
| 304 } | 307 } |
| 305 } | 308 } |
| 306 | 309 |
| 307 #endif /* CONTEXT_ROWS_SUPPORTED */ | 310 #endif /* CONTEXT_ROWS_SUPPORTED */ |
| 308 | 311 |
| 309 | 312 |
| 310 /* | 313 /* |
| 311 * Initialize preprocessing controller. | 314 * Initialize preprocessing controller. |
| 312 */ | 315 */ |
| 313 | 316 |
| 314 GLOBAL(void) | 317 GLOBAL(void) |
| 315 jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer) | 318 jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer) |
| 316 { | 319 { |
| 317 my_prep_ptr prep; | 320 my_prep_ptr prep; |
| 318 int ci; | 321 int ci; |
| 319 jpeg_component_info * compptr; | 322 jpeg_component_info *compptr; |
| 320 | 323 |
| 321 if (need_full_buffer)»» /* safety check */ | 324 if (need_full_buffer) /* safety check */ |
| 322 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); | 325 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); |
| 323 | 326 |
| 324 prep = (my_prep_ptr) | 327 prep = (my_prep_ptr) |
| 325 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 328 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
| 326 » » » » SIZEOF(my_prep_controller)); | 329 sizeof(my_prep_controller)); |
| 327 cinfo->prep = (struct jpeg_c_prep_controller *) prep; | 330 cinfo->prep = (struct jpeg_c_prep_controller *) prep; |
| 328 prep->pub.start_pass = start_pass_prep; | 331 prep->pub.start_pass = start_pass_prep; |
| 329 | 332 |
| 330 /* Allocate the color conversion buffer. | 333 /* Allocate the color conversion buffer. |
| 331 * We make the buffer wide enough to allow the downsampler to edge-expand | 334 * We make the buffer wide enough to allow the downsampler to edge-expand |
| 332 * horizontally within the buffer, if it so chooses. | 335 * horizontally within the buffer, if it so chooses. |
| 333 */ | 336 */ |
| 334 if (cinfo->downsample->need_context_rows) { | 337 if (cinfo->downsample->need_context_rows) { |
| 335 /* Set up to provide context rows */ | 338 /* Set up to provide context rows */ |
| 336 #ifdef CONTEXT_ROWS_SUPPORTED | 339 #ifdef CONTEXT_ROWS_SUPPORTED |
| 337 prep->pub.pre_process_data = pre_process_context; | 340 prep->pub.pre_process_data = pre_process_context; |
| 338 create_context_buffer(cinfo); | 341 create_context_buffer(cinfo); |
| 339 #else | 342 #else |
| 340 ERREXIT(cinfo, JERR_NOT_COMPILED); | 343 ERREXIT(cinfo, JERR_NOT_COMPILED); |
| 341 #endif | 344 #endif |
| 342 } else { | 345 } else { |
| 343 /* No context, just make it tall enough for one row group */ | 346 /* No context, just make it tall enough for one row group */ |
| 344 prep->pub.pre_process_data = pre_process_data; | 347 prep->pub.pre_process_data = pre_process_data; |
| 345 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 348 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 346 » ci++, compptr++) { | 349 ci++, compptr++) { |
| 347 prep->color_buf[ci] = (*cinfo->mem->alloc_sarray) | 350 prep->color_buf[ci] = (*cinfo->mem->alloc_sarray) |
| 348 » ((j_common_ptr) cinfo, JPOOL_IMAGE, | 351 ((j_common_ptr) cinfo, JPOOL_IMAGE, |
| 349 » (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE * | 352 (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE * |
| 350 » » » cinfo->max_h_samp_factor) / compptr->h_samp_factor), | 353 cinfo->max_h_samp_factor) / compptr->h_samp_factor), |
| 351 » (JDIMENSION) cinfo->max_v_samp_factor); | 354 (JDIMENSION) cinfo->max_v_samp_factor); |
| 352 } | 355 } |
| 353 } | 356 } |
| 354 } | 357 } |
| OLD | NEW |