⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac_vld_decode_n.sa

📁 h263,jpeg,mpeg2编解码核心程序(TI DSP C64xx)
💻 SA
📖 第 1 页 / 共 4 页
字号:
*                                                                           * *       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            * *       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            * *                                                                           * 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -