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", "Adjustments/Invert", true)] public class Texture2DInvert : BaseImageNode { [NodeAttributes.Input("")] public ImageData inputTexture; // Changed to ImageData [NodeAttributes.Output("")] public ImageData outputTexture; // Changed to ImageData public override void Process() { // Create an empty NativeArray for the output NativeArray output = new NativeArray(inputTexture.PixelData.Length, Allocator.Persistent); // Create and run the InvertJob InvertJob job = new InvertJob { pixels = inputTexture.PixelData, outputPixels = output }; job.Run(); // Store the result in the outputImage as an ImageData instance outputTexture = new ImageData(output, (inputTexture.Width, inputTexture.Height), inputTexture.isRGBA); } } [BurstCompile] public struct InvertJob : IJob { [ReadOnly] public NativeArray pixels; // Input pixels [WriteOnly] public NativeArray outputPixels; // Output pixels public void Execute() { int length = pixels.Length; // Invert each pixel color for (int i = 0; i < length; i++) { Color32 pixel = pixels[i]; outputPixels[i] = new Color32( (byte)(255 - pixel.r), (byte)(255 - pixel.g), (byte)(255 - pixel.b), pixel.a); } } } }