Fixed Color node and added single color invert
This commit is contained in:
parent
4f348fe66a
commit
9c6b5e8d6d
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Unity.Collections;
|
using Unity.Collections;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -5,6 +6,7 @@ using UnityEngine;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A structure that holds image pixel data and its dimensions.
|
/// A structure that holds image pixel data and its dimensions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
public struct ImageData
|
public struct ImageData
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -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<byte> input = new NativeArray<byte>(inputChannel.ChannelData, Allocator.Persistent);
|
||||||
|
NativeArray<byte> output = new NativeArray<byte>(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<byte> input;
|
||||||
|
[WriteOnly] public NativeArray<byte> output;
|
||||||
|
|
||||||
|
public void Execute()
|
||||||
|
{
|
||||||
|
int length = input.Length;
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
output[i] = (byte)(255 - input[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 51378877ff184d868ef4c507dba15ef9
|
||||||
|
timeCreated: 1745794420
|
@ -1,4 +1,5 @@
|
|||||||
using ImageProcessingGraph.Editor.Nodes.NodeAttributes;
|
using ImageProcessingGraph.Editor.Nodes.NodeAttributes;
|
||||||
|
using Unity.Burst;
|
||||||
using Unity.Collections;
|
using Unity.Collections;
|
||||||
using Unity.Jobs;
|
using Unity.Jobs;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -24,7 +25,9 @@ namespace ImageProcessingGraph.Editor.Nodes.Fun_Nodes.Texture
|
|||||||
public ImageData inputTexture;
|
public ImageData inputTexture;
|
||||||
|
|
||||||
// Job struct for combining RGBA channels
|
// Job struct for combining RGBA channels
|
||||||
|
[BurstCompile]
|
||||||
struct RGBACombineJob : IJob
|
struct RGBACombineJob : IJob
|
||||||
|
|
||||||
{
|
{
|
||||||
public NativeArray<byte> rData;
|
public NativeArray<byte> rData;
|
||||||
public NativeArray<byte> gData;
|
public NativeArray<byte> gData;
|
||||||
|
@ -34,6 +34,7 @@ namespace ImageProcessingGraph.Editor.Nodes.Import_Nodes
|
|||||||
textureImporter.ReadTextureSettings(settings);
|
textureImporter.ReadTextureSettings(settings);
|
||||||
settings.readable = true;
|
settings.readable = true;
|
||||||
textureImporter.SetTextureSettings(settings);
|
textureImporter.SetTextureSettings(settings);
|
||||||
|
EditorUtility.SetDirty(textureImport);
|
||||||
textureImporter.SaveAndReimport();
|
textureImporter.SaveAndReimport();
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ namespace ImageProcessingGraph.Editor.Nodes.Types.Image.Utilities
|
|||||||
{
|
{
|
||||||
int pixelCount = Width * Height;
|
int pixelCount = Width * Height;
|
||||||
|
|
||||||
NativeArray<byte> outputData = new NativeArray<byte>(pixelCount * 4, Allocator.Persistent);
|
NativeArray<byte> outputData = new NativeArray<byte>(pixelCount, Allocator.Persistent);
|
||||||
|
|
||||||
CreateSingleColorJob job = new CreateSingleColorJob
|
CreateSingleColorJob job = new CreateSingleColorJob
|
||||||
{
|
{
|
||||||
@ -50,7 +50,7 @@ namespace ImageProcessingGraph.Editor.Nodes.Types.Image.Utilities
|
|||||||
public void Execute()
|
public void Execute()
|
||||||
{
|
{
|
||||||
// More efficient linear write pattern
|
// 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;
|
outputData[i] = (byte)color32;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user