Skip to main content

ViewingCondition

Struct ViewingCondition 

Source
pub struct ViewingCondition {
    pub acuity_ppd: f64,
    pub browser_dppx: Option<f64>,
    pub image_intrinsic_dppx: Option<f64>,
    pub ppd: Option<f64>,
}
Expand description

Viewing condition for perceptual quality assessment.

Models how an image will be viewed, which affects whether compression artifacts will be perceptible.

§Example

use codec_eval::ViewingCondition;

// Desktop viewing with 2x retina display showing a 2x srcset image
let condition = ViewingCondition::desktop()
    .with_browser_dppx(2.0)
    .with_image_intrinsic_dppx(2.0);

// The effective PPD accounts for the srcset ratio
let ppd = condition.effective_ppd();

Fields§

§acuity_ppd: f64

Viewer’s visual acuity in pixels per degree.

This is the baseline PPD for the display and viewing distance. Typical values:

  • Desktop at arm’s length: ~40 PPD
  • Laptop: ~60 PPD
  • Smartphone held close: ~90+ PPD
§browser_dppx: Option<f64>

Browser/OS device pixel ratio.

For retina/HiDPI displays, this is typically 2.0 or 3.0. For standard displays, this is 1.0.

§image_intrinsic_dppx: Option<f64>

Image’s intrinsic pixels per CSS pixel.

For srcset images:

  • A 1x image has intrinsic_dppx = 1.0
  • A 2x image has intrinsic_dppx = 2.0

This affects the effective resolution at which the image is displayed.

§ppd: Option<f64>

Override or computed PPD for this specific viewing.

If Some, this value is used directly instead of computing from the other fields.

Implementations§

Source§

impl ViewingCondition

Source

pub fn new(acuity_ppd: f64) -> Self

Create a new viewing condition with the given acuity PPD.

§Arguments
  • acuity_ppd - The viewer’s visual acuity in pixels per degree.
Source

pub fn desktop() -> Self

Desktop viewing condition (acuity ~40 PPD).

Represents viewing a standard desktop monitor at arm’s length (approximately 24 inches / 60 cm).

Source

pub fn laptop() -> Self

Laptop viewing condition (acuity ~60 PPD).

Represents viewing a laptop screen at a typical distance (approximately 18 inches / 45 cm).

Source

pub fn smartphone() -> Self

Smartphone viewing condition (acuity ~90 PPD).

Represents viewing a smartphone held at reading distance (approximately 12 inches / 30 cm).

Source

pub fn with_browser_dppx(self, dppx: f64) -> Self

Set the browser/OS device pixel ratio.

§Arguments
  • dppx - Device pixel ratio (e.g., 2.0 for retina).
Source

pub fn with_image_intrinsic_dppx(self, dppx: f64) -> Self

Set the image’s intrinsic pixels per CSS pixel.

§Arguments
  • dppx - Intrinsic DPI ratio (e.g., 2.0 for a 2x srcset image).
Source

pub fn with_ppd_override(self, ppd: f64) -> Self

Override the computed PPD with a specific value.

§Arguments
  • ppd - The PPD value to use.
Source

pub fn effective_ppd(&self) -> f64

Compute the effective PPD for metric adjustment.

If ppd is set, returns that value directly. Otherwise, computes the effective PPD from the acuity and dppx values.

The formula is:

effective_ppd = acuity_ppd * (image_intrinsic_dppx / browser_dppx)

This accounts for how srcset images are scaled on HiDPI displays.

Source

pub fn srcset_ratio(&self) -> f64

Compute the srcset ratio (intrinsic / browser).

  • ratio < 1: Image is undersized, browser upscales
  • ratio = 1: Native resolution
  • ratio > 1: Image is oversized, browser downscales
Source

pub fn simulation_params( &self, image_width: u32, image_height: u32, mode: SimulationMode, ) -> SimulationParams

Compute simulation parameters for a given image size.

Returns the scale factor to apply and the adjusted PPD for metrics.

§Arguments
  • image_width - Original image width in pixels
  • image_height - Original image height in pixels
  • mode - Simulation mode (accurate or downsample-only)
§Example
use codec_eval::viewing::{ViewingCondition, SimulationMode};

let condition = ViewingCondition::desktop()
    .with_browser_dppx(2.0)
    .with_image_intrinsic_dppx(1.0); // undersized

let params = condition.simulation_params(1000, 800, SimulationMode::DownsampleOnly);
assert_eq!(params.scale_factor, 1.0); // No upscaling
assert!(params.adjusted_ppd < 40.0);  // Adjusted for missing upscale

Trait Implementations§

Source§

impl Clone for ViewingCondition

Source§

fn clone(&self) -> ViewingCondition

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ViewingCondition

Source§

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

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

impl Default for ViewingCondition

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ViewingCondition

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ViewingCondition

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.
Source§

impl Serialize for ViewingCondition

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ViewingCondition

Auto Trait Implementations§

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<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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,