[librsvg: 22/53] Minor cleanups to compare_surfaces()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 22/53] Minor cleanups to compare_surfaces()
- Date: Fri, 23 Oct 2020 02:19:07 +0000 (UTC)
commit 9c4fe01f9a5f79fbf21ae34c2ccac986666dde4e
Author: Sven Neumann <sven svenfoo org>
Date: Wed Oct 14 16:21:11 2020 +0200
Minor cleanups to compare_surfaces()
.../src/surface_utils/compare_surfaces.rs | 43 ++++++++--------------
1 file changed, 15 insertions(+), 28 deletions(-)
---
diff --git a/rsvg_internals/src/surface_utils/compare_surfaces.rs
b/rsvg_internals/src/surface_utils/compare_surfaces.rs
index 226a31de..5f893858 100644
--- a/rsvg_internals/src/surface_utils/compare_surfaces.rs
+++ b/rsvg_internals/src/surface_utils/compare_surfaces.rs
@@ -5,7 +5,7 @@ use super::{
};
use crate::error::RenderingError;
-use rgb::ComponentMap;
+use rgb::{ComponentMap, RGB};
pub enum BufferDiff {
DifferentSizes,
@@ -18,11 +18,6 @@ pub struct Diff {
pub surface: SharedImageSurface,
}
-#[inline]
-fn pixel_max(p: &Pixel) -> u8 {
- p.r.max(p.g).max(p.b).max(p.a)
-}
-
#[inline]
fn emphasize(p: &Pixel) -> Pixel {
let emphasize_component = |c| {
@@ -57,41 +52,33 @@ pub fn compare_surfaces(
let mut num_pixels_changed = 0;
let mut max_diff = 0;
+ let black = Pixel::default().alpha(255);
+
{
let mut diff_data = surf_diff.get_data().unwrap();
for ((xa, ya, pixel_a), (_, _, pixel_b)) in Pixels::new(surf_a).zip(Pixels::new(surf_b)) {
- if pixel_a != pixel_b {
+ let dest = if pixel_a != pixel_b {
num_pixels_changed += 1;
let pixel_diff = pixel_a.diff(&pixel_b);
- let pixel_max_diff = pixel_max(&pixel_diff);
-
- max_diff = max_diff.max(pixel_max_diff);
+ max_diff = pixel_diff.iter().fold(max_diff, |acc, c| acc.max(c));
- let mut pixel_diff = emphasize(&pixel_diff);
+ let pixel_diff = emphasize(&pixel_diff);
- if pixel_diff.r == 0 && pixel_diff.g == 0 && pixel_diff.b == 0 {
+ if pixel_diff.rgb() == RGB::default() {
// alpha only difference; convert alpha to gray
-
- pixel_diff.r = pixel_diff.a;
- pixel_diff.g = pixel_diff.a;
- pixel_diff.b = pixel_diff.a;
+ let a = pixel_diff.a;
+ pixel_diff.map_rgb(|_| a)
+ } else {
+ pixel_diff.alpha(255)
}
-
- pixel_diff.a = 255;
-
- diff_data.set_pixel(diff_stride, pixel_diff, xa, ya);
} else {
- let black = Pixel {
- r: 0,
- g: 0,
- b: 0,
- a: 255,
- };
- diff_data.set_pixel(diff_stride, black, xa, ya);
- }
+ black
+ };
+
+ diff_data.set_pixel(diff_stride, dest, xa, ya);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]