From 0f7abffc0e94b4bb9f8117db633bfd07d900eb93 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 22 Mar 2023 00:36:57 +0100 Subject: Draft (very) basic incremental rendering for `iced_tiny_skia` --- core/src/image.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'core/src/image.rs') diff --git a/core/src/image.rs b/core/src/image.rs index 70fbade0..618235ef 100644 --- a/core/src/image.rs +++ b/core/src/image.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use std::sync::Arc; /// A handle of some image data. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Handle { id: u64, data: Data, @@ -156,6 +156,34 @@ impl std::fmt::Debug for Data { } } +impl PartialEq for Data { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (Self::Path(a), Self::Path(b)) => a == b, + (Self::Bytes(a), Self::Bytes(b)) => a.as_ref() == b.as_ref(), + ( + Self::Rgba { + width: width_a, + height: height_a, + pixels: pixels_a, + }, + Self::Rgba { + width: width_b, + height: height_b, + pixels: pixels_b, + }, + ) => { + width_a == width_b + && height_a == height_b + && pixels_a.as_ref() == pixels_b.as_ref() + } + _ => false, + } + } +} + +impl Eq for Data {} + /// A [`Renderer`] that can render raster graphics. /// /// [renderer]: crate::renderer -- cgit From 4cae262d22cde458cbb5d0667e4bcf6adce9242a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 5 Apr 2023 05:47:29 +0200 Subject: Implement `PartialEq` and `Eq` for `image::Bytes` --- core/src/image.rs | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) (limited to 'core/src/image.rs') diff --git a/core/src/image.rs b/core/src/image.rs index 618235ef..85d9d475 100644 --- a/core/src/image.rs +++ b/core/src/image.rs @@ -110,6 +110,14 @@ impl std::hash::Hash for Bytes { } } +impl PartialEq for Bytes { + fn eq(&self, other: &Self) -> bool { + self.as_ref() == other.as_ref() + } +} + +impl Eq for Bytes {} + impl AsRef<[u8]> for Bytes { fn as_ref(&self) -> &[u8] { self.0.as_ref().as_ref() @@ -125,7 +133,7 @@ impl std::ops::Deref for Bytes { } /// The data of a raster image. -#[derive(Clone, Hash)] +#[derive(Clone, PartialEq, Eq, Hash)] pub enum Data { /// File data Path(PathBuf), @@ -156,34 +164,6 @@ impl std::fmt::Debug for Data { } } -impl PartialEq for Data { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (Self::Path(a), Self::Path(b)) => a == b, - (Self::Bytes(a), Self::Bytes(b)) => a.as_ref() == b.as_ref(), - ( - Self::Rgba { - width: width_a, - height: height_a, - pixels: pixels_a, - }, - Self::Rgba { - width: width_b, - height: height_b, - pixels: pixels_b, - }, - ) => { - width_a == width_b - && height_a == height_b - && pixels_a.as_ref() == pixels_b.as_ref() - } - _ => false, - } - } -} - -impl Eq for Data {} - /// A [`Renderer`] that can render raster graphics. /// /// [renderer]: crate::renderer -- cgit