Failure to save YUV420 data as a bitmap

Failure to save YUV420 data as a bitmap

stsybikov的头像

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

15 帖子 / 0 new
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项
stsybikov的头像

I attached the file with problem data.

附件: 

附件尺寸
下载 incorrect.bmp5.93 MB
stsybikov的头像

The attached file has been saved from the same YUV420 using win32 BITMAPINFO & BITMAPFILEHEADER

附件: 

附件尺寸
下载 correct.bmp5.93 MB
Ying H (Intel)的头像

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

stsybikov的头像

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

stsybikov的头像

Ying,
Sorry. Not RGB -> BGR
Sergey

Sergey Khlystov (Intel)的头像

Hi Sergey,

Could you try:


src.Color(IC_BGR);

src.Sampling(IS_444);


?
Regards,
Sergey

Regards, Sergey
stsybikov的头像

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

Sergey Khlystov (Intel)的头像

Sergey,

In the line "src.Attach..." specify "step" as the last parameter, instead of 0. It helped in my test example.

Regards,
Sergey

Regards, Sergey
stsybikov的头像

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

Sergey Khlystov (Intel)的头像
Best Reply

Sergey,

The last parameter in CIppImage::Attach function


  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);


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

Regards, Sergey
stsybikov的头像

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

stsybikov的头像

This file has been saved using Intel API

附件: 

附件尺寸
下载 intel.bmp5.93 MB
stsybikov的头像

This one using win32

附件: 

附件尺寸
下载 win32.bmp5.93 MB
stsybikov的头像

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

登陆并发表评论。