mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 07:18:04 +08:00
Instance tables refactor part 7: Rename "ImageFrame" -> "RasterData", "ImageFrameTable" -> "RasterDataType", and "RasterFrame" -> "RasterDataType"
This commit is contained in:
@@ -4,7 +4,7 @@ use crate::raster::curve::{CubicSplines, CurveManipulatorGroup};
|
||||
#[cfg(feature = "alloc")]
|
||||
use crate::raster::curve::{Curve, ValueMapperNode};
|
||||
#[cfg(feature = "alloc")]
|
||||
use crate::raster::image::{Image, ImageFrameTable};
|
||||
use crate::raster::image::{Image, RasterDataTable};
|
||||
use crate::raster::{Channel, Color, Pixel};
|
||||
use crate::registry::types::{Angle, Percentage, SignedPercentage};
|
||||
use crate::vector::VectorDataTable;
|
||||
@@ -265,7 +265,7 @@ fn luminance<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut input: T,
|
||||
@@ -289,7 +289,7 @@ fn extract_channel<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut input: T,
|
||||
@@ -312,7 +312,7 @@ fn make_opaque<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut input: T,
|
||||
@@ -337,7 +337,7 @@ fn brightness_contrast<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut input: T,
|
||||
@@ -426,7 +426,7 @@ fn levels<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut image: T,
|
||||
@@ -493,7 +493,7 @@ async fn black_and_white<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut image: T,
|
||||
@@ -565,7 +565,7 @@ async fn hue_saturation<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut input: T,
|
||||
@@ -599,7 +599,7 @@ async fn invert<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut input: T,
|
||||
@@ -621,7 +621,7 @@ async fn threshold<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut image: T,
|
||||
@@ -663,7 +663,7 @@ impl Blend<Color> for Option<Color> {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Blend<Color> for ImageFrameTable<Color> {
|
||||
impl Blend<Color> for RasterDataTable<Color> {
|
||||
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
||||
let mut result_table = self.clone();
|
||||
|
||||
@@ -706,14 +706,14 @@ async fn blend<T: Blend<Color> + Send>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
over: T,
|
||||
#[expose]
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
under: T,
|
||||
@@ -795,7 +795,7 @@ impl Adjust<Color> for GradientStops {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<P: Pixel> Adjust<P> for ImageFrameTable<P>
|
||||
impl<P: Pixel> Adjust<P> for RasterDataTable<P>
|
||||
where
|
||||
GraphicElement: From<Image<P>>,
|
||||
{
|
||||
@@ -829,7 +829,7 @@ async fn gradient_map<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut image: T,
|
||||
@@ -865,7 +865,7 @@ async fn vibrance<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut image: T,
|
||||
@@ -1037,7 +1037,7 @@ async fn channel_mixer<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut image: T,
|
||||
@@ -1166,7 +1166,7 @@ async fn selective_color<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut image: T,
|
||||
@@ -1309,7 +1309,7 @@ impl MultiplyAlpha for GraphicGroupTable {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<P: Pixel> MultiplyAlpha for ImageFrameTable<P>
|
||||
impl<P: Pixel> MultiplyAlpha for RasterDataTable<P>
|
||||
where
|
||||
GraphicElement: From<Image<P>>,
|
||||
{
|
||||
@@ -1331,7 +1331,7 @@ async fn posterize<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut input: T,
|
||||
@@ -1364,7 +1364,7 @@ async fn exposure<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut input: T,
|
||||
@@ -1438,7 +1438,7 @@ fn color_overlay<T: Adjust<Color>>(
|
||||
_: impl Ctx,
|
||||
#[implementations(
|
||||
Color,
|
||||
ImageFrameTable<Color>,
|
||||
RasterDataTable<Color>,
|
||||
GradientStops,
|
||||
)]
|
||||
mut image: T,
|
||||
@@ -1488,7 +1488,7 @@ fn color_overlay<T: Adjust<Color>>(
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::raster::adjustments::BlendMode;
|
||||
use crate::raster::image::{Image, ImageFrameTable};
|
||||
use crate::raster::image::{Image, RasterDataTable};
|
||||
use crate::{Color, Node};
|
||||
use std::pin::Pin;
|
||||
|
||||
@@ -1514,7 +1514,7 @@ mod test {
|
||||
// 100% of the output should come from the multiplied value
|
||||
let opacity = 100_f64;
|
||||
|
||||
let result = super::color_overlay((), ImageFrameTable::new(image.clone()), overlay_color, BlendMode::Multiply, opacity);
|
||||
let result = super::color_overlay((), RasterDataTable::new(image.clone()), overlay_color, BlendMode::Multiply, opacity);
|
||||
let result = result.instance_ref_iter().next().unwrap().instance;
|
||||
|
||||
// The output should just be the original green and alpha channels (as we multiply them by 1 and other channels by 0)
|
||||
|
||||
@@ -16,19 +16,13 @@ mod base64_serde {
|
||||
use base64::Engine;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
pub fn as_base64<S, P: Pixel>(key: &[P], serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
pub fn as_base64<S: Serializer, P: Pixel>(key: &[P], serializer: S) -> Result<S::Ok, S::Error> {
|
||||
let u8_data = bytemuck::cast_slice(key);
|
||||
let string = base64::engine::general_purpose::STANDARD.encode(u8_data);
|
||||
(key.len() as u64, string).serialize(serializer)
|
||||
}
|
||||
|
||||
pub fn from_base64<'a, D, P: Pixel>(deserializer: D) -> Result<Vec<P>, D::Error>
|
||||
where
|
||||
D: Deserializer<'a>,
|
||||
{
|
||||
pub fn from_base64<'a, D: Deserializer<'a>, P: Pixel>(deserializer: D) -> Result<Vec<P>, D::Error> {
|
||||
use serde::de::Error;
|
||||
<(u64, &[u8])>::deserialize(deserializer)
|
||||
.and_then(|(len, str)| {
|
||||
@@ -214,7 +208,7 @@ impl<P: Pixel> IntoIterator for Image<P> {
|
||||
}
|
||||
|
||||
// TODO: Eventually remove this migration document upgrade code
|
||||
pub fn migrate_image_frame<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<ImageFrameTable<Color>, D::Error> {
|
||||
pub fn migrate_image_frame<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<RasterDataTable<Color>, D::Error> {
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Clone, Default, Debug, PartialEq, specta::Type)]
|
||||
@@ -224,13 +218,13 @@ pub fn migrate_image_frame<'de, D: serde::Deserializer<'de>>(deserializer: D) ->
|
||||
}
|
||||
impl From<ImageFrame<Color>> for GraphicElement {
|
||||
fn from(image_frame: ImageFrame<Color>) -> Self {
|
||||
GraphicElement::RasterFrame(crate::RasterFrame::ImageFrame(ImageFrameTable::new(image_frame.image)))
|
||||
GraphicElement::RasterDataType(crate::RasterDataType::RasterData(RasterDataTable::new(image_frame.image)))
|
||||
}
|
||||
}
|
||||
impl From<GraphicElement> for ImageFrame<Color> {
|
||||
fn from(element: GraphicElement) -> Self {
|
||||
match element {
|
||||
GraphicElement::RasterFrame(crate::RasterFrame::ImageFrame(image)) => Self {
|
||||
GraphicElement::RasterDataType(crate::RasterDataType::RasterData(image)) => Self {
|
||||
image: image.instance_ref_iter().next().unwrap().instance.clone(),
|
||||
},
|
||||
_ => panic!("Expected Image, found {:?}", element),
|
||||
@@ -261,20 +255,20 @@ pub fn migrate_image_frame<'de, D: serde::Deserializer<'de>>(deserializer: D) ->
|
||||
Image(Image<Color>),
|
||||
OldImageFrame(OldImageFrame<Color>),
|
||||
ImageFrame(Instances<ImageFrame<Color>>),
|
||||
ImageFrameTable(ImageFrameTable<Color>),
|
||||
RasterDataTable(RasterDataTable<Color>),
|
||||
}
|
||||
|
||||
Ok(match FormatVersions::deserialize(deserializer)? {
|
||||
FormatVersions::Image(image) => ImageFrameTable::new(image),
|
||||
FormatVersions::Image(image) => RasterDataTable::new(image),
|
||||
FormatVersions::OldImageFrame(image_frame_with_transform_and_blending) => {
|
||||
let OldImageFrame { image, transform, alpha_blending } = image_frame_with_transform_and_blending;
|
||||
let mut image_frame_table = ImageFrameTable::new(image);
|
||||
let mut image_frame_table = RasterDataTable::new(image);
|
||||
*image_frame_table.instance_mut_iter().next().unwrap().transform = transform;
|
||||
*image_frame_table.instance_mut_iter().next().unwrap().alpha_blending = alpha_blending;
|
||||
image_frame_table
|
||||
}
|
||||
FormatVersions::ImageFrame(image_frame) => ImageFrameTable::new(image_frame.instance_ref_iter().next().unwrap().instance.image.clone()),
|
||||
FormatVersions::ImageFrameTable(image_frame_table) => image_frame_table,
|
||||
FormatVersions::ImageFrame(image_frame) => RasterDataTable::new(image_frame.instance_ref_iter().next().unwrap().instance.image.clone()),
|
||||
FormatVersions::RasterDataTable(image_frame_table) => image_frame_table,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -289,13 +283,13 @@ pub fn migrate_image_frame_instance<'de, D: serde::Deserializer<'de>>(deserializ
|
||||
}
|
||||
impl From<ImageFrame<Color>> for GraphicElement {
|
||||
fn from(image_frame: ImageFrame<Color>) -> Self {
|
||||
GraphicElement::RasterFrame(crate::RasterFrame::ImageFrame(ImageFrameTable::new(image_frame.image)))
|
||||
GraphicElement::RasterDataType(crate::RasterDataType::RasterData(RasterDataTable::new(image_frame.image)))
|
||||
}
|
||||
}
|
||||
impl From<GraphicElement> for ImageFrame<Color> {
|
||||
fn from(element: GraphicElement) -> Self {
|
||||
match element {
|
||||
GraphicElement::RasterFrame(crate::RasterFrame::ImageFrame(image)) => Self {
|
||||
GraphicElement::RasterDataType(crate::RasterDataType::RasterData(image)) => Self {
|
||||
image: image.instance_ref_iter().next().unwrap().instance.clone(),
|
||||
},
|
||||
_ => panic!("Expected Image, found {:?}", element),
|
||||
@@ -326,7 +320,7 @@ pub fn migrate_image_frame_instance<'de, D: serde::Deserializer<'de>>(deserializ
|
||||
Image(Image<Color>),
|
||||
OldImageFrame(OldImageFrame<Color>),
|
||||
ImageFrame(Instances<ImageFrame<Color>>),
|
||||
ImageFrameTable(ImageFrameTable<Color>),
|
||||
RasterDataTable(RasterDataTable<Color>),
|
||||
ImageInstance(Instance<Image<Color>>),
|
||||
}
|
||||
|
||||
@@ -345,13 +339,13 @@ pub fn migrate_image_frame_instance<'de, D: serde::Deserializer<'de>>(deserializ
|
||||
instance: image_frame.instance_ref_iter().next().unwrap().instance.image.clone(),
|
||||
..Default::default()
|
||||
},
|
||||
FormatVersions::ImageFrameTable(image_frame_table) => image_frame_table.instance_iter().next().unwrap_or_default(),
|
||||
FormatVersions::RasterDataTable(image_frame_table) => image_frame_table.instance_iter().next().unwrap_or_default(),
|
||||
FormatVersions::ImageInstance(image_instance) => image_instance,
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: Rename to ImageTable
|
||||
pub type ImageFrameTable<P> = Instances<Image<P>>;
|
||||
pub type RasterDataTable<P> = Instances<Image<P>>;
|
||||
|
||||
impl<P: Debug + Copy + Pixel> Sample for Image<P> {
|
||||
type Pixel = P;
|
||||
@@ -399,9 +393,9 @@ impl From<Image<Color>> for Image<SRGBA8> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ImageFrameTable<Color>> for ImageFrameTable<SRGBA8> {
|
||||
fn from(image_frame_table: ImageFrameTable<Color>) -> Self {
|
||||
let mut result_table = ImageFrameTable::<SRGBA8>::default();
|
||||
impl From<RasterDataTable<Color>> for RasterDataTable<SRGBA8> {
|
||||
fn from(image_frame_table: RasterDataTable<Color>) -> Self {
|
||||
let mut result_table = RasterDataTable::<SRGBA8>::default();
|
||||
|
||||
for image_frame_instance in image_frame_table.instance_iter() {
|
||||
result_table.push(Instance {
|
||||
|
||||
Reference in New Issue
Block a user