COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
jpeglib.h File Reference
#include <vector>
#include <stdint.h>
#include <stdio.h>
#include "jmorecfg.h"
#include "jconfig.h"
Include dependency graph for jpeglib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  JQUANT_TBL
 
struct  JHUFF_TBL
 
struct  jpeg_component_info
 
struct  jpeg_scan_info
 
struct  jpeg_marker_struct
 
struct  jpeg_common_struct
 
struct  jpeg_compress_struct
 
struct  jpeg_decompress_struct
 
struct  jpeg_error_mgr
 
struct  jpeg_progress_mgr
 
struct  jpeg_destination_mgr
 
struct  jpeg_source_mgr
 
struct  jpeg_memory_mgr
 

Macros

#define JPEG_LIB_VERSION   62 /* Version 6b */
 
#define DCTSIZE   8 /* The basic DCT block is 8x8 samples */
 
#define DCTSIZE2   64 /* DCTSIZE squared; # of elements in a block */
 
#define NUM_QUANT_TBLS   4 /* Quantization tables are numbered 0..3 */
 
#define NUM_HUFF_TBLS   4 /* Huffman tables are numbered 0..3 */
 
#define NUM_ARITH_TBLS   16 /* Arith-coding tables are numbered 0..15 */
 
#define MAX_COMPS_IN_SCAN   4 /* JPEG limit on # of components in one scan */
 
#define MAX_SAMP_FACTOR   4 /* JPEG limit on sampling factors */
 
#define C_MAX_BLOCKS_IN_MCU   10 /* compressor's limit on blocks per MCU */
 
#define D_MAX_BLOCKS_IN_MCU   10 /* decompressor's limit on blocks per MCU */
 
#define JDCT_DEFAULT   JDCT_ISLOW
 
#define JDCT_FASTEST   JDCT_IFAST
 
#define jpeg_common_fields
 
#define JMSG_LENGTH_MAX   200 /* recommended size of format_message buffer */
 
#define JMSG_STR_PARM_MAX   80
 
#define JPOOL_PERMANENT   0 /* lasts until master record is destroyed */
 
#define JPOOL_IMAGE   1 /* lasts until done with image/datastream */
 
#define JPOOL_NUMPOOLS   2
 
#define JPP(arglist)   arglist
 
#define jpeg_create_compress(cinfo)
 
#define jpeg_create_decompress(cinfo)
 
#define JPEG_SUSPENDED   0 /* Suspended due to lack of input data */
 
#define JPEG_HEADER_OK   1 /* Found valid image datastream */
 
#define JPEG_HEADER_TABLES_ONLY   2 /* Found valid table-specs-only datastream */
 
#define JPEG_REACHED_SOS   1 /* Reached start of new scan */
 
#define JPEG_REACHED_EOI   2 /* Reached end of image */
 
#define JPEG_ROW_COMPLETED   3 /* Completed one iMCU row */
 
#define JPEG_SCAN_COMPLETED   4 /* Completed last iMCU row of a scan */
 
#define JPEG_RST0   0xD0 /* RST0 marker code */
 
#define JPEG_EOI   0xD9 /* EOI marker code */
 
#define JPEG_APP0   0xE0 /* APP0 marker code */
 
#define JPEG_COM   0xFE /* COM marker code */
 

Typedefs

typedef JSAMPLEJSAMPROW
 
typedef JSAMPROWJSAMPARRAY
 
typedef JSAMPARRAYJSAMPIMAGE
 
typedef JCOEF JBLOCK[64]
 
typedef JBLOCKJBLOCKROW
 
typedef JBLOCKROWJBLOCKARRAY
 
typedef JBLOCKARRAYJBLOCKIMAGE
 
typedef JCOEFJCOEFPTR
 
typedef struct jpeg_marker_structjpeg_saved_marker_ptr
 
typedef struct jpeg_common_structj_common_ptr
 
typedef struct jpeg_compress_structj_compress_ptr
 
typedef struct jpeg_decompress_structj_decompress_ptr
 
typedef struct jvirt_sarray_controljvirt_sarray_ptr
 
typedef struct jvirt_barray_controljvirt_barray_ptr
 
typedef boolean(* jpeg_marker_parser_method) ()
 

Enumerations

enum  J_COLOR_SPACE {
  JCS_UNKNOWN, JCS_GRAYSCALE, JCS_RGB, JCS_YCbCr,
  JCS_CMYK, JCS_YCCK
}
 
enum  J_DCT_METHOD { JDCT_ISLOW, JDCT_IFAST, JDCT_FLOAT }
 
enum  J_DITHER_MODE { JDITHER_NONE, JDITHER_ORDERED, JDITHER_FS }
 

Functions

struct jpeg_error_mgrjpeg_std_error (struct jpeg_error_mgr *err)
 
void jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
 
void jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
 
void jpeg_destroy_compress (j_compress_ptr cinfo)
 
void jpeg_destroy_decompress (j_decompress_ptr cinfo)
 
void jpeg_stdio_dest (j_compress_ptr cinfo, FILE *outfile)
 
void jpeg_stdio_src (j_decompress_ptr cinfo, FILE *infile)
 
void jpeg_set_defaults (j_compress_ptr cinfo)
 
void jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
 
void jpeg_default_colorspace (j_compress_ptr cinfo)
 
void jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
 
void jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, boolean force_baseline)
 
void jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, const unsigned int *basic_table, int scale_factor, boolean force_baseline)
 
int jpeg_quality_scaling (int quality)
 
void jpeg_simple_progression (j_compress_ptr cinfo)
 
void jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
 
JQUANT_TBLjpeg_alloc_quant_table (j_common_ptr cinfo)
 
JHUFF_TBLjpeg_alloc_huff_table (j_common_ptr cinfo)
 
void jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
 
JDIMENSION jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)
 
void jpeg_finish_compress (j_compress_ptr cinfo)
 
JDIMENSION jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data, JDIMENSION num_lines)
 
void jpeg_write_marker (j_compress_ptr cinfo, int marker, const JOCTET *dataptr, unsigned int datalen)
 
void jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
 
void jpeg_write_m_byte (j_compress_ptr cinfo, int val)
 
void jpeg_write_tables (j_compress_ptr cinfo)
 
int jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
 
boolean jpeg_start_decompress (j_decompress_ptr cinfo)
 
JDIMENSION jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)
 
boolean jpeg_finish_decompress (j_decompress_ptr cinfo)
 
JDIMENSION jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data, JDIMENSION max_lines)
 
boolean jpeg_has_multiple_scans (j_decompress_ptr cinfo)
 
boolean jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
 
boolean jpeg_finish_output (j_decompress_ptr cinfo)
 
boolean jpeg_input_complete (j_decompress_ptr cinfo)
 
void jpeg_new_colormap (j_decompress_ptr cinfo)
 
int jpeg_consume_input (j_decompress_ptr cinfo)
 
void jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
 
void jpeg_save_markers (j_decompress_ptr cinfo, int marker_code, unsigned int length_limit)
 
void jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code, jpeg_marker_parser_method routine)
 
jvirt_barray_ptrjpeg_read_coefficients (j_decompress_ptr cinfo)
 
void jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr *coef_arrays)
 
void jpeg_copy_critical_parameters (j_decompress_ptr srcinfo, j_compress_ptr dstinfo)
 
void jpeg_abort_compress (j_compress_ptr cinfo)
 
void jpeg_abort_decompress (j_decompress_ptr cinfo)
 
void jpeg_abort (j_common_ptr cinfo)
 
void jpeg_destroy (j_common_ptr cinfo)
 
boolean jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
 
int read_JPEG_file (const char *filename, vector< vector< uint8_t > > &image_buffer)
 
int read_JPEG_file (const char *filename, JSAMPLE *image_buffer)
 
void write_JPEG_file (const char *filename, int quality, J_COLOR_SPACE in_color_space, int image_width, int image_height, JSAMPLE *image_buffer)
 

Macro Definition Documentation

#define JPEG_LIB_VERSION   62 /* Version 6b */
#define DCTSIZE   8 /* The basic DCT block is 8x8 samples */
#define DCTSIZE2   64 /* DCTSIZE squared; # of elements in a block */
#define NUM_QUANT_TBLS   4 /* Quantization tables are numbered 0..3 */
#define NUM_HUFF_TBLS   4 /* Huffman tables are numbered 0..3 */
#define NUM_ARITH_TBLS   16 /* Arith-coding tables are numbered 0..15 */
#define MAX_COMPS_IN_SCAN   4 /* JPEG limit on # of components in one scan */
#define MAX_SAMP_FACTOR   4 /* JPEG limit on sampling factors */
#define C_MAX_BLOCKS_IN_MCU   10 /* compressor's limit on blocks per MCU */
#define D_MAX_BLOCKS_IN_MCU   10 /* decompressor's limit on blocks per MCU */
#define JDCT_DEFAULT   JDCT_ISLOW
#define JDCT_FASTEST   JDCT_IFAST
#define jpeg_common_fields
Value:
struct jpeg_error_mgr * err; /* Error handler module */\
struct jpeg_memory_mgr * mem; /* Memory manager module */\
struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
void * client_data; /* Available for use by application */\
boolean is_decompressor; /* So common code can tell which is which */\
int global_state /* For checking call sequence validity */
Definition: jpeglib.h:648
int boolean
Definition: jmorecfg.h:227
Definition: jpeglib.h:706
string & err
Definition: json11.cpp:362
Definition: jpeglib.h:761
#define JMSG_LENGTH_MAX   200 /* recommended size of format_message buffer */
#define JMSG_STR_PARM_MAX   80
#define JPOOL_PERMANENT   0 /* lasts until master record is destroyed */
#define JPOOL_IMAGE   1 /* lasts until done with image/datastream */
#define JPOOL_NUMPOOLS   2
#define JPP (   arglist)    arglist
#define jpeg_create_compress (   cinfo)
Value:
(size_t) sizeof(struct jpeg_compress_struct))
#define JPEG_LIB_VERSION
Definition: jpeglib.h:38
Definition: jpeglib.h:273
void jpeg_CreateCompress(j_compress_ptr cinfo, int version, size_t structsize)
Definition: jcapimin.cpp:30
#define jpeg_create_decompress (   cinfo)
Value:
(size_t) sizeof(struct jpeg_decompress_struct))
#define JPEG_LIB_VERSION
Definition: jpeglib.h:38
Definition: jpeglib.h:416
void jpeg_CreateDecompress(j_decompress_ptr cinfo, int version, size_t structsize)
Definition: jdapimin.cpp:30
#define JPEG_SUSPENDED   0 /* Suspended due to lack of input data */
#define JPEG_HEADER_OK   1 /* Found valid image datastream */
#define JPEG_HEADER_TABLES_ONLY   2 /* Found valid table-specs-only datastream */
#define JPEG_REACHED_SOS   1 /* Reached start of new scan */
#define JPEG_REACHED_EOI   2 /* Reached end of image */
#define JPEG_ROW_COMPLETED   3 /* Completed one iMCU row */
#define JPEG_SCAN_COMPLETED   4 /* Completed last iMCU row of a scan */
#define JPEG_RST0   0xD0 /* RST0 marker code */
#define JPEG_EOI   0xD9 /* EOI marker code */
#define JPEG_APP0   0xE0 /* APP0 marker code */
#define JPEG_COM   0xFE /* COM marker code */

Typedef Documentation

typedef JSAMPLE* JSAMPROW
typedef JSAMPROW* JSAMPARRAY
typedef JCOEF JBLOCK[64]
typedef JBLOCK* JBLOCKROW
typedef JCOEF* JCOEFPTR
typedef boolean(* jpeg_marker_parser_method) ()

Enumeration Type Documentation

Enumerator
JCS_UNKNOWN 
JCS_GRAYSCALE 
JCS_RGB 
JCS_YCbCr 
JCS_CMYK 
JCS_YCCK 
211  {
212  JCS_UNKNOWN, /* error/unspecified */
213  JCS_GRAYSCALE, /* monochrome */
214  JCS_RGB, /* red/green/blue */
215  JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
216  JCS_CMYK, /* C/M/Y/K */
217  JCS_YCCK /* Y/Cb/Cr/K */
218 } J_COLOR_SPACE;
Definition: jpeglib.h:217
Definition: jpeglib.h:212
Definition: jpeglib.h:214
Definition: jpeglib.h:213
Definition: jpeglib.h:215
J_COLOR_SPACE
Definition: jpeglib.h:211
Definition: jpeglib.h:216
Enumerator
JDCT_ISLOW 
JDCT_IFAST 
JDCT_FLOAT 
222  {
223  JDCT_ISLOW, /* slow but accurate integer algorithm */
224  JDCT_IFAST, /* faster, less accurate integer method */
225  JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
226 } J_DCT_METHOD;
J_DCT_METHOD
Definition: jpeglib.h:222
Definition: jpeglib.h:224
Definition: jpeglib.h:225
Definition: jpeglib.h:223
Enumerator
JDITHER_NONE 
JDITHER_ORDERED 
JDITHER_FS 
237  {
238  JDITHER_NONE, /* no dithering */
239  JDITHER_ORDERED, /* simple ordered dither */
240  JDITHER_FS /* Floyd-Steinberg error diffusion dither */
241 } J_DITHER_MODE;
J_DITHER_MODE
Definition: jpeglib.h:237
Definition: jpeglib.h:238
Definition: jpeglib.h:240
Definition: jpeglib.h:239

Function Documentation

struct jpeg_error_mgr* jpeg_std_error ( struct jpeg_error_mgr err)
233 {
234  err->error_exit = error_exit;
235  err->emit_message = emit_message;
239 
240  err->trace_level = 0; /* default = no tracing */
241  err->num_warnings = 0; /* no warnings emitted yet */
242  err->msg_code = 0; /* may be useful as a flag for "no error" */
243 
244  /* Initialize message table pointers */
246  err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
247 
248  err->addon_message_table = NULL;
249  err->first_addon_message = 0; /* for safety */
250  err->last_addon_message = 0;
251 
252  return err;
253 }
static void emit_message(j_common_ptr cinfo, int msg_level)
Definition: jerror.cpp:129
long num_warnings
Definition: jpeglib.h:681
int last_jpeg_message
Definition: jpeglib.h:694
int last_addon_message
Definition: jpeglib.h:700
static void format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.cpp:158
Definition: jerror.h:188
const char *const * addon_message_table
Definition: jpeglib.h:698
const char *const jpeg_std_message_table[]
Definition: jerror.cpp:51
void(* format_message)()
Definition: jpeglib.h:656
void(* output_message)()
Definition: jpeglib.h:654
int msg_code
Definition: jpeglib.h:664
int trace_level
Definition: jpeglib.h:673
int first_addon_message
Definition: jpeglib.h:699
void(* reset_error_mgr)()
Definition: jpeglib.h:659
string & err
Definition: json11.cpp:362
static void reset_error_mgr(j_common_ptr cinfo)
Definition: jerror.cpp:213
static void output_message(j_common_ptr cinfo)
Definition: jerror.cpp:99
void(* emit_message)()
Definition: jpeglib.h:652
const char *const * jpeg_message_table
Definition: jpeglib.h:693
void(* error_exit)()
Definition: jpeglib.h:650
static void error_exit(j_common_ptr cinfo)
Definition: jerror.cpp:71
void jpeg_CreateCompress ( j_compress_ptr  cinfo,
int  version,
size_t  structsize 
)
31 {
32  int i;
33 
34  /* Guard against version mismatches between library and caller. */
35  cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
36  if (version != JPEG_LIB_VERSION)
38  if (structsize != SIZEOF(struct jpeg_compress_struct))
40  (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
41 
42  /* For debugging purposes, we zero the whole master structure.
43  * But the application has already set the err pointer, and may have set
44  * client_data, so we have to save and restore those fields.
45  * Note: if application hasn't set client_data, tools like Purify may
46  * complain here.
47  */
48  {
49  struct jpeg_error_mgr * err = cinfo->err;
50  void * client_data = cinfo->client_data; /* ignore Purify complaint here */
51  MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
52  cinfo->err = err;
53  cinfo->client_data = client_data;
54  }
55  cinfo->is_decompressor = FALSE;
56 
57  /* Initialize a memory manager instance for this object */
59 
60  /* Zero out pointers to permanent structures. */
61  cinfo->progress = NULL;
62  cinfo->dest = NULL;
63 
64  cinfo->comp_info = NULL;
65 
66  for (i = 0; i < NUM_QUANT_TBLS; i++)
67  cinfo->quant_tbl_ptrs[i] = NULL;
68 
69  for (i = 0; i < NUM_HUFF_TBLS; i++) {
70  cinfo->dc_huff_tbl_ptrs[i] = NULL;
71  cinfo->ac_huff_tbl_ptrs[i] = NULL;
72  }
73 
74  cinfo->script_space = NULL;
75 
76  cinfo->input_gamma = 1.0; /* in case application forgets */
77 
78  /* OK, I'm ready */
79  cinfo->global_state = CSTATE_START;
80 }
#define CSTATE_START
Definition: jpegint.h:25
#define NUM_QUANT_TBLS
Definition: jpeglib.h:48
int i
Definition: rw_test.cpp:37
Definition: jerror.h:55
JQUANT_TBL * quant_tbl_ptrs[4]
Definition: jpeglib.h:307
#define NUM_HUFF_TBLS
Definition: jpeglib.h:49
Definition: jpeglib.h:648
Definition: jpeglib.h:258
#define SIZEOF(object)
Definition: jinclude.h:80
struct jpeg_progress_mgr * progress
Definition: jpeglib.h:274
double input_gamma
Definition: jpeglib.h:289
#define FALSE
Definition: jpleph.cpp:69
void * client_data
Definition: jpeglib.h:274
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:274
#define JPEG_LIB_VERSION
Definition: jpeglib.h:38
struct jpeg_error_mgr * err
Definition: jpeglib.h:274
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:277
string & err
Definition: json11.cpp:362
Definition: jerror.h:67
Definition: jpeglib.h:273
boolean is_decompressor
Definition: jpeglib.h:274
void jinit_memory_mgr(j_common_ptr cinfo)
Definition: jmemmgr.cpp:1028
int global_state
Definition: jpeglib.h:274
JHUFF_TBL * ac_huff_tbl_ptrs[4]
Definition: jpeglib.h:311
JHUFF_TBL * dc_huff_tbl_ptrs[4]
Definition: jpeglib.h:310
jpeg_scan_info * script_space
Definition: jpeglib.h:409
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:212
jpeg_component_info * comp_info
Definition: jpeglib.h:304
#define MEMZERO(target, size)
Definition: jinclude.h:67
void jpeg_CreateDecompress ( j_decompress_ptr  cinfo,
int  version,
size_t  structsize 
)
31 {
32  int i;
33 
34  /* Guard against version mismatches between library and caller. */
35  cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
36  if (version != JPEG_LIB_VERSION)
38  if (structsize != SIZEOF(struct jpeg_decompress_struct))
40  (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
41 
42  /* For debugging purposes, we zero the whole master structure.
43  * But the application has already set the err pointer, and may have set
44  * client_data, so we have to save and restore those fields.
45  * Note: if application hasn't set client_data, tools like Purify may
46  * complain here.
47  */
48  {
49  struct jpeg_error_mgr * err = cinfo->err;
50  void * client_data = cinfo->client_data; /* ignore Purify complaint here */
51  MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
52  cinfo->err = err;
53  cinfo->client_data = client_data;
54  }
55  cinfo->is_decompressor = TRUE;
56 
57  /* Initialize a memory manager instance for this object */
59 
60  /* Zero out pointers to permanent structures. */
61  cinfo->progress = NULL;
62  cinfo->src = NULL;
63 
64  for (i = 0; i < NUM_QUANT_TBLS; i++)
65  cinfo->quant_tbl_ptrs[i] = NULL;
66 
67  for (i = 0; i < NUM_HUFF_TBLS; i++) {
68  cinfo->dc_huff_tbl_ptrs[i] = NULL;
69  cinfo->ac_huff_tbl_ptrs[i] = NULL;
70  }
71 
72  /* Initialize marker processor so application can override methods
73  * for COM, APPn markers before calling jpeg_read_header.
74  */
75  cinfo->marker_list = NULL;
76  jinit_marker_reader(cinfo);
77 
78  /* And initialize the overall input controller. */
80 
81  /* OK, I'm ready */
82  cinfo->global_state = DSTATE_START;
83 }
void jinit_input_controller(j_decompress_ptr cinfo)
Definition: jdinput.cpp:361
#define NUM_QUANT_TBLS
Definition: jpeglib.h:48
int i
Definition: rw_test.cpp:37
Definition: jerror.h:55
JHUFF_TBL * dc_huff_tbl_ptrs[4]
Definition: jpeglib.h:530
struct jpeg_progress_mgr * progress
Definition: jpeglib.h:417
#define NUM_HUFF_TBLS
Definition: jpeglib.h:49
Definition: jpeglib.h:648
struct jpeg_error_mgr * err
Definition: jpeglib.h:417
Definition: jpeglib.h:258
#define SIZEOF(object)
Definition: jinclude.h:80
void jinit_marker_reader(j_decompress_ptr cinfo)
Definition: jdmarker.cpp:1262
JHUFF_TBL * ac_huff_tbl_ptrs[4]
Definition: jpeglib.h:531
jpeg_saved_marker_ptr marker_list
Definition: jpeglib.h:571
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
#define JPEG_LIB_VERSION
Definition: jpeglib.h:38
#define DSTATE_START
Definition: jpegint.h:29
#define TRUE
Definition: jpleph.cpp:68
string & err
Definition: json11.cpp:362
Definition: jerror.h:67
void jinit_memory_mgr(j_common_ptr cinfo)
Definition: jmemmgr.cpp:1028
struct jpeg_source_mgr * src
Definition: jpeglib.h:420
JQUANT_TBL * quant_tbl_ptrs[4]
Definition: jpeglib.h:527
Definition: jpeglib.h:416
int global_state
Definition: jpeglib.h:417
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:212
void * client_data
Definition: jpeglib.h:417
#define MEMZERO(target, size)
Definition: jinclude.h:67
boolean is_decompressor
Definition: jpeglib.h:417
void jpeg_destroy_compress ( j_compress_ptr  cinfo)
89 {
90  jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
91 }
void jpeg_destroy(j_common_ptr cinfo)
Definition: jcomapi.cpp:69
Definition: jpeglib.h:258
void jpeg_destroy_decompress ( j_decompress_ptr  cinfo)
92 {
93  jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
94 }
void jpeg_destroy(j_common_ptr cinfo)
Definition: jcomapi.cpp:69
Definition: jpeglib.h:258
void jpeg_stdio_dest ( j_compress_ptr  cinfo,
FILE *  outfile 
)
131 {
132  my_dest_ptr dest;
133 
134  /* The destination object is made permanent so that multiple JPEG images
135  * can be written to the same file without re-executing jpeg_stdio_dest.
136  * This makes it dangerous to use this manager and a different destination
137  * manager serially with the same JPEG object, because their private object
138  * sizes may be different. Caveat programmer.
139  */
140  if (cinfo->dest == NULL) { /* first time for this JPEG object? */
141  cinfo->dest = (struct jpeg_destination_mgr *)
142  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
144  }
145 
146  dest = (my_dest_ptr) cinfo->dest;
150  dest->outfile = outfile;
151 }
static void term_destination(j_compress_ptr cinfo)
Definition: jdatadst.cpp:106
Definition: jdatadst.cpp:25
FILE * outfile
Definition: jdatadst.cpp:28
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
void *(* alloc_small)()
Definition: jpeglib.h:764
#define SIZEOF(object)
Definition: jinclude.h:80
struct jpeg_destination_mgr pub
Definition: jdatadst.cpp:26
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:274
void(* init_destination)()
Definition: jpeglib.h:722
my_destination_mgr * my_dest_ptr
Definition: jdatadst.cpp:32
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:277
Definition: jpeglib.h:718
boolean(* empty_output_buffer)()
Definition: jpeglib.h:723
static boolean empty_output_buffer(j_compress_ptr cinfo)
Definition: jdatadst.cpp:81
static void init_destination(j_compress_ptr cinfo)
Definition: jdatadst.cpp:43
#define JPOOL_PERMANENT
Definition: jpeglib.h:753
void(* term_destination)()
Definition: jpeglib.h:724
void jpeg_stdio_src ( j_decompress_ptr  cinfo,
FILE *  infile 
)
183 {
184  my_src_ptr src;
185 
186  /* The source object and input buffer are made permanent so that a series
187  * of JPEG images can be read from the same file by calling jpeg_stdio_src
188  * only before the first one. (If we discarded the buffer at the end of
189  * one image, we'd likely lose the start of the next one.)
190  * This makes it unsafe to use this manager and a different source
191  * manager serially with the same JPEG object. Caveat programmer.
192  */
193  if (cinfo->src == NULL) { /* first time for this JPEG object? */
194  cinfo->src = (struct jpeg_source_mgr *)
195  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
197  src = (my_src_ptr) cinfo->src;
198  src->buffer = (JOCTET *)
199  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
201  }
202 
203  src = (my_src_ptr) cinfo->src;
204  src->pub.init_source = init_source;
207  src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
208  src->pub.term_source = term_source;
209  src->infile = infile;
210  src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
211  src->pub.next_input_byte = NULL; /* until buffer loaded */
212 }
boolean(* fill_input_buffer)()
Definition: jpeglib.h:735
my_source_mgr * my_src_ptr
Definition: jdatasrc.cpp:33
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
boolean jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired)
Definition: jdmarker.cpp:1192
void(* skip_input_data)()
Definition: jpeglib.h:736
void *(* alloc_small)()
Definition: jpeglib.h:764
JOCTET * buffer
Definition: jdatasrc.cpp:29
boolean(* resync_to_restart)()
Definition: jpeglib.h:737
Definition: jpeglib.h:258
void(* term_source)()
Definition: jpeglib.h:738
#define SIZEOF(object)
Definition: jinclude.h:80
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
static void skip_input_data(j_decompress_ptr cinfo, long num_bytes)
Definition: jdatasrc.cpp:128
FILE * infile
Definition: jdatasrc.cpp:28
static void init_source(j_decompress_ptr cinfo)
Definition: jdatasrc.cpp:44
size_t bytes_in_buffer
Definition: jpeglib.h:732
Definition: jpeglib.h:730
struct jpeg_source_mgr * src
Definition: jpeglib.h:420
static boolean fill_input_buffer(j_decompress_ptr cinfo)
Definition: jdatasrc.cpp:90
Definition: jdatasrc.cpp:25
static void term_source(j_decompress_ptr cinfo)
Definition: jdatasrc.cpp:169
struct jpeg_source_mgr pub
Definition: jdatasrc.cpp:26
#define JPOOL_PERMANENT
Definition: jpeglib.h:753
char JOCTET
Definition: jmorecfg.h:115
void(* init_source)()
Definition: jpeglib.h:734
const JOCTET * next_input_byte
Definition: jpeglib.h:731
#define INPUT_BUF_SIZE
Definition: jdatasrc.cpp:35
void jpeg_set_defaults ( j_compress_ptr  cinfo)
269 {
270  int i;
271 
272  /* Safety check to ensure start_compress not called yet. */
273  if (cinfo->global_state != CSTATE_START)
274  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
275 
276  /* Allocate comp_info array large enough for maximum component count.
277  * Array is made permanent in case application wants to compress
278  * multiple images at same param settings.
279  */
280  if (cinfo->comp_info == NULL)
281  cinfo->comp_info = (jpeg_component_info *)
282  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
284 
285  /* Initialize everything not dependent on the color space */
286 
288  /* Set up two quantization tables using default quality of 75 */
289  jpeg_set_quality(cinfo, 75, TRUE);
290  /* Set up two Huffman tables */
291  std_huff_tables(cinfo);
292 
293  /* Initialize default arithmetic coding conditioning */
294  for (i = 0; i < NUM_ARITH_TBLS; i++) {
295  cinfo->arith_dc_L[i] = 0;
296  cinfo->arith_dc_U[i] = 1;
297  cinfo->arith_ac_K[i] = 5;
298  }
299 
300  /* Default is no multiple-scan output */
301  cinfo->scan_info = NULL;
302  cinfo->num_scans = 0;
303 
304  /* Expect normal source image, not raw downsampled data */
305  cinfo->raw_data_in = FALSE;
306 
307  /* Use Huffman coding, not arithmetic coding, by default */
308  cinfo->arith_code = FALSE;
309 
310  /* By default, don't do extra passes to optimize entropy coding */
311  cinfo->optimize_coding = FALSE;
312  /* The standard Huffman tables are only valid for 8-bit data precision.
313  * If the precision is higher, force optimization on so that usable
314  * tables will be computed. This test can be removed if default tables
315  * are supplied that are valid for the desired precision.
316  */
317  if (cinfo->data_precision > 8)
318  cinfo->optimize_coding = TRUE;
319 
320  /* By default, use the simpler non-cosited sampling alignment */
321  cinfo->CCIR601_sampling = FALSE;
322 
323  /* No input smoothing */
324  cinfo->smoothing_factor = 0;
325 
326  /* DCT algorithm preference */
327  cinfo->dct_method = JDCT_DEFAULT;
328 
329  /* No restart markers */
330  cinfo->restart_interval = 0;
331  cinfo->restart_in_rows = 0;
332 
333  /* Fill in default JFIF marker parameters. Note that whether the marker
334  * will actually be written is determined by jpeg_set_colorspace.
335  *
336  * By default, the library emits JFIF version code 1.01.
337  * An application that wants to emit JFIF 1.02 extension markers should set
338  * JFIF_minor_version to 2. We could probably get away with just defaulting
339  * to 1.02, but there may still be some decoders in use that will complain
340  * about that; saying 1.01 should minimize compatibility problems.
341  */
342  cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
343  cinfo->JFIF_minor_version = 1;
344  cinfo->density_unit = 0; /* Pixel size is unknown by default */
345  cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
346  cinfo->Y_density = 1;
347 
348  /* Choose JPEG colorspace based on input space, set defaults accordingly */
349 
351 }
#define BITS_IN_JSAMPLE
Definition: jmorecfg.h:23
#define CSTATE_START
Definition: jpegint.h:25
static void std_huff_tables(j_compress_ptr cinfo)
Definition: jcparam.cpp:182
int i
Definition: rw_test.cpp:37
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
const jpeg_scan_info * scan_info
Definition: jpeglib.h:319
void *(* alloc_small)()
Definition: jpeglib.h:764
#define MAX_COMPONENTS
Definition: jmorecfg.h:35
#define JDCT_DEFAULT
Definition: jpeglib.h:229
Definition: jerror.h:65
#define SIZEOF(object)
Definition: jinclude.h:80
int data_precision
Definition: jpeglib.h:299
#define FALSE
Definition: jpleph.cpp:69
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:274
uint8_t arith_ac_K[16]
Definition: jpeglib.h:316
int num_scans
Definition: jpeglib.h:318
uint8_t density_unit
Definition: jpeglib.h:349
void jpeg_default_colorspace(j_compress_ptr cinfo)
Definition: jcparam.cpp:359
#define TRUE
Definition: jpleph.cpp:68
int smoothing_factor
Definition: jpeglib.h:329
unsigned int restart_interval
Definition: jpeglib.h:337
int restart_in_rows
Definition: jpeglib.h:338
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
boolean arith_code
Definition: jpeglib.h:326
void jpeg_set_quality(j_compress_ptr cinfo, int quality, boolean force_baseline)
Definition: jcparam.cpp:132
int global_state
Definition: jpeglib.h:274
Definition: jpeglib.h:121
uint8_t arith_dc_L[16]
Definition: jpeglib.h:314
uint16_t X_density
Definition: jpeglib.h:350
boolean CCIR601_sampling
Definition: jpeglib.h:328
J_DCT_METHOD dct_method
Definition: jpeglib.h:330
boolean optimize_coding
Definition: jpeglib.h:327
uint8_t JFIF_minor_version
Definition: jpeglib.h:344
#define NUM_ARITH_TBLS
Definition: jpeglib.h:50
#define JPOOL_PERMANENT
Definition: jpeglib.h:753
uint8_t JFIF_major_version
Definition: jpeglib.h:343
uint16_t Y_density
Definition: jpeglib.h:351
boolean raw_data_in
Definition: jpeglib.h:325
uint8_t arith_dc_U[16]
Definition: jpeglib.h:315
jpeg_component_info * comp_info
Definition: jpeglib.h:304
void jpeg_set_colorspace ( j_compress_ptr  cinfo,
J_COLOR_SPACE  colorspace 
)
392 {
394  int ci;
395 
396 #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
397  (compptr = &cinfo->comp_info[index], \
398  compptr->component_id = (id), \
399  compptr->h_samp_factor = (hsamp), \
400  compptr->v_samp_factor = (vsamp), \
401  compptr->quant_tbl_no = (quant), \
402  compptr->dc_tbl_no = (dctbl), \
403  compptr->ac_tbl_no = (actbl) )
404 
405  /* Safety check to ensure start_compress not called yet. */
406  if (cinfo->global_state != CSTATE_START)
407  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
408 
409  /* For all colorspaces, we use Q and Huff tables 0 for luminance components,
410  * tables 1 for chrominance components.
411  */
412 
413  cinfo->jpeg_color_space = colorspace;
414 
415  cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
416  cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
417 
418  switch (colorspace) {
419  case JCS_GRAYSCALE:
420  cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
421  cinfo->num_components = 1;
422  /* JFIF specifies component ID 1 */
423  SET_COMP(0, 1, 1,1, 0, 0,0);
424  break;
425  case JCS_RGB:
426  cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
427  cinfo->num_components = 3;
428  SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
429  SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
430  SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
431  break;
432  case JCS_YCbCr:
433  cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
434  cinfo->num_components = 3;
435  /* JFIF specifies component IDs 1,2,3 */
436  /* We default to 2x2 subsamples of chrominance */
437  SET_COMP(0, 1, 2,2, 0, 0,0);
438  SET_COMP(1, 2, 1,1, 1, 1,1);
439  SET_COMP(2, 3, 1,1, 1, 1,1);
440  break;
441  case JCS_CMYK:
442  cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
443  cinfo->num_components = 4;
444  SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
445  SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
446  SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
447  SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
448  break;
449  case JCS_YCCK:
450  cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
451  cinfo->num_components = 4;
452  SET_COMP(0, 1, 2,2, 0, 0,0);
453  SET_COMP(1, 2, 1,1, 1, 1,1);
454  SET_COMP(2, 3, 1,1, 1, 1,1);
455  SET_COMP(3, 4, 2,2, 0, 0,0);
456  break;
457  case JCS_UNKNOWN:
458  cinfo->num_components = cinfo->input_components;
459  if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
462  for (ci = 0; ci < cinfo->num_components; ci++) {
463  SET_COMP(ci, ci, 1,1, 0, 0,0);
464  }
465  break;
466  default:
468  }
469 }
boolean write_Adobe_marker
Definition: jpeglib.h:352
Definition: jpeglib.h:217
#define CSTATE_START
Definition: jpegint.h:25
#define SET_COMP(index, id, hsamp, vsamp, quant, dctbl, actbl)
J_COLOR_SPACE jpeg_color_space
Definition: jpeglib.h:302
Definition: jpeglib.h:212
#define MAX_COMPONENTS
Definition: jmorecfg.h:35
int num_components
Definition: jpeglib.h:301
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jerror.h:65
Definition: jerror.h:72
boolean write_JFIF_header
Definition: jpeglib.h:342
Definition: jerror.h:52
jpeg_component_info * compptr
Definition: jdct.h:102
#define FALSE
Definition: jpleph.cpp:69
Definition: jpeglib.h:214
Definition: jpeglib.h:213
#define TRUE
Definition: jpleph.cpp:68
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:274
Definition: jpeglib.h:121
Definition: jpeglib.h:215
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:212
Definition: jpeglib.h:216
int input_components
Definition: jpeglib.h:286
void jpeg_default_colorspace ( j_compress_ptr  cinfo)
360 {
361  switch (cinfo->in_color_space) {
362  case JCS_GRAYSCALE:
364  break;
365  case JCS_RGB:
367  break;
368  case JCS_YCbCr:
370  break;
371  case JCS_CMYK:
372  jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
373  break;
374  case JCS_YCCK:
376  break;
377  case JCS_UNKNOWN:
379  break;
380  default:
382  }
383 }
Definition: jpeglib.h:217
Definition: jpeglib.h:212
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
J_COLOR_SPACE in_color_space
Definition: jpeglib.h:287
Definition: jpeglib.h:214
Definition: jpeglib.h:213
void jpeg_set_colorspace(j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
Definition: jcparam.cpp:391
Definition: jerror.h:51
Definition: jpeglib.h:215
Definition: jpeglib.h:216
void jpeg_set_quality ( j_compress_ptr  cinfo,
int  quality,
boolean  force_baseline 
)
138 {
139  /* Convert user 0-100 rating to percentage scaling */
140  quality = jpeg_quality_scaling(quality);
141 
142  /* Set up standard quality tables */
143  jpeg_set_linear_quality(cinfo, quality, force_baseline);
144 }
void jpeg_set_linear_quality(j_compress_ptr cinfo, int scale_factor, boolean force_baseline)
Definition: jcparam.cpp:64
int jpeg_quality_scaling(int quality)
Definition: jcparam.cpp:106
void jpeg_set_linear_quality ( j_compress_ptr  cinfo,
int  scale_factor,
boolean  force_baseline 
)
71 {
72  /* These are the sample quantization tables given in JPEG spec section K.1.
73  * The spec says that the values given produce "good" quality, and
74  * when divided by 2, "very good" quality.
75  */
76  static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
77  16, 11, 10, 16, 24, 40, 51, 61,
78  12, 12, 14, 19, 26, 58, 60, 55,
79  14, 13, 16, 24, 40, 57, 69, 56,
80  14, 17, 22, 29, 51, 87, 80, 62,
81  18, 22, 37, 56, 68, 109, 103, 77,
82  24, 35, 55, 64, 81, 104, 113, 92,
83  49, 64, 78, 87, 103, 121, 120, 101,
84  72, 92, 95, 98, 112, 100, 103, 99
85  };
86  static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
87  17, 18, 24, 47, 99, 99, 99, 99,
88  18, 21, 26, 66, 99, 99, 99, 99,
89  24, 26, 56, 99, 99, 99, 99, 99,
90  47, 66, 99, 99, 99, 99, 99, 99,
91  99, 99, 99, 99, 99, 99, 99, 99,
92  99, 99, 99, 99, 99, 99, 99, 99,
93  99, 99, 99, 99, 99, 99, 99, 99,
94  99, 99, 99, 99, 99, 99, 99, 99
95  };
96 
97  /* Set up two quantization tables using the specified scaling */
98  jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
99  scale_factor, force_baseline);
100  jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
101  scale_factor, force_baseline);
102 }
#define DCTSIZE2
Definition: jpeglib.h:47
void jpeg_add_quant_table(j_compress_ptr cinfo, int which_tbl, const unsigned int *basic_table, int scale_factor, boolean force_baseline)
Definition: jcparam.cpp:23
void jpeg_add_quant_table ( j_compress_ptr  cinfo,
int  which_tbl,
const unsigned int *  basic_table,
int  scale_factor,
boolean  force_baseline 
)
31 {
32  JQUANT_TBL ** qtblptr;
33  int i;
34  long temp;
35 
36  /* Safety check to ensure start_compress not called yet. */
37  if (cinfo->global_state != CSTATE_START)
38  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
39 
40  if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
41  ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
42 
43  qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
44 
45  if (*qtblptr == NULL)
46  *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
47 
48  for (i = 0; i < DCTSIZE2; i++) {
49  temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
50  /* limit the values to the valid range */
51  if (temp <= 0L) temp = 1L;
52  if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
53  if (force_baseline && temp > 255L)
54  temp = 255L; /* limit to baseline range if requested */
55  (*qtblptr)->quantval[i] = (uint16_t) temp;
56  }
57 
58  /* Initialize sent_table FALSE so table will be written to JPEG file. */
59  (*qtblptr)->sent_table = FALSE;
60 }
#define CSTATE_START
Definition: jpegint.h:25
#define NUM_QUANT_TBLS
Definition: jpeglib.h:48
JQUANT_TBL * jpeg_alloc_quant_table(j_common_ptr cinfo)
Definition: jcomapi.cpp:86
int i
Definition: rw_test.cpp:37
JQUANT_TBL * quant_tbl_ptrs[4]
Definition: jpeglib.h:307
Definition: jpeglib.h:88
Definition: jpeglib.h:258
Definition: jerror.h:65
#define FALSE
Definition: jpleph.cpp:69
#define DCTSIZE2
Definition: jpeglib.h:47
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:274
Definition: jerror.h:77
int jpeg_quality_scaling ( int  quality)
111 {
112  /* Safety limit on quality factor. Convert 0 to 1 to avoid zero divide. */
113  if (quality <= 0) quality = 1;
114  if (quality > 100) quality = 100;
115 
116  /* The basic table is used as-is (scaling 100) for a quality of 50.
117  * Qualities 50..100 are converted to scaling percentage 200 - 2*Q;
118  * note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table
119  * to make all the table entries 1 (hence, minimum quantization loss).
120  * Qualities 1..50 are converted to scaling percentage 5000/Q.
121  */
122  if (quality < 50)
123  quality = 5000 / quality;
124  else
125  quality = 200 - quality*2;
126 
127  return quality;
128 }
void jpeg_simple_progression ( j_compress_ptr  cinfo)
538 {
539  int ncomps = cinfo->num_components;
540  int nscans;
541  jpeg_scan_info * scanptr;
542 
543  /* Safety check to ensure start_compress not called yet. */
544  if (cinfo->global_state != CSTATE_START)
545  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
546 
547  /* Figure space needed for script. Calculation must match code below! */
548  if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
549  /* Custom script for YCbCr color images. */
550  nscans = 10;
551  } else {
552  /* All-purpose script for other color spaces. */
553  if (ncomps > MAX_COMPS_IN_SCAN)
554  nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
555  else
556  nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
557  }
558 
559  /* Allocate space for script.
560  * We need to put it in the permanent pool in case the application performs
561  * multiple compressions without changing the settings. To avoid a memory
562  * leak if jpeg_simple_progression is called repeatedly for the same JPEG
563  * object, we try to re-use previously allocated space, and we allocate
564  * enough space to handle YCbCr even if initially asked for grayscale.
565  */
566  if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
567  cinfo->script_space_size = MAX(nscans, 10);
568  cinfo->script_space = (jpeg_scan_info *)
569  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
571  }
572  scanptr = cinfo->script_space;
573  cinfo->scan_info = scanptr;
574  cinfo->num_scans = nscans;
575 
576  if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
577  /* Custom script for YCbCr color images. */
578  /* Initial DC scan */
579  scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
580  /* Initial AC scan: get some luma data out in a hurry */
581  scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
582  /* Chroma data is too small to be worth expending many scans on */
583  scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
584  scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
585  /* Complete spectral selection for luma AC */
586  scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
587  /* Refine next bit of luma AC */
588  scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
589  /* Finish DC successive approximation */
590  scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
591  /* Finish AC successive approximation */
592  scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
593  scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
594  /* Luma bottom bit comes last since it's usually largest scan */
595  scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
596  } else {
597  /* All-purpose script for other color spaces. */
598  /* Successive approximation first pass */
599  scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
600  scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
601  scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
602  /* Successive approximation second pass */
603  scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
604  /* Successive approximation final pass */
605  scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
606  scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
607  }
608 }
#define CSTATE_START
Definition: jpegint.h:25
J_COLOR_SPACE jpeg_color_space
Definition: jpeglib.h:302
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
const jpeg_scan_info * scan_info
Definition: jpeglib.h:319
void *(* alloc_small)()
Definition: jpeglib.h:764
int num_components
Definition: jpeglib.h:301
Definition: jerror.h:65
#define SIZEOF(object)
Definition: jinclude.h:80
static jpeg_scan_info * fill_scans(jpeg_scan_info *scanptr, int ncomps, int Ss, int Se, int Ah, int Al)
Definition: jcparam.cpp:490
static jpeg_scan_info * fill_a_scan(jpeg_scan_info *scanptr, int ci, int Ss, int Se, int Ah, int Al)
Definition: jcparam.cpp:475
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:274
#define MAX(a, b)
Definition: jpegint.h:267
int num_scans
Definition: jpeglib.h:318
int script_space_size
Definition: jpeglib.h:410
static jpeg_scan_info * fill_dc_scans(jpeg_scan_info *scanptr, int ncomps, int Ah, int Al)
Definition: jcparam.cpp:509
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:274
Definition: jpeglib.h:215
#define JPOOL_PERMANENT
Definition: jpeglib.h:753
jpeg_scan_info * script_space
Definition: jpeglib.h:409
#define MAX_COMPS_IN_SCAN
Definition: jpeglib.h:51
Definition: jpeglib.h:189
void jpeg_suppress_tables ( j_compress_ptr  cinfo,
boolean  suppress 
)
120 {
121  int i;
122  JQUANT_TBL * qtbl;
123  JHUFF_TBL * htbl;
124 
125  for (i = 0; i < NUM_QUANT_TBLS; i++) {
126  if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
127  qtbl->sent_table = suppress;
128  }
129 
130  for (i = 0; i < NUM_HUFF_TBLS; i++) {
131  if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
132  htbl->sent_table = suppress;
133  if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
134  htbl->sent_table = suppress;
135  }
136 }
#define NUM_QUANT_TBLS
Definition: jpeglib.h:48
int i
Definition: rw_test.cpp:37
JQUANT_TBL * quant_tbl_ptrs[4]
Definition: jpeglib.h:307
#define NUM_HUFF_TBLS
Definition: jpeglib.h:49
boolean sent_table
Definition: jpeglib.h:99
Definition: jpeglib.h:88
boolean sent_table
Definition: jpeglib.h:115
JHUFF_TBL * ac_huff_tbl_ptrs[4]
Definition: jpeglib.h:311
JHUFF_TBL * dc_huff_tbl_ptrs[4]
Definition: jpeglib.h:310
JHUFF_TBL * htbl
Definition: jchuff.h:47
Definition: jpeglib.h:105
JQUANT_TBL* jpeg_alloc_quant_table ( j_common_ptr  cinfo)
87 {
88  JQUANT_TBL *tbl;
89 
90  tbl = (JQUANT_TBL *)
91  (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
92  tbl->sent_table = FALSE; /* make sure this is false in any new table */
93  return tbl;
94 }
void *(* alloc_small)()
Definition: jpeglib.h:764
boolean sent_table
Definition: jpeglib.h:99
Definition: jpeglib.h:88
#define SIZEOF(object)
Definition: jinclude.h:80
#define FALSE
Definition: jpleph.cpp:69
#define JPOOL_PERMANENT
Definition: jpeglib.h:753
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:259
JHUFF_TBL* jpeg_alloc_huff_table ( j_common_ptr  cinfo)
99 {
100  JHUFF_TBL *tbl;
101 
102  tbl = (JHUFF_TBL *)
103  (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
104  tbl->sent_table = FALSE; /* make sure this is false in any new table */
105  return tbl;
106 }
void *(* alloc_small)()
Definition: jpeglib.h:764
#define SIZEOF(object)
Definition: jinclude.h:80
#define FALSE
Definition: jpleph.cpp:69
boolean sent_table
Definition: jpeglib.h:115
#define JPOOL_PERMANENT
Definition: jpeglib.h:753
Definition: jpeglib.h:105
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:259
void jpeg_start_compress ( j_compress_ptr  cinfo,
boolean  write_all_tables 
)
39 {
40  if (cinfo->global_state != CSTATE_START)
41  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
42 
43  if (write_all_tables)
44  jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
45 
46  /* (Re)initialize error mgr and destination modules */
47  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
48  (*cinfo->dest->init_destination) (cinfo);
49  /* Perform master selection of active modules */
50  jinit_compress_master(cinfo);
51  /* Set up for the first pass */
52  (*cinfo->master->prepare_for_pass) (cinfo);
53  /* Ready for application to drive first pass through jpeg_write_scanlines
54  * or jpeg_write_raw_data.
55  */
56  cinfo->next_scanline = 0;
58 }
#define CSTATE_START
Definition: jpegint.h:25
Definition: jpeglib.h:258
Definition: jerror.h:65
#define CSTATE_RAW_OK
Definition: jpegint.h:27
#define CSTATE_SCANNING
Definition: jpegint.h:26
JDIMENSION next_scanline
Definition: jpeglib.h:359
#define FALSE
Definition: jpleph.cpp:69
struct jpeg_error_mgr * err
Definition: jpeglib.h:274
void(* init_destination)()
Definition: jpeglib.h:722
void jinit_compress_master(j_compress_ptr cinfo)
Definition: jcinit.cpp:30
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:277
void(* reset_error_mgr)()
Definition: jpeglib.h:659
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
void jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress)
Definition: jcapimin.cpp:119
int global_state
Definition: jpeglib.h:274
boolean raw_data_in
Definition: jpeglib.h:325
struct jpeg_comp_master * master
Definition: jpeglib.h:400
JDIMENSION jpeg_write_scanlines ( j_compress_ptr  cinfo,
JSAMPARRAY  scanlines,
JDIMENSION  num_lines 
)
79 {
80  JDIMENSION row_ctr, rows_left;
81 
82  if (cinfo->global_state != CSTATE_SCANNING)
83  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
84  if (cinfo->next_scanline >= cinfo->image_height)
85  WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
86 
87  /* Call progress monitor hook if present */
88  if (cinfo->progress != NULL) {
89  cinfo->progress->pass_counter = (long) cinfo->next_scanline;
90  cinfo->progress->pass_limit = (long) cinfo->image_height;
91  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
92  }
93 
94  /* Give master control module another chance if this is first call to
95  * jpeg_write_scanlines. This lets output of the frame/scan headers be
96  * delayed so that application can write COM, etc, markers between
97  * jpeg_start_compress and jpeg_write_scanlines.
98  */
99  if (cinfo->master->call_pass_startup)
100  (*cinfo->master->pass_startup) (cinfo);
101 
102  /* Ignore any extra scanlines at bottom of image. */
103  rows_left = cinfo->image_height - cinfo->next_scanline;
104  if (num_lines > rows_left)
105  num_lines = rows_left;
106 
107  row_ctr = 0;
108  (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
109  cinfo->next_scanline += row_ctr;
110  return row_ctr;
111 }
void(* progress_monitor)()
Definition: jpeglib.h:707
long pass_limit
Definition: jpeglib.h:710
JDIMENSION image_height
Definition: jpeglib.h:285
Definition: jpeglib.h:258
Definition: jerror.h:65
struct jpeg_progress_mgr * progress
Definition: jpeglib.h:274
#define CSTATE_SCANNING
Definition: jpegint.h:26
boolean call_pass_startup
Definition: jpegint.h:51
long pass_counter
Definition: jpeglib.h:709
JDIMENSION next_scanline
Definition: jpeglib.h:359
Definition: jerror.h:184
struct jpeg_c_main_controller * main
Definition: jpeglib.h:401
#define WARNMS(cinfo, code)
Definition: jerror.h:238
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:274
unsigned int JDIMENSION
Definition: jmorecfg.h:171
struct jpeg_comp_master * master
Definition: jpeglib.h:400
void jpeg_finish_compress ( j_compress_ptr  cinfo)
148 {
149  JDIMENSION iMCU_row;
150 
151  if (cinfo->global_state == CSTATE_SCANNING ||
152  cinfo->global_state == CSTATE_RAW_OK) {
153  /* Terminate first pass */
154  if (cinfo->next_scanline < cinfo->image_height)
156  (*cinfo->master->finish_pass) (cinfo);
157  } else if (cinfo->global_state != CSTATE_WRCOEFS)
158  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
159  /* Perform any remaining passes */
160  while (! cinfo->master->is_last_pass) {
161  (*cinfo->master->prepare_for_pass) (cinfo);
162  for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
163  if (cinfo->progress != NULL) {
164  cinfo->progress->pass_counter = (long) iMCU_row;
165  cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
166  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
167  }
168  /* We bypass the main controller and invoke coef controller directly;
169  * all work is being done from the coefficient buffer.
170  */
171  if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
172  ERREXIT(cinfo, JERR_CANT_SUSPEND);
173  }
174  (*cinfo->master->finish_pass) (cinfo);
175  }
176  /* Write EOI, do final cleanup */
177  (*cinfo->marker->write_file_trailer) (cinfo);
178  (*cinfo->dest->term_destination) (cinfo);
179  /* We can use jpeg_abort to release memory and reset global_state */
180  jpeg_abort((j_common_ptr) cinfo);
181 }
void(* progress_monitor)()
Definition: jpeglib.h:707
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
long pass_limit
Definition: jpeglib.h:710
JDIMENSION image_height
Definition: jpeglib.h:285
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jpeglib.h:258
Definition: jerror.h:65
#define CSTATE_RAW_OK
Definition: jpegint.h:27
struct jpeg_progress_mgr * progress
Definition: jpeglib.h:274
#define CSTATE_SCANNING
Definition: jpegint.h:26
long pass_counter
Definition: jpeglib.h:709
JDIMENSION next_scanline
Definition: jpeglib.h:359
boolean is_last_pass
Definition: jpegint.h:52
struct jpeg_c_coef_controller * coef
Definition: jpeglib.h:403
JDIMENSION total_iMCU_rows
Definition: jpeglib.h:372
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:277
struct jpeg_marker_writer * marker
Definition: jpeglib.h:404
JSAMPARRAY * JSAMPIMAGE
Definition: jpeglib.h:73
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:274
Definition: jerror.h:70
unsigned int JDIMENSION
Definition: jmorecfg.h:171
#define CSTATE_WRCOEFS
Definition: jpegint.h:28
struct jpeg_comp_master * master
Definition: jpeglib.h:400
void jpeg_abort(j_common_ptr cinfo)
Definition: jcomapi.cpp:29
void(* term_destination)()
Definition: jpeglib.h:724
Definition: jerror.h:116
JDIMENSION jpeg_write_raw_data ( j_compress_ptr  cinfo,
JSAMPIMAGE  data,
JDIMENSION  num_lines 
)
122 {
123  JDIMENSION lines_per_iMCU_row;
124 
125  if (cinfo->global_state != CSTATE_RAW_OK)
126  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
127  if (cinfo->next_scanline >= cinfo->image_height) {
128  WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
129  return 0;
130  }
131 
132  /* Call progress monitor hook if present */
133  if (cinfo->progress != NULL) {
134  cinfo->progress->pass_counter = (long) cinfo->next_scanline;
135  cinfo->progress->pass_limit = (long) cinfo->image_height;
136  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
137  }
138 
139  /* Give master control module another chance if this is first call to
140  * jpeg_write_raw_data. This lets output of the frame/scan headers be
141  * delayed so that application can write COM, etc, markers between
142  * jpeg_start_compress and jpeg_write_raw_data.
143  */
144  if (cinfo->master->call_pass_startup)
145  (*cinfo->master->pass_startup) (cinfo);
146 
147  /* Verify that at least one iMCU row has been passed. */
148  lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
149  if (num_lines < lines_per_iMCU_row)
150  ERREXIT(cinfo, JERR_BUFFER_SIZE);
151 
152  /* Directly compress the row. */
153  if (! (*cinfo->coef->compress_data) (cinfo, data)) {
154  /* If compressor did not consume the whole row, suspend processing. */
155  return 0;
156  }
157 
158  /* OK, we processed one iMCU row. */
159  cinfo->next_scanline += lines_per_iMCU_row;
160  return lines_per_iMCU_row;
161 }
void(* progress_monitor)()
Definition: jpeglib.h:707
long pass_limit
Definition: jpeglib.h:710
JDIMENSION image_height
Definition: jpeglib.h:285
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jpeglib.h:258
Definition: jerror.h:65
#define CSTATE_RAW_OK
Definition: jpegint.h:27
struct jpeg_progress_mgr * progress
Definition: jpeglib.h:274
boolean call_pass_startup
Definition: jpegint.h:51
long pass_counter
Definition: jpeglib.h:709
JDIMENSION next_scanline
Definition: jpeglib.h:359
Definition: jerror.h:184
Definition: jerror.h:69
struct jpeg_c_coef_controller * coef
Definition: jpeglib.h:403
int max_v_samp_factor
Definition: jpeglib.h:370
#define WARNMS(cinfo, code)
Definition: jerror.h:238
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:274
#define DCTSIZE
Definition: jpeglib.h:46
unsigned int JDIMENSION
Definition: jmorecfg.h:171
struct jpeg_comp_master * master
Definition: jpeglib.h:400
void jpeg_write_marker ( j_compress_ptr  cinfo,
int  marker,
const JOCTET dataptr,
unsigned int  datalen 
)
194 {
195  JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
196 
197  if (cinfo->next_scanline != 0 ||
198  (cinfo->global_state != CSTATE_SCANNING &&
199  cinfo->global_state != CSTATE_RAW_OK &&
200  cinfo->global_state != CSTATE_WRCOEFS))
201  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
202 
203  (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
204  write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
205  while (datalen--) {
206  (*write_marker_byte) (cinfo, *dataptr);
207  dataptr++;
208  }
209 }
Definition: jerror.h:65
#define CSTATE_RAW_OK
Definition: jpegint.h:27
#define CSTATE_SCANNING
Definition: jpegint.h:26
JDIMENSION next_scanline
Definition: jpeglib.h:359
int datalen
Definition: mcastclient.c:41
struct jpeg_marker_writer * marker
Definition: jpeglib.h:404
#define JMETHOD(type, methodname, arglist)
Definition: jmorecfg.h:202
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
Definition: jpeglib.h:273
static void write_marker_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:450
int global_state
Definition: jpeglib.h:274
backing_store_ptr info
Definition: jmemsys.h:181
#define CSTATE_WRCOEFS
Definition: jpegint.h:28
void jpeg_write_m_header ( j_compress_ptr  cinfo,
int  marker,
unsigned int  datalen 
)
215 {
216  if (cinfo->next_scanline != 0 ||
217  (cinfo->global_state != CSTATE_SCANNING &&
218  cinfo->global_state != CSTATE_RAW_OK &&
219  cinfo->global_state != CSTATE_WRCOEFS))
220  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
221 
222  (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
223 }
Definition: jerror.h:65
#define CSTATE_RAW_OK
Definition: jpegint.h:27
#define CSTATE_SCANNING
Definition: jpegint.h:26
JDIMENSION next_scanline
Definition: jpeglib.h:359
int datalen
Definition: mcastclient.c:41
struct jpeg_marker_writer * marker
Definition: jpeglib.h:404
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:274
#define CSTATE_WRCOEFS
Definition: jpegint.h:28
void jpeg_write_m_byte ( j_compress_ptr  cinfo,
int  val 
)
227 {
228  (*cinfo->marker->write_marker_byte) (cinfo, val);
229 }
struct jpeg_marker_writer * marker
Definition: jpeglib.h:404
void jpeg_write_tables ( j_compress_ptr  cinfo)
255 {
256  if (cinfo->global_state != CSTATE_START)
257  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
258 
259  /* (Re)initialize error mgr and destination modules */
260  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
261  (*cinfo->dest->init_destination) (cinfo);
262  /* Initialize the marker writer ... bit of a crock to do it here. */
263  jinit_marker_writer(cinfo);
264  /* Write them tables! */
265  (*cinfo->marker->write_tables_only) (cinfo);
266  /* And clean up. */
267  (*cinfo->dest->term_destination) (cinfo);
268  /*
269  * In library releases up through v6a, we called jpeg_abort() here to free
270  * any working memory allocated by the destination manager and marker
271  * writer. Some applications had a problem with that: they allocated space
272  * of their own from the library memory manager, and didn't want it to go
273  * away during write_tables. So now we do nothing. This will cause a
274  * memory leak if an app calls write_tables repeatedly without doing a full
275  * compression cycle or otherwise resetting the JPEG object. However, that
276  * seems less bad than unexpectedly freeing memory in the normal case.
277  * An app that prefers the old behavior can call jpeg_abort for itself after
278  * each call to jpeg_write_tables().
279  */
280 }
#define CSTATE_START
Definition: jpegint.h:25
void jinit_marker_writer(j_compress_ptr cinfo)
Definition: jcmarker.cpp:645
Definition: jpeglib.h:258
Definition: jerror.h:65
struct jpeg_error_mgr * err
Definition: jpeglib.h:274
void(* init_destination)()
Definition: jpeglib.h:722
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:277
struct jpeg_marker_writer * marker
Definition: jpeglib.h:404
void(* reset_error_mgr)()
Definition: jpeglib.h:659
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:274
void(* term_destination)()
Definition: jpeglib.h:724
int jpeg_read_header ( j_decompress_ptr  cinfo,
boolean  require_image 
)
242 {
243  int retcode;
244 
245  if (cinfo->global_state != DSTATE_START &&
246  cinfo->global_state != DSTATE_INHEADER)
247  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
248 
249  retcode = jpeg_consume_input(cinfo);
250 
251  switch (retcode) {
252  case JPEG_REACHED_SOS:
253  retcode = JPEG_HEADER_OK;
254  break;
255  case JPEG_REACHED_EOI:
256  if (require_image) /* Complain if application wanted an image */
257  ERREXIT(cinfo, JERR_NO_IMAGE);
258  /* Reset to start state; it would be safer to require the application to
259  * call jpeg_abort, but we can't change it now for compatibility reasons.
260  * A side effect is to free any temporary memory (there shouldn't be any).
261  */
262  jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
263  retcode = JPEG_HEADER_TABLES_ONLY;
264  break;
265  case JPEG_SUSPENDED:
266  /* no work */
267  break;
268  }
269 
270  return retcode;
271 }
#define DSTATE_INHEADER
Definition: jpegint.h:30
#define JPEG_REACHED_SOS
Definition: jpeglib.h:1001
#define JPEG_REACHED_EOI
Definition: jpeglib.h:1002
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jpeglib.h:258
Definition: jerror.h:65
#define JPEG_HEADER_TABLES_ONLY
Definition: jpeglib.h:972
#define DSTATE_START
Definition: jpegint.h:29
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
#define JPEG_SUSPENDED
Definition: jpeglib.h:970
int jpeg_consume_input(j_decompress_ptr cinfo)
Definition: jdapimin.cpp:287
int global_state
Definition: jpeglib.h:417
Definition: jerror.h:98
void jpeg_abort(j_common_ptr cinfo)
Definition: jcomapi.cpp:29
#define JPEG_HEADER_OK
Definition: jpeglib.h:971
boolean jpeg_start_decompress ( j_decompress_ptr  cinfo)
39 {
40  if (cinfo->global_state == DSTATE_READY) {
41  /* First call: initialize master control, select active modules */
43  if (cinfo->buffered_image) {
44  /* No more work here; expecting jpeg_start_output next */
46  return TRUE;
47  }
49  }
50  if (cinfo->global_state == DSTATE_PRELOAD) {
51  /* If file has multiple scans, absorb them all into the coef buffer */
52  if (cinfo->inputctl->has_multiple_scans) {
53 #ifdef D_MULTISCAN_FILES_SUPPORTED
54  for (;;) {
55  int retcode;
56  /* Call progress monitor hook if present */
57  if (cinfo->progress != NULL)
58  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
59  /* Absorb some more input */
60  retcode = (*cinfo->inputctl->consume_input) (cinfo);
61  if (retcode == JPEG_SUSPENDED)
62  return FALSE;
63  if (retcode == JPEG_REACHED_EOI)
64  break;
65  /* Advance progress counter if appropriate */
66  if (cinfo->progress != NULL &&
67  (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
68  if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
69  /* jdmaster underestimated number of scans; ratchet up one scan */
70  cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
71  }
72  }
73  }
74 #else
75  ERREXIT(cinfo, JERR_NOT_COMPILED);
76 #endif /* D_MULTISCAN_FILES_SUPPORTED */
77  }
78  cinfo->output_scan_number = cinfo->input_scan_number;
79  } else if (cinfo->global_state != DSTATE_PRESCAN)
80  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
81  /* Perform any dummy output passes, and set up for the final pass */
82  return output_pass_setup(cinfo);
83 }
boolean has_multiple_scans
Definition: jpegint.h:153
void(* progress_monitor)()
Definition: jpeglib.h:707
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
#define JPEG_REACHED_SOS
Definition: jpeglib.h:1001
#define JPEG_REACHED_EOI
Definition: jpeglib.h:1002
struct jpeg_progress_mgr * progress
Definition: jpeglib.h:417
#define DSTATE_BUFIMAGE
Definition: jpegint.h:36
long pass_limit
Definition: jpeglib.h:710
int output_scan_number
Definition: jpeglib.h:506
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
#define JPEG_ROW_COMPLETED
Definition: jpeglib.h:1003
Definition: jpeglib.h:258
Definition: jerror.h:65
#define DSTATE_PRELOAD
Definition: jpegint.h:32
long pass_counter
Definition: jpeglib.h:709
#define FALSE
Definition: jpleph.cpp:69
Definition: jerror.h:95
static boolean output_pass_setup(j_decompress_ptr cinfo)
Definition: jdapistd.cpp:95
#define DSTATE_READY
Definition: jpegint.h:31
int input_scan_number
Definition: jpeglib.h:499
#define TRUE
Definition: jpleph.cpp:68
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
#define DSTATE_PRESCAN
Definition: jpegint.h:33
void jinit_master_decompress(j_decompress_ptr cinfo)
Definition: jdmaster.cpp:543
#define JPEG_SUSPENDED
Definition: jpeglib.h:970
int global_state
Definition: jpeglib.h:417
boolean buffered_image
Definition: jpeglib.h:441
JDIMENSION total_iMCU_rows
Definition: jpeglib.h:585
JDIMENSION jpeg_read_scanlines ( j_decompress_ptr  cinfo,
JSAMPARRAY  scanlines,
JDIMENSION  max_lines 
)
154 {
155  JDIMENSION row_ctr;
156 
157  if (cinfo->global_state != DSTATE_SCANNING)
158  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
159  if (cinfo->output_scanline >= cinfo->output_height) {
160  WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
161  return 0;
162  }
163 
164  /* Call progress monitor hook if present */
165  if (cinfo->progress != NULL) {
166  cinfo->progress->pass_counter = (long) cinfo->output_scanline;
167  cinfo->progress->pass_limit = (long) cinfo->output_height;
168  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
169  }
170 
171  /* Process some data */
172  row_ctr = 0;
173  (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
174  cinfo->output_scanline += row_ctr;
175  return row_ctr;
176 }
void(* progress_monitor)()
Definition: jpeglib.h:707
JDIMENSION output_height
Definition: jpeglib.h:465
struct jpeg_d_main_controller * main
Definition: jpeglib.h:625
struct jpeg_progress_mgr * progress
Definition: jpeglib.h:417
long pass_limit
Definition: jpeglib.h:710
Definition: jpeglib.h:258
Definition: jerror.h:65
long pass_counter
Definition: jpeglib.h:709
Definition: jerror.h:184
#define WARNMS(cinfo, code)
Definition: jerror.h:238
#define DSTATE_SCANNING
Definition: jpegint.h:34
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
JDIMENSION output_scanline
Definition: jpeglib.h:494
int global_state
Definition: jpeglib.h:417
unsigned int JDIMENSION
Definition: jmorecfg.h:171
boolean jpeg_finish_decompress ( j_decompress_ptr  cinfo)
370 {
371  if ((cinfo->global_state == DSTATE_SCANNING ||
372  cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
373  /* Terminate final pass of non-buffered mode */
374  if (cinfo->output_scanline < cinfo->output_height)
376  (*cinfo->master->finish_output_pass) (cinfo);
377  cinfo->global_state = DSTATE_STOPPING;
378  } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
379  /* Finishing after a buffered-image operation */
380  cinfo->global_state = DSTATE_STOPPING;
381  } else if (cinfo->global_state != DSTATE_STOPPING) {
382  /* STOPPING = repeat call after a suspension, anything else is error */
383  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
384  }
385  /* Read until EOI */
386  while (! cinfo->inputctl->eoi_reached) {
387  if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
388  return FALSE; /* Suspend, come back later */
389  }
390  /* Do final cleanup */
391  (*cinfo->src->term_source) (cinfo);
392  /* We can use jpeg_abort to release memory and reset global_state */
393  jpeg_abort((j_common_ptr) cinfo);
394  return TRUE;
395 }
#define DSTATE_RAW_OK
Definition: jpegint.h:35
JDIMENSION output_height
Definition: jpeglib.h:465
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
#define DSTATE_BUFIMAGE
Definition: jpegint.h:36
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jpeglib.h:258
Definition: jerror.h:65
void(* term_source)()
Definition: jpeglib.h:738
#define DSTATE_STOPPING
Definition: jpegint.h:39
#define FALSE
Definition: jpleph.cpp:69
struct jpeg_decomp_master * master
Definition: jpeglib.h:624
boolean eoi_reached
Definition: jpegint.h:154
#define DSTATE_SCANNING
Definition: jpegint.h:34
#define TRUE
Definition: jpleph.cpp:68
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
struct jpeg_source_mgr * src
Definition: jpeglib.h:420
JDIMENSION output_scanline
Definition: jpeglib.h:494
#define JPEG_SUSPENDED
Definition: jpeglib.h:970
int global_state
Definition: jpeglib.h:417
boolean buffered_image
Definition: jpeglib.h:441
void jpeg_abort(j_common_ptr cinfo)
Definition: jcomapi.cpp:29
Definition: jerror.h:116
JDIMENSION jpeg_read_raw_data ( j_decompress_ptr  cinfo,
JSAMPIMAGE  data,
JDIMENSION  max_lines 
)
187 {
188  JDIMENSION lines_per_iMCU_row;
189 
190  if (cinfo->global_state != DSTATE_RAW_OK)
191  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
192  if (cinfo->output_scanline >= cinfo->output_height) {
193  WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
194  return 0;
195  }
196 
197  /* Call progress monitor hook if present */
198  if (cinfo->progress != NULL) {
199  cinfo->progress->pass_counter = (long) cinfo->output_scanline;
200  cinfo->progress->pass_limit = (long) cinfo->output_height;
201  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
202  }
203 
204  /* Verify that at least one iMCU row can be returned. */
205  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
206  if (max_lines < lines_per_iMCU_row)
207  ERREXIT(cinfo, JERR_BUFFER_SIZE);
208 
209  /* Decompress directly into user's buffer. */
210  if (! (*cinfo->coef->decompress_data) (cinfo, data))
211  return 0; /* suspension forced, can do nothing more */
212 
213  /* OK, we processed one iMCU row. */
214  cinfo->output_scanline += lines_per_iMCU_row;
215  return lines_per_iMCU_row;
216 }
#define DSTATE_RAW_OK
Definition: jpegint.h:35
void(* progress_monitor)()
Definition: jpeglib.h:707
JDIMENSION output_height
Definition: jpeglib.h:465
struct jpeg_progress_mgr * progress
Definition: jpeglib.h:417
int min_DCT_scaled_size
Definition: jpeglib.h:583
long pass_limit
Definition: jpeglib.h:710
struct jpeg_d_coef_controller * coef
Definition: jpeglib.h:626
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jpeglib.h:258
Definition: jerror.h:65
long pass_counter
Definition: jpeglib.h:709
Definition: jerror.h:184
Definition: jerror.h:69
#define WARNMS(cinfo, code)
Definition: jerror.h:238
int max_v_samp_factor
Definition: jpeglib.h:581
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
JDIMENSION output_scanline
Definition: jpeglib.h:494
int global_state
Definition: jpeglib.h:417
unsigned int JDIMENSION
Definition: jmorecfg.h:171
boolean jpeg_has_multiple_scans ( j_decompress_ptr  cinfo)
350 {
351  /* Only valid after jpeg_read_header completes */
352  if (cinfo->global_state < DSTATE_READY ||
353  cinfo->global_state > DSTATE_STOPPING)
354  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
355  return cinfo->inputctl->has_multiple_scans;
356 }
boolean has_multiple_scans
Definition: jpegint.h:153
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
Definition: jerror.h:65
#define DSTATE_STOPPING
Definition: jpegint.h:39
#define DSTATE_READY
Definition: jpegint.h:31
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:417
boolean jpeg_start_output ( j_decompress_ptr  cinfo,
int  scan_number 
)
229 {
230  if (cinfo->global_state != DSTATE_BUFIMAGE &&
231  cinfo->global_state != DSTATE_PRESCAN)
232  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
233  /* Limit scan number to valid range */
234  if (scan_number <= 0)
235  scan_number = 1;
236  if (cinfo->inputctl->eoi_reached &&
237  scan_number > cinfo->input_scan_number)
238  scan_number = cinfo->input_scan_number;
239  cinfo->output_scan_number = scan_number;
240  /* Perform any dummy output passes, and set up for the real pass */
241  return output_pass_setup(cinfo);
242 }
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
#define DSTATE_BUFIMAGE
Definition: jpegint.h:36
int output_scan_number
Definition: jpeglib.h:506
Definition: jerror.h:65
static boolean output_pass_setup(j_decompress_ptr cinfo)
Definition: jdapistd.cpp:95
int input_scan_number
Definition: jpeglib.h:499
boolean eoi_reached
Definition: jpegint.h:154
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
#define DSTATE_PRESCAN
Definition: jpegint.h:33
int global_state
Definition: jpeglib.h:417
boolean jpeg_finish_output ( j_decompress_ptr  cinfo)
254 {
255  if ((cinfo->global_state == DSTATE_SCANNING ||
256  cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
257  /* Terminate this pass. */
258  /* We do not require the whole pass to have been completed. */
259  (*cinfo->master->finish_output_pass) (cinfo);
260  cinfo->global_state = DSTATE_BUFPOST;
261  } else if (cinfo->global_state != DSTATE_BUFPOST) {
262  /* BUFPOST = repeat call after a suspension, anything else is error */
263  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
264  }
265  /* Read markers looking for SOS or EOI */
266  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
267  ! cinfo->inputctl->eoi_reached) {
268  if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
269  return FALSE; /* Suspend, come back later */
270  }
271  cinfo->global_state = DSTATE_BUFIMAGE;
272  return TRUE;
273 }
#define DSTATE_RAW_OK
Definition: jpegint.h:35
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
#define DSTATE_BUFIMAGE
Definition: jpegint.h:36
int output_scan_number
Definition: jpeglib.h:506
Definition: jerror.h:65
#define FALSE
Definition: jpleph.cpp:69
int input_scan_number
Definition: jpeglib.h:499
struct jpeg_decomp_master * master
Definition: jpeglib.h:624
boolean eoi_reached
Definition: jpegint.h:154
#define DSTATE_SCANNING
Definition: jpegint.h:34
#define TRUE
Definition: jpleph.cpp:68
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
#define DSTATE_BUFPOST
Definition: jpegint.h:37
#define JPEG_SUSPENDED
Definition: jpeglib.h:970
int global_state
Definition: jpeglib.h:417
boolean buffered_image
Definition: jpeglib.h:441
boolean jpeg_input_complete ( j_decompress_ptr  cinfo)
335 {
336  /* Check for valid jpeg object */
337  if (cinfo->global_state < DSTATE_START ||
338  cinfo->global_state > DSTATE_STOPPING)
339  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
340  return cinfo->inputctl->eoi_reached;
341 }
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
Definition: jerror.h:65
#define DSTATE_STOPPING
Definition: jpegint.h:39
#define DSTATE_START
Definition: jpegint.h:29
boolean eoi_reached
Definition: jpegint.h:154
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:417
void jpeg_new_colormap ( j_decompress_ptr  cinfo)
516 {
517  my_master_ptr master = (my_master_ptr) cinfo->master;
518 
519  /* Prevent application from calling me at wrong times */
520  if (cinfo->global_state != DSTATE_BUFIMAGE)
521  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
522 
523  if (cinfo->quantize_colors && cinfo->enable_external_quant &&
524  cinfo->colormap != NULL) {
525  /* Select 2-pass quantizer for external colormap use */
526  cinfo->cquantize = master->quantizer_2pass;
527  /* Notify quantizer of colormap change */
528  (*cinfo->cquantize->new_color_map) (cinfo);
529  master->pub.is_dummy_pass = FALSE; /* just in case */
530  } else
531  ERREXIT(cinfo, JERR_MODE_CHANGE);
532 }
Definition: jcmaster.cpp:27
#define DSTATE_BUFIMAGE
Definition: jpegint.h:36
boolean quantize_colors
Definition: jpeglib.h:448
boolean enable_external_quant
Definition: jpeglib.h:455
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jerror.h:65
struct jpeg_comp_master pub
Definition: jcmaster.cpp:28
my_decomp_master * my_master_ptr
Definition: jdmaster.cpp:35
#define FALSE
Definition: jpleph.cpp:69
Definition: jerror.h:93
struct jpeg_color_quantizer * cquantize
Definition: jpeglib.h:634
struct jpeg_decomp_master * master
Definition: jpeglib.h:624
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
JSAMPARRAY colormap
Definition: jpeglib.h:484
int global_state
Definition: jpeglib.h:417
int jpeg_consume_input ( j_decompress_ptr  cinfo)
288 {
289  int retcode = JPEG_SUSPENDED;
290 
291  /* NB: every possible DSTATE value should be listed in this switch */
292  switch (cinfo->global_state) {
293  case DSTATE_START:
294  /* Start-of-datastream actions: reset appropriate modules */
295  (*cinfo->inputctl->reset_input_controller) (cinfo);
296  /* Initialize application's data source module */
297  (*cinfo->src->init_source) (cinfo);
298  cinfo->global_state = DSTATE_INHEADER;
299  /*FALLTHROUGH*/
300  case DSTATE_INHEADER:
301  retcode = (*cinfo->inputctl->consume_input) (cinfo);
302  if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
303  /* Set up default parameters based on header data */
305  /* Set global state: ready for start_decompress */
306  cinfo->global_state = DSTATE_READY;
307  }
308  break;
309  case DSTATE_READY:
310  /* Can't advance past first SOS until start_decompress is called */
311  retcode = JPEG_REACHED_SOS;
312  break;
313  case DSTATE_PRELOAD:
314  case DSTATE_PRESCAN:
315  case DSTATE_SCANNING:
316  case DSTATE_RAW_OK:
317  case DSTATE_BUFIMAGE:
318  case DSTATE_BUFPOST:
319  case DSTATE_STOPPING:
320  retcode = (*cinfo->inputctl->consume_input) (cinfo);
321  break;
322  default:
323  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
324  }
325  return retcode;
326 }
#define DSTATE_RAW_OK
Definition: jpegint.h:35
#define DSTATE_INHEADER
Definition: jpegint.h:30
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
#define JPEG_REACHED_SOS
Definition: jpeglib.h:1001
#define DSTATE_BUFIMAGE
Definition: jpegint.h:36
Definition: jerror.h:65
#define DSTATE_STOPPING
Definition: jpegint.h:39
#define DSTATE_PRELOAD
Definition: jpegint.h:32
#define DSTATE_READY
Definition: jpegint.h:31
#define DSTATE_START
Definition: jpegint.h:29
#define DSTATE_SCANNING
Definition: jpegint.h:34
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
#define DSTATE_BUFPOST
Definition: jpegint.h:37
struct jpeg_source_mgr * src
Definition: jpeglib.h:420
#define DSTATE_PRESCAN
Definition: jpegint.h:33
#define JPEG_SUSPENDED
Definition: jpeglib.h:970
int global_state
Definition: jpeglib.h:417
void(* init_source)()
Definition: jpeglib.h:734
static void default_decompress_parms(j_decompress_ptr cinfo)
Definition: jdapimin.cpp:114
void jpeg_calc_output_dimensions ( j_decompress_ptr  cinfo)
86 {
87 #ifdef IDCT_SCALING_SUPPORTED
88  int ci;
90 #endif
91 
92  /* Prevent application from calling me at wrong times */
93  if (cinfo->global_state != DSTATE_READY)
94  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
95 
96 #ifdef IDCT_SCALING_SUPPORTED
97 
98  /* Compute actual output image dimensions and DCT scaling choices. */
99  if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
100  /* Provide 1/8 scaling */
101  cinfo->output_width = (JDIMENSION)
102  jdiv_round_up((long) cinfo->image_width, 8L);
103  cinfo->output_height = (JDIMENSION)
104  jdiv_round_up((long) cinfo->image_height, 8L);
105  cinfo->min_DCT_scaled_size = 1;
106  } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
107  /* Provide 1/4 scaling */
108  cinfo->output_width = (JDIMENSION)
109  jdiv_round_up((long) cinfo->image_width, 4L);
110  cinfo->output_height = (JDIMENSION)
111  jdiv_round_up((long) cinfo->image_height, 4L);
112  cinfo->min_DCT_scaled_size = 2;
113  } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
114  /* Provide 1/2 scaling */
115  cinfo->output_width = (JDIMENSION)
116  jdiv_round_up((long) cinfo->image_width, 2L);
117  cinfo->output_height = (JDIMENSION)
118  jdiv_round_up((long) cinfo->image_height, 2L);
119  cinfo->min_DCT_scaled_size = 4;
120  } else {
121  /* Provide 1/1 scaling */
122  cinfo->output_width = cinfo->image_width;
123  cinfo->output_height = cinfo->image_height;
124  cinfo->min_DCT_scaled_size = DCTSIZE;
125  }
126  /* In selecting the actual DCT scaling for each component, we try to
127  * scale up the chroma components via IDCT scaling rather than upsampling.
128  * This saves time if the upsampler gets to use 1:1 scaling.
129  * Note this code assumes that the supported DCT scalings are powers of 2.
130  */
131  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
132  ci++, compptr++) {
133  int ssize = cinfo->min_DCT_scaled_size;
134  while (ssize < DCTSIZE &&
135  (compptr->h_samp_factor * ssize * 2 <=
136  cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
137  (compptr->v_samp_factor * ssize * 2 <=
138  cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
139  ssize = ssize * 2;
140  }
141  compptr->DCT_scaled_size = ssize;
142  }
143 
144  /* Recompute downsampled dimensions of components;
145  * application needs to know these if using raw downsampled data.
146  */
147  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
148  ci++, compptr++) {
149  /* Size in samples, after IDCT scaling */
150  compptr->downsampled_width = (JDIMENSION)
151  jdiv_round_up((long) cinfo->image_width *
152  (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
153  (long) (cinfo->max_h_samp_factor * DCTSIZE));
154  compptr->downsampled_height = (JDIMENSION)
155  jdiv_round_up((long) cinfo->image_height *
156  (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
157  (long) (cinfo->max_v_samp_factor * DCTSIZE));
158  }
159 
160 #else /* !IDCT_SCALING_SUPPORTED */
161 
162  /* Hardwire it to "no scaling" */
163  cinfo->output_width = cinfo->image_width;
164  cinfo->output_height = cinfo->image_height;
165  /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
166  * and has computed unscaled downsampled_width and downsampled_height.
167  */
168 
169 #endif /* IDCT_SCALING_SUPPORTED */
170 
171  /* Report number of components in selected colorspace. */
172  /* Probably this should be in the color conversion module... */
173  switch (cinfo->out_color_space) {
174  case JCS_GRAYSCALE:
175  cinfo->out_color_components = 1;
176  break;
177  case JCS_RGB:
178 #if RGB_PIXELSIZE != 3
179  cinfo->out_color_components = RGB_PIXELSIZE;
180  break;
181 #endif /* else share code with YCbCr */
182  case JCS_YCbCr:
183  cinfo->out_color_components = 3;
184  break;
185  case JCS_CMYK:
186  case JCS_YCCK:
187  cinfo->out_color_components = 4;
188  break;
189  default: /* else must be same colorspace as in file */
190  cinfo->out_color_components = cinfo->num_components;
191  break;
192  }
193  cinfo->output_components = (cinfo->quantize_colors ? 1 :
194  cinfo->out_color_components);
195 
196  /* See if upsampler will want to emit more than one row at a time */
197  if (use_merged_upsample(cinfo))
198  cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
199  else
200  cinfo->rec_outbuf_height = 1;
201 }
Definition: jpeglib.h:217
int v_samp_factor
Definition: jpeglib.h:128
int num_components
Definition: jpeglib.h:427
JDIMENSION output_height
Definition: jpeglib.h:465
JDIMENSION downsampled_width
Definition: jpeglib.h:159
int rec_outbuf_height
Definition: jpeglib.h:471
jpeg_component_info * comp_info
Definition: jpeglib.h:540
boolean quantize_colors
Definition: jpeglib.h:448
int min_DCT_scaled_size
Definition: jpeglib.h:583
int DCT_scaled_size
Definition: jpeglib.h:152
JDIMENSION image_width
Definition: jpeglib.h:425
Definition: jerror.h:65
JDIMENSION output_width
Definition: jpeglib.h:464
JDIMENSION image_height
Definition: jpeglib.h:426
jpeg_component_info * compptr
Definition: jdct.h:102
J_COLOR_SPACE out_color_space
Definition: jpeglib.h:435
int max_h_samp_factor
Definition: jpeglib.h:580
Definition: jpeglib.h:214
Definition: jpeglib.h:213
int output_components
Definition: jpeglib.h:467
#define DSTATE_READY
Definition: jpegint.h:31
int out_color_components
Definition: jpeglib.h:466
unsigned int scale_denom
Definition: jpeglib.h:437
int max_v_samp_factor
Definition: jpeglib.h:581
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
Definition: jpeglib.h:121
static boolean use_merged_upsample(j_decompress_ptr cinfo)
Definition: jdmaster.cpp:44
long jdiv_round_up(long a, long b)
Definition: jutils.cpp:72
Definition: jpeglib.h:215
#define DCTSIZE
Definition: jpeglib.h:46
int h_samp_factor
Definition: jpeglib.h:127
int global_state
Definition: jpeglib.h:417
unsigned int JDIMENSION
Definition: jmorecfg.h:171
unsigned int scale_num
Definition: jpeglib.h:437
Definition: jpeglib.h:216
JDIMENSION downsampled_height
Definition: jpeglib.h:160
void jpeg_save_markers ( j_decompress_ptr  cinfo,
int  marker_code,
unsigned int  length_limit 
)
1302 {
1303  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
1304  long maxlength;
1305  jpeg_marker_parser_method processor;
1306 
1307  /* Length limit mustn't be larger than what we can allocate
1308  * (should only be a concern in a 16-bit environment).
1309  */
1310  maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
1311  if (((long) length_limit) > maxlength)
1312  length_limit = (unsigned int) maxlength;
1313 
1314  /* Choose processor routine to use.
1315  * APP0/APP14 have special requirements.
1316  */
1317  if (length_limit) {
1318  processor = save_marker;
1319  /* If saving APP0/APP14, save at least enough for our internal use. */
1320  if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
1321  length_limit = APP0_DATA_LEN;
1322  else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
1323  length_limit = APP14_DATA_LEN;
1324  } else {
1325  processor = skip_variable;
1326  /* If discarding APP0/APP14, use our regular on-the-fly processor. */
1327  if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
1328  processor = get_interesting_appn;
1329  }
1330 
1331  if (marker_code == (int) M_COM) {
1332  marker->process_COM = processor;
1333  marker->length_limit_COM = length_limit;
1334  } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
1335  marker->process_APPn[marker_code - (int) M_APP0] = processor;
1336  marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
1337  } else
1338  ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
1339 }
Definition: jdmarker.cpp:76
Definition: jpeglib.h:200
Definition: jdmarker.cpp:80
boolean(* jpeg_marker_parser_method)()
Definition: jpeglib.h:814
static boolean skip_variable(j_decompress_ptr cinfo)
Definition: jdmarker.cpp:845
struct jpeg_marker_reader * marker
Definition: jpeglib.h:629
#define SIZEOF(object)
Definition: jinclude.h:80
my_marker_reader * my_marker_ptr
Definition: jdmarker.cpp:107
#define APP14_DATA_LEN
Definition: jdmarker.cpp:579
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
Definition: jerror.h:117
static boolean get_interesting_appn(j_decompress_ptr cinfo)
Definition: jdmarker.cpp:691
#define APP0_DATA_LEN
Definition: jdmarker.cpp:578
Definition: jdmarker.cpp:75
long max_alloc_chunk
Definition: jpeglib.h:807
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
Definition: jdmarker.cpp:61
static boolean save_marker(j_decompress_ptr cinfo)
Definition: jdmarker.cpp:739
Definition: jcmarker.cpp:86
void jpeg_set_marker_processor ( j_decompress_ptr  cinfo,
int  marker_code,
jpeg_marker_parser_method  routine 
)
1351 {
1352  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
1353 
1354  if (marker_code == (int) M_COM)
1355  marker->process_COM = routine;
1356  else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
1357  marker->process_APPn[marker_code - (int) M_APP0] = routine;
1358  else
1359  ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
1360 }
Definition: jdmarker.cpp:76
Definition: jdmarker.cpp:80
struct jpeg_marker_reader * marker
Definition: jpeglib.h:629
my_marker_reader * my_marker_ptr
Definition: jdmarker.cpp:107
Definition: jerror.h:117
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
Definition: jdmarker.cpp:61
Definition: jcmarker.cpp:86
jvirt_barray_ptr* jpeg_read_coefficients ( j_decompress_ptr  cinfo)
46 {
47  if (cinfo->global_state == DSTATE_READY) {
48  /* First call: initialize active modules */
51  }
52  if (cinfo->global_state == DSTATE_RDCOEFS) {
53  /* Absorb whole file into the coef buffer */
54  for (;;) {
55  int retcode;
56  /* Call progress monitor hook if present */
57  if (cinfo->progress != NULL)
58  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
59  /* Absorb some more input */
60  retcode = (*cinfo->inputctl->consume_input) (cinfo);
61  if (retcode == JPEG_SUSPENDED)
62  return NULL;
63  if (retcode == JPEG_REACHED_EOI)
64  break;
65  /* Advance progress counter if appropriate */
66  if (cinfo->progress != NULL &&
67  (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
68  if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
69  /* startup underestimated number of scans; ratchet up one scan */
70  cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
71  }
72  }
73  }
74  /* Set state so that jpeg_finish_decompress does the right thing */
76  }
77  /* At this point we should be in state DSTATE_STOPPING if being used
78  * standalone, or in state DSTATE_BUFIMAGE if being invoked to get access
79  * to the coefficients during a full buffered-image-mode decompression.
80  */
81  if ((cinfo->global_state == DSTATE_STOPPING ||
82  cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
83  return cinfo->coef->coef_arrays;
84  }
85  /* Oops, improper usage */
86  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
87  return NULL; /* keep compiler happy */
88 }
void(* progress_monitor)()
Definition: jpeglib.h:707
#define DSTATE_RDCOEFS
Definition: jpegint.h:38
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
#define JPEG_REACHED_SOS
Definition: jpeglib.h:1001
#define JPEG_REACHED_EOI
Definition: jpeglib.h:1002
struct jpeg_progress_mgr * progress
Definition: jpeglib.h:417
#define DSTATE_BUFIMAGE
Definition: jpegint.h:36
long pass_limit
Definition: jpeglib.h:710
struct jpeg_d_coef_controller * coef
Definition: jpeglib.h:626
#define JPEG_ROW_COMPLETED
Definition: jpeglib.h:1003
Definition: jpeglib.h:258
Definition: jerror.h:65
jvirt_barray_ptr * coef_arrays
Definition: jpegint.h:173
#define DSTATE_STOPPING
Definition: jpegint.h:39
long pass_counter
Definition: jpeglib.h:709
#define DSTATE_READY
Definition: jpegint.h:31
static void transdecode_master_selection(j_decompress_ptr cinfo)
Definition: jdtrans.cpp:97
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
#define JPEG_SUSPENDED
Definition: jpeglib.h:970
int global_state
Definition: jpeglib.h:417
boolean buffered_image
Definition: jpeglib.h:441
JDIMENSION total_iMCU_rows
Definition: jpeglib.h:585
void jpeg_write_coefficients ( j_compress_ptr  cinfo,
jvirt_barray_ptr coef_arrays 
)
39 {
40  if (cinfo->global_state != CSTATE_START)
41  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
42  /* Mark all tables to be written */
44  /* (Re)initialize error mgr and destination modules */
45  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
46  (*cinfo->dest->init_destination) (cinfo);
47  /* Perform master selection of active modules */
48  transencode_master_selection(cinfo, coef_arrays);
49  /* Wait for jpeg_finish_compress() call */
50  cinfo->next_scanline = 0; /* so jpeg_write_marker works */
52 }
#define CSTATE_START
Definition: jpegint.h:25
Definition: jpeglib.h:258
Definition: jerror.h:65
JDIMENSION next_scanline
Definition: jpeglib.h:359
#define FALSE
Definition: jpleph.cpp:69
struct jpeg_error_mgr * err
Definition: jpeglib.h:274
void(* init_destination)()
Definition: jpeglib.h:722
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:277
void(* reset_error_mgr)()
Definition: jpeglib.h:659
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
void jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress)
Definition: jcapimin.cpp:119
int global_state
Definition: jpeglib.h:274
#define CSTATE_WRCOEFS
Definition: jpegint.h:28
static void transencode_master_selection(j_compress_ptr cinfo, jvirt_barray_ptr *coef_arrays)
Definition: jctrans.cpp:158
void jpeg_copy_critical_parameters ( j_decompress_ptr  srcinfo,
j_compress_ptr  dstinfo 
)
65 {
66  JQUANT_TBL ** qtblptr;
67  jpeg_component_info *incomp, *outcomp;
68  JQUANT_TBL *c_quant, *slot_quant;
69  int tblno, ci, coefi;
70 
71  /* Safety check to ensure start_compress not called yet. */
72  if (dstinfo->global_state != CSTATE_START)
73  ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
74  /* Copy fundamental image dimensions */
75  dstinfo->image_width = srcinfo->image_width;
76  dstinfo->image_height = srcinfo->image_height;
77  dstinfo->input_components = srcinfo->num_components;
78  dstinfo->in_color_space = srcinfo->jpeg_color_space;
79  /* Initialize all parameters to default values */
80  jpeg_set_defaults(dstinfo);
81  /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB.
82  * Fix it to get the right header markers for the image colorspace.
83  */
84  jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
85  dstinfo->data_precision = srcinfo->data_precision;
86  dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
87  /* Copy the source's quantization tables. */
88  for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
89  if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
90  qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
91  if (*qtblptr == NULL)
92  *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
93  MEMCOPY((*qtblptr)->quantval,
94  srcinfo->quant_tbl_ptrs[tblno]->quantval,
95  SIZEOF((*qtblptr)->quantval));
96  (*qtblptr)->sent_table = FALSE;
97  }
98  }
99  /* Copy the source's per-component info.
100  * Note we assume jpeg_set_defaults has allocated the dest comp_info array.
101  */
102  dstinfo->num_components = srcinfo->num_components;
103  if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
104  ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
106  for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
107  ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
108  outcomp->component_id = incomp->component_id;
109  outcomp->h_samp_factor = incomp->h_samp_factor;
110  outcomp->v_samp_factor = incomp->v_samp_factor;
111  outcomp->quant_tbl_no = incomp->quant_tbl_no;
112  /* Make sure saved quantization table for component matches the qtable
113  * slot. If not, the input file re-used this qtable slot.
114  * IJG encoder currently cannot duplicate this.
115  */
116  tblno = outcomp->quant_tbl_no;
117  if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
118  srcinfo->quant_tbl_ptrs[tblno] == NULL)
119  ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
120  slot_quant = srcinfo->quant_tbl_ptrs[tblno];
121  c_quant = incomp->quant_table;
122  if (c_quant != NULL) {
123  for (coefi = 0; coefi < DCTSIZE2; coefi++) {
124  if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
125  ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
126  }
127  }
128  /* Note: we do not copy the source's Huffman table assignments;
129  * instead we rely on jpeg_set_colorspace to have made a suitable choice.
130  */
131  }
132  /* Also copy JFIF version and resolution information, if available.
133  * Strictly speaking this isn't "critical" info, but it's nearly
134  * always appropriate to copy it if available. In particular,
135  * if the application chooses to copy JFIF 1.02 extension markers from
136  * the source file, we need to copy the version to make sure we don't
137  * emit a file that has 1.02 extensions but a claimed version of 1.01.
138  * We will *not*, however, copy version info from mislabeled "2.01" files.
139  */
140  if (srcinfo->saw_JFIF_marker) {
141  if (srcinfo->JFIF_major_version == 1) {
142  dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
143  dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
144  }
145  dstinfo->density_unit = srcinfo->density_unit;
146  dstinfo->X_density = srcinfo->X_density;
147  dstinfo->Y_density = srcinfo->Y_density;
148  }
149 }
int v_samp_factor
Definition: jpeglib.h:128
int num_components
Definition: jpeglib.h:427
uint8_t JFIF_minor_version
Definition: jpeglib.h:558
#define CSTATE_START
Definition: jpegint.h:25
#define NUM_QUANT_TBLS
Definition: jpeglib.h:48
JQUANT_TBL * jpeg_alloc_quant_table(j_common_ptr cinfo)
Definition: jcomapi.cpp:86
jpeg_component_info * comp_info
Definition: jpeglib.h:540
JQUANT_TBL * quant_tbl_ptrs[4]
Definition: jpeglib.h:307
JDIMENSION image_height
Definition: jpeglib.h:285
#define MAX_COMPONENTS
Definition: jmorecfg.h:35
int data_precision
Definition: jpeglib.h:538
Definition: jpeglib.h:88
int num_components
Definition: jpeglib.h:301
boolean saw_JFIF_marker
Definition: jpeglib.h:555
JDIMENSION image_width
Definition: jpeglib.h:425
Definition: jpeglib.h:258
Definition: jerror.h:65
#define SIZEOF(object)
Definition: jinclude.h:80
Definition: jerror.h:72
JDIMENSION image_height
Definition: jpeglib.h:426
uint16_t quantval[64]
Definition: jpeglib.h:93
J_COLOR_SPACE in_color_space
Definition: jpeglib.h:287
int data_precision
Definition: jpeglib.h:299
#define FALSE
Definition: jpleph.cpp:69
uint8_t JFIF_major_version
Definition: jpeglib.h:557
uint16_t Y_density
Definition: jpeglib.h:561
#define MEMCOPY(dest, src, size)
Definition: jinclude.h:68
int quant_tbl_no
Definition: jpeglib.h:129
uint16_t X_density
Definition: jpeglib.h:560
#define DCTSIZE2
Definition: jpeglib.h:47
void jpeg_set_colorspace(j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
Definition: jcparam.cpp:391
int component_id
Definition: jpeglib.h:125
Definition: jerror.h:99
uint8_t density_unit
Definition: jpeglib.h:349
JQUANT_TBL * quant_table
Definition: jpeglib.h:180
boolean CCIR601_sampling
Definition: jpeglib.h:565
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:274
Definition: jpeglib.h:121
Definition: jerror.h:91
uint16_t X_density
Definition: jpeglib.h:350
JQUANT_TBL * quant_tbl_ptrs[4]
Definition: jpeglib.h:527
boolean CCIR601_sampling
Definition: jpeglib.h:328
void jpeg_set_defaults(j_compress_ptr cinfo)
Definition: jcparam.cpp:268
int h_samp_factor
Definition: jpeglib.h:127
uint8_t JFIF_minor_version
Definition: jpeglib.h:344
uint8_t density_unit
Definition: jpeglib.h:559
uint8_t JFIF_major_version
Definition: jpeglib.h:343
uint16_t Y_density
Definition: jpeglib.h:351
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:212
boolean int tblno
Definition: jchuff.h:42
jpeg_component_info * comp_info
Definition: jpeglib.h:304
J_COLOR_SPACE jpeg_color_space
Definition: jpeglib.h:428
int input_components
Definition: jpeglib.h:286
JDIMENSION image_width
Definition: jpeglib.h:284
void jpeg_abort_compress ( j_compress_ptr  cinfo)
101 {
102  jpeg_abort((j_common_ptr) cinfo); /* use common routine */
103 }
Definition: jpeglib.h:258
void jpeg_abort(j_common_ptr cinfo)
Definition: jcomapi.cpp:29
void jpeg_abort_decompress ( j_decompress_ptr  cinfo)
104 {
105  jpeg_abort((j_common_ptr) cinfo); /* use common routine */
106 }
Definition: jpeglib.h:258
void jpeg_abort(j_common_ptr cinfo)
Definition: jcomapi.cpp:29
void jpeg_abort ( j_common_ptr  cinfo)
30 {
31  int pool;
32 
33  /* Do nothing if called on a not-initialized or destroyed JPEG object. */
34  if (cinfo->mem == NULL)
35  return;
36 
37  /* Releasing pools in reverse order might help avoid fragmentation
38  * with some (brain-damaged) malloc libraries.
39  */
40  for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
41  (*cinfo->mem->free_pool) (cinfo, pool);
42  }
43 
44  /* Reset overall state for possible reuse of object */
45  if (cinfo->is_decompressor) {
46  cinfo->global_state = DSTATE_START;
47  /* Try to keep application from accessing now-deleted marker list.
48  * A bit kludgy to do it here, but this is the most central place.
49  */
50  ((j_decompress_ptr) cinfo)->marker_list = NULL;
51  } else {
52  cinfo->global_state = CSTATE_START;
53  }
54 }
struct jpeg_decompress_struct * j_decompress_ptr
Definition: jpeglib.h:268
#define CSTATE_START
Definition: jpegint.h:25
void(* free_pool)()
Definition: jpeglib.h:796
#define DSTATE_START
Definition: jpegint.h:29
#define JPOOL_NUMPOOLS
Definition: jpeglib.h:755
#define JPOOL_PERMANENT
Definition: jpeglib.h:753
boolean is_decompressor
Definition: jpeglib.h:259
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:259
int global_state
Definition: jpeglib.h:259
void jpeg_destroy ( j_common_ptr  cinfo)
70 {
71  /* We need only tell the memory manager to release everything. */
72  /* NB: mem pointer is NULL if memory mgr failed to initialize. */
73  if (cinfo->mem != NULL)
74  (*cinfo->mem->self_destruct) (cinfo);
75  cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
76  cinfo->global_state = 0; /* mark it destroyed */
77 }
void(* self_destruct)()
Definition: jpeglib.h:797
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:259
int global_state
Definition: jpeglib.h:259
boolean jpeg_resync_to_restart ( j_decompress_ptr  cinfo,
int  desired 
)
1193 {
1194  int marker = cinfo->unread_marker;
1195  int action = 1;
1196 
1197  /* Always put up a warning. */
1198  WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
1199 
1200  /* Outer loop handles repeated decision after scanning forward. */
1201  for (;;) {
1202  if (marker < (int) M_SOF0)
1203  action = 2; /* invalid marker */
1204  else if (marker < (int) M_RST0 || marker > (int) M_RST7)
1205  action = 3; /* valid non-restart marker */
1206  else {
1207  if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
1208  marker == ((int) M_RST0 + ((desired+2) & 7)))
1209  action = 3; /* one of the next two expected restarts */
1210  else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
1211  marker == ((int) M_RST0 + ((desired-2) & 7)))
1212  action = 2; /* a prior restart, so advance */
1213  else
1214  action = 1; /* desired restart or too far away */
1215  }
1216  TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
1217  switch (action) {
1218  case 1:
1219  /* Discard marker and let entropy decoder resume processing. */
1220  cinfo->unread_marker = 0;
1221  return TRUE;
1222  case 2:
1223  /* Scan to the next marker, and repeat the decision loop. */
1224  if (! next_marker(cinfo))
1225  return FALSE;
1226  marker = cinfo->unread_marker;
1227  break;
1228  case 3:
1229  /* Return without advancing past this marker. */
1230  /* Entropy decoder will be forced to process an empty segment. */
1231  return TRUE;
1232  }
1233  } /* end loop */
1234 }
Definition: jdmarker.cpp:21
#define TRACEMS2(cinfo, lvl, code, p1, p2)
Definition: jerror.h:259
Definition: jerror.h:150
#define WARNMS2(cinfo, code, p1, p2)
Definition: jerror.h:245
#define FALSE
Definition: jpleph.cpp:69
Definition: jdmarker.cpp:50
#define TRUE
Definition: jpleph.cpp:68
Definition: jerror.h:182
static boolean next_marker(j_decompress_ptr cinfo)
Definition: jdmarker.cpp:874
int unread_marker
Definition: jpeglib.h:619
Definition: jdmarker.cpp:43
int read_JPEG_file ( const char *  filename,
vector< vector< uint8_t > > &  image_buffer 
)
422 {
423  FILE *infile;
424 /* This struct contains the JPEG decompression parameters and pointers to
425  * working space (which is allocated as needed by the JPEG library).
426  */
427  struct jpeg_decompress_struct cinfo;
428  /* We use our private extension JPEG error handler.
429  * Note that this struct must live as long as the main JPEG parameter
430  * struct, to avoid dangling-pointer problems.
431  */
432  struct my_error_mgr jerr;
433  /* More stuff */
434  JSAMPARRAY buffer; /* Output row buffer */
435  int row_stride; /* physical row width in output buffer */
436 
437  /* In this example we want to open the input file before doing anything else,
438  * so that the setjmp() error recovery below can assume the file is open.
439  * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
440  * requires it in order to read binary files.
441  */
442 
443  if ((infile = fopen(filename, "rb")) == NULL) {
444  fprintf(stderr, "can't open %s\n", filename);
445  return 0;
446  }
447 
448  /* Step 1: allocate and initialize JPEG decompression object */
449 
450  /* We set up the normal JPEG error routines, then override error_exit. */
451  cinfo.err = jpeg_std_error(&jerr.pub);
452  jerr.pub.error_exit = my_error_exit;
453  /* Establish the setjmp return context for my_error_exit to use. */
454  if (setjmp(jerr.setjmp_buffer))
455  {
456  /* If we get here, the JPEG code has signaled an error.
457  * We need to clean up the JPEG object, close the input file, and return.
458  */
459  jpeg_destroy_decompress(&cinfo);
460  fclose(infile);
461  return 0;
462  }
463  /* Now we can initialize the JPEG decompression object. */
464  jpeg_create_decompress(&cinfo);
465 
466  /* Step 2: specify data source (eg, a file) */
467 
468  jpeg_stdio_src(&cinfo, infile);
469 
470  /* Step 3: read file parameters with jpeg_read_header() */
471 
472  (void) jpeg_read_header(&cinfo, TRUE);
473  /* We can ignore the return value from jpeg_read_header since
474  * (a) suspension is not possible with the stdio data source, and
475  * (b) we passed TRUE to reject a tables-only JPEG file as an error.
476  * See libjpeg.doc for more info.
477  */
478 
479  /* Step 4: set parameters for decompression */
480 
481  /* In this example, we don't need to change any of the defaults set by
482  * jpeg_read_header(), so we do nothing here.
483  */
484 
485  /* Step 5: Start decompressor */
486 
487  (void) jpeg_start_decompress(&cinfo);
488  /* We can ignore the return value since suspension is not possible
489  * with the stdio data source.
490  */
491 
492  /* We may need to do some setup of our own at this point before reading
493  * the data. After jpeg_start_decompress() we have the correct scaled
494  * output image dimensions available, as well as the output colormap
495  * if we asked for color quantization.
496  * In this example, we need to make an output work buffer of the right size.
497  */
498  /* JSAMPLEs per row in output buffer */
499  row_stride = cinfo.output_width * cinfo.output_components;
500  /* Make a one-row-high sample array that will go away when done with image */
501  buffer = (*cinfo.mem->alloc_sarray)
502  ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
503 
504  /* Step 6: while (scan lines remain to be read) */
505  /* jpeg_read_scanlines(...); */
506 
507  /* Here we use the library's state variable cinfo.output_scanline as the
508  * loop counter, so that we don't have to keep track ourselves.
509  */
510 // while (cinfo.output_scanline < cinfo.output_height)
511  image_buffer.resize(cinfo.output_height);
512  for (size_t ih=0; ih<cinfo.output_height; ++ih)
513  {
514  /* jpeg_read_scanlines expects an array of pointers to scanlines.
515  * Here the array is only one element long, but you could ask for
516  * more than one scanline at a time if that's more convenient.
517  */
518  (void) jpeg_read_scanlines(&cinfo, buffer, 1);
519  /* Assume put_scanline_someplace wants a pointer and sample count. */
520  //put_scanline_someplace(buffer[0], row_stride);
521  image_buffer[ih].resize(cinfo.output_width * cinfo.output_components);
522  memcpy((void *)image_buffer[ih].data(), (const void *)buffer[0], row_stride);
523  }
524 
525  /* Step 7: Finish decompression */
526 
527  (void) jpeg_finish_decompress(&cinfo);
528  /* We can ignore the return value since suspension is not possible
529  * with the stdio data source.
530  */
531 
532  /* Step 8: Release JPEG decompression object */
533 
534  /* This is an important step since it will release a good deal of memory. */
535  jpeg_destroy_decompress(&cinfo);
536 
537  /* After finish_decompress, we can close the input file.
538  * Here we postpone it until after no more JPEG errors are possible,
539  * so as to simplify the setjmp error logic above. (Actually, I don't
540  * think that jpeg_destroy can do an error exit, but why assume anything...)
541  */
542  fclose(infile);
543 
544  /* At this point you may want to check to see whether any corrupt-data
545  * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
546  */
547 
548  /* And we're done! */
549  return 1;
550 }
int jpeg_read_header(j_decompress_ptr cinfo, boolean require_image)
Definition: jdapimin.cpp:241
void jpeg_stdio_src(j_decompress_ptr cinfo, FILE *infile)
Definition: jdatasrc.cpp:182
void jpeg_destroy_decompress(j_decompress_ptr cinfo)
Definition: jdapimin.cpp:91
struct jpeg_error_mgr * jpeg_std_error(struct jpeg_error_mgr *err)
Definition: jerror.cpp:232
Definition: jpeglib.h:258
#define jpeg_create_decompress(cinfo)
Definition: jpeglib.h:902
#define JPOOL_IMAGE
Definition: jpeglib.h:754
static char buffer[255]
Definition: propagator_simple.cpp:60
Definition: jpeg_rw.cpp:259
#define TRUE
Definition: jpleph.cpp:68
boolean jpeg_start_decompress(j_decompress_ptr cinfo)
Definition: jdapistd.cpp:38
JSAMPROW * JSAMPARRAY
Definition: jpeglib.h:72
JDIMENSION jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)
Definition: jdapistd.cpp:152
Definition: jpeglib.h:416
static void my_error_exit(j_common_ptr cinfo)
Definition: jpeg_rw.cpp:272
boolean jpeg_finish_decompress(j_decompress_ptr cinfo)
Definition: jdapimin.cpp:369
int read_JPEG_file ( const char *  filename,
JSAMPLE image_buffer 
)
293 {
294  FILE *infile;
295 /* This struct contains the JPEG decompression parameters and pointers to
296  * working space (which is allocated as needed by the JPEG library).
297  */
298  struct jpeg_decompress_struct cinfo;
299  /* We use our private extension JPEG error handler.
300  * Note that this struct must live as long as the main JPEG parameter
301  * struct, to avoid dangling-pointer problems.
302  */
303  struct my_error_mgr jerr;
304  /* More stuff */
305  JSAMPARRAY buffer; /* Output row buffer */
306  int row_stride; /* physical row width in output buffer */
307 
308  /* In this example we want to open the input file before doing anything else,
309  * so that the setjmp() error recovery below can assume the file is open.
310  * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
311  * requires it in order to read binary files.
312  */
313 
314  if ((infile = fopen(filename, "rb")) == NULL) {
315  fprintf(stderr, "can't open %s\n", filename);
316  return 0;
317  }
318 
319  /* Step 1: allocate and initialize JPEG decompression object */
320 
321  /* We set up the normal JPEG error routines, then override error_exit. */
322  cinfo.err = jpeg_std_error(&jerr.pub);
323  jerr.pub.error_exit = my_error_exit;
324  /* Establish the setjmp return context for my_error_exit to use. */
325  if (setjmp(jerr.setjmp_buffer))
326  {
327  /* If we get here, the JPEG code has signaled an error.
328  * We need to clean up the JPEG object, close the input file, and return.
329  */
330  jpeg_destroy_decompress(&cinfo);
331  fclose(infile);
332  return 0;
333  }
334  /* Now we can initialize the JPEG decompression object. */
335  jpeg_create_decompress(&cinfo);
336 
337  /* Step 2: specify data source (eg, a file) */
338 
339  jpeg_stdio_src(&cinfo, infile);
340 
341  /* Step 3: read file parameters with jpeg_read_header() */
342 
343  (void) jpeg_read_header(&cinfo, TRUE);
344  /* We can ignore the return value from jpeg_read_header since
345  * (a) suspension is not possible with the stdio data source, and
346  * (b) we passed TRUE to reject a tables-only JPEG file as an error.
347  * See libjpeg.doc for more info.
348  */
349 
350  /* Step 4: set parameters for decompression */
351 
352  /* In this example, we don't need to change any of the defaults set by
353  * jpeg_read_header(), so we do nothing here.
354  */
355 
356  /* Step 5: Start decompressor */
357 
358  (void) jpeg_start_decompress(&cinfo);
359  /* We can ignore the return value since suspension is not possible
360  * with the stdio data source.
361  */
362 
363  /* We may need to do some setup of our own at this point before reading
364  * the data. After jpeg_start_decompress() we have the correct scaled
365  * output image dimensions available, as well as the output colormap
366  * if we asked for color quantization.
367  * In this example, we need to make an output work buffer of the right size.
368  */
369  /* JSAMPLEs per row in output buffer */
370  row_stride = cinfo.output_width * cinfo.output_components;
371  /* Make a one-row-high sample array that will go away when done with image */
372  buffer = (*cinfo.mem->alloc_sarray)
373  ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
374 
375  /* Step 6: while (scan lines remain to be read) */
376  /* jpeg_read_scanlines(...); */
377 
378  /* Here we use the library's state variable cinfo.output_scanline as the
379  * loop counter, so that we don't have to keep track ourselves.
380  */
381  while (cinfo.output_scanline < cinfo.output_height) {
382  /* jpeg_read_scanlines expects an array of pointers to scanlines.
383  * Here the array is only one element long, but you could ask for
384  * more than one scanline at a time if that's more convenient.
385  */
386  (void) jpeg_read_scanlines(&cinfo, buffer, 1);
387  /* Assume put_scanline_someplace wants a pointer and sample count. */
388  //put_scanline_someplace(buffer[0], row_stride);
389  memcpy((void *)image_buffer, (const void *)buffer[0], row_stride);
390  image_buffer += row_stride;
391  }
392 
393  /* Step 7: Finish decompression */
394 
395  (void) jpeg_finish_decompress(&cinfo);
396  /* We can ignore the return value since suspension is not possible
397  * with the stdio data source.
398  */
399 
400  /* Step 8: Release JPEG decompression object */
401 
402  /* This is an important step since it will release a good deal of memory. */
403  jpeg_destroy_decompress(&cinfo);
404 
405  /* After finish_decompress, we can close the input file.
406  * Here we postpone it until after no more JPEG errors are possible,
407  * so as to simplify the setjmp error logic above. (Actually, I don't
408  * think that jpeg_destroy can do an error exit, but why assume anything...)
409  */
410  fclose(infile);
411 
412  /* At this point you may want to check to see whether any corrupt-data
413  * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
414  */
415 
416  /* And we're done! */
417  return 1;
418 }
int jpeg_read_header(j_decompress_ptr cinfo, boolean require_image)
Definition: jdapimin.cpp:241
void jpeg_stdio_src(j_decompress_ptr cinfo, FILE *infile)
Definition: jdatasrc.cpp:182
void jpeg_destroy_decompress(j_decompress_ptr cinfo)
Definition: jdapimin.cpp:91
struct jpeg_error_mgr * jpeg_std_error(struct jpeg_error_mgr *err)
Definition: jerror.cpp:232
Definition: jpeglib.h:258
#define jpeg_create_decompress(cinfo)
Definition: jpeglib.h:902
#define JPOOL_IMAGE
Definition: jpeglib.h:754
static char buffer[255]
Definition: propagator_simple.cpp:60
Definition: jpeg_rw.cpp:259
#define TRUE
Definition: jpleph.cpp:68
boolean jpeg_start_decompress(j_decompress_ptr cinfo)
Definition: jdapistd.cpp:38
JSAMPROW * JSAMPARRAY
Definition: jpeglib.h:72
JDIMENSION jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)
Definition: jdapistd.cpp:152
Definition: jpeglib.h:416
static void my_error_exit(j_common_ptr cinfo)
Definition: jpeg_rw.cpp:272
boolean jpeg_finish_decompress(j_decompress_ptr cinfo)
Definition: jdapimin.cpp:369
void write_JPEG_file ( const char *  filename,
int  quality,
J_COLOR_SPACE  in_color_space,
int  image_width,
int  image_height,
JSAMPLE image_buffer 
)