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: f64Viewer’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
impl ViewingCondition
Sourcepub fn new(acuity_ppd: f64) -> Self
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.
Sourcepub fn desktop() -> Self
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).
Sourcepub fn laptop() -> Self
pub fn laptop() -> Self
Laptop viewing condition (acuity ~60 PPD).
Represents viewing a laptop screen at a typical distance (approximately 18 inches / 45 cm).
Sourcepub fn smartphone() -> Self
pub fn smartphone() -> Self
Smartphone viewing condition (acuity ~90 PPD).
Represents viewing a smartphone held at reading distance (approximately 12 inches / 30 cm).
Sourcepub fn with_browser_dppx(self, dppx: f64) -> Self
pub fn with_browser_dppx(self, dppx: f64) -> Self
Sourcepub fn with_image_intrinsic_dppx(self, dppx: f64) -> Self
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).
Sourcepub fn with_ppd_override(self, ppd: f64) -> Self
pub fn with_ppd_override(self, ppd: f64) -> Self
Sourcepub fn effective_ppd(&self) -> f64
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.
Sourcepub fn srcset_ratio(&self) -> f64
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
Sourcepub fn simulation_params(
&self,
image_width: u32,
image_height: u32,
mode: SimulationMode,
) -> SimulationParams
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 pixelsimage_height- Original image height in pixelsmode- 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 upscaleTrait Implementations§
Source§impl Clone for ViewingCondition
impl Clone for ViewingCondition
Source§fn clone(&self) -> ViewingCondition
fn clone(&self) -> ViewingCondition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ViewingCondition
impl Debug for ViewingCondition
Source§impl Default for ViewingCondition
impl Default for ViewingCondition
Source§impl<'de> Deserialize<'de> for ViewingCondition
impl<'de> Deserialize<'de> for ViewingCondition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ViewingCondition
impl PartialEq for ViewingCondition
Source§impl Serialize for ViewingCondition
impl Serialize for ViewingCondition
impl StructuralPartialEq for ViewingCondition
Auto Trait Implementations§
impl Freeze for ViewingCondition
impl RefUnwindSafe for ViewingCondition
impl Send for ViewingCondition
impl Sync for ViewingCondition
impl Unpin for ViewingCondition
impl UnwindSafe for ViewingCondition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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