KhronosGroup / KhronosGroup/WebGL

Tighten DOM uploads from PNG

Open
#2,789 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
2.9k
Forks
703
Avg merge
2d 9h
Merged PRs (30d)
4

Description

PNG images can contain various combinations of channels and bit depths. The WebGL 2.0 spec should disallow certain ambiguous cases or clearly describe the behavior. Namely:

### Components
Texels in PNG image can be:
- Grayscale (one component)
- Grayscale with alpha (two components)
- RGB (three components)
- RGBA (four components)

#### Expectations:
- Grayscale
- fills R as R001, RG as RR01, RGB as RRR1, and LUMINANCE as RRR1;
- fills RGBA and LUMINANCE_ALPHA as RRR1;
- fills ALPHA as 0001.
- Grayscale with alpha
- fills R as R001, RG as RR01, RGB as RRR1, and LUMINANCE as RRR1; source alpha values are lost;
- fills RGBA and LUMINANCE_ALPHA as RRRA;
- fills ALPHA as 000A.
- RGB
- fills R as R001, RG as RG01, RGB as RGB1, and RGBA as RGBA;
- fills LUMINANCE and LUMINANCE_ALPHA as RRR1;
- fills ALPHA as 0001.
- RGBA
- fills R as R001, RG as RG01, RGB as RGB1, and RGBA as RGBA;
- fills LUMINANCE as RRR1 and LUMINANCE_ALPHA as RRRA;
- fills ALPHA as 000A.

### Bit Depth
PNG files can have up to 16 bits per channel (in all four modes above). In addition to that, PNG files can define how many [_significant_ bits](https://www.w3.org/TR/2003/REC-PNG-20031110/#11sBIT) each channel has. Here are some implications of this for GPU uploads.

#### Floating point
```
R32F/RG32F/RGB32F/RGBA32F
R16F/RG16F/RGB16F/RGBA16F
R11F_G11F_B10F
RGB9_E5
```
These should have no ambiguities with taking normalized floating point (`0.0 .. 1.0`) values from PNG decoder. Conformance tests should ensure expected target precision.

#### Unsigned integers
```
R8UI/RG8UI/RGB8UI/RGBA8UI
RGB10_A2UI
R16UI/RG16UI/RGB16UI/RGBA16UI
R32UI/RG32UI/RGB32UI/RGBA32UI
```
A WebGL implementation could fill GPU texels with source integer values (multiplied by bit-mask based on the number of significant bits per channel), if PNG decoder provides such information. Otherwise, all uploads to unsigned integers (including 8 bit) should be disallowed.

#### Normalized 8-bit
```
LUMINANCE/ALPHA/LUMINANCE_ALPHA
R8/RG8/RGB8/RGBA8
SRGB8/SRGB8_ALPHA8
```
There is a clear fast path for source data with 8 bits in all channels. Other cases may require renormalization.

#### Normalized 10-bit
```
RGB10_A2
```
There could be a fast path for PNG files with the same per-channel bit depth (10-10-10-2). Otherwise, texels need to be carefully converted to maintain precision.

### Color space
PNG files can define:
- [Primary chromaticities and white point](https://www.w3.org/TR/2003/REC-PNG-20031110/#11cHRM)
- [Image gamma](https://www.w3.org/TR/2003/REC-PNG-20031110/#11gAMA)
- [Embedded ICC profile](https://www.w3.org/TR/2003/REC-PNG-20031110/#11iCCP)
- [sRGB Rendering Intent](https://www.w3.org/TR/2003/REC-PNG-20031110/#11sRGB)

When `UNPACK_COLORSPACE_CONVERSION_WEBGL` is set to `NONE`, these four PNG chunks should be ignored.

---

Which of statements above (assuming they are accurate) require spec or conformance suite updates?

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the WebGL 2.0 specification and the conformance suite in light of the PNG component, bit-depth, and color-space cases listed here. Determine which statements require normative specification text and which require conformance coverage; done means the required updates are clearly identified and scoped.

Written by the indexing model from the issue text.

Assessment

Domain
documentation, testing-qa
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.