Skip to main content

ass_renderer/debug/visual_comparison/
util.rs

1//! Helpers for composing visual comparison images
2
3use crate::utils::RenderError;
4use tiny_skia::{Pixmap, Transform};
5
6/// Create side-by-side comparison image
7pub fn create_comparison_image(
8    our_output: &Pixmap,
9    libass_output: &Pixmap,
10    diff_map: Option<&Pixmap>,
11) -> Result<Pixmap, RenderError> {
12    let width = our_output.width() + libass_output.width() + diff_map.map_or(0, |d| d.width());
13    let height = our_output.height().max(libass_output.height());
14
15    let mut comparison = Pixmap::new(width, height).ok_or(RenderError::InvalidPixmap)?;
16
17    // Copy our output to left side
18    comparison.draw_pixmap(
19        0,
20        0,
21        our_output.as_ref(),
22        &tiny_skia::PixmapPaint::default(),
23        Transform::identity(),
24        None,
25    );
26
27    // Copy libass output to middle
28    comparison.draw_pixmap(
29        our_output.width() as i32,
30        0,
31        libass_output.as_ref(),
32        &tiny_skia::PixmapPaint::default(),
33        Transform::identity(),
34        None,
35    );
36
37    // Copy diff map to right side if provided
38    if let Some(diff) = diff_map {
39        comparison.draw_pixmap(
40            (our_output.width() + libass_output.width()) as i32,
41            0,
42            diff.as_ref(),
43            &tiny_skia::PixmapPaint::default(),
44            Transform::identity(),
45            None,
46        );
47    }
48
49    Ok(comparison)
50}