📄 ac_vld_decode_c.c
字号:
/* *//* 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 *//* subtracting from 56. t02_ofs will be from 0...55. t35_ofs will *//* also be from 0..56 for the table entries from 56..112. Similar *//* properties hold for t68 and t9x offsets. *//* *//* p) run_val,size_val and len_cw are all loaded together using the same *//* offset that was figured in step (o) *//* *//* q) len_val is the length of the extra bits and is len_cw - size_val. *//* *//* r) The code bits of the base Huffman code word are shifted away and *//* the extra bits alone are retained in temp_ac. *//* *//* s) Neg_AC: Sign of the level and is 1 for positive and 0 for negative *//* numbers in conformance with JPEG. Neg_AC is the complement of the *//* sign of level_val. *//* *//* Neg_AC = 1 + ((signed)temp_ac >> 31); *//* *//* Neg_AC is 0 for positive level values and 1 for negative level *//* values. *//* *//* t) level_val = SHR(temp_ac,(32-size_val))-(Neg_AC<<size_val)+Neg_AC; *//* *//* level_val: shift right temp_ac after determining sign to get base *//* magnitude. If Neg_ac is 1 then remove this bit from Bit(sizeval) *//* by subtracting. Add 1 to the result. If Neg_ac is zero then the *//* magnitude reamins as such. *//* e.g. *//* levelval of -3 is coded as 01 with size-bits = 2 *//* This would be decoded as 01 -10 + 1 = 11 *//* levelval 0f 3 is code as 11 with size-bits = 2 *//* This would be decoded as 11 - 00 + 0 = 01 *//* *//* u) Store away run, level values and incr run, level pointers by 2 *//* *//* v) Increment num_coeffs (K) by run + 1 *//* *//* w) Deduct off the length of the codeword from bit_pos. Also advance *//* the data_stream by len_cw bits just parsed. *//* *//* x) Determine the complete number of bytes that can be inserted and *//* store in num_bytes_insert_val:(32-bit_pos_val)>>3 *//* For eg: if present bit_pos_val after step (w) is 9 then 2 complete *//* bytes and 7 bits of the 3rd byte can be insertes. These 7 bytes *//* constitute the overlap between data_word_val and dat_ptr. *//* *//* num_bytes_insert_val: This variable is used to increment *//* data_pointer. Start reading from this location on the next *//* iteration. This is also used to increment used_bytes_val *//* *//* y) The next set of bytes is being brought in as a 40 bit buffer in *//* temp word. To append this variable after bit_pos bits from the *//* left one needs to shift 8 + bit_pos_val *//* *//* z) Increment bit_pos_val by the number of bits in the complete byte *//* inserted. For eg. bit_pos = 9 and 2 bytes are inserted then it *//* will be incremented by 16 bits to become 25 *//* *//* Iterate steps k through z while EOB == 0 *//* *//* Steps to be performed after the loop *//* *//* a) *num_of_rles = numberval - 1. The number of run-level pairs found *//* is numberval - 1. Remember numberval is 1 more because it *//* increments for EOB as well. *//* *//* b) *bit_pos_vld = bit_pos_val; *//* Store off the current bit position in the pointer. Status variable *//* used for chaining VLD's. *//* *//* c) *used_up_bytes= used_bytes_val; *//* Store off the number of used up bytes in the pointer. Status *//* variable for chaining VLD's *//* *//* d) *data_word = data_word_val; *//* Store off the present VLD status word to begin resuming this on *//* next pass of the VLD. Status word of the VLD is the most important *//* state variable. *//* *//* e) *data_ptr = data_pointer; *//* Store off the pointer from which the next set of 5 bytes need *//* to be fetched at the end of the VLD. State variable used for *//* chaining VLD calls. *//* *//* DIAGNOSTICS *//* Return value == 1: Incorrect VLD stream in which K > 63 *//* Return value == 0: Correct VLD and valid JPEG stream *//* *//* BIBLIOGRAPHY *//* 1) JPEG still image data compression standard by William B *//* Pennabaker and Joan L. Mitchell *//* 2) CCITT T.81 standard *//* *//* ------------------------------------------------------------------------ *//* Copyright (c) 2002 Texas Instruments, Incorporated. *//* All Rights Reserved. *//* ======================================================================== */#ifdef _TMS320C6X# define SHR(a,b) ((a) >> (b))# define SHRL(a,b) ((a) >> (b))# ifndef _INLINE# define _INLINE inline# endiftypedef unsigned long uLong;#else# define SHR(a,b) (((b) & 32) ? 0 : (a) >> (b))# define SHRL(a,b) (((b) > 40) ? 0 : (a) >> (b))# ifndef _INLINE# define _INLINE# endiftypedef unsigned long long uLong; /* must be >= 40 bits in length */#endifint ac_vld_decode_cn ( const unsigned char *restrict *restrict data_ptr, unsigned int *restrict data_word, short *restrict run_level, unsigned char *restrict num_of_rles, unsigned char *restrict bit_pos_vld, unsigned int *restrict used_up_bytes,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -