📄 ac_vld_decode_h.h
字号:
/* 56 +-----------------------------------+ *//* | | *//* | 3 <= left-most zero <= 5 | *//* | | *//* 112 +-----------------------------------+ *//* | -- hole -- | *//* 120 +-----------------------------------+ *//* | | *//* | 6 <= left-most zero <= 8 | *//* | | *//* 176 +-----------------------------------+ *//* | -- hole -- | *//* 184 +-----------------------------------+ *//* | | *//* | | *//* | | *//* | | *//* | 9 <= left-most zero <= 15 | *//* | | *//* | | *//* | | *//* | | *//* 312 +---+-------------------------------+ *//* |pad| *//* 314 +---+ *//* *//* There are three such tables packed together (run, size, and *//* shift) into one super-table. A 2-byte "pad" is placed between *//* these three tables to allow three parallel lookups to proceed *//* without bank conflicts. The total super-table size is 940 bytes. *//* (That is, 312 * 3 + 4 bytes for padding.) *//* *//* To save time/space, the code corresponding to EOB is stored *//* in one of the holes in the table. Specifically, offsets *//* 112 and 113 in the super-table hold the 16-bit EOB code, and *//* offset 116 holds the actual length of the EOB code in bits. *//* (Although 32 bits of space are actually reserved to hold the *//* EOB code, valid JPEG Huffman codes are no longer than 16 bits.) *//* *//* When decoding, the sub-table within the run/size/shift tables *//* is selected based on the left-most zero near the front of the *//* bitstream. (This is found using the _lmbd() instrinsic on the *//* "data_word".) The lmbd value is calculated from the bitstream, *//* and the table offset is computed from the significant bits *//* to the right of the leftmost zero (as shown in the table above). *//* *//* Once calculated, the same offset is used to look up the run, *//* size, and shift values for the Huffman code in parallel. (The *//* shift value is essentially another way of describing the code *//* length). *//* *//* The size and code-length values are used for extracting the *//* encoded "level" from the bitstream. Once extracted, "level" and *//* "run" are stored in an interleaved array of runs/levels for *//* later run-length decoding. *//* *//* IMPLEMENTATION *//* *//* a) Three table pointers are used. They are run_tbl,sze_tbl,shf_tbl *//* run_tbl: points to the end of the run table and will use negative *//* offsets. sze_tbl and shf_tbl point to the start of the size and *//* shift tables and use positive offsets *//* *//* b) run, level are intterleaved pointers to run_level array that are *//* used to store run and level values. They are always offset one *//* bank from each other. *//* *//* c) bit_pos_val: Read in current position from bit_pos_vld which is *//* between 25 and 32 at the start of the VLD routine *//* *//* d) used_bytes_val: This variable is used to chain several stages of *//* VLD's and is used to keep count of the number of bytes consumed *//* from the buffer. At the start of the program it reads its initial *//* value from the pointer used_up_bytes passed to it. It accumulates *//* to this value the number of bytes consumed during this run of the *//* VLD and writes back the result in used_up_bytes *//* *//* e) data_word_val = *data_word is the first word or status word of *//* and contains the 32 bits from which VLD parsing will begin. *//* *//* f) data_ptr is a pointer to a pointer that contains the next set of *//* bytes to be fetched for the VLD. data_pointer = *data_ptr. *//* data_pointer now contains the pointer to the dat stream from which *//* the next set of VLD bytes will be fetched. *//* *//* g) number_val: variable used to calculate the number of rles found *//* for this run of VLD ( status variable). This is used *//* to convey state information for chaining VLD's *//* *//* h) num_coeffs: This variable implements the functionality of K *//* variable in the flow chart F.13 of the T.81 CCITT spec. pg 106. *//* It maintains a running sum of the run+1 values decoded. If this *//* reaches 63 then the VLD decode process is exited without an EOB *//* code actually ocurring in the bit-stream. In this case the EOB *//* flag is forcibly set to 1 so that the VLD may gracefully terminate. *//* *//* If this sum exceeds 63 then this is a case of an incorrect JPEG *//* bit-stream. In this case the flow chart F.13 does not recommend any *//* particular course of action. The approach taken by this decoder is *//* to continue treating this as a normal JPEG bit stream. The decoder *//* forces the EOB flag to 1 and treats the case of K > 63 identially *//* to the case where K = 63, except that it returns an error code *//* in the case where K > 63. *//* *//* i) eob_byte0 and eob_byte1 are used to read the EOB code stored in *//* offsets 112 and 113. This gives a 16 bit EOB code. These values *//* are left justified and added together to form EOB_CODE. EOB_LEN *//* is the len of the EOB_CODE and is stored in offset 116. *//* *//* j) EOB_MASK is used to prepare a mask which has 1's in the EOB_LEN *//* bits in the left and 0's in the 32 - EOB_LEN bits after that *//* For eg: for the K-5 table EOB is of length 4. In this case EOB_ *//* MASK is 0x11100000000000000(4 1's and 28 zeroes). *//* *//* k) LOOP: *//* Detect EOB_flag by applying EOB_MASK to data_word_val. If *//* the anded result is the same as EOB_CODE set EOB_flag *//* *//* l) lmbd_val = _lmbd(data_word_val,0). Check for the first 0 in the *//* data_word_val buffer to get index into table. *//* *//* m) In the meanwhile start fetching the next 5 bytes starting at *//* data_pointer speculatively, building these into a 40-bit qty. *//* *//* n) Increment numberval to indicate 1 run_level pair has been detected *//* *//* o) Also figure out speculatively the offset values for the possible *//* regions into the super-table. This is done using 4 seperate offsets *//* namely: *//* *//* t02_ofs = data_word_val >> 26; *//* t35_ofs = _extu(data_word_val, 3, 26); *//* t68_ofs = _extu(data_word_val, 5, 25); *//* t9x_ofs = _extu(data_word_val, 8, 24); *//* *//* t02_ofs: covers cases where lmbd value l: 0 <= l <= 2 *//* t35_ofs: covers cases where lmbd value l: 3 <= l <= 5 *//* t68_ofs: covers cases where lmbd value l: 6 <= l <= 8 *//* t9x_ofs: covers cases where lmbd value l: l>=9 *//* *//* Notice that this is the way that all the tables are organized. *//* Depending on the lmbd value one of these values is chosen. If the *//* lmbd value is 0 < l < 2 a negative offset is prepared by */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -