mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge PR #15198: fix(fill): keep opaque Dissolve fills fully covered
This commit is contained in:
commit
51a18f6096
4 files changed
+33
-4
No files matched your search
+11
-1
@@ -18,7 +18,7 @@ pub fn dither_noise(x: i32, y: i32) -> f32 {
|
||||
h ^= h >> 15;
|
||||
h = h.wrapping_mul(0x2C1B_3C6D);
|
||||
h ^= h >> 12;
|
||||
f32::from((h & 0xFFFF) as u16) / 65535.0
|
||||
f32::from((h & 0xFFFF) as u16) / 65536.0
|
||||
}
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -225,6 +225,16 @@ impl Color {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn dither_noise_keeps_the_largest_hash_below_one() {
|
||||
// This position hashes to 65535: a full-opacity probability must still include it.
|
||||
assert_eq!(dither_noise(8, 246), 65535.0 / 65536.0);
|
||||
assert_eq!(dither_noise(0, 0), 0.0);
|
||||
for (x, y) in [(8, 246), (-8, -246), (i32::MIN, i32::MAX), (i32::MAX, i32::MIN)] {
|
||||
assert!((0.0..1.0).contains(&dither_noise(x, y)));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn colors_convert_into_a_document_mode() {
|
||||
let blue = Color::rgba(0.0, 0.0, 1.0, 0.5);
|
||||
|
||||
@@ -136,8 +136,8 @@ fn dither_tile(s: &Surface, out: &Surface, t: &Transform, bounds: Rect, c: TileC
|
||||
*d = f32::from(*s) / 255.0;
|
||||
}
|
||||
t.eval_fast(&input[..ni], &mut output[..no]).map_err(super::cms_err)?;
|
||||
// The hash can return 1.0; recenter its 65536 bins strictly inside (0, 1).
|
||||
let threshold = (f64::from(photocraft_color::dither_noise(x, y)) * 65535.0 + 0.5) / 65536.0;
|
||||
// Recenter the hash's 65536 bins strictly inside (0, 1).
|
||||
let threshold = (f64::from(photocraft_color::dither_noise(x, y)) * 65536.0 + 0.5) / 65536.0;
|
||||
for (d, value) in dp.iter_mut().zip(output).take(no) {
|
||||
*d = quantize(value, threshold);
|
||||
}
|
||||
|
||||
@@ -84,6 +84,25 @@ fn opacity_mode_and_preserve_transparency() {
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_dissolve_fill_covers_the_largest_noise_sample_at_every_depth() {
|
||||
// (8, 246) hashes to the largest noise sample: it must still be below full coverage.
|
||||
for depth in [8, 16, 32] {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", json!({"width": 9, "height": 247, "depth": depth, "background": "transparent"})).unwrap();
|
||||
s.execute(CMD, json!({"contents": "white", "mode": "dissolve", "opacity": 0})).unwrap();
|
||||
assert_eq!(px(&s, 8, 246)[3], 0.0, "{depth}-bit zero-opacity fill");
|
||||
|
||||
s.execute(CMD, json!({"contents": "white", "mode": "dissolve", "opacity": 100})).unwrap();
|
||||
assert_eq!(px(&s, 8, 246), [1.0; 4], "{depth}-bit opaque fill at the largest noise sample");
|
||||
assert_eq!(px(&s, 0, 0), [1.0; 4], "{depth}-bit opaque fill at an ordinary sample");
|
||||
assert!(s.undo());
|
||||
assert_eq!(px(&s, 8, 246)[3], 0.0, "{depth}-bit undo");
|
||||
assert!(s.redo());
|
||||
assert_eq!(px(&s, 8, 246), [1.0; 4], "{depth}-bit redo");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preserve_transparency_blends_source_atop_on_semi_transparent_pixels() {
|
||||
// White at 50%, then black at 50% keeping alpha: Photoshop gives (127,127,127,128), the
|
||||
|
||||
@@ -827,7 +827,7 @@ fn dither_noise(d: vec2<i32>) -> f32 {
|
||||
h = h ^ (h >> 15u);
|
||||
h = h * 0x2C1B3C6Du;
|
||||
h = h ^ (h >> 12u);
|
||||
return f32(h & 0xFFFFu) / 65535.0;
|
||||
return f32(h & 0xFFFFu) / 65536.0;
|
||||
}
|
||||
|
||||
fn layer_texel(d: vec2<i32>) -> vec4<f32> {
|
||||
|
||||
Reference in new issue
Block a user