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

[Bug] sharp v0.30.0+ greyscale images with an embedded ICC profile change white pixels to dark grey #3112

Closed
3 tasks done
shodanwang opened this issue Feb 27, 2022 · 4 comments

Comments

@shodanwang
Copy link

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • Running npm install sharp completes without error.
  • Running node -e "require('sharp')" completes without error.

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

  • I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

npx: installed 1 in 0.435s

  System:
    OS: Linux 5.13 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor
    Memory: 9.07 GB / 15.59 GB
    Container: Yes
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.19.0 - /usr/bin/node
    npm: 6.14.16 - /usr/bin/npm

What are the steps to reproduce?

  1. Download the image from this link, rename it to in.jpg
  2. Convert ( resize ) in.jpg with the following snippet:
const sharp = require("sharp");

async function resizeImage() {
  try {
    await sharp("in.jpg")
      .resize({
        width: 480,
        height: 480
      })
      .toFile("out.jpg");
  } catch (error) {
    console.log(error);
  }
}

resizeImage();
  1. Check the result ( out.jpg ), it should be something like this.

What is the expected behaviour?

You can see the image is filled with lots of grey area, tainting ( not sure if this is the right word ) the image. It should just resize the image instead of filling the image with grey area.

Notice that this happens after v0.30.0+ ( so both v0.30.0 & v0.30.1 suffered from this problem ), but not in the version before that. v0.29.3 does not have this problem, it can convert the image normally.

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

( Check the "how to reproduce" section )

Please provide sample image(s) that help explain this problem

( Check the "how to reproduce" section )

@lovell
Copy link
Owner

lovell commented Feb 28, 2022

Hi, thanks for reporting, I can reproduce with the supplied input image using sharp("in.jpg").toFile("out.jpg").

The input image is 8-bit greyscale with an embedded ICC profile that appears to be valid for such an image.

ColorSync color profile 2.1, type ADBE, GRAY/XYZ-prtr device by ADBE, 912 bytes, 3-6-1999 "Dot Gain 30%"

The input image undergoes an ICC transform via lcms (Little CMS) using its embedded profile, which is where things go wrong.

sharp v0.29.x provides lcms 2.12 whereas sharp v0.30.x provides lcms 2.13 so we're probably seeing the effects of the following upstream bug:

mm2/Little-CMS@fdbfb76

https://bugs.archlinux.org/task/73580
https://bugs.gentoo.org/832520

@lovell lovell changed the title [Bug] sharp v0.30.0+ convert jpg with grey area in it, "tainting" the image [Bug] sharp v0.30.0+ dark background on greyscale images with an embedded ICC profile Feb 28, 2022
@lovell lovell added this to the v0.31.0 milestone Feb 28, 2022
@lovell lovell changed the title [Bug] sharp v0.30.0+ dark background on greyscale images with an embedded ICC profile [Bug] sharp v0.30.0+ greyscale images with an embedded ICC profile change white pixels to dark grey Feb 28, 2022
@lovell lovell modified the milestones: v0.31.0, v0.30.2 Feb 28, 2022
@lovell
Copy link
Owner

lovell commented Feb 28, 2022

Commit 21a9607 temporarily ignores greyscale ICC profiles. We can revert this to re-introduce support later after we pick up a newer version of lcms with the upstream bug fix.

@lovell
Copy link
Owner

lovell commented Feb 28, 2022

Created #3114 as a reminder to revert this temporary workaround later.

@lovell
Copy link
Owner

lovell commented Mar 2, 2022

v0.30.2 now available with a quick fix for this, thanks again for reporting.

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

No branches or pull requests

2 participants