W3C home > Mailing lists > Public > public-canvas-api@w3.org > April to June 2010

Re: Clarification in Section 13 Pixel manipulation

From: Ian Hickson <ian@hixie.ch>
Date: Fri, 9 Apr 2010 21:43:18 +0000 (UTC)
To: Jatinder Mann <jmann@microsoft.com>
Cc: "'public-canvas-api@w3.org'" <public-canvas-api@w3.org>
Message-ID: <Pine.LNX.4.64.1004092135450.751@ps20323.dreamhostps.com>
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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:10:26 UTC