ReactOS 0.4.15-dev-7834-g00c4b3d
jdapimin.c File Reference
#include "jinclude.h"
#include "jpeglib.h"
Include dependency graph for jdapimin.c:

Go to the source code of this file.

Macros

#define JPEG_INTERNALS
 

Functions

 jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
 
 jpeg_destroy_decompress (j_decompress_ptr cinfo)
 
 jpeg_abort_decompress (j_decompress_ptr cinfo)
 
 default_decompress_parms (j_decompress_ptr cinfo)
 
 jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
 
 jpeg_consume_input (j_decompress_ptr cinfo)
 
 jpeg_input_complete (j_decompress_ptr cinfo)
 
 jpeg_has_multiple_scans (j_decompress_ptr cinfo)
 
 jpeg_finish_decompress (j_decompress_ptr cinfo)
 

Macro Definition Documentation

◆ JPEG_INTERNALS

#define JPEG_INTERNALS

Definition at line 20 of file jdapimin.c.

Function Documentation

◆ default_decompress_parms()

default_decompress_parms ( j_decompress_ptr  cinfo)

Definition at line 115 of file jdapimin.c.

116{
117 int cid0, cid1, cid2;
118
119 /* Guess the input colorspace, and set output colorspace accordingly. */
120 /* Note application may override our guesses. */
121 switch (cinfo->num_components) {
122 case 1:
125 break;
126
127 case 3:
128 cid0 = cinfo->comp_info[0].component_id;
129 cid1 = cinfo->comp_info[1].component_id;
130 cid2 = cinfo->comp_info[2].component_id;
131
132 /* First try to guess from the component IDs */
133 if (cid0 == 0x01 && cid1 == 0x02 && cid2 == 0x03)
135 else if (cid0 == 0x01 && cid1 == 0x22 && cid2 == 0x23)
137 else if (cid0 == 0x52 && cid1 == 0x47 && cid2 == 0x42)
138 cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
139 else if (cid0 == 0x72 && cid1 == 0x67 && cid2 == 0x62)
140 cinfo->jpeg_color_space = JCS_BG_RGB; /* ASCII 'r', 'g', 'b' */
141 else if (cinfo->saw_JFIF_marker)
142 cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
143 else if (cinfo->saw_Adobe_marker) {
144 switch (cinfo->Adobe_transform) {
145 case 0:
146 cinfo->jpeg_color_space = JCS_RGB;
147 break;
148 case 1:
150 break;
151 default:
152 WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
153 cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
154 break;
155 }
156 } else {
157 TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
158 cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
159 }
160 /* Always guess RGB is proper output colorspace. */
161 cinfo->out_color_space = JCS_RGB;
162 break;
163
164 case 4:
165 if (cinfo->saw_Adobe_marker) {
166 switch (cinfo->Adobe_transform) {
167 case 0:
168 cinfo->jpeg_color_space = JCS_CMYK;
169 break;
170 case 2:
171 cinfo->jpeg_color_space = JCS_YCCK;
172 break;
173 default:
174 WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
175 cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
176 break;
177 }
178 } else {
179 /* No special markers, assume straight CMYK. */
180 cinfo->jpeg_color_space = JCS_CMYK;
181 }
182 cinfo->out_color_space = JCS_CMYK;
183 break;
184
185 default:
188 break;
189 }
190
191 /* Set defaults for other decompression parameters. */
192 cinfo->scale_num = cinfo->block_size; /* 1:1 scaling */
193 cinfo->scale_denom = cinfo->block_size;
194 cinfo->output_gamma = 1.0;
195 cinfo->buffered_image = FALSE;
196 cinfo->raw_data_out = FALSE;
197 cinfo->dct_method = JDCT_DEFAULT;
198 cinfo->do_fancy_upsampling = TRUE;
199 cinfo->do_block_smoothing = TRUE;
200 cinfo->quantize_colors = FALSE;
201 /* We set these in case application only sets quantize_colors. */
202 cinfo->dither_mode = JDITHER_FS;
203#ifdef QUANT_2PASS_SUPPORTED
204 cinfo->two_pass_quantize = TRUE;
205#else
206 cinfo->two_pass_quantize = FALSE;
207#endif
208 cinfo->desired_number_of_colors = 256;
209 cinfo->colormap = NULL;
210 /* Initialize for no mode change in buffered-image mode. */
211 cinfo->enable_1pass_quant = FALSE;
213 cinfo->enable_2pass_quant = FALSE;
214}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define WARNMS1(cinfo, code, p1)
Definition: jerror.h:254
#define TRACEMS3(cinfo, lvl, code, p1, p2, p3)
Definition: jerror.h:277
#define JDCT_DEFAULT
Definition: jpeglib.h:247
@ JDITHER_FS
Definition: jpeglib.h:258
@ JCS_YCCK
Definition: jpeglib.h:226
@ JCS_BG_RGB
Definition: jpeglib.h:227
@ JCS_BG_YCC
Definition: jpeglib.h:228
@ JCS_UNKNOWN
Definition: jpeglib.h:221
@ JCS_YCbCr
Definition: jpeglib.h:224
@ JCS_CMYK
Definition: jpeglib.h:225
@ JCS_GRAYSCALE
Definition: jpeglib.h:222
@ JCS_RGB
Definition: jpeglib.h:223
boolean two_pass_quantize
Definition: jpeglib.h:494
boolean saw_JFIF_marker
Definition: jpeglib.h:599
JSAMPARRAY colormap
Definition: jpeglib.h:527
boolean quantize_colors
Definition: jpeglib.h:491
boolean do_fancy_upsampling
Definition: jpeglib.h:488
boolean do_block_smoothing
Definition: jpeglib.h:489
J_COLOR_SPACE out_color_space
Definition: jpeglib.h:478
unsigned int scale_num
Definition: jpeglib.h:480
boolean enable_2pass_quant
Definition: jpeglib.h:499
J_COLOR_SPACE jpeg_color_space
Definition: jpeglib.h:471
boolean enable_1pass_quant
Definition: jpeglib.h:497
boolean buffered_image
Definition: jpeglib.h:484
boolean saw_Adobe_marker
Definition: jpeglib.h:606
boolean enable_external_quant
Definition: jpeglib.h:498
unsigned int scale_denom
Definition: jpeglib.h:480
J_DITHER_MODE dither_mode
Definition: jpeglib.h:493
J_DCT_METHOD dct_method
Definition: jpeglib.h:487
jpeg_component_info * comp_info
Definition: jpeglib.h:583

Referenced by jpeg_consume_input().

◆ jpeg_abort_decompress()

jpeg_abort_decompress ( j_decompress_ptr  cinfo)

Definition at line 104 of file jdapimin.c.

105{
106 jpeg_abort((j_common_ptr) cinfo); /* use common routine */
107}
jpeg_abort(j_common_ptr cinfo)
Definition: jcomapi.c:30

◆ jpeg_consume_input()

jpeg_consume_input ( j_decompress_ptr  cinfo)

Definition at line 291 of file jdapimin.c.

292{
293 int retcode = JPEG_SUSPENDED;
294
295 /* NB: every possible DSTATE value should be listed in this switch */
296 switch (cinfo->global_state) {
297 case DSTATE_START:
298 /* Start-of-datastream actions: reset appropriate modules */
299 (*cinfo->inputctl->reset_input_controller) (cinfo);
300 /* Initialize application's data source module */
301 (*cinfo->src->init_source) (cinfo);
302 cinfo->global_state = DSTATE_INHEADER;
303 /*FALLTHROUGH*/
304 case DSTATE_INHEADER:
305 retcode = (*cinfo->inputctl->consume_input) (cinfo);
306 if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
307 /* Set up default parameters based on header data */
309 /* Set global state: ready for start_decompress */
310 cinfo->global_state = DSTATE_READY;
311 }
312 break;
313 case DSTATE_READY:
314 /* Can't advance past first SOS until start_decompress is called */
315 retcode = JPEG_REACHED_SOS;
316 break;
317 case DSTATE_PRELOAD:
318 case DSTATE_PRESCAN:
319 case DSTATE_SCANNING:
320 case DSTATE_RAW_OK:
321 case DSTATE_BUFIMAGE:
322 case DSTATE_BUFPOST:
323 case DSTATE_STOPPING:
324 retcode = (*cinfo->inputctl->consume_input) (cinfo);
325 break;
326 default:
327 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
328 }
329 return retcode;
330}
default_decompress_parms(j_decompress_ptr cinfo)
Definition: jdapimin.c:115
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:212
#define DSTATE_BUFIMAGE
Definition: jpegint.h:37
#define DSTATE_INHEADER
Definition: jpegint.h:31
#define DSTATE_READY
Definition: jpegint.h:32
#define DSTATE_START
Definition: jpegint.h:30
#define DSTATE_PRELOAD
Definition: jpegint.h:33
#define DSTATE_PRESCAN
Definition: jpegint.h:34
#define DSTATE_SCANNING
Definition: jpegint.h:35
#define DSTATE_RAW_OK
Definition: jpegint.h:36
#define DSTATE_BUFPOST
Definition: jpegint.h:38
#define DSTATE_STOPPING
Definition: jpegint.h:40
#define JPEG_REACHED_SOS
Definition: jpeglib.h:1076
#define JPEG_SUSPENDED
Definition: jpeglib.h:1045
struct jpeg_source_mgr * src
Definition: jpeglib.h:463
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:682

Referenced by jpeg_read_header().

◆ jpeg_CreateDecompress()

jpeg_CreateDecompress ( j_decompress_ptr  cinfo,
int  version,
size_t  structsize 
)

Definition at line 31 of file jdapimin.c.

32{
33 int i;
34
35 /* Guard against version mismatches between library and caller. */
36 cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
38 ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
40 ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
41 (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
42
43 /* For debugging purposes, we zero the whole master structure.
44 * But the application has already set the err pointer, and may have set
45 * client_data, so we have to save and restore those fields.
46 * Note: if application hasn't set client_data, tools like Purify may
47 * complain here.
48 */
49 {
50 struct jpeg_error_mgr * err = cinfo->err;
51 void * client_data = cinfo->client_data; /* ignore Purify complaint here */
53 cinfo->err = err;
54 cinfo->client_data = client_data;
55 }
56 cinfo->is_decompressor = TRUE;
57
58 /* Initialize a memory manager instance for this object */
60
61 /* Zero out pointers to permanent structures. */
62 cinfo->progress = NULL;
63 cinfo->src = NULL;
64
65 for (i = 0; i < NUM_QUANT_TBLS; i++)
66 cinfo->quant_tbl_ptrs[i] = NULL;
67
68 for (i = 0; i < NUM_HUFF_TBLS; i++) {
69 cinfo->dc_huff_tbl_ptrs[i] = NULL;
70 cinfo->ac_huff_tbl_ptrs[i] = NULL;
71 }
72
73 /* Initialize marker processor so application can override methods
74 * for COM, APPn markers before calling jpeg_read_header.
75 */
76 cinfo->marker_list = NULL;
78
79 /* And initialize the overall input controller. */
81
82 /* OK, I'm ready */
83 cinfo->global_state = DSTATE_START;
84}
#define SIZEOF(_ar)
Definition: calc.h:97
static const WCHAR version[]
Definition: asmname.c:66
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
jinit_input_controller(j_decompress_ptr cinfo)
Definition: jdinput.c:642
jinit_marker_reader(j_decompress_ptr cinfo)
Definition: jdmarker.c:1408
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:216
jinit_memory_mgr(j_common_ptr cinfo)
Definition: jmemmgr.c:1025
#define NUM_HUFF_TBLS
Definition: jpeglib.h:53
int size_t structsize
Definition: jpeglib.h:966
#define NUM_QUANT_TBLS
Definition: jpeglib.h:52
#define JPEG_LIB_VERSION
Definition: jpeglib.h:40
#define for
Definition: utility.h:88
#define err(...)
jpeg_saved_marker_ptr marker_list
Definition: jpeglib.h:618
JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]
Definition: jpeglib.h:570
JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]
Definition: jpeglib.h:573
JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]
Definition: jpeglib.h:574
#define MEMZERO(addr, type, size)
Definition: svc_dg.c:324

◆ jpeg_destroy_decompress()

jpeg_destroy_decompress ( j_decompress_ptr  cinfo)

Definition at line 92 of file jdapimin.c.

93{
94 jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
95}
jpeg_destroy(j_common_ptr cinfo)
Definition: jcomapi.c:70

Referenced by main(), and read_JPEG_file().

◆ jpeg_finish_decompress()

jpeg_finish_decompress ( j_decompress_ptr  cinfo)

Definition at line 373 of file jdapimin.c.

374{
375 if ((cinfo->global_state == DSTATE_SCANNING ||
376 cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
377 /* Terminate final pass of non-buffered mode */
378 if (cinfo->output_scanline < cinfo->output_height)
379 ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
380 (*cinfo->master->finish_output_pass) (cinfo);
381 cinfo->global_state = DSTATE_STOPPING;
382 } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
383 /* Finishing after a buffered-image operation */
384 cinfo->global_state = DSTATE_STOPPING;
385 } else if (cinfo->global_state != DSTATE_STOPPING) {
386 /* STOPPING = repeat call after a suspension, anything else is error */
387 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
388 }
389 /* Read until EOI */
390 while (! cinfo->inputctl->eoi_reached) {
391 if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
392 return FALSE; /* Suspend, come back later */
393 }
394 /* Do final cleanup */
395 (*cinfo->src->term_source) (cinfo);
396 /* We can use jpeg_abort to release memory and reset global_state */
397 jpeg_abort((j_common_ptr) cinfo);
398 return TRUE;
399}
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
JDIMENSION output_height
Definition: jpeglib.h:508
JDIMENSION output_scanline
Definition: jpeglib.h:537
struct jpeg_decomp_master * master
Definition: jpeglib.h:678

Referenced by main(), and read_JPEG_file().

◆ jpeg_has_multiple_scans()

jpeg_has_multiple_scans ( j_decompress_ptr  cinfo)

Definition at line 353 of file jdapimin.c.

354{
355 /* Only valid after jpeg_read_header completes */
356 if (cinfo->global_state < DSTATE_READY ||
357 cinfo->global_state > DSTATE_STOPPING)
358 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
359 return cinfo->inputctl->has_multiple_scans;
360}

◆ jpeg_input_complete()

jpeg_input_complete ( j_decompress_ptr  cinfo)

Definition at line 338 of file jdapimin.c.

339{
340 /* Check for valid jpeg object */
341 if (cinfo->global_state < DSTATE_START ||
342 cinfo->global_state > DSTATE_STOPPING)
343 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
344 return cinfo->inputctl->eoi_reached;
345}

◆ jpeg_read_header()

jpeg_read_header ( j_decompress_ptr  cinfo,
boolean  require_image 
)

Definition at line 245 of file jdapimin.c.

246{
247 int retcode;
248
249 if (cinfo->global_state != DSTATE_START &&
250 cinfo->global_state != DSTATE_INHEADER)
251 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
252
253 retcode = jpeg_consume_input(cinfo);
254
255 switch (retcode) {
256 case JPEG_REACHED_SOS:
257 retcode = JPEG_HEADER_OK;
258 break;
259 case JPEG_REACHED_EOI:
260 if (require_image) /* Complain if application wanted an image */
261 ERREXIT(cinfo, JERR_NO_IMAGE);
262 /* Reset to start state; it would be safer to require the application to
263 * call jpeg_abort, but we can't change it now for compatibility reasons.
264 * A side effect is to free any temporary memory (there shouldn't be any).
265 */
266 jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
267 retcode = JPEG_HEADER_TABLES_ONLY;
268 break;
269 case JPEG_SUSPENDED:
270 /* no work */
271 break;
272 }
273
274 return retcode;
275}
jpeg_consume_input(j_decompress_ptr cinfo)
Definition: jdapimin.c:291
#define JPEG_HEADER_TABLES_ONLY
Definition: jpeglib.h:1047
boolean require_image
Definition: jpeglib.h:1043
#define JPEG_REACHED_EOI
Definition: jpeglib.h:1077
#define JPEG_HEADER_OK
Definition: jpeglib.h:1046

Referenced by main(), and read_JPEG_file().