0
votes

The JPEG standard defines the DECODE procedure like below. I'm confused about a few parts.

  1. CODE > MAXCODE(I), if this is true then it enters in a loop and apply left shift (<<) to code. AFAIK, if we apply left shift on non-zero number, the number will be larger then previous. In this figure it applies SLL (shift left logical operation), would't CODE always be greater than MAXCODE?

    Probably I coundn't read the figure correctly

  2. What does + NEXTBIT mean? For instance if CODE bits are 10101 and NEXTBIT is 00000001 then will result be 101011 (like string appending), am I right?

  3. Does HUFFVAL list is same as defined in DHT marker (Vi,j values). Do I need to build extra lookup table or something? Because it seems the procedure used that list directly

Thanks for clarifications

DECODE

EDIT:

My DECODE code (C):

uint8_t
jpg_decode(ImScan    * __restrict scan,
           ImHuffTbl * __restrict huff) {
  int32_t i, j, code;

  i    = 1;
  code = jpg_nextbit(scan);

  /* TODO: infinite loop ? */
  while (code > huff->maxcode[i]) {
    i++;
    code = (code << 1) | jpg_nextbit(scan);
  }

  j = huff->valptr[i];
  j = code + huff->delta[i]; /* delta = j - mincode[i] */

  return huff->huffval[j];
}
1

1 Answers

2
votes
  1. It's not MAXCODE, it's MAXCODE(I), which is a different value each time I is incremented.

  2. +NEXTBIT means literally adding the next bit from the input, which is a 0 or a 1. (NEXTBIT is not 00000001. It is only one bit.)

  3. Once you've found the length of the current code, you get the Vi,j indexing into HUFFVAL decoding table.