mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-29 09:46:29 +01:00
craft-texture: sRGB tests check the standard only, under tests/it/
The comparisons with craft-cms, craft-mesh and craft-psd and their dev-dependencies are removed. The tests of the pair against IEC 61966-2-1 move to tests/it/srgb.rs, linked through tests/it/main.rs.
This commit is contained in:
1 parent
4033e5b6e4
commit
c0f1c226e3
4 files changed
+4
-57
No files matched your search
Generated
-3
@@ -3144,9 +3144,6 @@ name = "craft-texture"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"craft-cms",
|
||||
"craft-mesh",
|
||||
"craft-psd",
|
||||
"dds",
|
||||
"half",
|
||||
"rayon",
|
||||
|
||||
@@ -24,9 +24,6 @@ dds = { version = "0.2.0", default-features = false, optional = true }
|
||||
bytemuck = { workspace = true, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
craft-cms = { workspace = true }
|
||||
craft-mesh = { workspace = true }
|
||||
craft-psd = { workspace = true }
|
||||
half = "2"
|
||||
dds = { version = "0.2.0", default-features = false }
|
||||
bytemuck = { workspace = true }
|
||||
@@ -0,0 +1,3 @@
|
||||
//! The crate's integration tests, linked into one test binary.
|
||||
|
||||
mod srgb;
|
||||
@@ -1,5 +1,4 @@
|
||||
//! The scalar sRGB pair against IEC 61966-2-1 and against the copies of it in craft-cms,
|
||||
//! craft-mesh and craft-psd.
|
||||
//! The scalar sRGB pair against IEC 61966-2-1.
|
||||
//!
|
||||
//! The encoding is the one the ICC sRGB registry entry gives for IEC 61966-2-1:1999
|
||||
//! (<https://registry.color.org/rgb-registry/srgb>); the decoding is the CSS Color 4 sample code
|
||||
@@ -11,15 +10,9 @@ use craft_texture::{linear_to_srgb, srgb_to_linear};
|
||||
|
||||
/// The largest difference allowed between the `f32` pair and the `f64` formulas.
|
||||
const STANDARD_TOLERANCE: f32 = 3.0e-7;
|
||||
/// The largest difference allowed between the pair and craft-cms's ICC curve, which is evaluated
|
||||
/// in `f64` and returned as `f32`.
|
||||
const CMS_TOLERANCE: f32 = 2.4e-7;
|
||||
/// The 8-bit and 16-bit code ranges.
|
||||
const DEPTHS: [u32; 2] = [255, 65_535];
|
||||
|
||||
/// One direction of an sRGB pair.
|
||||
type Scalar = fn(f32) -> f32;
|
||||
|
||||
fn encode64(c: f64) -> f64 {
|
||||
if c <= 0.003_130_8 { c * 12.92 } else { 1.055 * c.powf(1.0 / 2.4) - 0.055 }
|
||||
}
|
||||
@@ -53,9 +46,6 @@ fn worst_fails_on_a_difference_that_is_not_finite() {
|
||||
worst(255, |_| f32::NAN, |v| v);
|
||||
}
|
||||
|
||||
/// Inputs outside `[0, 1]` that the crates' copies must also agree on.
|
||||
const OUTSIDE: [f32; 10] = [-0.0, -1.0e-6, -0.5, -1.0, -100.0, 1.5, 2.0, 100.0, f32::INFINITY, f32::NEG_INFINITY];
|
||||
|
||||
#[test]
|
||||
fn encode_matches_the_standard_at_every_8_and_16_bit_code() {
|
||||
for max in DEPTHS {
|
||||
@@ -165,43 +155,3 @@ fn infinities_keep_their_sign_and_nan_stays_nan() {
|
||||
assert!(f(f32::NAN).is_nan());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mesh_pair_matches_bit_for_bit() {
|
||||
let pairs: [(Scalar, Scalar); 2] = [(linear_to_srgb, craft_mesh::linear_to_srgb), (srgb_to_linear, craft_mesh::srgb_to_linear)];
|
||||
for (ours, mesh) in pairs {
|
||||
for max in DEPTHS {
|
||||
for (n, v) in codes(max) {
|
||||
assert_eq!(ours(v).to_bits(), mesh(v).to_bits(), "code {n} of {max}");
|
||||
}
|
||||
}
|
||||
for v in OUTSIDE {
|
||||
assert_eq!(ours(v).to_bits(), mesh(v).to_bits(), "{v}");
|
||||
}
|
||||
assert!(mesh(f32::NAN).is_nan());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn psd_encoder_matches_bit_for_bit() {
|
||||
for max in DEPTHS {
|
||||
for (n, v) in codes(max) {
|
||||
assert_eq!(linear_to_srgb(v).to_bits(), craft_psd::float::srgb_encode(v).to_bits(), "code {n} of {max}");
|
||||
}
|
||||
}
|
||||
for v in OUTSIDE {
|
||||
assert_eq!(linear_to_srgb(v).to_bits(), craft_psd::float::srgb_encode(v).to_bits(), "{v}");
|
||||
}
|
||||
assert!(craft_psd::float::srgb_encode(f32::NAN).is_nan());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cms_curve_matches_within_rounding() {
|
||||
let trc = craft_cms::curve::srgb_trc();
|
||||
for max in DEPTHS {
|
||||
let (d, n) = worst(max, srgb_to_linear, |v| trc.eval(v));
|
||||
assert!(d <= CMS_TOLERANCE, "decode code {n} of {max} is {d} from craft-cms");
|
||||
let (d, n) = worst(max, linear_to_srgb, |v| trc.eval_inverse(v));
|
||||
assert!(d <= CMS_TOLERANCE, "encode code {n} of {max} is {d} from craft-cms");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user