Skip to content

Commit

Permalink
[giow] (0) ImageData objects now expose an explicit pixel density, en…
Browse files Browse the repository at this point in the history
…abling them to be converted to BitmapImage objects correctly.

Fixing https://www.w3.org/Bugs/Public/show_bug.cgi?id=21329
Affected topics: Canvas, DOM APIs

git-svn-id: http://svn.whatwg.org/webapps@7849 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed Apr 23, 2013
1 parent d1628e5 commit 710b9e1
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 74 deletions.
68 changes: 45 additions & 23 deletions complete.html
Expand Up @@ -7986,6 +7986,7 @@ <h4 id=transferable-objects><span class=secno>2.7.5 </span>Transferable objects<

<h4 id=safe-passing-of-structured-data><span class=secno>2.7.6 </span>Safe passing of structured data</h4>

<!--CLEANUP-->
<p>When a user agent is required to obtain a <dfn id=structured-clone>structured
clone</dfn> of a value, optionally with a <i>transfer map</i>, it
must run the following algorithm, which either returns a separate
Expand Down Expand Up @@ -8074,7 +8075,7 @@ <h4 id=safe-passing-of-structured-data><span class=secno>2.7.6 </span>Safe passi
<dt>If <var title="">input</var> is an <code><a href=#imagedata>ImageData</a></code> object</dt>

<dd><p>Let <var title="">output</var> be a newly constructed
<code><a href=#imagedata>ImageData</a></code> object whose <code title=dom-imagedata-width><a href=#dom-imagedata-width>width</a></code> and <code title=dom-imagedata-height><a href=#dom-imagedata-height>height</a></code> attributes have values
<code><a href=#imagedata>ImageData</a></code> object whose <code title=dom-imagedata-width><a href=#dom-imagedata-width>width</a></code>, <code title=dom-imagedata-height><a href=#dom-imagedata-height>height</a></code>, and <code title=dom-imagedata-resolution><a href=#dom-imagedata-resolution>resolution</a></code> attributes have values
equal to the corresponding attributes on <var title="">input</var>, and whose <code title=dom-imagedata-data><a href=#dom-imagedata-data>data</a></code> attribute has the value
obtained from invoking the <a href=#internal-structured-cloning-algorithm>internal structured cloning
algorithm</a> recursively with the value of the <code title=dom-imagedata-data><a href=#dom-imagedata-data>data</a></code> attribute on <var title="">input</var> as the new "<var title="">input</var>"
Expand Down Expand Up @@ -33233,6 +33234,7 @@ <h5 id=2dcontext><span class=secno>4.8.11.2 </span>The 2D rendering context</h5>
interface <dfn id=imagedata>ImageData</dfn> {
readonly attribute unsigned long <a href=#dom-imagedata-width title=dom-imagedata-width>width</a>;
readonly attribute unsigned long <a href=#dom-imagedata-height title=dom-imagedata-height>height</a>;
readonly attribute double <a href=#dom-imagedata-resolution title=dom-imagedata-resolution>resolution</a>;
readonly attribute <a href=#uint8clampedarray>Uint8ClampedArray</a> <a href=#dom-imagedata-data title=dom-imagedata-data>data</a>;
};

Expand Down Expand Up @@ -35620,9 +35622,10 @@ <h6 id=image-sources-for-2d-rendering-contexts><span class=secno>4.8.11.2.9 </sp

<li><code><a href=#imagebitmap>ImageBitmap</a></code></li>

<!-- v3: supporting ImageData object might make sense (when resizing as well as filtering) - ack Charles Pritchard -->
</ul><p class=note>The <code><a href=#imagebitmap>ImageBitmap</a></code> interface can be created from a number of other
image-representing types, including <code><a href=#imagedata>ImageData</a></code>.</p>

</ul><p>When a user agent is required to <dfn id=check-the-usability-of-the-image-argument>check the usability of the <var title="">image</var>
<p>When a user agent is required to <dfn id=check-the-usability-of-the-image-argument>check the usability of the <var title="">image</var>
argument</dfn>, where <var title="">image</var> is a <code><a href=#canvasimagesource>CanvasImageSource</a></code> object, the
user agent must run these steps, which return either <i>good</i>, <i>bad</i>, or
<i>aborted</i>:</p>
Expand Down Expand Up @@ -37624,6 +37627,7 @@ <h6 id=hit-regions><span class=secno>4.8.11.2.15 </span>Hit regions</h6>


<h6 id=pixel-manipulation><span class=secno>4.8.11.2.16 </span><dfn>Pixel manipulation</dfn></h6>
<!--CLEANUP-->

<dl class=domintro><dt><var title="">imagedata</var> = <var title="">context</var> . <code title=dom-context-2d-createImageData><a href=#dom-context-2d-createimagedata>createImageData</a></code>(<var title="">sw</var>, <var title="">sh</var>)</dt>

Expand Down Expand Up @@ -37701,6 +37705,18 @@ <h6 id=pixel-manipulation><span class=secno>4.8.11.2.16 </span><dfn>Pixel manipu

</dd>

<dt><var title="">imagedata</var> . <code title=dom-imagedata-resolution><a href=#dom-imagedata-resolution>resolution</a></code></dt>

<dd>

<p>Returns the theoretical number of pixels in the <code><a href=#imagedata>ImageData</a></code> object's data per
corresponding coordinate space unit. This value is automatically determined from the source
image when the <code><a href=#imagedata>ImageData</a></code> object is created. It is only used to ensure that
<code><a href=#imagebitmap>ImageBitmap</a></code> objects have the right pixel density when generated from
<code><a href=#imagedata>ImageData</a></code> objects.</p>

</dd>

<dt><var title="">imagedata</var> . <code title=dom-imagedata-data><a href=#dom-imagedata-data>data</a></code></dt>

<dd>
Expand All @@ -37726,7 +37742,8 @@ <h6 id=pixel-manipulation><span class=secno>4.8.11.2.16 </span><dfn>Pixel manipu
<p>Throws a <code><a href=#notsupportederror>NotSupportedError</a></code> exception if any of the
arguments are not finite.</p>

<p>Each pixel in the image data is mapped to one coordinate space unit on the bitmap.</p>
<p>Each pixel in the image data is mapped to one coordinate space unit on the bitmap, regardless
of the value of the <code title=dom-imagedata-resolution><a href=#dom-imagedata-resolution>resolution</a></code> attribute.</p>

</dd>

Expand All @@ -37735,8 +37752,8 @@ <h6 id=pixel-manipulation><span class=secno>4.8.11.2.16 </span><dfn>Pixel manipu
<dd>

<p>Paints the data from the given <code><a href=#imagedata>ImageData</a></code> object onto the bitmap, at the bitmap's
native pixel density. If a dirty rectangle is provided, only the pixels from that rectangle are
painted.</p>
native pixel density (regardless of the value of the <code><a href=#imagedata>ImageData</a></code> object's <code title=dom-imagedata-resolution><a href=#dom-imagedata-resolution>resolution</a></code> attribute). If a dirty rectangle is provided,
only the pixels from that rectangle are painted.</p>

<p>The <code title=dom-context-2d-globalAlpha><a href=#dom-context-2d-globalalpha>globalAlpha</a></code>
and <code title=dom-context-2d-globalCompositeOperation><a href=#dom-context-2d-globalcompositeoperation>globalCompositeOperation</a></code>
Expand All @@ -37758,23 +37775,21 @@ <h6 id=pixel-manipulation><span class=secno>4.8.11.2.16 </span><dfn>Pixel manipu
objects.</p>

<p>When the <dfn id=dom-context-2d-createimagedata title=dom-context-2d-createImageData><code>createImageData()</code></dfn>
method is invoked with two arguments <var title="">sw</var> and <var title="">sh</var>, it must return a new <code><a href=#imagedata>ImageData</a></code>
object representing a rectangle with a width in equal to the
absolute magnitude of <var title="">sw</var> and a height equal to
the absolute magnitude of <var title="">sh</var>. When invoked with
a single <var title="">imagedata</var> argument, it must return a
new <code><a href=#imagedata>ImageData</a></code> object representing a rectangle with the
same dimensions as the <code><a href=#imagedata>ImageData</a></code> object passed as the
argument. The <code><a href=#imagedata>ImageData</a></code> object returned must be filled
with transparent black.</p>
method is invoked with two arguments <var title="">sw</var> and <var title="">sh</var>, it must
return a new <code><a href=#imagedata>ImageData</a></code> object representing a rectangle with a width in equal to the
absolute magnitude of <var title="">sw</var> and a height equal to the absolute magnitude of <var title="">sh</var>, and with a 1.0 pixel density. When invoked with a single <var title="">imagedata</var> argument, it must return a new <code><a href=#imagedata>ImageData</a></code> object representing
a rectangle with the same dimensions and pixel density as the <code><a href=#imagedata>ImageData</a></code> object passed
as the argument. In either case, the <code><a href=#imagedata>ImageData</a></code> object returned must be filled with
transparent black.</p>

<p>When the <dfn id=dom-context-2d-createimagedatahd title=dom-context-2d-createImageDataHD><code>createImageDataHD()</code></dfn>
method is invoked (with its two arguments <var title="">sw</var> and <var title="">sh</var>) it
must return a new <code><a href=#imagedata>ImageData</a></code> object representing a rectangle with a width in equal to
the absolute magnitude of <var title="">sw</var> multiplied by <var title="">scale</var> and a
height equal to the absolute magnitude of <var title="">sh</var> multiplied by <var title="">scale</var>, where <var title="">scale</var> is the number of pixels in the <a href=#scratch-bitmap>scratch
bitmap</a> per coordinate space units. The <code><a href=#imagedata>ImageData</a></code> object returned must be
filled with transparent black.</p>
the absolute magnitude of <var title="">sw</var> multiplied by <var title="">scale</var>, a height
equal to the absolute magnitude of <var title="">sh</var> multiplied by <var title="">scale</var>,
and a pixel density equal to <var title="">scale</var>, where <var title="">scale</var> is the
number of pixels in the <a href=#scratch-bitmap>scratch bitmap</a> per coordinate space units. The
<code><a href=#imagedata>ImageData</a></code> object returned must be filled with transparent black.</p>

<p>The <dfn id=dom-context-2d-getimagedata title=dom-context-2d-getImageData><code>getImageData(<var title="">sx</var>, <var title="">sy</var>, <var title="">sw</var>, <var title="">sh</var>)</code></dfn> method must, if
either the <var title="">sw</var> or <var title="">sh</var> arguments are zero, throw an
Expand All @@ -37783,14 +37798,15 @@ <h6 id=pixel-manipulation><span class=secno>4.8.11.2.16 </span><dfn>Pixel manipu
if the <a href=#scratch-bitmap>scratch bitmap</a>'s <a href=#concept-canvas-origin-clean title=concept-canvas-origin-clean>origin-clean</a>
flag is set to false, it must throw a <code><a href=#securityerror>SecurityError</a></code> exception;
<!--REMOVE-TOPIC:Security-->

otherwise, it must return an <code><a href=#imagedata>ImageData</a></code> object with width <var title="">sw</var> and
height <var title="">sh</var> representing the <a href=#scratch-bitmap>scratch bitmap</a> for the area of that
bitmap denoted by the rectangle whose corners are the four points (<var title="">sx</var>, <var title="">sy</var>), (<span title=""><var title="">sx</var>+<var title="">sw</var></span>, <var title="">sy</var>), (<span title=""><var title="">sx</var>+<var title="">sw</var></span>, <span title=""><var title="">sy</var>+<var title="">sh</var></span>), (<var title="">sx</var>, <span title=""><var title="">sy</var>+<var title="">sh</var></span>), in the bitmap's coordinate space
units. If the bitmap does not represent each coordinate space unit square using exactly one pixel,
the value of each pixel in the returned abject must be derived from the value(s) of the pixel(s)
in the bitmap that correspond to the same coordinate. Pixels outside the <a href=#scratch-bitmap>scratch
bitmap</a> must be returned as transparent black. Pixels must be returned as non-premultiplied
alpha values.</p>
alpha values. The pixel density of the object returned must be 1.0.</p>

<p>The <dfn id=dom-context-2d-getimagedatahd title=dom-context-2d-getImageDataHD><code>getImageDataHD(<var title="">sx</var>,
<var title="">sy</var>, <var title="">sw</var>, <var title="">sh</var>)</code></dfn> method must,
Expand All @@ -37804,13 +37820,17 @@ <h6 id=pixel-manipulation><span class=secno>4.8.11.2.16 </span><dfn>Pixel manipu
multiplied by <var title="">scale</var> and height <var title="">sh</var> multiplied by <var title="">scale</var> representing the <a href=#scratch-bitmap>scratch bitmap</a> for the area of that bitmap
denoted by the rectangle whose corners are the four points (<var title="">sx</var>, <var title="">sy</var>), (<span title=""><var title="">sx</var>+<var title="">sw</var></span>, <var title="">sy</var>), (<span title=""><var title="">sx</var>+<var title="">sw</var></span>, <span title=""><var title="">sy</var>+<var title="">sh</var></span>), (<var title="">sx</var>, <span title=""><var title="">sy</var>+<var title="">sh</var></span>), in the bitmap's coordinate space
units. Pixels outside the <a href=#scratch-bitmap>scratch bitmap</a> must be returned as transparent black.
Pixels must be returned as non-premultiplied alpha values.</p>
Pixels must be returned as non-premultiplied alpha values. The pixel density of the object
returned must be <var title="">scale</var>. For the purposes of this paragraph, <var title="">scale</var> is the number of pixels in the <a href=#scratch-bitmap>scratch bitmap</a> per coordinate
space units.</p>

<!--CLEANUP-->
<p>New <code><a href=#imagedata>ImageData</a></code> objects must be initialized so that
their <dfn id=dom-imagedata-width title=dom-imagedata-width><code>width</code></dfn>
attribute is set to the number of pixels per row in the image data,
their <dfn id=dom-imagedata-height title=dom-imagedata-height><code>height</code></dfn>
attribute is set to the number of rows in the image data, and their
attribute is set to the number of rows in the image data,
their <dfn id=dom-imagedata-resolution title=dom-imagedata-resolution><code>resolution</code></dfn> is set to the object's pixel density, and their
<dfn id=dom-imagedata-data title=dom-imagedata-data><code>data</code></dfn> attribute is
initialized to a <code><a href=#uint8clampedarray>Uint8ClampedArray</a></code> object. The
<code><a href=#uint8clampedarray>Uint8ClampedArray</a></code> object must use a <a href=#canvas-pixel-arraybuffer>Canvas Pixel
Expand Down Expand Up @@ -73825,7 +73845,9 @@ <h3 id=images><span class=secno>7.6 </span>Images</h3>
<li><p>Create a new <code><a href=#imagebitmap>ImageBitmap</a></code> object.</li>

<li><p>Let the <code><a href=#imagebitmap>ImageBitmap</a></code> object's bitmap data be the image data given by the
<code><a href=#imagedata>ImageData</a></code> object, <a href=#cropped-to-the-source-rectangle>cropped to the source rectangle</a>.</li>
<code><a href=#imagedata>ImageData</a></code> object, <a href=#cropped-to-the-source-rectangle>cropped to the source rectangle</a>, using the value
ofd the object's <code title=dom-imagedata-resolution><a href=#dom-imagedata-resolution>resolution</a></code> attribute as the
object's pixel density.</li>

<li><p>Return, but continue running these steps asynchronously.</li>

Expand Down

0 comments on commit 710b9e1

Please sign in to comment.