Information: Convert to 256 color space not possible with JPG

XnConvert Multi Platform - Windows, MacOSX, Linux

Moderators: XnTriq, helmut, xnview

JDB
Posts: 3
Joined: Fri Jan 10, 2020 12:56 pm

Information: Convert to 256 color space not possible with JPG

Post by JDB »

Hi,

I think this is more for everyone's information. Perhaps most readers of this forum already know this, but for those who don't --

I was confused when converting some TIFF images to 256 color JPG (ie 8-bit depth). I did not realize that this is impossible, because JPG only supports a 24-bit (16M) color space. However, XnConvert allows one to select 256 colors when converting to JPG, which led to my confusion. The log file shows an error message however: "WARNING: the picture will be converted to RGB with 8bits per component". This is a clue, but not much explanation. Note that the term "component" means R, G, and B values. R=8, G=8, B=8 ==> total of 24 bit, 16+ million colors possible.

CAVEAT - This does not apply to grayscale. JPG DOES support 8-bit grayscale. I am only talking about color.

What seems to happen is: XnConvert will resample the input image and create an internal bitmap with 256 colors, but when this is saved as JPG, the output routines utilize the full 24-bit (16M) color space and generate RGB values that are 8 bits each. Obviously the software will not use the entire available color space given only 256 starting colors, but the number of colors will grow somewhat when the file is saved.

My "256 color" JPG output actually wound up with 1,950 unique colors after it was saved. Whereas, saving as PNG results in exactly 256 colors, because PNG supports an indexed 256 color palette as opposed to RGB values.

Perhaps the only reason one might want to save a JPG file using less than 24-bit (16M) color would be to improve compression for lower quality images. However, the effect is minimal. Otherwise, just save JPG as 24-bit color. If you need a fixed number of colors, save as PNG or TIFF.

-JDB
User avatar
xnview
Author of XnView
Posts: 44922
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: Information: Convert to 256 color space not possible with JPG

Post by xnview »

JPEG is lossless format, so you have not exactly the same pixel as original
Pierre.
JDB
Posts: 3
Joined: Fri Jan 10, 2020 12:56 pm

Re: Information: Convert to 256 color space not possible with JPG

Post by JDB »

xnview wrote: Mon Jan 13, 2020 8:07 am JPEG is lossless format, so you have not exactly the same pixel as original
Thank you Pierre. I assume that you meant "lossy" (not lossless). I still know what you meant. I guess that my long-winded post was just another way of saying that, using many many more words. :-)

:)
User avatar
xnview
Author of XnView
Posts: 44922
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: Information: Convert to 256 color space not possible with JPG

Post by xnview »

yep sorry lossy not lossless :)
Pierre.