-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use RGBX rawmode for RGB JPEG images #1989
Use RGBX rawmode for RGB JPEG images #1989
Conversation
Don't understand why tiff loading fails in Travis environment. Investigating. |
Well, it's a jpeg encoded tiff, so at least there's some basis for why it's failing. This is im.tile from that image: |
@homm 3.5.0 then? |
Sure |
4b79592
to
a926d2e
Compare
As always, weird bug. I don't have it on Ubuntu 14.04, so I installed Ubuntu 12.04. stock libjpeg-turbo 1.1.90, no modifications: no problems It is absolutely unclear how |
After night debugging I can say what is going on. First, libjpeg-turbo 1.5.1 fails due to compilation issue, not relevant to this case. The real problem was that the TIFF file is in RGB colorspace, while all other JPEGs for tests are YCbCr (or maybe CMYK). On Ubuntu 12.04. LTS the default libjpeg-turbo version is 1.1.90. And it doesn't support Starting from 1.2.1 libjpeg-turbo supports all So before implementing this small feature, we need to do the following:
As for solution: in theory, we can do not switch to |
Unfortunately, this not so easy to detect current libjpeg-turbo version: libjpeg-turbo/libjpeg-turbo#166 |
Resolved the libjpeg-turbo version issue. |
@@ -189,6 +218,10 @@ ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes) | |||
context->cinfo.out_color_space = JCS_GRAYSCALE; | |||
else if (strcmp(context->rawmode, "RGB") == 0) | |||
context->cinfo.out_color_space = JCS_RGB; | |||
#ifdef JCS_EXTENSIONS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This simple check is enough because anything else is checked when rawmode
is set to RGBX
.
int use_jcs_extensions = 0; | ||
#ifdef JCS_EXTENSIONS | ||
#if defined(LIBJPEG_TURBO_VERSION_NUMBER) | ||
#if LIBJPEG_TURBO_VERSION_NUMBER >= 1002010 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LIBJPEG_TURBO_VERSION_NUMBER
is defined starting from 1.5.0
(1005000). Compare it one more time to be sure.
#endif | ||
#else | ||
if (libjpeg_turbo_version) { | ||
use_jcs_extensions = strcmp(libjpeg_turbo_version, "1.2.1") >= 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this literally means:
use_jcs_extensions = (libjpeg_turbo_version >= "1.2.1")
@wiredfool Could you review this. I've added explanations for all significant lines. |
How are you feeling about the three bullet points above? (#1989 (comment))
I'm not sure about the status of the other bullets. (edit: do you want to rebase to pull in the .travis.yml that runs against Fedora?) |
Not for this release, unfortunately. The most important thing is "Add tests for all JPEG input colorspaces" but as I can see, we had |
Both Fedoras passed |
@wiredfool I meant that I'm not ready to implement bullets, «Propagate errors from libjpeg», for example. As of this PR, I think it is ready and relatively safe for all systems. |
Ok, fair enough. |
libjpeg-turbo supports different output formats.
We are choosing Pillow's native format (3 color bytes + 1 padding) to avoid extra conversion in Unpack.c.
This speeds up JPEG loading by 19% and saving by 14%.