Canvas getImageData with negative size violates invariant

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
pjt47@cam.ac.uk

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