我是靠谱客的博主 开心长颈鹿,最近开发中收集的这篇文章主要介绍YUV422转BGR888(海思3516平台),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#include "hi_comm_ive.h"
#include "mpi_ive.h"

#pragma pack(1)

typedef struct{
    short type;
    int size;
    short reserved1;
    short reserved2;
    int offset;
} BMPHeader;

typedef struct{
    int size;
    int width;
    int height;
    short planes;
    short bitsPerPixel;
    unsigned compression;
    unsigned imageSize;
    int xPelsPerMeter;
    int yPelsPerMeter;
    int clrUsed;
    int clrImportant;
} BMPInfoHeader;

#pragma pack()


int saveBMPFile(unsigned char* src, int width, int height, const char* name){
	BMPHeader hdr;
	BMPInfoHeader infoHdr;
    int ret = 0;

	FILE* fp = NULL;
    if(NULL == src) 
    {
		return (-1);
    }

    fp = fopen(name,"wb");
	if(NULL == fp)
    {
		printf("saveBMPFile: Err: Open!n");
		return (-1);
	}

	infoHdr.size	= sizeof(BMPInfoHeader);
	infoHdr.width	= width;
	infoHdr.height	= 0 - height;
	infoHdr.planes	= 1;
	infoHdr.bitsPerPixel	= 24;
	infoHdr.compression		= 0;
	infoHdr.imageSize		= width*height;
	infoHdr.xPelsPerMeter	= 0;
	infoHdr.yPelsPerMeter	= 0;
	infoHdr.clrUsed			= 0;
	infoHdr.clrImportant	= 0;

	hdr.type	= 0x4D42;
	hdr.size	= 54 + infoHdr.imageSize*3;
	hdr.reserved1	= 0;
	hdr.reserved2	= 0;
	hdr.offset	= 54;


    //BGR2RGB
    int i;
    int temp;
    for(i = 0;i < width*height;i++)
    {
        temp = src[i*3];
        src[i*3] = src[i*3 + 2];
        src[i*3 + 2] = temp;
    }

	fwrite(&hdr, sizeof(hdr), 1, fp);
  	fwrite(&infoHdr, sizeof(infoHdr), 1, fp);
 	fwrite(src, sizeof(unsigned char), width*height*3, fp); //TODO:
    fflush(fp);

	if(ferror(fp)){
		printf("saveBMPFile: Err: Unknown!***n");
	}

	fclose(fp);
    fp = NULL;

	return 0;
}

int main()
{
    HI_VOID *pVirtSrc = NULL;
	HI_VOID *pVirtDst = NULL;
	IVE_SRC_INFO_S stSrc;
	IVE_MEM_INFO_S stDst;
    unsigned int * pImage = NULL;

    stSrc.enSrcFmt = IVE_SRC_FMT_SP422;
    stSrc.stSrcMem.u32Stride = nWidth;
    stSrc.stSrcMem.u32PhyAddr = frameInfo->phyAddr;
    stSrc.u32Width = nWidth;
    stSrc.u32Height = nHeight;

    stDst.u32Stride = nWidth;

    IVE_HANDLE IveHandle;
    HI_BOOL bInstant = HI_TRUE;
    IVE_CSC_CTRL_S stCscCtrl;
    stCscCtrl.enOutFmt = IVE_CSC_OUT_FMT_PACKAGE;
    stCscCtrl.enCscMode = IVE_CSC_MODE_VIDEO_BT601_AND_BT656;

    //s32Ret = HI_MPI_SYS_MmzAlloc_Cached (&pstSrc->stSrcMem.u32PhyAddr,&pVirtSrc,"User", HI_NULL, pstSrc->u32Height * pstSrc->stSrcMem.u32Stride*2);
    //memset(pVirtSrc,1,pstSrc->u32Height * pstSrc->stSrcMem.u32Stride);
    ret = HI_MPI_SYS_MmzAlloc_Cached (&stDst.u32PhyAddr, &pVirtDst,"User", HI_NULL, stSrc.u32Height * stDst.u32Stride);
    //s32Ret = HI_MPI_IVE_DMA(&IveHandle, &stSrc, &stDst, bInstant);
    //HI_MPI_SYS_MmzFree(stSrc.stSrcMem.u32PhyAddr, pVirtSrc);
    HI_MPI_SYS_MmzFree(stDst.u32PhyAddr, pVirtDst);
    ret=HI_MPI_IVE_CSC(&IveHandle,&stSrc,&stDst,&stCscCtrl,bInstant);
    if(ret==HI_FAILURE)
    {
        printf("YUV Convert to RGB failed!n");
        return HI_FAILURE;
    }

    pImage = HI_MPI_SYS_Mmap(stDst.u32PhyAddr, nLengthImage/2*3);
    if(NULL == pImage)
    {
        msg_print( "HI_MPI_SYS_Mmap err!n");
        return NVD_FALSE;
    }

    ret = saveBMPFile((Byte*)pImage, nWidth, nHeight, "/mnt/rgb.dib");
    if(0 != ret)
    {
        printf( "saveBMPFile errorn");
        return;
    }
    printf("saveBMPFile done!n");

    //uninit();
}


 

最后

以上就是开心长颈鹿为你收集整理的YUV422转BGR888(海思3516平台)的全部内容,希望文章能够帮你解决YUV422转BGR888(海思3516平台)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(79)

评论列表共有 0 条评论

立即
投稿
返回
顶部