istereo2

annotate libs/libjpeg/jdpostct.c @ 27:f0da8b2b61ec

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