Skip to content

context.drawImage method "scuffs" the original image #202

@BullChiken

Description

@BullChiken

Expected Behaviour

  1. After drawing image from source it should look the same as the source.
    Input Image/Expected Output

Actual Behaviour

  1. Certain vertical and horizontal lines are messed up (either swapped with or replaced by a neighboring line).
  2. The example image is 200x200 and the wrong lines at x/y coords 31, 59, 60, 113, 114, 115, 116 are visible.
    Actual Output

Steps To Reproduce

  1. Decode image from a file (image with something like a black&white checkerboard pattern allows to see the issue better);
  2. Create a canvas with the same dimensions;
  3. Draw the image calling drawImage method (2 arguments form is enough, but reproduceable even with 4 and 8 form) with zero coords;
  4. Encode image to another file, compare them.

Any Relevant Code Snippets

const img = await PImage.decodePNGFromStream(fs.createReadStream('./test_in.png'));
const canvas = PImage.make(img.width, img.height);
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, img.width, img.height);
ctx.drawImage(img, 0, 0, img.width, img.height);
await PImage.encodePNGToStream(canvas, fs.createWriteStream('./test_out.png'));
// the output is scuffed

When I replace the drawImage line with this one, the scuffing suddenly disappears (used as a temporary hack in my project):

ctx.drawImage(img, -1, -1, src.width + 1, src.height + 1);

Platform

OS: Windows 11
Node Version: 20.12.2
NPM Version: 10.5.0
PureImage Version: 0.4.13

Any Additional Info

I think the problem may rise from incorrect bounding points calculation (left/top one), some indexing mistake inside loops, or from scaling matrices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions