Bug 188347

Summary: Calling .decode() on Image instance referencing an SVG throws an EncodingError
Product: WebKit Reporter: Marcel Miranda <m>
Component: DOMAssignee: Said Abou-Hallawa <sabouhallawa>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: cdumez, dino, sabouhallawa, simon.fraser
Priority: P2    
Version: Safari 11   
Hardware: Mac   
OS: Unspecified   

Description Marcel Miranda 2018-08-06 07:47:25 PDT
Calling the decode method on an Image instance referencing a SVG file throws an EncodingError exception

I've created a small reproducible environment here: https://codesandbox.io/s/xl6mq18704

Code to replicate

```
function loadImage(src, onLoad) {
  var image = new window.Image();
  image.onload = function(e) {
    image.decode().then(() => onLoad(e)); 
  };
  image.src = src;
  return image;
}

loadImage('https://xl6mq18704.codesandbox.io/img/refresh.svg', (e) => document.body.appendChild(e.target))

```
Comment 1 Said Abou-Hallawa 2018-08-06 09:38:28 PDT
According to the specs https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element, the description of the decode() method is the following:

image . decode()
This method causes the user agent to decode the image in parallel, returning a promise that fulfills when decoding is complete.

The promise will be rejected with an "EncodingError" DOMException if the image cannot be decoded.

Image encoding is the process of compressing the image pixels data into a specialized format for efficient transmission or storage.  Image decoding is the opposite process -- the conversion of an encoded format back into the original pixels data format.

It is clear that The SVG image is not represented in pixels format and it is not saved in compressed format, unless it is a base-64 data URL. But the decoding of the base-64 data URL is different from the HTMLImageElement.deocde() and it is done implicitly as part of loading the SVG image sub-resource.

So I think there is no bug here.
Comment 2 Simon Fraser (smfr) 2018-08-06 11:14:51 PDT
I think SVG should fall into the "If decoding does not need to be performed for this image (for example because it is a vector graphic), resolve promise with undefined." case, not the exception throwing case.
Comment 3 Said Abou-Hallawa 2019-09-01 13:14:40 PDT

*** This bug has been marked as a duplicate of bug 201243 ***