W3C home > Mailing lists > Public > public-html@w3.org > May 2009

Canvas getImageData with negative size violates invariant

From: Philip Taylor <pjt47@cam.ac.uk>
Date: Sat, 30 May 2009 17:20:35 +0100
Message-ID: <4A215CD3.7080008@cam.ac.uk>
To: HTML WG <public-html@w3.org>
The spec says:

   "the following must result in no visible changes to the rendering:
    context.putImageData(context.getImageData(x, y, w, h), x, y);"

But if I write

    context.fillRect(0, 0, 10, 10);
    var imgdata = context.getImageData(0, 10, 10, -10);
    context.putImageData(imgdata, 0, 10);

then imgdata will contain the data from the rectangle (0,0)-(10,10) that 
was just filled (by the definition of getImageData), but will have 
imgdata.height = 10 (not -10) since that's the number of rows of image 
data. putImageData will then draw this data in the rectangle 
(0,10)-(10,20), and therefore will probably visibly change the rendering.

I think a more precise invariant is:

   context.putImageData(context.getImageData(x, y, w, h),
     Math.min(x, x+w), Math.min(y, y+h));

but I don't know if there's a nicer way to fix the issue.

Philip Taylor
Received on Saturday, 30 May 2009 16:21:14 UTC

This archive was generated by hypermail 2.4.0 : Saturday, 9 October 2021 18:44:47 UTC