| OLD | NEW |
| 1 /* | 1 /* |
| 2 * jdmainct.c | 2 * jdmainct.c |
| 3 * | 3 * |
| 4 * This file was part of the Independent JPEG Group's software: | 4 * This file was part of the Independent JPEG Group's software: |
| 5 * Copyright (C) 1994-1996, Thomas G. Lane. | 5 * Copyright (C) 1994-1996, Thomas G. Lane. |
| 6 * libjpeg-turbo Modifications: | 6 * libjpeg-turbo Modifications: |
| 7 * Copyright (C) 2010, D. R. Commander. | 7 * Copyright (C) 2010, D. R. Commander. |
| 8 * For conditions of distribution and use, see the accompanying README file. | 8 * For conditions of distribution and use, see the accompanying README file. |
| 9 * | 9 * |
| 10 * This file contains the main buffer controller for decompression. | 10 * This file contains the main buffer controller for decompression. |
| 11 * The main buffer lies between the JPEG decompressor proper and the | 11 * The main buffer lies between the JPEG decompressor proper and the |
| 12 * post-processor; it holds downsampled data in the JPEG colorspace. | 12 * post-processor; it holds downsampled data in the JPEG colorspace. |
| 13 * | 13 * |
| 14 * Note that this code is bypassed in raw-data mode, since the application | 14 * Note that this code is bypassed in raw-data mode, since the application |
| 15 * supplies the equivalent of the main buffer in that case. | 15 * supplies the equivalent of the main buffer in that case. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #define JPEG_INTERNALS | 18 #include "jdmainct.h" |
| 19 #include "jinclude.h" | |
| 20 #include "jpeglib.h" | |
| 21 #include "jpegcomp.h" | |
| 22 | 19 |
| 23 | 20 |
| 24 /* | 21 /* |
| 25 * In the current system design, the main buffer need never be a full-image | 22 * In the current system design, the main buffer need never be a full-image |
| 26 * buffer; any full-height buffers will be found inside the coefficient or | 23 * buffer; any full-height buffers will be found inside the coefficient or |
| 27 * postprocessing controllers. Nonetheless, the main controller is not | 24 * postprocessing controllers. Nonetheless, the main controller is not |
| 28 * trivial. Its responsibility is to provide context rows for upsampling/ | 25 * trivial. Its responsibility is to provide context rows for upsampling/ |
| 29 * rescaling, and doing this in an efficient fashion is a bit tricky. | 26 * rescaling, and doing this in an efficient fashion is a bit tricky. |
| 30 * | 27 * |
| 31 * Postprocessor input data is counted in "row groups". A row group | 28 * Postprocessor input data is counted in "row groups". A row group |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 * This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1. In that | 102 * This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1. In that |
| 106 * situation each iMCU row provides only one row group so the buffering logic | 103 * situation each iMCU row provides only one row group so the buffering logic |
| 107 * must be different (eg, we must read two iMCU rows before we can emit the | 104 * must be different (eg, we must read two iMCU rows before we can emit the |
| 108 * first row group). For now, we simply do not support providing context | 105 * first row group). For now, we simply do not support providing context |
| 109 * rows when min_DCT_scaled_size is 1. That combination seems unlikely to | 106 * rows when min_DCT_scaled_size is 1. That combination seems unlikely to |
| 110 * be worth providing --- if someone wants a 1/8th-size preview, they probably | 107 * be worth providing --- if someone wants a 1/8th-size preview, they probably |
| 111 * want it quick and dirty, so a context-free upsampler is sufficient. | 108 * want it quick and dirty, so a context-free upsampler is sufficient. |
| 112 */ | 109 */ |
| 113 | 110 |
| 114 | 111 |
| 115 /* Private buffer controller object */ | |
| 116 | |
| 117 typedef struct { | |
| 118 struct jpeg_d_main_controller pub; /* public fields */ | |
| 119 | |
| 120 /* Pointer to allocated workspace (M or M+2 row groups). */ | |
| 121 JSAMPARRAY buffer[MAX_COMPONENTS]; | |
| 122 | |
| 123 boolean buffer_full; /* Have we gotten an iMCU row from decoder? */ | |
| 124 JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */ | |
| 125 | |
| 126 /* Remaining fields are only used in the context case. */ | |
| 127 | |
| 128 /* These are the master pointers to the funny-order pointer lists. */ | |
| 129 JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */ | |
| 130 | |
| 131 int whichptr; /* indicates which pointer set is now in use */ | |
| 132 int context_state; /* process_data state machine status */ | |
| 133 JDIMENSION rowgroups_avail; /* row groups available to postprocessor */ | |
| 134 JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */ | |
| 135 } my_main_controller; | |
| 136 | |
| 137 typedef my_main_controller * my_main_ptr; | |
| 138 | |
| 139 /* context_state values: */ | |
| 140 #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */ | |
| 141 #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */ | |
| 142 #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */ | |
| 143 | |
| 144 | |
| 145 /* Forward declarations */ | 112 /* Forward declarations */ |
| 146 METHODDEF(void) process_data_simple_main | 113 METHODDEF(void) process_data_simple_main |
| 147 JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, | 114 JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, |
| 148 JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); | 115 JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); |
| 149 METHODDEF(void) process_data_context_main | 116 METHODDEF(void) process_data_context_main |
| 150 JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, | 117 JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, |
| 151 JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); | 118 JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); |
| 152 #ifdef QUANT_2PASS_SUPPORTED | 119 #ifdef QUANT_2PASS_SUPPORTED |
| 153 METHODDEF(void) process_data_crank_post | 120 METHODDEF(void) process_data_crank_post |
| 154 JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, | 121 JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 * to happen in xbuffer[0]. | 198 * to happen in xbuffer[0]. |
| 232 */ | 199 */ |
| 233 for (i = 0; i < rgroup; i++) { | 200 for (i = 0; i < rgroup; i++) { |
| 234 xbuf0[i - rgroup] = xbuf0[0]; | 201 xbuf0[i - rgroup] = xbuf0[0]; |
| 235 } | 202 } |
| 236 } | 203 } |
| 237 } | 204 } |
| 238 | 205 |
| 239 | 206 |
| 240 LOCAL(void) | 207 LOCAL(void) |
| 241 set_wraparound_pointers (j_decompress_ptr cinfo) | |
| 242 /* Set up the "wraparound" pointers at top and bottom of the pointer lists. | |
| 243 * This changes the pointer list state from top-of-image to the normal state. | |
| 244 */ | |
| 245 { | |
| 246 my_main_ptr main_ptr = (my_main_ptr) cinfo->main; | |
| 247 int ci, i, rgroup; | |
| 248 int M = cinfo->_min_DCT_scaled_size; | |
| 249 jpeg_component_info *compptr; | |
| 250 JSAMPARRAY xbuf0, xbuf1; | |
| 251 | |
| 252 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | |
| 253 ci++, compptr++) { | |
| 254 rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / | |
| 255 cinfo->_min_DCT_scaled_size; /* height of a row group of component */ | |
| 256 xbuf0 = main_ptr->xbuffer[0][ci]; | |
| 257 xbuf1 = main_ptr->xbuffer[1][ci]; | |
| 258 for (i = 0; i < rgroup; i++) { | |
| 259 xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i]; | |
| 260 xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i]; | |
| 261 xbuf0[rgroup*(M+2) + i] = xbuf0[i]; | |
| 262 xbuf1[rgroup*(M+2) + i] = xbuf1[i]; | |
| 263 } | |
| 264 } | |
| 265 } | |
| 266 | |
| 267 | |
| 268 LOCAL(void) | |
| 269 set_bottom_pointers (j_decompress_ptr cinfo) | 208 set_bottom_pointers (j_decompress_ptr cinfo) |
| 270 /* Change the pointer lists to duplicate the last sample row at the bottom | 209 /* Change the pointer lists to duplicate the last sample row at the bottom |
| 271 * of the image. whichptr indicates which xbuffer holds the final iMCU row. | 210 * of the image. whichptr indicates which xbuffer holds the final iMCU row. |
| 272 * Also sets rowgroups_avail to indicate number of nondummy row groups in row. | 211 * Also sets rowgroups_avail to indicate number of nondummy row groups in row. |
| 273 */ | 212 */ |
| 274 { | 213 { |
| 275 my_main_ptr main_ptr = (my_main_ptr) cinfo->main; | 214 my_main_ptr main_ptr = (my_main_ptr) cinfo->main; |
| 276 int ci, i, rgroup, iMCUheight, rows_left; | 215 int ci, i, rgroup, iMCUheight, rows_left; |
| 277 jpeg_component_info *compptr; | 216 jpeg_component_info *compptr; |
| 278 JSAMPARRAY xbuf; | 217 JSAMPARRAY xbuf; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 445 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
| 507 ci++, compptr++) { | 446 ci++, compptr++) { |
| 508 rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / | 447 rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / |
| 509 cinfo->_min_DCT_scaled_size; /* height of a row group of component */ | 448 cinfo->_min_DCT_scaled_size; /* height of a row group of component */ |
| 510 main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray) | 449 main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray) |
| 511 ((j_common_ptr) cinfo, JPOOL_IMAGE, | 450 ((j_common_ptr) cinfo, JPOOL_IMAGE, |
| 512 compptr->width_in_blocks * compptr->_DCT_scaled_size, | 451 compptr->width_in_blocks * compptr->_DCT_scaled_size, |
| 513 (JDIMENSION) (rgroup * ngroups)); | 452 (JDIMENSION) (rgroup * ngroups)); |
| 514 } | 453 } |
| 515 } | 454 } |
| OLD | NEW |