Skip to main content

Module display

Module display 

Source
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 DisplayTarget is 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, LinearSrgb by default) turns scene pixels into a Stage for 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::Display of 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§

DisplayTarget
What a window’s surface expects.
ImageSurface
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.
LinearSrgb
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§

ColorSpace
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.
SurfaceFormat
The surface’s pixel format, as configured.
TargetSource
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§

DisplayTransform
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_surface for 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_display hook).
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).