[whatwg] createImageData should take unsigned long

On Mon, 31 Aug 2009 08:08:05 +0200, Ian Hickson <ian at hixie.ch> wrote:

> On Mon, 24 Aug 2009, Philip J?genstedt wrote:
>>
>> As far as I can see there's no good reason why createImageData should
>> take a float as input rather than unsigned long. Having it as float
>> creates the odd situation where (0.1, 0.1) gives a 1x1 ImageData while
>> (10.1, 10.1) gives a 10x10 or 11x11 depening on if you ceil or round the
>> input (not defined). Unless there's a compelling reason to allow
>> something like (0.1, 0.1) I suggest changing the type and leaving the
>> float->unsigned conversion to WebIDL.
>
> Twenty years from now, when we're using 960dpi screens, 1 CSS pixel might
> well map to ten device pixels reliably, such that people will want
> sub-CSS-pixel-level accuracy in their calls to createImageData().

I get the impression this has all been discussed before. Still, it seems  
unlikely that any browser will ever be able to switch to anything but a  
1:1 CSS pixel:device pixel ratio, as that would break all existing pages  
assuming that getImageData(0, 0, 100, 100) returns a 100x100 bitmap  
(because assuming that is much easier, unless you read the spec carefully  
you're unlikely to know it could ever be any different). I don't doubt  
that high DPI screens will happen, but when it does browsers are more  
likely to provide an extra flag like getImageData(..., useDevicePixels) or  
another opt-in method in order to stay compatible with existing content.  
Another option for the page author is simply creating a 1000x1000 canvas  
and setting its CSS width/height to 100x100 (assuming the CSS pixel:device  
pixel ratio can be found via script).

In any event, judging by existing implementations, the behavior of  
createImageData(w, h) isn't as clear as it needs to be:

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/223

Firefox:

log: ctx.createImageData(-1.1,1) => [Exception...
log: ctx.createImageData(-1,1) => [Exception...
log: ctx.createImageData(-0.1,1) => [Exception...
log: ctx.createImageData(0,1) => [Exception...
log: ctx.createImageData(0.1,1) => [Exception...
log: ctx.createImageData(1,1) => 1x1
log: ctx.createImageData(1.1,1) => 1x1

Safari/Chrome:

log: ctx.createImageData(-1.1,1) => 1x1
log: ctx.createImageData(-1,1) => 1x1
log: ctx.createImageData(-0.1,1) => 1x1
log: ctx.createImageData(0,1) => 1x1
log: ctx.createImageData(0.1,1) => 1x1
log: ctx.createImageData(1,1) => 1x1
log: ctx.createImageData(1.1,1) => 2x1

My interpretation of the spec:

log: ctx.createImageData(-1.1,1) => 1x1
log: ctx.createImageData(-1,1) => 1x1
log: ctx.createImageData(-0.1,1) => 1x1
log: ctx.createImageData(0,1) => INDEX_SIZE_ERR
log: ctx.createImageData(0.1,1) => 1x1
log: ctx.createImageData(1,1) => 1x1
log: ctx.createImageData(1.1,1) => 1x1

If the spec doesn't say to round rather than ceil, we're bound to have  
subtle compatibility bugs on this.

-- 
Philip J?genstedt
Core Developer
Opera Software

Received on Monday, 31 August 2009 01:55:04 UTC