ReactOS 0.4.15-dev-5667-ged97270
jcinit.c File Reference
#include "jinclude.h"
#include "jpeglib.h"
Include dependency graph for jcinit.c:

Go to the source code of this file.

Macros

#define JPEG_INTERNALS
 

Functions

 jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo)
 
 jinit_compress_master (j_compress_ptr cinfo)
 

Macro Definition Documentation

◆ JPEG_INTERNALS

#define JPEG_INTERNALS

Definition at line 19 of file jcinit.c.

Function Documentation

◆ jinit_compress_master()

jinit_compress_master ( j_compress_ptr  cinfo)

Definition at line 193 of file jcinit.c.

194{
195 long samplesperrow;
196 JDIMENSION jd_samplesperrow;
197
198 /* For now, precision must match compiled-in value... */
199 if (cinfo->data_precision != BITS_IN_JSAMPLE)
200 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
201
202 /* Sanity check on input image dimensions */
203 if (cinfo->image_height <= 0 || cinfo->image_width <= 0 ||
204 cinfo->input_components <= 0)
205 ERREXIT(cinfo, JERR_EMPTY_IMAGE);
206
207 /* Width of an input scanline must be representable as JDIMENSION. */
208 samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
209 jd_samplesperrow = (JDIMENSION) samplesperrow;
210 if ((long) jd_samplesperrow != samplesperrow)
211 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
212
213 /* Compute JPEG image dimensions and related values. */
215
216 /* Initialize master control (includes parameter checking/processing) */
217 jinit_c_master_control(cinfo, FALSE /* full compression */);
218
219 /* Preprocessing */
220 if (! cinfo->raw_data_in) {
222 jinit_downsampler(cinfo);
223 jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
224 }
225 /* Forward DCT */
226 jinit_forward_dct(cinfo);
227 /* Entropy encoding: either Huffman or arithmetic coding. */
228 if (cinfo->arith_code)
229 jinit_arith_encoder(cinfo);
230 else {
231 jinit_huff_encoder(cinfo);
232 }
233
234 /* Need a full-image coefficient buffer in any multi-pass mode. */
236 (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
237 jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
238
239 jinit_marker_writer(cinfo);
240
241 /* We can now tell the memory manager to allocate virtual arrays. */
242 (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
243
244 /* Write the datastream header (SOI) immediately.
245 * Frame and scan headers are postponed till later.
246 * This lets application insert special markers after the SOI.
247 */
248 (*cinfo->marker->write_file_header) (cinfo);
249}
#define FALSE
Definition: types.h:117
jinit_arith_encoder(j_compress_ptr cinfo)
Definition: jcarith.c:926
jinit_c_coef_controller(j_compress_ptr cinfo, boolean need_full_buffer)
Definition: jccoefct.c:410
jinit_color_converter(j_compress_ptr cinfo)
Definition: jccolor.c:438
jinit_forward_dct(j_compress_ptr cinfo)
Definition: jcdctmgr.c:458
jinit_huff_encoder(j_compress_ptr cinfo)
Definition: jchuff.c:1622
jpeg_calc_jpeg_dimensions(j_compress_ptr cinfo)
Definition: jcinit.c:31
jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer)
Definition: jcmainct.c:248
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
jinit_c_prep_controller(j_compress_ptr cinfo, boolean need_full_buffer)
Definition: jcprepct.c:318
jinit_downsampler(j_compress_ptr cinfo)
Definition: jcsample.c:478
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:212
unsigned int JDIMENSION
Definition: jmorecfg.h:229
#define BITS_IN_JSAMPLE
Definition: jmorecfg.h:33
#define long
Definition: qsort.c:33
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
boolean optimize_coding
Definition: jpeglib.h:359
JDIMENSION image_height
Definition: jpeglib.h:303
boolean raw_data_in
Definition: jpeglib.h:357
struct jpeg_marker_writer * marker
Definition: jpeglib.h:447
boolean arith_code
Definition: jpeglib.h:358
JDIMENSION image_width
Definition: jpeglib.h:302

Referenced by jpeg_start_compress().

◆ jpeg_calc_jpeg_dimensions()

jpeg_calc_jpeg_dimensions ( j_compress_ptr  cinfo)

Definition at line 31 of file jcinit.c.

33{
34 /* Sanity check on input image dimensions to prevent overflow in
35 * following calculations.
36 * We do check jpeg_width and jpeg_height in initial_setup in jcmaster.c,
37 * but image_width and image_height can come from arbitrary data,
38 * and we need some space for multiplication by block_size.
39 */
40 if (((long) cinfo->image_width >> 24) || ((long) cinfo->image_height >> 24))
41 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
42
43#ifdef DCT_SCALING_SUPPORTED
44
45 /* Compute actual JPEG image dimensions and DCT scaling choices. */
46 if (cinfo->scale_num >= cinfo->scale_denom * cinfo->block_size) {
47 /* Provide block_size/1 scaling */
48 cinfo->jpeg_width = cinfo->image_width * cinfo->block_size;
49 cinfo->jpeg_height = cinfo->image_height * cinfo->block_size;
50 cinfo->min_DCT_h_scaled_size = 1;
51 cinfo->min_DCT_v_scaled_size = 1;
52 } else if (cinfo->scale_num * 2 >= cinfo->scale_denom * cinfo->block_size) {
53 /* Provide block_size/2 scaling */
54 cinfo->jpeg_width = (JDIMENSION)
55 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 2L);
56 cinfo->jpeg_height = (JDIMENSION)
57 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 2L);
58 cinfo->min_DCT_h_scaled_size = 2;
59 cinfo->min_DCT_v_scaled_size = 2;
60 } else if (cinfo->scale_num * 3 >= cinfo->scale_denom * cinfo->block_size) {
61 /* Provide block_size/3 scaling */
62 cinfo->jpeg_width = (JDIMENSION)
63 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 3L);
64 cinfo->jpeg_height = (JDIMENSION)
65 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 3L);
66 cinfo->min_DCT_h_scaled_size = 3;
67 cinfo->min_DCT_v_scaled_size = 3;
68 } else if (cinfo->scale_num * 4 >= cinfo->scale_denom * cinfo->block_size) {
69 /* Provide block_size/4 scaling */
70 cinfo->jpeg_width = (JDIMENSION)
71 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 4L);
72 cinfo->jpeg_height = (JDIMENSION)
73 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 4L);
74 cinfo->min_DCT_h_scaled_size = 4;
75 cinfo->min_DCT_v_scaled_size = 4;
76 } else if (cinfo->scale_num * 5 >= cinfo->scale_denom * cinfo->block_size) {
77 /* Provide block_size/5 scaling */
78 cinfo->jpeg_width = (JDIMENSION)
79 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 5L);
80 cinfo->jpeg_height = (JDIMENSION)
81 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 5L);
82 cinfo->min_DCT_h_scaled_size = 5;
83 cinfo->min_DCT_v_scaled_size = 5;
84 } else if (cinfo->scale_num * 6 >= cinfo->scale_denom * cinfo->block_size) {
85 /* Provide block_size/6 scaling */
86 cinfo->jpeg_width = (JDIMENSION)
87 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 6L);
88 cinfo->jpeg_height = (JDIMENSION)
89 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 6L);
90 cinfo->min_DCT_h_scaled_size = 6;
91 cinfo->min_DCT_v_scaled_size = 6;
92 } else if (cinfo->scale_num * 7 >= cinfo->scale_denom * cinfo->block_size) {
93 /* Provide block_size/7 scaling */
94 cinfo->jpeg_width = (JDIMENSION)
95 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 7L);
96 cinfo->jpeg_height = (JDIMENSION)
97 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 7L);
98 cinfo->min_DCT_h_scaled_size = 7;
99 cinfo->min_DCT_v_scaled_size = 7;
100 } else if (cinfo->scale_num * 8 >= cinfo->scale_denom * cinfo->block_size) {
101 /* Provide block_size/8 scaling */
102 cinfo->jpeg_width = (JDIMENSION)
103 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 8L);
104 cinfo->jpeg_height = (JDIMENSION)
105 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 8L);
106 cinfo->min_DCT_h_scaled_size = 8;
107 cinfo->min_DCT_v_scaled_size = 8;
108 } else if (cinfo->scale_num * 9 >= cinfo->scale_denom * cinfo->block_size) {
109 /* Provide block_size/9 scaling */
110 cinfo->jpeg_width = (JDIMENSION)
111 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 9L);
112 cinfo->jpeg_height = (JDIMENSION)
113 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 9L);
114 cinfo->min_DCT_h_scaled_size = 9;
115 cinfo->min_DCT_v_scaled_size = 9;
116 } else if (cinfo->scale_num * 10 >= cinfo->scale_denom * cinfo->block_size) {
117 /* Provide block_size/10 scaling */
118 cinfo->jpeg_width = (JDIMENSION)
119 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 10L);
120 cinfo->jpeg_height = (JDIMENSION)
121 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 10L);
122 cinfo->min_DCT_h_scaled_size = 10;
123 cinfo->min_DCT_v_scaled_size = 10;
124 } else if (cinfo->scale_num * 11 >= cinfo->scale_denom * cinfo->block_size) {
125 /* Provide block_size/11 scaling */
126 cinfo->jpeg_width = (JDIMENSION)
127 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 11L);
128 cinfo->jpeg_height = (JDIMENSION)
129 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 11L);
130 cinfo->min_DCT_h_scaled_size = 11;
131 cinfo->min_DCT_v_scaled_size = 11;
132 } else if (cinfo->scale_num * 12 >= cinfo->scale_denom * cinfo->block_size) {
133 /* Provide block_size/12 scaling */
134 cinfo->jpeg_width = (JDIMENSION)
135 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 12L);
136 cinfo->jpeg_height = (JDIMENSION)
137 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 12L);
138 cinfo->min_DCT_h_scaled_size = 12;
139 cinfo->min_DCT_v_scaled_size = 12;
140 } else if (cinfo->scale_num * 13 >= cinfo->scale_denom * cinfo->block_size) {
141 /* Provide block_size/13 scaling */
142 cinfo->jpeg_width = (JDIMENSION)
143 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 13L);
144 cinfo->jpeg_height = (JDIMENSION)
145 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 13L);
146 cinfo->min_DCT_h_scaled_size = 13;
147 cinfo->min_DCT_v_scaled_size = 13;
148 } else if (cinfo->scale_num * 14 >= cinfo->scale_denom * cinfo->block_size) {
149 /* Provide block_size/14 scaling */
150 cinfo->jpeg_width = (JDIMENSION)
151 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 14L);
152 cinfo->jpeg_height = (JDIMENSION)
153 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 14L);
154 cinfo->min_DCT_h_scaled_size = 14;
155 cinfo->min_DCT_v_scaled_size = 14;
156 } else if (cinfo->scale_num * 15 >= cinfo->scale_denom * cinfo->block_size) {
157 /* Provide block_size/15 scaling */
158 cinfo->jpeg_width = (JDIMENSION)
159 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 15L);
160 cinfo->jpeg_height = (JDIMENSION)
161 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 15L);
162 cinfo->min_DCT_h_scaled_size = 15;
163 cinfo->min_DCT_v_scaled_size = 15;
164 } else {
165 /* Provide block_size/16 scaling */
166 cinfo->jpeg_width = (JDIMENSION)
167 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 16L);
168 cinfo->jpeg_height = (JDIMENSION)
169 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 16L);
170 cinfo->min_DCT_h_scaled_size = 16;
171 cinfo->min_DCT_v_scaled_size = 16;
172 }
173
174#else /* !DCT_SCALING_SUPPORTED */
175
176 /* Hardwire it to "no scaling" */
177 cinfo->jpeg_width = cinfo->image_width;
178 cinfo->jpeg_height = cinfo->image_height;
181
182#endif /* DCT_SCALING_SUPPORTED */
183}
#define JPEG_MAX_DIMENSION
Definition: jmorecfg.h:231
#define DCTSIZE
Definition: jpeglib.h:50
jdiv_round_up(long a, long b)
Definition: jutils.c:124
unsigned int scale_num
Definition: jpeglib.h:317
unsigned int scale_denom
Definition: jpeglib.h:317
JDIMENSION jpeg_width
Definition: jpeglib.h:319
JDIMENSION jpeg_height
Definition: jpeglib.h:320

Referenced by jinit_compress_master().