1
12
13
14
15
16
17
18
23
24
25
26
27
28
29
30
31
32
33
34
35
36
40
41
42
43
47
48
49
50
51
52
53
54
55
56
57
58
61
62
63
64
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
103
104
105
106
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
131
132
133
134
135
148
151
155
156
157
158
159
160
161
162
163
167
168
169
170
171
172
173
174
175
176
177
178
179
180
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
230
231
232
233
234
235
236
237
238
239
240
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
293
/* ... */
#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 main = (my_main_ptr) cinfo->main;
if (cinfo->raw_data_in)
return;
main->cur_iMCU_row = 0;
main->rowgroup_ctr = 0;
main->suspended = FALSE;
main->pass_mode = pass_mode;
switch (pass_mode) {
case JBUF_PASS_THRU:
#ifdef FULL_MAIN_BUFFER_SUPPORTED
if (main->whole_image[0] != NULL)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);/* ... */
#endif
main->pub.process_data = process_data_simple_main;
break;
#ifdef FULL_MAIN_BUFFER_SUPPORTEDcase JBUF_PASS_THRU:
case JBUF_SAVE_SOURCE:
case JBUF_CRANK_DEST:
case JBUF_SAVE_AND_PASS:
if (main->whole_image[0] == NULL)
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
main->pub.process_data = process_data_buffer_main;
break;/* ... */
#endif
default:
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
break;default
}switch (pass_mode) { ... }
}{ ... }
/* ... */
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 (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
if (main->rowgroup_ctr < (JDIMENSION) cinfo->min_DCT_v_scaled_size)
(*cinfo->prep->pre_process_data) (cinfo,
input_buf, in_row_ctr, in_rows_avail,
main->buffer, &main->rowgroup_ctr,
(JDIMENSION) cinfo->min_DCT_v_scaled_size);
/* ... */
if (main->rowgroup_ctr != (JDIMENSION) cinfo->min_DCT_v_scaled_size)
return;
if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
/* ... */
if (! main->suspended) {
(*in_row_ctr)--;
main->suspended = TRUE;
}if (! main->suspended) { ... }
return;
}if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) { ... }
/* ... */
if (main->suspended) {
(*in_row_ctr)++;
main->suspended = FALSE;
}if (main->suspended) { ... }
main->rowgroup_ctr = 0;
main->cur_iMCU_row++;
}while (main->cur_iMCU_row < cinfo->total_iMCU_rows) { ... }
}{ ... }
#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);
}for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++) { ... }
if (! writing) {
*in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
main->rowgroup_ctr = DCTSIZE;
}if (! writing) { ... }
}if (main->rowgroup_ctr == 0) { ... }
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 (writing) { ... }
if (main->pass_mode != JBUF_SAVE_SOURCE) {
if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
/* ... */
if (! main->suspended) {
(*in_row_ctr)--;
main->suspended = TRUE;
}if (! main->suspended) { ... }
return;
}if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) { ... }
/* ... */
if (main->suspended) {
(*in_row_ctr)++;
main->suspended = FALSE;
}if (main->suspended) { ... }
}if (main->pass_mode != JBUF_SAVE_SOURCE) { ... }
main->rowgroup_ctr = 0;
main->cur_iMCU_row++;
}while (main->cur_iMCU_row < cinfo->total_iMCU_rows) { ... }
}process_data_buffer_main (j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail) { ... }
/* ... */
#endif
/* ... */
GLOBAL(void)
jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
{
my_main_ptr main;
int ci;
jpeg_component_info *compptr;
main = (my_main_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_main_controller));
cinfo->main = (struct jpeg_c_main_controller *) main;
main->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++) {
main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
compptr->width_in_blocks * compptr->DCT_h_scaled_size,
(JDIMENSION) jround_up((long) compptr->height_in_blocks,
(long) compptr->v_samp_factor) * DCTSIZE,
(JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size));
}for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++) { ... }
/* ... */#else
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
#endif
}if (need_full_buffer) { ... } else {
#ifdef FULL_MAIN_BUFFER_SUPPORTED
main->whole_image[0] = NULL;
#endif
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) {
main->buffer[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE,
compptr->width_in_blocks * compptr->DCT_h_scaled_size,
(JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size));
}for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; ci++, compptr++) { ... }
}else { ... }
}{ ... }