123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- #define JPEG_INTERNALS
- #include "jinclude.h"
- #include "jpeglib.h"
- #undef FULL_MAIN_BUFFER_SUPPORTED
- typedef struct {
- struct jpeg_c_main_controller pub;
- JDIMENSION cur_iMCU_row;
- JDIMENSION rowgroup_ctr;
- boolean suspended;
- J_BUF_MODE pass_mode;
-
- JSAMPARRAY buffer[MAX_COMPONENTS];
- #ifdef FULL_MAIN_BUFFER_SUPPORTED
-
- jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
- #endif
- } my_main_controller;
- typedef my_main_controller * my_main_ptr;
- METHODDEF void process_data_simple_main
- JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
- JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
- #ifdef FULL_MAIN_BUFFER_SUPPORTED
- METHODDEF void process_data_buffer_main
- JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
- JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
- #endif
- METHODDEF void
- start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
- {
-
- my_main_ptr jmain = (my_main_ptr) cinfo->main;
-
- if (cinfo->raw_data_in)
- return;
- jmain->cur_iMCU_row = 0;
- jmain->rowgroup_ctr = 0;
- jmain->suspended = FALSE;
- jmain->pass_mode = pass_mode;
- switch (pass_mode) {
- case JBUF_PASS_THRU:
- #ifdef FULL_MAIN_BUFFER_SUPPORTED
- if (jmain->whole_image[0] != NULL)
- ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
- #endif
- jmain->pub.process_data = process_data_simple_main;
- break;
- #ifdef FULL_MAIN_BUFFER_SUPPORTED
- case JBUF_SAVE_SOURCE:
- case JBUF_CRANK_DEST:
- case JBUF_SAVE_AND_PASS:
- if (jmain->whole_image[0] == NULL)
- ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
- jmain->pub.process_data = process_data_buffer_main;
- break;
- #endif
- default:
- ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
- break;
- }
- }
- METHODDEF void
- process_data_simple_main (j_compress_ptr cinfo,
- JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
- JDIMENSION in_rows_avail)
- {
-
- my_main_ptr jmain = (my_main_ptr) cinfo->main;
- while (jmain->cur_iMCU_row < cinfo->total_iMCU_rows) {
-
- if (jmain->rowgroup_ctr < DCTSIZE)
- (*cinfo->prep->pre_process_data) (cinfo,
- input_buf, in_row_ctr, in_rows_avail,
- jmain->buffer, &jmain->rowgroup_ctr,
- (JDIMENSION) DCTSIZE);
-
- if (jmain->rowgroup_ctr != DCTSIZE)
- return;
-
- if (! (*cinfo->coef->compress_data) (cinfo, jmain->buffer)) {
-
- if (! jmain->suspended) {
- (*in_row_ctr)--;
- jmain->suspended = TRUE;
- }
- return;
- }
-
- if (jmain->suspended) {
- (*in_row_ctr)++;
- jmain->suspended = FALSE;
- }
- jmain->rowgroup_ctr = 0;
- jmain->cur_iMCU_row++;
- }
- }
- #ifdef FULL_MAIN_BUFFER_SUPPORTED
- METHODDEF void
- process_data_buffer_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;
- int ci;
- jpeg_component_info *compptr;
- boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
- while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
-
- if (main->rowgroup_ctr == 0) {
- for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
- ci++, compptr++) {
- main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
- ((j_common_ptr) cinfo, main->whole_image[ci],
- main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
- (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
- }
-
- if (! writing) {
- *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
- main->rowgroup_ctr = DCTSIZE;
- }
- }
-
-
- if (writing) {
- (*cinfo->prep->pre_process_data) (cinfo,
- input_buf, in_row_ctr, in_rows_avail,
- main->buffer, &main->rowgroup_ctr,
- (JDIMENSION) DCTSIZE);
-
- if (main->rowgroup_ctr < DCTSIZE)
- return;
- }
-
- if (main->pass_mode != JBUF_SAVE_SOURCE) {
- if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
-
- if (! main->suspended) {
- (*in_row_ctr)--;
- main->suspended = TRUE;
- }
- return;
- }
-
- if (main->suspended) {
- (*in_row_ctr)++;
- main->suspended = FALSE;
- }
- }
-
- main->rowgroup_ctr = 0;
- main->cur_iMCU_row++;
- }
- }
- #endif
- GLOBAL void
- jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
- {
-
- my_main_ptr jmain;
- int ci;
- jpeg_component_info *compptr;
- jmain = (my_main_ptr)
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
- SIZEOF(my_main_controller));
- cinfo->main = (struct jpeg_c_main_controller *) jmain;
- jmain->pub.start_pass = start_pass_main;
-
- if (cinfo->raw_data_in)
- return;
-
- if (need_full_buffer) {
- #ifdef FULL_MAIN_BUFFER_SUPPORTED
-
-
- for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
- ci++, compptr++) {
- jmain->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
- ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
- compptr->width_in_blocks * DCTSIZE,
- (JDIMENSION) jround_up((long) compptr->height_in_blocks,
- (long) compptr->v_samp_factor) * DCTSIZE,
- (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
- }
- #else
- ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
- #endif
- } else {
- #ifdef FULL_MAIN_BUFFER_SUPPORTED
- jmain->whole_image[0] = NULL;
- #endif
-
- for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
- ci++, compptr++) {
- jmain->buffer[ci] = (*cinfo->mem->alloc_sarray)
- ((j_common_ptr) cinfo, JPOOL_IMAGE,
- compptr->width_in_blocks * DCTSIZE,
- (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
- }
- }
- }
|