Skip to content
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

vips_colourspace: no known route between 'cmyk' and 'srgb' #99

Closed
jeromegv opened this issue Oct 5, 2014 · 16 comments
Closed

vips_colourspace: no known route between 'cmyk' and 'srgb' #99

jeromegv opened this issue Oct 5, 2014 · 16 comments
Labels

Comments

@jeromegv
Copy link

jeromegv commented Oct 5, 2014

Hi

I'm trying to resize an image with sharp and I get this error:
vips_colourspace: no known route between 'cmyk' and 'srgb'
vips_image_pio_input: no image data

I'm using vips: stable 7.40.10 (installed with homebrew on mac)

The image is here:
https://infinitely-production.s3.amazonaws.com/uploads/assets/attachment/5187ae04f3317f2f1f00164a/Jacinto_Lirio_kwaderno.jpg

Here's the full metadata of the image

identify -verbose Jacinto_Lirio_kwaderno.jpg

Image: Jacinto_Lirio_kwaderno.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 4961x3508+0+0
Resolution: 300x300
Print size: 16.5367x11.6933
Units: PixelsPerInch
Type: ColorSeparation
Endianess: Undefined
Colorspace: CMYK
Depth: 8-bit
Channel depth:
cyan: 8-bit
magenta: 8-bit
yellow: 8-bit
black: 8-bit
Channel statistics:
Pixels: 17403188
Cyan:
min: 0 (0)
max: 100 (0.392157)
mean: 3.0409 (0.0119251)
standard deviation: 16.4575 (0.0645393)
kurtosis: 25.6952
skewness: 5.25657
Magenta:
min: 0 (0)
max: 135 (0.529412)
mean: 4.28151 (0.0167902)
standard deviation: 23.1797 (0.0909008)
kurtosis: 25.6952
skewness: 5.25664
Yellow:
min: 0 (0)
max: 255 (1)
mean: 8.29823 (0.0325421)
standard deviation: 44.9226 (0.176167)
kurtosis: 25.6945
skewness: 5.25658
Black:
min: 0 (0)
max: 49 (0.192157)
mean: 1.50316 (0.00589474)
standard deviation: 8.13645 (0.0319076)
kurtosis: 25.6944
skewness: 5.2565
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 4.28095 (0.016788)
standard deviation: 26.8905 (0.105453)
kurtosis: 61.5876
skewness: 7.59952
Total ink density: 209.02%
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: cmyk(255,255,255,0)
Border color: cmyk(223,223,223,0)
Matte color: cmyk(189,189,189,0)
Transparent color: cmyk(0,0,0,0)
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 4961x3508+0+0
Dispose: Undefined
Iterations: 0
Compression: JPEG
Quality: 99
Orientation: Undefined
Properties:
date:create: 2014-10-04T12:55:45-04:00
date:modify: 2013-05-06T09:20:13-04:00
jpeg:colorspace: 4
jpeg:sampling-factor: 1x1,1x1,1x1,1x1
signature: e2bee6d037910f0b23db5881471ba9e735bfa6e1ac26fad8a6eda20a1b277ed2
Profiles:
Profile-8bim: 28 bytes
Profile-icc: 557168 bytes
Artifacts:
filename: Jacinto_Lirio_kwaderno.jpg
verbose: true
Tainted: False
Filesize: 2.595MB
Number pixels: 17.4M
Pixels per second: 47.04MB
User time: 0.370u
Elapsed time: 0:01.370
Version: ImageMagick 6.8.9-7 Q16 x86_64 2014-08-31 http://www.imagemagick.org

I've seen a similar bug to that on libvips tracker, but it's apparently already fixed (and it was affecting vipsthumbnail which I don't think is what we use here)
https://github.com/jcupitt/libvips/issues/152#issuecomment-57929979

@lovell lovell added the bug label Oct 5, 2014
@lovell
Copy link
Owner

lovell commented Oct 5, 2014

Good spot, definitely a bug, thanks for reporting.

This module borrows extensively from vipsthumbnail - I need to apply a similar fix - leave it with me.

@lovell
Copy link
Owner

lovell commented Oct 6, 2014

Hi @jeromegv, are you able to check this problem is fixed for you when using the work-in-progress alpha branch:

npm install lovell/sharp#alpha

@jeromegv
Copy link
Author

jeromegv commented Oct 6, 2014

Hi @lovell , thanks for the quick answer.

So yes, it is now resizing.
However, I'm using background white as an option and the background is yellow instead of white. So I'm not sure if it's an issue because of this fix or if it's just generic to all background code

Here's what I used
sharp(filePath).resize(354,354).max().quality(90).background('white').embed().progressive()

@lovell
Copy link
Owner

lovell commented Oct 7, 2014

Thank you for checking this. alpha by name...

This yellow problem you're seeing is very likely to be related to the new background method clashing with an image in CMYK colour space. I need to ensure the conversion to non-linear sRGB occurs before the background is applied.

@lovell
Copy link
Owner

lovell commented Oct 7, 2014

I've moved the sRGB colour space conversion, if required, to occur sooner. I've added a test for this - are you able to retest too?

I also noticed my original fix for this had negative performance implications so it's a good thing you spotted this!

@jeromegv
Copy link
Author

jeromegv commented Oct 7, 2014

I confirm, that worked! No more yellow and the resize happens, seems fixed! Thanks a lot again

@lovell
Copy link
Owner

lovell commented Oct 7, 2014

Brilliant, thanks for verifying this works Jérôme. The fix will be included in the forthcoming v0.7.0 release.

@lovell lovell closed this as completed Oct 7, 2014
@bradisbell
Copy link

I still have this issue on v0.7.1. However, I am still using libvips 7.40.2. @lovell Does your fix require an update to libvips beyond my version as well? Thanks again for all of your assistance!

@lovell
Copy link
Owner

lovell commented Nov 5, 2014

@bradisbell The fix was to this module so should work with libvips 7.40.2. Are you able to provide an example image that generates this error?

@bradisbell
Copy link

DropBox link in case GitHub decides to do something to the image: https://www.dropbox.com/s/026tppp744dmjbk/raw%20(7).jpg?dl=1

raw 7

$ identify -verbose raw.jpg
Image: raw.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 546x427+0+0
  Resolution: 150x150
  Print size: 3.64x2.84667
  Units: PixelsPerInch
  Type: ColorSeparation
  Endianess: Undefined
  Colorspace: CMYK
  Depth: 8-bit
  Channel depth:
    cyan: 8-bit
    magenta: 8-bit
    yellow: 8-bit
    black: 8-bit
  Channel statistics:
    Cyan:
      min: 0 (0)
      max: 229 (0.898039)
      mean: 82.2191 (0.322428)
      standard deviation: 32.677 (0.128145)
      kurtosis: 0.709972
      skewness: 0.0176837
    Magenta:
      min: 0 (0)
      max: 222 (0.870588)
      mean: 84.0311 (0.329534)
      standard deviation: 38.7435 (0.151935)
      kurtosis: -0.44617
      skewness: -0.143854
    Yellow:
      min: 0 (0)
      max: 255 (1)
      mean: 96.8463 (0.379789)
      standard deviation: 43.7538 (0.171583)
      kurtosis: -0.0651751
      skewness: 0.226805
    Black:
      min: 0 (0)
      max: 255 (1)
      mean: 37.8641 (0.148487)
      standard deviation: 59.3405 (0.232708)
      kurtosis: 1.19166
      skewness: 1.56223
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 75.2401 (0.295059)
      standard deviation: 44.734 (0.175428)
      kurtosis: 0.954185
      skewness: 0.245123
  Total ink density: 272.941%
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: cmyk(255,255,255,0)
  Border color: cmyk(223,223,223,0)
  Matte color: cmyk(189,189,189,0)
  Transparent color: cmyk(0,0,0,0)
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 546x427+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 75
  Orientation: Undefined
  Properties:
    date:create: 2014-11-05T14:44:13+00:00
    date:modify: 2014-11-04T16:51:44+00:00
    jpeg:colorspace: 4
    jpeg:sampling-factor: 1x1,1x1,1x1,1x1
    signature: 3cf5d2f0885fe21ffc01ec03f8537aa80bd49c7f3663988dbcdfe33b89070d90
  Artifacts:
    filename: raw.jpg
    verbose: true
  Tainted: False
  Filesize: 50.4KB
  Number pixels: 233K
  Pixels per second: 11.66MB
  User time: 0.010u
  Elapsed time: 0:01.019
  Version: ImageMagick 6.8.9-5 Q16 x86_64 2014-09-30 http://www.imagemagick.org

@lovell
Copy link
Owner

lovell commented Nov 5, 2014

@bradisbell This seems to be a JPEG image in a non sRGB colourspace (namely CMYK) but without an ICC colour profile. I'd expect identify -verbose ... to include a "Profiles" section for CMYK JPEG images.

Could it have passed through an overly-zealous metadata stripping tool?

@bradisbell
Copy link

@lovell I wouldn't be surprised if many of the photos I need to resize were passed through a meat grinder before reaching my code. :-) I am unable to control the source.

Is there any way to set a default ICC profile? Unfortunately, I'm in a situation where if the photo can be handled at all, it must be, even if quality of color is lost. The expectation is that if a browser or photo viewer can render it, I should be able to resize it.

@lovell
Copy link
Owner

lovell commented Nov 6, 2014

The most common ICC profile for CMYK is "US Web Coated (SWOP) v2" so would make a sensible default.

I can add the relevant 545KB file to this module then use it for the colour space conversion of any 4 channel JPEG without an embedded ICC profile.

The profile will be loaded from disk only when needed, so there will be a slight performance hit for the first image of this nature.

@bradisbell "The expectation is that if a browser or photo viewer can render it..."

By way of example, Chrome uses Skia under the hood for this sort of thing. The source code reveals:

"At this point we've received CMYK pixels from libjpeg. We perform a crude conversion to RGB (based on the formulae from easyrgb.com)"

This proposed addition to sharp means passing a profile-less CMYK JPEG image through it should produce more accurate colours than viewing the original image in Chrome.

@lovell lovell reopened this Nov 6, 2014
@lovell
Copy link
Owner

lovell commented Nov 6, 2014

I've added support to the master branch for CMYK input images without an embedded profile.

@bradisbell Are you able to test using npm install lovell/sharp?

@bradisbell
Copy link

@lovell Your update resolved my issue perfectly. Thank you!

As a bonus, your profile does indeed do a much better job at handling CMYK images than what is built into Chrome.

w800-h-q

@lovell
Copy link
Owner

lovell commented Nov 6, 2014

Great news, thanks for confirming. I'll publish v0.7.2 to npm in the next day or so.

If you're able to share, a few details about your use of this module would be most welcome over at #35.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants