Skip to content

Instance tables refactor part 3: flatten ImageFrame<P> in lieu of Image<P> #2256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::node_graph_executor::NodeGraphExecutor;
use bezier_rs::Subpath;
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{NodeId, NodeInput, NodeNetwork, OldNodeNetwork};
use graphene_core::raster::image::{ImageFrame, ImageFrameTable};
use graphene_core::raster::image::ImageFrameTable;
use graphene_core::raster::BlendMode;
use graphene_core::vector::style::ViewMode;
use graphene_std::renderer::{ClickTarget, Quad};
Expand Down Expand Up @@ -818,7 +818,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag

responses.add(DocumentMessage::AddTransaction);

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

if let Some(name) = name {
responses.add(NodeGraphMessage::SetDisplayName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use graphene_core::raster::{
use graphene_core::text::Font;
use graphene_core::vector::misc::CentroidType;
use graphene_core::vector::style::{GradientType, LineCap, LineJoin};
use graphene_std::application_io::TextureFrame;
use graphene_std::application_io::TextureFrameTable;
use graphene_std::transform::Footprint;
use graphene_std::vector::misc::BooleanOperation;
use graphene_std::vector::style::{Fill, FillChoice, FillType, GradientStops};
Expand Down Expand Up @@ -159,7 +159,7 @@ pub(crate) fn property_from_type(
Some(x) if x == TypeId::of::<Curve>() => curves_widget(document_node, node_id, index, name, true),
Some(x) if x == TypeId::of::<GradientStops>() => color_widget(document_node, node_id, index, name, ColorInput::default().allow_none(false), true),
Some(x) if x == TypeId::of::<VectorDataTable>() => vector_widget(document_node, node_id, index, name, true).into(),
Some(x) if x == TypeId::of::<RasterFrame>() || x == TypeId::of::<ImageFrameTable<Color>>() || x == TypeId::of::<TextureFrame>() => {
Some(x) if x == TypeId::of::<RasterFrame>() || x == TypeId::of::<ImageFrameTable<Color>>() || x == TypeId::of::<TextureFrameTable>() => {
raster_widget(document_node, node_id, index, name, true).into()
}
Some(x) if x == TypeId::of::<GraphicGroupTable>() => group_widget(document_node, node_id, index, name, true).into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6222,10 +6222,11 @@ impl PropertiesRow {
fn migrate_output_names<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<Vec<String>, D::Error> {
use serde::Deserialize;

const REPLACEMENTS: [(&str, &str); 3] = [
const REPLACEMENTS: [(&str, &str); 4] = [
("VectorData", "Instances<VectorData>"),
("GraphicGroup", "Instances<GraphicGroup>"),
("ImageFrame", "Instances<ImageFrame>"),
("ImageFrame", "Instances<Image>"),
("Instances<ImageFrame>", "Instances<Image>"),
];

let mut names = Vec::<String>::deserialize(deserializer)?;
Expand Down
15 changes: 8 additions & 7 deletions node-graph/gcore/src/application_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,18 @@ impl Size for web_sys::HtmlCanvasElement {
}
}

pub type TextureFrameTable = Instances<TextureFrame>;
// TODO: Rename to ImageTextureTable
pub type TextureFrameTable = Instances<ImageTexture>;

#[derive(Debug, Clone)]
pub struct TextureFrame {
pub struct ImageTexture {
#[cfg(feature = "wgpu")]
pub texture: Arc<wgpu::Texture>,
#[cfg(not(feature = "wgpu"))]
pub texture: (),
}

impl Hash for TextureFrame {
impl Hash for ImageTexture {
#[cfg(feature = "wgpu")]
fn hash<H: Hasher>(&self, state: &mut H) {
self.texture.hash(state);
Expand All @@ -83,18 +84,18 @@ impl Hash for TextureFrame {
fn hash<H: Hasher>(&self, _state: &mut H) {}
}

impl PartialEq for TextureFrame {
impl PartialEq for ImageTexture {
fn eq(&self, other: &Self) -> bool {
self.texture == other.texture
}
}

unsafe impl StaticType for TextureFrame {
type Static = TextureFrame;
unsafe impl StaticType for ImageTexture {
type Static = ImageTexture;
}

#[cfg(feature = "wgpu")]
impl Size for TextureFrame {
impl Size for ImageTexture {
fn size(&self) -> UVec2 {
UVec2::new(self.texture.width(), self.texture.height())
}
Expand Down
42 changes: 21 additions & 21 deletions node-graph/gcore/src/graphic_element.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::application_io::{TextureFrame, TextureFrameTable};
use crate::application_io::{ImageTexture, TextureFrameTable};
use crate::instances::Instances;
use crate::raster::image::{ImageFrame, ImageFrameTable};
use crate::raster::image::{Image, ImageFrameTable};
use crate::raster::BlendMode;
use crate::transform::{Transform, TransformMut};
use crate::uuid::NodeId;
Expand Down Expand Up @@ -111,19 +111,19 @@ impl From<VectorDataTable> for GraphicGroupTable {
Self::new(GraphicGroup::new(vec![GraphicElement::VectorData(vector_data)]))
}
}
impl From<ImageFrame<Color>> for GraphicGroupTable {
fn from(image_frame: ImageFrame<Color>) -> Self {
Self::new(GraphicGroup::new(vec![GraphicElement::RasterFrame(RasterFrame::ImageFrame(ImageFrameTable::new(image_frame)))]))
impl From<Image<Color>> for GraphicGroupTable {
fn from(image: Image<Color>) -> Self {
Self::new(GraphicGroup::new(vec![GraphicElement::RasterFrame(RasterFrame::ImageFrame(ImageFrameTable::new(image)))]))
}
}
impl From<ImageFrameTable<Color>> for GraphicGroupTable {
fn from(image_frame: ImageFrameTable<Color>) -> Self {
Self::new(GraphicGroup::new(vec![GraphicElement::RasterFrame(RasterFrame::ImageFrame(image_frame))]))
}
}
impl From<TextureFrame> for GraphicGroupTable {
fn from(texture_frame: TextureFrame) -> Self {
Self::new(GraphicGroup::new(vec![GraphicElement::RasterFrame(RasterFrame::TextureFrame(TextureFrameTable::new(texture_frame)))]))
impl From<ImageTexture> for GraphicGroupTable {
fn from(image_texture: ImageTexture) -> Self {
Self::new(GraphicGroup::new(vec![GraphicElement::RasterFrame(RasterFrame::TextureFrame(TextureFrameTable::new(image_texture)))]))
}
}
impl From<TextureFrameTable> for GraphicGroupTable {
Expand Down Expand Up @@ -194,11 +194,14 @@ impl GraphicElement {
}
}

// TODO: Rename to Raster
#[derive(Clone, Debug, Hash, PartialEq, DynAny)]
pub enum RasterFrame {
/// A CPU-based bitmap image with a finite position and extent, equivalent to the SVG <image> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image
// TODO: Rename to ImageTable
ImageFrame(ImageFrameTable<Color>),
/// A GPU texture with a finite position and extent
// TODO: Rename to ImageTextureTable
TextureFrame(TextureFrameTable),
}

Expand All @@ -207,7 +210,7 @@ impl<'de> serde::Deserialize<'de> for RasterFrame {
where
D: serde::Deserializer<'de>,
{
Ok(RasterFrame::ImageFrame(ImageFrameTable::new(ImageFrame::deserialize(deserializer)?)))
Ok(RasterFrame::ImageFrame(ImageFrameTable::new(Image::deserialize(deserializer)?)))
}
}

Expand Down Expand Up @@ -239,7 +242,7 @@ impl Artboard {
pub fn new(location: IVec2, dimensions: IVec2) -> Self {
Self {
graphic_group: GraphicGroupTable::default(),
label: String::from("Artboard"),
label: "Artboard".to_string(),
location: location.min(location + dimensions),
dimensions: dimensions.abs(),
background: Color::WHITE,
Expand Down Expand Up @@ -382,25 +385,22 @@ async fn to_artboard<Data: Into<GraphicGroupTable> + 'n>(
}

#[node_macro::node(category(""))]
async fn append_artboard(ctx: impl Ctx, mut artboards: ArtboardGroup, artboard: Artboard, node_path: Vec<NodeId>) -> ArtboardGroup {
async fn append_artboard(_ctx: impl Ctx, mut artboards: ArtboardGroup, artboard: Artboard, node_path: Vec<NodeId>) -> ArtboardGroup {
// let mut artboards = artboards.eval(ctx.clone()).await;
// let artboard = artboard.eval(ctx).await;
// let foot = ctx.footprint();
// log::debug!("{:?}", foot);
// Get the penultimate element of the node path, or None if the path is too short

// TODO: Delete this line
let _ctx = ctx;

// Get the penultimate element of the node path, or None if the path is too short.
// This is used to get the ID of the user-facing "Artboard" node (which encapsulates this internal "Append Artboard" node).
let encapsulating_node_id = node_path.get(node_path.len().wrapping_sub(2)).copied();
artboards.append_artboard(artboard, encapsulating_node_id);

artboards
}

// TODO: Remove this one
impl From<ImageFrame<Color>> for GraphicElement {
fn from(image_frame: ImageFrame<Color>) -> Self {
impl From<Image<Color>> for GraphicElement {
fn from(image_frame: Image<Color>) -> Self {
GraphicElement::RasterFrame(RasterFrame::ImageFrame(ImageFrameTable::new(image_frame)))
}
}
Expand All @@ -410,8 +410,8 @@ impl From<ImageFrameTable<Color>> for GraphicElement {
}
}
// TODO: Remove this one
impl From<TextureFrame> for GraphicElement {
fn from(texture: TextureFrame) -> Self {
impl From<ImageTexture> for GraphicElement {
fn from(texture: ImageTexture) -> Self {
GraphicElement::RasterFrame(RasterFrame::TextureFrame(TextureFrameTable::new(texture)))
}
}
Expand Down Expand Up @@ -462,7 +462,7 @@ trait ToGraphicElement: Into<GraphicElement> {}

impl ToGraphicElement for VectorDataTable {}
impl ToGraphicElement for ImageFrameTable<Color> {}
impl ToGraphicElement for TextureFrame {}
impl ToGraphicElement for ImageTexture {}

impl<T> From<T> for GraphicGroup
where
Expand Down
17 changes: 9 additions & 8 deletions node-graph/gcore/src/graphic_element/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ pub struct RenderMetadata {
pub clip_targets: HashSet<NodeId>,
}

// TODO: Rename to "Graphical"
pub trait GraphicElementRendered {
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams);

Expand Down Expand Up @@ -831,7 +832,7 @@ impl GraphicElementRendered for ImageFrameTable<Color> {

match render_params.image_render_mode {
ImageRenderMode::Base64 => {
let image = &instance.instance.image;
let image = &instance.instance;
if image.data.is_empty() {
return;
}
Expand Down Expand Up @@ -894,7 +895,7 @@ impl GraphicElementRendered for ImageFrameTable<Color> {
use vello::peniko;

for instance in self.instances() {
let image = &instance.instance.image;
let image = &instance.instance;
if image.data.is_empty() {
return;
}
Expand All @@ -918,7 +919,7 @@ impl GraphicElementRendered for RasterFrame {
};

for instance in image.instances() {
let (image, blending) = (&instance.instance.image, instance.alpha_blending);
let (image, blending) = (&instance.instance, instance.alpha_blending);
if image.data.is_empty() {
return;
}
Expand Down Expand Up @@ -992,9 +993,9 @@ impl GraphicElementRendered for RasterFrame {
};

match self {
RasterFrame::ImageFrame(image_frame) => {
for instance in image_frame.instances() {
let image = &instance.instance.image;
RasterFrame::ImageFrame(image) => {
for instance in image.instances() {
let image = &instance.instance;
if image.data.is_empty() {
return;
}
Expand All @@ -1004,8 +1005,8 @@ impl GraphicElementRendered for RasterFrame {
render_stuff(image, *instance.alpha_blending);
}
}
RasterFrame::TextureFrame(texture) => {
for instance in texture.instances() {
RasterFrame::TextureFrame(image_texture) => {
for instance in image_texture.instances() {
let image =
vello::peniko::Image::new(vec![].into(), peniko::Format::Rgba8, instance.instance.texture.width(), instance.instance.texture.height()).with_extend(peniko::Extend::Repeat);

Expand Down
24 changes: 12 additions & 12 deletions node-graph/gcore/src/instances.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::application_io::{TextureFrame, TextureFrameTable};
use crate::raster::image::{ImageFrame, ImageFrameTable};
use crate::application_io::{ImageTexture, TextureFrameTable};
use crate::raster::image::{Image, ImageFrameTable};
use crate::raster::Pixel;
use crate::transform::{Transform, TransformMut};
use crate::vector::{InstanceId, VectorData, VectorDataTable};
Expand Down Expand Up @@ -180,18 +180,18 @@ impl TransformMut for GraphicGroupTable {
}
}

// TEXTURE FRAME
impl Transform for Instance<'_, TextureFrame> {
// IMAGE TEXTURE
impl Transform for Instance<'_, ImageTexture> {
fn transform(&self) -> DAffine2 {
*self.transform
}
}
impl Transform for InstanceMut<'_, TextureFrame> {
impl Transform for InstanceMut<'_, ImageTexture> {
fn transform(&self) -> DAffine2 {
*self.transform
}
}
impl TransformMut for InstanceMut<'_, TextureFrame> {
impl TransformMut for InstanceMut<'_, ImageTexture> {
fn transform_mut(&mut self) -> &mut DAffine2 {
self.transform
}
Expand All @@ -209,24 +209,24 @@ impl TransformMut for TextureFrameTable {
}
}

// IMAGE FRAME
impl<P: Pixel> Transform for Instance<'_, ImageFrame<P>> {
// IMAGE
impl<P: Pixel> Transform for Instance<'_, Image<P>> {
fn transform(&self) -> DAffine2 {
*self.transform
}
fn local_pivot(&self, pivot: DVec2) -> DVec2 {
self.transform.transform_point2(pivot)
}
}
impl<P: Pixel> Transform for InstanceMut<'_, ImageFrame<P>> {
impl<P: Pixel> Transform for InstanceMut<'_, Image<P>> {
fn transform(&self) -> DAffine2 {
*self.transform
}
fn local_pivot(&self, pivot: DVec2) -> DVec2 {
self.transform.transform_point2(pivot)
}
}
impl<P: Pixel> TransformMut for InstanceMut<'_, ImageFrame<P>> {
impl<P: Pixel> TransformMut for InstanceMut<'_, Image<P>> {
fn transform_mut(&mut self) -> &mut DAffine2 {
self.transform
}
Expand All @@ -237,7 +237,7 @@ impl<P: Pixel> Transform for ImageFrameTable<P>
where
P: dyn_any::StaticType,
P::Static: Pixel,
GraphicElement: From<ImageFrame<P>>,
GraphicElement: From<Image<P>>,
{
fn transform(&self) -> DAffine2 {
self.one_instance().transform()
Expand All @@ -247,7 +247,7 @@ impl<P: Pixel> TransformMut for ImageFrameTable<P>
where
P: dyn_any::StaticType,
P::Static: Pixel,
GraphicElement: From<ImageFrame<P>>,
GraphicElement: From<Image<P>>,
{
fn transform_mut(&mut self) -> &mut DAffine2 {
self.transform.first_mut().unwrap_or_else(|| panic!("ONE INSTANCE EXPECTED"))
Expand Down
Loading