public static Texture2D BlendMono(Texture2D a, Texture2D b, int mode)
    {
        IntPairClass resA = new IntPairClass(a);
        IntPairClass resB = new IntPairClass(b);
        IntPairClass res = new IntPairClass();
        res.SetFromMinimum(resA, resB);

        Color[] originalColorsA = a.GetPixels(0, 0, res.value01, res.value02);
        Color[] originalColorsB = b.GetPixels(0, 0, res.value01, res.value02);
        Color[] resultColors = new Color[originalColorsA.Length];

        for (int i = 0; i < resultColors.Length; i++)
        {
            float aValue = originalColorsA[i].a;
            float bValue = originalColorsB[i].a;
            Color r = new Color();
            if (mode == 0 || mode == 1)
            {
                r = new Color(1f, 1f, 1f, aValue);
            }
            else if(mode == 2)
            {
                r = new Color(1f, 1f, 1f, aValue * bValue);
            }
            resultColors[i] = r;
        }

        Texture2D toReturn = new Texture2D(a.width, a.height, TextureFormat.Alpha8, true);
        toReturn.SetPixels(0, 0, a.width, a.height, resultColors);
        toReturn.Apply(true);
        return toReturn;
    }
    //0 - A over B, 1 - B over A, 2 - Multiply
    public static Texture2D Blend(Texture2D a, Texture2D b, int mode)
    {
        IntPairClass resA = new IntPairClass(a);
        IntPairClass resB = new IntPairClass(b);
        IntPairClass res = new IntPairClass();
        res.SetFromMinimum(resA, resB);

        Color[] originalColorsA = a.GetPixels(0, 0, res.value01, res.value02);
        Color[] originalColorsB = b.GetPixels(0, 0, res.value01, res.value02);
        Color[] resultColors = new Color[originalColorsA.Length];

        for(int i = 0; i < resultColors.Length; i++)
        {
            Color aColor = originalColorsA[i];
            Color bColor = originalColorsB[i];
            Color r = new Color();
            if(mode == 0 || mode == 1)
            {
                float restForB = GetMin(bColor.a, 1 - aColor.a);
                r = new Color(GetMiddleValue(aColor.r, bColor.r, aColor.a, restForB), GetMiddleValue(aColor.g, bColor.g, aColor.a, restForB), GetMiddleValue(aColor.b, bColor.b, aColor.a, restForB), aColor.a + restForB);
            }
            else if(mode == 2)
            {
                r = new Color(aColor.r * bColor.r, aColor.g * bColor.g, aColor.b * bColor.b, aColor.a * bColor.a);
            }
            resultColors[i] = r;
        }

        Texture2D toReturn = new Texture2D(a.width, a.height, TextureFormat.RGBA32, true);
        toReturn.SetPixels(0, 0, a.width, a.height, resultColors);
        toReturn.Apply(true);
        return toReturn;
    }
示例#3
0
    public override bool Calculate()
    {
        if (Inputs[0].connection != null)
        {
            inputResolution = Inputs[0].connection.GetValue<IntPairClass>();
            if (inputResolution.GetProduct() != 0)
            {
                outputImage = ImageHelperClass.MakeMonoSolidColor(value, inputResolution);

                Outputs[0].SetValue<Texture2D>(outputImage);
            }
        }
        return true;
    }
    public override bool Calculate()
    {
        if(Inputs[0].connection != null)
        {
            resolution = Inputs[0].connection.GetValue<IntPairClass>();
            xValue = resolution.value01;
            yValue = resolution.value02;

            Outputs[0].SetValue<int>(xValue);
            Outputs[1].SetValue<int>(yValue);
        }

        return true;
    }
示例#5
0
    public override bool Calculate()
    {
        if(inputImage != null)
        {
            Outputs[0].SetValue<Texture2D>(inputImage);
            imageResolution = new IntPairClass(inputImage.width, inputImage.height);
            Outputs[1].SetValue<IntPairClass>(imageResolution);

            prevImage = ImageHelperClass.MakePreviewImage(inputImage);
            prevStyle = ImageHelperClass.GetPreviewStyle();
        }

        return true;
    }
    public override bool Calculate()
    {
        if (Inputs[0].connection != null)
        {
            inputImage = Inputs[0].connection.GetValue<Texture2D>();
            if (inputImage != null)
            {
                outputResolution = new IntPairClass(inputImage);

                Outputs[0].SetValue<IntPairClass>(outputResolution);
            }

        }
        return true;
    }
    public override bool Calculate()
    {
        if(Inputs[0].connection != null)
        {
            inputImage = Inputs[0].connection.GetValue<Texture2D>();

            if(inputImage != null)
            {
                IntPairClass resolution = new IntPairClass(inputImage);
                Color[] originalColors = inputImage.GetPixels(0, 0, resolution.value01, resolution.value02);

                Color[] rColors = new Color[originalColors.Length];
                Color[] gColors = new Color[originalColors.Length];
                Color[] bColors = new Color[originalColors.Length];
                Color[] aColors = new Color[originalColors.Length];

                for(int i = 0; i < originalColors.Length; i++)
                {
                    Color c = originalColors[i];
                    rColors[i] = new Color(1, 1, 1, c.r);
                    gColors[i] = new Color(1, 1, 1, c.g);
                    bColors[i] = new Color(1, 1, 1, c.b);
                    aColors[i] = new Color(1, 1, 1, c.a);
                }
                rChannel = new Texture2D(resolution.value01, resolution.value02, TextureFormat.Alpha8, false);
                gChannel = new Texture2D(resolution.value01, resolution.value02, TextureFormat.Alpha8, false);
                bChannel = new Texture2D(resolution.value01, resolution.value02, TextureFormat.Alpha8, false);
                aChannel = new Texture2D(resolution.value01, resolution.value02, TextureFormat.Alpha8, false);

                rChannel.SetPixels(0, 0, resolution.value01, resolution.value02, rColors);
                rChannel.Apply();
                gChannel.SetPixels(0, 0, resolution.value01, resolution.value02, gColors);
                gChannel.Apply();
                bChannel.SetPixels(0, 0, resolution.value01, resolution.value02, bColors);
                bChannel.Apply();
                aChannel.SetPixels(0, 0, resolution.value01, resolution.value02, aColors);
                aChannel.Apply();

                Outputs[0].SetValue<Texture2D>(rChannel);
                Outputs[1].SetValue<Texture2D>(gChannel);
                Outputs[2].SetValue<Texture2D>(bChannel);
                Outputs[3].SetValue<Texture2D>(aChannel);
            }

        }

        return true;
    }
    public override bool Calculate()
    {
        if (Inputs[0].connection != null && Inputs[1].connection != null && Inputs[2].connection != null && Inputs[3].connection != null)
        {
            rInput = Inputs[0].connection.GetValue<Texture2D>();
            gInput = Inputs[1].connection.GetValue<Texture2D>();
            bInput = Inputs[2].connection.GetValue<Texture2D>();
            aInput = Inputs[3].connection.GetValue<Texture2D>();

            if (rInput != null && gInput != null && bInput != null && aInput != null)
            {
                IntPairClass rRes = new IntPairClass(rInput);
                IntPairClass gRes = new IntPairClass(gInput);
                IntPairClass bRes = new IntPairClass(bInput);
                IntPairClass aRes = new IntPairClass(aInput);

                IntPairClass resolution = new IntPairClass();
                resolution.SetFromMinimum(rRes, gRes, bRes, aRes);

                resTexture = new Texture2D(resolution.value01, resolution.value02, TextureFormat.RGBA32, true);
                Color[] rColors = rInput.GetPixels(0, 0, resolution.value01, resolution.value02);
                Color[] gColors = gInput.GetPixels(0, 0, resolution.value01, resolution.value02);
                Color[] bColors = bInput.GetPixels(0, 0, resolution.value01, resolution.value02);
                Color[] aColors = aInput.GetPixels(0, 0, resolution.value01, resolution.value02);

                Color[] resColors = new Color[rColors.Length];
                for (int i = 0; i < resColors.Length; i++)
                {
                    resColors[i] = new Color(rColors[i].a, gColors[i].a, bColors[i].a, aColors[i].a);
                }
                resTexture.SetPixels(0, 0, resolution.value01, resolution.value02, resColors);
                resTexture.Apply(true);
                Outputs[0].SetValue<Texture2D>(resTexture);

                prevImage = ImageHelperClass.MakePreviewImage(resTexture);
                prevStyle = ImageHelperClass.GetPreviewStyle();
            }
        }

        return true;
    }
示例#9
0
    public override bool Calculate()
    {
        if (Inputs[1].connection != null)
        {
            inputResolution = Inputs[1].connection.GetValue<IntPairClass>();
        }
        if (Inputs[0].connection != null)
        {
            inputImage = Inputs[0].connection.GetValue<Texture2D>();

            if(inputResolution.GetProduct() != 0)
            {
                outputImage = Instantiate(inputImage);
                TextureScale.Bilinear(outputImage, inputResolution.value01, inputResolution.value02);

                Outputs[0].SetValue<Texture2D>(outputImage);
            }
        }

        return true;
    }
    public override bool Calculate()
    {
        if (Inputs[0].connection != null)
        {
            inputImage = Inputs[0].connection.GetValue<Texture2D>();
            if(inputImage != null)
            {
                IntPairClass resolution = new IntPairClass(inputImage);
                if(type == resizeType.x2)
                {
                    resolution.MinScale(2);
                }
                else if(type == resizeType.x4)
                {
                    resolution.MinScale(4);
                }
                else if(type == resizeType.x8)
                {
                    resolution.MinScale(8);
                }
                else if(type == resizeType.x16)
                {
                    resolution.MinScale(16);
                }
                else if(type == resizeType.x32)
                {
                    resolution.MinScale(32);
                }
                outputImage = Instantiate(inputImage);
                TextureScale.Bilinear(outputImage, resolution.value01, resolution.value02);

                Outputs[0].SetValue<Texture2D>(outputImage);
            }

        }

        return true;
    }
示例#11
0
 public void SetFromMinimum(IntPairClass p1, IntPairClass p2, IntPairClass p3, IntPairClass p4)
 {
     int[] a1 = new int[4] { p1.value01, p2.value01, p3.value01, p4.value01 };
     int[] a2 = new int[4] { p1.value02, p2.value02, p3.value02, p4.value02 };
     value01 = Mathf.Min(a1);
     value02 = Mathf.Min(a2);
 }
示例#12
0
 public void SetFromMaximum(IntPairClass p1, IntPairClass p2, IntPairClass p3)
 {
     int[] a1 = new int[3] { p1.value01, p2.value01, p3.value01 };
     int[] a2 = new int[3] { p1.value02, p2.value02, p3.value02 };
     value01 = Mathf.Max(a1);
     value02 = Mathf.Max(a2);
 }
示例#13
0
    public static Texture2D MakeSolidColor(Color color, IntPairClass resolution)
    {
        if(resolution.GetProduct() > 0)
        {
            Texture2D toReturn = new Texture2D(resolution.value01, resolution.value02, TextureFormat.RGBA32, true);
            Color[] colors = new Color[resolution.GetProduct()];
            for(int i = 0; i < colors.Length; i++)
            {
                colors[i] = color;
            }
            toReturn.SetPixels(0, 0, toReturn.width, toReturn.height, colors);
            toReturn.Apply(true);

            return toReturn;
        }
        else
        {
            return Texture2D.whiteTexture;
        }
    }
示例#14
0
    public static Texture2D MakeReplaceAlpha(Texture2D image, Texture2D alpha)
    {
        Color[] originalColors = image.GetPixels(0, 0, image.width, image.height);
        Color[] alphaColors = alpha.GetPixels(0, 0, alpha.width, alpha.height);
        IntPairClass originalResolution = new IntPairClass(image);
        IntPairClass alphaResolution = new IntPairClass(alpha);
        IntPairClass res = new IntPairClass();
        res.SetFromMinimum(originalResolution, alphaResolution);
        Color[] contrastedColors = new Color[res.GetProduct()];
        for (int i = 0; i < contrastedColors.Length; i++)
        {
            Color c = originalColors[i];
            contrastedColors[i] = new Color(c.r, c.g, c.b, alphaColors[i].a);
        }
        Texture2D toReturn = new Texture2D(res.value01, res.value02, TextureFormat.RGBA32, true);
        toReturn.SetPixels(0, 0, res.value01, res.value02, contrastedColors);
        toReturn.Apply(true);

        return toReturn;
    }
示例#15
0
 public static Texture2D MakePreviewImage(Texture2D inputImage)
 {
     //Create preview image
     if(inputImage != null)
     {
         Texture2D prevImage = UnityEngine.Object.Instantiate<Texture2D>(inputImage);
         IntPairClass resolution = new IntPairClass(inputImage);
         if (!resolution.IsLimited(120))
         {
             float x = (float)resolution.value01;
             float y = (float)resolution.value02;
             float f = x / y;
             if (f < 1.0)
             {
                 TextureScale.Bilinear(prevImage, Convert.ToInt32(f * 120.0), 120);
             }
             else
             {
                 TextureScale.Bilinear(prevImage, 120, Convert.ToInt32(120.0 / f));
             }
         }
         return prevImage;
     }
     else
     {
         return Texture2D.blackTexture;
     }
 }
    public override bool Calculate()
    {
        if(type == resolutionType.x2)
        {
            IntPairClass resolution = new IntPairClass(2, 2);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }
        else if (type == resolutionType.x4)
        {
            IntPairClass resolution = new IntPairClass(4, 4);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }
        else if (type == resolutionType.x8)
        {
            IntPairClass resolution = new IntPairClass(8, 8);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }
        else if (type == resolutionType.x16)
        {
            IntPairClass resolution = new IntPairClass(16, 16);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }
        else if (type == resolutionType.x32)
        {
            IntPairClass resolution = new IntPairClass(32, 32);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }
        else if (type == resolutionType.x64)
        {
            IntPairClass resolution = new IntPairClass(64, 64);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }
        else if (type == resolutionType.x128)
        {
            IntPairClass resolution = new IntPairClass(128, 128);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }
        else if (type == resolutionType.x256)
        {
            IntPairClass resolution = new IntPairClass(256, 256);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }
        else if (type == resolutionType.x512)
        {
            IntPairClass resolution = new IntPairClass(512, 512);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }
        else if (type == resolutionType.x1024)
        {
            IntPairClass resolution = new IntPairClass(1024, 1024);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }
        else if (type == resolutionType.x2048)
        {
            IntPairClass resolution = new IntPairClass(2048, 2048);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }
        else if (type == resolutionType.x4096)
        {
            IntPairClass resolution = new IntPairClass(4096, 4096);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }
        else
        {
            IntPairClass resolution = new IntPairClass(1, 1);
            Outputs[0].SetValue<IntPairClass>(resolution);
        }

        return true;
    }