ReactOS 0.4.16-dev-297-gc569aee
jctrans.c File Reference
#include "jinclude.h"
#include "jpeglib.h"
Include dependency graph for jctrans.c:

Go to the source code of this file.

Classes

struct  my_coef_controller
 

Macros

#define JPEG_INTERNALS
 

Typedefs

typedef my_coef_controllermy_coef_ptr
 

Functions

 LOCAL (void)
 
 jpeg_copy_critical_parameters (j_decompress_ptr srcinfo, j_compress_ptr dstinfo)
 
 jpeg_calc_trans_dimensions (j_compress_ptr cinfo)
 
 transencode_master_selection (j_compress_ptr cinfo, jvirt_barray_ptr *coef_arrays)
 
 start_iMCU_row (j_compress_ptr cinfo)
 
 start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
 
 compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
 
 transencode_coef_controller (j_compress_ptr cinfo, jvirt_barray_ptr *coef_arrays)
 

Macro Definition Documentation

◆ JPEG_INTERNALS

#define JPEG_INTERNALS

Definition at line 14 of file jctrans.c.

Typedef Documentation

◆ my_coef_ptr

Definition at line 238 of file jctrans.c.

Function Documentation

◆ compress_output()

compress_output ( j_compress_ptr  cinfo,
JSAMPIMAGE  input_buf 
)

Definition at line 293 of file jctrans.c.

294{
295 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
296 JDIMENSION MCU_col_num; /* index of current MCU within row */
297 JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
298 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299 int blkn, ci, xindex, yindex, yoffset, blockcnt;
302 JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
303 JBLOCKROW buffer_ptr;
305
306 /* Align the virtual buffers for the components used in this scan. */
307 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
308 compptr = cinfo->cur_comp_info[ci];
309 buffer[ci] = (*cinfo->mem->access_virt_barray)
313 }
314
315 /* Loop to process one whole iMCU row */
316 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
317 yoffset++) {
318 for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
319 MCU_col_num++) {
320 /* Construct list of pointers to DCT blocks belonging to this MCU */
321 blkn = 0; /* index of current DCT block within MCU */
322 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
323 compptr = cinfo->cur_comp_info[ci];
324 start_col = MCU_col_num * compptr->MCU_width;
325 blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
327 for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
328 if (coef->iMCU_row_num < last_iMCU_row ||
329 yindex+yoffset < compptr->last_row_height) {
330 /* Fill in pointers to real blocks in this row */
331 buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
332 for (xindex = 0; xindex < blockcnt; xindex++)
333 MCU_buffer[blkn++] = buffer_ptr++;
334 } else {
335 /* At bottom of image, need a whole row of dummy blocks */
336 xindex = 0;
337 }
338 /* Fill in any dummy blocks needed in this row.
339 * Dummy blocks are filled in the same way as in jccoefct.c:
340 * all zeroes in the AC entries, DC entries equal to previous
341 * block's DC value. The init routine has already zeroed the
342 * AC entries, so we need only set the DC entries correctly.
343 */
344 for (; xindex < compptr->MCU_width; xindex++) {
345 MCU_buffer[blkn] = coef->dummy_buffer[blkn];
346 MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
347 blkn++;
348 }
349 }
350 }
351 /* Try to write the MCU. */
352 if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
353 /* Suspension forced; update state counters and exit */
354 coef->MCU_vert_offset = yoffset;
355 coef->mcu_ctr = MCU_col_num;
356 return FALSE;
357 }
358 }
359 /* Completed an MCU row, but perhaps not an iMCU row */
360 coef->mcu_ctr = 0;
361 }
362 /* Completed the iMCU row, advance counters for next one */
363 coef->iMCU_row_num++;
364 start_iMCU_row(cinfo);
365 return TRUE;
366}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLint GLint GLint yoffset
Definition: gl.h:1547
GLuint buffer
Definition: glext.h:5915
start_iMCU_row(j_compress_ptr cinfo)
Definition: jctrans.c:242
my_coef_controller * my_coef_ptr
Definition: jctrans.c:238
JSAMPARRAY JDIMENSION start_col
Definition: jdct.h:169
jpeg_component_info * compptr
Definition: jdct.h:238
unsigned int JDIMENSION
Definition: jmorecfg.h:229
JBLOCK FAR * JBLOCKROW
Definition: jpeglib.h:80
#define C_MAX_BLOCKS_IN_MCU
Definition: jpeglib.h:64
JBLOCKROW * JBLOCKARRAY
Definition: jpeglib.h:81
#define MAX_COMPS_IN_SCAN
Definition: jpeglib.h:55
#define for
Definition: utility.h:88
jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN]
Definition: jpeglib.h:423
struct jpeg_entropy_encoder * entropy
Definition: jpeglib.h:451
JDIMENSION MCUs_per_row
Definition: jpeglib.h:426
struct jpeg_c_coef_controller * coef
Definition: jpeglib.h:446
JDIMENSION total_iMCU_rows
Definition: jpeglib.h:411
JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU]
Definition: jctrans.c:235
jvirt_barray_ptr whole_image[MAX_COMPONENTS]
Definition: jccoefct.c:55
JDIMENSION mcu_ctr
Definition: jccoefct.c:39
JDIMENSION iMCU_row_num
Definition: jccoefct.c:38

Referenced by start_pass_coef(), and transencode_coef_controller().

◆ jpeg_calc_trans_dimensions()

jpeg_calc_trans_dimensions ( j_compress_ptr  cinfo)

Definition at line 164 of file jctrans.c.

166{
167 if (cinfo->min_DCT_h_scaled_size != cinfo->min_DCT_v_scaled_size)
168 ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
170
171 cinfo->block_size = cinfo->min_DCT_h_scaled_size;
172}
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:216

Referenced by transencode_master_selection().

◆ jpeg_copy_critical_parameters()

jpeg_copy_critical_parameters ( j_decompress_ptr  srcinfo,
j_compress_ptr  dstinfo 
)

Definition at line 64 of file jctrans.c.

66{
67 JQUANT_TBL ** qtblptr;
68 jpeg_component_info *incomp, *outcomp;
69 JQUANT_TBL *c_quant, *slot_quant;
70 int tblno, ci, coefi;
71
72 /* Safety check to ensure start_compress not called yet. */
73 if (dstinfo->global_state != CSTATE_START)
74 ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
75 /* Copy fundamental image dimensions */
84 /* Initialize all parameters to default values */
86 /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB.
87 * Fix it to get the right header markers for the image colorspace.
88 * Note: Entropy table assignment in jpeg_set_colorspace
89 * depends on color_transform.
90 * Adaption is also required for setting the appropriate
91 * entropy coding mode dependent on image data precision.
92 */
96 dstinfo->arith_code = srcinfo->data_precision > 8 ? TRUE : FALSE;
98 /* Copy the source's quantization tables. */
99 for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
100 if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
101 qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
102 if (*qtblptr == NULL)
104 MEMCOPY((*qtblptr)->quantval,
105 srcinfo->quant_tbl_ptrs[tblno]->quantval,
106 SIZEOF((*qtblptr)->quantval));
107 (*qtblptr)->sent_table = FALSE;
108 }
109 }
110 /* Copy the source's per-component info.
111 * Note we assume jpeg_set_defaults has allocated the dest comp_info array.
112 */
115 ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
117 for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
118 ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
119 outcomp->component_id = incomp->component_id;
120 outcomp->h_samp_factor = incomp->h_samp_factor;
121 outcomp->v_samp_factor = incomp->v_samp_factor;
122 outcomp->quant_tbl_no = incomp->quant_tbl_no;
123 /* Make sure saved quantization table for component matches the qtable
124 * slot. If not, the input file re-used this qtable slot.
125 * IJG encoder currently cannot duplicate this.
126 */
127 tblno = outcomp->quant_tbl_no;
128 if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
129 srcinfo->quant_tbl_ptrs[tblno] == NULL)
130 ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
131 slot_quant = srcinfo->quant_tbl_ptrs[tblno];
132 c_quant = incomp->quant_table;
133 if (c_quant != NULL) {
134 for (coefi = 0; coefi < DCTSIZE2; coefi++) {
135 if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
136 ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
137 }
138 }
139 /* Note: we do not copy the source's entropy table assignments;
140 * instead we rely on jpeg_set_colorspace to have made a suitable choice.
141 */
142 }
143 /* Also copy JFIF version and resolution information, if available.
144 * Strictly speaking this isn't "critical" info, but it's nearly
145 * always appropriate to copy it if available. In particular,
146 * if the application chooses to copy JFIF 1.02 extension markers from
147 * the source file, we need to copy the version to make sure we don't
148 * emit a file that has 1.02 extensions but a claimed version of 1.01.
149 */
150 if (srcinfo->saw_JFIF_marker) {
151 if (srcinfo->JFIF_major_version == 1 ||
152 srcinfo->JFIF_major_version == 2) {
155 }
157 dstinfo->X_density = srcinfo->X_density;
158 dstinfo->Y_density = srcinfo->Y_density;
159 }
160}
#define SIZEOF(_ar)
Definition: calc.h:97
#define NULL
Definition: types.h:112
jpeg_alloc_quant_table(j_common_ptr cinfo)
Definition: jcomapi.c:87
jpeg_set_colorspace(j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
Definition: jcparam.c:336
jpeg_set_defaults(j_compress_ptr cinfo)
Definition: jcparam.c:196
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:212
#define MEMCOPY(dest, src, size)
Definition: jinclude.h:69
#define MAX_COMPONENTS
Definition: jmorecfg.h:45
#define CSTATE_START
Definition: jpegint.h:26
j_compress_ptr dstinfo
Definition: jpeglib.h:1100
#define NUM_QUANT_TBLS
Definition: jpeglib.h:52
boolean int tblno
Definition: jpeglib.h:1010
#define DCTSIZE2
Definition: jpeglib.h:51
UINT16 quantval[DCTSIZE2]
Definition: jpeglib.h:97
JQUANT_TBL * quant_table
Definition: jpeglib.h:189
JDIMENSION image_height
Definition: jpeglib.h:303
J_COLOR_TRANSFORM color_transform
Definition: jpeglib.h:387
jpeg_component_info * comp_info
Definition: jpeglib.h:333
JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]
Definition: jpeglib.h:336
UINT8 JFIF_major_version
Definition: jpeglib.h:376
boolean arith_code
Definition: jpeglib.h:358
UINT8 JFIF_minor_version
Definition: jpeglib.h:377
JDIMENSION jpeg_width
Definition: jpeglib.h:319
JDIMENSION jpeg_height
Definition: jpeglib.h:320
boolean CCIR601_sampling
Definition: jpeglib.h:360
J_COLOR_SPACE in_color_space
Definition: jpeglib.h:305
JDIMENSION image_width
Definition: jpeglib.h:302
JDIMENSION output_height
Definition: jpeglib.h:508
boolean saw_JFIF_marker
Definition: jpeglib.h:599
JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]
Definition: jpeglib.h:570
JDIMENSION image_width
Definition: jpeglib.h:468
boolean CCIR601_sampling
Definition: jpeglib.h:612
J_COLOR_TRANSFORM color_transform
Definition: jpeglib.h:609
J_COLOR_SPACE jpeg_color_space
Definition: jpeglib.h:471
JDIMENSION output_width
Definition: jpeglib.h:507
JDIMENSION image_height
Definition: jpeglib.h:469
jpeg_component_info * comp_info
Definition: jpeglib.h:583

Referenced by main().

◆ LOCAL()

LOCAL ( void  )

Definition at line 20 of file jctrans.c.

40{
41 if (cinfo->global_state != CSTATE_START)
42 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
43 /* Mark all tables to be written */
45 /* (Re)initialize error mgr and destination modules */
46 (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
47 (*cinfo->dest->init_destination) (cinfo);
48 /* Perform master selection of active modules */
50 /* Wait for jpeg_finish_compress() call */
51 cinfo->next_scanline = 0; /* so jpeg_write_marker works */
52 cinfo->global_state = CSTATE_WRCOEFS;
53}
jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress)
Definition: jcapimin.c:127
transencode_master_selection(j_compress_ptr cinfo, jvirt_barray_ptr *coef_arrays)
Definition: jctrans.c:181
#define CSTATE_WRCOEFS
Definition: jpegint.h:29
jvirt_barray_ptr * coef_arrays
Definition: jpeglib.h:1098

◆ start_iMCU_row()

start_iMCU_row ( j_compress_ptr  cinfo)

Definition at line 242 of file jctrans.c.

244{
245 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
246
247 /* In an interleaved scan, an MCU row is the same as an iMCU row.
248 * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
249 * But at the bottom of the image, process only what's left.
250 */
251 if (cinfo->comps_in_scan > 1) {
252 coef->MCU_rows_per_iMCU_row = 1;
253 } else {
254 if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
256 else
258 }
259
260 coef->mcu_ctr = 0;
261 coef->MCU_vert_offset = 0;
262}
if(dx< 0)
Definition: linetemp.h:194
int MCU_rows_per_iMCU_row
Definition: jccoefct.c:41

Referenced by compress_data(), compress_output(), decompress_onepass(), start_input_pass(), and start_pass_coef().

◆ start_pass_coef()

start_pass_coef ( j_compress_ptr  cinfo,
J_BUF_MODE  pass_mode 
)

Definition at line 270 of file jctrans.c.

271{
272 my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
273
274 if (pass_mode != JBUF_CRANK_DEST)
275 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
276
277 coef->iMCU_row_num = 0;
278 start_iMCU_row(cinfo);
279}
@ JBUF_CRANK_DEST
Definition: jpegint.h:21
#define ERREXIT(msg)
Definition: rdjpgcom.c:72

Referenced by transencode_coef_controller().

◆ transencode_coef_controller()

transencode_coef_controller ( j_compress_ptr  cinfo,
jvirt_barray_ptr coef_arrays 
)

Definition at line 378 of file jctrans.c.

380{
381 my_coef_ptr coef;
383 int i;
384
385 coef = (my_coef_ptr)
386 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
388 cinfo->coef = &coef->pub;
389 coef->pub.start_pass = start_pass_coef;
390 coef->pub.compress_data = compress_output;
391
392 /* Save pointer to virtual arrays */
393 coef->whole_image = coef_arrays;
394
395 /* Allocate and pre-zero space for dummy DCT blocks. */
396 buffer = (JBLOCKROW)
397 (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
400 for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
401 coef->dummy_buffer[i] = buffer + i;
402 }
403}
#define FAR
Definition: zlib.h:34
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
start_pass_coef(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
Definition: jctrans.c:270
compress_output(j_compress_ptr cinfo, JSAMPIMAGE input_buf)
Definition: jctrans.c:293
#define FMEMZERO(target, size)
Definition: jpegint.h:368
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:284
JCOEF JBLOCK[DCTSIZE2]
Definition: jpeglib.h:79
#define JPOOL_IMAGE
Definition: jpeglib.h:808
struct jpeg_c_coef_controller pub
Definition: jccoefct.c:36

Referenced by transencode_master_selection().

◆ transencode_master_selection()

transencode_master_selection ( j_compress_ptr  cinfo,
jvirt_barray_ptr coef_arrays 
)

Definition at line 181 of file jctrans.c.

183{
184 /* Do computations that are needed before master selection phase */
186
187 /* Initialize master control (includes parameter checking/processing) */
188 jinit_c_master_control(cinfo, TRUE /* transcode only */);
189
190 /* Entropy encoding: either Huffman or arithmetic coding. */
191 if (cinfo->arith_code)
192 jinit_arith_encoder(cinfo);
193 else {
194 jinit_huff_encoder(cinfo);
195 }
196
197 /* We need a special coefficient buffer controller. */
199
200 jinit_marker_writer(cinfo);
201
202 /* We can now tell the memory manager to allocate virtual arrays. */
203 (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
204
205 /* Write the datastream header (SOI, JFIF) immediately.
206 * Frame and scan headers are postponed till later.
207 * This lets application insert special markers after the SOI.
208 */
209 (*cinfo->marker->write_file_header) (cinfo);
210}
jinit_arith_encoder(j_compress_ptr cinfo)
Definition: jcarith.c:926
jinit_huff_encoder(j_compress_ptr cinfo)
Definition: jchuff.c:1622
jinit_marker_writer(j_compress_ptr cinfo)
Definition: jcmarker.c:699
jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only)
Definition: jcmaster.c:623
transencode_coef_controller(j_compress_ptr cinfo, jvirt_barray_ptr *coef_arrays)
Definition: jctrans.c:378
jpeg_calc_trans_dimensions(j_compress_ptr cinfo)
Definition: jctrans.c:164
struct jpeg_marker_writer * marker
Definition: jpeglib.h:447