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

fixed plugin-crop full width slices math #1073

Merged
merged 1 commit into from
Feb 3, 2023

Conversation

endreszabo
Copy link
Contributor

@endreszabo endreszabo commented Feb 21, 2022

What's Changing and Why

Fixed how the crop function calculates the slice range size. This bug happens with the 'shortcut' where cropped image-to-be starts from original image x=0, and crop width == original image width.

I have a 96x2048 pixels image from which I'd like to crop out a lot of smaller images (sprites). Original code miscalculates the end variable:

> f=function(x,y,w,h) {
...       const start = (w * y + x) << 2;
...       const end = (start + h * w) << 2;
...       console.log(end-start)
... }
> f(0,0,96,96)
36864
> f(0,96,96,96)
147456

^^ error, this should be 36864 as well

Fixed one:

> f=function(x,y,w,h) {
...       const start = (w * y + x) << 2;
...       const end = start + (h * w << 2);
...       console.log(end-start)
... }
> f(0,0,96,96)
36864
> f(0,96,96,96)
36864

this is okay.

What else might be affected

Nothing else (except for any other code that might rely on this bug somehow).

Tasks

  • Add tests
  • Update Documentation
  • Update jimp.d.ts
  • Add SemVer Label
📦 Published PR as canary version: 0.16.2-canary.1073.1276.0

✨ Test out this PR locally via:

npm install @jimp/cli@0.16.2-canary.1073.1276.0
npm install @jimp/core@0.16.2-canary.1073.1276.0
npm install @jimp/custom@0.16.2-canary.1073.1276.0
npm install jimp@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-blit@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-blur@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-circle@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-color@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-contain@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-cover@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-crop@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-displace@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-dither@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-fisheye@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-flip@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-gaussian@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-invert@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-mask@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-normalize@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-print@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-resize@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-rotate@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-scale@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-shadow@0.16.2-canary.1073.1276.0
npm install @jimp/plugin-threshold@0.16.2-canary.1073.1276.0
npm install @jimp/plugins@0.16.2-canary.1073.1276.0
npm install @jimp/test-utils@0.16.2-canary.1073.1276.0
npm install @jimp/bmp@0.16.2-canary.1073.1276.0
npm install @jimp/gif@0.16.2-canary.1073.1276.0
npm install @jimp/jpeg@0.16.2-canary.1073.1276.0
npm install @jimp/png@0.16.2-canary.1073.1276.0
npm install @jimp/tiff@0.16.2-canary.1073.1276.0
npm install @jimp/types@0.16.2-canary.1073.1276.0
npm install @jimp/utils@0.16.2-canary.1073.1276.0
# or 
yarn add @jimp/cli@0.16.2-canary.1073.1276.0
yarn add @jimp/core@0.16.2-canary.1073.1276.0
yarn add @jimp/custom@0.16.2-canary.1073.1276.0
yarn add jimp@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-blit@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-blur@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-circle@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-color@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-contain@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-cover@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-crop@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-displace@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-dither@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-fisheye@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-flip@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-gaussian@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-invert@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-mask@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-normalize@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-print@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-resize@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-rotate@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-scale@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-shadow@0.16.2-canary.1073.1276.0
yarn add @jimp/plugin-threshold@0.16.2-canary.1073.1276.0
yarn add @jimp/plugins@0.16.2-canary.1073.1276.0
yarn add @jimp/test-utils@0.16.2-canary.1073.1276.0
yarn add @jimp/bmp@0.16.2-canary.1073.1276.0
yarn add @jimp/gif@0.16.2-canary.1073.1276.0
yarn add @jimp/jpeg@0.16.2-canary.1073.1276.0
yarn add @jimp/png@0.16.2-canary.1073.1276.0
yarn add @jimp/tiff@0.16.2-canary.1073.1276.0
yarn add @jimp/types@0.16.2-canary.1073.1276.0
yarn add @jimp/utils@0.16.2-canary.1073.1276.0

@hipstersmoothie hipstersmoothie merged commit 263df47 into jimp-dev:master Feb 3, 2023
@hipstersmoothie
Copy link
Collaborator

🚀 PR was released in v0.16.13 🚀

@hipstersmoothie hipstersmoothie added the released This issue/pull request has been released. label Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants