Discussion:
[png-mng-misc] Image variants or sets and addressing fragments (fMAP, fcTL, fdAT, aPAL)
Christoph Päper
2017-05-08 11:26:25 UTC
Permalink
There are several reasons why and methods how people are putting multiple still
images into a single file. PNG currently only supports some of them and only
indirectly.

Some use cases frequently require several very similar still bitmap images. They
may only differ in a single color being substituted, which may be the background
color or any other, or in a different palette being used which may be shared by
several images. They may also differ simply by size or color mode, where lower
resolution or low-fidelity versions are not necessarily the results of simple
algorithmic transformations from the largest, most colorful image, cf. the ICO
and other icon formats.

I'm not at all interested in backporting everything found in MNG to PNG, but I
only want PNG to

1. better support techniques already employed and
2. support multiple related variants of a semantically identical image.

Sprite maps
------------

Regarding goal #1, PNGs are regularly used to contain a set of small images in a
so-called sprite map (e.g. for a collection of emojis). Serving a single sprite
map instead of many individual image files is more efficient when using HTTP
1.x. The authors of the MNG specification anticipated this use case when they
wrote [Example 17: Storing an icon
library](http://www.libpng.org/pub/mng/spec/#x17).

In a sprite map, each icon is put into a virtual cell in a grid of vertical
columns and horizontal rows. Their numbers and dimensions must be known and used
externally. In CSS, this is traditionally achieved by using the
`background-position` property for a PNG file included with the
`background-image` property, but the recently added [`image()`
notation](https://www.w3.org/TR/css3-images/#image-fragments) also requires
support for spatial [Media Fragments], i.e.
`#xywh=pixel:left-offset,top-offset,width,height` (`pixel:` is optional and
`percent:` is also supported), which has some advantages, e.g. for repeated
tiles. The [Media Fragments
specification](https://www.w3.org/TR/media-frags/#naming-space), however,
suggested that owners of media types like `image/png` (see [RFC2083]) should
formally update their registration to include the `xywh` URL fragment (and/or
The Media Fragment WG has no authority to update registries of all targeted
media types.
We recommend media type owners to harmonize their existing schemes with the
ones proposed in this document
and update or add the fragment semantics specification to their media type
registration.
It would be even more user-friendly if authors could reference sprites by a
semantic name. The `IDAT` image resource within a PNG file does not have a
natural language name, let alone multiple ones for arbitrary slices of it. I am
proposing a new `fMAP` chunk below which may be able to achieve this, see the
Github repository for details. I'm *not* proposing a method to directly
reference cells in a grid, e.g. `#cell=2,6` or `#col=2;row=6`.

<https://github.com/Crissov/PNG-extensions/blob/master/fcTL%2BfdAT.md>
<https://github.com/Crissov/PNG-extensions/blob/master/fMAP.md>

Please note that MNG does already support arbitrarily named views using the
[`eXPI` chunk](http://www.libpng.org/pub/mng/spec/#mng-eXPI), but that adds some
The eXPI chunk takes a snapshot of a viewable object (either concrete or
abstract),
associates the name with that snapshot,
and makes the name available to the "outside world" (like a scripting
language).
Sprite stack
------------

Sprite maps fall back to a planar overview of all available sprites. This is not
desired in cases where there is a default image that has several variants. Emoji
images of people, for instance, should usually come in a default gender-neutral,
a female and a male variant, often identified either by a prefix `1f469`/`1F468`
or a suffix `-2640`/`_2642` that is based upon the respective hexadecimal
Unicode code point. Another example are "High DPI" or "Retina ready" bitmaps
that come in multiple resolutions, which are either referred to by the pixel
dimensions or by a (usually integer) scaling factor like `2x` that is often
preceded by an at-sign in the file name, e.g. `***@2x.png`, but other
conventions also exist. A third use case is found in internationalization (i18n)
or rather localization (l10n): some PNG files contain text and variants exists
for other languages, which are currently often recorded in separate files with
multiple dot-lead extensions based upon [BCP47], e.g. `map.en-us.png`.

The default graphic should be found in `IDAT` chunks, but vanilla PNG does not
have anything to put the alternatives in. I propose to take advantage of support
in existing implementations by adopting the `fdAT` and `fcTL` chunks for this,
which were introduced in the unofficial [APNG] extension currently maintained by
Mozilla. Its proprietary `acTL` is not needed for this, because I'm *not*
proposing to add animation support to PNG.

The `fcTL` chunk type is only needed for unique numeric identifiers for each
fragment, but I maintained compatibility with APNG by declaring some bytes
reserved for future use. This means, `foo.png#2` should work, but, again, named
fragments would be more user friendly, so the proposed `fMAP` chunk also applies
to sprite stacks, so `dancing_emoji.png#male`, `icon.png#@3x` and
`screenshot.png#UHD` would work. To make i18n more automatic, i.e. requiring
less effort, `fMAP` should also support language tags, so implementations would,
for instance, transparently and implicitly select `map.png#lang=en` if the
embedding environment of the PNG file is tagged as `en-us`, while authors could
still explicitly choose `map.png#french`.

<https://github.com/Crissov/PNG-extensions/blob/master/fcTL%2BfdAT%2BfMAP.md>

Layers
---------

Layers are a can of worms that I don't want to open right now, but do think
needs mentioning.

A sprite stack where the default `IDAT` image has the largest dimensions and all
`fdAT` fragments are partially transparent and all these chunks would be
rendered at once would constitute a simple open layered image format with `IDAT`
as the first or background layer. To be really useful, `fcTL` or another chunk
type would need to learn to specify blending modes etc. This is stuff for a
potential PNG 2.0, because the fallback to just the background seems inadequate
in general.

Palette manipulation
------------

Some image variants do not need additional bitmap data chunks at all. For
example, each emoji that shows a body part or complete person comes in six
variations for skin tones: non-human default, Fitzpatrick scale 1-2, 3, 4, 5 and
6 (darkest). Hair color and possibly eye color may also change with the
complexion, but overall it's just about replacing the color values for some
palette entries.

PNG already supports suggested palettes with the `sPLT` chunk (and `PLTE`+`hIST`
for the default), which can even be named, but these are tailored for dithering
of true-color images on limited-color devices. I'm proposing to add a new `aPLT`
chunk type with almost identical syntax to `sPLT` which would be used replace
`PLTE` in color modes that use this chunk if requested by the user, e.g. via
fragment identifiers `baby.png#pal=dark`.

<https://github.com/Crissov/PNG-extensions/blob/master/aPLT.md>

References
-------------

[Media Fragments]: https://www.w3.org/TR/media-frags/
[RFC2083]: https://tools.ietf.org/html/rfc2083#section-8 "RFC 2083: PNG
(Portable Network Graphics) Specification Version 1.0 (1997-03), section 8.2.
Internet media type"
[APNG]: https://wiki.mozilla.org/APNG_Specification
[BCP47]: https://tools.ietf.org/html/bcp47
Matthias B.
2017-05-08 14:38:48 UTC
Permalink
On Mon, 8 May 2017 13:26:25 +0200 (CEST)
Post by Christoph Päper
There are several reasons why and methods how people are putting
multiple still images into a single file. PNG currently only supports
some of them and only indirectly.
1. better support techniques already employed and
2. support multiple related variants of a semantically identical image.
In order for your suggested features to be useful on the web, there
would have to be corresponding CSS selectors and/or DOM objects. Are
you in contact with the relevant W3C groups? I don't think there's any
point in the PNG/MNG group making the first step here without any
support from the major players on the web.

For anything that's not the web, private chunks are the way to go.

MSB
--
My hovercraft is full of eels.
Christoph Päper
2017-05-09 07:57:21 UTC
Permalink
Post by Matthias B.
In order for your suggested features to be useful on the web, there
would have to be corresponding CSS selectors and/or DOM objects. Are
you in contact with the relevant W3C groups? I don't think there's any
point in the PNG/MNG group making the first step here without any
support from the major players on the web.
As a matter of fact, I am indeed in contact with the CSS WG and WhatWG (for
different matters), but nothing of what I'm proposing here requires any changes
in or additions to CSS, DOM, JS, HTML, ... or even URL
<https://url.spec.whatwg.org/>. Wherever image resources are referenced by URL,
fragment identifiers are already supported transparently, i.e. it's the job of
the image renderer to deal with that information. Except for Microsoft, all
major browser vendors are now supporting APNG <http://caniuse.com/#feat=apng>
and thus `fdAT` and `fcTL` are already widely implemented. Only `fMAP` is
entirely new (and needs some work). `aPLT` is much like `sPLT` syntax-wise, but
has different semantics and implications. Nevertheless, the new sprite stack and
palette manipulation features I'm proposing are designed to have useful fallback
behavior. Sprite maps, which are already widely used, have no good fallback or
addressing interface, but CSS requiring spatial Media Fragments support for
`image()` notation <https://drafts.csswg.org/css-images-4/#image-fragments>
makes them much more useful on the web.

background-image: url('swirl.png'); /* old UAs */
background-image: image('sprites.png#xywh=10,30,60,20'); /* new UAs */

That being said, now would be the perfect time to get a note or example
regarding named subimages in PNG added to css-images which would certainly
improve the adoption rate (once approved as an extension by the PNG Group).
Post by Matthias B.
For anything that's not the web, private chunks are the way to go.
Everything ends up on the web (or at least in browsers) nowadays.

JFTR, I'm trying to get all of this added to PNG proper, because I think it's
well in scope, but if that fails I will take it to APNG, which will hopefully
move to a location with defined specification process soon (e.g. WhatWG).
GLENN PEHRSON
2017-05-26 18:01:35 UTC
Permalink
It has been more than two weeks and there has been no helpful feedback and hardly any at all. Is the proposal too bad, too good, too weird, too long ... or this list just the wrong place?
Instead of enhancing APNG, I'd consider enhancing the mPNG proposal

(ftp://ftp.simplesystems.org/pub/png-group/documents/history/png-mpng-proposal-20070411.txt)

by adding a name field to the tile structure.


Glenn
John Bowler
2017-05-26 19:45:45 UTC
Permalink
In my opinion one of Matthias's comments is particularly wise:

[For anything that's not the web,] private chunks are the way to go.

I wouldn't exclude "anything on the web" either; an independent authority
can standardize a private chunk, just as JEITA standardized an APP marker
for EXIF in JPEG (APP markers in JPEG correspond to PNG private chunks.)

Anyone can create and use a private chunk. Private chunks can be
publically documented and even if they are not will probably be
reverse-engineered if they come into wide-spread use.

W3C is certainly the body that should be defining web-specific PNG chunks
if and when they are required and, while it might be polite to post a
message here to say this is happening, any debate should happen in the
appropriate W3C forum.

At some point if multiple private chunks exist to define the same
information I can see that this group might need to vote on a public chunk
with a common format but I'm not aware of any case where that been
necessary to date.
--
John Bowler <***@gmail.com>
+1 (541) 450-9885
PO BOX 3151
KERBY OR 97531-3151
USA
Christoph Päper
2017-05-28 19:06:19 UTC
Permalink
Post by GLENN PEHRSON
Instead of enhancing APNG, I'd consider enhancing the mPNG proposal
by adding a name field to the tile structure.
`mpNG` would be an alternative solution to the Sprite Map use case and probably better than `fmAP`, which is the part of my proposal that is the least thought through. I only included `fmAP` for sprite maps for completeness. Sprite maps already become more usable with Media Fragments, but named slices/cells would be really nice. Alas, MPNG would be another animation format when all that was needed were addressable parts of a still picture. I omitted `acTL` from APNG on purpose, because without it, `fcTL` and `fdAT` do not constitute animation data and thus might be accepatble for the majority of PNG Group members.
Matthias B.
2017-05-27 11:36:01 UTC
Permalink
It would help if you implemented prototype code as patch for libpng,
preferably in a way that can be IFDEFd out.

MSB

On Fri, 26 May 2017 15:40:30 +0200 (CEST)
It has been more than two weeks and there has been no helpful
feedback and hardly any at all. Is the proposal too bad, too good,
too weird, too long ... or this list just the wrong place?
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
png-mng-misc mailing list
https://lists.sourceforge.net/lists/listinfo/png-mng-misc
--
Guns don't kill people. Buckyballs kill people.
GLENN PEHRSON
2017-05-27 13:44:22 UTC
Permalink
Post by Matthias B.
It would help if you implemented prototype code as patch for libpng,
preferably in a way that can be IFDEFd out.
Or as a user chunk reader, using
png_set_read_fn(png_ptr, info_ptr, your_read_function)

See my support for private vpAg, caNv, exIf chunks in ImageMagick/GraphicsMagick
for example.

Glenn
Christoph Päper
2017-05-28 19:10:18 UTC
Permalink
Post by GLENN PEHRSON
Post by Matthias B.
It would help if you implemented prototype code as patch for libpng,
I'm not sure my rusty C skills are up to that task.
Post by GLENN PEHRSON
Or as a user chunk reader, using
png_set_read_fn(png_ptr, info_ptr, your_read_function)
Is there a libpng fork with APNG support? It would make sense to build upon that.
Glenn Randers-Pehrson
2017-05-28 19:20:10 UTC
Permalink
In the mozilla/firefox distribution, media/libpng has been patched
to include APNG support. It's based on Max Stepin's APNG project
at SourceForge (which is in turn originally by Andrew Smith as
a Google Summer of Code project).

On Sun, May 28, 2017 at 3:10 PM, Christoph Päper
Post by Christoph Päper
Is there a libpng fork with APNG support? It would make sense to build upon that.
Loading...