Skip to content

Commit

Permalink
Unit tests for roundtripping of pHYs and sRGB chunks. (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
anforowicz authored Feb 4, 2025
1 parent e0cb919 commit 819d91e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cifuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fuzz-seconds: 120
output-sarif: true
- name: Upload Crash
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
Expand Down
43 changes: 40 additions & 3 deletions src/decoder/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,7 @@ mod tests {
use super::ScaledFloat;
use super::SourceChromaticities;
use crate::test_utils::*;
use crate::{Decoder, DecodingError, Reader};
use crate::{Decoder, DecodingError, Reader, SrgbRenderingIntent, Unit};
use approx::assert_relative_eq;
use byteorder::WriteBytesExt;
use std::borrow::Cow;
Expand Down Expand Up @@ -2127,6 +2127,43 @@ mod tests {
assert_eq!(dummy_icc, &**dec.info().icc_profile.as_ref().unwrap());
}

#[test]
fn test_phys_roundtrip() {
let mut info = crate::Info::with_size(1, 1);
info.pixel_dims = Some(crate::PixelDimensions {
xppu: 12,
yppu: 34,
unit: Unit::Meter,
});
let mut encoded_image = Vec::new();
let enc = crate::Encoder::with_info(&mut encoded_image, info).unwrap();
let mut enc = enc.write_header().unwrap();
enc.write_image_data(&[0]).unwrap();
enc.finish().unwrap();

let dec = crate::Decoder::new(encoded_image.as_slice());
let dec = dec.read_info().unwrap();
let phys = dec.info().pixel_dims.as_ref().unwrap();
assert_eq!(phys.xppu, 12);
assert_eq!(phys.yppu, 34);
assert_eq!(phys.unit, Unit::Meter);
}

#[test]
fn test_srgb_roundtrip() {
let mut info = crate::Info::with_size(1, 1);
info.srgb = Some(SrgbRenderingIntent::Saturation);
let mut encoded_image = Vec::new();
let enc = crate::Encoder::with_info(&mut encoded_image, info).unwrap();
let mut enc = enc.write_header().unwrap();
enc.write_image_data(&[0]).unwrap();
enc.finish().unwrap();

let dec = crate::Decoder::new(encoded_image.as_slice());
let dec = dec.read_info().unwrap();
assert_eq!(dec.info().srgb.unwrap(), SrgbRenderingIntent::Saturation);
}

#[test]
fn test_png_with_broken_iccp() {
let decoder = crate::Decoder::new(File::open("tests/iccp/broken_iccp.png").unwrap());
Expand All @@ -2136,9 +2173,9 @@ mod tests {
assert!(decoder.read_info().is_ok());
}

/// Test handling of `mDCV` and `cLLI` chunks.
/// Test handling of `cICP`, `mDCV`, and `cLLI` chunks.
#[test]
fn test_mdcv_and_clli_chunks() {
fn test_cicp_mdcv_and_clli_chunks() {
let decoder = crate::Decoder::new(File::open("tests/bugfixes/cicp_pq.png").unwrap());
let reader = decoder.read_info().unwrap();
let info = reader.info();
Expand Down

0 comments on commit 819d91e

Please sign in to comment.