From 97f118e67b04014d0b1f780551b77af417b1db3e Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 14 Dec 2018 10:21:44 +0300 Subject: [PATCH 1/2] Add a test for a crash in filter color conversion --- .../feMerge-color-interpolation-srgb.svg | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/fixtures/render-crash/feMerge-color-interpolation-srgb.svg diff --git a/tests/fixtures/render-crash/feMerge-color-interpolation-srgb.svg b/tests/fixtures/render-crash/feMerge-color-interpolation-srgb.svg new file mode 100644 index 000000000..c43442811 --- /dev/null +++ b/tests/fixtures/render-crash/feMerge-color-interpolation-srgb.svg @@ -0,0 +1,47 @@ + + + color-interpolation-filters=sRGB + + + + + + + + + + + + + + + + + + + + -- GitLab From 841bb5e5e38105f1526aa0f590c184d05d62decf Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 14 Dec 2018 10:22:43 +0300 Subject: [PATCH 2/2] Make sure to convert to sRGB in filter get_input --- rsvg_internals/src/filters/context.rs | 46 +++++++++++++-------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/rsvg_internals/src/filters/context.rs b/rsvg_internals/src/filters/context.rs index 1c2306434..ebda2a3ea 100644 --- a/rsvg_internals/src/filters/context.rs +++ b/rsvg_internals/src/filters/context.rs @@ -551,30 +551,30 @@ impl FilterContext { ) -> Result { let raw = self.get_input_raw(draw_ctx, in_)?; - // Linearize the returned surface if needed. - if self.processing_linear_rgb { - let (surface, bounds) = match raw { - FilterInput::StandardInput(ref surface) => { - (surface, self.effects_region().rect.unwrap().into()) - } - FilterInput::PrimitiveOutput(FilterOutput { - ref surface, - ref bounds, - }) => (surface, *bounds), - }; - - surface - .to_linear_rgb(bounds) - .map_err(FilterError::CairoError) - .map(|surface| match raw { - FilterInput::StandardInput(_) => FilterInput::StandardInput(surface), - FilterInput::PrimitiveOutput(ref output) => { - FilterInput::PrimitiveOutput(FilterOutput { surface, ..*output }) - } - }) + // Convert the input surface to the desired format. + let (surface, bounds) = match raw { + FilterInput::StandardInput(ref surface) => { + (surface, self.effects_region().rect.unwrap().into()) + } + FilterInput::PrimitiveOutput(FilterOutput { + ref surface, + ref bounds, + }) => (surface, *bounds), + }; + + let surface = if self.processing_linear_rgb { + surface.to_linear_rgb(bounds) } else { - Ok(raw) - } + surface.to_srgb(bounds) + }; + surface + .map_err(FilterError::CairoError) + .map(|surface| match raw { + FilterInput::StandardInput(_) => FilterInput::StandardInput(surface), + FilterInput::PrimitiveOutput(ref output) => { + FilterInput::PrimitiveOutput(FilterOutput { surface, ..*output }) + } + }) } /// Calls the given closure with linear RGB processing enabled. -- GitLab