Skip to content

Commit 1ede93f

Browse files
committed
Remove ImageFrame<T> by flattening it into Image<T>
1 parent 3183949 commit 1ede93f

File tree

16 files changed

+189
-227
lines changed

16 files changed

+189
-227
lines changed

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::node_graph_executor::NodeGraphExecutor;
2828
use bezier_rs::Subpath;
2929
use graph_craft::document::value::TaggedValue;
3030
use graph_craft::document::{NodeId, NodeInput, NodeNetwork, OldNodeNetwork};
31-
use graphene_core::raster::image::{ImageFrame, ImageFrameTable};
31+
use graphene_core::raster::image::ImageFrameTable;
3232
use graphene_core::raster::BlendMode;
3333
use graphene_core::vector::style::ViewMode;
3434
use graphene_std::renderer::{ClickTarget, Quad};
@@ -818,7 +818,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
818818

819819
responses.add(DocumentMessage::AddTransaction);
820820

821-
let layer = graph_modification_utils::new_image_layer(ImageFrameTable::new(ImageFrame { image }), layer_node_id, self.new_layer_parent(true), responses);
821+
let layer = graph_modification_utils::new_image_layer(ImageFrameTable::new(image), layer_node_id, self.new_layer_parent(true), responses);
822822

823823
if let Some(name) = name {
824824
responses.add(NodeGraphMessage::SetDisplayName {

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6222,10 +6222,11 @@ impl PropertiesRow {
62226222
fn migrate_output_names<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<Vec<String>, D::Error> {
62236223
use serde::Deserialize;
62246224

6225-
const REPLACEMENTS: [(&str, &str); 3] = [
6225+
const REPLACEMENTS: [(&str, &str); 4] = [
62266226
("VectorData", "Instances<VectorData>"),
62276227
("GraphicGroup", "Instances<GraphicGroup>"),
6228-
("ImageFrame", "Instances<ImageFrame>"),
6228+
("ImageFrame", "Instances<Image>"),
6229+
("Instances<ImageFrame>", "Instances<Image>"),
62296230
];
62306231

62316232
let mut names = Vec::<String>::deserialize(deserializer)?;

node-graph/gcore/src/graphic_element.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::application_io::{TextureFrame, TextureFrameTable};
22
use crate::instances::Instances;
3-
use crate::raster::image::{ImageFrame, ImageFrameTable};
3+
use crate::raster::image::{Image, ImageFrameTable};
44
use crate::raster::BlendMode;
55
use crate::transform::{Transform, TransformMut};
66
use crate::uuid::NodeId;
@@ -111,9 +111,9 @@ impl From<VectorDataTable> for GraphicGroupTable {
111111
Self::new(GraphicGroup::new(vec![GraphicElement::VectorData(vector_data)]))
112112
}
113113
}
114-
impl From<ImageFrame<Color>> for GraphicGroupTable {
115-
fn from(image_frame: ImageFrame<Color>) -> Self {
116-
Self::new(GraphicGroup::new(vec![GraphicElement::RasterFrame(RasterFrame::ImageFrame(ImageFrameTable::new(image_frame)))]))
114+
impl From<Image<Color>> for GraphicGroupTable {
115+
fn from(image: Image<Color>) -> Self {
116+
Self::new(GraphicGroup::new(vec![GraphicElement::RasterFrame(RasterFrame::ImageFrame(ImageFrameTable::new(image)))]))
117117
}
118118
}
119119
impl From<ImageFrameTable<Color>> for GraphicGroupTable {
@@ -207,7 +207,7 @@ impl<'de> serde::Deserialize<'de> for RasterFrame {
207207
where
208208
D: serde::Deserializer<'de>,
209209
{
210-
Ok(RasterFrame::ImageFrame(ImageFrameTable::new(ImageFrame::deserialize(deserializer)?)))
210+
Ok(RasterFrame::ImageFrame(ImageFrameTable::new(Image::deserialize(deserializer)?)))
211211
}
212212
}
213213

@@ -382,7 +382,7 @@ async fn to_artboard<Data: Into<GraphicGroupTable> + 'n>(
382382
}
383383

384384
#[node_macro::node(category(""))]
385-
async fn append_artboard(ctx: impl Ctx, mut artboards: ArtboardGroup, artboard: Artboard, node_path: Vec<NodeId>) -> ArtboardGroup {
385+
async fn append_artboard(_ctx: impl Ctx, mut artboards: ArtboardGroup, artboard: Artboard, node_path: Vec<NodeId>) -> ArtboardGroup {
386386
// let mut artboards = artboards.eval(ctx.clone()).await;
387387
// let artboard = artboard.eval(ctx).await;
388388
// let foot = ctx.footprint();
@@ -399,8 +399,8 @@ async fn append_artboard(ctx: impl Ctx, mut artboards: ArtboardGroup, artboard:
399399
}
400400

401401
// TODO: Remove this one
402-
impl From<ImageFrame<Color>> for GraphicElement {
403-
fn from(image_frame: ImageFrame<Color>) -> Self {
402+
impl From<Image<Color>> for GraphicElement {
403+
fn from(image_frame: Image<Color>) -> Self {
404404
GraphicElement::RasterFrame(RasterFrame::ImageFrame(ImageFrameTable::new(image_frame)))
405405
}
406406
}

node-graph/gcore/src/graphic_element/renderer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ impl GraphicElementRendered for ImageFrameTable<Color> {
831831

832832
match render_params.image_render_mode {
833833
ImageRenderMode::Base64 => {
834-
let image = &instance.instance.image;
834+
let image = &instance.instance;
835835
if image.data.is_empty() {
836836
return;
837837
}
@@ -894,7 +894,7 @@ impl GraphicElementRendered for ImageFrameTable<Color> {
894894
use vello::peniko;
895895

896896
for instance in self.instances() {
897-
let image = &instance.instance.image;
897+
let image = &instance.instance;
898898
if image.data.is_empty() {
899899
return;
900900
}
@@ -918,7 +918,7 @@ impl GraphicElementRendered for RasterFrame {
918918
};
919919

920920
for instance in image.instances() {
921-
let (image, blending) = (&instance.instance.image, instance.alpha_blending);
921+
let (image, blending) = (&instance.instance, instance.alpha_blending);
922922
if image.data.is_empty() {
923923
return;
924924
}
@@ -994,7 +994,7 @@ impl GraphicElementRendered for RasterFrame {
994994
match self {
995995
RasterFrame::ImageFrame(image_frame) => {
996996
for instance in image_frame.instances() {
997-
let image = &instance.instance.image;
997+
let image = &instance.instance;
998998
if image.data.is_empty() {
999999
return;
10001000
}

node-graph/gcore/src/instances.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::application_io::{TextureFrame, TextureFrameTable};
2-
use crate::raster::image::{ImageFrame, ImageFrameTable};
2+
use crate::raster::image::{Image, ImageFrameTable};
33
use crate::raster::Pixel;
44
use crate::transform::{Transform, TransformMut};
55
use crate::vector::{InstanceId, VectorData, VectorDataTable};
@@ -209,24 +209,24 @@ impl TransformMut for TextureFrameTable {
209209
}
210210
}
211211

212-
// IMAGE FRAME
213-
impl<P: Pixel> Transform for Instance<'_, ImageFrame<P>> {
212+
// IMAGE
213+
impl<P: Pixel> Transform for Instance<'_, Image<P>> {
214214
fn transform(&self) -> DAffine2 {
215215
*self.transform
216216
}
217217
fn local_pivot(&self, pivot: DVec2) -> DVec2 {
218218
self.transform.transform_point2(pivot)
219219
}
220220
}
221-
impl<P: Pixel> Transform for InstanceMut<'_, ImageFrame<P>> {
221+
impl<P: Pixel> Transform for InstanceMut<'_, Image<P>> {
222222
fn transform(&self) -> DAffine2 {
223223
*self.transform
224224
}
225225
fn local_pivot(&self, pivot: DVec2) -> DVec2 {
226226
self.transform.transform_point2(pivot)
227227
}
228228
}
229-
impl<P: Pixel> TransformMut for InstanceMut<'_, ImageFrame<P>> {
229+
impl<P: Pixel> TransformMut for InstanceMut<'_, Image<P>> {
230230
fn transform_mut(&mut self) -> &mut DAffine2 {
231231
self.transform
232232
}
@@ -237,7 +237,7 @@ impl<P: Pixel> Transform for ImageFrameTable<P>
237237
where
238238
P: dyn_any::StaticType,
239239
P::Static: Pixel,
240-
GraphicElement: From<ImageFrame<P>>,
240+
GraphicElement: From<Image<P>>,
241241
{
242242
fn transform(&self) -> DAffine2 {
243243
self.one_instance().transform()
@@ -247,7 +247,7 @@ impl<P: Pixel> TransformMut for ImageFrameTable<P>
247247
where
248248
P: dyn_any::StaticType,
249249
P::Static: Pixel,
250-
GraphicElement: From<ImageFrame<P>>,
250+
GraphicElement: From<Image<P>>,
251251
{
252252
fn transform_mut(&mut self) -> &mut DAffine2 {
253253
self.transform.first_mut().unwrap_or_else(|| panic!("ONE INSTANCE EXPECTED"))

node-graph/gcore/src/raster/adjustments.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#[cfg(feature = "alloc")]
44
use crate::raster::curve::{Curve, CurveManipulatorGroup, ValueMapperNode};
55
#[cfg(feature = "alloc")]
6-
use crate::raster::image::{ImageFrame, ImageFrameTable};
6+
use crate::raster::image::{Image, ImageFrameTable};
77
use crate::raster::{Channel, Color, Pixel};
88
use crate::registry::types::{Angle, Percentage, SignedPercentage};
99
use crate::vector::style::GradientStops;
@@ -605,15 +605,13 @@ impl Blend<Color> for ImageFrameTable<Color> {
605605
let mut result = self.clone();
606606

607607
for (over, under) in result.instances_mut().zip(under.instances()) {
608-
let data = over.instance.image.data.iter().zip(under.instance.image.data.iter()).map(|(a, b)| blend_fn(*a, *b)).collect();
609-
610-
*over.instance = ImageFrame {
611-
image: super::Image {
612-
data,
613-
width: over.instance.image.width,
614-
height: over.instance.image.height,
615-
base64_string: None,
616-
},
608+
let data = over.instance.data.iter().zip(under.instance.data.iter()).map(|(a, b)| blend_fn(*a, *b)).collect();
609+
610+
*over.instance = Image {
611+
data,
612+
width: over.instance.width,
613+
height: over.instance.height,
614+
base64_string: None,
617615
};
618616
}
619617

@@ -738,11 +736,11 @@ impl<P: Pixel> Adjust<P> for ImageFrameTable<P>
738736
where
739737
P: dyn_any::StaticType,
740738
P::Static: Pixel,
741-
GraphicElement: From<ImageFrame<P>>,
739+
GraphicElement: From<Image<P>>,
742740
{
743741
fn adjust(&mut self, map_fn: impl Fn(&P) -> P) {
744742
for instance in self.instances_mut() {
745-
for c in instance.instance.image.data.iter_mut() {
743+
for c in instance.instance.data.iter_mut() {
746744
*c = map_fn(c);
747745
}
748746
}
@@ -1386,7 +1384,7 @@ impl<P: Pixel> MultiplyAlpha for ImageFrameTable<P>
13861384
where
13871385
P: dyn_any::StaticType,
13881386
P::Static: Pixel,
1389-
GraphicElement: From<ImageFrame<P>>,
1387+
GraphicElement: From<Image<P>>,
13901388
{
13911389
fn multiply_alpha(&mut self, factor: f64) {
13921390
for instance in self.instances_mut() {
@@ -1539,13 +1537,13 @@ fn color_overlay<T: Adjust<Color>>(
15391537

15401538
// #[cfg(feature = "alloc")]
15411539
// mod index_node {
1542-
// use crate::raster::{Color, ImageFrame};
1540+
// use crate::raster::{Color, Image};
15431541
// use crate::Ctx;
15441542

15451543
// #[node_macro::node(category(""))]
15461544
// pub fn index<T: Default + Clone>(
15471545
// _: impl Ctx,
1548-
// #[implementations(Vec<ImageFrame<Color>>, Vec<Color>)]
1546+
// #[implementations(Vec<Image<Color>>, Vec<Color>)]
15491547
// #[widget(ParsedWidgetOverride::Hidden)]
15501548
// input: Vec<T>,
15511549
// index: u32,
@@ -1561,7 +1559,7 @@ fn color_overlay<T: Adjust<Color>>(
15611559

15621560
#[cfg(test)]
15631561
mod test {
1564-
use crate::raster::image::{ImageFrame, ImageFrameTable};
1562+
use crate::raster::image::{Image, ImageFrameTable};
15651563
use crate::raster::{BlendMode, Image};
15661564
use crate::{Color, Node};
15671565
use std::pin::Pin;
@@ -1580,7 +1578,7 @@ mod test {
15801578
#[tokio::test]
15811579
async fn color_overlay_multiply() {
15821580
let image_color = Color::from_rgbaf32_unchecked(0.7, 0.6, 0.5, 0.4);
1583-
let image = ImageFrame { image: Image::new(1, 1, image_color) };
1581+
let image = Image::new(1, 1, image_color);
15841582

15851583
// Color { red: 0., green: 1., blue: 0., alpha: 1. }
15861584
let overlay_color = Color::GREEN;
@@ -1592,6 +1590,6 @@ mod test {
15921590
let result = result.one_instance().instance;
15931591

15941592
// The output should just be the original green and alpha channels (as we multiply them by 1 and other channels by 0)
1595-
assert_eq!(result.image.data[0], Color::from_rgbaf32_unchecked(0., image_color.g(), 0., image_color.a()));
1593+
assert_eq!(result.data[0], Color::from_rgbaf32_unchecked(0., image_color.g(), 0., image_color.a()));
15961594
}
15971595
}

node-graph/gcore/src/raster/brush_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct BrushCacheImpl {
3232
impl BrushCacheImpl {
3333
fn compute_brush_plan(&mut self, mut background: ImageFrameTable<Color>, input: &[BrushStroke]) -> BrushPlan {
3434
// Do background invalidation.
35-
if background.one_instance().instance.image != self.background.one_instance().instance.image {
35+
if background.one_instance().instance != self.background.one_instance().instance {
3636
self.background = background.clone();
3737
return BrushPlan {
3838
strokes: input.to_vec(),

0 commit comments

Comments
 (0)