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

Clarification in Section 13 Pixel manipulation

From: Jatinder Mann <jmann@microsoft.com>
Date: Fri, 9 Apr 2010 17:09:03 +0000
To: "'public-canvas-api@w3.org'" <public-canvas-api@w3.org>
Message-ID: <EAACC9DF6817544486F0D0ADA05CA4281A44E605@TK5EX14MBXC120.redmond.corp.microsoft.com>

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.

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]);

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

In my testing, Chrome and Safari will assign 255 when the value is above 255 and assign 0 when the value is below 0. Opera will wrap the values - for example, it will assign 144 when the input value is 400 and assign 156 when the input value is -100. Firefox will assign the value as is.

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.

Thank you,

[1] http://dev.w3.org/html5/2dcontext/#pixel-manipulation
[2] http://dev.w3.org/html5/canvas-api/canvas-2d-api.html

Jatinder Mann | Microsoft Program Manager | jmann@microsoft.com
Received on Friday, 9 April 2010 17:09:42 UTC

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