Community
cancel
Showing results for 
Search instead for 
Did you mean: 
alekseyd
Beginner
63 Views

UIC::JPEGDecoder -> Convert JPEG to IYUV or YUY2

Hi,

Currently I am trying to make JPEGDecoder convert JPEG image to some YUV format like YUY2 (4:2:2, packed) or IYUV (4:2:0, planar). UIC documentation contains the example related to JPEG decoding, but as far as I have understood it shows how to decompress JPEG image in usual bitmap (4:4:4, RGB). All my attempts to change this example so that YUY2 or IYUV images are generated have failed so far. Is it possible at all to get output image in those formats? What I need to do for that? Unfortunately there are no other examples or clear documentation that would be useful for me.
0 Kudos
5 Replies
scandinaf
Beginner
63 Views

Hi,

I have the same problem. Have you found the answer?
scandinaf
Beginner
63 Views

I use the following code snippet from UIC documentation:

[cpp]int i;
CStdFileInput fi;
JPEGDecoder jpegdec;
ExcStatus status;

if( !BaseStream::IsOk(fi.Open(argv[1])) )
return 1;
status = jpegdec.Init();

if(ExcStatusOk != status)
return 1;

status = jpegdec.AttachStream(fi);

if(ExcStatusOk != status)
return 1;

ImageColorSpec colorSpec;
ImageSamplingGeometry geometry;

status = jpegdec.ReadHeader(colorSpec,geometry);

if(ExcStatusOk != status)
return 1;

Image imageCn;
ImageDataOrder dataOrder;

int nOfComponents = geometry.NOfComponents();

if(colorSpec.DataRange()->BitDepth() + 1 <= 8)
dataOrder.SetDataType(T8u);
else
dataOrder.SetDataType(T16u);

dataOrder.ReAlloc(Interleaved, nOfComponents);
dataOrder.PixelStep()[0] = nOfComponents;
dataOrder.LineStep() [0] = AlignStep(geometry.RefGridRect().Width() * nOfComponents);

geometry.SetEnumSampling(S444);
imageCn.Buffer().ReAlloc(dataOrder, geometry);
imageCn.ColorSpec().ReAlloc(nOfComponents);
imageCn.ColorSpec().SetColorSpecMethod(Enumerated);
imageCn.ColorSpec().SetComponentToColorMap(Direct);

for(i = 0; i < nOfComponents; i++)
{
if(colorSpec.DataRange()->BitDepth() + 1 <= 8)
imageCn.ColorSpec().DataRange().SetAsRange8u(255);
else
imageCn.ColorSpec().DataRange().SetAsRange16u(1 <<
colorSpec.DataRange()->BitDepth());
}

imageCn.ColorSpec().SetEnumColorSpace(RGB);
status = jpegdec.SetParams(imageCn.ColorSpec(),imageCn.Buffer().BufferFormat().SamplingGeometry());

if(ExcStatusOk != status)
return 1;

status = jpegdec.ReadData(imageCn.Buffer().DataPtr(),dataOrder);

if(ExcStatusOk != status)
return 1;[/cpp]

This example converts my JPEG image (4:1:1, YCbCr, planar) in RGB 4:4:4. However I need YUY2 (or IYUV also possible). I investigated JPEG decoder APIs and noticed that color conversion is performed only when both source and destination images have YCbCr color scheme and 422 subsampling. Maybe this is a reason why I cannot convert ny JPEG image with subsampling 411 in some YUV format.

Could somebody help me? I added my input picture to the attachments.
Vladimir_Dudnik
Employee
63 Views

Hello,

you may be interested to review a similar thread discussed on this forum a couple month ago..
We have provided a simple sample how to get YUV data from UIC JPEG decoder (or how to apply YUV data to UIC JPEG encoder)

Regards,
Vladimir
scandinaf
Beginner
63 Views

Hi,

Thank you. This thread contains a reference to the example that shows how to convert JPEG image (YCbCr, 422) to YUY2 (YCbCr, 422) and vice versa. But in my case I have JPEG images with YCbCr color specification and 411 subsampling. These images come to me from different IP cameras. I found out that currently JPEGDecoder cannot convert YCbCr, 411 to YCbCr, 422. However I tried to add my piece of code in CJPEGDecoder::ColorConvert method in order to solve this problem, i.e. I used ippiYCbCr411ToYCbCr422_8u_P3C2R function for conversion. My YUV tools showed that output image was correct YUY2 image. I was able to see all objects at the picture. However, something wrong was with decoded image: ~5/6 of image was in gray scale, whereas ~1/6 of image (right-bottom corner) contained blurred color spots. It seems that it was not enough just to add appropriate function. Thus, I had to find any other way to solve my problem. Then I found out the solution: firstly I convert JPEG image (YCbCr, 411) to RGB 444; then I convert RGB 444 to YUY2 422 with help of ippiRGBToYCbCr422_8u_C3C2R function. Of course, it affects performance of JPEG decompression. But it seems that there is no any opportunity to make JPEGDecoder work properly in my case.
Naveen_G_Intel
Employee
63 Views

Hi,

There is no direct conversion function, this is the way to convert JPEG image to YUY2 422.

STEP 1: JPEG image (YCbCr, 411) to RGB 444;

STEP 2: convert RGB 444 to YUY2 422

Detail description about color conversion function in the reference manual.

Regards,

Naveen Gv