Skip to main content

Image

Struct Image 

Source
pub struct Image { /* private fields */ }
Expand description

A raster image. RGBA pixels (see PixelFormat) tagged with the ColorSpace they were authored in; top-left origin, row-major. Cheap Arc-backed clone; backends key their texture cache off Self::content_hash so two equal Images share a GPU slot.

Implementations§

Source§

impl Image

Source

pub fn from_rgba8(width: u32, height: u32, pixels: Vec<u8>) -> Self

Build from sRGB-encoded RGBA8 pixels — the common case for decoded PNG/JPEG art. Panics if pixels.len() != width * height * 4. Untagged 8-bit sources should use this (the web’s convention for untagged images is sRGB).

Source

pub fn from_rgba8_in( space: ColorSpace, width: u32, height: u32, pixels: Vec<u8>, ) -> Self

Build from RGBA8 pixels authored in space — e.g. ColorSpace::DISPLAY_P3 for a P3-tagged JPEG. Panics if pixels.len() != width * height * 4.

Source

pub fn from_rgba16_in( space: ColorSpace, width: u32, height: u32, pixels: Vec<u16>, ) -> Self

Build from 16-bit unsigned-normalized RGBA pixels authored in space — e.g. a 16-bit PNG. Panics if pixels.len() != width * height * 4 (u16 channel values, not bytes).

Source

pub fn from_rgba_f16_bits_in( space: ColorSpace, width: u32, height: u32, bits: Vec<u16>, ) -> Self

Build from half-float RGBA pixels given as raw IEEE 754 bit patterns (the shape most decoders hand f16 data in) authored in space. Panics if bits.len() != width * height * 4.

Source

pub fn from_rgba_f32_in( space: ColorSpace, width: u32, height: u32, pixels: Vec<f32>, ) -> Self

Build from f32 RGBA pixels authored in space — e.g. a decoded EXR in ColorSpace::SCRGB_LINEAR. Panics if pixels.len() != width * height * 4.

Source

pub fn width(&self) -> u32

Source

pub fn height(&self) -> u32

Source

pub fn format(&self) -> PixelFormat

Source

pub fn color_space(&self) -> ColorSpace

The color space the pixel values were authored in.

Source

pub fn pixels(&self) -> &[u8]

Raw pixel bytes, length width * height * format().bytes_per_pixel(), native-endian. Top-left origin.

Source

pub fn is_srgb8(&self) -> bool

True when the pixel buffer can upload directly to an 8-bit sRGB texture and let the sampler decode — RGBA8 in the default ColorSpace::SRGB. Everything else goes through Self::to_scrgb_f16.

Source

pub fn to_scrgb_f16(&self) -> Vec<u16>

Convert to linear sRGB-primaries extended-range (“scRGB”) half-float pixels for GPU upload: RGBA interleaved, width * height * 4 raw f16 bit patterns, alpha unchanged (straight, not premultiplied — the image shader premultiplies at blend).

This is the working-space representation every renderer composites in, so sampling needs no further conversion. Wide-gamut primaries land outside [0, 1] and HDR brights above 1.0; both survive on float textures.

§Luminance contract

Working-space 1.0 displays at the output’s reference white (the renderer scales to the swapchain’s encoding, e.g. white_scale on scRGB). Relative transfers (sRGB, gamma, linear) already encode 1.0 = reference white and convert as-is. PQ is absolute (signal 1.0 = 10000 nits), so this conversion anchors it: a pixel at the source’s reference_luminance_nits (203 for ColorSpace::BT2020_PQ, per BT.2408) converts to working-space 1.0, and a 1000-nit highlight lands at ~4.9× — HDR headroom the per-image remaster grades into the panel’s volume (see DynamicRangeLimit). HLG is scene-referred and currently decodes without an OOTF or anchoring — its contract is still open. Note crate::color::Color conversion does not anchor PQ (UI colors stay encoding-literal); the anchor is an image-pipeline behavior.

Source

pub fn to_scrgb_f16_with_peak(&self) -> (Vec<u16>, f32)

Self::to_scrgb_f16 plus the image’s measured content peak: the maximum linear RGB channel value over all pixels, in working-space units (1.0 = reference white). For a still image this is its effective MaxCLL — backends cache it per texture and feed it to the luminance remaster (see DynamicRangeLimit and docs/COLOR_MANAGEMENT.md). Alpha is ignored (the remaster runs on straight rgb before the blend premultiply). Non-finite channel values are skipped.

Source

pub fn content_hash(&self) -> u64

Stable hash of (width, height, format, color_space, pixels). Backends use this as the key into their per-image texture cache.

Source

pub fn label(&self) -> String

Short hex label for inspection / dump output, e.g. "image:1a2b3c4d".

Trait Implementations§

Source§

impl Clone for Image

Source§

fn clone(&self) -> Image

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Image

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Image

Source§

impl PartialEq for Image

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl Freeze for Image

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnsafeUnpin for Image

§

impl UnwindSafe for Image

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.