input rgb color space, can we set up sub-sampling when it was converted to yuv?

139 views
Skip to first unread message

Jerry

unread,
Jan 14, 2021, 8:00:03 AM1/14/21
to libjpeg-turbo User Discussion/Support
Hi all,

my version: libjpeg-turbo 2.0.3

If i read a rgb color space image into buffer.
Then use tjCompress2 to compress to JPEG.

I know it will be converted to yuv then compressed to JPEG, but what kind of yuv it is?
yuv444? yuv422? yuv420? or can i set the format somewhere?

Please tell me if you have any idea.
Thanks in advanced.

Jerry


DRC

unread,
Jan 14, 2021, 9:04:50 AM1/14/21
to libjpeg-t...@googlegroups.com
I can’t explain it any better than the API documentation already does.


On Jan 14, 2021, at 7:00 AM, Jerry <jerry...@gmail.com> wrote:

Hi all,
--
You received this message because you are subscribed to the Google Groups "libjpeg-turbo User Discussion/Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libjpeg-turbo-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/libjpeg-turbo-users/de689de0-e00b-4f8e-a020-626359bc89d5n%40googlegroups.com.

Jerry

unread,
Jan 14, 2021, 10:20:53 AM1/14/21
to libjpeg-turbo User Discussion/Support
Hi DRC,

Sorry i must be confused by myself... i 'm sorry for this simple mistake.

Actually i'm using libjpeg-turbo these days, and i found a difference result when i did the following things:
1. I have a yuv422 image, use tjCompressFromYUV and i got a JPEG image.
2. On the other hand, i converted this yuv422 image to rgb and use tjCompress2 to get a JPEG image.

After i compared the 2 jpeg images with the original yuv422 image, i found that the jpeg(input yuv422) is a little bit brighter than another one(input rgb).
Here is how i compare:
1. I save the original yuv422 image to BMP, then i compute this BMP and 2 JPEG images' histogram, and i found rgb input's histogram is almost like the BMP's.        But the yuv422 input's histogram is more "brighter" than the BMP's.
2. By my eyes, it's obvious that input yuv422 one is brighter than input rgb one.

Is there anything i missed? or is this just something like loss? (i don't really know JPEG theory), please give me some advice.
Thanks!!!

DRC 在 2021年1月14日 星期四下午10:04:50 [UTC+8] 的信中寫道:

DRC

unread,
Jan 14, 2021, 2:27:11 PM1/14/21
to libjpeg-t...@googlegroups.com
No, JPEG loss shouldn't affect average brightness. My first suspicion
would be how you are converting the YUV 4:2:2 image to RGB. Did you use
tjDecodeYUV() to perform that conversion? If not, which conversion
formulae did you use?

The TurboJPEG API allows you to separate the color conversion portion of
the JPEG pipeline. It should be the case (and you can confirm this by
running tjbench with and without the -yuv argument) that compressing an
RGB image with tjCompress2() produces mathematically identical results
to converting the same RGB image to YUV with tjEncodeYUV3() or
tjEncodeYUVPlanes() and then compressing the resulting YUV image with
tjCompressFromYUV(). On the decompression side, the same mathematical
equivalency also exists for tjDecompress2() and tjDecompressToYUV2() +
tjDecodeYUV()/tjDecodeYUVPlanes() if you are decompressing a grayscale
or 4:4:4 image. For 4:2:0 and 4:2:2 images, the same mathematical
equivalency exists if you are using fast/non-fancy upsampling (passing
-fastupsample to tjbench or setting TJFLAG_FASTUPSAMPLE in the flags.)
Fancy upsampling needs context rows, so that algorithm isn't supported
in tjDecodeYUV()/tjDecodeYUVPlanes().

On 1/14/21 9:20 AM, Jerry wrote:
> Hi DRC,
>
> Sorry i must be confused by myself... i 'm sorry for this simple mistake.
>
> Actually i'm using libjpeg-turbo these days, and i found a difference
> result when i did the following things:
> 1. I have a yuv422 image, use *tjCompressFromYUV* and i got a JPEG image.
> 2. On the other hand, i converted this yuv422 image to rgb and use
> *tjCompress2* to get a JPEG image.
>
> After i compared the 2 jpeg images with the original yuv422 image, i
> found that the jpeg(input yuv422) is a little bit *brighter* than
> another one(input rgb).
> Here is how i compare:
> 1. I save the original yuv422 image to BMP, then i compute this BMP and
> 2 JPEG images' histogram, and i found rgb input's histogram is almost
> like the BMP's.        But the yuv422 input's histogram is more
> "brighter" than the BMP's.
> 2. By my eyes, it's obvious that input yuv422 one is brighter than input
> rgb one.
>
> Is there anything i missed? or is this just something like loss? (i
> don't really know JPEG theory), please give me some advice.
> Thanks!!!
>
> DRC 在 2021年1月14日 星期四下午10:04:50 [UTC+8] 的信中寫道:
>
> I can’t explain it any better than the API documentation already does.
>
> https://cdn.rawgit.com/libjpeg-turbo/libjpeg-turbo/master/doc/html/group___turbo_j_p_e_g.html#gafbdce0112fd78fd38efae841443a9bcf
>
>> On Jan 14, 2021, at 7:00 AM, Jerry <jerry...@gmail.com> wrote:
>>
>> Hi all,
>>
>> my version: libjpeg-turbo 2.0.3
>>
>> If i read a rgb color space image into buffer.
>> Then use*tjCompress2 *to compress to JPEG.
>>
>> I know it will be converted to yuv then compressed to JPEG, but
>> what kind of yuv it is?
>> yuv444? yuv422? yuv420? or can i set the format somewhere?
>>
>> Please tell me if you have any idea.
>> Thanks in advanced.
>>
>> Jerry
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "libjpeg-turbo User Discussion/Support" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to libjpeg-turbo-u...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/libjpeg-turbo-users/de689de0-e00b-4f8e-a020-626359bc89d5n%40googlegroups.com
>> <https://groups.google.com/d/msgid/libjpeg-turbo-users/de689de0-e00b-4f8e-a020-626359bc89d5n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "libjpeg-turbo User Discussion/Support" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to libjpeg-turbo-u...@googlegroups.com
> <mailto:libjpeg-turbo-u...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/libjpeg-turbo-users/024aa6be-89d8-4a2a-8b06-21b5e36e24a6n%40googlegroups.com
> <https://groups.google.com/d/msgid/libjpeg-turbo-users/024aa6be-89d8-4a2a-8b06-21b5e36e24a6n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Shibe

unread,
May 16, 2021, 12:56:32 PM5/16/21
to libjpeg-turbo User Discussion/Support
Hi DRC,

Sorry for reply late, because of COVID-19, I wasn't able to look into this project.
I re-overlook our situation, for now we are not going to consider the rgb i mentioned before.(because we receive yuv422 data)
In our work, we will receive YUV422 data, then we use libjpeg-turbo to compress it to jpeg image.
And we found that the output image will become brighter. (from eyes and histogram)
We are now thinking that is it caused by difference between YUV & YCbCr problems?

Thanks.



DRC 在 2021年1月15日 星期五上午3:27:11 [UTC+8] 的信中寫道:

DRC

unread,
May 16, 2021, 1:07:35 PM5/16/21
to libjpeg-t...@googlegroups.com
The terms “YCbCr” and “YUV” are used interchangeably in libjpeg-turbo. Historically, the libjpeg API uses the term “YCbCr”, but the TurboJPEG API uses the term “YUV”. That’s because the video community tends to prefer “YUV”, and the TurboJPEG functions were developed to support video applications. Behind the scenes, however, the same computations are performed.

On May 16, 2021, at 11:56 AM, Shibe <jerry...@gmail.com> wrote:

Hi DRC,

DRC

unread,
May 16, 2021, 5:56:29 PM5/16/21
to libjpeg-t...@googlegroups.com

To elaborate, when you feed YUV (YCbCr) data directly into the libjpeg-turbo compressor using tjCompressFromYUV*() or jpeg_write_raw_data(), no color conversion is performed.  Thus, there is no opportunity for brightness to be altered by the compressor.  But if your YUV data is encoded using a different YUV conversion formula than the one that JPEG uses, then the decompressed RGB image will not appear as you expect.  If that is the case, then you need to decompress the JPEG image to YUV and perform the YUV-to-RGB conversion outside of libjpeg-turbo.

Reply all
Reply to author
Forward
0 new messages