Expand description
The display transform: the last step from the source’s pixels to the window, where the application plugs in its colour management.
Experimental: may change in any release
(docs/stability.md).
- A
DisplayTargetis an encoding a surface expects: primaries, transfer, the luminance of SDR white, the headroom above it, the surface format. A window’s surface has one (set_target,target; sRGB until said otherwise, and the GPU path records what eframe configured when it is installed). - The application may want another for a window (
want): Display P3, HDR with PQ or HLG. The viewport then draws for what the surface can carry and says why when that is less (resolve,Resolution): an application declaring a P3 or HDR target gets faithful output where the platform allows it, and a correct sRGB fallback with the reason otherwise. - A
DisplayTransform(the application’s,LinearSrgbby default) turns scene pixels into aStagefor a target: a 3×3 matrix from the working space to the target’s primaries (computed from their chromaticities,Primaries::conversion), a clamp, and the target’s transfer (sRGB, 2.2, extended linear or extended sRGB, SMPTE ST 2084 PQ, BT.2100 HLG). The GPU path runs the stage in its shader; the CPU path (apply_cpu) runs the same arithmetic (Stage::encode) and writes 8-bit sRGB textures, so it always draws sRGB. - A source that does its own transform on the CPU delivers display
pixels (
Pixels::Displayof the tile source) and skips this.
use egui_pop_viewport::display::{DisplayTarget, DisplayTransform, LinearSrgb, Transfer};
let stage = LinearSrgb.stage(&DisplayTarget::srgb());
// Linear 0.5 is sRGB-encoded 188.
assert_eq!(stage.encode_8bit([0.5, 0.5, 0.5]), [188, 188, 188]);
// SDR white at 203 nits is 58 % of the PQ signal (BT.2408).
assert!((Transfer::Pq.encode_at(1.0, 203.0) - 0.5807).abs() < 1e-3);Structs§
- Display
Target - What a window’s surface expects.
- Image
Surface - The image’s own surface in a window, as the image surface layer
decided it (
image_surface, Wayland). - Linear
- Scene pixels in linear RGB of other primaries (a wide working space: linear BT.2020, custom primaries): converted to the target’s primaries, clamped and encoded.
- Linear
Srgb - Scene pixels already in linear sRGB primaries: converted to the target’s primaries, clamped and encoded.
- Matrix
- Scene pixels through a matrix of the application’s to linear sRGB, then to the target’s primaries, clamped and encoded.
- Resolution
- What a window draws for, and why when less than wanted.
- Stage
- The arithmetic of a display transform for one target, as the shader
runs it:
encode(clamp(matrix × rgb)).
Enums§
- Color
Space - The colour space a surface is configured with: how the compositor reads what is written (the colour spaces wgpu configures).
- Fallback
- Why a target is not drawn as wanted.
- Primaries
- The primaries (and white) of an encoding.
- Surface
Format - The surface’s pixel format, as configured.
- Target
Source - Where the target’s description comes from.
- Transfer
- The transfer the shader applies before writing.
Constants§
- D65
- The D65 white point.
- HDR_
REFERENCE_ WHITE - The luminance of SDR white BT.2408 recommends for HDR (nits).
- HLG_
WHITE - The HLG scene light SDR white maps to: the signal 0.75 (BT.2408).
- IDENTITY
- The identity matrix.
Traits§
- Display
Transform - The application’s colour management at the end of the viewport.
Functions§
- apply_
cpu - The CPU path: scene pixels through a transform for a target.
- hlg_
inverse_ oetf - The normalised scene light of an HLG signal (the inverse OETF).
- hlg_
oetf - The HLG signal of normalised scene light (0..1, the BT.2100 OETF).
- image_
surface_ of - What was set with
set_image_surfacefor a window. - pq_
decode - The luminance in nits of a PQ signal.
- pq_
encode - The PQ signal of an absolute luminance in nits.
- resolution
- What the window being drawn draws for: what is wanted against what
its surface expects, on the GPU path when it is installed (as a
viewport resolves it, before its
before_displayhook). - resolve
- What the viewport draws for, given what is wanted, what the surface expects and whether the GPU path runs: the surface’s encoding when it is supported (the stage converts the wanted content into it), sRGB otherwise; the fallback says what is lost.
- set_
default_ target - Sets what every window’s surface expects unless set per window (the GPU path calls it with what eframe configured).
- set_
image_ surface - Sets what a window’s image is drawn into when it has a surface of its own, and why not (or why less than wanted); viewports in that window follow on the next frame.
- set_
target - Sets what a window’s surface expects (for example when its surface or monitor changes, or when the application configured the surface itself). Viewports in that window follow on the next frame and signal it.
- target
- What the surface of the window being drawn expects: what was set for it, else what the GPU path found when installed, else sRGB.
- target_
of - What a window’s image is drawn into: the image’s own surface when it
has one (
set_image_surface), else the window’s surface. - want
- Declares what the application wants for a window: Display P3, HDR.
The viewport draws it when the surface carries it, and says why not
otherwise (
Resolution::fallback). - wanted
- What the application wants for the window being drawn (sRGB until said).
- wanted_
of - What the application wants for a window (sRGB until said).