From 9c6b5e8d6dd0374cd24ad4b18b4ebd7c25db1d79 Mon Sep 17 00:00:00 2001
From: Chromium <62724067+Chromum@users.noreply.github.com>
Date: Mon, 28 Apr 2025 00:27:57 +0100
Subject: [PATCH] Fixed Color node and added single color invert
---
Editor/Scripts/Editor/Data Types/ImageData.cs | 2 +
.../Types/Image/Adjustments/InvertChannel.cs | 52 +++++++++++++++++++
.../Image/Adjustments/InvertChannel.cs.meta | 3 ++
.../Nodes/Types/Image/Channels/RGBACombine.cs | 3 ++
.../Types/Image/Import/Texture2DImport.cs | 1 +
.../Image/Utilities/SingleChannelColor.cs | 4 +-
6 files changed, 63 insertions(+), 2 deletions(-)
create mode 100644 Editor/Scripts/Editor/Nodes/Types/Image/Adjustments/InvertChannel.cs
create mode 100644 Editor/Scripts/Editor/Nodes/Types/Image/Adjustments/InvertChannel.cs.meta
diff --git a/Editor/Scripts/Editor/Data Types/ImageData.cs b/Editor/Scripts/Editor/Data Types/ImageData.cs
index 4670507..590b36b 100644
--- a/Editor/Scripts/Editor/Data Types/ImageData.cs
+++ b/Editor/Scripts/Editor/Data Types/ImageData.cs
@@ -1,3 +1,4 @@
+using System;
using System.IO;
using Unity.Collections;
using UnityEngine;
@@ -5,6 +6,7 @@ using UnityEngine;
///
/// A structure that holds image pixel data and its dimensions.
///
+[Serializable]
public struct ImageData
{
///
diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Adjustments/InvertChannel.cs b/Editor/Scripts/Editor/Nodes/Types/Image/Adjustments/InvertChannel.cs
new file mode 100644
index 0000000..077896d
--- /dev/null
+++ b/Editor/Scripts/Editor/Nodes/Types/Image/Adjustments/InvertChannel.cs
@@ -0,0 +1,52 @@
+using ImageProcessingGraph.Editor.Nodes.NodeAttributes;
+using Unity.Burst;
+using Unity.Collections;
+using Unity.Jobs;
+using UnityEngine;
+
+namespace ImageProcessingGraph.Editor.Nodes.Fun_Nodes.Texture
+{
+ [NodeInfoAttribute("Invert Channel", "Adjustments/InvertChannel", true)]
+ public class ChannelInvertNode : BaseImageNode
+ {
+ [NodeAttributes.Input("Input Channel")]
+ public SplitChannelData inputChannel;
+
+ [NodeAttributes.Output("Output Channel")]
+ public SplitChannelData outputChannel;
+
+ public override void Process()
+ {
+ NativeArray input = new NativeArray(inputChannel.ChannelData, Allocator.Persistent);
+ NativeArray output = new NativeArray(inputChannel.ChannelData.Length, Allocator.Persistent);
+
+ InvertChannelJob job = new InvertChannelJob
+ {
+ input = input,
+ output = output
+ };
+
+ job.Run();
+
+ byte[] outputArray = output.ToArray();
+
+ outputChannel = new SplitChannelData(outputArray, (inputChannel.Width, inputChannel.Height));
+ }
+ }
+
+ [BurstCompile]
+ public struct InvertChannelJob : IJob
+ {
+ [ReadOnly] public NativeArray input;
+ [WriteOnly] public NativeArray output;
+
+ public void Execute()
+ {
+ int length = input.Length;
+ for (int i = 0; i < length; i++)
+ {
+ output[i] = (byte)(255 - input[i]);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Adjustments/InvertChannel.cs.meta b/Editor/Scripts/Editor/Nodes/Types/Image/Adjustments/InvertChannel.cs.meta
new file mode 100644
index 0000000..2f56693
--- /dev/null
+++ b/Editor/Scripts/Editor/Nodes/Types/Image/Adjustments/InvertChannel.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 51378877ff184d868ef4c507dba15ef9
+timeCreated: 1745794420
\ No newline at end of file
diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Channels/RGBACombine.cs b/Editor/Scripts/Editor/Nodes/Types/Image/Channels/RGBACombine.cs
index deb7d80..6ae5113 100644
--- a/Editor/Scripts/Editor/Nodes/Types/Image/Channels/RGBACombine.cs
+++ b/Editor/Scripts/Editor/Nodes/Types/Image/Channels/RGBACombine.cs
@@ -1,4 +1,5 @@
using ImageProcessingGraph.Editor.Nodes.NodeAttributes;
+using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;
@@ -24,7 +25,9 @@ namespace ImageProcessingGraph.Editor.Nodes.Fun_Nodes.Texture
public ImageData inputTexture;
// Job struct for combining RGBA channels
+ [BurstCompile]
struct RGBACombineJob : IJob
+
{
public NativeArray rData;
public NativeArray gData;
diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Import/Texture2DImport.cs b/Editor/Scripts/Editor/Nodes/Types/Image/Import/Texture2DImport.cs
index 965a040..7be2c71 100644
--- a/Editor/Scripts/Editor/Nodes/Types/Image/Import/Texture2DImport.cs
+++ b/Editor/Scripts/Editor/Nodes/Types/Image/Import/Texture2DImport.cs
@@ -34,6 +34,7 @@ namespace ImageProcessingGraph.Editor.Nodes.Import_Nodes
textureImporter.ReadTextureSettings(settings);
settings.readable = true;
textureImporter.SetTextureSettings(settings);
+ EditorUtility.SetDirty(textureImport);
textureImporter.SaveAndReimport();
diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/SingleChannelColor.cs b/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/SingleChannelColor.cs
index efce42c..aa1daeb 100644
--- a/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/SingleChannelColor.cs
+++ b/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/SingleChannelColor.cs
@@ -23,7 +23,7 @@ namespace ImageProcessingGraph.Editor.Nodes.Types.Image.Utilities
{
int pixelCount = Width * Height;
- NativeArray outputData = new NativeArray(pixelCount * 4, Allocator.Persistent);
+ NativeArray outputData = new NativeArray(pixelCount, Allocator.Persistent);
CreateSingleColorJob job = new CreateSingleColorJob
{
@@ -50,7 +50,7 @@ namespace ImageProcessingGraph.Editor.Nodes.Types.Image.Utilities
public void Execute()
{
// More efficient linear write pattern
- for (int i = 0; i < width*height*4; i++)
+ for (int i = 0; i < width*height; i++)
{
outputData[i] = (byte)color32;
}