Showing the changes to codec/decoder/core/src/rec_mb.cpp (1 of 308 files). Show all
Unified · Split
| @@ -0,0 +1,589 @@ | ||
| 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 | +#include <memory.h> | |
| 41 | + | |
| 42 | +#include "macros.h" | |
| 43 | + | |
| 44 | +#include "rec_mb.h" | |
| 45 | +#include "parse_mb_syn_cavlc.h" | |
| 46 | +#include "get_intra_predictor.h" | |
| 47 | +#include "decode_mb_aux.h" | |
| 48 | +#include "decode_slice.h" | |
| 49 | + | |
| 50 | +namespace WelsDec { | |
| 51 | + | |
| 52 | +void_t WelsFillRecNeededMbInfo(PWelsDecoderContext pCtx, bool_t bOutput, PDqLayer pCurLayer) | |
| 53 | +{ | |
| 54 | + PPicture pCurPic = pCtx->pDec; | |
| 55 | + int32_t iLumaStride = pCurPic->iLinesize[0]; | |
| 56 | + int32_t iChromaStride = pCurPic->iLinesize[1]; | |
| 57 | + int32_t iMbX = pCurLayer->iMbX; | |
| 58 | + int32_t iMbY = pCurLayer->iMbY; | |
| 59 | + | |
| 60 | + pCurLayer->iLumaStride= iLumaStride; | |
| 61 | + pCurLayer->iChromaStride= iChromaStride; | |
| 62 | + | |
| 63 | + if(bOutput) | |
| 64 | + { | |
| 65 | + pCurLayer->pPred[0] = pCurPic->pData[0] + ((iMbY * iLumaStride + iMbX)<<4); | |
| 66 | + pCurLayer->pPred[1] = pCurPic->pData[1] + ((iMbY * iChromaStride + iMbX)<<3); | |
| 67 | + pCurLayer->pPred[2] = pCurPic->pData[2] + ((iMbY * iChromaStride + iMbX)<<3); | |
| 68 | + } | |
| 69 | +} | |
| 70 | + | |
| 71 | +int32_t RecI4x4Mb(int32_t iMBXY, PWelsDecoderContext pCtx, int16_t *pScoeffLevel, PDqLayer pDqLayer) | |
| 72 | +{ | |
| 73 | + RecI4x4Luma(iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 74 | + RecI4x4Chroma( iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 75 | + return ERR_NONE; | |
| 76 | +} | |
| 77 | + | |
| 78 | +int32_t RecI4x4Luma(int32_t iMBXY, PWelsDecoderContext pCtx, int16_t *pScoeffLevel, PDqLayer pDqLayer) | |
| 79 | +{ | |
| 80 | + /*****get local variable from outer variable********/ | |
| 81 | + /*prediction info*/ | |
| 82 | + uint8_t *pPred = pDqLayer->pPred[0]; | |
| 83 | + | |
| 84 | + int32_t iLumaStride = pDqLayer->iLumaStride; | |
| 85 | + int32_t *pBlockOffset = pCtx->iDecBlockOffsetArray; | |
| 86 | + PGetIntraPredFunc *pGetI4x4LumaPredFunc = pCtx->pGetI4x4LumaPredFunc; | |
| 87 | + | |
| 88 | + int8_t *pIntra4x4PredMode = pDqLayer->pIntra4x4FinalMode[iMBXY]; | |
| 89 | + int16_t *pRS = pScoeffLevel; | |
| 90 | + /*itransform info*/ | |
| 91 | + PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc; | |
| 92 | + | |
| 93 | + | |
| 94 | + /*************local variable********************/ | |
| 95 | + uint8_t i = 0; | |
| 96 | + | |
| 97 | + /*************real process*********************/ | |
| 98 | + for(i=0; i<16; i++) | |
| 99 | + { | |
| 100 | + | |
| 101 | + uint8_t *pPredI4x4 = pPred + pBlockOffset[i]; | |
| 102 | + uint8_t uiMode= pIntra4x4PredMode[g_kuiScan4[i]]; | |
| 103 | + | |
| 104 | + pGetI4x4LumaPredFunc[uiMode](pPredI4x4, iLumaStride); | |
| 105 | + | |
| 106 | + if ( pDqLayer->pNzc[iMBXY][g_kuiMbNonZeroCountIdx[i]] ) | |
| 107 | + { | |
| 108 | + int16_t *pRSI4x4 = &pRS[i<<4]; | |
| 109 | + pIdctResAddPredFunc(pPredI4x4, iLumaStride, pRSI4x4); | |
| 110 | + } | |
| 111 | + } | |
| 112 | + | |
| 113 | + return ERR_NONE; | |
| 114 | +} | |
| 115 | + | |
| 116 | + | |
| 117 | +int32_t RecI4x4Chroma(int32_t iMBXY, PWelsDecoderContext pCtx, int16_t *pScoeffLevel, PDqLayer pDqLayer) | |
| 118 | +{ | |
| 119 | + int32_t iChromaStride = pCtx->pCurDqLayer->iCsStride[1]; | |
| 120 | + | |
| 121 | + int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY]; | |
| 122 | + | |
| 123 | + PGetIntraPredFunc *pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc; | |
| 124 | + | |
| 125 | + uint8_t *pPred = pDqLayer->pPred[1]; | |
| 126 | + | |
| 127 | + pGetIChromaPredFunc[iChromaPredMode](pPred, iChromaStride); | |
| 128 | + pPred = pDqLayer->pPred[2]; | |
| 129 | + pGetIChromaPredFunc[iChromaPredMode](pPred, iChromaStride); | |
| 130 | + | |
| 131 | + RecChroma(iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 132 | + | |
| 133 | + return ERR_NONE; | |
| 134 | +} | |
| 135 | + | |
| 136 | + | |
| 137 | +int32_t RecI16x16Mb(int32_t iMBXY, PWelsDecoderContext pCtx, int16_t *pScoeffLevel, PDqLayer pDqLayer) | |
| 138 | +{ | |
| 139 | + /*decoder use, encoder no use*/ | |
| 140 | + int8_t iI16x16PredMode = pDqLayer->pIntraPredMode[iMBXY][7]; | |
| 141 | + int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY]; | |
| 142 | + PGetIntraPredFunc *pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc; | |
| 143 | + PGetIntraPredFunc *pGetI16x16LumaPredFunc = pCtx->pGetI16x16LumaPredFunc; | |
| 144 | + int32_t iUVStride = pCtx->pCurDqLayer->iCsStride[1]; | |
| 145 | + | |
| 146 | + /*common use by decoder&encoder*/ | |
| 147 | + int32_t iYStride = pDqLayer->iLumaStride; | |
| 148 | + int32_t *pBlockOffset = pCtx->iDecBlockOffsetArray; | |
| 149 | + int16_t *pRS = pScoeffLevel; | |
| 150 | + | |
| 151 | + uint8_t *pPred = pDqLayer->pPred[0]; | |
| 152 | + | |
| 153 | + PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc; | |
| 154 | + | |
| 155 | + uint8_t i = 0; | |
| 156 | + | |
| 157 | + /*decode i16x16 y*/ | |
| 158 | + pGetI16x16LumaPredFunc[iI16x16PredMode](pPred, iYStride); | |
| 159 | + | |
| 160 | + /*1 mb is divided 16 4x4_block to idct*/ | |
| 161 | + for(i=0; i<16; i++) | |
| 162 | + { | |
| 163 | + int16_t *pRSI4x4 = pRS + (i<<4); | |
| 164 | + uint8_t *pPredI4x4 = pPred + pBlockOffset[i]; | |
| 165 | + | |
| 166 | + if ( pDqLayer->pNzc[iMBXY][g_kuiMbNonZeroCountIdx[i]] || pRSI4x4[0] ) | |
| 167 | + { | |
| 168 | + pIdctResAddPredFunc(pPredI4x4, iYStride, pRSI4x4); | |
| 169 | + } | |
| 170 | + } | |
| 171 | + | |
| 172 | + /*decode intra mb cb&cr*/ | |
| 173 | + pPred = pDqLayer->pPred[1]; | |
| 174 | + pGetIChromaPredFunc[iChromaPredMode](pPred, iUVStride); | |
| 175 | + pPred = pDqLayer->pPred[2]; | |
| 176 | + pGetIChromaPredFunc[iChromaPredMode](pPred, iUVStride); | |
| 177 | + RecChroma(iMBXY, pCtx, pScoeffLevel,pDqLayer); | |
| 178 | + | |
| 179 | + return ERR_NONE; | |
| 180 | +} | |
| 181 | + | |
| 182 | +typedef struct TagMCRefMember { | |
| 183 | + uint8_t* pDstY; | |
| 184 | + uint8_t* pDstU; | |
| 185 | + uint8_t* pDstV; | |
| 186 | + | |
| 187 | + uint8_t* pSrcY; | |
| 188 | + uint8_t* pSrcU; | |
| 189 | + uint8_t* pSrcV; | |
| 190 | + | |
| 191 | + int32_t iSrcLineLuma; | |
| 192 | + int32_t iSrcLineChroma; | |
| 193 | + | |
| 194 | + int32_t iDstLineLuma; | |
| 195 | + int32_t iDstLineChroma; | |
| 196 | + | |
| 197 | + int32_t iPicWidth; | |
| 198 | + int32_t iPicHeight; | |
| 199 | +}sMCRefMember; | |
| 200 | +//according to current 8*8 block ref_index to gain reference picture | |
| 201 | +static inline void_t GetRefPic(sMCRefMember* pMCRefMem, PWelsDecoderContext pCtx, int8_t* pRefIdxList, int32_t iIndex) | |
| 202 | +{ | |
| 203 | + PPicture pRefPic; | |
| 204 | + | |
| 205 | + int8_t iRefIdx = pRefIdxList[iIndex]; | |
| 206 | + pRefPic = pCtx->sRefPic.pRefList[LIST_0][iRefIdx]; | |
| 207 | + | |
| 208 | + pMCRefMem->iSrcLineLuma = pRefPic->iLinesize[0]; | |
| 209 | + pMCRefMem->iSrcLineChroma = pRefPic->iLinesize[1]; | |
| 210 | + | |
| 211 | + pMCRefMem->pSrcY = pRefPic->pData[0]; | |
| 212 | + pMCRefMem->pSrcU = pRefPic->pData[1]; | |
| 213 | + pMCRefMem->pSrcV = pRefPic->pData[2]; | |
| 214 | +} | |
| 215 | + | |
| 216 | + | |
| 217 | +#ifndef MC_FLOW_SIMPLE_JUDGE | |
| 218 | +#define MC_FLOW_SIMPLE_JUDGE 1 | |
| 219 | +#endif //MC_FLOW_SIMPLE_JUDGE | |
| 220 | +static inline void_t BaseMC(sMCRefMember* pMCRefMem, int32_t iXOffset, int32_t iYOffset, SMcFunc* pMCFunc, | |
| 221 | + int32_t iBlkWidth, int32_t iBlkHeight, int16_t iMVs[2]) | |
| 222 | +{ | |
| 223 | + int32_t iExpandWidth = PADDING_LENGTH; | |
| 224 | + int32_t iExpandHeight = PADDING_LENGTH; | |
| 225 | + | |
| 226 | + | |
| 227 | + int16_t iMVX = iMVs[0] >> 2; | |
| 228 | + int16_t iMVY = iMVs[1] >> 2; | |
| 229 | + int32_t iMVOffsetLuma = iMVX + iMVY * pMCRefMem->iSrcLineLuma; | |
| 230 | + int32_t iMVOffsetChroma = (iMVX>>1) + (iMVY>>1) * pMCRefMem->iSrcLineChroma; | |
| 231 | + | |
| 232 | + int32_t iFullMVx = (iXOffset << 2) + iMVs[0]; //quarter pixel | |
| 233 | + int32_t iFullMVy = (iYOffset << 2) + iMVs[1]; | |
| 234 | + int32_t iIntMVx = iFullMVx >> 2;//integer pixel | |
| 235 | + int32_t iIntMVy = iFullMVy >> 2; | |
| 236 | + | |
| 237 | + int32_t iSrcPixOffsetLuma = iXOffset + iYOffset * pMCRefMem->iSrcLineLuma; | |
| 238 | + int32_t iSrcPixOffsetChroma = (iXOffset>>1) + (iYOffset>>1) * pMCRefMem->iSrcLineChroma; | |
| 239 | + | |
| 240 | + int32_t iBlkWidthChroma = iBlkWidth >> 1; | |
| 241 | + int32_t iBlkHeightChroma = iBlkHeight >> 1; | |
| 242 | + int32_t iPicWidthChroma = pMCRefMem->iPicWidth >> 1; | |
| 243 | + int32_t iPicHeightChroma = pMCRefMem->iPicHeight >> 1; | |
| 244 | + | |
| 245 | + //the offset only for luma padding if MV violation as there was 5-tap (-2, -1, 0, 1, 2) filter for luma (horizon and vertical) | |
| 246 | + int32_t iPadOffset = 2 + (pMCRefMem->iSrcLineLuma << 1); //(-2, -2) pixel location as the starting point | |
| 247 | + | |
| 248 | + uint8_t* pSrcY = pMCRefMem->pSrcY + iSrcPixOffsetLuma; | |
| 249 | + uint8_t* pSrcU = pMCRefMem->pSrcU + iSrcPixOffsetChroma; | |
| 250 | + uint8_t* pSrcV = pMCRefMem->pSrcV + iSrcPixOffsetChroma; | |
| 251 | + uint8_t* pDstY = pMCRefMem->pDstY; | |
| 252 | + uint8_t* pDstU = pMCRefMem->pDstU; | |
| 253 | + uint8_t* pDstV = pMCRefMem->pDstV; | |
| 254 | + bool_t bExpand = false; | |
| 255 | + | |
| 256 | + FORCE_STACK_ALIGN_1D( uint8_t, uiExpandBuf, (PADDING_LENGTH+6)*(PADDING_LENGTH+6), 16 ); | |
| 257 | + | |
| 258 | + if (iFullMVx & 0x07) | |
| 259 | + { | |
| 260 | + iExpandWidth -= 3; | |
| 261 | + } | |
| 262 | + if (iFullMVy & 0x07) | |
| 263 | + { | |
| 264 | + iExpandHeight -= 3; | |
| 265 | + } | |
| 266 | + | |
| 267 | +#ifdef MC_FLOW_SIMPLE_JUDGE | |
| 268 | + if (iIntMVx < -iExpandWidth || | |
| 269 | + iIntMVy < -iExpandHeight || | |
| 270 | + iIntMVx + iBlkWidth > pMCRefMem->iPicWidth - 1 + iExpandWidth || | |
| 271 | + iIntMVy + iBlkHeight > pMCRefMem->iPicHeight - 1 + iExpandHeight) | |
| 272 | +#else | |
| 273 | + if (iIntMVx < -iExpandWidth || | |
| 274 | + iIntMVy < -iExpandHeight || | |
| 275 | + iIntMVx + PADDING_LENGTH > pMCRefMem->iPicWidth + iExpandWidth || | |
| 276 | + iIntMVy + PADDING_LENGTH > pMCRefMem->iPicHeight + iExpandHeight) | |
| 277 | +#endif | |
| 278 | + { | |
| 279 | + FillBufForMc(uiExpandBuf, 21, pSrcY, pMCRefMem->iSrcLineLuma, iMVOffsetLuma-iPadOffset, | |
| 280 | + iBlkWidth+5, iBlkHeight+5, iIntMVx-2, iIntMVy-2, pMCRefMem->iPicWidth, pMCRefMem->iPicHeight); | |
| 281 | + pMCFunc->pMcLumaFunc(uiExpandBuf+44, 21, pDstY, pMCRefMem->iDstLineLuma, iFullMVx, iFullMVy, iBlkWidth, iBlkHeight);//44=2+2*21 | |
| 282 | + bExpand = true; | |
| 283 | + } | |
| 284 | + else | |
| 285 | + { | |
| 286 | + pSrcY += iMVOffsetLuma; | |
| 287 | + pMCFunc->pMcLumaFunc(pSrcY, pMCRefMem->iSrcLineLuma, pDstY, pMCRefMem->iDstLineLuma, iFullMVx, iFullMVy, iBlkWidth, iBlkHeight); | |
| 288 | + } | |
| 289 | + | |
| 290 | + if (bExpand) | |
| 291 | + { | |
| 292 | + FillBufForMc(uiExpandBuf, 21, pSrcU, pMCRefMem->iSrcLineChroma, iMVOffsetChroma, iBlkWidthChroma+1, iBlkHeightChroma+1, iFullMVx>>3, iFullMVy>>3, iPicWidthChroma, iPicHeightChroma); | |
| 293 | + pMCFunc->pMcChromaFunc(uiExpandBuf, 21, pDstU, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy, iBlkWidthChroma, iBlkHeightChroma); | |
| 294 | + | |
| 295 | + FillBufForMc(uiExpandBuf, 21, pSrcV, pMCRefMem->iSrcLineChroma, iMVOffsetChroma, iBlkWidthChroma+1, iBlkHeightChroma+1, iFullMVx>>3, iFullMVy>>3, iPicWidthChroma, iPicHeightChroma); | |
| 296 | + pMCFunc->pMcChromaFunc(uiExpandBuf, 21, pDstV, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy, iBlkWidthChroma, iBlkHeightChroma); | |
| 297 | + } | |
| 298 | + else | |
| 299 | + { | |
| 300 | + pSrcU += iMVOffsetChroma; | |
| 301 | + pSrcV += iMVOffsetChroma; | |
| 302 | + pMCFunc->pMcChromaFunc(pSrcU, pMCRefMem->iSrcLineChroma, pDstU, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy, iBlkWidthChroma, iBlkHeightChroma); | |
| 303 | + pMCFunc->pMcChromaFunc(pSrcV, pMCRefMem->iSrcLineChroma, pDstV, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy, iBlkWidthChroma, iBlkHeightChroma); | |
| 304 | + } | |
| 305 | +} | |
| 306 | + | |
| 307 | +void_t GetInterPred(uint8_t *pPredY, uint8_t *pPredCb, uint8_t *pPredCr, PWelsDecoderContext pCtx) | |
| 308 | +{ | |
| 309 | + sMCRefMember pMCRefMem; | |
| 310 | + PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 311 | + SMcFunc* pMCFunc = &pCtx->sMcFunc; | |
| 312 | + | |
| 313 | + int32_t iMBXY = pCurDqLayer->iMbXyIndex; | |
| 314 | + | |
| 315 | + int16_t iMVs[2] = {0}; | |
| 316 | + | |
| 317 | + int32_t iMBType = pCurDqLayer->pMbType[iMBXY]; | |
| 318 | + | |
| 319 | + int32_t iMBOffsetX = pCurDqLayer->iMbX << 4; | |
| 320 | + int32_t iMBOffsetY = pCurDqLayer->iMbY << 4; | |
| 321 | + | |
| 322 | + int32_t iDstLineLuma = pCtx->pDec->iLinesize[0]; | |
| 323 | + int32_t iDstLineChroma = pCtx->pDec->iLinesize[1]; | |
| 324 | + | |
| 325 | + int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, i, j, iIIdx, iJIdx; | |
| 326 | + | |
| 327 | + pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth<<4); | |
| 328 | + pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight<<4); | |
| 329 | + | |
| 330 | + pMCRefMem.pDstY = pPredY; | |
| 331 | + pMCRefMem.pDstU = pPredCb; | |
| 332 | + pMCRefMem.pDstV = pPredCr; | |
| 333 | + | |
| 334 | + pMCRefMem.iDstLineLuma = iDstLineLuma; | |
| 335 | + pMCRefMem.iDstLineChroma = iDstLineChroma; | |
| 336 | + switch(iMBType) | |
| 337 | + { | |
| 338 | + case MB_TYPE_SKIP: | |
| 339 | + case MB_TYPE_16x16: | |
| 340 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 341 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 342 | + GetRefPic( &pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0 ); | |
| 343 | + BaseMC(&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 344 | + break; | |
| 345 | + case MB_TYPE_16x8: | |
| 346 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 347 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 348 | + GetRefPic( &pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0 ); | |
| 349 | + BaseMC(&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 8, iMVs); | |
| 350 | + | |
| 351 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][8][0]; | |
| 352 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][8][1]; | |
| 353 | + GetRefPic( &pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 8 ); | |
| 354 | + pMCRefMem.pDstY = pPredY + (iDstLineLuma << 3); | |
| 355 | + pMCRefMem.pDstU = pPredCb + (iDstLineChroma << 2); | |
| 356 | + pMCRefMem.pDstV = pPredCr + (iDstLineChroma << 2); | |
| 357 | + BaseMC(&pMCRefMem, iMBOffsetX, iMBOffsetY+8, pMCFunc, 16, 8, iMVs); | |
| 358 | + break; | |
| 359 | + case MB_TYPE_8x16: | |
| 360 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 361 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 362 | + GetRefPic( &pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0 ); | |
| 363 | + BaseMC(&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 364 | + | |
| 365 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][2][0]; | |
| 366 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][2][1]; | |
| 367 | + GetRefPic( &pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 2 ); | |
| 368 | + pMCRefMem.pDstY = pPredY + 8; | |
| 369 | + pMCRefMem.pDstU = pPredCb + 4; | |
| 370 | + pMCRefMem.pDstV = pPredCr + 4; | |
| 371 | + BaseMC(&pMCRefMem, iMBOffsetX+8, iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 372 | + break; | |
| 373 | + case MB_TYPE_8x8: | |
| 374 | + case MB_TYPE_8x8_REF0: | |
| 375 | + { | |
| 376 | + uint32_t iSubMBType; | |
| 377 | + int32_t iXOffset, iYOffset; | |
| 378 | + uint8_t *pDstY, *pDstU, *pDstV; | |
| 379 | + for (i = 0; i < 4; i++) | |
| 380 | + { | |
| 381 | + iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i]; | |
| 382 | + iBlk8X = (i&1) << 3; | |
| 383 | + iBlk8Y = (i>>1) << 3; | |
| 384 | + iXOffset = iMBOffsetX + iBlk8X; | |
| 385 | + iYOffset = iMBOffsetY + iBlk8Y; | |
| 386 | + | |
| 387 | + iIIdx = ((i>>1)<<3) +((i&1)<<1); | |
| 388 | + GetRefPic( &pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], iIIdx ); | |
| 389 | + | |
| 390 | + pDstY = pPredY + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 391 | + pDstU = pPredCb + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 392 | + pDstV = pPredCr + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 393 | + pMCRefMem.pDstY = pDstY; | |
| 394 | + pMCRefMem.pDstU = pDstU; | |
| 395 | + pMCRefMem.pDstV = pDstV; | |
| 396 | + switch(iSubMBType) | |
| 397 | + { | |
| 398 | + case SUB_MB_TYPE_8x8: | |
| 399 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 400 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 401 | + BaseMC( &pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs ); | |
| 402 | + break; | |
| 403 | + case SUB_MB_TYPE_8x4: | |
| 404 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 405 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 406 | + BaseMC(&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 407 | + | |
| 408 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx+4][0]; | |
| 409 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx+4][1]; | |
| 410 | + pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 411 | + pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 412 | + pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 413 | + BaseMC(&pMCRefMem, iXOffset, iYOffset+4, pMCFunc, 8, 4, iMVs); | |
| 414 | + break; | |
| 415 | + case SUB_MB_TYPE_4x8: | |
| 416 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 417 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 418 | + BaseMC(&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 419 | + | |
| 420 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx+1][0]; | |
| 421 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx+1][1]; | |
| 422 | + pMCRefMem.pDstY += 4; | |
| 423 | + pMCRefMem.pDstU += 2; | |
| 424 | + pMCRefMem.pDstV += 2; | |
| 425 | + BaseMC(&pMCRefMem, iXOffset+4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 426 | + break; | |
| 427 | + case SUB_MB_TYPE_4x4: | |
| 428 | + { | |
| 429 | + for (j = 0; j < 4; j++) | |
| 430 | + { | |
| 431 | + int32_t iUVLineStride; | |
| 432 | + iJIdx = ((j>>1)<<2) + (j&1); | |
| 433 | + | |
| 434 | + iBlk4X = (j&1) << 2; | |
| 435 | + iBlk4Y = (j>>1) << 2; | |
| 436 | + | |
| 437 | + iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 438 | + pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 439 | + pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 440 | + pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 441 | + | |
| 442 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx+iJIdx][0]; | |
| 443 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx+iJIdx][1]; | |
| 444 | + BaseMC(&pMCRefMem, iXOffset+iBlk4X, iYOffset+iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 445 | + } | |
| 446 | + } | |
| 447 | + break; | |
| 448 | + default: | |
| 449 | + break; | |
| 450 | + } | |
| 451 | + } | |
| 452 | + } | |
| 453 | + break; | |
| 454 | + default: | |
| 455 | + break; | |
| 456 | + } | |
| 457 | +} | |
| 458 | + | |
| 459 | +int32_t RecChroma(int32_t iMBXY, PWelsDecoderContext pCtx, int16_t *pScoeffLevel, PDqLayer pDqLayer) | |
| 460 | +{ | |
| 461 | + int32_t iChromaStride = pCtx->pCurDqLayer->iCsStride[1]; | |
| 462 | + PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc; | |
| 463 | + | |
| 464 | + uint8_t i=0, j=0; | |
| 465 | + uint8_t uiCbpC = pDqLayer->pCbp[iMBXY] >> 4; | |
| 466 | + | |
| 467 | + if ( 1 == uiCbpC || 2 == uiCbpC ) | |
| 468 | + { | |
| 469 | + WelsChromaDcIdct( pScoeffLevel + 256 ); // 256 = 16*16 | |
| 470 | + WelsChromaDcIdct( pScoeffLevel + 320 ); // 256 = 16*16 | |
| 471 | + for(i=0; i<2; i++) | |
| 472 | + { | |
| 473 | + int16_t *pRS = pScoeffLevel + 256 + (i << 6); | |
| 474 | + uint8_t *pPred = pDqLayer->pPred[i+1]; | |
| 475 | + int32_t *pBlockOffset = i==0 ? &pCtx->iDecBlockOffsetArray[16] : &pCtx->iDecBlockOffsetArray[20]; | |
| 476 | + | |
| 477 | + /*1 chroma is divided 4 4x4_block to idct*/ | |
| 478 | + for(j=0; j<4; j++) | |
| 479 | + { | |
| 480 | + int16_t *pRSI4x4 = &pRS[j<<4]; | |
| 481 | + uint8_t *pPredI4x4 = pPred + pBlockOffset[j]; | |
| 482 | + | |
| 483 | + if ( pDqLayer->pNzc[iMBXY][g_kuiMbNonZeroCountIdx[16+(i<<2)+j]] || pRSI4x4[0] ) | |
| 484 | + { | |
| 485 | + pIdctResAddPredFunc(pPredI4x4, iChromaStride, pRSI4x4); | |
| 486 | + } | |
| 487 | + } | |
| 488 | + } | |
| 489 | + } | |
| 490 | + | |
| 491 | + return ERR_NONE; | |
| 492 | +} | |
| 493 | + | |
| 494 | +void_t FillBufForMc(uint8_t *pBuf, int32_t iBufStride, uint8_t *pSrc, int32_t iSrcStride, int32_t iSrcOffset, | |
| 495 | + int32_t iBlockWidth, int32_t iBlockHeight, int32_t iSrcX, int32_t iSrcY, int32_t iPicWidth, int32_t iPicHeight) | |
| 496 | +{ | |
| 497 | + int32_t iY; | |
| 498 | + int32_t iStartY, iStartX, iEndY, iEndX; | |
| 499 | + int32_t iOffsetAdj = 0; | |
| 500 | + int32_t iAddrSrc, iAddrBuf; | |
| 501 | + int32_t iNum, iNum1; | |
| 502 | + uint8_t *pBufSrc, *pBufDst; | |
| 503 | + uint8_t *pBufSrc1, *pBufDst1; | |
| 504 | + | |
| 505 | + if( iSrcY >= iPicHeight ) | |
| 506 | + { | |
| 507 | + iOffsetAdj += ( iPicHeight - 1 - iSrcY ) * iSrcStride; | |
| 508 | + iSrcY = iPicHeight - 1; | |
| 509 | + } | |
| 510 | + else if( iSrcY <= -iBlockHeight ) | |
| 511 | + { | |
| 512 | + iOffsetAdj += ( 1 - iBlockHeight - iSrcY ) * iSrcStride; | |
| 513 | + iSrcY = 1 - iBlockHeight; | |
| 514 | + } | |
| 515 | + if( iSrcX >= iPicWidth ) | |
| 516 | + { | |
| 517 | + iOffsetAdj += ( iPicWidth - 1 - iSrcX ); | |
| 518 | + iSrcX = iPicWidth - 1; | |
| 519 | + } | |
| 520 | + else if( iSrcX <= -iBlockWidth ) | |
| 521 | + { | |
| 522 | + iOffsetAdj += ( 1 - iBlockWidth - iSrcX ); | |
| 523 | + iSrcX = 1 - iBlockWidth; | |
| 524 | + } | |
| 525 | + | |
| 526 | + iOffsetAdj += iSrcOffset; | |
| 527 | + | |
| 528 | +#define MAX(a,b) ((a) > (b) ? (a) : (b)) | |
| 529 | +#define MIN(a,b) ((a) > (b) ? (b) : (a)) | |
| 530 | + | |
| 531 | + iStartY = MAX(0, -iSrcY); | |
| 532 | + iStartX = MAX(0, -iSrcX); | |
| 533 | + iEndY = MIN(iBlockHeight, iPicHeight - iSrcY); | |
| 534 | + iEndX = MIN(iBlockWidth, iPicWidth - iSrcX); | |
| 535 | + | |
| 536 | + // copy existing part | |
| 537 | + iAddrSrc = iStartX + iStartY * iSrcStride; | |
| 538 | + iAddrBuf = iStartX + iStartY * iBufStride; | |
| 539 | + iNum = iEndX - iStartX; | |
| 540 | + for( iY = iStartY; iY < iEndY; iY++ ) | |
| 541 | + { | |
| 542 | + memcpy( pBuf + iAddrBuf, pSrc + iOffsetAdj + iAddrSrc, iNum ); | |
| 543 | + iAddrSrc += iSrcStride; | |
| 544 | + iAddrBuf += iBufStride; | |
| 545 | + } | |
| 546 | + | |
| 547 | + //top | |
| 548 | + pBufSrc = pBuf + iStartX + iStartY * iBufStride; | |
| 549 | + pBufDst = pBuf + iStartX; | |
| 550 | + iNum = iEndX - iStartX; | |
| 551 | + for( iY = 0; iY < iStartY; iY++ ) | |
| 552 | + { | |
| 553 | + memcpy( pBufDst, pBufSrc, iNum ); | |
| 554 | + pBufDst += iBufStride; | |
| 555 | + } | |
| 556 | + | |
| 557 | + //bottom | |
| 558 | + pBufSrc = pBuf + iStartX + ( iEndY - 1 ) * iBufStride; | |
| 559 | + pBufDst = pBuf + iStartX + iEndY * iBufStride; | |
| 560 | + iNum = iEndX - iStartX; | |
| 561 | + for( iY = iEndY; iY < iBlockHeight; iY++ ) | |
| 562 | + { | |
| 563 | + memcpy( pBufDst, pBufSrc, iNum ); | |
| 564 | + pBufDst += iBufStride; | |
| 565 | + } | |
| 566 | + | |
| 567 | + | |
| 568 | + pBufSrc = pBuf + iStartX; | |
| 569 | + pBufDst = pBuf; | |
| 570 | + iNum = iStartX; | |
| 571 | + | |
| 572 | + pBufSrc1 = pBuf + iEndX - 1; | |
| 573 | + pBufDst1 = pBuf + iEndX; | |
| 574 | + iNum1 = iBlockWidth - iEndX; | |
| 575 | + for( iY=0; iY<iBlockHeight; iY++ ) | |
| 576 | + { | |
| 577 | + //left | |
| 578 | + memset( pBufDst, pBufSrc[0], iNum ); | |
| 579 | + pBufDst += iBufStride; | |
| 580 | + pBufSrc += iBufStride; | |
| 581 | + | |
| 582 | + //right | |
| 583 | + memset( pBufDst1, pBufSrc1[0], iNum1 ); | |
| 584 | + pBufDst1 += iBufStride; | |
| 585 | + pBufSrc1 += iBufStride; | |
| 586 | + } | |
| 587 | +} | |
| 588 | + | |
| 589 | +} // namespace WelsDec | |