📄 ac_vld_decode_c.c
字号:
const AC_TBL_str *restrict ac_table_luma){ unsigned int Neg_AC, run_val, size_val, len_val; unsigned int temp_ac, num_coeffs; unsigned int numberval; uLong tempword; unsigned int used_bytes_val,data_word_val; unsigned int len_cw,num_bytes_insert_val; unsigned int EOB_MASK,EOB_LEN,EOB_CODE; unsigned int EOB_flag; const unsigned char *restrict sze_tbl; const unsigned char *restrict data_pointer; const unsigned char *restrict shf_tbl; const unsigned char *restrict run_tbl; const unsigned char *restrict tbl; short *restrict run, *restrict level; int bit_pos_val; int level_val; int t02_ofs, t35_ofs, t68_ofs; int t9x_ofs, ofs; /* -------------------------------------------------------------------- */ /* Set the pointers to tbl, run, sze, and shf arrays */ /* Read in bit_pos,used_bytes from VLD buffer,and EOB_flag */ /* Set numberval and num_coeffs to zero */ /* To prepare EOB read codes from locations offset 112 and 113. */ /* Read EOB length from location 116. Prepare EOB mask for */ /* codeword of specific length. */ /* -------------------------------------------------------------------- */ tbl = ac_table_luma->run_ptr; run_tbl = ac_table_luma->run_ptr + 56; sze_tbl = ac_table_luma->sze_ptr + 314 + 56; shf_tbl = ac_table_luma->shf_ptr + 628 + 56; run = run_level; level = run_level + 1; bit_pos_val = *bit_pos_vld; used_bytes_val = *used_up_bytes; data_word_val = *data_word; data_pointer = *data_ptr; numberval = 0; num_coeffs = 0; /* -------------------------------------------------------------------- */ /* Prepare EOB_CODE, EOB_LEN and EOB_MASK based on user */ /* -------------------------------------------------------------------- */ EOB_CODE = (tbl[112] << 24) | (tbl[113] << 16); EOB_LEN = tbl[116]; EOB_MASK = ~(~0U >> EOB_LEN); do { /* ---------------------------------------------------------------- */ /* -- Use EOB_MASK and EOB_CODE to check for EOB_flag in the */ /* bit_stream. */ /* -- Detect leftmost zero in data_word_val. */ /* -- Read 5 the next 5 bytes from the bitstream at data_pointer */ /* and merge these into a single 40-bit quantity. */ /* -- Increment numberval to indicate that 1 run/level pair has */ /* been detected. */ /* ---------------------------------------------------------------- */ EOB_flag = ((data_word_val & EOB_MASK) == EOB_CODE); tempword = ((uLong) data_pointer[0] << 32) | ((unsigned) data_pointer[1] << 24) | ((unsigned) data_pointer[2] << 16) | ((unsigned) data_pointer[3] << 8 ) | ((unsigned) data_pointer[4] << 0 ); numberval++; /* ---------------------------------------------------------------- */ /* Perform offset calculation speculatively for the 4 sub-tables */ /* in the super table. This is done using extu and shifts and */ /* then choosing amongst these offsets by the lmbd value. Once */ /* the offset has been figured load run, size and length of the */ /* codeword together. (Note: pure-C version uses range compare */ /* on unsigned values in lieu of lmbd.) */ /* ---------------------------------------------------------------- */ t02_ofs = data_word_val >> 26; t35_ofs = data_word_val << 3 >> 26; t68_ofs = data_word_val << 5 >> 25; t9x_ofs = data_word_val << 8 >> 24; ofs = t35_ofs; if (data_word_val < 0xE0000000UL) ofs = t02_ofs - 56; if (data_word_val >= 0xFC000000UL) ofs = t68_ofs; if (data_word_val >= 0xFF800000UL) ofs = t9x_ofs; run_val = run_tbl[ofs]; size_val = sze_tbl[ofs]; len_cw = shf_tbl[ofs]; /* ---------------------------------------------------------------- */ /* Perform level calculation by figuring the len_val extra */ /* bits. This is obtained by deducting the length of the codeword */ /* (Huffman+extra bits) This is then shifted left and stored */ /* in temp_ac. temp_ac contains the xtra bits left justified */ /* and other additional bits. Neg_AC obtains the sign bit and */ /* inverts it. For eg. if the sign bit of temp_ac is 1 then */ /* Neg_AC is 0. To get merely the level temp_ac is shifted right */ /* to have extra bits right justified. The sign bit needs to be */ /* removed and this is done by subtracting ( Neg_AC << size_val). */ /* ---------------------------------------------------------------- */ len_val = len_cw - size_val; temp_ac = data_word_val << len_val; Neg_AC = 1 + ((signed)temp_ac >> 31); level_val = SHR(temp_ac,(32-size_val)) - (Neg_AC << size_val ) + Neg_AC; /* ---------------------------------------------------------------- */ /* Store run-val and level_val in the pointers pointed to by */ /* run,level. Increment run,level. In addition increment the */ /* number of coefficients found. Subtract the length of the */ /* codeword extracted from bit_pos. Remove the extracted */ /* codeword from the datstream by shifting left. Determine */ /* the number of complete bytes that can be inserted using */ /* num_bytes_insert_val= (32-bit_pos_val)>>3. This will be used */ /* to increment data_pointer to start fetching bytes from this */ /* location. num_bytes_insert_val is also used to accumulate */ /* into the number of bytes used from used_bytes_val. */ /* ---------------------------------------------------------------- */ *run = run_val; *level = level_val; run += 2; level += 2; num_coeffs += (run_val+1); bit_pos_val -= len_cw ; num_bytes_insert_val = (32 - bit_pos_val) >> 3; data_pointer += num_bytes_insert_val; used_bytes_val += num_bytes_insert_val; /* ---------------------------------------------------------------- */ /* Add up the left shifted bytes that were fetched to form */ /* tempword. bit_pos_val at present indicates the location */ /* from where fresh bits can be pasted. Since a 40 bit shift is */ /* being used 8 is added to the bit_pos_val to compute the shift */ /* amount. This shifted word is then ORed because there is no */ /* overlap with the existing word. bit_pos is now incremented */ /* by the bits in the complete bytes inserted. A running counter */ /* of run + 1 values is maintained and if this is > 63 then the */ /* EOB flag is forcibly set to exit the loop. */ /* ---------------------------------------------------------------- */ data_word_val = (data_word_val << len_cw) | SHRL(tempword, 8+bit_pos_val); bit_pos_val += (num_bytes_insert_val*8); if (num_coeffs >= 63) EOB_flag = 1; } while (!EOB_flag); /* -------------------------------------------------------------------- */ /* At the end of the loop store out the number of rles, bit_pos_vld */ /* and the number of bytes used so far in the buffer. In addition */ /* store the existing data_pointer and the state word of data_word_val */ /* to begin VLD for next iter. All these variables namely num_of_rles, */ /* bit_pos_vld, used_up_bytes data_word, data_ptr are used as state */ /* variables to perform chaining of VLD stages from one invocation */ /* to the other. As [art of error checking the VLD returns 1 if the */ /* number of coefficients indicating error and 0 if the block is a */ /* valid VLD block. */ /* -------------------------------------------------------------------- */ *num_of_rles = numberval - 1; *bit_pos_vld = bit_pos_val; *used_up_bytes = used_bytes_val; *data_word = data_word_val; *data_ptr = data_pointer; return (num_coeffs > 63);}/* ======================================================================== *//* End of file: ac_vld_decode_c.c *//* ------------------------------------------------------------------------ *//* Copyright (c) 1999 Texas Instruments, Incorporated. *//* All Rights Reserved. *//* ======================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -