Skip to content

Commit

Permalink
convertToBlob
Browse files Browse the repository at this point in the history
  • Loading branch information
fserb committed Oct 9, 2018
1 parent a6c8281 commit 9ec7c9e
Showing 1 changed file with 72 additions and 87 deletions.
159 changes: 72 additions & 87 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -59406,6 +59406,7 @@ interface <dfn>HTMLCanvasElement</dfn> : <span>HTMLElement</span> {

USVString <span data-x="dom-canvas-toDataURL">toDataURL</span>(optional DOMString type, optional any quality);
void <span data-x="dom-canvas-toBlob">toBlob</span>(<span>BlobCallback</span> _callback, optional DOMString type, optional any quality);
Promise&lt;<span>Blob</span>> <span data-x="dom-canvas-convertToBlob">convertToBlob</span>(optional <span>ImageEncodeOptions</span> options);
<span>OffscreenCanvas</span> <span data-x="dom-canvas-transferControlToOffscreen">transferControlToOffscreen</span>();
};

Expand Down Expand Up @@ -65108,8 +65109,77 @@ dictionary <dfn>ImageBitmapRenderingContextSettings</dfn> {

</ol>

</div>
<dl class="domintro">
<dt><var>promise</var> = <var>canvas</var> . <code subdfn
data-x="dom-canvas-convertToBlob">convertToBlob</code>( [<var>options</var>] )</dt>

<dd>
<p>Returns a promise that will fulfill with a new <code>Blob</code> object representing a file
containing the image in the <code>Canvas</code> object.</p>

<p>The argument, if provided, is a dictionary that controls the encoding options of the image
file to be created. The <code data-x="image-encode-options-type">type</code>
field specifies the file format and has a default value of "<code>image/png</code>"; that type
is also used if the requested type isn't supported. If the image format supports variable
quality (such as "<code>image/jpeg</code>"), then the <code
data-x="image-encode-options-quality">quality</code> field is a number in the range 0.0
to 1.0 inclusive indicating the desired quality level for the resulting image. The
<code data-x="image-encode-options-pixelformat">pixelFormat</code> option specifies
the underlying pixel storage for the ceated image, if the image format supports it.</p>
</dd>
</dl>

<p>The <dfn><code
data-x="dom-canvas-convertToBlob">convertToBlob(<var>options</var>)</code></dfn> method,
when invoked, must run the following steps:</p>

<ol>
<li><p>If this <code>Canvas</code> object's <span
data-x="concept-canvas-context-mode">context mode</span> is <span
data-x="canvas-context-2d">2d</span> and the rendering context's <span
data-x="concept-canvas-origin-clean">origin-clean</span> flag is set to false, then return a
promise rejected with a <span>"<code>SecurityError</code>"</span> <code>DOMException</code>.</p>

<li><p>If this <code>Canvas</code> object's has no pixels (i.e., either its
horizontal dimension or its vertical dimension is zero) then return a promise rejected with an
<span>"<code>IndexSizeError</code>"</span> <code>DOMException</code>.</p></li>

<li><p>Let <var>result</var> be a new promise object.</p></li>

<li>
<p>Run these steps <span>in parallel</span>:</p>

<ol>
<li><p>Let <var>file</var> be <span data-x="a serialization of the bitmap as a file">a
serialization of the <code>Canvas</code>'s bitmap as a file</span>, with <var>options</var>'s
<dfn><code data-x="image-encode-options-type">type</code></dfn>, <dfn><code
data-x="image-encode-options-pixelformat">pixelFormat</code></dfn> and <dfn><code
data-x="image-encode-options-quality">quality</code></dfn>.</p></li>

<li>
<p><span>Queue a task</span> to run these steps:</p>

<ol>
<li><p>If <var>file</var> is null, then reject <var>result</var> with an
<span>"<code>EncodingError</code>"</span> <code>DOMException</code>.</p></li>

<li><p>Otherwise, resolve <var>result</var> with a new <code>Blob</code> object, created in
the <span data-x="concept-relevant-realm">relevant Realm</span> of this
<code>OffscreenCanvas</code> object, representing <var>file</var>. <ref
spec=FILEAPI></p></li>
</ol>

<p>The <span>task source</span> for this task is the <span>canvas blob serialization task
source</span>.</p>
</li>
</ol>
</li>

<li><p>Return <var>result</var>.</p></li>
</ol>


</div>



Expand All @@ -65131,7 +65201,7 @@ interface <dfn>OffscreenCanvas</dfn> : <span>EventTarget</span> {

<span>OffscreenRenderingContext</span>? <span data-x="dom-OffscreenCanvas-getContext">getContext</span>(<span>OffscreenRenderingContextId</span> contextId, optional any options = null);
<span>ImageBitmap</span> <span data-x="dom-OffscreenCanvas-transferToImageBitmap">transferToImageBitmap</span>();
Promise&lt;<span>Blob</span>> <span data-x="dom-OffscreenCanvas-convertToBlob">convertToBlob</span>(optional <span>ImageEncodeOptions</span> options);
Promise&lt;<span>Blob</span>> <span data-x="dom-canvas-convertToBlob">convertToBlob</span>(optional <span>ImageEncodeOptions</span> options);
};</code></pre>

<p class="note"><code>OffscreenCanvas</code> is an <code>EventTarget</code> so that WebGL can
Expand Down Expand Up @@ -65374,93 +65444,8 @@ interface <dfn>OffscreenCanvas</dfn> : <span>EventTarget</span> {
data-x="offscreencontext-commit">commit()</code> method of the <code>OffscreenCanvas</code>
object's rendering context.</p>

<dl class="domintro">
<dt><var>promise</var> = <var>offscreenCanvas</var> . <code subdfn
data-x="dom-OffscreenCanvas-convertToBlob">convertToBlob</code>( [<var>options</var>] )</dt>

<dd>
<p>Returns a promise that will fulfill with a new <code>Blob</code> object representing a file
containing the image in the <code>OffscreenCanvas</code> object.</p>

<p>The argument, if provided, is a dictionary that controls the encoding options of the image
file to be created. The <code data-x="image-encode-options-type">type</code>
field specifies the file format and has a default value of "<code>image/png</code>"; that type
is also used if the requested type isn't supported. If the image format supports variable
quality (such as "<code>image/jpeg</code>"), then the <code
data-x="image-encode-options-quality">quality</code> field is a number in the range 0.0
to 1.0 inclusive indicating the desired quality level for the resulting image.</p>
</dd>

<dt><var>canvas</var> . <code subdfn
data-x="dom-OffscreenCanvas-transferToImageBitmap">transferToImageBitmap</code>()</dt>

<dd>
<p>Returns a newly created <code>ImageBitmap</code> object with the image in the
<code>OffscreenCanvas</code> object. The image in the <code>OffscreenCanvas</code> object is
replaced with a new blank image.</p>
</dd>

</dl>

<div w-nodev>

<p>The <dfn><code
data-x="dom-OffscreenCanvas-convertToBlob">convertToBlob(<var>options</var>)</code></dfn> method,
when invoked, must run the following steps:</p>

<ol>
<li><p>If the value of this <code>OffscreenCanvas</code> object's <span>[[Detached]]</span>
internal slot is set to true, then return a promise rejected with an
<span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.</p></li>

<li><p>If this <code>OffscreenCanvas</code> object's <span
data-x="offscreencanvas-context-mode">context mode</span> is <span
data-x="offscreencanvas-context-2d">2d</span> and the rendering context's <span
data-x="offscreencontext2d-bitmap">bitmap</span>'s <span
data-x="offscreencontext2d-origin-clean">origin-clean</span> flag is set to false, then return a
promise rejected with a <span>"<code>SecurityError</code>"</span> <code>DOMException</code>.</p>

<li><p>If this <code>OffscreenCanvas</code> object's <span
data-x="offscreencanvas-bitmap">bitmap</span> has no pixels (i.e., either its
horizontal dimension or its vertical dimension is zero) then return a promise rejected with an
<span>"<code>IndexSizeError</code>"</span> <code>DOMException</code>.</p></li>

<li><p>Let <var>bitmap</var> be a copy of this <code>OffscreenCanvas</code> object's <span
data-x="offscreencanvas-bitmap">bitmap</span>.</p></li>

<li><p>Let <var>result</var> be a new promise object.</p></li>

<li>
<p>Run these steps <span>in parallel</span>:</p>

<ol>
<li><p>Let <var>file</var> be <span data-x="a serialization of the bitmap as a file">a
serialization of <var>bitmap</var> as a file</span>, with <var>options</var>'s <dfn><code
data-x="image-encode-options-type">type</code></dfn> and <dfn><code
data-x="image-encode-options-quality">quality</code></dfn>.</p></li>

<li>
<p><span>Queue a task</span> to run these steps:</p>

<ol>
<li><p>If <var>file</var> is null, then reject <var>result</var> with an
<span>"<code>EncodingError</code>"</span> <code>DOMException</code>.</p></li>

<li><p>Otherwise, resolve <var>result</var> with a new <code>Blob</code> object, created in
the <span data-x="concept-relevant-realm">relevant Realm</span> of this
<code>OffscreenCanvas</code> object, representing <var>file</var>. <ref
spec=FILEAPI></p></li>
</ol>

<p>The <span>task source</span> for this task is the <span>canvas blob serialization task
source</span>.</p>
</li>
</ol>
</li>

<li><p>Return <var>result</var>.</p></li>
</ol>

<p>The <dfn><code
data-x="dom-OffscreenCanvas-transferToImageBitmap">transferToImageBitmap()</code></dfn> method,
when invoked, must run the following steps:</p>
Expand Down

0 comments on commit 9ec7c9e

Please sign in to comment.