<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>12586</bug_id>
          
          <creation_ts>2011-05-03 02:13:48 +0000</creation_ts>
          <short_desc>Suggest using Typed Array for ImageData pixels. Add a new &apos;buffer&apos; attribute that references ArrayBuffer of the pixel data. Convert &apos;data&apos; (CanvasPixelArray) to Uint8Array view of &apos;buffer&apos;.</short_desc>
          <delta_ts>2012-02-29 23:32:09 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>HTML WG</product>
          <component>LC1 HTML Canvas 2D Context</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#canvaspixelarray</bug_file_loc>
          <status_whiteboard>canvas</status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>13800</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to>contributor</assigned_to>
          <cc>bzbarsky</cc>
    
    <cc>cam</cc>
    
    <cc>ian</cc>
    
    <cc>jonas</cc>
    
    <cc>kbr</cc>
    
    <cc>mike</cc>
    
    <cc>public-html-admin</cc>
    
    <cc>public-html-wg-issue-tracking</cc>
    
    <cc>travil</cc>
    
    <cc>w3.org</cc>
          
          <qa_contact name="HTML WG Bugzilla archive list">public-html-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>47856</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2011-05-03 02:13:48 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html
Section: http://www.whatwg.org/specs/web-apps/current-work/complete.html#the-canvas-state

Comment:
Suggest using Typed Array for ImageData pixels. Add a new &apos;buffer&apos; attribute
that references ArrayBuffer of the pixel data. Convert &apos;data&apos;
(CanvasPixelArray) to Uint8Array view of &apos;buffer&apos;.

Posted from: 99.20.208.90
User agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.205 Safari/534.16</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>47857</commentid>
    <comment_count>1</comment_count>
    <who name="Joel Martin">w3.org</who>
    <bug_when>2011-05-03 02:20:07 +0000</bug_when>
    <thetext>If necessary &apos;CanvasPixelArray&apos; could be alias for Uint8Array type if it is believed that scripts are actually checking the type of CanvasPixelArray.

This accomplishes a couple things:
- consolidate binary array data types (focus browser optimization resources)
- allows developers to create a Uint32Array from the raw ArrayBuffer to access whole pixels at a time.

Typed Array views and the CanvasPixelArray definition are largely compatible (with the typed array definition actually having more power).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>47858</commentid>
    <comment_count>2</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-05-03 02:28:41 +0000</bug_when>
    <thetext>Note that Uint8Array doesn&apos;t have the same overflow/rounding semantics that CanvasPixelArray does.

In Gecko, CanvasPixelArray is implemented as a new typed array type called Uint8ClampedArray.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51721</commentid>
    <comment_count>3</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-07-29 01:30:21 +0000</bug_when>
    <thetext>It&apos;s not quite a typed array. For example, some of the TypedArray constructors don&apos;t make much sense, since the canvas pixel array is based on the underlying buffer and so the same dimensions can have different buffer sizes.

It might make sense to define some sort of relationship, though.

What&apos;s the implementation status of CanvasPixelArray in the various browsers, in terms of their relationship to TypedArrays? Does anyone else have an underlying ArrayBuffer like Gecko?

bz: Is the TypedArrayness of CanvasPixelArray in Gecko visible to JS in any way?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51725</commentid>
    <comment_count>4</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-07-29 02:29:14 +0000</bug_when>
    <thetext>&gt; bz: Is the TypedArrayness of CanvasPixelArray in Gecko visible to JS in any
&gt; way?

Yep.  The CanvasPixelArray is just a typed array, and you can do all the normal typed array stuff to it from JS: get the underlying ArrayBuffer, create other views on the data, construct subarrays, etc.  In fact, there is no CanvasPixelArray interface in Gecko at all at the moment; if you ask the .data of an imageData whether it&apos;s instanceof Uint8ClampedArrays you should get back true.

Furthermore, you can create Uint8ClampedArrays using the normal typed array constructors and then work with them.  And since the .data of imagedata is not readonly in Gecko at the moment you can assign one of those (or some other typed array, or a regular array) to it.

I&apos;m not sure all of this necessarily makes sense from a spec point of view; just describing what Gecko does right now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51754</commentid>
    <comment_count>5</comment_count>
    <who name="Joel Martin">w3.org</who>
    <bug_when>2011-07-29 14:13:34 +0000</bug_when>
    <thetext>Actually, I think the gecko approach makes a lot of sense from a spec consistency and usefulness perspective. Typed arrays are the native data format for 3D Canvas (WebGL) interaction. It seems consistent that 2D Canvas data formats would also be typed arrays.

As I noted in comment #1 it would be really useful/efficient in some situations to be able to address 2D image data as whole pixels (Uint32Array or Uint32ClampedArray or whatever). Also, being able to move data back and forth easily between 2D Canvas and WebSockets, File API, etc seems like another plus from a spec consistency/simplicity perspective.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51800</commentid>
    <comment_count>6</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2011-07-30 00:40:51 +0000</bug_when>
    <thetext>In WebKit, CanvasPixelArray is currently a distinct type from the rest of the typed arrays. It owns its storage, which is distinct from that of the Canvas&apos;s backing store, and it doesn&apos;t expose it in the form of an ArrayBuffer. It would definitely be possible to respecify it as Uint8ClampedArray and add aliases (i.e., CanvasPixelArray == Uint8ClampedArray) for backward compatibility.

I&apos;d be glad to see this unification for all of the reasons mentioned here. If we do go down this route, I would strongly prefer to add only Uint8ClampedArray to the typed array spec, and not clamped versions of the other typed arrays, to avoid an explosion of the typed array types.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>52772</commentid>
    <comment_count>7</comment_count>
    <who name="Michael[tm] Smith">mike</who>
    <bug_when>2011-08-04 05:04:07 +0000</bug_when>
    <thetext>mass-move component to LC1</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>54667</commentid>
    <comment_count>8</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-08-11 03:12:52 +0000</bug_when>
    <thetext>Ok, Kenneth, can you add Uint8ClampedArray? Then I&apos;ll redefine the canvas in those terms.

No need to make an alias, I doubt anyone is relying on the old name since not everyone implements it anyway.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>56685</commentid>
    <comment_count>9</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2011-09-13 01:09:28 +0000</bug_when>
    <thetext>I apologize for the delay. Uint8ClampedArray has been added to the typed array editor&apos;s draft:

https://www.khronos.org/registry/typedarray/specs/latest/

Please send me any feedback, in particular any concerns over inheriting from Uint8Array (which made the IDL for both types slightly simpler).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>56688</commentid>
    <comment_count>10</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-09-13 04:06:22 +0000</bug_when>
    <thetext>There&apos;s an open item on whether after clamping Uint8ClampedArray should round or truncate.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58495</commentid>
    <comment_count>11</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2011-10-20 02:02:50 +0000</bug_when>
    <thetext>(In reply to comment #10)
&gt; There&apos;s an open item on whether after clamping Uint8ClampedArray should round
&gt; or truncate.

(Sorry for the delay, I didn&apos;t see this comment until now.)

After clamping, it should not matter; the values are guaranteed to be within the range that Uint8ClampedArray can represent internally. Rounding and truncation should produce the same results. Am I missing something?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58496</commentid>
    <comment_count>12</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-10-20 02:16:14 +0000</bug_when>
    <thetext>Yes, you are.  Consider a computation that in fact always produces values in the range 0-255 but is subject to the usual floating point rounding errors.  If you truncate, you will never get 255 out of it.

For many computations the end result of this as the computation is iterated is for all the color channels to collapse to 0...

So you really do want rounding.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58497</commentid>
    <comment_count>13</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2011-10-20 02:33:55 +0000</bug_when>
    <thetext>(In reply to comment #12)
&gt; Yes, you are.  Consider a computation that in fact always produces values in
&gt; the range 0-255 but is subject to the usual floating point rounding errors.  If
&gt; you truncate, you will never get 255 out of it.
&gt; 
&gt; For many computations the end result of this as the computation is iterated is
&gt; for all the color channels to collapse to 0...
&gt; 
&gt; So you really do want rounding.

Sorry for missing this on first glance.

It looks like this was fixed with the [Clamp] tweaks in the September 27 update to the Web IDL editors&apos; draft. See http://dev.w3.org/2006/webapi/WebIDL/#changes .</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58545</commentid>
    <comment_count>14</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-10-20 14:59:07 +0000</bug_when>
    <thetext>Yeah, IDL [Clamp] does the right thing.  If the typed array spec is defined via WebIDL, then we&apos;re probably all set.  (Though if it does, it needs various verbiage about sets of supported indices and such that it seems to be missing.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61362</commentid>
    <comment_count>15</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-12-09 23:26:48 +0000</bug_when>
    <thetext>EDITOR&apos;S RESPONSE: This is an Editor&apos;s Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Accepted
Change Description: part of the trunk merge
Rationale: Concurred with reporter&apos;s comments.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>64795</commentid>
    <comment_count>16</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2012-02-29 23:32:09 +0000</bug_when>
    <thetext>(In reply to comment #14)
&gt; Yeah, IDL [Clamp] does the right thing.  If the typed array spec is defined via
&gt; WebIDL, then we&apos;re probably all set.  (Though if it does, it needs various
&gt; verbiage about sets of supported indices and such that it seems to be missing.)

Sorry for letting this go so long, but the editor&apos;s draft of the typed array spec now defines the supported indexed properties. https://www.khronos.org/registry/typedarray/specs/latest/#7</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>