Some newlines were fixed in "Merge pull request #2997 from GuangweiWang/fix-issue-external", but lots were still left behind.
Showing the changes to codec/decoder/core/src/rec_mb.cpp (1 of 14 files). Show all
Unified · Split
| @@ -1,1044 +1,1044 @@ | ||
| 1 | −/*! | |
| 2 | − * \copy | |
| 3 | − * Copyright (c) 2009-2013, Cisco Systems | |
| 4 | − * All rights reserved. | |
| 5 | − * | |
| 6 | − * Redistribution and use in source and binary forms, with or without | |
| 7 | − * modification, are permitted provided that the following conditions | |
| 8 | − * are met: | |
| 9 | − * | |
| 10 | − * * Redistributions of source code must retain the above copyright | |
| 11 | − * notice, this list of conditions and the following disclaimer. | |
| 12 | − * | |
| 13 | − * * Redistributions in binary form must reproduce the above copyright | |
| 14 | − * notice, this list of conditions and the following disclaimer in | |
| 15 | − * the documentation and/or other materials provided with the | |
| 16 | − * distribution. | |
| 17 | − * | |
| 18 | − * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | − * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | − * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | − * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | − * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | − * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | − * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | − * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | − * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | − * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | − * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | − * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | − * | |
| 31 | − * | |
| 32 | − * \file rec_mb.c | |
| 33 | − * | |
| 34 | − * \brief implementation for all macroblock decoding process after mb syntax parsing and residual decoding with cavlc. | |
| 35 | − * | |
| 36 | − * \date 3/18/2009 Created | |
| 37 | − * | |
| 38 | − ************************************************************************************* | |
| 39 | − */ | |
| 40 | − | |
| 41 | − | |
| 42 | −#include "rec_mb.h" | |
| 43 | −#include "decode_slice.h" | |
| 44 | − | |
| 45 | −namespace WelsDec { | |
| 46 | − | |
| 47 | −void WelsFillRecNeededMbInfo (PWelsDecoderContext pCtx, bool bOutput, PDqLayer pCurLayer) { | |
| 48 | − PPicture pCurPic = pCtx->pDec; | |
| 49 | − int32_t iLumaStride = pCurPic->iLinesize[0]; | |
| 50 | − int32_t iChromaStride = pCurPic->iLinesize[1]; | |
| 51 | − int32_t iMbX = pCurLayer->iMbX; | |
| 52 | − int32_t iMbY = pCurLayer->iMbY; | |
| 53 | − | |
| 54 | − pCurLayer->iLumaStride = iLumaStride; | |
| 55 | − pCurLayer->iChromaStride = iChromaStride; | |
| 56 | − | |
| 57 | − if (bOutput) { | |
| 58 | − pCurLayer->pPred[0] = pCurPic->pData[0] + ((iMbY * iLumaStride + iMbX) << 4); | |
| 59 | − pCurLayer->pPred[1] = pCurPic->pData[1] + ((iMbY * iChromaStride + iMbX) << 3); | |
| 60 | − pCurLayer->pPred[2] = pCurPic->pData[2] + ((iMbY * iChromaStride + iMbX) << 3); | |
| 61 | − } | |
| 62 | −} | |
| 63 | − | |
| 64 | −int32_t RecI8x8Mb (int32_t iMbXy, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 65 | − RecI8x8Luma (iMbXy, pCtx, pScoeffLevel, pDqLayer); | |
| 66 | − RecI4x4Chroma (iMbXy, pCtx, pScoeffLevel, pDqLayer); | |
| 67 | − return ERR_NONE; | |
| 68 | −} | |
| 69 | − | |
| 70 | −int32_t RecI8x8Luma (int32_t iMbXy, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 71 | − /*****get local variable from outer variable********/ | |
| 72 | − /*prediction info*/ | |
| 73 | − uint8_t* pPred = pDqLayer->pPred[0]; | |
| 74 | − | |
| 75 | − int32_t iLumaStride = pDqLayer->iLumaStride; | |
| 76 | − int32_t* pBlockOffset = pCtx->iDecBlockOffsetArray; | |
| 77 | − PGetIntraPred8x8Func* pGetI8x8LumaPredFunc = pCtx->pGetI8x8LumaPredFunc; | |
| 78 | − | |
| 79 | − int8_t* pIntra8x8PredMode = pDqLayer->pIntra4x4FinalMode[iMbXy]; // I_NxN | |
| 80 | − int16_t* pRS = pScoeffLevel; | |
| 81 | − /*itransform info*/ | |
| 82 | − PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc8x8; | |
| 83 | − | |
| 84 | − /*************local variable********************/ | |
| 85 | − uint8_t i = 0; | |
| 86 | − bool bTLAvail[4], bTRAvail[4]; | |
| 87 | − // Top-Right : Left : Top-Left : Top | |
| 88 | − bTLAvail[0] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x02); | |
| 89 | − bTLAvail[1] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x01); | |
| 90 | − bTLAvail[2] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x04); | |
| 91 | − bTLAvail[3] = true; | |
| 92 | − | |
| 93 | − bTRAvail[0] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x01); | |
| 94 | − bTRAvail[1] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x08); | |
| 95 | − bTRAvail[2] = true; | |
| 96 | − bTRAvail[3] = false; | |
| 97 | − | |
| 98 | − /*************real process*********************/ | |
| 99 | − for (i = 0; i < 4; i++) { | |
| 100 | − | |
| 101 | − uint8_t* pPredI8x8 = pPred + pBlockOffset[i << 2]; | |
| 102 | − uint8_t uiMode = pIntra8x8PredMode[g_kuiScan4[i << 2]]; | |
| 103 | − | |
| 104 | − pGetI8x8LumaPredFunc[uiMode] (pPredI8x8, iLumaStride, bTLAvail[i], bTRAvail[i]); | |
| 105 | − | |
| 106 | − int32_t iIndex = g_kuiMbCountScan4Idx[i << 2]; | |
| 107 | − if (pDqLayer->pNzc[iMbXy][iIndex] || pDqLayer->pNzc[iMbXy][iIndex + 1] || pDqLayer->pNzc[iMbXy][iIndex + 4] | |
| 108 | − || pDqLayer->pNzc[iMbXy][iIndex + 5]) { | |
| 109 | − int16_t* pRSI8x8 = &pRS[i << 6]; | |
| 110 | − pIdctResAddPredFunc (pPredI8x8, iLumaStride, pRSI8x8); | |
| 111 | − } | |
| 112 | − } | |
| 113 | − | |
| 114 | − return ERR_NONE; | |
| 115 | −} | |
| 116 | − | |
| 117 | −int32_t RecI4x4Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 118 | − RecI4x4Luma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 119 | − RecI4x4Chroma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 120 | − return ERR_NONE; | |
| 121 | −} | |
| 122 | − | |
| 123 | − | |
| 124 | −int32_t RecI4x4Luma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 125 | − /*****get local variable from outer variable********/ | |
| 126 | − /*prediction info*/ | |
| 127 | − uint8_t* pPred = pDqLayer->pPred[0]; | |
| 128 | − | |
| 129 | − int32_t iLumaStride = pDqLayer->iLumaStride; | |
| 130 | − int32_t* pBlockOffset = pCtx->iDecBlockOffsetArray; | |
| 131 | − PGetIntraPredFunc* pGetI4x4LumaPredFunc = pCtx->pGetI4x4LumaPredFunc; | |
| 132 | − | |
| 133 | − int8_t* pIntra4x4PredMode = pDqLayer->pIntra4x4FinalMode[iMBXY]; | |
| 134 | − int16_t* pRS = pScoeffLevel; | |
| 135 | − /*itransform info*/ | |
| 136 | − PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc; | |
| 137 | − | |
| 138 | − | |
| 139 | − /*************local variable********************/ | |
| 140 | − uint8_t i = 0; | |
| 141 | − | |
| 142 | − /*************real process*********************/ | |
| 143 | − for (i = 0; i < 16; i++) { | |
| 144 | − | |
| 145 | − uint8_t* pPredI4x4 = pPred + pBlockOffset[i]; | |
| 146 | − uint8_t uiMode = pIntra4x4PredMode[g_kuiScan4[i]]; | |
| 147 | − | |
| 148 | − pGetI4x4LumaPredFunc[uiMode] (pPredI4x4, iLumaStride); | |
| 149 | − | |
| 150 | − if (pDqLayer->pNzc[iMBXY][g_kuiMbCountScan4Idx[i]]) { | |
| 151 | − int16_t* pRSI4x4 = &pRS[i << 4]; | |
| 152 | − pIdctResAddPredFunc (pPredI4x4, iLumaStride, pRSI4x4); | |
| 153 | − } | |
| 154 | − } | |
| 155 | − | |
| 156 | − return ERR_NONE; | |
| 157 | −} | |
| 158 | − | |
| 159 | − | |
| 160 | −int32_t RecI4x4Chroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 161 | − int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1]; | |
| 162 | − | |
| 163 | − int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY]; | |
| 164 | − | |
| 165 | − PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc; | |
| 166 | − | |
| 167 | − uint8_t* pPred = pDqLayer->pPred[1]; | |
| 168 | − | |
| 169 | − pGetIChromaPredFunc[iChromaPredMode] (pPred, iChromaStride); | |
| 170 | − pPred = pDqLayer->pPred[2]; | |
| 171 | − pGetIChromaPredFunc[iChromaPredMode] (pPred, iChromaStride); | |
| 172 | − | |
| 173 | − RecChroma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 174 | − | |
| 175 | − return ERR_NONE; | |
| 176 | −} | |
| 177 | − | |
| 178 | − | |
| 179 | −int32_t RecI16x16Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 180 | − /*decoder use, encoder no use*/ | |
| 181 | − int8_t iI16x16PredMode = pDqLayer->pIntraPredMode[iMBXY][7]; | |
| 182 | − int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY]; | |
| 183 | − PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc; | |
| 184 | − PGetIntraPredFunc* pGetI16x16LumaPredFunc = pCtx->pGetI16x16LumaPredFunc; | |
| 185 | − int32_t iUVStride = pCtx->pCurDqLayer->pDec->iLinesize[1]; | |
| 186 | − | |
| 187 | − /*common use by decoder&encoder*/ | |
| 188 | − int32_t iYStride = pDqLayer->iLumaStride; | |
| 189 | − int16_t* pRS = pScoeffLevel; | |
| 190 | − | |
| 191 | − uint8_t* pPred = pDqLayer->pPred[0]; | |
| 192 | − | |
| 193 | − PIdctFourResAddPredFunc pIdctFourResAddPredFunc = pCtx->pIdctFourResAddPredFunc; | |
| 194 | − | |
| 195 | − /*decode i16x16 y*/ | |
| 196 | − pGetI16x16LumaPredFunc[iI16x16PredMode] (pPred, iYStride); | |
| 197 | − | |
| 198 | − /*1 mb is divided 16 4x4_block to idct*/ | |
| 199 | − const int8_t* pNzc = pDqLayer->pNzc[iMBXY]; | |
| 200 | − pIdctFourResAddPredFunc (pPred + 0 * iYStride + 0, iYStride, pRS + 0 * 64, pNzc + 0); | |
| 201 | − pIdctFourResAddPredFunc (pPred + 0 * iYStride + 8, iYStride, pRS + 1 * 64, pNzc + 2); | |
| 202 | − pIdctFourResAddPredFunc (pPred + 8 * iYStride + 0, iYStride, pRS + 2 * 64, pNzc + 8); | |
| 203 | − pIdctFourResAddPredFunc (pPred + 8 * iYStride + 8, iYStride, pRS + 3 * 64, pNzc + 10); | |
| 204 | − | |
| 205 | − /*decode intra mb cb&cr*/ | |
| 206 | − pPred = pDqLayer->pPred[1]; | |
| 207 | − pGetIChromaPredFunc[iChromaPredMode] (pPred, iUVStride); | |
| 208 | − pPred = pDqLayer->pPred[2]; | |
| 209 | − pGetIChromaPredFunc[iChromaPredMode] (pPred, iUVStride); | |
| 210 | − RecChroma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 211 | − | |
| 212 | − return ERR_NONE; | |
| 213 | −} | |
| 214 | − | |
| 215 | − | |
| 216 | −//according to current 8*8 block ref_index to gain reference picture | |
| 217 | −static inline void GetRefPic (sMCRefMember* pMCRefMem, PWelsDecoderContext pCtx, int8_t* pRefIdxList, | |
| 218 | − int32_t iIndex, int32_t listIdx) { | |
| 219 | − PPicture pRefPic; | |
| 220 | − | |
| 221 | − int8_t iRefIdx = pRefIdxList[iIndex]; | |
| 222 | − if (iRefIdx >= 0) { | |
| 223 | − pRefPic = pCtx->sRefPic.pRefList[listIdx][iRefIdx]; | |
| 224 | − | |
| 225 | − if (pRefPic != NULL) { | |
| 226 | − pMCRefMem->iSrcLineLuma = pRefPic->iLinesize[0]; | |
| 227 | − pMCRefMem->iSrcLineChroma = pRefPic->iLinesize[1]; | |
| 228 | − | |
| 229 | − pMCRefMem->pSrcY = pRefPic->pData[0]; | |
| 230 | − pMCRefMem->pSrcU = pRefPic->pData[1]; | |
| 231 | − pMCRefMem->pSrcV = pRefPic->pData[2]; | |
| 232 | − } | |
| 233 | − } | |
| 234 | −} | |
| 235 | − | |
| 236 | − | |
| 237 | −#ifndef MC_FLOW_SIMPLE_JUDGE | |
| 238 | −#define MC_FLOW_SIMPLE_JUDGE 1 | |
| 239 | −#endif //MC_FLOW_SIMPLE_JUDGE | |
| 240 | −void BaseMC (sMCRefMember* pMCRefMem, int32_t iXOffset, int32_t iYOffset, SMcFunc* pMCFunc, | |
| 241 | − int32_t iBlkWidth, int32_t iBlkHeight, int16_t iMVs[2]) { | |
| 242 | − int32_t iFullMVx = (iXOffset << 2) + iMVs[0]; //quarter pixel | |
| 243 | − int32_t iFullMVy = (iYOffset << 2) + iMVs[1]; | |
| 244 | − iFullMVx = WELS_CLIP3 (iFullMVx, ((-PADDING_LENGTH + 2) * (1 << 2)), | |
| 245 | − ((pMCRefMem->iPicWidth + PADDING_LENGTH - 19) * (1 << 2))); | |
| 246 | − iFullMVy = WELS_CLIP3 (iFullMVy, ((-PADDING_LENGTH + 2) * (1 << 2)), | |
| 247 | − ((pMCRefMem->iPicHeight + PADDING_LENGTH - 19) * (1 << 2))); | |
| 248 | − | |
| 249 | − int32_t iSrcPixOffsetLuma = (iFullMVx >> 2) + (iFullMVy >> 2) * pMCRefMem->iSrcLineLuma; | |
| 250 | − int32_t iSrcPixOffsetChroma = (iFullMVx >> 3) + (iFullMVy >> 3) * pMCRefMem->iSrcLineChroma; | |
| 251 | − | |
| 252 | − int32_t iBlkWidthChroma = iBlkWidth >> 1; | |
| 253 | − int32_t iBlkHeightChroma = iBlkHeight >> 1; | |
| 254 | − | |
| 255 | − uint8_t* pSrcY = pMCRefMem->pSrcY + iSrcPixOffsetLuma; | |
| 256 | − uint8_t* pSrcU = pMCRefMem->pSrcU + iSrcPixOffsetChroma; | |
| 257 | − uint8_t* pSrcV = pMCRefMem->pSrcV + iSrcPixOffsetChroma; | |
| 258 | − uint8_t* pDstY = pMCRefMem->pDstY; | |
| 259 | − uint8_t* pDstU = pMCRefMem->pDstU; | |
| 260 | − uint8_t* pDstV = pMCRefMem->pDstV; | |
| 261 | − | |
| 262 | − pMCFunc->pMcLumaFunc (pSrcY, pMCRefMem->iSrcLineLuma, pDstY, pMCRefMem->iDstLineLuma, iFullMVx, iFullMVy, iBlkWidth, | |
| 263 | − iBlkHeight); | |
| 264 | − pMCFunc->pMcChromaFunc (pSrcU, pMCRefMem->iSrcLineChroma, pDstU, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy, | |
| 265 | − iBlkWidthChroma, iBlkHeightChroma); | |
| 266 | − pMCFunc->pMcChromaFunc (pSrcV, pMCRefMem->iSrcLineChroma, pDstV, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy, | |
| 267 | − iBlkWidthChroma, iBlkHeightChroma); | |
| 268 | − | |
| 269 | −} | |
| 270 | − | |
| 271 | −static void WeightPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, int32_t listIdx, int32_t iRefIdx, | |
| 272 | − int32_t iBlkWidth, | |
| 273 | − int32_t iBlkHeight) { | |
| 274 | − | |
| 275 | − | |
| 276 | − int32_t iLog2denom, iWoc, iOoc; | |
| 277 | − int32_t iPredTemp, iLineStride; | |
| 278 | − int32_t iPixel = 0; | |
| 279 | − uint8_t* pDst; | |
| 280 | − //luma | |
| 281 | − iLog2denom = pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom; | |
| 282 | − iWoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iLumaWeight[iRefIdx]; | |
| 283 | − iOoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iLumaOffset[iRefIdx]; | |
| 284 | − iLineStride = pMCRefMem->iDstLineLuma; | |
| 285 | − | |
| 286 | − for (int i = 0; i < iBlkHeight; i++) { | |
| 287 | − for (int j = 0; j < iBlkWidth; j++) { | |
| 288 | − iPixel = j + i * (iLineStride); | |
| 289 | − if (iLog2denom >= 1) { | |
| 290 | − iPredTemp = ((pMCRefMem->pDstY[iPixel] * iWoc + (1 << (iLog2denom - 1))) >> iLog2denom) + iOoc; | |
| 291 | − | |
| 292 | − pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 293 | − } else { | |
| 294 | − iPredTemp = pMCRefMem->pDstY[iPixel] * iWoc + iOoc; | |
| 295 | − | |
| 296 | − pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 297 | − | |
| 298 | − } | |
| 299 | − } | |
| 300 | − } | |
| 301 | − | |
| 302 | − | |
| 303 | − //UV | |
| 304 | − iBlkWidth = iBlkWidth >> 1; | |
| 305 | − iBlkHeight = iBlkHeight >> 1; | |
| 306 | − iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 307 | − iLineStride = pMCRefMem->iDstLineChroma; | |
| 308 | − | |
| 309 | − for (int i = 0; i < 2; i++) { | |
| 310 | − | |
| 311 | − | |
| 312 | − //iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 313 | − iWoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iChromaWeight[iRefIdx][i]; | |
| 314 | − iOoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iChromaOffset[iRefIdx][i]; | |
| 315 | − pDst = i ? pMCRefMem->pDstV : pMCRefMem->pDstU; | |
| 316 | − //iLineStride = pMCRefMem->iDstLineChroma; | |
| 317 | − | |
| 318 | − for (int i = 0; i < iBlkHeight ; i++) { | |
| 319 | − for (int j = 0; j < iBlkWidth; j++) { | |
| 320 | − iPixel = j + i * (iLineStride); | |
| 321 | − if (iLog2denom >= 1) { | |
| 322 | − iPredTemp = ((pDst[iPixel] * iWoc + (1 << (iLog2denom - 1))) >> iLog2denom) + iOoc; | |
| 323 | − | |
| 324 | − pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 325 | − } else { | |
| 326 | − iPredTemp = pDst[iPixel] * iWoc + iOoc; | |
| 327 | − | |
| 328 | − pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 329 | − | |
| 330 | − } | |
| 331 | − } | |
| 332 | − | |
| 333 | − } | |
| 334 | − | |
| 335 | − | |
| 336 | − } | |
| 337 | −} | |
| 338 | − | |
| 339 | −static void BiWeightPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, sMCRefMember* pTempMCRefMem, | |
| 340 | − int32_t iRefIdx1, int32_t iRefIdx2, bool bWeightedBipredIdcIs1, int32_t iBlkWidth, | |
| 341 | − int32_t iBlkHeight) { | |
| 342 | − int32_t iWoc1 = 0, iOoc1 = 0, iWoc2 = 0, iOoc2 = 0; | |
| 343 | − int32_t iPredTemp, iLineStride; | |
| 344 | − int32_t iPixel = 0; | |
| 345 | − //luma | |
| 346 | − int32_t iLog2denom = pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom; | |
| 347 | − if (bWeightedBipredIdcIs1) { | |
| 348 | − iWoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iLumaWeight[iRefIdx1]; | |
| 349 | − iOoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iLumaOffset[iRefIdx1]; | |
| 350 | − iWoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iLumaWeight[iRefIdx2]; | |
| 351 | − iOoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iLumaOffset[iRefIdx2]; | |
| 352 | − } else { | |
| 353 | − iWoc1 = pCurDqLayer->pPredWeightTable->iImplicitWeight[iRefIdx1][iRefIdx2]; | |
| 354 | − iWoc2 = 64 - iWoc1; | |
| 355 | − } | |
| 356 | − iLineStride = pMCRefMem->iDstLineLuma; | |
| 357 | − | |
| 358 | − for (int i = 0; i < iBlkHeight; i++) { | |
| 359 | − for (int j = 0; j < iBlkWidth; j++) { | |
| 360 | − iPixel = j + i * (iLineStride); | |
| 361 | − iPredTemp = ((pMCRefMem->pDstY[iPixel] * iWoc1 + pTempMCRefMem->pDstY[iPixel] * iWoc2 + (1 << iLog2denom)) >> | |
| 362 | − (iLog2denom + 1)) + ((iOoc1 + iOoc2 + 1) >> 1); | |
| 363 | − pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 364 | − } | |
| 365 | − } | |
| 366 | − | |
| 367 | − //UV | |
| 368 | − iBlkWidth = iBlkWidth >> 1; | |
| 369 | − iBlkHeight = iBlkHeight >> 1; | |
| 370 | − iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 371 | − iLineStride = pMCRefMem->iDstLineChroma; | |
| 372 | − | |
| 373 | − uint8_t* pDst; | |
| 374 | − uint8_t* pTempDst; | |
| 375 | − for (int k = 0; k < 2; k++) { | |
| 376 | − //iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 377 | − if (bWeightedBipredIdcIs1) { | |
| 378 | − iWoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iChromaWeight[iRefIdx1][k]; | |
| 379 | − iOoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iChromaOffset[iRefIdx1][k]; | |
| 380 | − iWoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iChromaWeight[iRefIdx2][k]; | |
| 381 | − iOoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iChromaOffset[iRefIdx2][k]; | |
| 382 | − } | |
| 383 | − pDst = k ? pMCRefMem->pDstV : pMCRefMem->pDstU; | |
| 384 | − pTempDst = k ? pTempMCRefMem->pDstV : pTempMCRefMem->pDstU; | |
| 385 | − //iLineStride = pMCRefMem->iDstLineChroma; | |
| 386 | − | |
| 387 | − for (int i = 0; i < iBlkHeight; i++) { | |
| 388 | − for (int j = 0; j < iBlkWidth; j++) { | |
| 389 | − iPixel = j + i * (iLineStride); | |
| 390 | − iPredTemp = ((pDst[iPixel] * iWoc1 + pTempDst[iPixel] * iWoc2 + (1 << iLog2denom)) >> (iLog2denom + 1)) + (( | |
| 391 | − iOoc1 + iOoc2 + 1) >> 1); | |
| 392 | − pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 393 | − } | |
| 394 | − } | |
| 395 | − } | |
| 396 | −} | |
| 397 | − | |
| 398 | −static void BiPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, sMCRefMember* pTempMCRefMem, int32_t iBlkWidth, | |
| 399 | − int32_t iBlkHeight) { | |
| 400 | − int32_t iPredTemp, iLineStride; | |
| 401 | − int32_t iPixel = 0; | |
| 402 | − //luma | |
| 403 | − iLineStride = pMCRefMem->iDstLineLuma; | |
| 404 | − | |
| 405 | − for (int i = 0; i < iBlkHeight; i++) { | |
| 406 | − for (int j = 0; j < iBlkWidth; j++) { | |
| 407 | − iPixel = j + i * (iLineStride); | |
| 408 | − iPredTemp = (pMCRefMem->pDstY[iPixel] + pTempMCRefMem->pDstY[iPixel] + 1) >> 1; | |
| 409 | − pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 410 | − } | |
| 411 | − } | |
| 412 | − | |
| 413 | − //UV | |
| 414 | − iBlkWidth = iBlkWidth >> 1; | |
| 415 | − iBlkHeight = iBlkHeight >> 1; | |
| 416 | − iLineStride = pMCRefMem->iDstLineChroma; | |
| 417 | − | |
| 418 | − uint8_t* pDst; | |
| 419 | − uint8_t* pTempDst; | |
| 420 | − for (int k = 0; k < 2; k++) { | |
| 421 | − pDst = k ? pMCRefMem->pDstV : pMCRefMem->pDstU; | |
| 422 | − pTempDst = k ? pTempMCRefMem->pDstV : pTempMCRefMem->pDstU; | |
| 423 | − //iLineStride = pMCRefMem->iDstLineChroma; | |
| 424 | − | |
| 425 | − for (int i = 0; i < iBlkHeight; i++) { | |
| 426 | − for (int j = 0; j < iBlkWidth; j++) { | |
| 427 | − iPixel = j + i * (iLineStride); | |
| 428 | − iPredTemp = (pDst[iPixel] + pTempDst[iPixel] + 1) >> 1; | |
| 429 | − pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 430 | − } | |
| 431 | − } | |
| 432 | − } | |
| 433 | −} | |
| 434 | − | |
| 435 | −void GetInterPred (uint8_t* pPredY, uint8_t* pPredCb, uint8_t* pPredCr, PWelsDecoderContext pCtx) { | |
| 436 | − sMCRefMember pMCRefMem; | |
| 437 | − PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 438 | − SMcFunc* pMCFunc = &pCtx->sMcFunc; | |
| 439 | − | |
| 440 | − int32_t iMBXY = pCurDqLayer->iMbXyIndex; | |
| 441 | − | |
| 442 | − int16_t iMVs[2] = {0}; | |
| 443 | − | |
| 444 | − uint32_t iMBType = pCurDqLayer->pMbType[iMBXY]; | |
| 445 | − | |
| 446 | − int32_t iMBOffsetX = pCurDqLayer->iMbX << 4; | |
| 447 | − int32_t iMBOffsetY = pCurDqLayer->iMbY << 4; | |
| 448 | − | |
| 449 | − int32_t iDstLineLuma = pCtx->pDec->iLinesize[0]; | |
| 450 | − int32_t iDstLineChroma = pCtx->pDec->iLinesize[1]; | |
| 451 | − | |
| 452 | − int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, i, j, iIIdx, iJIdx; | |
| 453 | − | |
| 454 | − pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth << 4); | |
| 455 | − pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight << 4); | |
| 456 | − | |
| 457 | − pMCRefMem.pDstY = pPredY; | |
| 458 | − pMCRefMem.pDstU = pPredCb; | |
| 459 | − pMCRefMem.pDstV = pPredCr; | |
| 460 | − | |
| 461 | − pMCRefMem.iDstLineLuma = iDstLineLuma; | |
| 462 | − pMCRefMem.iDstLineChroma = iDstLineChroma; | |
| 463 | − | |
| 464 | − int32_t iRefIndex = 0; | |
| 465 | − | |
| 466 | − switch (iMBType) { | |
| 467 | − case MB_TYPE_SKIP: | |
| 468 | − case MB_TYPE_16x16: | |
| 469 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 470 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 471 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0); | |
| 472 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 473 | − | |
| 474 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 475 | − iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0]; | |
| 476 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 16); | |
| 477 | − } | |
| 478 | − break; | |
| 479 | − case MB_TYPE_16x8: | |
| 480 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 481 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 482 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0); | |
| 483 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 8, iMVs); | |
| 484 | − | |
| 485 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 486 | − iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0]; | |
| 487 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 8); | |
| 488 | − } | |
| 489 | − | |
| 490 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][8][0]; | |
| 491 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][8][1]; | |
| 492 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 8, LIST_0); | |
| 493 | − pMCRefMem.pDstY = pPredY + (iDstLineLuma << 3); | |
| 494 | − pMCRefMem.pDstU = pPredCb + (iDstLineChroma << 2); | |
| 495 | − pMCRefMem.pDstV = pPredCr + (iDstLineChroma << 2); | |
| 496 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY + 8, pMCFunc, 16, 8, iMVs); | |
| 497 | − | |
| 498 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 499 | − iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][8]; | |
| 500 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 8); | |
| 501 | − } | |
| 502 | − break; | |
| 503 | − case MB_TYPE_8x16: | |
| 504 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 505 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 506 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0); | |
| 507 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 508 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 509 | − iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0]; | |
| 510 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 16); | |
| 511 | − } | |
| 512 | − | |
| 513 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][2][0]; | |
| 514 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][2][1]; | |
| 515 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 2, LIST_0); | |
| 516 | − pMCRefMem.pDstY = pPredY + 8; | |
| 517 | − pMCRefMem.pDstU = pPredCb + 4; | |
| 518 | − pMCRefMem.pDstV = pPredCr + 4; | |
| 519 | − BaseMC (&pMCRefMem, iMBOffsetX + 8, iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 520 | − | |
| 521 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 522 | − iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][2]; | |
| 523 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 16); | |
| 524 | − } | |
| 525 | − break; | |
| 526 | − case MB_TYPE_8x8: | |
| 527 | − case MB_TYPE_8x8_REF0: { | |
| 528 | − uint32_t iSubMBType; | |
| 529 | − int32_t iXOffset, iYOffset; | |
| 530 | − uint8_t* pDstY, *pDstU, *pDstV; | |
| 531 | − for (i = 0; i < 4; i++) { | |
| 532 | − iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i]; | |
| 533 | − iBlk8X = (i & 1) << 3; | |
| 534 | − iBlk8Y = (i >> 1) << 3; | |
| 535 | − iXOffset = iMBOffsetX + iBlk8X; | |
| 536 | − iYOffset = iMBOffsetY + iBlk8Y; | |
| 537 | − | |
| 538 | − iIIdx = ((i >> 1) << 3) + ((i & 1) << 1); | |
| 539 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], iIIdx, LIST_0); | |
| 540 | − iRefIndex = pCurDqLayer->bUseWeightPredictionFlag ? pCurDqLayer->pRefIndex[0][iMBXY][iIIdx] : 0; | |
| 541 | − | |
| 542 | − pDstY = pPredY + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 543 | − pDstU = pPredCb + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 544 | − pDstV = pPredCr + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 545 | − pMCRefMem.pDstY = pDstY; | |
| 546 | − pMCRefMem.pDstU = pDstU; | |
| 547 | − pMCRefMem.pDstV = pDstV; | |
| 548 | − switch (iSubMBType) { | |
| 549 | − case SUB_MB_TYPE_8x8: | |
| 550 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 551 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 552 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 553 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 554 | − | |
| 555 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 8); | |
| 556 | − } | |
| 557 | − | |
| 558 | − break; | |
| 559 | − case SUB_MB_TYPE_8x4: | |
| 560 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 561 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 562 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 563 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 564 | − | |
| 565 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 4); | |
| 566 | − } | |
| 567 | − | |
| 568 | − | |
| 569 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 4][0]; | |
| 570 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 4][1]; | |
| 571 | − pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 572 | − pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 573 | − pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 574 | − BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 575 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 576 | − | |
| 577 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 4); | |
| 578 | − } | |
| 579 | − | |
| 580 | − break; | |
| 581 | − case SUB_MB_TYPE_4x8: | |
| 582 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 583 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 584 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 585 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 586 | − | |
| 587 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 8); | |
| 588 | − } | |
| 589 | − | |
| 590 | − | |
| 591 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 1][0]; | |
| 592 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 1][1]; | |
| 593 | − pMCRefMem.pDstY += 4; | |
| 594 | − pMCRefMem.pDstU += 2; | |
| 595 | − pMCRefMem.pDstV += 2; | |
| 596 | − BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 597 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 598 | − | |
| 599 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 8); | |
| 600 | − } | |
| 601 | − | |
| 602 | − break; | |
| 603 | − case SUB_MB_TYPE_4x4: { | |
| 604 | − for (j = 0; j < 4; j++) { | |
| 605 | − int32_t iUVLineStride; | |
| 606 | − iJIdx = ((j >> 1) << 2) + (j & 1); | |
| 607 | − | |
| 608 | − iBlk4X = (j & 1) << 2; | |
| 609 | − iBlk4Y = (j >> 1) << 2; | |
| 610 | − | |
| 611 | − iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 612 | − pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 613 | − pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 614 | − pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 615 | − | |
| 616 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + iJIdx][0]; | |
| 617 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + iJIdx][1]; | |
| 618 | − BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 619 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 620 | − | |
| 621 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 4); | |
| 622 | − } | |
| 623 | − | |
| 624 | − } | |
| 625 | − } | |
| 626 | − break; | |
| 627 | − default: | |
| 628 | − break; | |
| 629 | − } | |
| 630 | − } | |
| 631 | − } | |
| 632 | − break; | |
| 633 | − default: | |
| 634 | − break; | |
| 635 | − } | |
| 636 | −} | |
| 637 | − | |
| 638 | −void GetInterBPred (uint8_t* pPredYCbCr[3], uint8_t* pTempPredYCbCr[3], PWelsDecoderContext pCtx) { | |
| 639 | − sMCRefMember pMCRefMem; | |
| 640 | − sMCRefMember pTempMCRefMem; | |
| 641 | − | |
| 642 | − PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 643 | − SMcFunc* pMCFunc = &pCtx->sMcFunc; | |
| 644 | − | |
| 645 | − int32_t iMBXY = pCurDqLayer->iMbXyIndex; | |
| 646 | − | |
| 647 | − int16_t iMVs[2] = { 0 }; | |
| 648 | − | |
| 649 | − uint32_t iMBType = pCurDqLayer->pMbType[iMBXY]; | |
| 650 | − | |
| 651 | − int32_t iMBOffsetX = pCurDqLayer->iMbX << 4; | |
| 652 | − int32_t iMBOffsetY = pCurDqLayer->iMbY << 4; | |
| 653 | − | |
| 654 | − int32_t iDstLineLuma = pCtx->pDec->iLinesize[0]; | |
| 655 | − int32_t iDstLineChroma = pCtx->pDec->iLinesize[1]; | |
| 656 | − | |
| 657 | − | |
| 658 | − pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth << 4); | |
| 659 | − pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight << 4); | |
| 660 | − | |
| 661 | − pMCRefMem.pDstY = pPredYCbCr[0]; | |
| 662 | − pMCRefMem.pDstU = pPredYCbCr[1]; | |
| 663 | − pMCRefMem.pDstV = pPredYCbCr[2]; | |
| 664 | − | |
| 665 | − pMCRefMem.iDstLineLuma = iDstLineLuma; | |
| 666 | − pMCRefMem.iDstLineChroma = iDstLineChroma; | |
| 667 | − | |
| 668 | − pTempMCRefMem = pMCRefMem; | |
| 669 | − pTempMCRefMem.pDstY = pTempPredYCbCr[0]; | |
| 670 | − pTempMCRefMem.pDstU = pTempPredYCbCr[1]; | |
| 671 | − pTempMCRefMem.pDstV = pTempPredYCbCr[2]; | |
| 672 | − | |
| 673 | − | |
| 674 | − int32_t iRefIndex1 = 0; | |
| 675 | − int32_t iRefIndex2 = 0; | |
| 676 | − | |
| 677 | − bool bWeightedBipredIdcIs1 = pCurDqLayer->sLayerInfo.pPps->uiWeightedBipredIdc == 1; | |
| 678 | − | |
| 679 | − if (IS_INTER_16x16 (iMBType)) { | |
| 680 | − if (IS_TYPE_L0 (iMBType) && IS_TYPE_L1 (iMBType)) { | |
| 681 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][0][0]; | |
| 682 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][0][1]; | |
| 683 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_0][iMBXY], 0, LIST_0); | |
| 684 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 685 | − | |
| 686 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][0][0]; | |
| 687 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][0][1]; | |
| 688 | − GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], 0, LIST_1); | |
| 689 | − BaseMC (&pTempMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 690 | − iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][0]; | |
| 691 | − iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][0]; | |
| 692 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 693 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 16, 16); | |
| 694 | − } else { | |
| 695 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 16, 16); | |
| 696 | − } | |
| 697 | − } else { | |
| 698 | − int32_t listIdx = (iMBType & MB_TYPE_P0L0) ? LIST_0 : LIST_1; | |
| 699 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][0][0]; | |
| 700 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][0][1]; | |
| 701 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], 0, listIdx); | |
| 702 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 703 | − if (bWeightedBipredIdcIs1) { | |
| 704 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][0]; | |
| 705 | − WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 16, 16); | |
| 706 | − } | |
| 707 | − } | |
| 708 | − } else if (IS_INTER_16x8 (iMBType)) { | |
| 709 | − for (int32_t i = 0; i < 2; ++i) { | |
| 710 | − int32_t iPartIdx = i << 3; | |
| 711 | − uint32_t listCount = 0; | |
| 712 | − int32_t lastListIdx = LIST_0; | |
| 713 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 714 | − if (IS_DIR (iMBType, i, listIdx)) { | |
| 715 | − lastListIdx = listIdx; | |
| 716 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iPartIdx][0]; | |
| 717 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iPartIdx][1]; | |
| 718 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], iPartIdx, listIdx); | |
| 719 | − if (i) { | |
| 720 | − pMCRefMem.pDstY += (iDstLineLuma << 3); | |
| 721 | − pMCRefMem.pDstU += (iDstLineChroma << 2); | |
| 722 | − pMCRefMem.pDstV += (iDstLineChroma << 2); | |
| 723 | − } | |
| 724 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY + iPartIdx, pMCFunc, 16, 8, iMVs); | |
| 725 | − if (++listCount == 2) { | |
| 726 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iPartIdx][0]; | |
| 727 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iPartIdx][1]; | |
| 728 | − GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], iPartIdx, LIST_1); | |
| 729 | − if (i) { | |
| 730 | − pTempMCRefMem.pDstY += (iDstLineLuma << 3); | |
| 731 | − pTempMCRefMem.pDstU += (iDstLineChroma << 2); | |
| 732 | − pTempMCRefMem.pDstV += (iDstLineChroma << 2); | |
| 733 | − } | |
| 734 | − BaseMC (&pTempMCRefMem, iMBOffsetX, iMBOffsetY + iPartIdx, pMCFunc, 16, 8, iMVs); | |
| 735 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 736 | − iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][iPartIdx]; | |
| 737 | − iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][iPartIdx]; | |
| 738 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 16, 8); | |
| 739 | − } else { | |
| 740 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 16, 8); | |
| 741 | − } | |
| 742 | − } | |
| 743 | − } | |
| 744 | − } | |
| 745 | − if (listCount == 1) { | |
| 746 | − if (bWeightedBipredIdcIs1) { | |
| 747 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[lastListIdx][iMBXY][iPartIdx]; | |
| 748 | − WeightPrediction (pCurDqLayer, &pMCRefMem, lastListIdx, iRefIndex, 16, 8); | |
| 749 | − } | |
| 750 | − } | |
| 751 | − } | |
| 752 | − } else if (IS_INTER_8x16 (iMBType)) { | |
| 753 | − for (int32_t i = 0; i < 2; ++i) { | |
| 754 | − uint32_t listCount = 0; | |
| 755 | − int32_t lastListIdx = LIST_0; | |
| 756 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 757 | − if (IS_DIR (iMBType, i, listIdx)) { | |
| 758 | − lastListIdx = listIdx; | |
| 759 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][i << 1][0]; | |
| 760 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][i << 1][1]; | |
| 761 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], i << 1, listIdx); | |
| 762 | − if (i) { | |
| 763 | − pMCRefMem.pDstY += 8; | |
| 764 | − pMCRefMem.pDstU += 4; | |
| 765 | − pMCRefMem.pDstV += 4; | |
| 766 | − } | |
| 767 | − BaseMC (&pMCRefMem, iMBOffsetX + (i ? 8 : 0), iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 768 | − if (++listCount == 2) { | |
| 769 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][i << 1][0]; | |
| 770 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][i << 1][1]; | |
| 771 | − GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], i << 1, LIST_1); | |
| 772 | − if (i) { | |
| 773 | − pTempMCRefMem.pDstY += 8; | |
| 774 | − pTempMCRefMem.pDstU += 4; | |
| 775 | − pTempMCRefMem.pDstV += 4; | |
| 776 | − } | |
| 777 | − BaseMC (&pTempMCRefMem, iMBOffsetX + (i ? 8 : 0), iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 778 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 779 | − iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][i << 1]; | |
| 780 | − iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][i << 1]; | |
| 781 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 16); | |
| 782 | − } else { | |
| 783 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 16); | |
| 784 | − } | |
| 785 | − } | |
| 786 | − } | |
| 787 | − } | |
| 788 | − if (listCount == 1) { | |
| 789 | − if (bWeightedBipredIdcIs1) { | |
| 790 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[lastListIdx][iMBXY][i << 1]; | |
| 791 | − WeightPrediction (pCurDqLayer, &pMCRefMem, lastListIdx, iRefIndex, 8, 16); | |
| 792 | − } | |
| 793 | − } | |
| 794 | − } | |
| 795 | − } else if (IS_Inter_8x8 (iMBType)) { | |
| 796 | − int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, iIIdx, iJIdx; | |
| 797 | − uint32_t iSubMBType; | |
| 798 | − int32_t iXOffset, iYOffset; | |
| 799 | − uint8_t* pDstY, *pDstU, *pDstV; | |
| 800 | − uint8_t* pDstY2, *pDstU2, *pDstV2; | |
| 801 | − for (int32_t i = 0; i < 4; i++) { | |
| 802 | − iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i]; | |
| 803 | − iBlk8X = (i & 1) << 3; | |
| 804 | − iBlk8Y = (i >> 1) << 3; | |
| 805 | − iXOffset = iMBOffsetX + iBlk8X; | |
| 806 | − iYOffset = iMBOffsetY + iBlk8Y; | |
| 807 | − | |
| 808 | − iIIdx = ((i >> 1) << 3) + ((i & 1) << 1); | |
| 809 | − | |
| 810 | − pDstY = pPredYCbCr[0] + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 811 | − pDstU = pPredYCbCr[1] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 812 | − pDstV = pPredYCbCr[2] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 813 | − pMCRefMem.pDstY = pDstY; | |
| 814 | − pMCRefMem.pDstU = pDstU; | |
| 815 | − pMCRefMem.pDstV = pDstV; | |
| 816 | − | |
| 817 | − pTempMCRefMem = pMCRefMem; | |
| 818 | − pDstY2 = pTempPredYCbCr[0] + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 819 | − pDstU2 = pTempPredYCbCr[1] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 820 | − pDstV2 = pTempPredYCbCr[2] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 821 | − | |
| 822 | − pTempMCRefMem.pDstY = pDstY2; | |
| 823 | − pTempMCRefMem.pDstU = pDstU2; | |
| 824 | − pTempMCRefMem.pDstV = pDstV2; | |
| 825 | − | |
| 826 | − if ((IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType))) { | |
| 827 | − iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][iIIdx]; | |
| 828 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_0][iMBXY], iIIdx, LIST_0); | |
| 829 | − | |
| 830 | − iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][iIIdx]; | |
| 831 | − GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], iIIdx, LIST_1); | |
| 832 | − } else { | |
| 833 | − int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 834 | − iRefIndex1 = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 835 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], iIIdx, listIdx); | |
| 836 | − } | |
| 837 | − | |
| 838 | − if (IS_SUB_8x8 (iSubMBType)) { | |
| 839 | − if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { | |
| 840 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0]; | |
| 841 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1]; | |
| 842 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 843 | − | |
| 844 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0]; | |
| 845 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1]; | |
| 846 | − BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 847 | − | |
| 848 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 849 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 8); | |
| 850 | − } else { | |
| 851 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 8); | |
| 852 | − } | |
| 853 | − } else { | |
| 854 | − int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 855 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0]; | |
| 856 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1]; | |
| 857 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 858 | − if (bWeightedBipredIdcIs1) { | |
| 859 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 860 | − WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 8, 8); | |
| 861 | − } | |
| 862 | − } | |
| 863 | − } else if (IS_SUB_8x4 (iSubMBType)) { | |
| 864 | − if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { //B_Bi_8x4 | |
| 865 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0]; | |
| 866 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1]; | |
| 867 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 868 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0]; | |
| 869 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1]; | |
| 870 | − BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 871 | − | |
| 872 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 873 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 4); | |
| 874 | − } else { | |
| 875 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 4); | |
| 876 | − } | |
| 877 | − | |
| 878 | − pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 879 | − pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 880 | − pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 881 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 4][0]; | |
| 882 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 4][1]; | |
| 883 | − BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 884 | − | |
| 885 | − pTempMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 886 | − pTempMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 887 | − pTempMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 888 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 4][0]; | |
| 889 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 4][1]; | |
| 890 | − BaseMC (&pTempMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 891 | − | |
| 892 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 893 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 4); | |
| 894 | − } else { | |
| 895 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 4); | |
| 896 | − } | |
| 897 | − } else { //B_L0_8x4 B_L1_8x4 | |
| 898 | − int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 899 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0]; | |
| 900 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1]; | |
| 901 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 902 | − pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 903 | − pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 904 | − pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 905 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 4][0]; | |
| 906 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 4][1]; | |
| 907 | − BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 908 | − if (bWeightedBipredIdcIs1) { | |
| 909 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 910 | − WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 8, 4); | |
| 911 | − } | |
| 912 | − } | |
| 913 | − } else if (IS_SUB_4x8 (iSubMBType)) { | |
| 914 | − if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { //B_Bi_4x8 | |
| 915 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0]; | |
| 916 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1]; | |
| 917 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 918 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0]; | |
| 919 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1]; | |
| 920 | − BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 921 | − | |
| 922 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 923 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 8); | |
| 924 | − } else { | |
| 925 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 8); | |
| 926 | − } | |
| 927 | − | |
| 928 | − pMCRefMem.pDstY += 4; | |
| 929 | − pMCRefMem.pDstU += 2; | |
| 930 | − pMCRefMem.pDstV += 2; | |
| 931 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 1][0]; | |
| 932 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 1][1]; | |
| 933 | − BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 934 | − | |
| 935 | − pTempMCRefMem.pDstY += 4; | |
| 936 | − pTempMCRefMem.pDstU += 2; | |
| 937 | − pTempMCRefMem.pDstV += 2; | |
| 938 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 1][0]; | |
| 939 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 1][1]; | |
| 940 | − BaseMC (&pTempMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 941 | − | |
| 942 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 943 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 8); | |
| 944 | − } else { | |
| 945 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 8); | |
| 946 | − } | |
| 947 | − } else { //B_L0_4x8 B_L1_4x8 | |
| 948 | − int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 949 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0]; | |
| 950 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1]; | |
| 951 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 952 | − pMCRefMem.pDstY += 4; | |
| 953 | − pMCRefMem.pDstU += 2; | |
| 954 | − pMCRefMem.pDstV += 2; | |
| 955 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 1][0]; | |
| 956 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 1][1]; | |
| 957 | − BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 958 | − if (bWeightedBipredIdcIs1) { | |
| 959 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 960 | − WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 4, 8); | |
| 961 | − } | |
| 962 | − } | |
| 963 | − } else if (IS_SUB_4x4 (iSubMBType)) { | |
| 964 | − if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { | |
| 965 | − for (int32_t j = 0; j < 4; j++) { | |
| 966 | − int32_t iUVLineStride; | |
| 967 | − iJIdx = ((j >> 1) << 2) + (j & 1); | |
| 968 | − | |
| 969 | − iBlk4X = (j & 1) << 2; | |
| 970 | − iBlk4Y = (j >> 1) << 2; | |
| 971 | − | |
| 972 | − iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 973 | − pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 974 | − pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 975 | − pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 976 | − | |
| 977 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + iJIdx][0]; | |
| 978 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + iJIdx][1]; | |
| 979 | − BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 980 | − | |
| 981 | − pTempMCRefMem.pDstY = pDstY2 + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 982 | − pTempMCRefMem.pDstU = pDstU2 + iUVLineStride; | |
| 983 | − pTempMCRefMem.pDstV = pDstV2 + iUVLineStride;; | |
| 984 | − | |
| 985 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + iJIdx][0]; | |
| 986 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + iJIdx][1]; | |
| 987 | − BaseMC (&pTempMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 988 | − | |
| 989 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 990 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 4); | |
| 991 | − } else { | |
| 992 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 4); | |
| 993 | − } | |
| 994 | − } | |
| 995 | − } else { | |
| 996 | − int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 997 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 998 | − for (int32_t j = 0; j < 4; j++) { | |
| 999 | − int32_t iUVLineStride; | |
| 1000 | − iJIdx = ((j >> 1) << 2) + (j & 1); | |
| 1001 | − | |
| 1002 | − iBlk4X = (j & 1) << 2; | |
| 1003 | − iBlk4Y = (j >> 1) << 2; | |
| 1004 | − | |
| 1005 | − iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 1006 | − pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 1007 | − pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 1008 | − pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 1009 | − | |
| 1010 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + iJIdx][0]; | |
| 1011 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + iJIdx][1]; | |
| 1012 | − BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 1013 | − if (bWeightedBipredIdcIs1) { | |
| 1014 | − WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 4, 4); | |
| 1015 | − } | |
| 1016 | − } | |
| 1017 | − } | |
| 1018 | − } | |
| 1019 | − } | |
| 1020 | − } | |
| 1021 | −} | |
| 1022 | − | |
| 1023 | −int32_t RecChroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 1024 | − int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1]; | |
| 1025 | − PIdctFourResAddPredFunc pIdctFourResAddPredFunc = pCtx->pIdctFourResAddPredFunc; | |
| 1026 | − | |
| 1027 | − uint8_t i = 0; | |
| 1028 | − uint8_t uiCbpC = pDqLayer->pCbp[iMBXY] >> 4; | |
| 1029 | − | |
| 1030 | − if (1 == uiCbpC || 2 == uiCbpC) { | |
| 1031 | − for (i = 0; i < 2; i++) { | |
| 1032 | − int16_t* pRS = pScoeffLevel + 256 + (i << 6); | |
| 1033 | − uint8_t* pPred = pDqLayer->pPred[i + 1]; | |
| 1034 | − const int8_t* pNzc = pDqLayer->pNzc[iMBXY] + 16 + 2 * i; | |
| 1035 | − | |
| 1036 | − /*1 chroma is divided 4 4x4_block to idct*/ | |
| 1037 | − pIdctFourResAddPredFunc (pPred, iChromaStride, pRS, pNzc); | |
| 1038 | − } | |
| 1039 | − } | |
| 1040 | − | |
| 1041 | − return ERR_NONE; | |
| 1042 | −} | |
| 1043 | − | |
| 1044 | −} // namespace WelsDec | |
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2009-2013, Cisco Systems | |
| 4 | + * All rights reserved. | |
| 5 | + * | |
| 6 | + * Redistribution and use in source and binary forms, with or without | |
| 7 | + * modification, are permitted provided that the following conditions | |
| 8 | + * are met: | |
| 9 | + * | |
| 10 | + * * Redistributions of source code must retain the above copyright | |
| 11 | + * notice, this list of conditions and the following disclaimer. | |
| 12 | + * | |
| 13 | + * * Redistributions in binary form must reproduce the above copyright | |
| 14 | + * notice, this list of conditions and the following disclaimer in | |
| 15 | + * the documentation and/or other materials provided with the | |
| 16 | + * distribution. | |
| 17 | + * | |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | + * | |
| 31 | + * | |
| 32 | + * \file rec_mb.c | |
| 33 | + * | |
| 34 | + * \brief implementation for all macroblock decoding process after mb syntax parsing and residual decoding with cavlc. | |
| 35 | + * | |
| 36 | + * \date 3/18/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | + | |
| 41 | + | |
| 42 | +#include "rec_mb.h" | |
| 43 | +#include "decode_slice.h" | |
| 44 | + | |
| 45 | +namespace WelsDec { | |
| 46 | + | |
| 47 | +void WelsFillRecNeededMbInfo (PWelsDecoderContext pCtx, bool bOutput, PDqLayer pCurLayer) { | |
| 48 | + PPicture pCurPic = pCtx->pDec; | |
| 49 | + int32_t iLumaStride = pCurPic->iLinesize[0]; | |
| 50 | + int32_t iChromaStride = pCurPic->iLinesize[1]; | |
| 51 | + int32_t iMbX = pCurLayer->iMbX; | |
| 52 | + int32_t iMbY = pCurLayer->iMbY; | |
| 53 | + | |
| 54 | + pCurLayer->iLumaStride = iLumaStride; | |
| 55 | + pCurLayer->iChromaStride = iChromaStride; | |
| 56 | + | |
| 57 | + if (bOutput) { | |
| 58 | + pCurLayer->pPred[0] = pCurPic->pData[0] + ((iMbY * iLumaStride + iMbX) << 4); | |
| 59 | + pCurLayer->pPred[1] = pCurPic->pData[1] + ((iMbY * iChromaStride + iMbX) << 3); | |
| 60 | + pCurLayer->pPred[2] = pCurPic->pData[2] + ((iMbY * iChromaStride + iMbX) << 3); | |
| 61 | + } | |
| 62 | +} | |
| 63 | + | |
| 64 | +int32_t RecI8x8Mb (int32_t iMbXy, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 65 | + RecI8x8Luma (iMbXy, pCtx, pScoeffLevel, pDqLayer); | |
| 66 | + RecI4x4Chroma (iMbXy, pCtx, pScoeffLevel, pDqLayer); | |
| 67 | + return ERR_NONE; | |
| 68 | +} | |
| 69 | + | |
| 70 | +int32_t RecI8x8Luma (int32_t iMbXy, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 71 | + /*****get local variable from outer variable********/ | |
| 72 | + /*prediction info*/ | |
| 73 | + uint8_t* pPred = pDqLayer->pPred[0]; | |
| 74 | + | |
| 75 | + int32_t iLumaStride = pDqLayer->iLumaStride; | |
| 76 | + int32_t* pBlockOffset = pCtx->iDecBlockOffsetArray; | |
| 77 | + PGetIntraPred8x8Func* pGetI8x8LumaPredFunc = pCtx->pGetI8x8LumaPredFunc; | |
| 78 | + | |
| 79 | + int8_t* pIntra8x8PredMode = pDqLayer->pIntra4x4FinalMode[iMbXy]; // I_NxN | |
| 80 | + int16_t* pRS = pScoeffLevel; | |
| 81 | + /*itransform info*/ | |
| 82 | + PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc8x8; | |
| 83 | + | |
| 84 | + /*************local variable********************/ | |
| 85 | + uint8_t i = 0; | |
| 86 | + bool bTLAvail[4], bTRAvail[4]; | |
| 87 | + // Top-Right : Left : Top-Left : Top | |
| 88 | + bTLAvail[0] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x02); | |
| 89 | + bTLAvail[1] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x01); | |
| 90 | + bTLAvail[2] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x04); | |
| 91 | + bTLAvail[3] = true; | |
| 92 | + | |
| 93 | + bTRAvail[0] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x01); | |
| 94 | + bTRAvail[1] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x08); | |
| 95 | + bTRAvail[2] = true; | |
| 96 | + bTRAvail[3] = false; | |
| 97 | + | |
| 98 | + /*************real process*********************/ | |
| 99 | + for (i = 0; i < 4; i++) { | |
| 100 | + | |
| 101 | + uint8_t* pPredI8x8 = pPred + pBlockOffset[i << 2]; | |
| 102 | + uint8_t uiMode = pIntra8x8PredMode[g_kuiScan4[i << 2]]; | |
| 103 | + | |
| 104 | + pGetI8x8LumaPredFunc[uiMode] (pPredI8x8, iLumaStride, bTLAvail[i], bTRAvail[i]); | |
| 105 | + | |
| 106 | + int32_t iIndex = g_kuiMbCountScan4Idx[i << 2]; | |
| 107 | + if (pDqLayer->pNzc[iMbXy][iIndex] || pDqLayer->pNzc[iMbXy][iIndex + 1] || pDqLayer->pNzc[iMbXy][iIndex + 4] | |
| 108 | + || pDqLayer->pNzc[iMbXy][iIndex + 5]) { | |
| 109 | + int16_t* pRSI8x8 = &pRS[i << 6]; | |
| 110 | + pIdctResAddPredFunc (pPredI8x8, iLumaStride, pRSI8x8); | |
| 111 | + } | |
| 112 | + } | |
| 113 | + | |
| 114 | + return ERR_NONE; | |
| 115 | +} | |
| 116 | + | |
| 117 | +int32_t RecI4x4Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 118 | + RecI4x4Luma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 119 | + RecI4x4Chroma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 120 | + return ERR_NONE; | |
| 121 | +} | |
| 122 | + | |
| 123 | + | |
| 124 | +int32_t RecI4x4Luma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 125 | + /*****get local variable from outer variable********/ | |
| 126 | + /*prediction info*/ | |
| 127 | + uint8_t* pPred = pDqLayer->pPred[0]; | |
| 128 | + | |
| 129 | + int32_t iLumaStride = pDqLayer->iLumaStride; | |
| 130 | + int32_t* pBlockOffset = pCtx->iDecBlockOffsetArray; | |
| 131 | + PGetIntraPredFunc* pGetI4x4LumaPredFunc = pCtx->pGetI4x4LumaPredFunc; | |
| 132 | + | |
| 133 | + int8_t* pIntra4x4PredMode = pDqLayer->pIntra4x4FinalMode[iMBXY]; | |
| 134 | + int16_t* pRS = pScoeffLevel; | |
| 135 | + /*itransform info*/ | |
| 136 | + PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc; | |
| 137 | + | |
| 138 | + | |
| 139 | + /*************local variable********************/ | |
| 140 | + uint8_t i = 0; | |
| 141 | + | |
| 142 | + /*************real process*********************/ | |
| 143 | + for (i = 0; i < 16; i++) { | |
| 144 | + | |
| 145 | + uint8_t* pPredI4x4 = pPred + pBlockOffset[i]; | |
| 146 | + uint8_t uiMode = pIntra4x4PredMode[g_kuiScan4[i]]; | |
| 147 | + | |
| 148 | + pGetI4x4LumaPredFunc[uiMode] (pPredI4x4, iLumaStride); | |
| 149 | + | |
| 150 | + if (pDqLayer->pNzc[iMBXY][g_kuiMbCountScan4Idx[i]]) { | |
| 151 | + int16_t* pRSI4x4 = &pRS[i << 4]; | |
| 152 | + pIdctResAddPredFunc (pPredI4x4, iLumaStride, pRSI4x4); | |
| 153 | + } | |
| 154 | + } | |
| 155 | + | |
| 156 | + return ERR_NONE; | |
| 157 | +} | |
| 158 | + | |
| 159 | + | |
| 160 | +int32_t RecI4x4Chroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 161 | + int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1]; | |
| 162 | + | |
| 163 | + int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY]; | |
| 164 | + | |
| 165 | + PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc; | |
| 166 | + | |
| 167 | + uint8_t* pPred = pDqLayer->pPred[1]; | |
| 168 | + | |
| 169 | + pGetIChromaPredFunc[iChromaPredMode] (pPred, iChromaStride); | |
| 170 | + pPred = pDqLayer->pPred[2]; | |
| 171 | + pGetIChromaPredFunc[iChromaPredMode] (pPred, iChromaStride); | |
| 172 | + | |
| 173 | + RecChroma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 174 | + | |
| 175 | + return ERR_NONE; | |
| 176 | +} | |
| 177 | + | |
| 178 | + | |
| 179 | +int32_t RecI16x16Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 180 | + /*decoder use, encoder no use*/ | |
| 181 | + int8_t iI16x16PredMode = pDqLayer->pIntraPredMode[iMBXY][7]; | |
| 182 | + int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY]; | |
| 183 | + PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc; | |
| 184 | + PGetIntraPredFunc* pGetI16x16LumaPredFunc = pCtx->pGetI16x16LumaPredFunc; | |
| 185 | + int32_t iUVStride = pCtx->pCurDqLayer->pDec->iLinesize[1]; | |
| 186 | + | |
| 187 | + /*common use by decoder&encoder*/ | |
| 188 | + int32_t iYStride = pDqLayer->iLumaStride; | |
| 189 | + int16_t* pRS = pScoeffLevel; | |
| 190 | + | |
| 191 | + uint8_t* pPred = pDqLayer->pPred[0]; | |
| 192 | + | |
| 193 | + PIdctFourResAddPredFunc pIdctFourResAddPredFunc = pCtx->pIdctFourResAddPredFunc; | |
| 194 | + | |
| 195 | + /*decode i16x16 y*/ | |
| 196 | + pGetI16x16LumaPredFunc[iI16x16PredMode] (pPred, iYStride); | |
| 197 | + | |
| 198 | + /*1 mb is divided 16 4x4_block to idct*/ | |
| 199 | + const int8_t* pNzc = pDqLayer->pNzc[iMBXY]; | |
| 200 | + pIdctFourResAddPredFunc (pPred + 0 * iYStride + 0, iYStride, pRS + 0 * 64, pNzc + 0); | |
| 201 | + pIdctFourResAddPredFunc (pPred + 0 * iYStride + 8, iYStride, pRS + 1 * 64, pNzc + 2); | |
| 202 | + pIdctFourResAddPredFunc (pPred + 8 * iYStride + 0, iYStride, pRS + 2 * 64, pNzc + 8); | |
| 203 | + pIdctFourResAddPredFunc (pPred + 8 * iYStride + 8, iYStride, pRS + 3 * 64, pNzc + 10); | |
| 204 | + | |
| 205 | + /*decode intra mb cb&cr*/ | |
| 206 | + pPred = pDqLayer->pPred[1]; | |
| 207 | + pGetIChromaPredFunc[iChromaPredMode] (pPred, iUVStride); | |
| 208 | + pPred = pDqLayer->pPred[2]; | |
| 209 | + pGetIChromaPredFunc[iChromaPredMode] (pPred, iUVStride); | |
| 210 | + RecChroma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 211 | + | |
| 212 | + return ERR_NONE; | |
| 213 | +} | |
| 214 | + | |
| 215 | + | |
| 216 | +//according to current 8*8 block ref_index to gain reference picture | |
| 217 | +static inline void GetRefPic (sMCRefMember* pMCRefMem, PWelsDecoderContext pCtx, int8_t* pRefIdxList, | |
| 218 | + int32_t iIndex, int32_t listIdx) { | |
| 219 | + PPicture pRefPic; | |
| 220 | + | |
| 221 | + int8_t iRefIdx = pRefIdxList[iIndex]; | |
| 222 | + if (iRefIdx >= 0) { | |
| 223 | + pRefPic = pCtx->sRefPic.pRefList[listIdx][iRefIdx]; | |
| 224 | + | |
| 225 | + if (pRefPic != NULL) { | |
| 226 | + pMCRefMem->iSrcLineLuma = pRefPic->iLinesize[0]; | |
| 227 | + pMCRefMem->iSrcLineChroma = pRefPic->iLinesize[1]; | |
| 228 | + | |
| 229 | + pMCRefMem->pSrcY = pRefPic->pData[0]; | |
| 230 | + pMCRefMem->pSrcU = pRefPic->pData[1]; | |
| 231 | + pMCRefMem->pSrcV = pRefPic->pData[2]; | |
| 232 | + } | |
| 233 | + } | |
| 234 | +} | |
| 235 | + | |
| 236 | + | |
| 237 | +#ifndef MC_FLOW_SIMPLE_JUDGE | |
| 238 | +#define MC_FLOW_SIMPLE_JUDGE 1 | |
| 239 | +#endif //MC_FLOW_SIMPLE_JUDGE | |
| 240 | +void BaseMC (sMCRefMember* pMCRefMem, int32_t iXOffset, int32_t iYOffset, SMcFunc* pMCFunc, | |
| 241 | + int32_t iBlkWidth, int32_t iBlkHeight, int16_t iMVs[2]) { | |
| 242 | + int32_t iFullMVx = (iXOffset << 2) + iMVs[0]; //quarter pixel | |
| 243 | + int32_t iFullMVy = (iYOffset << 2) + iMVs[1]; | |
| 244 | + iFullMVx = WELS_CLIP3 (iFullMVx, ((-PADDING_LENGTH + 2) * (1 << 2)), | |
| 245 | + ((pMCRefMem->iPicWidth + PADDING_LENGTH - 19) * (1 << 2))); | |
| 246 | + iFullMVy = WELS_CLIP3 (iFullMVy, ((-PADDING_LENGTH + 2) * (1 << 2)), | |
| 247 | + ((pMCRefMem->iPicHeight + PADDING_LENGTH - 19) * (1 << 2))); | |
| 248 | + | |
| 249 | + int32_t iSrcPixOffsetLuma = (iFullMVx >> 2) + (iFullMVy >> 2) * pMCRefMem->iSrcLineLuma; | |
| 250 | + int32_t iSrcPixOffsetChroma = (iFullMVx >> 3) + (iFullMVy >> 3) * pMCRefMem->iSrcLineChroma; | |
| 251 | + | |
| 252 | + int32_t iBlkWidthChroma = iBlkWidth >> 1; | |
| 253 | + int32_t iBlkHeightChroma = iBlkHeight >> 1; | |
| 254 | + | |
| 255 | + uint8_t* pSrcY = pMCRefMem->pSrcY + iSrcPixOffsetLuma; | |
| 256 | + uint8_t* pSrcU = pMCRefMem->pSrcU + iSrcPixOffsetChroma; | |
| 257 | + uint8_t* pSrcV = pMCRefMem->pSrcV + iSrcPixOffsetChroma; | |
| 258 | + uint8_t* pDstY = pMCRefMem->pDstY; | |
| 259 | + uint8_t* pDstU = pMCRefMem->pDstU; | |
| 260 | + uint8_t* pDstV = pMCRefMem->pDstV; | |
| 261 | + | |
| 262 | + pMCFunc->pMcLumaFunc (pSrcY, pMCRefMem->iSrcLineLuma, pDstY, pMCRefMem->iDstLineLuma, iFullMVx, iFullMVy, iBlkWidth, | |
| 263 | + iBlkHeight); | |
| 264 | + pMCFunc->pMcChromaFunc (pSrcU, pMCRefMem->iSrcLineChroma, pDstU, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy, | |
| 265 | + iBlkWidthChroma, iBlkHeightChroma); | |
| 266 | + pMCFunc->pMcChromaFunc (pSrcV, pMCRefMem->iSrcLineChroma, pDstV, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy, | |
| 267 | + iBlkWidthChroma, iBlkHeightChroma); | |
| 268 | + | |
| 269 | +} | |
| 270 | + | |
| 271 | +static void WeightPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, int32_t listIdx, int32_t iRefIdx, | |
| 272 | + int32_t iBlkWidth, | |
| 273 | + int32_t iBlkHeight) { | |
| 274 | + | |
| 275 | + | |
| 276 | + int32_t iLog2denom, iWoc, iOoc; | |
| 277 | + int32_t iPredTemp, iLineStride; | |
| 278 | + int32_t iPixel = 0; | |
| 279 | + uint8_t* pDst; | |
| 280 | + //luma | |
| 281 | + iLog2denom = pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom; | |
| 282 | + iWoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iLumaWeight[iRefIdx]; | |
| 283 | + iOoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iLumaOffset[iRefIdx]; | |
| 284 | + iLineStride = pMCRefMem->iDstLineLuma; | |
| 285 | + | |
| 286 | + for (int i = 0; i < iBlkHeight; i++) { | |
| 287 | + for (int j = 0; j < iBlkWidth; j++) { | |
| 288 | + iPixel = j + i * (iLineStride); | |
| 289 | + if (iLog2denom >= 1) { | |
| 290 | + iPredTemp = ((pMCRefMem->pDstY[iPixel] * iWoc + (1 << (iLog2denom - 1))) >> iLog2denom) + iOoc; | |
| 291 | + | |
| 292 | + pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 293 | + } else { | |
| 294 | + iPredTemp = pMCRefMem->pDstY[iPixel] * iWoc + iOoc; | |
| 295 | + | |
| 296 | + pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 297 | + | |
| 298 | + } | |
| 299 | + } | |
| 300 | + } | |
| 301 | + | |
| 302 | + | |
| 303 | + //UV | |
| 304 | + iBlkWidth = iBlkWidth >> 1; | |
| 305 | + iBlkHeight = iBlkHeight >> 1; | |
| 306 | + iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 307 | + iLineStride = pMCRefMem->iDstLineChroma; | |
| 308 | + | |
| 309 | + for (int i = 0; i < 2; i++) { | |
| 310 | + | |
| 311 | + | |
| 312 | + //iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 313 | + iWoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iChromaWeight[iRefIdx][i]; | |
| 314 | + iOoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iChromaOffset[iRefIdx][i]; | |
| 315 | + pDst = i ? pMCRefMem->pDstV : pMCRefMem->pDstU; | |
| 316 | + //iLineStride = pMCRefMem->iDstLineChroma; | |
| 317 | + | |
| 318 | + for (int i = 0; i < iBlkHeight ; i++) { | |
| 319 | + for (int j = 0; j < iBlkWidth; j++) { | |
| 320 | + iPixel = j + i * (iLineStride); | |
| 321 | + if (iLog2denom >= 1) { | |
| 322 | + iPredTemp = ((pDst[iPixel] * iWoc + (1 << (iLog2denom - 1))) >> iLog2denom) + iOoc; | |
| 323 | + | |
| 324 | + pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 325 | + } else { | |
| 326 | + iPredTemp = pDst[iPixel] * iWoc + iOoc; | |
| 327 | + | |
| 328 | + pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 329 | + | |
| 330 | + } | |
| 331 | + } | |
| 332 | + | |
| 333 | + } | |
| 334 | + | |
| 335 | + | |
| 336 | + } | |
| 337 | +} | |
| 338 | + | |
| 339 | +static void BiWeightPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, sMCRefMember* pTempMCRefMem, | |
| 340 | + int32_t iRefIdx1, int32_t iRefIdx2, bool bWeightedBipredIdcIs1, int32_t iBlkWidth, | |
| 341 | + int32_t iBlkHeight) { | |
| 342 | + int32_t iWoc1 = 0, iOoc1 = 0, iWoc2 = 0, iOoc2 = 0; | |
| 343 | + int32_t iPredTemp, iLineStride; | |
| 344 | + int32_t iPixel = 0; | |
| 345 | + //luma | |
| 346 | + int32_t iLog2denom = pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom; | |
| 347 | + if (bWeightedBipredIdcIs1) { | |
| 348 | + iWoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iLumaWeight[iRefIdx1]; | |
| 349 | + iOoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iLumaOffset[iRefIdx1]; | |
| 350 | + iWoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iLumaWeight[iRefIdx2]; | |
| 351 | + iOoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iLumaOffset[iRefIdx2]; | |
| 352 | + } else { | |
| 353 | + iWoc1 = pCurDqLayer->pPredWeightTable->iImplicitWeight[iRefIdx1][iRefIdx2]; | |
| 354 | + iWoc2 = 64 - iWoc1; | |
| 355 | + } | |
| 356 | + iLineStride = pMCRefMem->iDstLineLuma; | |
| 357 | + | |
| 358 | + for (int i = 0; i < iBlkHeight; i++) { | |
| 359 | + for (int j = 0; j < iBlkWidth; j++) { | |
| 360 | + iPixel = j + i * (iLineStride); | |
| 361 | + iPredTemp = ((pMCRefMem->pDstY[iPixel] * iWoc1 + pTempMCRefMem->pDstY[iPixel] * iWoc2 + (1 << iLog2denom)) >> | |
| 362 | + (iLog2denom + 1)) + ((iOoc1 + iOoc2 + 1) >> 1); | |
| 363 | + pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 364 | + } | |
| 365 | + } | |
| 366 | + | |
| 367 | + //UV | |
| 368 | + iBlkWidth = iBlkWidth >> 1; | |
| 369 | + iBlkHeight = iBlkHeight >> 1; | |
| 370 | + iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 371 | + iLineStride = pMCRefMem->iDstLineChroma; | |
| 372 | + | |
| 373 | + uint8_t* pDst; | |
| 374 | + uint8_t* pTempDst; | |
| 375 | + for (int k = 0; k < 2; k++) { | |
| 376 | + //iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 377 | + if (bWeightedBipredIdcIs1) { | |
| 378 | + iWoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iChromaWeight[iRefIdx1][k]; | |
| 379 | + iOoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iChromaOffset[iRefIdx1][k]; | |
| 380 | + iWoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iChromaWeight[iRefIdx2][k]; | |
| 381 | + iOoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iChromaOffset[iRefIdx2][k]; | |
| 382 | + } | |
| 383 | + pDst = k ? pMCRefMem->pDstV : pMCRefMem->pDstU; | |
| 384 | + pTempDst = k ? pTempMCRefMem->pDstV : pTempMCRefMem->pDstU; | |
| 385 | + //iLineStride = pMCRefMem->iDstLineChroma; | |
| 386 | + | |
| 387 | + for (int i = 0; i < iBlkHeight; i++) { | |
| 388 | + for (int j = 0; j < iBlkWidth; j++) { | |
| 389 | + iPixel = j + i * (iLineStride); | |
| 390 | + iPredTemp = ((pDst[iPixel] * iWoc1 + pTempDst[iPixel] * iWoc2 + (1 << iLog2denom)) >> (iLog2denom + 1)) + (( | |
| 391 | + iOoc1 + iOoc2 + 1) >> 1); | |
| 392 | + pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 393 | + } | |
| 394 | + } | |
| 395 | + } | |
| 396 | +} | |
| 397 | + | |
| 398 | +static void BiPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, sMCRefMember* pTempMCRefMem, int32_t iBlkWidth, | |
| 399 | + int32_t iBlkHeight) { | |
| 400 | + int32_t iPredTemp, iLineStride; | |
| 401 | + int32_t iPixel = 0; | |
| 402 | + //luma | |
| 403 | + iLineStride = pMCRefMem->iDstLineLuma; | |
| 404 | + | |
| 405 | + for (int i = 0; i < iBlkHeight; i++) { | |
| 406 | + for (int j = 0; j < iBlkWidth; j++) { | |
| 407 | + iPixel = j + i * (iLineStride); | |
| 408 | + iPredTemp = (pMCRefMem->pDstY[iPixel] + pTempMCRefMem->pDstY[iPixel] + 1) >> 1; | |
| 409 | + pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 410 | + } | |
| 411 | + } | |
| 412 | + | |
| 413 | + //UV | |
| 414 | + iBlkWidth = iBlkWidth >> 1; | |
| 415 | + iBlkHeight = iBlkHeight >> 1; | |
| 416 | + iLineStride = pMCRefMem->iDstLineChroma; | |
| 417 | + | |
| 418 | + uint8_t* pDst; | |
| 419 | + uint8_t* pTempDst; | |
| 420 | + for (int k = 0; k < 2; k++) { | |
| 421 | + pDst = k ? pMCRefMem->pDstV : pMCRefMem->pDstU; | |
| 422 | + pTempDst = k ? pTempMCRefMem->pDstV : pTempMCRefMem->pDstU; | |
| 423 | + //iLineStride = pMCRefMem->iDstLineChroma; | |
| 424 | + | |
| 425 | + for (int i = 0; i < iBlkHeight; i++) { | |
| 426 | + for (int j = 0; j < iBlkWidth; j++) { | |
| 427 | + iPixel = j + i * (iLineStride); | |
| 428 | + iPredTemp = (pDst[iPixel] + pTempDst[iPixel] + 1) >> 1; | |
| 429 | + pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 430 | + } | |
| 431 | + } | |
| 432 | + } | |
| 433 | +} | |
| 434 | + | |
| 435 | +void GetInterPred (uint8_t* pPredY, uint8_t* pPredCb, uint8_t* pPredCr, PWelsDecoderContext pCtx) { | |
| 436 | + sMCRefMember pMCRefMem; | |
| 437 | + PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 438 | + SMcFunc* pMCFunc = &pCtx->sMcFunc; | |
| 439 | + | |
| 440 | + int32_t iMBXY = pCurDqLayer->iMbXyIndex; | |
| 441 | + | |
| 442 | + int16_t iMVs[2] = {0}; | |
| 443 | + | |
| 444 | + uint32_t iMBType = pCurDqLayer->pMbType[iMBXY]; | |
| 445 | + | |
| 446 | + int32_t iMBOffsetX = pCurDqLayer->iMbX << 4; | |
| 447 | + int32_t iMBOffsetY = pCurDqLayer->iMbY << 4; | |
| 448 | + | |
| 449 | + int32_t iDstLineLuma = pCtx->pDec->iLinesize[0]; | |
| 450 | + int32_t iDstLineChroma = pCtx->pDec->iLinesize[1]; | |
| 451 | + | |
| 452 | + int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, i, j, iIIdx, iJIdx; | |
| 453 | + | |
| 454 | + pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth << 4); | |
| 455 | + pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight << 4); | |
| 456 | + | |
| 457 | + pMCRefMem.pDstY = pPredY; | |
| 458 | + pMCRefMem.pDstU = pPredCb; | |
| 459 | + pMCRefMem.pDstV = pPredCr; | |
| 460 | + | |
| 461 | + pMCRefMem.iDstLineLuma = iDstLineLuma; | |
| 462 | + pMCRefMem.iDstLineChroma = iDstLineChroma; | |
| 463 | + | |
| 464 | + int32_t iRefIndex = 0; | |
| 465 | + | |
| 466 | + switch (iMBType) { | |
| 467 | + case MB_TYPE_SKIP: | |
| 468 | + case MB_TYPE_16x16: | |
| 469 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 470 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 471 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0); | |
| 472 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 473 | + | |
| 474 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 475 | + iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0]; | |
| 476 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 16); | |
| 477 | + } | |
| 478 | + break; | |
| 479 | + case MB_TYPE_16x8: | |
| 480 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 481 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 482 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0); | |
| 483 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 8, iMVs); | |
| 484 | + | |
| 485 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 486 | + iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0]; | |
| 487 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 8); | |
| 488 | + } | |
| 489 | + | |
| 490 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][8][0]; | |
| 491 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][8][1]; | |
| 492 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 8, LIST_0); | |
| 493 | + pMCRefMem.pDstY = pPredY + (iDstLineLuma << 3); | |
| 494 | + pMCRefMem.pDstU = pPredCb + (iDstLineChroma << 2); | |
| 495 | + pMCRefMem.pDstV = pPredCr + (iDstLineChroma << 2); | |
| 496 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY + 8, pMCFunc, 16, 8, iMVs); | |
| 497 | + | |
| 498 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 499 | + iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][8]; | |
| 500 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 8); | |
| 501 | + } | |
| 502 | + break; | |
| 503 | + case MB_TYPE_8x16: | |
| 504 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 505 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 506 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0); | |
| 507 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 508 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 509 | + iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0]; | |
| 510 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 16); | |
| 511 | + } | |
| 512 | + | |
| 513 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][2][0]; | |
| 514 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][2][1]; | |
| 515 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 2, LIST_0); | |
| 516 | + pMCRefMem.pDstY = pPredY + 8; | |
| 517 | + pMCRefMem.pDstU = pPredCb + 4; | |
| 518 | + pMCRefMem.pDstV = pPredCr + 4; | |
| 519 | + BaseMC (&pMCRefMem, iMBOffsetX + 8, iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 520 | + | |
| 521 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 522 | + iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][2]; | |
| 523 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 16); | |
| 524 | + } | |
| 525 | + break; | |
| 526 | + case MB_TYPE_8x8: | |
| 527 | + case MB_TYPE_8x8_REF0: { | |
| 528 | + uint32_t iSubMBType; | |
| 529 | + int32_t iXOffset, iYOffset; | |
| 530 | + uint8_t* pDstY, *pDstU, *pDstV; | |
| 531 | + for (i = 0; i < 4; i++) { | |
| 532 | + iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i]; | |
| 533 | + iBlk8X = (i & 1) << 3; | |
| 534 | + iBlk8Y = (i >> 1) << 3; | |
| 535 | + iXOffset = iMBOffsetX + iBlk8X; | |
| 536 | + iYOffset = iMBOffsetY + iBlk8Y; | |
| 537 | + | |
| 538 | + iIIdx = ((i >> 1) << 3) + ((i & 1) << 1); | |
| 539 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], iIIdx, LIST_0); | |
| 540 | + iRefIndex = pCurDqLayer->bUseWeightPredictionFlag ? pCurDqLayer->pRefIndex[0][iMBXY][iIIdx] : 0; | |
| 541 | + | |
| 542 | + pDstY = pPredY + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 543 | + pDstU = pPredCb + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 544 | + pDstV = pPredCr + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 545 | + pMCRefMem.pDstY = pDstY; | |
| 546 | + pMCRefMem.pDstU = pDstU; | |
| 547 | + pMCRefMem.pDstV = pDstV; | |
| 548 | + switch (iSubMBType) { | |
| 549 | + case SUB_MB_TYPE_8x8: | |
| 550 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 551 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 552 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 553 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 554 | + | |
| 555 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 8); | |
| 556 | + } | |
| 557 | + | |
| 558 | + break; | |
| 559 | + case SUB_MB_TYPE_8x4: | |
| 560 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 561 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 562 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 563 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 564 | + | |
| 565 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 4); | |
| 566 | + } | |
| 567 | + | |
| 568 | + | |
| 569 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 4][0]; | |
| 570 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 4][1]; | |
| 571 | + pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 572 | + pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 573 | + pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 574 | + BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 575 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 576 | + | |
| 577 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 4); | |
| 578 | + } | |
| 579 | + | |
| 580 | + break; | |
| 581 | + case SUB_MB_TYPE_4x8: | |
| 582 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 583 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 584 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 585 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 586 | + | |
| 587 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 8); | |
| 588 | + } | |
| 589 | + | |
| 590 | + | |
| 591 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 1][0]; | |
| 592 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 1][1]; | |
| 593 | + pMCRefMem.pDstY += 4; | |
| 594 | + pMCRefMem.pDstU += 2; | |
| 595 | + pMCRefMem.pDstV += 2; | |
| 596 | + BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 597 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 598 | + | |
| 599 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 8); | |
| 600 | + } | |
| 601 | + | |
| 602 | + break; | |
| 603 | + case SUB_MB_TYPE_4x4: { | |
| 604 | + for (j = 0; j < 4; j++) { | |
| 605 | + int32_t iUVLineStride; | |
| 606 | + iJIdx = ((j >> 1) << 2) + (j & 1); | |
| 607 | + | |
| 608 | + iBlk4X = (j & 1) << 2; | |
| 609 | + iBlk4Y = (j >> 1) << 2; | |
| 610 | + | |
| 611 | + iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 612 | + pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 613 | + pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 614 | + pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 615 | + | |
| 616 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + iJIdx][0]; | |
| 617 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + iJIdx][1]; | |
| 618 | + BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 619 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 620 | + | |
| 621 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 4); | |
| 622 | + } | |
| 623 | + | |
| 624 | + } | |
| 625 | + } | |
| 626 | + break; | |
| 627 | + default: | |
| 628 | + break; | |
| 629 | + } | |
| 630 | + } | |
| 631 | + } | |
| 632 | + break; | |
| 633 | + default: | |
| 634 | + break; | |
| 635 | + } | |
| 636 | +} | |
| 637 | + | |
| 638 | +void GetInterBPred (uint8_t* pPredYCbCr[3], uint8_t* pTempPredYCbCr[3], PWelsDecoderContext pCtx) { | |
| 639 | + sMCRefMember pMCRefMem; | |
| 640 | + sMCRefMember pTempMCRefMem; | |
| 641 | + | |
| 642 | + PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 643 | + SMcFunc* pMCFunc = &pCtx->sMcFunc; | |
| 644 | + | |
| 645 | + int32_t iMBXY = pCurDqLayer->iMbXyIndex; | |
| 646 | + | |
| 647 | + int16_t iMVs[2] = { 0 }; | |
| 648 | + | |
| 649 | + uint32_t iMBType = pCurDqLayer->pMbType[iMBXY]; | |
| 650 | + | |
| 651 | + int32_t iMBOffsetX = pCurDqLayer->iMbX << 4; | |
| 652 | + int32_t iMBOffsetY = pCurDqLayer->iMbY << 4; | |
| 653 | + | |
| 654 | + int32_t iDstLineLuma = pCtx->pDec->iLinesize[0]; | |
| 655 | + int32_t iDstLineChroma = pCtx->pDec->iLinesize[1]; | |
| 656 | + | |
| 657 | + | |
| 658 | + pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth << 4); | |
| 659 | + pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight << 4); | |
| 660 | + | |
| 661 | + pMCRefMem.pDstY = pPredYCbCr[0]; | |
| 662 | + pMCRefMem.pDstU = pPredYCbCr[1]; | |
| 663 | + pMCRefMem.pDstV = pPredYCbCr[2]; | |
| 664 | + | |
| 665 | + pMCRefMem.iDstLineLuma = iDstLineLuma; | |
| 666 | + pMCRefMem.iDstLineChroma = iDstLineChroma; | |
| 667 | + | |
| 668 | + pTempMCRefMem = pMCRefMem; | |
| 669 | + pTempMCRefMem.pDstY = pTempPredYCbCr[0]; | |
| 670 | + pTempMCRefMem.pDstU = pTempPredYCbCr[1]; | |
| 671 | + pTempMCRefMem.pDstV = pTempPredYCbCr[2]; | |
| 672 | + | |
| 673 | + | |
| 674 | + int32_t iRefIndex1 = 0; | |
| 675 | + int32_t iRefIndex2 = 0; | |
| 676 | + | |
| 677 | + bool bWeightedBipredIdcIs1 = pCurDqLayer->sLayerInfo.pPps->uiWeightedBipredIdc == 1; | |
| 678 | + | |
| 679 | + if (IS_INTER_16x16 (iMBType)) { | |
| 680 | + if (IS_TYPE_L0 (iMBType) && IS_TYPE_L1 (iMBType)) { | |
| 681 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][0][0]; | |
| 682 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][0][1]; | |
| 683 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_0][iMBXY], 0, LIST_0); | |
| 684 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 685 | + | |
| 686 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][0][0]; | |
| 687 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][0][1]; | |
| 688 | + GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], 0, LIST_1); | |
| 689 | + BaseMC (&pTempMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 690 | + iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][0]; | |
| 691 | + iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][0]; | |
| 692 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 693 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 16, 16); | |
| 694 | + } else { | |
| 695 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 16, 16); | |
| 696 | + } | |
| 697 | + } else { | |
| 698 | + int32_t listIdx = (iMBType & MB_TYPE_P0L0) ? LIST_0 : LIST_1; | |
| 699 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][0][0]; | |
| 700 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][0][1]; | |
| 701 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], 0, listIdx); | |
| 702 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 703 | + if (bWeightedBipredIdcIs1) { | |
| 704 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][0]; | |
| 705 | + WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 16, 16); | |
| 706 | + } | |
| 707 | + } | |
| 708 | + } else if (IS_INTER_16x8 (iMBType)) { | |
| 709 | + for (int32_t i = 0; i < 2; ++i) { | |
| 710 | + int32_t iPartIdx = i << 3; | |
| 711 | + uint32_t listCount = 0; | |
| 712 | + int32_t lastListIdx = LIST_0; | |
| 713 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 714 | + if (IS_DIR (iMBType, i, listIdx)) { | |
| 715 | + lastListIdx = listIdx; | |
| 716 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iPartIdx][0]; | |
| 717 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iPartIdx][1]; | |
| 718 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], iPartIdx, listIdx); | |
| 719 | + if (i) { | |
| 720 | + pMCRefMem.pDstY += (iDstLineLuma << 3); | |
| 721 | + pMCRefMem.pDstU += (iDstLineChroma << 2); | |
| 722 | + pMCRefMem.pDstV += (iDstLineChroma << 2); | |
| 723 | + } | |
| 724 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY + iPartIdx, pMCFunc, 16, 8, iMVs); | |
| 725 | + if (++listCount == 2) { | |
| 726 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iPartIdx][0]; | |
| 727 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iPartIdx][1]; | |
| 728 | + GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], iPartIdx, LIST_1); | |
| 729 | + if (i) { | |
| 730 | + pTempMCRefMem.pDstY += (iDstLineLuma << 3); | |
| 731 | + pTempMCRefMem.pDstU += (iDstLineChroma << 2); | |
| 732 | + pTempMCRefMem.pDstV += (iDstLineChroma << 2); | |
| 733 | + } | |
| 734 | + BaseMC (&pTempMCRefMem, iMBOffsetX, iMBOffsetY + iPartIdx, pMCFunc, 16, 8, iMVs); | |
| 735 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 736 | + iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][iPartIdx]; | |
| 737 | + iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][iPartIdx]; | |
| 738 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 16, 8); | |
| 739 | + } else { | |
| 740 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 16, 8); | |
| 741 | + } | |
| 742 | + } | |
| 743 | + } | |
| 744 | + } | |
| 745 | + if (listCount == 1) { | |
| 746 | + if (bWeightedBipredIdcIs1) { | |
| 747 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[lastListIdx][iMBXY][iPartIdx]; | |
| 748 | + WeightPrediction (pCurDqLayer, &pMCRefMem, lastListIdx, iRefIndex, 16, 8); | |
| 749 | + } | |
| 750 | + } | |
| 751 | + } | |
| 752 | + } else if (IS_INTER_8x16 (iMBType)) { | |
| 753 | + for (int32_t i = 0; i < 2; ++i) { | |
| 754 | + uint32_t listCount = 0; | |
| 755 | + int32_t lastListIdx = LIST_0; | |
| 756 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 757 | + if (IS_DIR (iMBType, i, listIdx)) { | |
| 758 | + lastListIdx = listIdx; | |
| 759 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][i << 1][0]; | |
| 760 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][i << 1][1]; | |
| 761 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], i << 1, listIdx); | |
| 762 | + if (i) { | |
| 763 | + pMCRefMem.pDstY += 8; | |
| 764 | + pMCRefMem.pDstU += 4; | |
| 765 | + pMCRefMem.pDstV += 4; | |
| 766 | + } | |
| 767 | + BaseMC (&pMCRefMem, iMBOffsetX + (i ? 8 : 0), iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 768 | + if (++listCount == 2) { | |
| 769 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][i << 1][0]; | |
| 770 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][i << 1][1]; | |
| 771 | + GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], i << 1, LIST_1); | |
| 772 | + if (i) { | |
| 773 | + pTempMCRefMem.pDstY += 8; | |
| 774 | + pTempMCRefMem.pDstU += 4; | |
| 775 | + pTempMCRefMem.pDstV += 4; | |
| 776 | + } | |
| 777 | + BaseMC (&pTempMCRefMem, iMBOffsetX + (i ? 8 : 0), iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 778 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 779 | + iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][i << 1]; | |
| 780 | + iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][i << 1]; | |
| 781 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 16); | |
| 782 | + } else { | |
| 783 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 16); | |
| 784 | + } | |
| 785 | + } | |
| 786 | + } | |
| 787 | + } | |
| 788 | + if (listCount == 1) { | |
| 789 | + if (bWeightedBipredIdcIs1) { | |
| 790 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[lastListIdx][iMBXY][i << 1]; | |
| 791 | + WeightPrediction (pCurDqLayer, &pMCRefMem, lastListIdx, iRefIndex, 8, 16); | |
| 792 | + } | |
| 793 | + } | |
| 794 | + } | |
| 795 | + } else if (IS_Inter_8x8 (iMBType)) { | |
| 796 | + int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, iIIdx, iJIdx; | |
| 797 | + uint32_t iSubMBType; | |
| 798 | + int32_t iXOffset, iYOffset; | |
| 799 | + uint8_t* pDstY, *pDstU, *pDstV; | |
| 800 | + uint8_t* pDstY2, *pDstU2, *pDstV2; | |
| 801 | + for (int32_t i = 0; i < 4; i++) { | |
| 802 | + iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i]; | |
| 803 | + iBlk8X = (i & 1) << 3; | |
| 804 | + iBlk8Y = (i >> 1) << 3; | |
| 805 | + iXOffset = iMBOffsetX + iBlk8X; | |
| 806 | + iYOffset = iMBOffsetY + iBlk8Y; | |
| 807 | + | |
| 808 | + iIIdx = ((i >> 1) << 3) + ((i & 1) << 1); | |
| 809 | + | |
| 810 | + pDstY = pPredYCbCr[0] + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 811 | + pDstU = pPredYCbCr[1] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 812 | + pDstV = pPredYCbCr[2] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 813 | + pMCRefMem.pDstY = pDstY; | |
| 814 | + pMCRefMem.pDstU = pDstU; | |
| 815 | + pMCRefMem.pDstV = pDstV; | |
| 816 | + | |
| 817 | + pTempMCRefMem = pMCRefMem; | |
| 818 | + pDstY2 = pTempPredYCbCr[0] + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 819 | + pDstU2 = pTempPredYCbCr[1] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 820 | + pDstV2 = pTempPredYCbCr[2] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 821 | + | |
| 822 | + pTempMCRefMem.pDstY = pDstY2; | |
| 823 | + pTempMCRefMem.pDstU = pDstU2; | |
| 824 | + pTempMCRefMem.pDstV = pDstV2; | |
| 825 | + | |
| 826 | + if ((IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType))) { | |
| 827 | + iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][iIIdx]; | |
| 828 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_0][iMBXY], iIIdx, LIST_0); | |
| 829 | + | |
| 830 | + iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][iIIdx]; | |
| 831 | + GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], iIIdx, LIST_1); | |
| 832 | + } else { | |
| 833 | + int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 834 | + iRefIndex1 = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 835 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], iIIdx, listIdx); | |
| 836 | + } | |
| 837 | + | |
| 838 | + if (IS_SUB_8x8 (iSubMBType)) { | |
| 839 | + if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { | |
| 840 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0]; | |
| 841 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1]; | |
| 842 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 843 | + | |
| 844 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0]; | |
| 845 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1]; | |
| 846 | + BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 847 | + | |
| 848 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 849 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 8); | |
| 850 | + } else { | |
| 851 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 8); | |
| 852 | + } | |
| 853 | + } else { | |
| 854 | + int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 855 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0]; | |
| 856 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1]; | |
| 857 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 858 | + if (bWeightedBipredIdcIs1) { | |
| 859 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 860 | + WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 8, 8); | |
| 861 | + } | |
| 862 | + } | |
| 863 | + } else if (IS_SUB_8x4 (iSubMBType)) { | |
| 864 | + if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { //B_Bi_8x4 | |
| 865 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0]; | |
| 866 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1]; | |
| 867 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 868 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0]; | |
| 869 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1]; | |
| 870 | + BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 871 | + | |
| 872 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 873 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 4); | |
| 874 | + } else { | |
| 875 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 4); | |
| 876 | + } | |
| 877 | + | |
| 878 | + pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 879 | + pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 880 | + pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 881 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 4][0]; | |
| 882 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 4][1]; | |
| 883 | + BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 884 | + | |
| 885 | + pTempMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 886 | + pTempMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 887 | + pTempMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 888 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 4][0]; | |
| 889 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 4][1]; | |
| 890 | + BaseMC (&pTempMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 891 | + | |
| 892 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 893 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 4); | |
| 894 | + } else { | |
| 895 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 4); | |
| 896 | + } | |
| 897 | + } else { //B_L0_8x4 B_L1_8x4 | |
| 898 | + int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 899 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0]; | |
| 900 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1]; | |
| 901 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 902 | + pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 903 | + pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 904 | + pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 905 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 4][0]; | |
| 906 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 4][1]; | |
| 907 | + BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 908 | + if (bWeightedBipredIdcIs1) { | |
| 909 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 910 | + WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 8, 4); | |
| 911 | + } | |
| 912 | + } | |
| 913 | + } else if (IS_SUB_4x8 (iSubMBType)) { | |
| 914 | + if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { //B_Bi_4x8 | |
| 915 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0]; | |
| 916 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1]; | |
| 917 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 918 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0]; | |
| 919 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1]; | |
| 920 | + BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 921 | + | |
| 922 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 923 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 8); | |
| 924 | + } else { | |
| 925 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 8); | |
| 926 | + } | |
| 927 | + | |
| 928 | + pMCRefMem.pDstY += 4; | |
| 929 | + pMCRefMem.pDstU += 2; | |
| 930 | + pMCRefMem.pDstV += 2; | |
| 931 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 1][0]; | |
| 932 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 1][1]; | |
| 933 | + BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 934 | + | |
| 935 | + pTempMCRefMem.pDstY += 4; | |
| 936 | + pTempMCRefMem.pDstU += 2; | |
| 937 | + pTempMCRefMem.pDstV += 2; | |
| 938 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 1][0]; | |
| 939 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 1][1]; | |
| 940 | + BaseMC (&pTempMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 941 | + | |
| 942 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 943 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 8); | |
| 944 | + } else { | |
| 945 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 8); | |
| 946 | + } | |
| 947 | + } else { //B_L0_4x8 B_L1_4x8 | |
| 948 | + int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 949 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0]; | |
| 950 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1]; | |
| 951 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 952 | + pMCRefMem.pDstY += 4; | |
| 953 | + pMCRefMem.pDstU += 2; | |
| 954 | + pMCRefMem.pDstV += 2; | |
| 955 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 1][0]; | |
| 956 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 1][1]; | |
| 957 | + BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 958 | + if (bWeightedBipredIdcIs1) { | |
| 959 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 960 | + WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 4, 8); | |
| 961 | + } | |
| 962 | + } | |
| 963 | + } else if (IS_SUB_4x4 (iSubMBType)) { | |
| 964 | + if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { | |
| 965 | + for (int32_t j = 0; j < 4; j++) { | |
| 966 | + int32_t iUVLineStride; | |
| 967 | + iJIdx = ((j >> 1) << 2) + (j & 1); | |
| 968 | + | |
| 969 | + iBlk4X = (j & 1) << 2; | |
| 970 | + iBlk4Y = (j >> 1) << 2; | |
| 971 | + | |
| 972 | + iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 973 | + pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 974 | + pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 975 | + pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 976 | + | |
| 977 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + iJIdx][0]; | |
| 978 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + iJIdx][1]; | |
| 979 | + BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 980 | + | |
| 981 | + pTempMCRefMem.pDstY = pDstY2 + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 982 | + pTempMCRefMem.pDstU = pDstU2 + iUVLineStride; | |
| 983 | + pTempMCRefMem.pDstV = pDstV2 + iUVLineStride;; | |
| 984 | + | |
| 985 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + iJIdx][0]; | |
| 986 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + iJIdx][1]; | |
| 987 | + BaseMC (&pTempMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 988 | + | |
| 989 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 990 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 4); | |
| 991 | + } else { | |
| 992 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 4); | |
| 993 | + } | |
| 994 | + } | |
| 995 | + } else { | |
| 996 | + int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 997 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 998 | + for (int32_t j = 0; j < 4; j++) { | |
| 999 | + int32_t iUVLineStride; | |
| 1000 | + iJIdx = ((j >> 1) << 2) + (j & 1); | |
| 1001 | + | |
| 1002 | + iBlk4X = (j & 1) << 2; | |
| 1003 | + iBlk4Y = (j >> 1) << 2; | |
| 1004 | + | |
| 1005 | + iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 1006 | + pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 1007 | + pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 1008 | + pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 1009 | + | |
| 1010 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + iJIdx][0]; | |
| 1011 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + iJIdx][1]; | |
| 1012 | + BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 1013 | + if (bWeightedBipredIdcIs1) { | |
| 1014 | + WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 4, 4); | |
| 1015 | + } | |
| 1016 | + } | |
| 1017 | + } | |
| 1018 | + } | |
| 1019 | + } | |
| 1020 | + } | |
| 1021 | +} | |
| 1022 | + | |
| 1023 | +int32_t RecChroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 1024 | + int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1]; | |
| 1025 | + PIdctFourResAddPredFunc pIdctFourResAddPredFunc = pCtx->pIdctFourResAddPredFunc; | |
| 1026 | + | |
| 1027 | + uint8_t i = 0; | |
| 1028 | + uint8_t uiCbpC = pDqLayer->pCbp[iMBXY] >> 4; | |
| 1029 | + | |
| 1030 | + if (1 == uiCbpC || 2 == uiCbpC) { | |
| 1031 | + for (i = 0; i < 2; i++) { | |
| 1032 | + int16_t* pRS = pScoeffLevel + 256 + (i << 6); | |
| 1033 | + uint8_t* pPred = pDqLayer->pPred[i + 1]; | |
| 1034 | + const int8_t* pNzc = pDqLayer->pNzc[iMBXY] + 16 + 2 * i; | |
| 1035 | + | |
| 1036 | + /*1 chroma is divided 4 4x4_block to idct*/ | |
| 1037 | + pIdctFourResAddPredFunc (pPred, iChromaStride, pRS, pNzc); | |
| 1038 | + } | |
| 1039 | + } | |
| 1040 | + | |
| 1041 | + return ERR_NONE; | |
| 1042 | +} | |
| 1043 | + | |
| 1044 | +} // namespace WelsDec | |