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

Negate doesn't work with create constructor #3139

Closed
3 tasks done
petrzjunior opened this issue Mar 17, 2022 · 3 comments
Closed
3 tasks done

Negate doesn't work with create constructor #3139

petrzjunior opened this issue Mar 17, 2022 · 3 comments

Comments

@petrzjunior
Copy link

petrzjunior commented Mar 17, 2022

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.

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.

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

  System:
    OS: Linux 5.16 Arch Linux
    CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
    Memory: 10.56 GB / 23.20 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 16.9.1 - ~/.nvm/versions/node/v16.9.1/bin/node
    Yarn: 1.22.17 - /usr/bin/yarn
    npm: 7.21.1 - ~/.nvm/versions/node/v16.9.1/bin/npm

What are the steps to reproduce?

sharp({
  create: {
    width: 2,
    height: 2,
    channels: 3,
    background: { r: 10, g: 20, b: 30 }
  }
})
.negate()
.negate()
.toBuffer(function(err, data, info) {
  console.log('data', data);
});

What is the expected behaviour?

Expected output: data <Buffer 0a 14 1e 0a 14 1e 0a 14 1e 0a 14 1e>
Actual output: data <Buffer 00 00 00 00 00 00 00 00 00 00 00 00>

Additional information

Unit tests cover the case of loading PNG and JPEG which run correctly. But constructing the image manually via create {} turns all bytes into 00.

Calling negate should negate the image, but 00 is instead set to all bytes. When negate(true) is called, 00 is set to all bytes expect for the alpha channel, which is kept untouched.

@lovell
Copy link
Owner

lovell commented Mar 22, 2022

Thanks for reporting this. It looks like the bit depth of newly-created images was not always being correctly set internally, which triggered a float/int mix-up in the negate operation.

Commit 1d36936 fixes this, adds a unit test that would previously have failed, and also simplifies and corrects the selection of the relevant colourspace.

@lovell lovell added this to the v0.30.4 milestone Mar 22, 2022
@petrzjunior
Copy link
Author

petrzjunior commented Mar 23, 2022

Thank you for fixing this. I will try it once the next version is out.

@lovell
Copy link
Owner

lovell commented Apr 18, 2022

v0.30.4 now available, thanks again for reporting.

@lovell lovell closed this as completed Apr 18, 2022
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