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

📄 umc_vc1_dec_blk.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* /////////////////////////////////////////////////////////////////////////////
//
//                  INTEL CORPORATION PROPRIETARY INFORMATION
//     This software is supplied under the terms of a license agreement or
//     nondisclosure agreement with Intel Corporation and may not be copied
//     or disclosed except in accordance with the terms of that agreement.
//          Copyright(c) 2004-2007 Intel Corporation. All Rights Reserved.
//
//
//          VC-1 (VC1) decoder, block layer, simple\main profile
//
*/

#include "umc_defs.h"

#if defined (UMC_ENABLE_VC1_VIDEO_DECODER)

#include "ippi.h"

#include "umc_vc1_dec_seq.h"
#include "umc_vc1_common_zigzag_tbl.h"
#include "umc_vc1_common_blk_order_tbl.h"
#include "umc_vc1_dec_run_level_tbl.h"

#include "umc_vc1_dec_debug.h"

#include "umc_vc1_dec_time_statistics.h"

typedef Ipp8u (*DCPrediction)(VC1DCBlkParam* CurrBlk, VC1DCPredictors* PredData,
                               Ipp32s blk_num, Ipp16s* pBlock,Ipp16s defaultDC, Ipp32u PTYPE);

inline static void PredictACLeft(Ipp16s* pCurrAC, Ipp32u CurrQuant,
                                 Ipp16s* pPredAC, Ipp32u PredQuant,
                                 Ipp32s Step)
{
    Ipp32s i;
    Ipp32s Scale = VC1_DQScaleTbl[CurrQuant-1] * (PredQuant-1);
    Ipp32u step = Step;

    for (i = 1; i<VC1_PIXEL_IN_BLOCK; i++, step+=Step)
        pCurrAC[step] = pCurrAC[step] + (Ipp16s)((pPredAC[i] * Scale + 0x20000)>>18);
}

inline static void PredictACTop(Ipp16s* pCurrAC, Ipp32u CurrQuant,
                                Ipp16s* pPredAC, Ipp32u PredQuant)
{
    Ipp32s i;
    Ipp32s Scale = VC1_DQScaleTbl[CurrQuant-1] * (PredQuant-1);

    for (i = 1; i<VC1_PIXEL_IN_BLOCK; i++)
        pCurrAC[i] = pCurrAC[i] + (Ipp16s)((pPredAC[i] * Scale + 0x20000)>>18);
}


static Ipp8u GetDCACPrediction(VC1DCBlkParam* CurrBlk, VC1DCPredictors* PredData,
                               Ipp32s blk_num, Ipp16s* pBlock,Ipp16s defaultDC, Ipp32u PTYPE)
{
    Ipp8u blkType = VC1_BLK_INTRA;

    VC1DCPredictors DCPred;
    Ipp8u PredPattern;
    Ipp32u CurrQuant = PredData->DoubleQuant[2];

    Ipp16s DCA, DCB, DCC, DC = 0;
    Ipp32u step = VC1_pixel_table[blk_num];

    memcpy(&DCPred, PredData, sizeof(VC1DCPredictors));
    PredPattern = DCPred.BlkPattern[blk_num];

    switch(PredPattern)
    {
    case 7:
        {
            DCA = DCPred.DC[VC1_PredDCIndex[0][blk_num]];
            DCB = DCPred.DC[VC1_PredDCIndex[1][blk_num]];
            DCC = DCPred.DC[VC1_PredDCIndex[2][blk_num]];

            if (vc1_abs_16s(DCB - DCA) <= vc1_abs_16s(DCB - DCC))
            {
                #ifdef VC1_DEBUG_ON
                VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                                "DC left prediction\n");
                #endif

                DC = CurrBlk->DC + DCC;
                PredictACLeft(pBlock, CurrQuant, DCPred.ACLEFT[VC1_PredDCIndex[2][blk_num]],
                    DCPred.DoubleQuant[VC1_QuantIndex[1][blk_num]], step);

                blkType =  VC1_BLK_INTRA_LEFT;
            }
            else
            {
                #ifdef VC1_DEBUG_ON
                VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                                "DC top prediction\n");
                #endif

                DC = CurrBlk->DC + DCA;
                PredictACTop(pBlock, CurrQuant, DCPred.ACTOP[VC1_PredDCIndex[0][blk_num]],
                    DCPred.DoubleQuant[VC1_QuantIndex[0][blk_num]]);

                blkType = VC1_BLK_INTRA_TOP;
            }
        }
        break;
    case 4:
    case 6:
        {
            //A is available, C - not
            #ifdef VC1_DEBUG_ON
            VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                            "DC top prediction\n");
            #endif

            DCA = DCPred.DC[VC1_PredDCIndex[0][blk_num]];
            DC = CurrBlk->DC + DCA;

            if (!(DCA==defaultDC && (PTYPE == VC1_I_FRAME ||  PTYPE == VC1_BI_FRAME)))
            {
                PredictACTop(pBlock, CurrQuant, DCPred.ACTOP[VC1_PredDCIndex[0][blk_num]],
                    DCPred.DoubleQuant[VC1_QuantIndex[0][blk_num]]);
                blkType = VC1_BLK_INTRA_TOP;
            }
        }
        break;
    case 1:
    case 3:
        {
            //C is available, A - not
            #ifdef VC1_DEBUG_ON
            VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                            "DC left prediction\n");
            #endif

            DCC = DCPred.DC[VC1_PredDCIndex[2][blk_num]];
            DC = CurrBlk->DC + DCC;
            PredictACLeft(pBlock, CurrQuant, DCPred.ACLEFT[VC1_PredDCIndex[2][blk_num]],
                DCPred.DoubleQuant[VC1_QuantIndex[1][blk_num]], step);
            blkType = VC1_BLK_INTRA_LEFT;
        }
        break;
    case 5:
        {
            DCA = DCPred.DC[VC1_PredDCIndex[0][blk_num]];
            DCB = defaultDC;
            DCC = DCPred.DC[VC1_PredDCIndex[2][blk_num]];

            if (vc1_abs_16s(DCA) <= vc1_abs_16s(DCC))
            {
                #ifdef VC1_DEBUG_ON
                VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                                "DC left prediction\n");
                #endif

                DC= CurrBlk->DC + DCC;
                PredictACLeft(pBlock, CurrQuant, DCPred.ACLEFT[VC1_PredDCIndex[2][blk_num]],
                    DCPred.DoubleQuant[VC1_QuantIndex[1][blk_num]], step);
                blkType = VC1_BLK_INTRA_LEFT;
            }
            else
            {
                #ifdef VC1_DEBUG_ON
                VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                                    "DC top prediction\n");
                #endif

                DC = CurrBlk->DC + DCA;
                PredictACTop(pBlock, CurrQuant, DCPred.ACTOP[VC1_PredDCIndex[0][blk_num]],
                    DCPred.DoubleQuant[VC1_QuantIndex[0][blk_num]]);
                blkType = VC1_BLK_INTRA_TOP;
            }
        }
        break;
    case 0:
    case 2:
        {
            // A, C unavailable
            #ifdef VC1_DEBUG_ON
            VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                            "DC left prediction\n");
            #endif

            blkType = VC1_BLK_INTRA_LEFT;
            DC = CurrBlk->DC + defaultDC;
         }
        break;
    }

    pBlock[0] = DC;
    PredData->DC[blk_num] = DC;
    CurrBlk->DC = DC;
    return blkType;
}

static Ipp8u GetDCPrediction(VC1DCBlkParam* CurrBlk,VC1DCPredictors* PredData,
                             Ipp32s blk_num, Ipp16s* pBlock,Ipp16s defaultDC, Ipp32u PTYPE)
{
    Ipp8u blkType = VC1_BLK_INTRA;

    VC1DCPredictors DCPred;
    Ipp8u PredPattern;

    Ipp16s DCA, DCB, DCC = 0;

    memcpy(&DCPred, PredData, sizeof(VC1DCPredictors));

    PredPattern = DCPred.BlkPattern[blk_num];

    switch(PredPattern)
    {
    case 7:
        {
            DCA = DCPred.DC[VC1_PredDCIndex[0][blk_num]];
            DCB = DCPred.DC[VC1_PredDCIndex[1][blk_num]];
            DCC = DCPred.DC[VC1_PredDCIndex[2][blk_num]];

            if (vc1_abs_16s(DCB - DCA) <= vc1_abs_16s(DCB - DCC))
            {
                #ifdef VC1_DEBUG_ON
                VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                            "DC left prediction\n");
                #endif

                CurrBlk->DC = CurrBlk->DC + DCC;
                blkType =  VC1_BLK_INTRA_LEFT;
            }
            else
            {
                #ifdef VC1_DEBUG_ON
                VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                                "DC top prediction\n");
                #endif

                CurrBlk->DC = CurrBlk->DC + DCA;
                blkType = VC1_BLK_INTRA_TOP;
            }
        }
        break;
    case 4:
    case 6:
        {
            //A is available, C - not
            #ifdef VC1_DEBUG_ON
            VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                            "DC top prediction\n");
            #endif

            DCA = DCPred.DC[VC1_PredDCIndex[0][blk_num]];

            CurrBlk->DC = CurrBlk->DC + DCA;
            if (!(DCA==defaultDC && (PTYPE == VC1_I_FRAME ||  PTYPE == VC1_BI_FRAME)))
                blkType = VC1_BLK_INTRA_TOP;
        }
        break;
    case 1:
    case 3:
        {
            //C is available, A - not
            #ifdef VC1_DEBUG_ON
            VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                            "DC left prediction\n");
            #endif

            DCC = DCPred.DC[VC1_PredDCIndex[2][blk_num]];
            CurrBlk->DC = CurrBlk->DC + DCC;
            blkType = VC1_BLK_INTRA_LEFT;
        }
        break;
    case 5:
        {
            DCA = DCPred.DC[VC1_PredDCIndex[0][blk_num]];
            DCC = DCPred.DC[VC1_PredDCIndex[2][blk_num]];

            if (vc1_abs_16s(DCA) <= vc1_abs_16s(DCC))
            {
                #ifdef VC1_DEBUG_ON
                VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                            "DC left prediction\n");
                #endif

                CurrBlk->DC = CurrBlk->DC + DCC;
                blkType = VC1_BLK_INTRA_LEFT;
            }
            else
            {
                #ifdef VC1_DEBUG_ON
                VM_Debug::GetInstance(VC1DebugRoutine).vm_debug_frame(-1,VC1_COEFFS,
                                                                "DC top prediction\n");
                #endif

                CurrBlk->DC = CurrBlk->DC + DCA;

⌨️ 快捷键说明

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