[librsvg: 7/15] feComponentTransfer: clone the table_values instead of keeping a reference to them
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 7/15] feComponentTransfer: clone the table_values instead of keeping a reference to them
- Date: Tue, 9 Mar 2021 20:51:37 +0000 (UTC)
commit 9de48bed6ad42a794addd911361a0d57f55b724f
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Mar 8 19:36:02 2021 -0600
feComponentTransfer: clone the table_values instead of keeping a reference to them
See #691 about limiting the size of that array.
This is to make it easier to extract the primitive's parameters into a
standalone struct.
src/filters/component_transfer.rs | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
---
diff --git a/src/filters/component_transfer.rs b/src/filters/component_transfer.rs
index 0d89a262..f1648ff4 100644
--- a/src/filters/component_transfer.rs
+++ b/src/filters/component_transfer.rs
@@ -71,8 +71,8 @@ impl Parse for FunctionType {
}
/// The compute function parameters.
-struct FunctionParameters<'a> {
- table_values: &'a Vec<f64>,
+struct FunctionParameters {
+ table_values: Vec<f64>,
slope: f64,
intercept: f64,
amplitude: f64,
@@ -81,15 +81,15 @@ struct FunctionParameters<'a> {
}
/// The compute function type.
-type Function = fn(&FunctionParameters<'_>, f64) -> f64;
+type Function = fn(&FunctionParameters, f64) -> f64;
/// The identity component transfer function.
-fn identity(_: &FunctionParameters<'_>, value: f64) -> f64 {
+fn identity(_: &FunctionParameters, value: f64) -> f64 {
value
}
/// The table component transfer function.
-fn table(params: &FunctionParameters<'_>, value: f64) -> f64 {
+fn table(params: &FunctionParameters, value: f64) -> f64 {
let n = params.table_values.len() - 1;
let k = (value * (n as f64)).floor() as usize;
@@ -108,7 +108,7 @@ fn table(params: &FunctionParameters<'_>, value: f64) -> f64 {
}
/// The discrete component transfer function.
-fn discrete(params: &FunctionParameters<'_>, value: f64) -> f64 {
+fn discrete(params: &FunctionParameters, value: f64) -> f64 {
let n = params.table_values.len();
let k = (value * (n as f64)).floor() as usize;
@@ -116,12 +116,12 @@ fn discrete(params: &FunctionParameters<'_>, value: f64) -> f64 {
}
/// The linear component transfer function.
-fn linear(params: &FunctionParameters<'_>, value: f64) -> f64 {
+fn linear(params: &FunctionParameters, value: f64) -> f64 {
params.slope * value + params.intercept
}
/// The gamma component transfer function.
-fn gamma(params: &FunctionParameters<'_>, value: f64) -> f64 {
+fn gamma(params: &FunctionParameters, value: f64) -> f64 {
params.amplitude * value.powf(params.exponent) + params.offset
}
@@ -130,7 +130,7 @@ trait FeComponentTransferFunc {
fn function(&self) -> Function;
/// Returns the component transfer function parameters.
- fn function_parameters(&self) -> FunctionParameters<'_>;
+ fn function_parameters(&self) -> FunctionParameters;
/// Returns the channel.
fn channel(&self) -> Channel;
@@ -167,9 +167,9 @@ macro_rules! func_x {
impl FeComponentTransferFunc for $func_name {
#[inline]
- fn function_parameters(&self) -> FunctionParameters<'_> {
+ fn function_parameters(&self) -> FunctionParameters {
FunctionParameters {
- table_values: &self.table_values,
+ table_values: self.table_values.clone(),
slope: self.slope,
intercept: self.intercept,
amplitude: self.amplitude,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]