76 lines
2.5 KiB
C#
76 lines
2.5 KiB
C#
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<byte> rData;
|
|
public NativeArray<byte> gData;
|
|
public NativeArray<byte> bData;
|
|
public NativeArray<byte> aData;
|
|
public NativeArray<Color32> 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<byte> rChannel = new NativeArray<byte>(r.ChannelData, Allocator.Persistent);
|
|
NativeArray<byte> gChannel = new NativeArray<byte>(g.ChannelData, Allocator.Persistent);
|
|
NativeArray<byte> bChannel = new NativeArray<byte>(b.ChannelData, Allocator.Persistent);
|
|
NativeArray<byte> aChannel = new NativeArray<byte>(a.ChannelData, Allocator.Persistent);
|
|
|
|
NativeArray<Color32> outputPixels = new NativeArray<Color32>(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);
|
|
}
|
|
}
|
|
}
|