istereo

annotate libs/libjpeg/jcmainct.c @ 36:834503dcb486

fixed the rotated gui problem
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 09 Sep 2011 10:25:03 +0300
parents
children
rev   line source
nuclear@26 1 /*
nuclear@26 2 * jcmainct.c
nuclear@26 3 *
nuclear@26 4 * Copyright (C) 1994-1996, Thomas G. Lane.
nuclear@26 5 * This file is part of the Independent JPEG Group's software.
nuclear@26 6 * For conditions of distribution and use, see the accompanying README file.
nuclear@26 7 *
nuclear@26 8 * This file contains the main buffer controller for compression.
nuclear@26 9 * The main buffer lies between the pre-processor and the JPEG
nuclear@26 10 * compressor proper; it holds downsampled data in the JPEG colorspace.
nuclear@26 11 */
nuclear@26 12
nuclear@26 13 #define JPEG_INTERNALS
nuclear@26 14 #include "jinclude.h"
nuclear@26 15 #include "jpeglib.h"
nuclear@26 16
nuclear@26 17
nuclear@26 18 /* Note: currently, there is no operating mode in which a full-image buffer
nuclear@26 19 * is needed at this step. If there were, that mode could not be used with
nuclear@26 20 * "raw data" input, since this module is bypassed in that case. However,
nuclear@26 21 * we've left the code here for possible use in special applications.
nuclear@26 22 */
nuclear@26 23 #undef FULL_MAIN_BUFFER_SUPPORTED
nuclear@26 24
nuclear@26 25
nuclear@26 26 /* Private buffer controller object */
nuclear@26 27
nuclear@26 28 typedef struct {
nuclear@26 29 struct jpeg_c_main_controller pub; /* public fields */
nuclear@26 30
nuclear@26 31 JDIMENSION cur_iMCU_row; /* number of current iMCU row */
nuclear@26 32 JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
nuclear@26 33 boolean suspended; /* remember if we suspended output */
nuclear@26 34 J_BUF_MODE pass_mode; /* current operating mode */
nuclear@26 35
nuclear@26 36 /* If using just a strip buffer, this points to the entire set of buffers
nuclear@26 37 * (we allocate one for each component). In the full-image case, this
nuclear@26 38 * points to the currently accessible strips of the virtual arrays.
nuclear@26 39 */
nuclear@26 40 JSAMPARRAY buffer[MAX_COMPONENTS];
nuclear@26 41
nuclear@26 42 #ifdef FULL_MAIN_BUFFER_SUPPORTED
nuclear@26 43 /* If using full-image storage, this array holds pointers to virtual-array
nuclear@26 44 * control blocks for each component. Unused if not full-image storage.
nuclear@26 45 */
nuclear@26 46 jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
nuclear@26 47 #endif
nuclear@26 48 } my_main_controller;
nuclear@26 49
nuclear@26 50 typedef my_main_controller * my_main_ptr;
nuclear@26 51
nuclear@26 52
nuclear@26 53 /* Forward declarations */
nuclear@26 54 METHODDEF(void) process_data_simple_main
nuclear@26 55 JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
nuclear@26 56 JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
nuclear@26 57 #ifdef FULL_MAIN_BUFFER_SUPPORTED
nuclear@26 58 METHODDEF(void) process_data_buffer_main
nuclear@26 59 JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
nuclear@26 60 JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
nuclear@26 61 #endif
nuclear@26 62
nuclear@26 63
nuclear@26 64 /*
nuclear@26 65 * Initialize for a processing pass.
nuclear@26 66 */
nuclear@26 67
nuclear@26 68 METHODDEF(void)
nuclear@26 69 start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
nuclear@26 70 {
nuclear@26 71 my_main_ptr main = (my_main_ptr) cinfo->main;
nuclear@26 72
nuclear@26 73 /* Do nothing in raw-data mode. */
nuclear@26 74 if (cinfo->raw_data_in)
nuclear@26 75 return;
nuclear@26 76
nuclear@26 77 main->cur_iMCU_row = 0; /* initialize counters */
nuclear@26 78 main->rowgroup_ctr = 0;
nuclear@26 79 main->suspended = FALSE;
nuclear@26 80 main->pass_mode = pass_mode; /* save mode for use by process_data */
nuclear@26 81
nuclear@26 82 switch (pass_mode) {
nuclear@26 83 case JBUF_PASS_THRU:
nuclear@26 84 #ifdef FULL_MAIN_BUFFER_SUPPORTED
nuclear@26 85 if (main->whole_image[0] != NULL)
nuclear@26 86 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
nuclear@26 87 #endif
nuclear@26 88 main->pub.process_data = process_data_simple_main;
nuclear@26 89 break;
nuclear@26 90 #ifdef FULL_MAIN_BUFFER_SUPPORTED
nuclear@26 91 case JBUF_SAVE_SOURCE:
nuclear@26 92 case JBUF_CRANK_DEST:
nuclear@26 93 case JBUF_SAVE_AND_PASS:
nuclear@26 94 if (main->whole_image[0] == NULL)
nuclear@26 95 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
nuclear@26 96 main->pub.process_data = process_data_buffer_main;
nuclear@26 97 break;
nuclear@26 98 #endif
nuclear@26 99 default:
nuclear@26 100 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
nuclear@26 101 break;
nuclear@26 102 }
nuclear@26 103 }
nuclear@26 104
nuclear@26 105
nuclear@26 106 /*
nuclear@26 107 * Process some data.
nuclear@26 108 * This routine handles the simple pass-through mode,
nuclear@26 109 * where we have only a strip buffer.
nuclear@26 110 */
nuclear@26 111
nuclear@26 112 METHODDEF(void)
nuclear@26 113 process_data_simple_main (j_compress_ptr cinfo,
nuclear@26 114 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
nuclear@26 115 JDIMENSION in_rows_avail)
nuclear@26 116 {
nuclear@26 117 my_main_ptr main = (my_main_ptr) cinfo->main;
nuclear@26 118
nuclear@26 119 while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
nuclear@26 120 /* Read input data if we haven't filled the main buffer yet */
nuclear@26 121 if (main->rowgroup_ctr < DCTSIZE)
nuclear@26 122 (*cinfo->prep->pre_process_data) (cinfo,
nuclear@26 123 input_buf, in_row_ctr, in_rows_avail,
nuclear@26 124 main->buffer, &main->rowgroup_ctr,
nuclear@26 125 (JDIMENSION) DCTSIZE);
nuclear@26 126
nuclear@26 127 /* If we don't have a full iMCU row buffered, return to application for
nuclear@26 128 * more data. Note that preprocessor will always pad to fill the iMCU row
nuclear@26 129 * at the bottom of the image.
nuclear@26 130 */
nuclear@26 131 if (main->rowgroup_ctr != DCTSIZE)
nuclear@26 132 return;
nuclear@26 133
nuclear@26 134 /* Send the completed row to the compressor */
nuclear@26 135 if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
nuclear@26 136 /* If compressor did not consume the whole row, then we must need to
nuclear@26 137 * suspend processing and return to the application. In this situation
nuclear@26 138 * we pretend we didn't yet consume the last input row; otherwise, if
nuclear@26 139 * it happened to be the last row of the image, the application would
nuclear@26 140 * think we were done.
nuclear@26 141 */
nuclear@26 142 if (! main->suspended) {
nuclear@26 143 (*in_row_ctr)--;
nuclear@26 144 main->suspended = TRUE;
nuclear@26 145 }
nuclear@26 146 return;
nuclear@26 147 }
nuclear@26 148 /* We did finish the row. Undo our little suspension hack if a previous
nuclear@26 149 * call suspended; then mark the main buffer empty.
nuclear@26 150 */
nuclear@26 151 if (main->suspended) {
nuclear@26 152 (*in_row_ctr)++;
nuclear@26 153 main->suspended = FALSE;
nuclear@26 154 }
nuclear@26 155 main->rowgroup_ctr = 0;
nuclear@26 156 main->cur_iMCU_row++;
nuclear@26 157 }
nuclear@26 158 }
nuclear@26 159
nuclear@26 160
nuclear@26 161 #ifdef FULL_MAIN_BUFFER_SUPPORTED
nuclear@26 162
nuclear@26 163 /*
nuclear@26 164 * Process some data.
nuclear@26 165 * This routine handles all of the modes that use a full-size buffer.
nuclear@26 166 */
nuclear@26 167
nuclear@26 168 METHODDEF(void)
nuclear@26 169 process_data_buffer_main (j_compress_ptr cinfo,
nuclear@26 170 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
nuclear@26 171 JDIMENSION in_rows_avail)
nuclear@26 172 {
nuclear@26 173 my_main_ptr main = (my_main_ptr) cinfo->main;
nuclear@26 174 int ci;
nuclear@26 175 jpeg_component_info *compptr;
nuclear@26 176 boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
nuclear@26 177
nuclear@26 178 while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
nuclear@26 179 /* Realign the virtual buffers if at the start of an iMCU row. */
nuclear@26 180 if (main->rowgroup_ctr == 0) {
nuclear@26 181 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
nuclear@26 182 ci++, compptr++) {
nuclear@26 183 main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
nuclear@26 184 ((j_common_ptr) cinfo, main->whole_image[ci],
nuclear@26 185 main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
nuclear@26 186 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
nuclear@26 187 }
nuclear@26 188 /* In a read pass, pretend we just read some source data. */
nuclear@26 189 if (! writing) {
nuclear@26 190 *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
nuclear@26 191 main->rowgroup_ctr = DCTSIZE;
nuclear@26 192 }
nuclear@26 193 }
nuclear@26 194
nuclear@26 195 /* If a write pass, read input data until the current iMCU row is full. */
nuclear@26 196 /* Note: preprocessor will pad if necessary to fill the last iMCU row. */
nuclear@26 197 if (writing) {
nuclear@26 198 (*cinfo->prep->pre_process_data) (cinfo,
nuclear@26 199 input_buf, in_row_ctr, in_rows_avail,
nuclear@26 200 main->buffer, &main->rowgroup_ctr,
nuclear@26 201 (JDIMENSION) DCTSIZE);
nuclear@26 202 /* Return to application if we need more data to fill the iMCU row. */
nuclear@26 203 if (main->rowgroup_ctr < DCTSIZE)
nuclear@26 204 return;
nuclear@26 205 }
nuclear@26 206
nuclear@26 207 /* Emit data, unless this is a sink-only pass. */
nuclear@26 208 if (main->pass_mode != JBUF_SAVE_SOURCE) {
nuclear@26 209 if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
nuclear@26 210 /* If compressor did not consume the whole row, then we must need to
nuclear@26 211 * suspend processing and return to the application. In this situation
nuclear@26 212 * we pretend we didn't yet consume the last input row; otherwise, if
nuclear@26 213 * it happened to be the last row of the image, the application would
nuclear@26 214 * think we were done.
nuclear@26 215 */
nuclear@26 216 if (! main->suspended) {
nuclear@26 217 (*in_row_ctr)--;
nuclear@26 218 main->suspended = TRUE;
nuclear@26 219 }
nuclear@26 220 return;
nuclear@26 221 }
nuclear@26 222 /* We did finish the row. Undo our little suspension hack if a previous
nuclear@26 223 * call suspended; then mark the main buffer empty.
nuclear@26 224 */
nuclear@26 225 if (main->suspended) {
nuclear@26 226 (*in_row_ctr)++;
nuclear@26 227 main->suspended = FALSE;
nuclear@26 228 }
nuclear@26 229 }
nuclear@26 230
nuclear@26 231 /* If get here, we are done with this iMCU row. Mark buffer empty. */
nuclear@26 232 main->rowgroup_ctr = 0;
nuclear@26 233 main->cur_iMCU_row++;
nuclear@26 234 }
nuclear@26 235 }
nuclear@26 236
nuclear@26 237 #endif /* FULL_MAIN_BUFFER_SUPPORTED */
nuclear@26 238
nuclear@26 239
nuclear@26 240 /*
nuclear@26 241 * Initialize main buffer controller.
nuclear@26 242 */
nuclear@26 243
nuclear@26 244 GLOBAL(void)
nuclear@26 245 jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
nuclear@26 246 {
nuclear@26 247 my_main_ptr main;
nuclear@26 248 int ci;
nuclear@26 249 jpeg_component_info *compptr;
nuclear@26 250
nuclear@26 251 main = (my_main_ptr)
nuclear@26 252 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
nuclear@26 253 SIZEOF(my_main_controller));
nuclear@26 254 cinfo->main = (struct jpeg_c_main_controller *) main;
nuclear@26 255 main->pub.start_pass = start_pass_main;
nuclear@26 256
nuclear@26 257 /* We don't need to create a buffer in raw-data mode. */
nuclear@26 258 if (cinfo->raw_data_in)
nuclear@26 259 return;
nuclear@26 260
nuclear@26 261 /* Create the buffer. It holds downsampled data, so each component
nuclear@26 262 * may be of a different size.
nuclear@26 263 */
nuclear@26 264 if (need_full_buffer) {
nuclear@26 265 #ifdef FULL_MAIN_BUFFER_SUPPORTED
nuclear@26 266 /* Allocate a full-image virtual array for each component */
nuclear@26 267 /* Note we pad the bottom to a multiple of the iMCU height */
nuclear@26 268 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
nuclear@26 269 ci++, compptr++) {
nuclear@26 270 main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
nuclear@26 271 ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
nuclear@26 272 compptr->width_in_blocks * DCTSIZE,
nuclear@26 273 (JDIMENSION) jround_up((long) compptr->height_in_blocks,
nuclear@26 274 (long) compptr->v_samp_factor) * DCTSIZE,
nuclear@26 275 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
nuclear@26 276 }
nuclear@26 277 #else
nuclear@26 278 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
nuclear@26 279 #endif
nuclear@26 280 } else {
nuclear@26 281 #ifdef FULL_MAIN_BUFFER_SUPPORTED
nuclear@26 282 main->whole_image[0] = NULL; /* flag for no virtual arrays */
nuclear@26 283 #endif
nuclear@26 284 /* Allocate a strip buffer for each component */
nuclear@26 285 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
nuclear@26 286 ci++, compptr++) {
nuclear@26 287 main->buffer[ci] = (*cinfo->mem->alloc_sarray)
nuclear@26 288 ((j_common_ptr) cinfo, JPOOL_IMAGE,
nuclear@26 289 compptr->width_in_blocks * DCTSIZE,
nuclear@26 290 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
nuclear@26 291 }
nuclear@26 292 }
nuclear@26 293 }