Request: add jpeg parsing directly to YCbCr (without color conversion)
Closed this issue · 5 comments
When loading a YCbCr jpeg image (a.k.a. YUV), it would be really nice to have a way to get the Y and chroma components without the double color conversion (YCbCr -> RGB -> YCbCr).
On images with chroma subsampling (e.g. almost all jpegs in existence) the double color conversion degrades quality. I know it's not visually significant, but I'm doing image analysis, and it's worsening the jpeg artifacts.
P.S. you can take a look at libjpeg-turbo (https://github.com/libjpeg-turbo/libjpeg-turbo) - they have functions for loading directly to YCbCr - both into a single channel and to multiple buffers.
thanks.
If someone has a piece of code that does this, and compatible with the libjpeg and libjpeg-turbo libraries, then I'll be glad to add this option to the JPEG loader.
I have a wrapper around libjpeg-turbo for doing this. To incorporate it into CImg, don't we need CImg to include libjpeg-turbo? Isn't that a problem?
The jpeg loader of CImg works both for libjpeg and lijpeg-turbo and must be probably kept as generic as possible. We cannot break the compatibility with a library just to add a feature that most people probably don't care about.
But please show your piece of code using libjpeg-turbo. If this is simple enough to add a simple 'do_not_convert_YCbCr' boolean argument to the CImg::load_jpeg() function, then it's probably fine to add it.
take a look at:
https://gist.github.com/mousomer/97c43e8b53dd8733c4a8
C++ string IO isn't critical. It was originally inside an Image class I wrote. If I can help incorporate it into CImg that would be nice.
Do you really wrap libjpeg-turbo?
Anyway, it sees as if the main thing would be using jpeg_read_raw_data() instead of jpeg_read_scanlines().
from libjpeg.h:
/* Replaces jpeg_read_scanlines when reading raw downsampled data. */
EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo, JSAMPIMAGE data, JDIMENSION max_lines));