Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Failure to save YUV420 data as a bitmap

stsybikov
Beginner
1,399 Views

Hi Intel Gurus,

 

I am having trouble to save YUV420 data as a bitmap.

Let’s say I have a pointer to the data – pData

My code:

Const  Ipp8u* (pYUV[3]) = {0,0,0};

pYUV[0] = pData;

pYUV[1] = pYUV[0] + 1920*1080;

pYUV[2] = pYUV[1] + 1920*1080/4

int YUVStep[3] = {1920,960,960};

Int step;

IppiSize roi = {1920,1080};

Ipp8u* pBuf = ippiMalloc_8u_C3(1920,1080, &step);

ippiYUV420ToBGR_8u_P3C3R(pYUV, YUVStep, pBuf, step, roi};

 

CIppImage src(1920,1080,3,8,0);

src.Attach(1920,1080,3,8, pBuf, 0);

src.Color(IC_BGR);

src.Sampling(IS_411);

src.ComponentOrder(0);

src.Format(IF_UNSIGNED);

 

// No I am trying to use function from picnic bmp sample

PARAMS_BITMAP params;

err = SaveImageBMP(src, params, fileout);

 

File has been saved but the result is three identical overlapped pictures. Color looks OK.

 

When I tried to save the same data using win32 BITMAPINFO & BITMAPFILEHEADER the content is fine.

 

I tried to modify SaveImageBMP  replacing geometry.SetEnumSampling(S444) by geometry.SetEnumSampling(S411) but in this caseencoder.AttachImage(imageCn) fails

 

Any suggestions?

 

Thank you in advance

Sergey Tsybikov

Smith&Nephew Endoscopy

0 Kudos
1 Solution
Sergey_K_Intel
Employee
1,399 Views
Sergey, The last parameter in CIppImage::Attach function [cpp] int Attach(IppiSize roi, int nchannels, int precision, void* data, int step); int Attach(int width, int height, int nchannels, int precision, void* data, int step); [/cpp] is step, i.e. distance in bytes between beginnings of image lines. By default, when it's 0, BMP functions use width*nchannels formula. But in your case the image array is allocated by ippiMalloc_8u_C3 function and step=width*nchannels+alignment. This is why this distance is returned by ippiMalloc_8u_C3 function by &step parameter and must be used in other IPP functions. So, try to specify not 0, not 1920 and not 1920*3, but "step" )) Regards, Sergey

View solution in original post

0 Kudos
14 Replies
stsybikov
Beginner
1,399 Views
I attached the file with problem data.
0 Kudos
stsybikov
Beginner
1,399 Views
The attached file has been saved from the same YUV420 using win32 BITMAPINFO & BITMAPFILEHEADER
0 Kudos
Ying_H_Intel
Employee
1,399 Views
Hi Sergey, I haven't try , but I saw you have converted the YUV format to BGR format, thus sampling format is not IS_411, why you have src.Sampling(IS_411) ? Regards, Ying Just
0 Kudos
stsybikov
Beginner
1,399 Views
Hi Ying, I tried to use without sampling and every element from IM_SAMPLING structure. It's the same result for final image. What should I define for decoder to undestand that the source is RGB? Thank you in advance. Sergey Tsybikov Smith&Nephew Endoscopy
0 Kudos
stsybikov
Beginner
1,399 Views
Ying, Sorry. Not RGB -> BGR Sergey
0 Kudos
Sergey_K_Intel
Employee
1,399 Views
Hi Sergey, Could you try: [cpp] src.Color(IC_BGR); src.Sampling(IS_444); [/cpp] ? Regards, Sergey
0 Kudos
stsybikov
Beginner
1,399 Views
Hi Sergey, Thank you for suggestion. I tried code before and this time. No luck. Bitmap content is the same as file "incorrect.bmp" whatI uploaded previously. Sergey Tsybikov Smith&Nephew Endoscopy
0 Kudos
Sergey_K_Intel
Employee
1,399 Views
Sergey, In the line "src.Attach..." specify "step" as the last parameter, instead of 0. It helped in my test example. Regards, Sergey
0 Kudos
stsybikov
Beginner
1,399 Views
Hi Sergey, What do mean as last parameter? If I use 1920 I have the same bitmap content as when I use 0. Using the other values for this parameter completly massed the content. Thank you. Sergey Tsybikov Smith&Nephew Endoscopy
0 Kudos
Sergey_K_Intel
Employee
1,400 Views
Sergey, The last parameter in CIppImage::Attach function [cpp] int Attach(IppiSize roi, int nchannels, int precision, void* data, int step); int Attach(int width, int height, int nchannels, int precision, void* data, int step); [/cpp] is step, i.e. distance in bytes between beginnings of image lines. By default, when it's 0, BMP functions use width*nchannels formula. But in your case the image array is allocated by ippiMalloc_8u_C3 function and step=width*nchannels+alignment. This is why this distance is returned by ippiMalloc_8u_C3 function by &step parameter and must be used in other IPP functions. So, try to specify not 0, not 1920 and not 1920*3, but "step" )) Regards, Sergey
0 Kudos
stsybikov
Beginner
1,399 Views
Thank you, Sergey: It works finally. Right now my concern is that the color is off a little bit. It looks that the brightness has been changed. Could you tell me what parameter is responsible for the brightness? I attached the bitmaps that I saved using Intel API (intel.bmp) and win32 BITMAPINFO & BITMAPFILEHEADER (win32.bmp) where you could see the difference. The source data is the same for both files. Any idea? Regards, Sergey Tsybikov
0 Kudos
stsybikov
Beginner
1,399 Views
This file has been saved using Intel API
0 Kudos
stsybikov
Beginner
1,399 Views
This one using win32
0 Kudos
stsybikov
Beginner
1,399 Views
Hi Sergey: I found the solution. I replaced ippiYUV420ToBGR_8u_P3C3R by ippiYCbCr420ToBGR_8u_P3C3R and I received a color spectrum identical to the image saved using win32 processing. This data is also works for jpeg image as well. Thank you again for your help. Sergey Tsybikov Smith&Nephew Endoscopy
0 Kudos
Reply