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

📄 deblock_test.sc

📁 deblocking 在SPI DSP平台优化好的代码,超级强
💻 SC
📖 第 1 页 / 共 2 页
字号:
            exit(-1);        }        else        {            spi_printf("Invalid argument: %s", argv[argnum]);            exit(-1);        }        argnum++;    }    if (*use_jm_data){        *Random = 0;        *Seed   = 0;    }}//--------------------------------------------------------------------void CreateFrame//--------------------------------------------------------------------( // Output yuv_frame_t* Frame, // Input int Width, int Height, int buf_width, int buf_height)//--------------------------------------------------------------------{    Frame->width = buf_width;    Frame->height = buf_height;    Frame->image_width = Width;    Frame->image_height = Height;    Frame->y = spi_malloc(buf_width*buf_height);    Frame->u = spi_malloc(2*(buf_width/2)*(buf_height/2));        if ((Frame->y == NULL) || (Frame->u == NULL)) {        spi_printf("Error allocating memory for image frames!!  Exiting...");        exit(-1);    }    Frame->v = Frame->u + (buf_width/2)*(buf_height/2);}//--------------------------------------------------------------------void DestroyFrame//--------------------------------------------------------------------( // Input and Output yuv_frame_t* Frame)//--------------------------------------------------------------------{    if (Frame->y) spi_free(Frame->y);    if (Frame->u) spi_free(Frame->u);}//--------------------------------------------------------------------void CopyFrame//--------------------------------------------------------------------( // Input and Output yuv_frame_t* FrameIn, yuv_frame_t* FrameOut)//--------------------------------------------------------------------{    int NumLumaPix, NumChromaPix;    assert(FrameIn->width == FrameOut->width);    assert(FrameIn->height == FrameOut->height);        FrameOut->image_width = FrameIn->image_width;    FrameOut->image_height = FrameIn->image_height;    NumLumaPix = FrameIn->width * FrameIn->height;    NumChromaPix = NumLumaPix / 4;    memcpy(FrameOut->y, FrameIn->y, NumLumaPix);    memcpy(FrameOut->u, FrameIn->u, NumChromaPix);    memcpy(FrameOut->v, FrameIn->v, NumChromaPix);}//--------------------------------------------------------------------void InitPixels//--------------------------------------------------------------------( yuv_frame_t* Frame, int Random )//--------------------------------------------------------------------{    int NumLumaPix = Frame->width * Frame->height;    int NumChromaPix = NumLumaPix / 4;    if (Random) {        RandomData(Frame->y, NumLumaPix);        RandomData(Frame->u, NumChromaPix);        RandomData(Frame->v, NumChromaPix);    }else{        LinearData(Frame->y, NumLumaPix);        LinearData(Frame->u, NumChromaPix);        LinearData(Frame->v, NumChromaPix);    }}//--------------------------------------------------------------------void InitMBContext//--------------------------------------------------------------------( S_BLK_MB_INFO *pBlkMBInfo, S_BLK_MB_INFO_COMPRESSED *p_blk_mb_info_comp, int Random, int NumMBx, int NumMBy )//--------------------------------------------------------------------{    int i, j, k, x, y;    int NumMB = NumMBx * NumMBy;    int StartNewSlice = 1;    int *SliceMap = spi_malloc(NumMB * sizeof(*SliceMap));    char *disable_filter_idc_p = spi_malloc(NumMB);    char *filt_offseta_p = spi_malloc(NumMB);    char *filt_offsetb_p = spi_malloc(NumMB);    int SliceNum = 0;    // Fill SliceMap    for (i = 0; i < NumMB; i++) {        SliceMap[i] = SliceNum;        if (Random) {            StartNewSlice = ((rand() % ((NumMB + 2)/2)) == 0);        } else {            StartNewSlice = ((i % ((NumMB + 3)/3)) == 0);        }        if (StartNewSlice) {            // For new slice set alpha, beta offsets and disable_filter            SliceNum++;        }    }    // Fill context data structure    for (i = 0; i < NumMB; i++) {        unsigned int CBP = 0;        int QP, Type, RefFrameIdx[2][2];        // Picture boundaries        int Loc = 0;        Loc = 0;        Loc |= (i % NumMBx) ? 0 : LOC_MB_LEFT_PICTURE_EDGE;        Loc |= (i >= NumMBx) ? 0 : LOC_MB_TOP_PICTURE_EDGE;        Loc |= ((i % NumMBx) < (NumMBx-1)) ? 0 : LOC_MB_RIGHT_PICTURE_EDGE;        Loc |= (i < (NumMB - NumMBx)) ? 0 : LOC_MB_BOTTOM_PICTURE_EDGE;        // Slice boundaries        if ((Loc & LOC_MB_LEFT_PICTURE_EDGE)            || (SliceMap[i] != SliceMap[i - 1])) {            Loc |= LOC_MB_LEFT_SLICE_EDGE;        }        if ((Loc & LOC_MB_RIGHT_PICTURE_EDGE)            || (SliceMap[i] != SliceMap[i + 1])) {            Loc |= LOC_MB_RIGHT_SLICE_EDGE;        }        if ((Loc & LOC_MB_TOP_PICTURE_EDGE)            || (SliceMap[i] != SliceMap[i - NumMBx])) {            Loc |= LOC_MB_TOP_SLICE_EDGE;        }        if ((Loc & LOC_MB_BOTTOM_PICTURE_EDGE)            || (SliceMap[i] != SliceMap[i + NumMBx])) {            Loc |= LOC_MB_BOTTOM_SLICE_EDGE;        }        if (Random) {            QP = (rand() % 52);            Type = (rand() % 4);        } else {            QP = (i % 52);            Type = (i % 4);        }        for (j = 0; j < 2; j++) {            for (k = 0; k < 2; k++) {                if (Random) {                    RefFrameIdx[j][k] = (rand() % 2);                } else {                    RefFrameIdx[j][k] = (((x + y + i) % 23) != 0) ? 0 : 1;                }            }        }        for (j = 0; j < BLOCKS_PER_MB; j++) {            int RefFrameIdxVal, MVx, MVy, CBP_local, TotalCoeffLuma;            int Idx = i*BLOCKS_PER_MB + j;            x = j % 4;            y = j / 4;                        RefFrameIdxVal = RefFrameIdx[y/2][x/2];                        if (Random){                MVx = (rand() % 256) - 128;                MVy = (rand() % 256) - 128;                CBP_local = ((rand() % 2) << 16);                TotalCoeffLuma = (CBP_local) ? 5 : 0;            }else{                MVx = ((x + y + i) % 17);                MVy = ((x + y + i) % 25);                CBP_local = ((1 % 2) << 16);                TotalCoeffLuma = (CBP_local) ? 5 : 0;            }                                    pBlkMBInfo[Idx].Loc = Loc;            pBlkMBInfo[Idx].QP = QP;            pBlkMBInfo[Idx].Type = Type;            pBlkMBInfo[Idx].RefFrameIdx = RefFrameIdxVal;                        pBlkMBInfo[Idx].MV.x = MVx;            pBlkMBInfo[Idx].MV.y = MVy;            pBlkMBInfo[Idx].CBP = CBP_local;            pBlkMBInfo[Idx].TotalCoeffLuma = (CBP_local) ? 5 : 0;            //spi_printf("Idx %d  Loc 0x%04X QP %d Type %d RefFrameIdx %d MV_x %d MV_y %d CBP %d \n",            //           Idx, Loc, QP, Type, RefFrameIdxVal, MVx, MVy, CBP_local);            p_blk_mb_info_comp[Idx].MBModes = (RefFrameIdxVal << 24) | Type;            p_blk_mb_info_comp[Idx].Misc = (QP << 8);            p_blk_mb_info_comp[Idx].Loc = Loc;            p_blk_mb_info_comp[Idx].NumCoefsAndSAD = pBlkMBInfo[Idx].TotalCoeffLuma << 24;            p_blk_mb_info_comp[Idx].MV = (MVy << 16) | (MVx & 0xFFFF);        }    }    spi_free(SliceMap);    spi_free(disable_filter_idc_p);    spi_free(filt_offseta_p);    spi_free(filt_offsetb_p);}//--------------------------------------------------------------------void RandomData//--------------------------------------------------------------------( unsigned char *arr, int len )//--------------------------------------------------------------------{    int i;    assert(RAND_MAX >= 255);    for (i = 0; i < len; i++) {        arr[i] = rand() % 256;    }}//--------------------------------------------------------------------void LinearData//--------------------------------------------------------------------( unsigned char *arr, int len )//--------------------------------------------------------------------{    int i;    assert(RAND_MAX >= 255);    for (i = 0; i < len; i++) {        arr[i] = i % 256;    }}//--------------------------------------------------------------------int CompareData//--------------------------------------------------------------------( // Cmp frame unsigned char *arr1, // Ref frame unsigned char *arr2, int len, char *name, int width)//--------------------------------------------------------------------{    int mismatch = 0;    int i;    for (i = 0; i < len; i++) {        if (arr1[i] != arr2[i]) {            spi_printf("Error at %d in %s x %d y %d Ref 0x%02X Cmp 0x%02X\n",                       i, name, i % width, i/width, arr2[i], arr1[i]);            mismatch++;        }    }    return(mismatch);}

⌨️ 快捷键说明

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