00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #define JPEG_INTERNALS
00014 #include "jinclude.h"
00015 #include "jpeglib.h"
00016
00017
00018
00019
00020
00021
00022
00023 #undef FULL_MAIN_BUFFER_SUPPORTED
00024
00025
00026
00027
00028 typedef struct {
00029 struct jpeg_c_main_controller pub;
00030
00031 JDIMENSION cur_iMCU_row;
00032 JDIMENSION rowgroup_ctr;
00033 boolean suspended;
00034 J_BUF_MODE pass_mode;
00035
00036
00037
00038
00039
00040 JSAMPARRAY buffer[MAX_COMPONENTS];
00041
00042 #ifdef FULL_MAIN_BUFFER_SUPPORTED
00043
00044
00045
00046 jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
00047 #endif
00048 } my_main_controller;
00049
00050 typedef my_main_controller * my_main_ptr;
00051
00052
00053
00054 METHODDEF(void) process_data_simple_main
00055 JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
00056 JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
00057 #ifdef FULL_MAIN_BUFFER_SUPPORTED
00058 METHODDEF(void) process_data_buffer_main
00059 JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
00060 JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
00061 #endif
00062
00063
00064
00065
00066
00067
00068 METHODDEF(void)
00069 start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
00070 {
00071 my_main_ptr main = (my_main_ptr) cinfo->main;
00072
00073
00074 if (cinfo->raw_data_in)
00075 return;
00076
00077 main->cur_iMCU_row = 0;
00078 main->rowgroup_ctr = 0;
00079 main->suspended = FALSE;
00080 main->pass_mode = pass_mode;
00081
00082 switch (pass_mode) {
00083 case JBUF_PASS_THRU:
00084 #ifdef FULL_MAIN_BUFFER_SUPPORTED
00085 if (main->whole_image[0] != NULL)
00086 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
00087 #endif
00088 main->pub.process_data = process_data_simple_main;
00089 break;
00090 #ifdef FULL_MAIN_BUFFER_SUPPORTED
00091 case JBUF_SAVE_SOURCE:
00092 case JBUF_CRANK_DEST:
00093 case JBUF_SAVE_AND_PASS:
00094 if (main->whole_image[0] == NULL)
00095 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
00096 main->pub.process_data = process_data_buffer_main;
00097 break;
00098 #endif
00099 default:
00100 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
00101 break;
00102 }
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112 METHODDEF(void)
00113 process_data_simple_main (j_compress_ptr cinfo,
00114 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
00115 JDIMENSION in_rows_avail)
00116 {
00117 my_main_ptr main = (my_main_ptr) cinfo->main;
00118
00119 while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
00120
00121 if (main->rowgroup_ctr < DCTSIZE)
00122 (*cinfo->prep->pre_process_data) (cinfo,
00123 input_buf, in_row_ctr, in_rows_avail,
00124 main->buffer, &main->rowgroup_ctr,
00125 (JDIMENSION) DCTSIZE);
00126
00127
00128
00129
00130
00131 if (main->rowgroup_ctr != DCTSIZE)
00132 return;
00133
00134
00135 if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
00136
00137
00138
00139
00140
00141
00142 if (! main->suspended) {
00143 (*in_row_ctr)--;
00144 main->suspended = TRUE;
00145 }
00146 return;
00147 }
00148
00149
00150
00151 if (main->suspended) {
00152 (*in_row_ctr)++;
00153 main->suspended = FALSE;
00154 }
00155 main->rowgroup_ctr = 0;
00156 main->cur_iMCU_row++;
00157 }
00158 }
00159
00160
00161 #ifdef FULL_MAIN_BUFFER_SUPPORTED
00162
00163
00164
00165
00166
00167
00168 METHODDEF(void)
00169 process_data_buffer_main (j_compress_ptr cinfo,
00170 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
00171 JDIMENSION in_rows_avail)
00172 {
00173 my_main_ptr main = (my_main_ptr) cinfo->main;
00174 int ci;
00175 jpeg_component_info *compptr;
00176 boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
00177
00178 while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
00179
00180 if (main->rowgroup_ctr == 0) {
00181 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00182 ci++, compptr++) {
00183 main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
00184 ((j_common_ptr) cinfo, main->whole_image[ci],
00185 main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
00186 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
00187 }
00188
00189 if (! writing) {
00190 *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
00191 main->rowgroup_ctr = DCTSIZE;
00192 }
00193 }
00194
00195
00196
00197 if (writing) {
00198 (*cinfo->prep->pre_process_data) (cinfo,
00199 input_buf, in_row_ctr, in_rows_avail,
00200 main->buffer, &main->rowgroup_ctr,
00201 (JDIMENSION) DCTSIZE);
00202
00203 if (main->rowgroup_ctr < DCTSIZE)
00204 return;
00205 }
00206
00207
00208 if (main->pass_mode != JBUF_SAVE_SOURCE) {
00209 if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
00210
00211
00212
00213
00214
00215
00216 if (! main->suspended) {
00217 (*in_row_ctr)--;
00218 main->suspended = TRUE;
00219 }
00220 return;
00221 }
00222
00223
00224
00225 if (main->suspended) {
00226 (*in_row_ctr)++;
00227 main->suspended = FALSE;
00228 }
00229 }
00230
00231
00232 main->rowgroup_ctr = 0;
00233 main->cur_iMCU_row++;
00234 }
00235 }
00236
00237 #endif
00238
00239
00240
00241
00242
00243
00244 GLOBAL(void)
00245 jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
00246 {
00247 my_main_ptr main;
00248 int ci;
00249 jpeg_component_info *compptr;
00250
00251 main = (my_main_ptr)
00252 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00253 SIZEOF(my_main_controller));
00254 cinfo->main = (struct jpeg_c_main_controller *) main;
00255 main->pub.start_pass = start_pass_main;
00256
00257
00258 if (cinfo->raw_data_in)
00259 return;
00260
00261
00262
00263
00264 if (need_full_buffer) {
00265 #ifdef FULL_MAIN_BUFFER_SUPPORTED
00266
00267
00268 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00269 ci++, compptr++) {
00270 main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
00271 ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
00272 compptr->width_in_blocks * DCTSIZE,
00273 (JDIMENSION) jround_up((long) compptr->height_in_blocks,
00274 (long) compptr->v_samp_factor) * DCTSIZE,
00275 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
00276 }
00277 #else
00278 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
00279 #endif
00280 } else {
00281 #ifdef FULL_MAIN_BUFFER_SUPPORTED
00282 main->whole_image[0] = NULL;
00283 #endif
00284
00285 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00286 ci++, compptr++) {
00287 main->buffer[ci] = (*cinfo->mem->alloc_sarray)
00288 ((j_common_ptr) cinfo, JPOOL_IMAGE,
00289 compptr->width_in_blocks * DCTSIZE,
00290 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
00291 }
00292 }
00293 }