Skip to content

Composite: don't write to null pixels#1226

Merged
hipstersmoothie merged 1 commit into
jimp-dev:mainfrom
sjoerdthedev:fix-composite-offsets-outside-image
May 11, 2023
Merged

Composite: don't write to null pixels#1226
hipstersmoothie merged 1 commit into
jimp-dev:mainfrom
sjoerdthedev:fix-composite-offsets-outside-image

Conversation

@sjoerdthedev

@sjoerdthedev sjoerdthedev commented Apr 22, 2023

Copy link
Copy Markdown
Member

What's Changing and Why

This fixes a bug with the composite function which would write garbage data to a pixel at 0, 0 when the target pixel doesn't exist, which can happen when:

  • The source image is bigger than the destination image
  • Using negative x, y offsets

This is because getPixelIndex() returns -1 when using EDGE_CROP which didn't get checked for. So when writing to the target the red channel maps to -1 in the destination buffer, which gets discarded silently (Buffers surprisingly don't throw when you do this) and then the GBA parts of the source get written to the RGB channels on the target.

You can actually see it in the testing image I fixed for this PR: The old "correct" one has a random, off color pixel in the top left, the new one doesn't.

What else might be affected

Should not affect anything.

Tasks

  • Add tests
  • Update Documentation
  • Update jimp.d.ts
  • Add SemVer Label

@hipstersmoothie hipstersmoothie merged commit aec79d0 into jimp-dev:main May 11, 2023
@github-actions

Copy link
Copy Markdown
Contributor

🚀 PR was released in v0.22.8 🚀

@github-actions github-actions Bot added the released This issue/pull request has been released. label May 11, 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