vrshoot

annotate libs/libjpeg/jcmainct.c @ 2:334d17aed7de

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