Re: Clarification in Section 13 Pixel manipulation

On Fri, 9 Apr 2010, Jatinder Mann wrote:
> 
> I came across an issue that needs clarification in Section 13 Pixel 
> manipulation [1] regarding the CanvasPixelArray object. The spec is 
> clear that the CanvasPixelArray contains image data in the range of 
> 0..255, representing the 8 bit value for that component. However, the 
> spec is not clear on what the expected behavior should be when a value 
> greater or less than the range of 0..255 is assigned to the array.

It's defined by Web IDL:

   http://dev.w3.org/2006/webapi/WebIDL/#es-octet


> For example, the following code gives different results per browser :
> 
> 0 var imgdata = ctx.getImageData(0, 0, 100, 100);
> 
> 1 //Greater than range
> 2 imgdata.data[0] = 300;
> 3 alert('Greater than range; input value: 300; actual: '+imgdata.data[0]);

This should alert "Greater than range; input value: 300; actual: 44".

> 4 //Less than range
> 5 imgdata.data[0] = -100;
> 6 alert('Less than range; input value: -100; actual: '+imgdata.data[0]);

This should alert "Less than range; input value: -100; actual: 156".


> Looking back, I noticed that the October 2008 draft of the spec [2], had 
> the following details that are now no longer in the March 2009 version 
> of the spec [1]:
> 
> "When a CanvasPixelArray object is indexed to modify an indexed property 
> index, with value value, the value of the component occupying the 
> position index, in the array must be set to value. JS undefined values 
> must be converted to zero. Other values must first be converted to 
> numbers using , and if the result is a NaN value, then the value must be 
> converted to zero. If the result is less than 0, it must be clamped to 
> zero. If the result is more than 255, it must be clamped to 255. If the 
> number is not an integer, it should be rounded to the nearest integer 
> using the IEEE 754 convertToIntegerTiesToEven rounding mode."
> 
> Was there a reason to remove this section? Clarity in this section might 
> help remove the interoperability issue.

This text was removed because it would never have been invoked, since Web 
IDL changes the value before the method is invoked, so you can't actually 
invoke the method with out-of-range values. So it was rather confusing!

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

Received on Friday, 9 April 2010 21:43:46 UTC