📄 intrapred.c
字号:
/*COPYRIGHT, LICENSE AND WARRANTY INFORMATIONThis software module has been originally developed by Nokia Corporation. Provided that a person, entity or a company willing to use the Software (hereinafter Licensee) comply with all the terms and conditions of this Statement and subject to the limitations set forth in this Statement Nokia grants to such Licensee a non-exclusive, sub-licensable, worldwide, limited license under copyrights owned by Nokia to use the Software for the sole purpose of creating, manufacturing, selling, marketing, or distributing (including the right to make modifications to the Software) a fully compliant decoder implementation (hereinafter "Decoder") of ITU-T Recommendation H.264 / ISO/IEC International Standard 14496-10 and an encoder implementation producing output that is decodable with the Decoder.Nokia retains the ownership of copyrights to the Software. There is no patent nor other intellectual property right of Nokia licensed under this Statement (except the copyright license above). Licensee hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if patent licenses are required, it is their responsibility to acquire the license before utilizing the Software.The license by Nokia is subject to that the Licensee grants to Nokia the non-exclusive, worldwide, royalty-free, perpetual and irrevocable covenant that the Licensee(s) shall not bring a suit before any court or administrative agency or otherwise assert a claim for infringement under the Licensee intellectual property rights that, but for a license, would be infringed by the Software against (a) Nokia or Nokia's Affiliate; or (b) other recipient of a license and covenant not to sue with respect to the Software from Nokia; or (c) contractor, customer or distributor of a party listed above in a or b, which suit or claim is related to the Software or use thereof.The Licensee(s) further agrees to grant a reciprocal license to Nokia (as granted by Nokia to the Licensee(s) on the modifications made by Licensee(s) to the Software. THE SOFTWARE IS PROVIDED "AS IS" AND THE ORIGINAL DEVELOPER DISCLAIMS ANY AND ALL WARRANTIES WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. THOSE INTENDING TO USE THE SOFTWARE ARE EXPRESSLY ADVISED THAT ITS USE MAY INFRINGE EXISTING PATENTS AND BE SUBJECT TO ROYALTY PAYMENTS TO PATENT OWNERS. ANYONE USING THE SOFTWARE ON THE BASIS OF THIS LICENSE AGREES TO OBTAIN THE NECESSARY PERMISSIONS FROM ANY AND ALL APPLICABLE PATENT OWNERS FOR SUCH USE.IN NO EVENT SHALL THE ORIGINAL DEVELOPER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.This copyright, license and warranty information notice must be retained in all copies and derivative works of the Software or substantial portions thereof.*/#include "globals.h"#include "prederrordec.h"#include "intrapred.h"/* * Prototypes for static functions */static void intraPred4x4(u_int8 predBlk[BLK_SIZE][MBK_SIZE], int mode, u_int8 *reco, int picWidth, int blkAvailBits);/* * * intraPred4x4 * * Parameters: * predBlk Return pointer for predicted pixels * mode Prediction for the block * reco Reconstruction pixels * picWidth Horizontal size of the frame * blkAvailBits Availability of neighboring blocks * * Function: * Compute prediction for one 4x4 block using given mode * * Returns: * - * */static void intraPred4x4(u_int8 predBlk[BLK_SIZE][MBK_SIZE], int mode, u_int8 *reco, int picWidth, int blkAvailBits){ int i, j; int X,A,B,C,D,E,F,G,H,I,J,K,L; int dc; /* * Copy reconstruction pixels used for prediction */ if (blkAvailBits & 0x1000) /* up-left */ X = reco[0]; else X = 128; if (blkAvailBits & 0x0010) { /* up */ A = reco[1]; B = reco[2]; C = reco[3]; D = reco[4]; if (blkAvailBits & 0x0100) { /* up-right */ E = reco[5]; F = reco[6]; G = reco[7]; H = reco[8]; } else E = F = G = H = D; } else A = B = C = D = E = F = G = H = 128; if (blkAvailBits & 0x0001) { /* left */ I = reco[1*picWidth]; J = reco[2*picWidth]; K = reco[3*picWidth]; L = reco[4*picWidth]; } else I = J = K = L = 128; switch (mode) { case IPR_MODE_DC: /* DC PREDICTION */ if ((blkAvailBits & 0x0010) && (blkAvailBits & 0x0001)) /* up & left */ dc = (A+B+C+D+I+J+K+L+4)>>3; else if (blkAvailBits & 0x0010) /* up */ dc = (A+B+C+D+2)>>2; else if (blkAvailBits & 0x0001) /* left */ dc = (I+J+K+L+2)>>2; else dc = 128; for (j = 0; j < BLK_SIZE; j++) { predBlk[j][0] = (u_int8) dc; predBlk[j][1] = (u_int8) dc; predBlk[j][2] = (u_int8) dc; predBlk[j][3] = (u_int8) dc; } break; case IPR_MODE_VERT: /* VERTICAL PREDICTION */ for (j = 0; j < BLK_SIZE; j++) { predBlk[j][0] = (u_int8) A; predBlk[j][1] = (u_int8) B; predBlk[j][2] = (u_int8) C; predBlk[j][3] = (u_int8) D; } break; case IPR_MODE_HOR: /* HORIZONTAL PREDICTION */ for (i = 0; i < BLK_SIZE; i++) { predBlk[0][i] = (u_int8) I; predBlk[1][i] = (u_int8) J; predBlk[2][i] = (u_int8) K; predBlk[3][i] = (u_int8) L; } break; case IPR_MODE_DIAG_DOWN_RIGHT: /* DIAGONAL PREDICTION */ predBlk[3][0] = (u_int8) ((L+2*K+J+2)>>2); predBlk[2][0] = predBlk[3][1] = (u_int8) ((K+2*J+I+2)>>2); predBlk[1][0] = predBlk[2][1] = predBlk[3][2] = (u_int8) ((J+2*I+X+2)>>2); predBlk[0][0] = predBlk[1][1] = predBlk[2][2] = predBlk[3][3] = (u_int8) ((I+2*X+A+2)>>2); predBlk[0][1] = predBlk[1][2] = predBlk[2][3] = (u_int8) ((X+2*A+B+2)>>2); predBlk[0][2] = predBlk[1][3] = (u_int8) ((A+2*B+C+2)>>2); predBlk[0][3] = (u_int8) ((B+2*C+D+2)>>2); break; case IPR_MODE_DIAG_DOWN_LEFT: predBlk[0][0] = (u_int8) ((A+2*B+C+2)>>2); predBlk[0][1] = predBlk[1][0] = (u_int8) ((B+2*C+D+2)>>2); predBlk[0][2] = predBlk[1][1] = predBlk[2][0] = (u_int8) ((C+2*D+E+2)>>2); predBlk[0][3] = predBlk[1][2] = predBlk[2][1] = predBlk[3][0] = (u_int8) ((D+2*E+F+2)>>2); predBlk[1][3] = predBlk[2][2] = predBlk[3][1] = (u_int8) ((E+2*F+G+2)>>2); predBlk[2][3] = predBlk[3][2] = (u_int8) ((F+2*G+H+2)>>2); predBlk[3][3] = (u_int8) ((G+3*H+2)>>2); break; case IPR_MODE_VERT_RIGHT:/* diagonal prediction -22.5 deg to horizontal plane */ predBlk[0][0] = predBlk[2][1] = (u_int8) ((X+A+1)>>1); predBlk[0][1] = predBlk[2][2] = (u_int8) ((A+B+1)>>1); predBlk[0][2] = predBlk[2][3] = (u_int8) ((B+C+1)>>1); predBlk[0][3] = (u_int8) ((C+D+1)>>1); predBlk[1][0] = predBlk[3][1] = (u_int8) ((I+2*X+A+2)>>2); predBlk[1][1] = predBlk[3][2] = (u_int8) ((X+2*A+B+2)>>2); predBlk[1][2] = predBlk[3][3] = (u_int8) ((A+2*B+C+2)>>2); predBlk[1][3] = (u_int8) ((B+2*C+D+2)>>2); predBlk[2][0] = (u_int8) ((X+2*I+J+2)>>2); predBlk[3][0] = (u_int8) ((I+2*J+K+2)>>2); break; case IPR_MODE_VERT_LEFT:/* diagonal prediction -22.5 deg to horizontal plane */ predBlk[0][0] = (u_int8) ((A+B+1)>>1); predBlk[0][1] = predBlk[2][0] = (u_int8) ((B+C+1)>>1); predBlk[0][2] = predBlk[2][1] = (u_int8) ((C+D+1)>>1); predBlk[0][3] = predBlk[2][2] = (u_int8) ((D+E+1)>>1); predBlk[2][3] = (u_int8) ((E+F+1)>>1); predBlk[1][0] = (u_int8) ((A+2*B+C+2)>>2); predBlk[1][1] = predBlk[3][0] = (u_int8) ((B+2*C+D+2)>>2); predBlk[1][2] = predBlk[3][1] = (u_int8) ((C+2*D+E+2)>>2); predBlk[1][3] = predBlk[3][2] = (u_int8) ((D+2*E+F+2)>>2); predBlk[3][3] = (u_int8) ((E+2*F+G+2)>>2); break; case IPR_MODE_HOR_UP:/* diagonal prediction -22.5 deg to horizontal plane */ predBlk[0][0] = (u_int8) ((I+J+1)>>1); predBlk[0][1] = (u_int8) ((I+2*J+K+2)>>2); predBlk[0][2] = predBlk[1][0] = (u_int8) ((J+K+1)>>1); predBlk[0][3] = predBlk[1][1] = (u_int8) ((J+2*K+L+2)>>2); predBlk[1][2] = predBlk[2][0] = (u_int8) ((K+L+1)>>1); predBlk[1][3] = predBlk[2][1] = (u_int8) ((K+2*L+L+2)>>2); predBlk[2][3] = predBlk[3][1] = predBlk[2][2] = predBlk[3][0] = predBlk[3][2] = predBlk[3][3] = (u_int8) L; break; case IPR_MODE_HOR_DOWN:/* diagonal prediction -22.5 deg to horizontal plane */ predBlk[0][0] = predBlk[1][2] = (u_int8) ((X+I+1)>>1); predBlk[0][1] = predBlk[1][3] = (u_int8) ((I+2*X+A+2)>>2); predBlk[0][2] = (u_int8) ((X+2*A+B+2)>>2); predBlk[0][3] = (u_int8) ((A+2*B+C+2)>>2); predBlk[1][0] = predBlk[2][2] = (u_int8) ((I+J+1)>>1); predBlk[1][1] = predBlk[2][3] = (u_int8) ((X+2*I+J+2)>>2); predBlk[2][0] = predBlk[3][2] = (u_int8) ((J+K+1)>>1); predBlk[2][1] = predBlk[3][3] = (u_int8) ((I+2*J+K+2)>>2); predBlk[3][0] = (u_int8) ((K+L+1)>>1); predBlk[3][1] = (u_int8) ((J+2*K+L+2)>>2); break; default: deb0f(stderr, "Illegal 4x4 intra mode\n"); break; }}/* * * iprPredLuma4x4blocks * * Parameters: * coef Transform coefficints for 4x4 blocks * reco Reconstruction pixels * picWidth Horizontal size of the frame * picHeight Vertical size of the frame * ipModes Intra prediction modes for the frame * mbAvailBits Macroblock availability flags * mbIdxX Horz. location of the MB in the frame * mbIdxY Vert. location of the MB in the frame * cbp Coded Block Pattern * qp Quantization parameter * * Function: * Make 4x4 luma intra prediction for all blocks in the macroblock. * * Returns: * - * */void iprPredLuma4x4blocks(int coef[BLK_PER_MB][BLK_PER_MB][BLK_SIZE][BLK_SIZE], u_int8 *reco, int picWidth, int8 *ipModes, int mbAvailBits, int mbIdxX, int mbIdxY, int cbp, int qp){ u_int8 predY[BLK_SIZE][MBK_SIZE]; int blkIdxX, blkIdxY; int blkAvailUp, blkAvailLeft, blkAvailUpRight, blkAvailUpLeft; u_int8 *recoPtr; int blkAvailBits; int blkNum; recoPtr = &reco[mbIdxY*MBK_SIZE*picWidth+mbIdxX*MBK_SIZE]; /* * Check block availability (1 bit per block, 4 directions) */ blkAvailUp = (mbAvailBits & 2) ? 0xFFFF : 0xFFF0; blkAvailLeft = (mbAvailBits & 1) ? 0xFFFF : 0xEEEE; blkAvailUpRight = 0x5750; if (mbAvailBits & 2) blkAvailUpRight |= 0x0007; if (mbAvailBits & 4) blkAvailUpRight |= 0x0008; blkAvailUpLeft = 0xEEE0; if (mbAvailBits & 2) blkAvailUpLeft |= 0x000E; if (mbAvailBits & 1) blkAvailUpLeft |= 0x1110; if (mbAvailBits & 8) blkAvailUpLeft |= 0x0001; /* * Build 4x4 intra prediction */ for (blkIdxY = 0; blkIdxY < BLK_PER_MB; blkIdxY++) { /* Gather availability bits for 4 blocks in raster scan order */ blkAvailBits = ( blkAvailLeft & 0x000f ) | ((blkAvailUp & 0x000f) << 4) | ((blkAvailUpRight & 0x000f) << 8) | ((blkAvailUpLeft & 0x000f) << 12); /* Next 4 blocks */ blkAvailLeft >>= 4; blkAvailUp >>= 4; blkAvailUpRight >>= 4; blkAvailUpLeft >>= 4; for (blkIdxX = 0; blkIdxX < BLK_PER_MB; blkIdxX++) { blkNum = blkIdxY*BLK_PER_MB+blkIdxX; /* Make all possible 4x4 predictions for current block */ intraPred4x4(predY, ipModes[blkIdxX], &recoPtr[blkIdxX*BLK_SIZE-picWidth-1], picWidth, blkAvailBits); if ((cbp>>blkNum) & 1) { pedRecoBlock(predY, coef[blkIdxY][blkIdxX], &recoPtr[blkIdxX*BLK_SIZE], picWidth, 0, 0, qp); } else { pedRecoBlockNoCoef(predY, &recoPtr[blkIdxX*BLK_SIZE], picWidth); } blkAvailBits >>= 1; } recoPtr += BLK_SIZE*picWidth; ipModes += BLK_PER_MB; }}/* * * iprPredLuma16x16
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -