Re: Canvas getImageData with negative size violates invariant

On Sat, 30 May 2009, Philip Taylor wrote:
>
> 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.

Fixed.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Friday, 12 June 2009 03:43:23 UTC