{
  "Name": "Waveform",
  "_id": "32248acd-d49d-4727-ace6-7c20f123aa9f",
  "Namespace": "lib.image.analysis",
  "Description": "Generates a spectroscope of the incoming image.",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "a2b9e803-87a2-4390-8d08-a14f9373e238",
      "DefaultValue": {
        "Type": "Text",
        "Value": [
          "//>>> _common parameters\r",
          "float4x4 objectToWorldMatrix;",
          "float4x4 worldToCameraMatrix;",
          "float4x4 projMatrix;",
          "Texture2D txDiffuse;",
          "float2 RenderTargetSize;",
          "//<<< _common parameters\r",
          "\r",
          "//>>> _parameters\r",
          "Texture2D Image;",
          "float UpperLimit;",
          "float SampleCount;",
          "float Original;",
          "float RGB;",
          "float GrayScale;",
          "float Lines;",
          "float GuideAt;",
          "//<<< _parameters\r",
          " \r",
          "//>>> setup\r",
          "SamplerState samLinear\r",
          "{\r",
          "    //Filter = MIN_MAG_MIP_POINT;\r",
          "    Filter = MIN_MAG_MIP_LINEAR;\r",
          "    AddressU = Clamp;\r",
          "    AddressV = Clamp;\r",
          "};\r",
          "//<<< setup\r",
          "\r",
          "//>>> declarations\r",
          "struct VS_IN\r",
          "{\r",
          "    float4 pos : POSITION;\r",
          "    float2 texCoord : TEXCOORD;\r",
          "};\r",
          "\r",
          "struct PS_IN\r",
          "{\r",
          "    float4 pos : SV_POSITION;\r",
          "    float2 texCoord: TEXCOORD0;\t    \r",
          "    float3 worldTViewPos: TEXCOORD1;\r",
          "    float3 worldTViewDir: TEXCOORD2;\r",
          "};\r",
          "//<<< declarations\r",
          "\r",
          "//>>> _GS\r",
          "",
          "//<<< _GS\r",
          "\r",
          "//>>> _VS \r",
          "PS_IN VS( VS_IN input )",
          "{",
          "    PS_IN output = (PS_IN)0;",
          "",
          "    output.pos = mul(input.pos, worldToCameraMatrix);",
          "    output.pos = mul(output.pos, projMatrix);",
          "    output.texCoord = input.texCoord;",
          "",
          "    return output;",
          "}",
          "//<<< _VS\r",
          "\r",
          "//>>> PS\r",
          "\r",
          "float IsBetween( float value, float low, float high) {\r",
          "    return (value >= low && value <= high) ? 1:0;\r",
          "}\r",
          "\r",
          "\r",
          "float4 PS( PS_IN input ) : SV_Target\r",
          "{\r",
          "\r",
          "    float4 c = Image.Sample(samLinear, input.texCoord);\r",
          "    c.rgb = clamp(c.rgb, 0, 1000);\r",
          "    \r",
          "    c*= Original;\r",
          "    float4 rgba;\r",
          "    float gray;\r",
          "    \r",
          "    float lowBound = 0.95 * UpperLimit - input.texCoord.y * UpperLimit - 0.1;\r",
          "    float highBound= 0.95 * UpperLimit - input.texCoord.y * UpperLimit - 0.1 + 1/(RenderTargetSize.y) * UpperLimit;\r",
          "    \r",
          "    float sampleX = input.texCoord.x * 4.2 % 1.05;\r",
          "    \r",
          "    if ( sampleX > 1){\r",
          "        discard;\r",
          "    }\r",
          "    for (int i = 0; i < SampleCount  ; ++i) {\r",
          "        float4 s = Image.Sample(samLinear, float2(sampleX, i/SampleCount));\r",
          "        //s = clamp(s, 0, 1000);\r",
          "        \r",
          "        rgba.r += IsBetween( s.r, lowBound, highBound) / SampleCount;\r",
          "        rgba.g += IsBetween( s.g, lowBound, highBound) / SampleCount; \r",
          "        rgba.b += IsBetween( s.b, lowBound, highBound) / SampleCount; \r",
          "        rgba.a += IsBetween( s.a, lowBound, highBound) / SampleCount; \r",
          "        \r",
          "        float average=(s.r + s.g + s.b)/3 ; \r",
          "        gray += IsBetween( average, lowBound, highBound) / SampleCount; \r",
          "    }\r",
          "        \r",
          "    \r",
          "    if( input.texCoord.x < 0.25) {\r",
          "        c.r += rgba.r * RGB;\r",
          "        c.gb += rgba.r * RGB * 0.5;\r",
          "    }\r",
          "    else if( input.texCoord.x < 0.5) {\r",
          "        c.g += rgba.g * RGB;\r",
          "        c.rb += rgba.g * RGB * 0.5;\r",
          "    }\r",
          "    else if( input.texCoord.x < 0.75) {\r",
          "        c.b += rgba.b * RGB;\r",
          "        c.rg += rgba.b * RGB * 0.5;\r",
          "    }\r",
          "    else {\r",
          "        //c.b += rgb.b * RGB;\r",
          "        //c.rg += rgb.b * RGB * 0.5;\r",
          "        //c.rgb +=  gray * GrayScale;\r",
          "        c.rgb += rgba.a * 0.5 * RGB;\r",
          "    }\r",
          "    //c.rgb = clamp(c.rgb, 0,1);\r",
          "    \r",
          "    \r",
          "        \r",
          "    float px = input.texCoord.x * (RenderTargetSize.x+1);\r",
          "    float py = input.texCoord.y * (RenderTargetSize.y+1);\r",
          "    if( IsBetween( GuideAt, lowBound, highBound)) {\r",
          "        if( px % 6 > 3) {\r",
          "            c.rgb+= Lines;\r",
          "        }\r",
          "    }\r",
          "    \r",
          "    if(  highBound > 1 || highBound < 0) {\r",
          "        if( (px-0.5 + py-0.5) % 10 > 9) {\r",
          "            c.rgb+= Lines/3;\r",
          "        }\r",
          "    }\r",
          "\r",
          "    c.a = 1.0;\r",
          "    //c.rgb = 1- c.rgb;\r",
          "    //c.rgb = clamp( c.rgb, 0.0, 1);\r",
          "    //c= float4(0,0,1,1);\r",
          "    return c;\r",
          "}\r",
          "//<<< PS\r",
          "\r",
          "//>>> _technique\r",
          "technique10 Render",
          "{",
          "    pass P0",
          "    {",
          "        SetGeometryShader( 0 );",
          "        SetVertexShader( CompileShader( vs_4_0, VS() ) );",
          "        SetPixelShader( CompileShader( ps_4_0, PS() ) );",
          "    }",
          "}",
          "//<<< _technique\r",
          "\r",
          ""
        ]
      },
      "MetaID": "c522a66e-3260-4692-b3e3-79fd0361fa3d",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Image",
      "MetaInstanceID": "c4d80ad1-0934-4626-b912-1629e8f3f5a0",
      "DefaultValue": {
        "Type": "Image",
        "Value": "Framefield.Core.Image"
      },
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab",
      "IsMultiInput": "False",
      "Relevance": "Required",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "UpperLimit",
      "MetaInstanceID": "2944d144-eec5-4e6d-8bbc-edfc92bf4742",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1.4"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "1",
      "Max": "100",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "SampleCount",
      "MetaInstanceID": "20ac9eaf-929d-48c7-9ce8-cf90ece41a7c",
      "DefaultValue": {
        "Type": "Float",
        "Value": "50"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "100",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Original",
      "MetaInstanceID": "79655682-f2c0-492d-9825-1a443890a188",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0.2"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "100000",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "RGB",
      "MetaInstanceID": "545e5bed-2f93-4c71-8d36-87ef415191c3",
      "DefaultValue": {
        "Type": "Float",
        "Value": "13"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "GrayScale",
      "MetaInstanceID": "c21ffa04-c92d-4c3c-a13f-ac0d182de866",
      "DefaultValue": {
        "Type": "Float",
        "Value": "15"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Lines",
      "MetaInstanceID": "6ab22a7b-6552-4751-8a5a-625101f355e7",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0.5"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "GuideAt",
      "MetaInstanceID": "fdf015b5-0872-4fe6-90d2-7bc79b7b29b7",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0.9"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    }
  ],
  "Outputs": [
    {
      "Name": "Image",
      "MetaInstanceID": "ddc16ea0-687d-4baa-ad30-f1935fc5efbe",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "48039fd1-519a-4f8e-921f-287b659e4052",
      "MetaID": "f78aeed9-6573-416d-8029-ebe9d0fe7e49",
      "Name": "WaveformFunc",
      "Version": "880e7560-e217-417c-8b50-fb04758fcc30",
      "Type": "Float",
      "IsMultiInput": "True",
      "Script": [
        "//>>> _using",
        "using System;",
        "using System.Collections.Generic;",
        "using System.Linq;",
        "using System.Text;",
        "using SharpDX;",
        "using SharpDX.Direct3D11;",
        "using SharpDX.Windows;",
        "//<<< _using",
        "",
        "namespace Framefield.Core.IDf78aeed9_6573_416d_8029_ebe9d0fe7e49",
        "{",
        "    public class Class_Waveform : FXImageFunction",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Image = 1,",
        "            UpperLimit = 2,",
        "            SampleCount = 3,",
        "            Original = 4,",
        "            RGB = 5,",
        "            GrayScale = 6,",
        "            Lines = 7,",
        "            GuideAt = 8",
        "        }",
        "        //<<< _inputids",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx)",
        "        {",
        "            //>>> _params",
        "            var Code = inputs[(int)InputId.Code].Eval(context).Text;",
        "            var Image = inputs[(int)InputId.Image].Eval(context).Image; // Needs to be checked for null!",
        "            var UpperLimit = inputs[(int)InputId.UpperLimit].Eval(context).Value;",
        "            var SampleCount = inputs[(int)InputId.SampleCount].Eval(context).Value;",
        "            var Original = inputs[(int)InputId.Original].Eval(context).Value;",
        "            var RGB = inputs[(int)InputId.RGB].Eval(context).Value;",
        "            var GrayScale = inputs[(int)InputId.GrayScale].Eval(context).Value;",
        "            var Lines = inputs[(int)InputId.Lines].Eval(context).Value;",
        "            var GuideAt = inputs[(int)InputId.GuideAt].Eval(context).Value;",
        "            //<<< _params",
        "",
        "            return PrepareAndEvalOnChange(context, () => {",
        "                ClearRenderTarget(context, new SharpDX.Color4(0, 0, 0, 1));",
        "",
        "                //>>> _setup",
        "                using (var ImageView = new ShaderResourceView(context.D3DDevice, Image))",
        "                {",
        "                    _effect.GetVariableByName(\"RenderTargetSize\").AsVector().Set(new Vector2(_usedViewport.Width, _usedViewport.Height));",
        "                    _effect.GetVariableByName(\"Image\").AsShaderResource().SetResource(ImageView);",
        "                    _effect.GetVariableByName(\"UpperLimit\").AsScalar().Set(UpperLimit);",
        "                    _effect.GetVariableByName(\"SampleCount\").AsScalar().Set(SampleCount);",
        "                    _effect.GetVariableByName(\"Original\").AsScalar().Set(Original);",
        "                    _effect.GetVariableByName(\"RGB\").AsScalar().Set(RGB);",
        "                    _effect.GetVariableByName(\"GrayScale\").AsScalar().Set(GrayScale);",
        "                    _effect.GetVariableByName(\"Lines\").AsScalar().Set(Lines);",
        "                    _effect.GetVariableByName(\"GuideAt\").AsScalar().Set(GuideAt);",
        "                //<<< _setup",
        "",
        "                Render(context);",
        "",
        "                //>>> _cleanup",
        "                }",
        "                //<<< _cleanup",
        "            });",
        "        }",
        "",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "48039fd1-519a-4f8e-921f-287b659e4052",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "ddc16ea0-687d-4baa-ad30-f1935fc5efbe"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "a2b9e803-87a2-4390-8d08-a14f9373e238",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "48039fd1-519a-4f8e-921f-287b659e4052"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "c4d80ad1-0934-4626-b912-1629e8f3f5a0",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "48039fd1-519a-4f8e-921f-287b659e4052"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "2944d144-eec5-4e6d-8bbc-edfc92bf4742",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "48039fd1-519a-4f8e-921f-287b659e4052"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "20ac9eaf-929d-48c7-9ce8-cf90ece41a7c",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "48039fd1-519a-4f8e-921f-287b659e4052"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "79655682-f2c0-492d-9825-1a443890a188",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "48039fd1-519a-4f8e-921f-287b659e4052"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "545e5bed-2f93-4c71-8d36-87ef415191c3",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "48039fd1-519a-4f8e-921f-287b659e4052"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "c21ffa04-c92d-4c3c-a13f-ac0d182de866",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "48039fd1-519a-4f8e-921f-287b659e4052"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "6ab22a7b-6552-4751-8a5a-625101f355e7",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "48039fd1-519a-4f8e-921f-287b659e4052"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "fdf015b5-0872-4fe6-90d2-7bc79b7b29b7",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "48039fd1-519a-4f8e-921f-287b659e4052"
    }
  ]
}