Fill bitmap with FFMPEG to RGB

Source: Internet
Author: User
Tags bmp image
Sws_scale (img_convert_ctx,
Pvideoframe [nchannel]-> data,
Pvideoframe [nchannel]-> linesize,
0,
Pcodecontext [nchannel]-> height,
Prgbframe-> data,
Prgbframe-> linesize );

Createbmp (szfilename, prgbframe-> data [0],
Pcodecontext [nchannel]-> width,
Pcodecontext [nchannel]-> height,
24)

Bool createbmp (char * filename, uint8_t * prgbbuffer, int width, int height, int bpp)
{
Bitmapfileheader bmpheader;
Bitmapinfo BMP Info;
File * fp = NULL;

Fp = fopen (filename, "WB ");
If (FP = NULL)
{
Return false;
}

Bmpheader. bftype = ('M' <8) | 'B ';
Bmpheader. bfreserved1 = 0;
Bmpheader. bfreserved2 = 0;
Bmpheader. bfoffbits = sizeof (bitmapfileheader) + sizeof (bitmapinfoheader );
Bmpheader. bfsize = bmpheader. bfoffbits + width * height * BPP/8;

BMP info. bmiheader. bisize = sizeof (bitmapinfoheader );
BMP info. bmiheader. biwidth = width;
BMP info. bmiheader. biheight = height;
BMP info. bmiheader. biplanes = 1;
BMP info. bmiheader. bibitcount = BPP;
BMP info. bmiheader. bicompression = bi_rgb;
BMP info. bmiheader. bisizeimage = 0;
BMP info. bmiheader. bixpelspermeter = 100;
Bminfo. bmiheader. biypelspermeter = 100;
BMP info. bmiheader. biclrused = 0;
BMP info. bmiheader. biclrimportant = 0;

Fwrite (& bmpheader, sizeof (bitmapfileheader), 1, FP );
Fwrite (& BMP info. bmiheader, sizeof (bitmapinfoheader), 1, FP );
Fwrite (prgbbuffer, width * height * BPP/8, 1, FP );
Fclose (FP );
Fp = NULL;

Return true;
}

1st answers to this question:
BMP info. bmiheader. biheight =-height;
2nd answers to this question:
The upside down is right, while the BMP image data goes from bottom to top.

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.