📄 h263_vld_c.c
字号:
/* */ /* -- If 'f5' is not less than 4, then we need to look at the */ /* first 7 bits to determine what code we have. */ /* */ /* -- For 001xxxx through 1xxxxxx codes, lookup */ /* tab[176 + f7]. We know that f7 >= 32, so therefore, */ /* the lookup will occur over the range [198,303]. */ /* */ /* -- If 'f7' equals 3, we have an escape code of the form */ /* 0000011Lrrrrrrllllllll, where 'L' is the LAST flag, */ /* 'rrrrrr' is the Run, and 'llllllll' is the signed level. */ /* */ /* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */ /* Grab portions of the bitstream and fire off table lookups. */ /* See comments above for explanations of each of these variables. */ /* ---------------------------------------------------------------- */ f5 = vld_buf >> 27; /* First 5 bits. */ f7 = vld_buf >> 25; /* First 7 bits. */ f9 = vld_buf >> 23; /* First 9 bits. */ idx2 = vld_buf >> 22; /* First 10 bits. */ idx1 = vld_buf >> 20; /* First 12 bits. */ c4 = f5 < 4; /* First 5 < 4: 00000xxxxx...00011xxxxx */ /* ---------------------------------------------------------------- */ /* Try to determine the length of the VLC code. Flag an error */ /* if we look up an invalid length. */ /* */ /* Note: We do the first of the two lookups speculatively, and */ /* so it can actually access a 512-byte range even though we'll */ /* only use lookup results from the first 64 bytes. */ /* ---------------------------------------------------------------- */ nbit = len[f9]; /* Codes 00000xxxxx...00011xxxxx */ if (!c4) nbit = len_[f5]; /* Codes 001xxxxx...1xxxxx */ if (!nbit) err |= 0x2; /* Error to 2 if length == 0. */ /* ---------------------------------------------------------------- */ /* Decode an Esc code and check if it is 0x03. If so extract last, */ /* run, level from the escape code */ /* ---------------------------------------------------------------- */ nesc = f7 - 3; /* Test for ESCape: f7 == 0000011 */ if (!nesc) { last = ((unsigned)vld_buf << 7) >> 31; run = ((unsigned)vld_buf << 8) >> 26; level = (( signed)vld_buf << 14) >> 24; /* NOTE: Signed Value! */ sign = level < 0; } /* ---------------------------------------------------------------- */ /* Look up the last/run/level values for the VLC, assuming this */ /* was _not_ an ESC. */ /* */ /* Note: The first lookup occurs speculatively, so it may access */ /* over the entire range tab[176] through tab[303]. */ /* If this was NOT an escape code, replace 'last', 'run' and */ /* 'level' with the appropriate values. Most of the computation */ /* of 'level' is performed speculatively, with a conditional */ /* replace of 'level' and 'sign' at the end. */ /* ---------------------------------------------------------------- */ if (nesc) { lrl = tab_[f7]; /* Codes: 001xxxx ... 1xxxxx */ idx = idx1; /* Codes: 00000xxxxx */ if (f5) idx = 64 + idx2; /* Codes: 00001xxxxx .. 00011xxxxx */ if (c4) lrl = tab[idx]; /* Codes: 00000xxxxx .. 00011xxxxx */ last = (lrl << 16) >> 30; run = (lrl << 19) >> 26; l_tmp = (lrl << 25) >> 25; /* NOTE: Unsigned Level */ s_tmp = (vld_buf << (nbit - 1)); /* Extract sign. */ sign = s_tmp < 0; /* Set 'sign'. */ if (sign) l_tmp = -l_tmp; /* Apply sign to level. */ level = l_tmp; /* Set 'level'. */ } /* ---------------------------------------------------------------- */ /* Perform inverse quantization, and add the appropriate */ /* reconstruction constant. */ /* |REC| = Quant.(2.|Level|+ 1) if Quant = odd */ /* |REC| = Quant.(2.|Level|+ 1) - 1 if Quant = even */ /* */ /* After calculation of |REC| sign is added:REC = sign(level)*|REC| */ /* Note copying of dq into dqs is done so that the negation of dq */ /* on the sign bit leaves dq untouched */ /* ---------------------------------------------------------------- */ dq_s = dq; if (sign) dq_s = -dq_s; levelQ = level * Q + dq_s; /* ---------------------------------------------------------------- */ /* Advance the bitstream forward by subtracting off the code's */ /* length. We speculatively load the potential next word in */ /* the bitstream. */ /* ---------------------------------------------------------------- */ w2 = buf[2]; bit -= nbit; if (bit <= 0) { /* ------------------------------------------------------------ */ /* If we have < 32 valid bits, move the bitstream by one word. */ /* ------------------------------------------------------------ */ w0 = w1; w1 = w2; bit += 32; buf++; } /* ---------------------------------------------------------------- */ /* Extract the top 32 bits from the bitstream for the next iter. */ /* ---------------------------------------------------------------- */ vld_buf = SHL(w0, (32 - bit)) | SHR(w1, bit); /* ---------------------------------------------------------------- */ /* Update the Zig-Zag pointer according to the run-length that */ /* was decoded, and read in the IDCT array index value. */ /* ---------------------------------------------------------------- */ zz += 1 + run;; idx = *zz; /* ---------------------------------------------------------------- */ /* Flag an error if our zig-zag pointer wandered past the end */ /* of the zig-zag table. Set error code to 1 if zz > zz_end */ /* ---------------------------------------------------------------- */ err |= (zz > zz_end); /* ---------------------------------------------------------------- */ /* If there was no error, store the Inv. Quantized coefficient */ /* to the IDCT array. */ /* ---------------------------------------------------------------- */ if (!err) idct[idx] = levelQ; /* ---------------------------------------------------------------- */ /* We've hit 'End of Block' if we've seen a symbol with 'LAST' */ /* set, or if we've seen at least one error. */ /* ---------------------------------------------------------------- */ EOB = last + err; } while (!EOB); /* Loop until end-of-block. */ /* -------------------------------------------------------------------- */ /* Store out our updated bit and word pointers. */ /* -------------------------------------------------------------------- */ *bufPtr = buf; *bitPtr = bit; /* -------------------------------------------------------------------- */ /* Return and report our error status. */ /* -------------------------------------------------------------------- */ return err;}/* ======================================================================== *//* End of file: h263_vld_c.c *//* ------------------------------------------------------------------------ *//* Copyright (c) 2000 Texas Instruments, Incorporated. *//* All Rights Reserved. *//* ======================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -