Browse Source

Merge pull request #894 from PixiEditor/sample-img-ctx-fix

Fixed SampleImageNode not working without a context
Krzysztof Krysiński 4 months ago
parent
commit
16c298f6fc

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 67e28c2a97d6002457875a3e81eb5c51ca8f4201
+Subproject commit 631c8e4cda079ae6872ff90ca2528bf6be09a69d

+ 3 - 3
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/CombineSeparate/SeparateColorNode.cs

@@ -56,13 +56,13 @@ public class SeparateColorNode : Node
         };
 
     private Half4 GetRgba(FuncContext ctx) => 
-        contextVariables.GetOrAttachNew(ctx, Color, () => ctx.GetValue(Color));
+        ctx.HasContext ? contextVariables.GetOrAttachNew(ctx, Color, () => ctx.GetValue(Color)) : ctx.GetValue(Color);
 
     private Half4 GetHsva(FuncContext ctx) =>
-        contextVariables.GetOrAttachNew(ctx, Color, () => ctx.RgbaToHsva(ctx.GetValue(Color)));
+        ctx.HasContext ? contextVariables.GetOrAttachNew(ctx, Color, () => ctx.RgbaToHsva(ctx.GetValue(Color))) : ctx.RgbaToHsva(ctx.GetValue(Color));
 
     private Half4 GetHsla(FuncContext ctx) =>
-        contextVariables.GetOrAttachNew(ctx, Color, () => ctx.RgbaToHsla(ctx.GetValue(Color)));
+        ctx.HasContext ? contextVariables.GetOrAttachNew(ctx, Color, () => ctx.RgbaToHsla(ctx.GetValue(Color))) : ctx.RgbaToHsla(ctx.GetValue(Color));
 
     public override Node CreateCopy() => new SeparateColorNode();
 }

+ 18 - 5
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/SampleImageNode.cs

@@ -30,21 +30,34 @@ public class SampleImageNode : Node
 
     private Half4 GetColor(FuncContext context)
     {
-        context.ThrowOnMissingContext();
-
         if (Image.Value is null)
         {
             return new Half4("");
         }
 
-        Expression uv = context.GetValue(Coordinate);
+        if (context.HasContext)
+        {
+            Expression uv = context.GetValue(Coordinate);
+
+            return context.SampleSurface(Image.Value.DrawingSurface, uv, SampleMode.Value);
+        }
+
+        Color color;
+        VecI pixelCoordinate = (VecI)context.GetValue(Coordinate).ConstantValue.Round();
+        if (SampleMode.Value == ColorSampleMode.ColorManaged)
+        {
+            color = Image.Value.GetSRGBPixel(pixelCoordinate);
+        }
+        else
+        {
+            color = Image.Value.GetPixel(pixelCoordinate);
+        }
 
-        return context.SampleSurface(Image.Value.DrawingSurface, uv, SampleMode.Value);
+        return new Half4("") { ConstantValue = color };
     }
 
     protected override void OnExecute(RenderContext context)
     {
-
     }
 
     public override Node CreateCopy() => new SampleImageNode();