Save JPEG without chroma subsampling

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Save JPEG without chroma subsampling

Post by Lunasole »

I've noticed that JPEGs saved with PB library having the same defect as many other regular jpeg libs and image viewers are producing -- noticeable loss of color saturation that affects bright colors. This makes them "dirty" and thus corrupting whole photo/image a lot regardless of quality setting.

That's all result of subsampling applied. https://en.wikipedia.org/wiki/Chroma_subsampling

Here is an image showing the difference between nicely-done JPEG saving lib and one using default noob way:
Image

The typical and easiest solution is to disable chroma subsampling by setting it's block size to 1x1 pixel, so it does bare calculations and not affects image pixels.
There is big sense to do this, as it surely increases size of JPEG files slightly, but they anyway are taking much less space than PNG or any true lossless format. Thus cool quality/size coefficient is provided to store all your precious photos.

I suggest to add such fix to PB library and some kind of flag to use it optionally when saving files.

PS. There is wrong text on image, used Photoshop JPEG setting was "11 of 12", which is much better than 80 (no matter)
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Save JPEG without chroma subsampling

Post by wilbert »

For my app GrayTone ( http://www.purebasic.fr/english/viewtop ... 14&t=65314 ) I used libjpeg-turbo instead of the encoder / decoder that comes with PureBasic.
It gives you better control of the output and is faster compared to the encoder / decoder that comes with PureBasic.
I also chose to write the images it outputs without chroma subsampling to have better quality.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Save JPEG without chroma subsampling

Post by Lunasole »

wilbert wrote:For my app GrayTone ( http://www.purebasic.fr/english/viewtop ... 14&t=65314 ) I used libjpeg-turbo instead of the encoder / decoder that comes with PureBasic.
It gives you better control of the output and is faster compared to the encoder / decoder that comes with PureBasic.
I also chose to write the images it outputs without chroma subsampling to have better quality.
That library looks very nice, I should add it to list of my libs, thanks. Does it support output without ss or you added this manually by changing sources?
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Save JPEG without chroma subsampling

Post by wilbert »

Lunasole wrote:Does it support output without ss or you added this manually by changing sources?
It supports it manually.

I'm using version 1.4.2 .
The static libs (which I prefer) worked out of the box on Linux and OSX.
The dll version for Windows also should work out of the box.
Keya was able to work out the problems with the static version on Windows.
The 'fixed' static build is confirmed to work on Windows XP to Windows 10.

It has two api sets. I chose to use the TurboJPEG 1.4 api which the the easiest one to use.
https://cdn.rawgit.com/libjpeg-turbo/li ... p_e_g.html
The TJSAMP_444 flag gives you output without chroma subsampling.
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply