YUV422 to BGR888 (haisi 3516 platform)

Source: Internet
Author: User

[Cpp] # 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;} BMP infoheader; # pragma pack () int saveBM PFile (unsigned char * src, int width, int height, const char * name) {BMPHeader hdr; BMP infoheader 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 (BMP infoheader); 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. rese Rved2 = 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 * p1_src = NULL; HI_VOID * p1_dst = 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 IveHandl E; 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, & p1_src, "User", HI_NULL, pstSrc-> u32Height * pstSrc-> stSrcMem. u32Stride * 2); // memset (p1_src, 1, pstSrc-> u32Height * pstSrc-> stSrcMem. u32Stride); ret = HI_MPI_SYS_MmzAllo C_Cached (& stDst. u32PhyAddr, & p1_dst, "User", HI_NULL, stSrc. u32Height * stDst. u32Stride); // s32Ret = HI_MPI_IVE_DMA (& IveHandle, & stSrc, & stDst, bInstant); // HI_MPI_SYS_MmzFree (stSrc. stSrcMem. u32PhyAddr, p1_src); HI_MPI_SYS_MmzFree (stDst. u32PhyAddr, p1_dst); 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 (" assumerr! \ N "); return NVD_FALSE;} www.2cto.com ret = saveBMPFile (Byte *) pImage, nWidth, nHeight,"/mnt/rgb. dib "); if (0! = Ret) {printf ("saveBMPFile error \ n"); return;} printf ("saveBMPFile done! \ N "); // uninit ();}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.