JPEGView/Independent JPEG Group/jcmainct.c

1 line
8.8 KiB
C
Raw Permalink Normal View History

/* * jcmainct.c * * Copyright (C) 1994, Thomas G. Lane. * This file is part of the Independent JPEG Group's software. * For conditions of distribution and use, see the accompanying README file. * * This file contains the main buffer controller for compression. * The main buffer lies between the pre-processor and the JPEG * compressor proper; it holds downsampled data in the JPEG colorspace. */ #define JPEG_INTERNALS #include "jinclude.h" #include "jpeglib.h" /* Private buffer controller object */ typedef struct { struct jpeg_c_main_controller pub; /* public fields */ JDIMENSION cur_mcu_row; /* number of current MCU row */ JDIMENSION rowgroup_ctr; /* counts row groups received in MCU row */ JDIMENSION mcu_ctr; /* counts MCUs output from current row */ boolean suspended; /* remember if we suspended output */ J_BUF_MODE pass_mode; /* current operating mode */ /* If using full-image storage, this array holds pointers to virtual-array * control blocks for each component. Unused if not full-image storage. */ jvirt_sarray_ptr virtual[MAX_COMPONENTS]; /* If using just a strip buffer, this points to the entire set of buffers * (we allocate one for each component). In the virtual-array case, this * points to the currently accessible strips of the virtual arrays. */ JSAMPARRAY buffer[MAX_COMPONENTS]; /* This vector points to the current strips of the components being written * during the current scan. */ JSAMPARRAY cur_buffer[MAX_COMPS_IN_SCAN]; } my_main_controller; typedef my_main_controller * my_main_ptr; /* Forward declarations */ METHODDEF void process_data_simple_main JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)); METHODDEF void process_data_buffer_main JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)); /* * Initialize for a processing pass. */ METHODDEF void start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode) { my_main_ptr main = (my_main_ptr) cinfo->main; int ci, cindex; main->cur_mcu_row = 0; /* initialize counters */ main->rowgroup_ctr = 0; main->mcu_ctr = 0; main->suspended = FALSE; main->pass_mode = pass_mode; /* save mode for use by process_data */ switch (pass_mode) { case JBUF_PASS_THRU: if (main->virtual[0] != NULL) ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); main->pub.process_data = process_data_simple_main; /* The output-strip pointers can be set up once for the whole pass. */ for (ci = 0; ci < cinfo->comps_in_scan; ci++) { cindex = cinfo->cur_comp_info[ci]->component_index; main->cur_buffer[ci] = main->buffer[cindex]; } break; case JBUF_SAVE_SOURCE: case JBUF_CRANK_DEST: case JBUF_SAVE_AND_PASS: if (main->virtual[0] == NULL) ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); main->pub.process_data = process_data_buffer_main; break; default: ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); break; } } /* * Process some data. * This routine handles the simple pass-through mode, * where we have only a strip buffer. */ METHODDEF void process_data_simple_main (j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail) { my_main_ptr main = (my_main_ptr) cinfo->main; while (*in_row_ctr < in_rows_avail) { /* Read input data if we haven't filled the main buffer yet */ if (main->rowgroup_ctr < DCTSIZE) (*cinfo->prep->pre_process_data) (cinfo, input_buf, in_row_ctr, in_rows_avail, main->buffer, &main->rowgroup_ctr, (JDIMENSION) DCTSIZE); /* If we have a full MCU row buffered, emit data. */ /* Note that preprocessor ensures this will be true at bottom of image. */ if (main->rowgroup_ctr == DCTSIZE) { (*cinfo->coef->compress_data) (cinfo, main->cur_buffer, &main->mcu_ctr); /* If compressor did not consume the whole row, then we must need to * suspend processing and return to the application. In this situation * we pretend we didn't yet co