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

Classes

struct  savable_state
 
struct  huff_entropy_decoder
 

Macros

#define JPEG_INTERNALS
 
#define ASSIGN_STATE(dest, src)   ((dest) = (src))
 
#define MIN_GET_BITS   (BIT_BUF_SIZE-7)
 
#define HUFF_EXTEND(x, s)   ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
 

Typedefs

typedef huff_entropy_decoderhuff_entropy_ptr
 

Functions

static void start_pass_huff_decoder (j_decompress_ptr cinfo)
 
void jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, d_derived_tbl **pdtbl)
 
boolean jpeg_fill_bit_buffer (bitread_working_state *state, register bit_buf_type get_buffer, register int bits_left, int nbits)
 
int jpeg_huff_decode (bitread_working_state *state, register bit_buf_type get_buffer, register int bits_left, d_derived_tbl *htbl, int min_bits)
 
static boolean process_restart (j_decompress_ptr cinfo)
 
static boolean decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
 
void jinit_huff_decoder (j_decompress_ptr cinfo)
 

Variables

static const int extend_test [16]
 
static const int extend_offset [16]
 

Macro Definition Documentation

#define JPEG_INTERNALS
#define ASSIGN_STATE (   dest,
  src 
)    ((dest) = (src))
#define MIN_GET_BITS   (BIT_BUF_SIZE-7)
#define HUFF_EXTEND (   x,
 
)    ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))

Typedef Documentation

Function Documentation

static void start_pass_huff_decoder ( j_decompress_ptr  cinfo)
static
87 {
88  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
89  int ci, blkn, dctbl, actbl;
91 
92  /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
93  * This ought to be an error condition, but we make it a warning because
94  * there are some baseline files out there with all zeroes in these bytes.
95  */
96  if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
97  cinfo->Ah != 0 || cinfo->Al != 0)
99 
100  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
101  compptr = cinfo->cur_comp_info[ci];
102  dctbl = compptr->dc_tbl_no;
103  actbl = compptr->ac_tbl_no;
104  /* Compute derived values for Huffman tables */
105  /* We may do this more than once for a table, but it's not expensive */
106  jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
107  & entropy->dc_derived_tbls[dctbl]);
108  jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
109  & entropy->ac_derived_tbls[actbl]);
110  /* Initialize DC predictions to 0 */
111  entropy->saved.last_dc_val[ci] = 0;
112  }
113 
114  /* Precalculate decoding info for each block in an MCU of this scan */
115  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
116  ci = cinfo->MCU_membership[blkn];
117  compptr = cinfo->cur_comp_info[ci];
118  /* Precalculate which table to use for each block */
119  entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
120  entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
121  /* Decide whether we really care about the coefficient values */
122  if (compptr->component_needed) {
123  entropy->dc_needed[blkn] = TRUE;
124  /* we don't need the ACs if producing a 1/8th-size image */
125  entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
126  } else {
127  entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
128  }
129  }
130 
131  /* Initialize bitread state variables */
132  entropy->bitstate.bits_left = 0;
133  entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
134  entropy->pub.insufficient_data = FALSE;
135 
136  /* Initialize restart counter */
137  entropy->restarts_to_go = cinfo->restart_interval;
138 }
void jpeg_make_d_derived_tbl(j_decompress_ptr cinfo, boolean isDC, int tblno, d_derived_tbl **pdtbl)
Definition: jdhuff.cpp:149
jpeg_component_info * cur_comp_info[4]
Definition: jpeglib.h:602
int comps_in_scan
Definition: jpeglib.h:601
int last_dc_val[4]
Definition: jchuff.cpp:32
int Se
Definition: jpeglib.h:613
savable_state saved
Definition: jchuff.cpp:58
int DCT_scaled_size
Definition: jpeglib.h:152
int dc_tbl_no
Definition: jpeglib.h:134
boolean component_needed
Definition: jpeglib.h:165
int Ah
Definition: jpeglib.h:613
Definition: jerror.h:183
jpeg_component_info * compptr
Definition: jdct.h:102
int ac_tbl_no
Definition: jpeglib.h:135
#define FALSE
Definition: jpleph.cpp:69
#define DCTSIZE2
Definition: jpeglib.h:47
int Al
Definition: jpeglib.h:613
unsigned int restart_interval
Definition: jpeglib.h:550
struct jpeg_entropy_encoder pub
Definition: jchuff.cpp:56
c_derived_tbl * dc_derived_tbls[4]
Definition: jchuff.cpp:65
#define WARNMS(cinfo, code)
Definition: jerror.h:238
#define TRUE
Definition: jpleph.cpp:68
Definition: jchuff.cpp:55
huff_entropy_decoder * huff_entropy_ptr
Definition: jdhuff.cpp:78
int Ss
Definition: jpeglib.h:613
c_derived_tbl * ac_derived_tbls[4]
Definition: jchuff.cpp:66
Definition: jpeglib.h:121
int MCU_membership[10]
Definition: jpeglib.h:609
unsigned int restarts_to_go
Definition: jchuff.cpp:61
int blocks_in_MCU
Definition: jpeglib.h:608
struct jpeg_entropy_decoder * entropy
Definition: jpeglib.h:630
void jpeg_make_d_derived_tbl ( j_decompress_ptr  cinfo,
boolean  isDC,
int  tblno,
d_derived_tbl **  pdtbl 
)
151 {
152  JHUFF_TBL *htbl;
153  d_derived_tbl *dtbl;
154  int p, i, l, si, numsymbols;
155  int lookbits, ctr;
156  char huffsize[257];
157  unsigned int huffcode[257];
158  unsigned int code;
159 
160  /* Note that huffsize[] and huffcode[] are filled in code-length order,
161  * paralleling the order of the symbols themselves in htbl->huffval[].
162  */
163 
164  /* Find the input Huffman table */
165  if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
167  htbl =
168  isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
169  if (htbl == NULL)
171 
172  /* Allocate a workspace if we haven't already done so. */
173  if (*pdtbl == NULL)
174  *pdtbl = (d_derived_tbl *)
175  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
177  dtbl = *pdtbl;
178  dtbl->pub = htbl; /* fill in back link */
179 
180  /* Figure C.1: make table of Huffman code length for each symbol */
181 
182  p = 0;
183  for (l = 1; l <= 16; l++) {
184  i = (int) htbl->bits[l];
185  if (i < 0 || p + i > 256) /* protect against table overrun */
187  while (i--)
188  huffsize[p++] = (char) l;
189  }
190  huffsize[p] = 0;
191  numsymbols = p;
192 
193  /* Figure C.2: generate the codes themselves */
194  /* We also validate that the counts represent a legal Huffman code tree. */
195 
196  code = 0;
197  si = huffsize[0];
198  p = 0;
199  while (huffsize[p]) {
200  while (((int) huffsize[p]) == si) {
201  huffcode[p++] = code;
202  code++;
203  }
204  /* code is now 1 more than the last code used for codelength si; but
205  * it must still fit in si bits, since no code is allowed to be all ones.
206  */
207  if (((int32_t) code) >= (((int32_t) 1) << si))
209  code <<= 1;
210  si++;
211  }
212 
213  /* Figure F.15: generate decoding tables for bit-sequential decoding */
214 
215  p = 0;
216  for (l = 1; l <= 16; l++) {
217  if (htbl->bits[l]) {
218  /* valoffset[l] = huffval[] index of 1st symbol of code length l,
219  * minus the minimum code of length l
220  */
221  dtbl->valoffset[l] = (int32_t) p - (int32_t) huffcode[p];
222  p += htbl->bits[l];
223  dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
224  } else {
225  dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
226  }
227  }
228  dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
229 
230  /* Compute lookahead tables to speed up decoding.
231  * First we set all the table entries to 0, indicating "too long";
232  * then we iterate through the Huffman codes that are short enough and
233  * fill in all the entries that correspond to bit sequences starting
234  * with that code.
235  */
236 
237  MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
238 
239  p = 0;
240  for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
241  for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
242  /* l = current code's length, p = its index in huffcode[] & huffval[]. */
243  /* Generate left-justified code followed by all possible bit sequences */
244  lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
245  for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
246  dtbl->look_nbits[lookbits] = l;
247  dtbl->look_sym[lookbits] = htbl->huffval[p];
248  lookbits++;
249  }
250  }
251  }
252 
253  /* Validate symbols as being reasonable.
254  * For AC tables, we make no check, but accept all byte values 0..255.
255  * For DC tables, we require the symbols to be in range 0..15.
256  * (Tighter bounds could be applied depending on the data depth and mode,
257  * but this is sufficient to ensure safe decoding.)
258  */
259  if (isDC) {
260  for (i = 0; i < numsymbols; i++) {
261  int sym = htbl->huffval[i];
262  if (sym < 0 || sym > 15)
264  }
265  }
266 }
Definition: jdhuff.h:26
boolean int c_derived_tbl ** pdtbl
Definition: jchuff.h:42
int32_t valoffset[17]
Definition: jdhuff.h:30
int i
Definition: rw_test.cpp:37
JHUFF_TBL * dc_huff_tbl_ptrs[4]
Definition: jpeglib.h:530
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
void *(* alloc_small)()
Definition: jpeglib.h:764
#define NUM_HUFF_TBLS
Definition: jpeglib.h:49
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
#define SIZEOF(object)
Definition: jinclude.h:80
JHUFF_TBL * ac_huff_tbl_ptrs[4]
Definition: jpeglib.h:531
Definition: jerror.h:97
#define JPOOL_IMAGE
Definition: jpeglib.h:754
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
static double * p
Definition: gauss_jackson_test.cpp:42
uint8_t look_sym[1<< 8]
Definition: jdhuff.h:45
int32_t maxcode[18]
Definition: jdhuff.h:28
uint8_t huffval[256]
Definition: jpeglib.h:109
int look_nbits[1<< 8]
Definition: jdhuff.h:44
#define HUFF_LOOKAHEAD
Definition: jdhuff.h:24
uint8_t bits[17]
Definition: jpeglib.h:107
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
Definition: inftrees.h:24
Definition: jerror.h:50
JHUFF_TBL * htbl
Definition: jchuff.h:47
Definition: jpeglib.h:105
boolean int tblno
Definition: jchuff.h:42
boolean isDC
Definition: jchuff.h:42
JHUFF_TBL * pub
Definition: jdhuff.h:37
#define MEMZERO(target, size)
Definition: jinclude.h:67
boolean jpeg_fill_bit_buffer ( bitread_working_state state,
register bit_buf_type  get_buffer,
register int  bits_left,
int  nbits 
)
296 {
297  /* Copy heavily used state fields into locals (hopefully registers) */
298  register const JOCTET * next_input_byte = state->next_input_byte;
299  register size_t bytes_in_buffer = state->bytes_in_buffer;
300  j_decompress_ptr cinfo = state->cinfo;
301 
302  /* Attempt to load at least MIN_GET_BITS bits into get_buffer. */
303  /* (It is assumed that no request will be for more than that many bits.) */
304  /* We fail to do so only if we hit a marker or are forced to suspend. */
305 
306  if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
307  while (bits_left < MIN_GET_BITS) {
308  register int c;
309 
310  /* Attempt to read a byte */
311  if (bytes_in_buffer == 0) {
312  if (! (*cinfo->src->fill_input_buffer) (cinfo))
313  return FALSE;
314  next_input_byte = cinfo->src->next_input_byte;
315  bytes_in_buffer = cinfo->src->bytes_in_buffer;
316  }
317  bytes_in_buffer--;
318  c = GETJOCTET(*next_input_byte++);
319 
320  /* If it's 0xFF, check and discard stuffed zero byte */
321  if (c == 0xFF) {
322  /* Loop here to discard any padding FF's on terminating marker,
323  * so that we can save a valid unread_marker value. NOTE: we will
324  * accept multiple FF's followed by a 0 as meaning a single FF data
325  * byte. This data pattern is not valid according to the standard.
326  */
327  do {
328  if (bytes_in_buffer == 0) {
329  if (! (*cinfo->src->fill_input_buffer) (cinfo))
330  return FALSE;
331  next_input_byte = cinfo->src->next_input_byte;
332  bytes_in_buffer = cinfo->src->bytes_in_buffer;
333  }
334  bytes_in_buffer--;
335  c = GETJOCTET(*next_input_byte++);
336  } while (c == 0xFF);
337 
338  if (c == 0) {
339  /* Found FF/00, which represents an FF data byte */
340  c = 0xFF;
341  } else {
342  /* Oops, it's actually a marker indicating end of compressed data.
343  * Save the marker code for later use.
344  * Fine point: it might appear that we should save the marker into
345  * bitread working state, not straight into permanent state. But
346  * once we have hit a marker, we cannot need to suspend within the
347  * current MCU, because we will read no more bytes from the data
348  * source. So it is OK to update permanent state right away.
349  */
350  cinfo->unread_marker = c;
351  /* See if we need to insert some fake zero bits. */
352  goto no_more_bytes;
353  }
354  }
355 
356  /* OK, load c into get_buffer */
357  get_buffer = (get_buffer << 8) | c;
358  bits_left += 8;
359  } /* end while */
360  } else {
361  no_more_bytes:
362  /* We get here if we've read the marker that terminates the compressed
363  * data segment. There should be enough bits in the buffer register
364  * to satisfy the request; if so, no problem.
365  */
366  if (nbits > bits_left) {
367  /* Uh-oh. Report corrupted data to user and stuff zeroes into
368  * the data stream, so that we can produce some kind of image.
369  * We use a nonvolatile flag to ensure that only one warning message
370  * appears per data segment.
371  */
372  if (! cinfo->entropy->insufficient_data) {
373  WARNMS(cinfo, JWRN_HIT_MARKER);
374  cinfo->entropy->insufficient_data = TRUE;
375  }
376  /* Fill the buffer with zero bits */
378  bits_left = MIN_GET_BITS;
379  }
380  }
381 
382  /* Unload the local registers */
383  state->next_input_byte = next_input_byte;
384  state->bytes_in_buffer = bytes_in_buffer;
385  state->get_buffer = get_buffer;
386  state->bits_left = bits_left;
387 
388  return TRUE;
389 }
bit_buf_type get_buffer
Definition: jdhuff.h:95
#define GETJOCTET(value)
Definition: jmorecfg.h:119
boolean(* fill_input_buffer)()
Definition: jpeglib.h:735
int bits_left
Definition: jdhuff.h:96
const JOCTET * next_input_byte
Definition: jdhuff.h:90
size_t bytes_in_buffer
Definition: jdhuff.h:91
#define MIN_GET_BITS
Definition: jdhuff.cpp:287
j_decompress_ptr cinfo
Definition: jdhuff.h:98
#define FALSE
Definition: jpleph.cpp:69
size_t bytes_in_buffer
Definition: jpeglib.h:732
register bit_buf_type register int int nbits
Definition: jdhuff.h:155
#define WARNMS(cinfo, code)
Definition: jerror.h:238
#define TRUE
Definition: jpleph.cpp:68
Definition: jerror.h:177
struct jpeg_source_mgr * src
Definition: jpeglib.h:420
Definition: jpeglib.h:416
int unread_marker
Definition: jpeglib.h:619
char JOCTET
Definition: jmorecfg.h:115
boolean insufficient_data
Definition: jpegint.h:216
register bit_buf_type get_buffer
Definition: jdhuff.h:155
const JOCTET * next_input_byte
Definition: jpeglib.h:731
register bit_buf_type register int bits_left
Definition: jdhuff.h:155
struct jpeg_entropy_decoder * entropy
Definition: jpeglib.h:630
int jpeg_huff_decode ( bitread_working_state state,
register bit_buf_type  get_buffer,
register int  bits_left,
d_derived_tbl htbl,
int  min_bits 
)
401 {
402  register int l = min_bits;
403  register int32_t code;
404 
405  /* HUFF_DECODE has determined that the code is at least min_bits */
406  /* bits long, so fetch that many bits in one swoop. */
407 
408  CHECK_BIT_BUFFER(*state, l, return -1);
409  code = GET_BITS(l);
410 
411  /* Collect the rest of the Huffman code one bit at a time. */
412  /* This is per Figure F.16 in the JPEG spec. */
413 
414  while (code > htbl->maxcode[l]) {
415  code <<= 1;
416  CHECK_BIT_BUFFER(*state, 1, return -1);
417  code |= GET_BITS(1);
418  l++;
419  }
420 
421  /* Unload the local registers */
422  state->get_buffer = get_buffer;
423  state->bits_left = bits_left;
424 
425  /* With garbage input we may reach the sentinel value l = 17. */
426 
427  if (l > 16) {
429  return 0; /* fake a zero as the safest result */
430  }
431 
432  return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
433 }
bit_buf_type get_buffer
Definition: jdhuff.h:95
int32_t valoffset[17]
Definition: jdhuff.h:30
int bits_left
Definition: jdhuff.h:96
j_decompress_ptr cinfo
Definition: jdhuff.h:98
#define GET_BITS(nbits)
Definition: jdhuff.h:144
Definition: jerror.h:178
register bit_buf_type register int d_derived_tbl int min_bits
Definition: jdhuff.h:200
int32_t maxcode[18]
Definition: jdhuff.h:28
uint8_t huffval[256]
Definition: jpeglib.h:109
#define CHECK_BIT_BUFFER(state, nbits, action)
Definition: jdhuff.h:138
#define WARNMS(cinfo, code)
Definition: jerror.h:238
Definition: inftrees.h:24
register bit_buf_type get_buffer
Definition: jdhuff.h:155
JHUFF_TBL * pub
Definition: jdhuff.h:37
register bit_buf_type register int bits_left
Definition: jdhuff.h:155
static boolean process_restart ( j_decompress_ptr  cinfo)
static
469 {
470  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
471  int ci;
472 
473  /* Throw away any unused bits remaining in bit buffer; */
474  /* include any full bytes in next_marker's count of discarded bytes */
475  cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
476  entropy->bitstate.bits_left = 0;
477 
478  /* Advance past the RSTn marker */
479  if (! (*cinfo->marker->read_restart_marker) (cinfo))
480  return FALSE;
481 
482  /* Re-initialize DC predictions to 0 */
483  for (ci = 0; ci < cinfo->comps_in_scan; ci++)
484  entropy->saved.last_dc_val[ci] = 0;
485 
486  /* Reset restart counter */
487  entropy->restarts_to_go = cinfo->restart_interval;
488 
489  /* Reset out-of-data flag, unless read_restart_marker left us smack up
490  * against a marker. In that case we will end up treating the next data
491  * segment as empty, and we can avoid producing bogus output pixels by
492  * leaving the flag set.
493  */
494  if (cinfo->unread_marker == 0)
495  entropy->pub.insufficient_data = FALSE;
496 
497  return TRUE;
498 }
unsigned int discarded_bytes
Definition: jpegint.h:205
int comps_in_scan
Definition: jpeglib.h:601
int last_dc_val[4]
Definition: jchuff.cpp:32
struct jpeg_marker_reader * marker
Definition: jpeglib.h:629
savable_state saved
Definition: jchuff.cpp:58
#define FALSE
Definition: jpleph.cpp:69
unsigned int restart_interval
Definition: jpeglib.h:550
struct jpeg_entropy_encoder pub
Definition: jchuff.cpp:56
#define TRUE
Definition: jpleph.cpp:68
Definition: jchuff.cpp:55
huff_entropy_decoder * huff_entropy_ptr
Definition: jdhuff.cpp:78
unsigned int restarts_to_go
Definition: jchuff.cpp:61
int unread_marker
Definition: jpeglib.h:619
jpeg_marker_parser_method read_restart_marker
Definition: jpegint.h:197
struct jpeg_entropy_decoder * entropy
Definition: jpeglib.h:630
static boolean decode_mcu ( j_decompress_ptr  cinfo,
JBLOCKROW MCU_data 
)
static
518 {
519  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
520  int blkn;
522  savable_state state;
523 
524  /* Process restart marker if needed; may have to suspend */
525  if (cinfo->restart_interval) {
526  if (entropy->restarts_to_go == 0)
527  if (! process_restart(cinfo))
528  return FALSE;
529  }
530 
531  /* If we've run out of data, just leave the MCU set to zeroes.
532  * This way, we return uniform gray for the remainder of the segment.
533  */
534  if (! entropy->pub.insufficient_data) {
535 
536  /* Load up working state */
537  BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
538  ASSIGN_STATE(state, entropy->saved);
539 
540  /* Outer loop handles each block in the MCU */
541 
542  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
543  JBLOCKROW block = MCU_data[blkn];
544  d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
545  d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
546  register int s, k, r;
547 
548  /* Decode a single block's worth of coefficients */
549 
550  /* Section F.2.2.1: decode the DC coefficient difference */
551  HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
552  if (s) {
553  CHECK_BIT_BUFFER(br_state, s, return FALSE);
554  r = GET_BITS(s);
555  s = HUFF_EXTEND(r, s);
556  }
557 
558  if (entropy->dc_needed[blkn]) {
559  /* Convert DC difference to actual value, update last_dc_val */
560  int ci = cinfo->MCU_membership[blkn];
561  s += state.last_dc_val[ci];
562  state.last_dc_val[ci] = s;
563  /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */
564  (*block)[0] = (JCOEF) s;
565  }
566 
567  if (entropy->ac_needed[blkn]) {
568 
569  /* Section F.2.2.2: decode the AC coefficients */
570  /* Since zeroes are skipped, output area must be cleared beforehand */
571  for (k = 1; k < DCTSIZE2; k++) {
572  HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
573 
574  r = s >> 4;
575  s &= 15;
576 
577  if (s) {
578  k += r;
579  CHECK_BIT_BUFFER(br_state, s, return FALSE);
580  r = GET_BITS(s);
581  s = HUFF_EXTEND(r, s);
582  /* Output coefficient in natural (dezigzagged) order.
583  * Note: the extra entries in jpeg_natural_order[] will save us
584  * if k >= DCTSIZE2, which could happen if the data is corrupted.
585  */
586  (*block)[jpeg_natural_order[k]] = (JCOEF) s;
587  } else {
588  if (r != 15)
589  break;
590  k += 15;
591  }
592  }
593 
594  } else {
595 
596  /* Section F.2.2.2: decode the AC coefficients */
597  /* In this path we just discard the values */
598  for (k = 1; k < DCTSIZE2; k++) {
599  HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
600 
601  r = s >> 4;
602  s &= 15;
603 
604  if (s) {
605  k += r;
606  CHECK_BIT_BUFFER(br_state, s, return FALSE);
607  DROP_BITS(s);
608  } else {
609  if (r != 15)
610  break;
611  k += 15;
612  }
613  }
614 
615  }
616  }
617 
618  /* Completed MCU, so update state */
619  BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
620  ASSIGN_STATE(entropy->saved, state);
621  }
622 
623  /* Account for restart interval (no-op if not using restarts) */
624  entropy->restarts_to_go--;
625 
626  return TRUE;
627 }
#define HUFF_EXTEND(x, s)
Definition: jdhuff.cpp:447
#define BITREAD_STATE_VARS
Definition: jdhuff.h:102
static boolean process_restart(j_decompress_ptr cinfo)
Definition: jdhuff.cpp:468
#define ASSIGN_STATE(dest, src)
Definition: jdhuff.cpp:40
Definition: jdhuff.h:26
#define DROP_BITS(nbits)
Definition: jdhuff.h:150
const int jpeg_natural_order[]
Definition: jutils.cpp:53
savable_state saved
Definition: jchuff.cpp:58
short JCOEF
Definition: jmorecfg.h:99
#define HUFF_DECODE(result, state, htbl, failaction, slowlabel)
Definition: jdhuff.h:176
#define GET_BITS(nbits)
Definition: jdhuff.h:144
#define FALSE
Definition: jpleph.cpp:69
Definition: jchuff.cpp:29
#define DCTSIZE2
Definition: jpeglib.h:47
unsigned int restart_interval
Definition: jpeglib.h:550
#define CHECK_BIT_BUFFER(state, nbits, action)
Definition: jdhuff.h:138
struct jpeg_entropy_encoder pub
Definition: jchuff.cpp:56
#define TRUE
Definition: jpleph.cpp:68
Definition: jchuff.cpp:55
huff_entropy_decoder * huff_entropy_ptr
Definition: jdhuff.cpp:78
#define BITREAD_SAVE_STATE(cinfop, permstate)
Definition: jdhuff.h:114
JBLOCK * JBLOCKROW
Definition: jpeglib.h:76
int MCU_membership[10]
Definition: jpeglib.h:609
#define BITREAD_LOAD_STATE(cinfop, permstate)
Definition: jdhuff.h:107
unsigned int restarts_to_go
Definition: jchuff.cpp:61
int blocks_in_MCU
Definition: jpeglib.h:608
struct jpeg_entropy_decoder * entropy
Definition: jpeglib.h:630
void jinit_huff_decoder ( j_decompress_ptr  cinfo)
636 {
637  huff_entropy_ptr entropy;
638  int i;
639 
640  entropy = (huff_entropy_ptr)
641  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
643  cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
644  entropy->pub.start_pass = start_pass_huff_decoder;
645  entropy->pub.decode_mcu = decode_mcu;
646 
647  /* Mark tables unallocated */
648  for (i = 0; i < NUM_HUFF_TBLS; i++) {
649  entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
650  }
651 }
int i
Definition: rw_test.cpp:37
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
void *(* alloc_small)()
Definition: jpeglib.h:764
#define NUM_HUFF_TBLS
Definition: jpeglib.h:49
#define SIZEOF(object)
Definition: jinclude.h:80
#define JPOOL_IMAGE
Definition: jpeglib.h:754
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
static void start_pass_huff_decoder(j_decompress_ptr cinfo)
Definition: jdhuff.cpp:86
struct jpeg_entropy_encoder pub
Definition: jchuff.cpp:56
c_derived_tbl * dc_derived_tbls[4]
Definition: jchuff.cpp:65
Definition: jpegint.h:209
Definition: jchuff.cpp:55
Definition: jdhuff.cpp:52
huff_entropy_decoder * huff_entropy_ptr
Definition: jdhuff.cpp:78
c_derived_tbl * ac_derived_tbls[4]
Definition: jchuff.cpp:66
static boolean decode_mcu(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
Definition: jdhuff.cpp:517
struct jpeg_entropy_decoder * entropy
Definition: jpeglib.h:630

Variable Documentation

const int extend_test[16]
static
Initial value:
=
{ 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 }
const int extend_offset[16]
static
Initial value:
=
{ 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 }