Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge pull request #2534 from klosixgaming-arch/fix/2022-render-banding

BFlat07d1de1764b2
diff --cc crates/export/src/pipeline.rs
index 66c2177be,b7f4ef06e..c639ebad1
--- a/crates/export/src/pipeline.rs
+++ b/crates/export/src/pipeline.rs
@@@ -634,8 -589,20 +648,21 @@@ fn premultiplied8(img: &Image, dither:
mod tests {
use super::*;
use rayon::prelude::*;
+ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
+ /// Dither may round a colour up while alpha rounds down; premultiplied colour stays at or
+ /// below the written alpha at every pixel.
+ #[test]
+ fn dithered_premultiplied_colour_never_exceeds_alpha() {
+ let v = 100.25 / 255.0;
+ let img = Image::filled(64, 64, [v, v, v, v]);
+ let px = premultiplied8(&img, true);
+ assert!(px.as_chunks::<4>().0.iter().all(|p| p[..3].iter().all(|c| *c <= p[3])), "a colour byte is above its alpha");
+ assert!(px.as_chunks::<4>().0.iter().all(|p| p[3] == 100));
+ let plain = premultiplied8(&img, false);
+ assert!(plain.as_chunks::<4>().0.iter().all(|p| *p == [100, 100, 100, 100]));
+ }
+
/// Frames `0..n` through [`map_frames`] with `cap`, recording the most running at once.
fn run_capped(n: u64, cap: Option<usize>) -> (Vec<u64>, usize) {
use std::sync::atomic::{AtomicUsize, Ordering};