[librsvg] shared_surface: shorten code
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] shared_surface: shorten code
- Date: Tue, 5 Jan 2021 13:47:31 +0000 (UTC)
commit 40ee738c7dabbaf8eae0137d13edb1594d5d8539
Author: Paolo Borelli <pborelli gnome org>
Date: Tue Jan 5 14:36:06 2021 +0100
shared_surface: shorten code
src/surface_utils/shared_surface.rs | 16 +++++++---------
src/surface_utils/srgb.rs | 9 ++-------
2 files changed, 9 insertions(+), 16 deletions(-)
---
diff --git a/src/surface_utils/shared_surface.rs b/src/surface_utils/shared_surface.rs
index 86123512..b2dbe17d 100644
--- a/src/surface_utils/shared_surface.rs
+++ b/src/surface_utils/shared_surface.rs
@@ -334,7 +334,7 @@ impl ImageSurface<Shared> {
/// Returns `true` if the surface contains meaningful data only in the alpha channel.
#[inline]
- pub fn is_alpha_only(&self) -> bool {
+ fn is_alpha_only(&self) -> bool {
self.surface_type == SurfaceType::AlphaOnly
}
@@ -519,20 +519,18 @@ impl ImageSurface<Shared> {
/// Converts the surface to the linear sRGB color space.
#[inline]
pub fn to_linear_rgb(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Status> {
- if self.surface_type == SurfaceType::LinearRgb {
- Ok(self.clone())
- } else {
- srgb::linearize_surface(self, bounds)
+ match self.surface_type {
+ SurfaceType::LinearRgb | SurfaceType::AlphaOnly => Ok(self.clone()),
+ _ => srgb::linearize_surface(self, bounds),
}
}
/// Converts the surface to the sRGB color space.
#[inline]
pub fn to_srgb(&self, bounds: IRect) -> Result<SharedImageSurface, cairo::Status> {
- if self.surface_type == SurfaceType::SRgb {
- Ok(self.clone())
- } else {
- srgb::unlinearize_surface(self, bounds)
+ match self.surface_type {
+ SurfaceType::SRgb | SurfaceType::AlphaOnly => Ok(self.clone()),
+ _ => srgb::unlinearize_surface(self, bounds),
}
}
diff --git a/src/surface_utils/srgb.rs b/src/surface_utils/srgb.rs
index b88f486e..a6676a57 100644
--- a/src/surface_utils/srgb.rs
+++ b/src/surface_utils/srgb.rs
@@ -65,11 +65,6 @@ fn map_unpremultiplied_components<F: Fn(u8) -> u8>(
f: F,
new_type: SurfaceType,
) -> Result<SharedImageSurface, cairo::Status> {
- // This function doesn't affect the alpha channel.
- if surface.is_alpha_only() {
- return Ok(surface.clone());
- }
-
let (width, height) = (surface.width(), surface.height());
let mut output_surface = ExclusiveImageSurface::new(width, height, new_type)?;
map_unpremultiplied_components_loop(surface, &mut output_surface, bounds, f);
@@ -83,7 +78,7 @@ pub fn linearize_surface(
surface: &SharedImageSurface,
bounds: IRect,
) -> Result<SharedImageSurface, cairo::Status> {
- assert_ne!(surface.surface_type(), SurfaceType::LinearRgb);
+ assert_eq!(surface.surface_type(), SurfaceType::SRgb);
map_unpremultiplied_components(surface, bounds, linearize, SurfaceType::LinearRgb)
}
@@ -94,7 +89,7 @@ pub fn unlinearize_surface(
surface: &SharedImageSurface,
bounds: IRect,
) -> Result<SharedImageSurface, cairo::Status> {
- assert_ne!(surface.surface_type(), SurfaceType::SRgb);
+ assert_eq!(surface.surface_type(), SurfaceType::LinearRgb);
map_unpremultiplied_components(surface, bounds, unlinearize, SurfaceType::SRgb)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]