COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
jcmarker.cpp File Reference
#include "jinclude.h"
#include "jpeglib.h"
Include dependency graph for jcmarker.cpp:

Classes

struct  my_marker_writer
 

Macros

#define JPEG_INTERNALS
 

Typedefs

typedef my_marker_writermy_marker_ptr
 

Enumerations

enum  JPEG_MARKER {
  M_SOF0 = 0xc0, M_SOF1 = 0xc1, M_SOF2 = 0xc2, M_SOF3 = 0xc3,
  M_SOF5 = 0xc5, M_SOF6 = 0xc6, M_SOF7 = 0xc7, M_JPG = 0xc8,
  M_SOF9 = 0xc9, M_SOF10 = 0xca, M_SOF11 = 0xcb, M_SOF13 = 0xcd,
  M_SOF14 = 0xce, M_SOF15 = 0xcf, M_DHT = 0xc4, M_DAC = 0xcc,
  M_RST0 = 0xd0, M_RST1 = 0xd1, M_RST2 = 0xd2, M_RST3 = 0xd3,
  M_RST4 = 0xd4, M_RST5 = 0xd5, M_RST6 = 0xd6, M_RST7 = 0xd7,
  M_SOI = 0xd8, M_EOI = 0xd9, M_SOS = 0xda, M_DQT = 0xdb,
  M_DNL = 0xdc, M_DRI = 0xdd, M_DHP = 0xde, M_EXP = 0xdf,
  M_APP0 = 0xe0, M_APP1 = 0xe1, M_APP2 = 0xe2, M_APP3 = 0xe3,
  M_APP4 = 0xe4, M_APP5 = 0xe5, M_APP6 = 0xe6, M_APP7 = 0xe7,
  M_APP8 = 0xe8, M_APP9 = 0xe9, M_APP10 = 0xea, M_APP11 = 0xeb,
  M_APP12 = 0xec, M_APP13 = 0xed, M_APP14 = 0xee, M_APP15 = 0xef,
  M_JPG0 = 0xf0, M_JPG13 = 0xfd, M_COM = 0xfe, M_TEM = 0x01,
  M_ERROR = 0x100, M_SOF0 = 0xc0, M_SOF1 = 0xc1, M_SOF2 = 0xc2,
  M_SOF3 = 0xc3, M_SOF5 = 0xc5, M_SOF6 = 0xc6, M_SOF7 = 0xc7,
  M_JPG = 0xc8, M_SOF9 = 0xc9, M_SOF10 = 0xca, M_SOF11 = 0xcb,
  M_SOF13 = 0xcd, M_SOF14 = 0xce, M_SOF15 = 0xcf, M_DHT = 0xc4,
  M_DAC = 0xcc, M_RST0 = 0xd0, M_RST1 = 0xd1, M_RST2 = 0xd2,
  M_RST3 = 0xd3, M_RST4 = 0xd4, M_RST5 = 0xd5, M_RST6 = 0xd6,
  M_RST7 = 0xd7, M_SOI = 0xd8, M_EOI = 0xd9, M_SOS = 0xda,
  M_DQT = 0xdb, M_DNL = 0xdc, M_DRI = 0xdd, M_DHP = 0xde,
  M_EXP = 0xdf, M_APP0 = 0xe0, M_APP1 = 0xe1, M_APP2 = 0xe2,
  M_APP3 = 0xe3, M_APP4 = 0xe4, M_APP5 = 0xe5, M_APP6 = 0xe6,
  M_APP7 = 0xe7, M_APP8 = 0xe8, M_APP9 = 0xe9, M_APP10 = 0xea,
  M_APP11 = 0xeb, M_APP12 = 0xec, M_APP13 = 0xed, M_APP14 = 0xee,
  M_APP15 = 0xef, M_JPG0 = 0xf0, M_JPG13 = 0xfd, M_COM = 0xfe,
  M_TEM = 0x01, M_ERROR = 0x100
}
 

Functions

static void emit_byte (j_compress_ptr cinfo, int val)
 
static void emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
 
static void emit_2bytes (j_compress_ptr cinfo, int value)
 
static int emit_dqt (j_compress_ptr cinfo, int index)
 
static void emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
 
static void emit_dac (j_compress_ptr cinfo)
 
static void emit_dri (j_compress_ptr cinfo)
 
static void emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
 
static void emit_sos (j_compress_ptr cinfo)
 
static void emit_jfif_app0 (j_compress_ptr cinfo)
 
static void emit_adobe_app14 (j_compress_ptr cinfo)
 
static void write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
 
static void write_marker_byte (j_compress_ptr cinfo, int val)
 
static void write_file_header (j_compress_ptr cinfo)
 
static void write_frame_header (j_compress_ptr cinfo)
 
static void write_scan_header (j_compress_ptr cinfo)
 
static void write_file_trailer (j_compress_ptr cinfo)
 
static void write_tables_only (j_compress_ptr cinfo)
 
void jinit_marker_writer (j_compress_ptr cinfo)
 

Macro Definition Documentation

#define JPEG_INTERNALS

Typedef Documentation

Enumeration Type Documentation

Enumerator
M_SOF0 
M_SOF1 
M_SOF2 
M_SOF3 
M_SOF5 
M_SOF6 
M_SOF7 
M_JPG 
M_SOF9 
M_SOF10 
M_SOF11 
M_SOF13 
M_SOF14 
M_SOF15 
M_DHT 
M_DAC 
M_RST0 
M_RST1 
M_RST2 
M_RST3 
M_RST4 
M_RST5 
M_RST6 
M_RST7 
M_SOI 
M_EOI 
M_SOS 
M_DQT 
M_DNL 
M_DRI 
M_DHP 
M_EXP 
M_APP0 
M_APP1 
M_APP2 
M_APP3 
M_APP4 
M_APP5 
M_APP6 
M_APP7 
M_APP8 
M_APP9 
M_APP10 
M_APP11 
M_APP12 
M_APP13 
M_APP14 
M_APP15 
M_JPG0 
M_JPG13 
M_COM 
M_TEM 
M_ERROR 
M_SOF0 
M_SOF1 
M_SOF2 
M_SOF3 
M_SOF5 
M_SOF6 
M_SOF7 
M_JPG 
M_SOF9 
M_SOF10 
M_SOF11 
M_SOF13 
M_SOF14 
M_SOF15 
M_DHT 
M_DAC 
M_RST0 
M_RST1 
M_RST2 
M_RST3 
M_RST4 
M_RST5 
M_RST6 
M_RST7 
M_SOI 
M_EOI 
M_SOS 
M_DQT 
M_DNL 
M_DRI 
M_DHP 
M_EXP 
M_APP0 
M_APP1 
M_APP2 
M_APP3 
M_APP4 
M_APP5 
M_APP6 
M_APP7 
M_APP8 
M_APP9 
M_APP10 
M_APP11 
M_APP12 
M_APP13 
M_APP14 
M_APP15 
M_JPG0 
M_JPG13 
M_COM 
M_TEM 
M_ERROR 
16  { /* JPEG marker codes */
17  M_SOF0 = 0xc0,
18  M_SOF1 = 0xc1,
19  M_SOF2 = 0xc2,
20  M_SOF3 = 0xc3,
21 
22  M_SOF5 = 0xc5,
23  M_SOF6 = 0xc6,
24  M_SOF7 = 0xc7,
25 
26  M_JPG = 0xc8,
27  M_SOF9 = 0xc9,
28  M_SOF10 = 0xca,
29  M_SOF11 = 0xcb,
30 
31  M_SOF13 = 0xcd,
32  M_SOF14 = 0xce,
33  M_SOF15 = 0xcf,
34 
35  M_DHT = 0xc4,
36 
37  M_DAC = 0xcc,
38 
39  M_RST0 = 0xd0,
40  M_RST1 = 0xd1,
41  M_RST2 = 0xd2,
42  M_RST3 = 0xd3,
43  M_RST4 = 0xd4,
44  M_RST5 = 0xd5,
45  M_RST6 = 0xd6,
46  M_RST7 = 0xd7,
47 
48  M_SOI = 0xd8,
49  M_EOI = 0xd9,
50  M_SOS = 0xda,
51  M_DQT = 0xdb,
52  M_DNL = 0xdc,
53  M_DRI = 0xdd,
54  M_DHP = 0xde,
55  M_EXP = 0xdf,
56 
57  M_APP0 = 0xe0,
58  M_APP1 = 0xe1,
59  M_APP2 = 0xe2,
60  M_APP3 = 0xe3,
61  M_APP4 = 0xe4,
62  M_APP5 = 0xe5,
63  M_APP6 = 0xe6,
64  M_APP7 = 0xe7,
65  M_APP8 = 0xe8,
66  M_APP9 = 0xe9,
67  M_APP10 = 0xea,
68  M_APP11 = 0xeb,
69  M_APP12 = 0xec,
70  M_APP13 = 0xed,
71  M_APP14 = 0xee,
72  M_APP15 = 0xef,
73 
74  M_JPG0 = 0xf0,
75  M_JPG13 = 0xfd,
76  M_COM = 0xfe,
77 
78  M_TEM = 0x01,
79 
80  M_ERROR = 0x100
81 } JPEG_MARKER;
Definition: jcmarker.cpp:26
Definition: jcmarker.cpp:58
Definition: jcmarker.cpp:60
Definition: jcmarker.cpp:75
Definition: jcmarker.cpp:31
Definition: jcmarker.cpp:49
Definition: jcmarker.cpp:37
Definition: jcmarker.cpp:70
Definition: jcmarker.cpp:46
Definition: jcmarker.cpp:32
Definition: jcmarker.cpp:78
Definition: jcmarker.cpp:53
Definition: jcmarker.cpp:33
Definition: jcmarker.cpp:62
Definition: jcmarker.cpp:74
Definition: jcmarker.cpp:39
Definition: jcmarker.cpp:71
Definition: jcmarker.cpp:64
Definition: jcmarker.cpp:69
Definition: jcmarker.cpp:65
Definition: jcmarker.cpp:22
Definition: jcmarker.cpp:20
Definition: jcmarker.cpp:76
Definition: jcmarker.cpp:23
Definition: jcmarker.cpp:57
Definition: jcmarker.cpp:19
Definition: jcmarker.cpp:54
Definition: jcmarker.cpp:50
Definition: jcmarker.cpp:40
Definition: jcmarker.cpp:59
Definition: jcmarker.cpp:66
Definition: jcmarker.cpp:17
Definition: jcmarker.cpp:43
Definition: jcmarker.cpp:41
Definition: jcmarker.cpp:80
Definition: jcmarker.cpp:61
Definition: jcmarker.cpp:35
Definition: jcmarker.cpp:63
Definition: jcmarker.cpp:44
Definition: jcmarker.cpp:42
JPEG_MARKER
Definition: jcmarker.cpp:16
Definition: jcmarker.cpp:51
Definition: jcmarker.cpp:68
Definition: jcmarker.cpp:67
Definition: jcmarker.cpp:72
Definition: jcmarker.cpp:27
Definition: jcmarker.cpp:45
Definition: jcmarker.cpp:24
Definition: jcmarker.cpp:55
Definition: jcmarker.cpp:52
Definition: jcmarker.cpp:29
Definition: jcmarker.cpp:28
Definition: jcmarker.cpp:48
Definition: jcmarker.cpp:18

Function Documentation

static void emit_byte ( j_compress_ptr  cinfo,
int  val 
)
static
110 {
111  struct jpeg_destination_mgr * dest = cinfo->dest;
112 
113  *(dest->next_output_byte)++ = (JOCTET) val;
114  if (--dest->free_in_buffer == 0) {
115  if (! (*dest->empty_output_buffer) (cinfo))
116  ERREXIT(cinfo, JERR_CANT_SUSPEND);
117  }
118 }
size_t free_in_buffer
Definition: jpeglib.h:720
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:277
Definition: jpeglib.h:718
boolean(* empty_output_buffer)()
Definition: jpeglib.h:723
Definition: jerror.h:70
char JOCTET
Definition: jmorecfg.h:115
JOCTET * next_output_byte
Definition: jpeglib.h:719
static void emit_marker ( j_compress_ptr  cinfo,
JPEG_MARKER  mark 
)
static
124 {
125  emit_byte(cinfo, 0xFF);
126  emit_byte(cinfo, (int) mark);
127 }
static void emit_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:108
static void emit_2bytes ( j_compress_ptr  cinfo,
int  value 
)
static
133 {
134  emit_byte(cinfo, (value >> 8) & 0xFF);
135  emit_byte(cinfo, value & 0xFF);
136 }
static void emit_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:108
static int emit_dqt ( j_compress_ptr  cinfo,
int  index 
)
static
147 {
148  JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
149  int prec;
150  int i;
151 
152  if (qtbl == NULL)
153  ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
154 
155  prec = 0;
156  for (i = 0; i < DCTSIZE2; i++) {
157  if (qtbl->quantval[i] > 255)
158  prec = 1;
159  }
160 
161  if (! qtbl->sent_table) {
162  emit_marker(cinfo, M_DQT);
163 
164  emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
165 
166  emit_byte(cinfo, index + (prec<<4));
167 
168  for (i = 0; i < DCTSIZE2; i++) {
169  /* The table entries must be emitted in zigzag order. */
170  unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
171  if (prec)
172  emit_byte(cinfo, (int) (qval >> 8));
173  emit_byte(cinfo, (int) (qval & 0xFF));
174  }
175 
176  qtbl->sent_table = TRUE;
177  }
178 
179  return prec;
180 }
int i
Definition: rw_test.cpp:37
JQUANT_TBL * quant_tbl_ptrs[4]
Definition: jpeglib.h:307
const int jpeg_natural_order[]
Definition: jutils.cpp:53
boolean sent_table
Definition: jpeglib.h:99
Definition: jpeglib.h:88
static void emit_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:108
uint16_t quantval[64]
Definition: jpeglib.h:93
static void emit_2bytes(j_compress_ptr cinfo, int value)
Definition: jcmarker.cpp:131
#define DCTSIZE2
Definition: jpeglib.h:47
Definition: jerror.h:99
#define TRUE
Definition: jpleph.cpp:68
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
Definition: jcmarker.cpp:51
static void emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
Definition: jcmarker.cpp:122
static void emit_dht ( j_compress_ptr  cinfo,
int  index,
boolean  is_ac 
)
static
186 {
187  JHUFF_TBL * htbl;
188  int length, i;
189 
190  if (is_ac) {
191  htbl = cinfo->ac_huff_tbl_ptrs[index];
192  index += 0x10; /* output index has AC bit set */
193  } else {
194  htbl = cinfo->dc_huff_tbl_ptrs[index];
195  }
196 
197  if (htbl == NULL)
198  ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
199 
200  if (! htbl->sent_table) {
201  emit_marker(cinfo, M_DHT);
202 
203  length = 0;
204  for (i = 1; i <= 16; i++)
205  length += htbl->bits[i];
206 
207  emit_2bytes(cinfo, length + 2 + 1 + 16);
208  emit_byte(cinfo, index);
209 
210  for (i = 1; i <= 16; i++)
211  emit_byte(cinfo, htbl->bits[i]);
212 
213  for (i = 0; i < length; i++)
214  emit_byte(cinfo, htbl->huffval[i]);
215 
216  htbl->sent_table = TRUE;
217  }
218 }
int i
Definition: rw_test.cpp:37
static void emit_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:108
Definition: jerror.h:97
static void emit_2bytes(j_compress_ptr cinfo, int value)
Definition: jcmarker.cpp:131
uint8_t huffval[256]
Definition: jpeglib.h:109
#define TRUE
Definition: jpleph.cpp:68
uint8_t bits[17]
Definition: jpeglib.h:107
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
Definition: jcmarker.cpp:35
boolean sent_table
Definition: jpeglib.h:115
png_uint_32 length
Definition: png.c:2173
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
static void emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
Definition: jcmarker.cpp:122
static void emit_dac ( j_compress_ptr  cinfo)
static
226 {
227 #ifdef C_ARITH_CODING_SUPPORTED
228  char dc_in_use[NUM_ARITH_TBLS];
229  char ac_in_use[NUM_ARITH_TBLS];
230  int length, i;
232 
233  for (i = 0; i < NUM_ARITH_TBLS; i++)
234  dc_in_use[i] = ac_in_use[i] = 0;
235 
236  for (i = 0; i < cinfo->comps_in_scan; i++) {
237  compptr = cinfo->cur_comp_info[i];
238  dc_in_use[compptr->dc_tbl_no] = 1;
239  ac_in_use[compptr->ac_tbl_no] = 1;
240  }
241 
242  length = 0;
243  for (i = 0; i < NUM_ARITH_TBLS; i++)
244  length += dc_in_use[i] + ac_in_use[i];
245 
246  emit_marker(cinfo, M_DAC);
247 
248  emit_2bytes(cinfo, length*2 + 2);
249 
250  for (i = 0; i < NUM_ARITH_TBLS; i++) {
251  if (dc_in_use[i]) {
252  emit_byte(cinfo, i);
253  emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
254  }
255  if (ac_in_use[i]) {
256  emit_byte(cinfo, i + 0x10);
257  emit_byte(cinfo, cinfo->arith_ac_K[i]);
258  }
259  }
260 #endif /* C_ARITH_CODING_SUPPORTED */
261 }
Definition: jcmarker.cpp:37
int i
Definition: rw_test.cpp:37
int dc_tbl_no
Definition: jpeglib.h:134
static void emit_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:108
jpeg_component_info * compptr
Definition: jdct.h:102
int ac_tbl_no
Definition: jpeglib.h:135
static void emit_2bytes(j_compress_ptr cinfo, int value)
Definition: jcmarker.cpp:131
uint8_t arith_ac_K[16]
Definition: jpeglib.h:316
Definition: jpeglib.h:121
uint8_t arith_dc_L[16]
Definition: jpeglib.h:314
png_uint_32 length
Definition: png.c:2173
int comps_in_scan
Definition: jpeglib.h:383
#define NUM_ARITH_TBLS
Definition: jpeglib.h:50
jpeg_component_info * cur_comp_info[4]
Definition: jpeglib.h:384
uint8_t arith_dc_U[16]
Definition: jpeglib.h:315
static void emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
Definition: jcmarker.cpp:122
static void emit_dri ( j_compress_ptr  cinfo)
static
267 {
268  emit_marker(cinfo, M_DRI);
269 
270  emit_2bytes(cinfo, 4); /* fixed length */
271 
272  emit_2bytes(cinfo, (int) cinfo->restart_interval);
273 }
Definition: jcmarker.cpp:53
static void emit_2bytes(j_compress_ptr cinfo, int value)
Definition: jcmarker.cpp:131
unsigned int restart_interval
Definition: jpeglib.h:337
static void emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
Definition: jcmarker.cpp:122
static void emit_sof ( j_compress_ptr  cinfo,
JPEG_MARKER  code 
)
static
279 {
280  int ci;
282 
283  emit_marker(cinfo, code);
284 
285  emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
286 
287  /* Make sure image isn't bigger than SOF field can handle */
288  if ((long) cinfo->image_height > 65535L ||
289  (long) cinfo->image_width > 65535L)
290  ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
291 
292  emit_byte(cinfo, cinfo->data_precision);
293  emit_2bytes(cinfo, (int) cinfo->image_height);
294  emit_2bytes(cinfo, (int) cinfo->image_width);
295 
296  emit_byte(cinfo, cinfo->num_components);
297 
298  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
299  ci++, compptr++) {
300  emit_byte(cinfo, compptr->component_id);
301  emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
302  emit_byte(cinfo, compptr->quant_tbl_no);
303  }
304 }
int v_samp_factor
Definition: jpeglib.h:128
JDIMENSION image_height
Definition: jpeglib.h:285
int num_components
Definition: jpeglib.h:301
static void emit_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:108
jpeg_component_info * compptr
Definition: jdct.h:102
int data_precision
Definition: jpeglib.h:299
static void emit_2bytes(j_compress_ptr cinfo, int value)
Definition: jcmarker.cpp:131
int quant_tbl_no
Definition: jpeglib.h:129
int component_id
Definition: jpeglib.h:125
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
Definition: inftrees.h:24
Definition: jpeglib.h:121
int h_samp_factor
Definition: jpeglib.h:127
Definition: jerror.h:87
static void emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
Definition: jcmarker.cpp:122
jpeg_component_info * comp_info
Definition: jpeglib.h:304
JDIMENSION image_width
Definition: jpeglib.h:284
static void emit_sos ( j_compress_ptr  cinfo)
static
310 {
311  int i, td, ta;
313 
314  emit_marker(cinfo, M_SOS);
315 
316  emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
317 
318  emit_byte(cinfo, cinfo->comps_in_scan);
319 
320  for (i = 0; i < cinfo->comps_in_scan; i++) {
321  compptr = cinfo->cur_comp_info[i];
322  emit_byte(cinfo, compptr->component_id);
323  td = compptr->dc_tbl_no;
324  ta = compptr->ac_tbl_no;
325  if (cinfo->progressive_mode) {
326  /* Progressive mode: only DC or only AC tables are used in one scan;
327  * furthermore, Huffman coding of DC refinement uses no table at all.
328  * We emit 0 for unused field(s); this is recommended by the P&M text
329  * but does not seem to be specified in the standard.
330  */
331  if (cinfo->Ss == 0) {
332  ta = 0; /* DC scan */
333  if (cinfo->Ah != 0 && !cinfo->arith_code)
334  td = 0; /* no DC table either */
335  } else {
336  td = 0; /* AC scan */
337  }
338  }
339  emit_byte(cinfo, (td << 4) + ta);
340  }
341 
342  emit_byte(cinfo, cinfo->Ss);
343  emit_byte(cinfo, cinfo->Se);
344  emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
345 }
Definition: eci2kep_test.cpp:33
int i
Definition: rw_test.cpp:37
int Ss
Definition: jpeglib.h:395
int dc_tbl_no
Definition: jpeglib.h:134
static void emit_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:108
jpeg_component_info * compptr
Definition: jdct.h:102
int ac_tbl_no
Definition: jpeglib.h:135
static void emit_2bytes(j_compress_ptr cinfo, int value)
Definition: jcmarker.cpp:131
int component_id
Definition: jpeglib.h:125
Definition: jcmarker.cpp:50
int Se
Definition: jpeglib.h:395
int Ah
Definition: jpeglib.h:395
boolean arith_code
Definition: jpeglib.h:326
boolean progressive_mode
Definition: jpeglib.h:368
int Al
Definition: jpeglib.h:395
Definition: jpeglib.h:121
int comps_in_scan
Definition: jpeglib.h:383
jpeg_component_info * cur_comp_info[4]
Definition: jpeglib.h:384
static void emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
Definition: jcmarker.cpp:122
static void emit_jfif_app0 ( j_compress_ptr  cinfo)
static
351 {
352  /*
353  * Length of APP0 block (2 bytes)
354  * Block ID (4 bytes - ASCII "JFIF")
355  * Zero byte (1 byte to terminate the ID string)
356  * Version Major, Minor (2 bytes - major first)
357  * Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
358  * Xdpu (2 bytes - dots per unit horizontal)
359  * Ydpu (2 bytes - dots per unit vertical)
360  * Thumbnail X size (1 byte)
361  * Thumbnail Y size (1 byte)
362  */
363 
364  emit_marker(cinfo, M_APP0);
365 
366  emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
367 
368  emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
369  emit_byte(cinfo, 0x46);
370  emit_byte(cinfo, 0x49);
371  emit_byte(cinfo, 0x46);
372  emit_byte(cinfo, 0);
373  emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
374  emit_byte(cinfo, cinfo->JFIF_minor_version);
375  emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
376  emit_2bytes(cinfo, (int) cinfo->X_density);
377  emit_2bytes(cinfo, (int) cinfo->Y_density);
378  emit_byte(cinfo, 0); /* No thumbnail image */
379  emit_byte(cinfo, 0);
380 }
static void emit_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:108
static void emit_2bytes(j_compress_ptr cinfo, int value)
Definition: jcmarker.cpp:131
Definition: jcmarker.cpp:57
uint8_t density_unit
Definition: jpeglib.h:349
uint16_t X_density
Definition: jpeglib.h:350
uint8_t JFIF_minor_version
Definition: jpeglib.h:344
uint8_t JFIF_major_version
Definition: jpeglib.h:343
uint16_t Y_density
Definition: jpeglib.h:351
static void emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
Definition: jcmarker.cpp:122
static void emit_adobe_app14 ( j_compress_ptr  cinfo)
static
386 {
387  /*
388  * Length of APP14 block (2 bytes)
389  * Block ID (5 bytes - ASCII "Adobe")
390  * Version Number (2 bytes - currently 100)
391  * Flags0 (2 bytes - currently 0)
392  * Flags1 (2 bytes - currently 0)
393  * Color transform (1 byte)
394  *
395  * Although Adobe TN 5116 mentions Version = 101, all the Adobe files
396  * now in circulation seem to use Version = 100, so that's what we write.
397  *
398  * We write the color transform byte as 1 if the JPEG color space is
399  * YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with
400  * whether the encoder performed a transformation, which is pretty useless.
401  */
402 
403  emit_marker(cinfo, M_APP14);
404 
405  emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
406 
407  emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
408  emit_byte(cinfo, 0x64);
409  emit_byte(cinfo, 0x6F);
410  emit_byte(cinfo, 0x62);
411  emit_byte(cinfo, 0x65);
412  emit_2bytes(cinfo, 100); /* Version */
413  emit_2bytes(cinfo, 0); /* Flags0 */
414  emit_2bytes(cinfo, 0); /* Flags1 */
415  switch (cinfo->jpeg_color_space) {
416  case JCS_YCbCr:
417  emit_byte(cinfo, 1); /* Color transform = 1 */
418  break;
419  case JCS_YCCK:
420  emit_byte(cinfo, 2); /* Color transform = 2 */
421  break;
422  default:
423  emit_byte(cinfo, 0); /* Color transform = 0 */
424  break;
425  }
426 }
Definition: jpeglib.h:217
J_COLOR_SPACE jpeg_color_space
Definition: jpeglib.h:302
static void emit_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:108
Definition: jcmarker.cpp:71
static void emit_2bytes(j_compress_ptr cinfo, int value)
Definition: jcmarker.cpp:131
Definition: jpeglib.h:215
static void emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
Definition: jcmarker.cpp:122
static void write_marker_header ( j_compress_ptr  cinfo,
int  marker,
unsigned int  datalen 
)
static
440 {
441  if (datalen > (unsigned int) 65533) /* safety check */
442  ERREXIT(cinfo, JERR_BAD_LENGTH);
443 
444  emit_marker(cinfo, (JPEG_MARKER) marker);
445 
446  emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
447 }
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jerror.h:53
static void emit_2bytes(j_compress_ptr cinfo, int value)
Definition: jcmarker.cpp:131
int datalen
Definition: mcastclient.c:41
JPEG_MARKER
Definition: jcmarker.cpp:16
static void emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
Definition: jcmarker.cpp:122
static void write_marker_byte ( j_compress_ptr  cinfo,
int  val 
)
static
452 {
453  emit_byte(cinfo, val);
454 }
static void emit_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:108
static void write_file_header ( j_compress_ptr  cinfo)
static
470 {
471  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
472 
473  emit_marker(cinfo, M_SOI); /* first the SOI */
474 
475  /* SOI is defined to reset restart interval to 0 */
476  marker->last_restart_interval = 0;
477 
478  if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
479  emit_jfif_app0(cinfo);
480  if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
481  emit_adobe_app14(cinfo);
482 }
boolean write_Adobe_marker
Definition: jpeglib.h:352
static void emit_adobe_app14(j_compress_ptr cinfo)
Definition: jcmarker.cpp:384
unsigned int last_restart_interval
Definition: jcmarker.cpp:89
boolean write_JFIF_header
Definition: jpeglib.h:342
static void emit_jfif_app0(j_compress_ptr cinfo)
Definition: jcmarker.cpp:349
struct jpeg_marker_writer * marker
Definition: jpeglib.h:404
my_marker_writer * my_marker_ptr
Definition: jcmarker.cpp:92
static void emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
Definition: jcmarker.cpp:122
Definition: jcmarker.cpp:48
Definition: jcmarker.cpp:86
static void write_frame_header ( j_compress_ptr  cinfo)
static
495 {
496  int ci, prec;
497  boolean is_baseline;
499 
500  /* Emit DQT for each quantization table.
501  * Note that emit_dqt() suppresses any duplicate tables.
502  */
503  prec = 0;
504  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
505  ci++, compptr++) {
506  prec += emit_dqt(cinfo, compptr->quant_tbl_no);
507  }
508  /* now prec is nonzero iff there are any 16-bit quant tables. */
509 
510  /* Check for a non-baseline specification.
511  * Note we assume that Huffman table numbers won't be changed later.
512  */
513  if (cinfo->arith_code || cinfo->progressive_mode ||
514  cinfo->data_precision != 8) {
515  is_baseline = FALSE;
516  } else {
517  is_baseline = TRUE;
518  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519  ci++, compptr++) {
520  if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
521  is_baseline = FALSE;
522  }
523  if (prec && is_baseline) {
524  is_baseline = FALSE;
525  /* If it's baseline except for quantizer size, warn the user */
526  TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
527  }
528  }
529 
530  /* Emit the proper SOF marker */
531  if (cinfo->arith_code) {
532  emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
533  } else {
534  if (cinfo->progressive_mode)
535  emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
536  else if (is_baseline)
537  emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
538  else
539  emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
540  }
541 }
int dc_tbl_no
Definition: jpeglib.h:134
jpeg_component_info * compptr
Definition: jdct.h:102
#define TRACEMS(cinfo, lvl, code)
Definition: jerror.h:252
int ac_tbl_no
Definition: jpeglib.h:135
int data_precision
Definition: jpeglib.h:299
static int emit_dqt(j_compress_ptr cinfo, int index)
Definition: jcmarker.cpp:144
#define FALSE
Definition: jpleph.cpp:69
Definition: jcmarker.cpp:19
int quant_tbl_no
Definition: jpeglib.h:129
static void emit_sof(j_compress_ptr cinfo, JPEG_MARKER code)
Definition: jcmarker.cpp:277
Definition: jcmarker.cpp:17
#define TRUE
Definition: jpleph.cpp:68
boolean arith_code
Definition: jpeglib.h:326
boolean progressive_mode
Definition: jpeglib.h:368
Definition: jpeglib.h:121
Definition: jerror.h:125
Definition: jcmarker.cpp:27
jpeg_component_info * comp_info
Definition: jpeglib.h:304
Definition: jcmarker.cpp:18
static void write_scan_header ( j_compress_ptr  cinfo)
static
552 {
553  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
554  int i;
556 
557  if (cinfo->arith_code) {
558  /* Emit arith conditioning info. We may have some duplication
559  * if the file has multiple scans, but it's so small it's hardly
560  * worth worrying about.
561  */
562  emit_dac(cinfo);
563  } else {
564  /* Emit Huffman tables.
565  * Note that emit_dht() suppresses any duplicate tables.
566  */
567  for (i = 0; i < cinfo->comps_in_scan; i++) {
568  compptr = cinfo->cur_comp_info[i];
569  if (cinfo->progressive_mode) {
570  /* Progressive mode: only DC or only AC tables are used in one scan */
571  if (cinfo->Ss == 0) {
572  if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
573  emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
574  } else {
575  emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
576  }
577  } else {
578  /* Sequential mode: need both DC and AC tables */
579  emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
580  emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
581  }
582  }
583  }
584 
585  /* Emit DRI if required --- note that DRI value could change for each scan.
586  * We avoid wasting space with unnecessary DRIs, however.
587  */
588  if (cinfo->restart_interval != marker->last_restart_interval) {
589  emit_dri(cinfo);
590  marker->last_restart_interval = cinfo->restart_interval;
591  }
592 
593  emit_sos(cinfo);
594 }
int i
Definition: rw_test.cpp:37
static void emit_dht(j_compress_ptr cinfo, int index, boolean is_ac)
Definition: jcmarker.cpp:184
int Ss
Definition: jpeglib.h:395
int dc_tbl_no
Definition: jpeglib.h:134
unsigned int last_restart_interval
Definition: jcmarker.cpp:89
jpeg_component_info * compptr
Definition: jdct.h:102
int ac_tbl_no
Definition: jpeglib.h:135
#define FALSE
Definition: jpleph.cpp:69
struct jpeg_marker_writer * marker
Definition: jpeglib.h:404
#define TRUE
Definition: jpleph.cpp:68
unsigned int restart_interval
Definition: jpeglib.h:337
static void emit_sos(j_compress_ptr cinfo)
Definition: jcmarker.cpp:308
int Ah
Definition: jpeglib.h:395
boolean arith_code
Definition: jpeglib.h:326
boolean progressive_mode
Definition: jpeglib.h:368
Definition: jpeglib.h:121
static void emit_dac(j_compress_ptr cinfo)
Definition: jcmarker.cpp:222
int comps_in_scan
Definition: jpeglib.h:383
static void emit_dri(j_compress_ptr cinfo)
Definition: jcmarker.cpp:265
jpeg_component_info * cur_comp_info[4]
Definition: jpeglib.h:384
my_marker_writer * my_marker_ptr
Definition: jcmarker.cpp:92
Definition: jcmarker.cpp:86
static void write_file_trailer ( j_compress_ptr  cinfo)
static
603 {
604  emit_marker(cinfo, M_EOI);
605 }
Definition: jcmarker.cpp:49
static void emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
Definition: jcmarker.cpp:122
static void write_tables_only ( j_compress_ptr  cinfo)
static
617 {
618  int i;
619 
620  emit_marker(cinfo, M_SOI);
621 
622  for (i = 0; i < NUM_QUANT_TBLS; i++) {
623  if (cinfo->quant_tbl_ptrs[i] != NULL)
624  (void) emit_dqt(cinfo, i);
625  }
626 
627  if (! cinfo->arith_code) {
628  for (i = 0; i < NUM_HUFF_TBLS; i++) {
629  if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
630  emit_dht(cinfo, i, FALSE);
631  if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
632  emit_dht(cinfo, i, TRUE);
633  }
634  }
635 
636  emit_marker(cinfo, M_EOI);
637 }
#define NUM_QUANT_TBLS
Definition: jpeglib.h:48
Definition: jcmarker.cpp:49
int i
Definition: rw_test.cpp:37
static void emit_dht(j_compress_ptr cinfo, int index, boolean is_ac)
Definition: jcmarker.cpp:184
JQUANT_TBL * quant_tbl_ptrs[4]
Definition: jpeglib.h:307
#define NUM_HUFF_TBLS
Definition: jpeglib.h:49
static int emit_dqt(j_compress_ptr cinfo, int index)
Definition: jcmarker.cpp:144
#define FALSE
Definition: jpleph.cpp:69
#define TRUE
Definition: jpleph.cpp:68
boolean arith_code
Definition: jpeglib.h:326
JHUFF_TBL * ac_huff_tbl_ptrs[4]
Definition: jpeglib.h:311
JHUFF_TBL * dc_huff_tbl_ptrs[4]
Definition: jpeglib.h:310
static void emit_marker(j_compress_ptr cinfo, JPEG_MARKER mark)
Definition: jcmarker.cpp:122
Definition: jcmarker.cpp:48
void jinit_marker_writer ( j_compress_ptr  cinfo)
646 {
647  my_marker_ptr marker;
648 
649  /* Create the subobject */
650  marker = (my_marker_ptr)
651  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
653  cinfo->marker = (struct jpeg_marker_writer *) marker;
654  /* Initialize method pointers */
655  marker->pub.write_file_header = write_file_header;
656  marker->pub.write_frame_header = write_frame_header;
657  marker->pub.write_scan_header = write_scan_header;
658  marker->pub.write_file_trailer = write_file_trailer;
659  marker->pub.write_tables_only = write_tables_only;
660  marker->pub.write_marker_header = write_marker_header;
661  marker->pub.write_marker_byte = write_marker_byte;
662  /* Initialize private state */
663  marker->last_restart_interval = 0;
664 }
static void write_file_trailer(j_compress_ptr cinfo)
Definition: jcmarker.cpp:602
Definition: jpegint.h:120
static void write_tables_only(j_compress_ptr cinfo)
Definition: jcmarker.cpp:616
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
static void write_frame_header(j_compress_ptr cinfo)
Definition: jcmarker.cpp:494
void *(* alloc_small)()
Definition: jpeglib.h:764
#define SIZEOF(object)
Definition: jinclude.h:80
unsigned int last_restart_interval
Definition: jcmarker.cpp:89
static void write_file_header(j_compress_ptr cinfo)
Definition: jcmarker.cpp:469
#define JPOOL_IMAGE
Definition: jpeglib.h:754
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:274
struct jpeg_marker_writer * marker
Definition: jpeglib.h:404
static void write_scan_header(j_compress_ptr cinfo)
Definition: jcmarker.cpp:551
static void write_marker_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:450
static void write_marker_header(j_compress_ptr cinfo, int marker, unsigned int datalen)
Definition: jcmarker.cpp:438
struct jpeg_marker_writer pub
Definition: jcmarker.cpp:87
my_marker_writer * my_marker_ptr
Definition: jcmarker.cpp:92
Definition: jcmarker.cpp:86