using ImageProcessingGraph.Editor.Nodes.NodeAttributes; using Unity.Collections; using Unity.Jobs; using UnityEngine; namespace ImageProcessingGraph.Editor.Nodes.Fun_Nodes.Texture { [NodeInfo("RGBA Combine", "Channels/RGBA Combine", true)] public class RGBASCombine : BaseImageNode { [NodeAttributes.Input("R")] public SplitChannelData r; [NodeAttributes.Input("G")] public SplitChannelData g; [NodeAttributes.Input("B")] public SplitChannelData b; [NodeAttributes.Input("A")] public SplitChannelData a; [NodeAttributes.Output("")] public ImageData inputTexture; // Job struct for combining RGBA channels struct RGBACombineJob : IJob { public NativeArray rData; public NativeArray gData; public NativeArray bData; public NativeArray aData; public NativeArray outputData; public int length; // Execute method to combine the RGBA channels into a Color32 array public void Execute() { for (int i = 0; i < length; i++) { outputData[i] = new Color32(rData[i], gData[i], bData[i], aData[i]); } } } public override void Process() { int length = r.ChannelData.Length; // Allocate NativeArrays for the RGBA channels and the output pixel data NativeArray rChannel = new NativeArray(r.ChannelData, Allocator.Persistent); NativeArray gChannel = new NativeArray(g.ChannelData, Allocator.Persistent); NativeArray bChannel = new NativeArray(b.ChannelData, Allocator.Persistent); NativeArray aChannel = new NativeArray(a.ChannelData, Allocator.Persistent); NativeArray outputPixels = new NativeArray(length, Allocator.Persistent); // Create the job to combine RGBA channels RGBACombineJob combineJob = new RGBACombineJob { rData = rChannel, gData = gChannel, bData = bChannel, aData = aChannel, outputData = outputPixels, length = length }; combineJob.Run(); // Create the ImageData object with the combined pixel data inputTexture = new ImageData(outputPixels, (r.Width, r.Height), false); } } }