cjpeg -rgb compatibility

62 views
Skip to first unread message

Zsolt Ero

unread,
Feb 26, 2021, 10:41:17 PM2/26/21
to libjpeg-turbo User Discussion/Support
Hi,

I'm trying to encode an image with some very fine line graphics, and it turns out that 50-60 quality range totally distorts the colors. Going up till quality 80 helps, but for HiDPI images for the web I never do that, the files are just very big. Also, I feel that even quality 80 changes the colors slightly.

I've found cjpeg's -rgb option and it seems to save the colors perfectly. Even using some low quality, like 30 preserves the colors (rgb's 30 is like a normal 80 in file size).

Can you tell me if I'm safe in using -rgb for web browsers?

Also, is there any better way to solve my issue, or I should just use -rgb?

Regards,
Zsolt

DRC

unread,
Feb 27, 2021, 11:27:03 AM2/27/21
to libjpeg-t...@googlegroups.com
There are no compatibility concerns with using the RGB JPEG colorspace, but in general, if your goal is color fidelity, you will get better compression and approximately the same color fidelity by using the YCbCr JPEG colorspace with 4:4:4 chroma subsampling (AKA no chroma subsampling.) The default tables are designed to compress well with YCbCr, so using the RGB colorspace always produces a larger file than 4:4:4. The default subsampling level in the libjpeg API is 4:2:0, which is probably why you observe that YCbCr has much lower color fidelity than RGB. Disabling subsampling should make both colorspaces produce approximately the same fidelity (YCbCr has a tiny, imperceptible amount of roundoff error.)

On Feb 26, 2021, at 9:41 PM, Zsolt Ero <zsol...@gmail.com> wrote:

Hi,
--
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/098e8390-3345-4bd8-ade3-ef948943b5een%40googlegroups.com.

Zsolt Ero

unread,
Feb 27, 2021, 4:47:00 PM2/27/21
to libjpeg-t...@googlegroups.com
Thanks. 

2 questions: 
  1. I've read somewhere that for quality >= 80 cjpeg automatically selects 4:4:4, is that right?
  2. How can I manually select 4:4:4 in cjpeg? Is it just "-sample 1x1" or I need something else?

Regards,
Zsolt



You received this message because you are subscribed to a topic in the Google Groups "libjpeg-turbo User Discussion/Support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/libjpeg-turbo-users/O-BK_pdwqmw/unsubscribe.
To unsubscribe from this group and all its topics, 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/DEBF5897-15C8-4D78-AFE8-02D7DA9B6311%40virtualgl.org.

DRC

unread,
Feb 28, 2021, 12:04:05 PM2/28/21
to libjpeg-t...@googlegroups.com
No, cjpeg does not automatically select a different subsampling level based on quality. It will use 4:2:0 unless you specify otherwise. Passing -sample 1,1 is the correct way to enable 4:4:4.

On Feb 27, 2021, at 3:47 PM, Zsolt Ero <zsol...@gmail.com> wrote:


Reply all
Reply to author
Forward
0 new messages