[librsvg: 10/14] Optimize srgb::* for alpha_only
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 10/14] Optimize srgb::* for alpha_only
- Date: Sun, 15 Jul 2018 17:56:11 +0000 (UTC)
commit 5b637bee0ff5ba9c0757786d69751b426ee259bb
Author: Ivan Molodetskikh <yalterz gmail com>
Date: Sun Jul 15 14:19:23 2018 +0300
Optimize srgb::* for alpha_only
rsvg_internals/src/filters/context.rs | 8 +-------
rsvg_internals/src/srgb.rs | 19 +++++++++----------
2 files changed, 10 insertions(+), 17 deletions(-)
---
diff --git a/rsvg_internals/src/filters/context.rs b/rsvg_internals/src/filters/context.rs
index a41216fc..14d385f1 100644
--- a/rsvg_internals/src/filters/context.rs
+++ b/rsvg_internals/src/filters/context.rs
@@ -407,10 +407,7 @@ impl FilterContext {
if self.processing_linear_rgb {
result.output.surface =
unlinearize_surface(&result.output.surface, result.output.bounds)
- .map_err(FilterError::CairoError)
- .and_then(|surface| {
- SharedImageSurface::new(surface).map_err(FilterError::CairoError)
- })?;
+ .map_err(FilterError::CairoError)?;
}
if let Some(name) = result.name {
@@ -575,9 +572,6 @@ impl FilterContext {
linearize_surface(surface, bounds)
.map_err(FilterError::CairoError)
- .and_then(|surface| {
- SharedImageSurface::new(surface).map_err(FilterError::CairoError)
- })
.map(|surface| match raw {
FilterInput::StandardInput(_) => FilterInput::StandardInput(surface),
FilterInput::PrimitiveOutput(ref output) => {
diff --git a/rsvg_internals/src/srgb.rs b/rsvg_internals/src/srgb.rs
index 136cafd7..0726314a 100644
--- a/rsvg_internals/src/srgb.rs
+++ b/rsvg_internals/src/srgb.rs
@@ -36,16 +36,19 @@ pub fn unlinearize(c: f64) -> f64 {
}
/// Applies the function to each pixel component after unpremultiplying.
-///
-/// The returned surface is transparent everywhere except the rectangle defined by `bounds`.
fn map_unpremultiplied_components<F>(
surface: &SharedImageSurface,
bounds: IRect,
f: F,
-) -> Result<cairo::ImageSurface, cairo::Status>
+) -> Result<SharedImageSurface, cairo::Status>
where
F: Fn(f64) -> f64,
{
+ // This function doesn't affect the alpha channel.
+ if surface.is_alpha_only() {
+ return Ok(surface.clone());
+ }
+
let width = surface.width();
let height = surface.height();
@@ -77,27 +80,23 @@ where
}
}
- Ok(output_surface)
+ SharedImageSurface::new(output_surface)
}
/// Converts an sRGB surface to a linear sRGB surface (undoes the gamma correction).
-///
-/// The returned surface is transparent everywhere except the rectangle defined by `bounds`.
#[inline]
pub fn linearize_surface(
surface: &SharedImageSurface,
bounds: IRect,
-) -> Result<cairo::ImageSurface, cairo::Status> {
+) -> Result<SharedImageSurface, cairo::Status> {
map_unpremultiplied_components(surface, bounds, linearize)
}
/// Converts a linear sRGB surface to a normal sRGB surface (applies the gamma correction).
-///
-/// The returned surface is transparent everywhere except the rectangle defined by `bounds`.
#[inline]
pub fn unlinearize_surface(
surface: &SharedImageSurface,
bounds: IRect,
-) -> Result<cairo::ImageSurface, cairo::Status> {
+) -> Result<SharedImageSurface, cairo::Status> {
map_unpremultiplied_components(surface, bounds, unlinearize)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]