mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-28 01:18:12 +08:00
Prune the unused legacy Adjust and Blend list implementations
This commit is contained in:
@@ -12,17 +12,9 @@ impl Adjust<Color> for Color {
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
mod adjust_std {
|
mod adjust_std {
|
||||||
use super::*;
|
use super::*;
|
||||||
use core_types::list::List;
|
|
||||||
use raster_types::{CPU, Raster};
|
use raster_types::{CPU, Raster};
|
||||||
use vector_types::GradientStops;
|
use vector_types::GradientStops;
|
||||||
|
|
||||||
impl Adjust<Color> for List<Raster<CPU>> {
|
|
||||||
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
|
||||||
for element in self.iter_element_values_mut() {
|
|
||||||
element.adjust(&map_fn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Adjust<Color> for Raster<CPU> {
|
impl Adjust<Color> for Raster<CPU> {
|
||||||
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
||||||
for color in self.data_mut().data.iter_mut() {
|
for color in self.data_mut().data.iter_mut() {
|
||||||
@@ -30,20 +22,6 @@ mod adjust_std {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Adjust<Color> for List<Color> {
|
|
||||||
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
|
||||||
for element in self.iter_element_values_mut() {
|
|
||||||
*element = map_fn(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Adjust<Color> for List<GradientStops> {
|
|
||||||
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
|
||||||
for element in self.iter_element_values_mut() {
|
|
||||||
element.adjust(&map_fn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Adjust<Color> for GradientStops {
|
impl Adjust<Color> for GradientStops {
|
||||||
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
||||||
for color in self.color.iter_mut() {
|
for color in self.color.iter_mut() {
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ impl Blend<Color> for Color {
|
|||||||
mod blend_std {
|
mod blend_std {
|
||||||
use super::*;
|
use super::*;
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
use core_types::list::List;
|
|
||||||
use raster_types::Image;
|
use raster_types::Image;
|
||||||
use raster_types::Raster;
|
use raster_types::Raster;
|
||||||
|
|
||||||
@@ -37,52 +36,6 @@ mod blend_std {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Blend<Color> for List<Raster<CPU>> {
|
|
||||||
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
|
||||||
let mut result_list = self.clone();
|
|
||||||
let pair_count = result_list.len().min(under.len());
|
|
||||||
for index in 0..pair_count {
|
|
||||||
let Some(over) = result_list.element(index) else { break };
|
|
||||||
let Some(under_element) = under.element(index) else { break };
|
|
||||||
let data = over.data.iter().zip(under_element.data.iter()).map(|(a, b)| blend_fn(*a, *b)).collect();
|
|
||||||
let (width, height) = (over.width, over.height);
|
|
||||||
|
|
||||||
*result_list.element_mut(index).unwrap() = Raster::new_cpu(Image {
|
|
||||||
data,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
base64_string: None,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
result_list
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Blend<Color> for List<Color> {
|
|
||||||
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
|
||||||
let mut result_list = self.clone();
|
|
||||||
let pair_count = result_list.len().min(under.len());
|
|
||||||
for index in 0..pair_count {
|
|
||||||
let Some(over) = result_list.element(index) else { break };
|
|
||||||
let Some(under_element) = under.element(index) else { break };
|
|
||||||
let new_val = blend_fn(*over, *under_element);
|
|
||||||
*result_list.element_mut(index).unwrap() = new_val;
|
|
||||||
}
|
|
||||||
result_list
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Blend<Color> for List<GradientStops> {
|
|
||||||
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
|
||||||
let mut result_list = self.clone();
|
|
||||||
let pair_count = result_list.len().min(under.len());
|
|
||||||
for index in 0..pair_count {
|
|
||||||
let Some(over) = result_list.element(index) else { break };
|
|
||||||
let Some(under_element) = under.element(index) else { break };
|
|
||||||
let new_val = over.blend(under_element, &blend_fn);
|
|
||||||
*result_list.element_mut(index).unwrap() = new_val;
|
|
||||||
}
|
|
||||||
result_list
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Blend<Color> for GradientStops {
|
impl Blend<Color> for GradientStops {
|
||||||
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
||||||
let mut combined_stops = self.position.iter().chain(under.position.iter()).copied().collect::<Vec<_>>();
|
let mut combined_stops = self.position.iter().chain(under.position.iter()).copied().collect::<Vec<_>>();
|
||||||
@@ -208,7 +161,6 @@ fn color_overlay<T: Adjust<Color> + Clone + Send + Sync + no_std_types::context:
|
|||||||
mod test {
|
mod test {
|
||||||
use core_types::blending::BlendMode;
|
use core_types::blending::BlendMode;
|
||||||
use core_types::color::Color;
|
use core_types::color::Color;
|
||||||
use core_types::list::List;
|
|
||||||
use raster_types::Image;
|
use raster_types::Image;
|
||||||
use raster_types::Raster;
|
use raster_types::Raster;
|
||||||
|
|
||||||
@@ -223,8 +175,7 @@ mod test {
|
|||||||
// 100% of the output should come from the multiplied value
|
// 100% of the output should come from the multiplied value
|
||||||
let opacity = 100.;
|
let opacity = 100.;
|
||||||
|
|
||||||
let result = super::color_overlay(&(), List::new_from_element(Raster::new_cpu(image.clone())), overlay_color, BlendMode::Multiply, opacity);
|
let result = super::color_overlay(&(), Raster::new_cpu(image.clone()), overlay_color, BlendMode::Multiply, opacity);
|
||||||
let result = result.element(0).unwrap().clone();
|
|
||||||
|
|
||||||
// The output should just be the original green and alpha channels (as we multiply them by 1 and other channels by 0)
|
// The output should just be the original green and alpha channels (as we multiply them by 1 and other channels by 0)
|
||||||
assert_eq!(result.data[0], Color::from_rgbaf32_unchecked(0., image_color.g(), 0., image_color.a()));
|
assert_eq!(result.data[0], Color::from_rgbaf32_unchecked(0., image_color.g(), 0., image_color.a()));
|
||||||
|
|||||||
Reference in New Issue
Block a user