Regression in blit function when srcx is non-zero
See original GitHub issueExpected Behavior
The blit function takes optional arguments srcx, srcy, srcw, srch
to specify a region of the source image to blit. For example, if the source image is a 100w x 100h square and the destination is a 50w x 100h rectangle, it should be possible to blit the left half of the source image into the destination with dest.blit(src, 0, 0, 0, 0, 50, 100)
, or the right half with dest.blit(src, 0, 0, 50, 0, 50, 100)
.
This worked as expected in Jimp 0.2.28, but it no longer works in Jimp 0.4.0 (I haven’t tested any other versions).
Current Behavior
Blitting the left half of the source image (with srcx = 0
) works as expected, but blitting the right half (with srcx > 0
) doesn’t affect the desination image at all. The problem seems to involve the following check at line 68 of plugin-blit/dist/index.js
:
if (x + sx >= 0 && y + sy >= 0 && maxw - x - sx > 0 && maxh - y - sy > 0)
This check causes all pixels to be skipped when blitting the right half of the source image. I’m not sure whether the problem is the check itself, or the values of sx
and sy
that are being passed to the scanQuiet()
callback.
Context
- Jimp Version: 0.4.0 (bug does not exist in 0.2.28)
- Operating System: Linux
- Node version: 10.7.0
Thank you for this fantastic project!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6
Top GitHub Comments
@t3rminus that was super useful! I basically added your code as test cases. The cat example made me laugh. I’ve opened #613. Once merged I’ll put a release together.
Seems to be working now https://jsfiddle.net/n7rd8by3/ 🎉