Skip to content

Commit 05525c8

Browse files
vmpstrannevk
authored andcommitted
Add <img decoding>
The decoding attribute indicates a decoding hint to the user agent. This hint aids the user agent in deciding how to process and decode the image before rasterizing it. Possible values are as follows: * "sync": prefer to decode the image synchronously for atomic presentation with other content * "async": prefer to decode the image asynchronously to reduce delay in presenting other content * "auto": default mode, which indicates no preference for the decoding mode. Fixes #1920.
1 parent 7567c80 commit 05525c8

File tree

1 file changed

+95
-9
lines changed

1 file changed

+95
-9
lines changed

source

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25403,6 +25403,7 @@ interface <dfn>HTMLSourceElement</dfn> : <span>HTMLElement</span> {
2540325403
<dd><code data-x="attr-dim-width">width</code></dd>
2540425404
<dd><code data-x="attr-dim-height">height</code></dd>
2540525405
<dd><code data-x="attr-img-referrerpolicy">referrerpolicy</code></dd>
25406+
<dd><code data-x="attr-img-decoding">decoding</code></dd>
2540625407
<dt><span data-x="concept-element-dom">DOM interface</span>:</dt>
2540725408
<dd w-nodev>
2540825409
<pre class="idl">[Exposed=Window,
@@ -25423,6 +25424,7 @@ interface <dfn>HTMLImageElement</dfn> : <span>HTMLElement</span> {
2542325424
readonly attribute boolean <span data-x="dom-img-complete">complete</span>;
2542425425
readonly attribute USVString <span data-x="dom-img-currentSrc">currentSrc</span>;
2542525426
[<span>CEReactions</span>] attribute DOMString <span data-x="dom-img-referrerPolicy">referrerPolicy</span>;
25427+
[<span>CEReactions</span>] attribute DOMString <span data-x="dom-img-decoding">decoding</span>;
2542625428

2542725429
Promise&lt;void&gt; <span data-x="dom-img-decode">decode</span>();
2542825430
};</pre>
@@ -25492,6 +25494,12 @@ interface <dfn>HTMLImageElement</dfn> : <span>HTMLElement</span> {
2549225494
<span>referrer policy attribute</span>. Its purpose is to set the <span>referrer policy</span>
2549325495
used when <span data-x="concept-fetch">fetching</span> the image. <ref spec=REFERRERPOLICY></p>
2549425496

25497+
<p>The <dfn data-x="attr-img-decoding"><code>decoding</code></dfn> attribute indicates the
25498+
preferred method to <span data-x="img-decoding-process">decode</span> this image. The attribute,
25499+
if present, must be an <span>image decoding hint</span>. This attribute's <i data-x="missing value
25500+
default">missing value default</i> and <i data-x="invalid value default">invalid value
25501+
default</i> are both the <span data-x="attr-img-decoding-auto-state">auto</span> state.</p>
25502+
2549525503
<hr>
2549625504

2549725505
<p>The <code>img</code> element must not be used as a layout tool. In particular, <code>img</code>
@@ -25676,6 +25684,10 @@ interface <dfn>HTMLImageElement</dfn> : <span>HTMLElement</span> {
2567625684
<span>reflect</span> the <code data-x="attr-img-referrerpolicy">referrerpolicy</code>
2567725685
content attribute, <span>limited to only known values</span>.</p>
2567825686

25687+
<p>The <dfn><code data-x="dom-img-decoding">decoding</code></dfn> IDL attribute must
25688+
<span>reflect</span> the <code data-x="attr-img-decoding">decoding</code> content
25689+
attribute, <span>limited to only known values</span>.
25690+
2567925691
</div>
2568025692

2568125693
<dl class="domintro">
@@ -25723,17 +25735,20 @@ interface <dfn>HTMLImageElement</dfn> : <span>HTMLElement</span> {
2572325735

2572425736
</dd>
2572525737

25726-
<dt><var>image</var> . <code subdfn data-x="dom-img-decode">decode</code>()</dt>
25738+
<dt><var>image</var> . <code subdfn data-x="dom-img-decoding">decoding</code></dt>
2572725739

2572825740
<dd>
2572925741

25730-
<p>Images usually exist in some encoded form; user agents need to decode them into raw pixels
25731-
before displaying them. This process can be relatively expensive.</p>
25742+
<p>Returns the <span>image decoding hint</span> set for this image.</p>
25743+
25744+
</dd>
25745+
25746+
<dt><var>image</var> . <code subdfn data-x="dom-img-decode">decode</code>()</dt>
2573225747

25733-
<p>This method causes the user agent to decode the image <span>in parallel</span>, returning a
25734-
promise that fulfills when decoding is complete. The decoded image data will then be readily
25735-
available for at least one frame after the fulfillment, ensuring that attempting to display the
25736-
image will complete without decoding delay.</p>
25748+
<dd>
25749+
25750+
<p>This method causes the user agent to <span data-x="img-decoding-process">decode</span> the
25751+
image <span>in parallel</span>, returning a promise that fulfills when decoding is complete.</p>
2573725752

2573825753
<p>The promise will be rejected with an <span>"<code>EncodingError</code>"</span>
2573925754
<code>DOMException</code> if the image cannot be decoded.</p>
@@ -25869,8 +25884,7 @@ img.decode();</pre>
2586925884
available</span></dt>
2587025885

2587125886
<dd>
25872-
<p>Decode the image's media data entirely into its bitmap form, suitable for rapid painting
25873-
to the screen.</p>
25887+
<p><span data-x="img-decoding-process">Decode</span> the image.</p>
2587425888

2587525889
<p>If decoding does not need to be performed for this image (for example because it is a
2587625890
vector graphic), resolve <var>promise</var> with undefined.</p>
@@ -27021,6 +27035,70 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2702127035
images</span> but could keep the image data separately, and use that if the server responds with a
2702227036
<code data-x="">304 Not Modified</code> status.</p>
2702327037

27038+
<h6>Decoding images</h6>
27039+
27040+
<p>Image data is usually encoded in order to reduce file size. This means that in order for the
27041+
user agent to present the image to the screen, the data needs to be decoded.
27042+
<dfn data-x="img-decoding-process">Decoding</dfn> is the process which converts an image's media
27043+
data into a bitmap form, suitable for presentation to the screen. Note that this process can be
27044+
slow relative to other processes involved in presenting content. Thus, the user agent can choose
27045+
when to perform decoding, in order to create the best user experience.</p>
27046+
27047+
<p>Image decoding is said to be synchronous if it prevents presentation of other content until it
27048+
is finished. Typically, this has an effect of atomically presenting the image and any other
27049+
content at the same time. However, this presentation is delayed by the amount of time it takes to
27050+
perform the decode.</p>
27051+
27052+
<p>Image decoding is said to be asynchronous if it does not prevent presentation of other content.
27053+
This has an effect of presenting non-image content faster. However, the image content is missing
27054+
on screen until the decode finishes. Once the decode is finished, the screen is updated with the
27055+
image.</p>
27056+
27057+
<p>In both synchronous and asynchronous decoding modes, the final content is presented to screen
27058+
after the same amount of time has elapsed. The main difference is whether the user agent presents
27059+
non-image content ahead of presenting the final content.</p>
27060+
27061+
<p>In order to aid the user agent in deciding whether to perform synchronous or asynchronous
27062+
decode, the <code data-x="attr-img-decoding">decoding</code> attribute can be set on
27063+
<code>img</code> elements. The possible values of of the <code
27064+
data-x="attr-img-decoding">decoding</code> attribute are the following <dfn>image decoding
27065+
hint</dfn> keywords:</p>
27066+
27067+
<table>
27068+
<thead>
27069+
<tr>
27070+
<th>Keyword
27071+
<th>State
27072+
<th>Description
27073+
<tbody>
27074+
<tr>
27075+
<td><dfn><code data-x="attr-img-decoding-sync">sync</code></dfn>
27076+
<td><dfn data-x="attr-img-decoding-sync-state">Sync</dfn>
27077+
<td>Indicates a preference to <span data-x="img-decoding-process">decode</span> this image
27078+
synchronously for atomic presentation with other content.
27079+
<tr>
27080+
<td><dfn><code data-x="attr-img-decoding-async">async</code></dfn>
27081+
<td><dfn data-x="attr-img-decoding-async-state">Async</dfn>
27082+
<td>Indicates a preference to <span data-x="img-decoding-process">decode</span> this image
27083+
asynchronously to avoid delaying presentation of other content.
27084+
<tr>
27085+
<td><dfn><code data-x="attr-img-decoding-auto">auto</code></dfn>
27086+
<td><dfn data-x="attr-img-decoding-auto-state">Auto</dfn>
27087+
<td>Indicates no preference in decoding mode (the default).
27088+
</table>
27089+
27090+
<p>When <span data-x="img-decoding-process">decoding</span> an image, the user agent should
27091+
respect the preference indicated by the <code data-x="attr-img-decoding">decoding</code>
27092+
attribute's state. If the state indicated is <span
27093+
data-x="attr-img-decoding-auto-state">auto</span>, then the user agent is free to choose any
27094+
decoding behavior.</p>
27095+
27096+
<p class="note">It is also possible to control the decoding behavior using the <code
27097+
data-x="dom-img-decode">decode()</code> method. Since the <code
27098+
data-x="dom-img-decode">decode()</code> method performs <span
27099+
data-x="img-decoding-process">decoding</span> independently from the process responsible for
27100+
presenting content to screen, it is unaffected by the <code
27101+
data-x="attr-img-decoding">decoding</code> attribute.</p>
2702427102

2702527103
<h6>Updating the image data</h6>
2702627104

@@ -115915,6 +115993,7 @@ interface <dfn>External</dfn> {
115915115993
<code data-x="attr-img-ismap">ismap</code>;
115916115994
<code data-x="attr-dim-width">width</code>;
115917115995
<code data-x="attr-dim-height">height</code>;
115996+
<code data-x="attr-img-decoding">decoding</code>;
115918115997
<code data-x="attr-img-referrerpolicy">referrerpolicy</code></td>
115919115998
<td><code>HTMLImageElement</code></td>
115920115999
</tr>
@@ -117469,6 +117548,13 @@ interface <dfn>External</dfn> {
117469117548
<span>valid week string</span>,
117470117549
<span>valid non-negative integer</span>, or
117471117550
<span>valid duration string</span>
117551+
<tr>
117552+
<th> <code data-x="">decoding</code>
117553+
<td> <code data-x="attr-img-decoding">img</code>
117554+
<td> Decoding hint to use when processing this image for presentation
117555+
<td> "<code data-x="attr-img-decoding-sync">sync</code>";
117556+
"<code data-x="attr-img-decoding-async">async</code>";
117557+
"<code data-x="attr-img-decoding-auto">auto</code>"
117472117558
<tr>
117473117559
<th> <code data-x="">default</code>
117474117560
<td> <code data-x="attr-track-default">track</code>

0 commit comments

Comments
 (0)