Skip to content

Commit

Permalink
Don't use source_ fields for output
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Dec 20, 2024
1 parent 38afa36 commit a46fdbf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
18 changes: 18 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,24 @@ impl Info<'_> {
.raw_row_length_from_width(self.bit_depth, width)
}

/// Gamma dependent on sRGB chunk
pub fn gamma(&self) -> Option<ScaledFloat> {
if self.srgb.is_some() {
Some(crate::srgb::substitute_gamma())
} else {
self.gama_chunk
}
}

/// Chromaticities dependent on sRGB chunk
pub fn chromaticities(&self) -> Option<SourceChromaticities> {
if self.srgb.is_some() {
Some(crate::srgb::substitute_chromaticities())
} else {
self.chrm_chunk
}
}

/// Mark the image data as conforming to the SRGB color space with the specified rendering intent.
///
/// Any ICC profiles will be ignored.
Expand Down
16 changes: 2 additions & 14 deletions src/decoder/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,11 +1315,6 @@ impl StreamingDecoder {
};

info.chrm_chunk = Some(source_chromaticities);
// Ignore chromaticities if sRGB profile is used.
if info.srgb.is_none() {
info.source_chromaticities = Some(source_chromaticities);
}

Ok(Decoded::Nothing)
}
}
Expand All @@ -1340,11 +1335,6 @@ impl StreamingDecoder {
let source_gamma = ScaledFloat::from_scaled(source_gamma);

info.gama_chunk = Some(source_gamma);
// Ignore chromaticities if sRGB profile is used.
if info.srgb.is_none() {
info.source_gamma = Some(source_gamma);
}

Ok(Decoded::Nothing)
}
}
Expand All @@ -1368,8 +1358,6 @@ impl StreamingDecoder {

// Set srgb and override source gamma and chromaticities.
info.srgb = Some(rendering_intent);
info.source_gamma = Some(crate::srgb::substitute_gamma());
info.source_chromaticities = Some(crate::srgb::substitute_chromaticities());
Ok(Decoded::Nothing)
}
}
Expand Down Expand Up @@ -1846,7 +1834,7 @@ mod tests {
fn trial(path: &str, expected: Option<ScaledFloat>) {
let decoder = crate::Decoder::new(File::open(path).unwrap());
let reader = decoder.read_info().unwrap();
let actual: Option<ScaledFloat> = reader.info().source_gamma;
let actual: Option<ScaledFloat> = reader.info().gamma();
assert!(actual == expected);
}
trial("tests/pngsuite/f00n0g08.png", None);
Expand Down Expand Up @@ -1887,7 +1875,7 @@ mod tests {
fn trial(path: &str, expected: Option<SourceChromaticities>) {
let decoder = crate::Decoder::new(File::open(path).unwrap());
let reader = decoder.read_info().unwrap();
let actual: Option<SourceChromaticities> = reader.info().source_chromaticities;
let actual: Option<SourceChromaticities> = reader.info().chromaticities();
assert!(actual == expected);
}
trial(
Expand Down
2 changes: 1 addition & 1 deletion src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2183,7 +2183,7 @@ mod tests {
let decoder = crate::Decoder::new(Cursor::new(buffer));
let mut reader = decoder.read_info()?;
assert_eq!(
reader.info().source_gamma,
reader.info().gamma(),
gamma,
"Deviation with gamma {:?}",
gamma
Expand Down

0 comments on commit a46fdbf

Please sign in to comment.