turbojpeg's tjDecompressToYUV2 data format

658 views Asked by At

I would like to convert a JPEG image into Y'UV420p using turbo jpeg. I think that this uses some 2x2 blocks with there being twice the information in the Y' that there is in each of the U and V components but I haven't been able to find an example that does this.

How do I extract these individual coponents from tjDecompressToYUV2 and what is the format of the buffer that is allocated for say an image whose dimensions are a multiple of a power of 2?

Say I have an image that is 1024 wide by 512 pixels high. How would I extract each Y' U and V value from the following code:

constexpr auto height = 512u;
constexpr auto width = 1024u;  
unsigned char buffer[height * width * 3 / 2];
...
tjDecompressToYUV2(jpegDecompressor, jpegImage, jpegSize, buffer, width, 2, height, TJFLAG_FASTDCT);
...

ie. How are the components extracted from buffer?

1

There are 1 answers

0
AudioBubble On

Try using the tjDecompressToYUV function which gives you the 3 colorspaces on 3 different output buffers. The Y buffer should contain one byte (eight bit value) for the Y component. I have never used the chroma components so I cannot tell you how they are stored.

What is it that you are trying to do, as there might be another way to solve this problem?