From 75383fa79838b08a0893a9bb51f25937a09d3e23 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Sun, 24 May 2020 19:41:31 +0300 Subject: [PATCH] Allow an image to indicate its own density and correct its intrinsic size. See https://discourse.wicg.io/t/proposal-exif-image-resolution-auto-and-from-image/4326/24 This proposal allows using EXIF or other metadata to determine an image's default resolution, which may be different from the requested resolution in srcset/image-set, or from the default of 1dppx. The use-case is, for example, allowing serving low-density placeholder in poor network conditions without affecting layout. When an image indicates its intrinsic density-corrected size, that indication is "stronger" than the requested density (current pixel density). This allows, for example, serving a regular 1x image when a 2x image is requested by srcset, allowing for correct presentation of content that contains that information. The WICG proposal defines that in detail - using size+resolution from EXIF when their values are matching. --- source | 54 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/source b/source index 21629cc6be4..968cb504f0f 100644 --- a/source +++ b/source @@ -27246,12 +27246,19 @@ was an English <a href="/wiki/Music_hall">music hall</a> singer, ...Each image request has a current pixel density, which must initially be undefined.

-

When an img element has a current pixel density that is not 1.0, the - element's image data must be treated as if its resolution, in device pixels per CSS pixels, was the current pixel density. The image's - density-corrected intrinsic width and height are the intrinsic width and height after taking into account the current pixel - density.

+

Each img element has preferred density-corrected dimensions, + which must initially be undefined.

+ +

To determine the a density-corrected intrinsic width and height of + img element img: +

    +
  1. Set dim to img's preferred density-corrected dimensions. + +

  2. If dim is not undefined, return dim.

  3. +
  4. Set dim to img's intrinsic dimensions.

  5. +
  6. Divide dim's width and height by img's current pixel density +

  7. Return dim. +

For example, if the current pixel density is 3.125, that means that there are 300 device pixels per CSS inch, and thus if the image @@ -27798,13 +27805,15 @@ was an English <a href="/wiki/Music_hall">music hall</a> singer, ...

  • If the user agent is able to determine image request's image's width and - height, and image request is pending request, set image - request's state to partially - available.

  • + height, and image request is pending request, + update the img metadata and set + image request's state to + partially available.

  • Otherwise, if the user agent is able to determine image request's image's - width and height, and image request is current request, update the - img element's presentation appropriately and set image request's + width and height, and image request is current request, + update the img metadata, and update + the img element's presentation appropriately and set image request's state to partially available.

  • @@ -27894,6 +27903,28 @@ was an English <a href="/wiki/Music_hall">music hall</a> singer, ...

    Let the img element's pending request be null.

    +
    Updating the image metadata
    +

    When asked to update the image metadata for a given img, user agents must do the following:

    + +
      +
    1. Attempt to read EXIF metadata embedded in the image, as defined in the + image codec.

    2. +
    3. If img does not have any EXIF metadata, return.

    4. +
    5. Let img's preferred width correspond to the value of EXIF tag PixelXDimension + (0xa002). If preferred width is not a number between 1 and 65535, return.

    6. +
    7. Let img's preferred height correspond to the value of EXIF tag PixelYDimension + (0xa003).

    8. If preferred width is not a number between 1 and 65535, return.

      +
    9. Let img's resolution unit correspond to the value of EXIF tag ResolutionUnit + (0x0128). If resolution unit is not Inches (2, return.

    10. +
    11. Let img's horizontal resolution correspond to the value of EXIF tag XResolution + (0x011a).

      If horizontal resolution is not a number between 1 and 65535, return.

    12. +
    13. Let img's vertical resolution correspond to the value of EXIF tag YResolution + (0x011b).

      If vertical resolution is not a number between 1 and 65535, return.

    14. +
    15. If img's width in inches divided by horizontal resolution is equal to img's + preferred width, and img's height in inches divided by vertical resolution is equal to img's width, + set img's preferred density-corrected dimensions to img's preferred width and preferred height

    16. . +
    17. Return.

    18. +
    Selecting an image source
    @@ -121464,6 +121495,7 @@ INSERT INTERFACES HERE Nikki Bee, Noah Mendelsohn, Noah Slater, + Noam Rosenthal, Noel Gordon, Nolan Waite, NoozNooz42,