开启辅助访问
 找回密码
 注册帐号

扫一扫,访问微社区

首页   >   博客   >   solk_yt

hi888 YUV422转BGR888(海思3516平台)

2017-1-12 18:14
0 个评论 | 阅读 16 | 收藏 | 举报

hi888

#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 error\n"); return; } printf("saveBMPFile done!\n"); //uninit(); }
 

转自:点击查看

0 0

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册帐号

个人分类

标签

阅读排行

评论排行

推荐博客

最新博客

返回顶部