Example #1
0
    private void RegenerateSVTexture()
    {
        double h = picker != null ? picker.H * 360 : 0;

        if (image.texture != null)
        {
            DestroyImmediate(image.texture);
        }

        Texture2D texture = new Texture2D(100, 100);

        texture.hideFlags = HideFlags.DontSave;

        for (int s = 0; s < 100; s++)
        {
            Color32[] colors = new Color32[100];
            for (int v = 0; v < 100; v++)
            {
                colors[v] = HSVUtil.ConvertHsvToRgb(h, (float)s / 100, (float)v / 100, 1);
            }
            texture.SetPixels32(s, 0, 1, 100, colors);
        }
        texture.Apply();

        image.texture = texture;
    }
Example #2
0
    private void HSVChanged()
    {
        Color color = HSVUtil.ConvertHsvToRgb(_hue * 360, _saturation, _brightness, _alpha);

        _red   = color.r;
        _green = color.g;
        _blue  = color.b;
    }
Example #3
0
    public Color GetColor(float posX, float posY)
    {
        var color = HSVUtil.ConvertHsvToRgb(pointerPos * -360 + 360, posX, posY);

        return(color);
        //Debug.Log(posX + " " + posY);
        //return ((Texture2D)hsvImage.texture).GetPixel((int)(posX * hsvImage.texture.width ), (int)(posY * hsvImage.texture.height));
    }
Example #4
0
    public Color GetColor(float posX, float posY)
    {
        posY = Mathf.Clamp(posY, minV, maxV);
        posX = Mathf.Clamp(posX, minSat, maxSat);

        var color = HSVUtil.ConvertHsvToRgb(pointerPos * -(minHue + maxHue) + (minHue + maxHue), posX, posY);

        return(color);
    }
Example #5
0
    private void UpdateHSVColor()
    {
        Color color = HSVUtil.ConvertHsvToRgb(h * 360, s, v, a);

        r            = color.r;
        g            = color.g;
        b            = color.b;
        a            = color.a;
        CurrentColor = color;
        UpdateUIData();
    }
Example #6
0
    private void RegenerateSVTexture()
    {
        if (supportsComputeShaders)
        {
            float hue = picker != null ? picker.H : 0;

            compute.SetTexture(kernelID, "Texture", renderTexture);
            compute.SetFloats("TextureSize", textureWidth, textureHeight);
            compute.SetFloat("Hue", hue);

            compute.SetBool("linearColorSpace", QualitySettings.activeColorSpace == ColorSpace.Linear);

            var threadGroupsX = Mathf.CeilToInt(textureWidth / 32f);
            var threadGroupsY = Mathf.CeilToInt(textureHeight / 32f);
            compute.Dispatch(kernelID, threadGroupsX, threadGroupsY, 1);
        }
        else
        {
            double h = picker != null ? picker.H * 360 : 0;

            if (image.texture != null)
            {
                DestroyImmediate(image.texture);
            }

            var texture = new Texture2D(textureWidth, textureHeight);
            texture.hideFlags = HideFlags.DontSave;

            for (int s = 0; s < textureWidth; s++)
            {
                Color32[] colors = new Color32[textureHeight];
                for (int v = 0; v < textureHeight; v++)
                {
                    colors[v] = HSVUtil.ConvertHsvToRgb(h, (float)s / 100, (float)v / 100, 1);
                }
                texture.SetPixels32(s, 0, 1, textureHeight, colors);
            }
            texture.Apply();

            image.texture = texture;
        }
    }
Example #7
0
        private void RegenerateSVTexture()
        {
            double h = ((!(picker != null)) ? 0f : (picker.H * 360f));

            if (image.texture != null)
            {
                Object.DestroyImmediate(image.texture);
            }
            Texture2D texture2D = new Texture2D(100, 100);

            texture2D.hideFlags = HideFlags.DontSave;
            Texture2D texture2D2 = texture2D;

            for (int i = 0; i < 100; i++)
            {
                Color32[] array = new Color32[100];
                for (int j = 0; j < 100; j++)
                {
                    ref Color32 reference = ref array[j];
                    reference = HSVUtil.ConvertHsvToRgb(h, (float)i / 100f, (float)j / 100f, 1f);
                }
                texture2D2.SetPixels32(i, 0, 1, 100, array);
            }
 private void RegenerateSVTexture()
 {
     if (SystemInfo.supportsComputeShaders && compute != null)
     {
         var hue = picker != null ? picker.H : 0;
         compute.SetTexture(kernelID, "Texture", renderTexture);
         compute.SetFloats("TextureSize", textureWidth, textureHeight);
         compute.SetFloat("Hue", hue);
         var threadGroupsX = Mathf.CeilToInt(textureWidth / 32f);
         var threadGroupsY = Mathf.CeilToInt(textureHeight / 32f);
         compute.Dispatch(kernelID, threadGroupsX, threadGroupsY, 1);
     }
     else
     {
         double h = picker != null ? picker.H * 360 : 0;
         if (image.texture != null)
         {
             Destroy(image.texture);
         }
         var texture = new Texture2D(textureWidth, textureHeight)
         {
             hideFlags = HideFlags.DontSave
         };
         for (var s = 0; s < textureWidth; s++)
         {
             var colors = new Color32[textureHeight];
             for (var v = 0; v < textureHeight; v++)
             {
                 colors[v] = HSVUtil.ConvertHsvToRgb(h, (float)s / 100, (float)v / 100, 1);
             }
             texture.SetPixels32(s, 0, 1, textureHeight, colors);
         }
         texture.Apply();
         image.texture = texture;
     }
 }
    private void RegenerateTexture()
    {
        Color32 baseColor = picker != null ? picker.CurrentColor : Color.black;

        float h = picker != null ? picker.H : 0;
        float s = picker != null ? picker.S : 0;
        float v = picker != null ? picker.V : 0;

        Texture2D texture;

        Color32[] colors;

        bool vertical = direction == Slider.Direction.BottomToTop || direction == Slider.Direction.TopToBottom;
        bool inverted = direction == Slider.Direction.TopToBottom || direction == Slider.Direction.RightToLeft;

        int size;

        switch (type)
        {
        case ColorValues.R:
        case ColorValues.G:
        case ColorValues.B:
        case ColorValues.A:
            size = 255;
            break;

        case ColorValues.Hue:
            size = 360;
            break;

        case ColorValues.Saturation:
        case ColorValues.Value:
            size = 100;
            break;

        default:
            throw new System.NotImplementedException("");
        }
        if (vertical)
        {
            texture = new Texture2D(1, size);
        }
        else
        {
            texture = new Texture2D(size, 1);
        }

        texture.hideFlags = HideFlags.DontSave;
        colors            = new Color32[size];

        switch (type)
        {
        case ColorValues.R:
            for (byte i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = new Color32(i, baseColor.g, baseColor.b, 255);
            }
            break;

        case ColorValues.G:
            for (byte i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, i, baseColor.b, 255);
            }
            break;

        case ColorValues.B:
            for (byte i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, baseColor.g, i, 255);
            }
            break;

        case ColorValues.A:
            for (byte i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = new Color32(i, i, i, 255);
            }
            break;

        case ColorValues.Hue:
            for (int i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(i, 1, 1, 1);
            }
            break;

        case ColorValues.Saturation:
            for (int i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, (float)i / size, v, 1);
            }
            break;

        case ColorValues.Value:
            for (int i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, s, (float)i / size, 1);
            }
            break;

        default:
            throw new System.NotImplementedException("");
        }
        texture.SetPixels32(colors);
        texture.Apply();

        if (image.texture != null)
        {
            DestroyImmediate(image.texture);
        }
        image.texture = texture;

        switch (direction)
        {
        case Slider.Direction.BottomToTop:
        case Slider.Direction.TopToBottom:
            image.uvRect = new Rect(0, 0, 2, 1);
            break;

        case Slider.Direction.LeftToRight:
        case Slider.Direction.RightToLeft:
            image.uvRect = new Rect(0, 0, 1, 2);
            break;

        default:
            break;
        }
    }
    public Color GetColor(float posX, float posY)
    {
        var color = HSVUtil.ConvertHsvToRgb(pointerPos * -360 + 360, posX, posY);

        return(color);
    }
 protected virtual void HSVChanged(float h, float s, float v)
 {
     createPresetImage.color = HSVUtil.ConvertHsvToRgb(h * 360, s, v, 1);
     //Debug.Log("hsv util color: " + createPresetImage.color);
 }
Example #12
0
    void SendChangedEvent()
    {
        Color c = HSVUtil.ConvertHsvToRgb(_hue * 360f, 1, 1, 1);

        onColorChanged.Invoke(c);
    }
    private void RegenerateTexture()
    {
        Color32 baseColor = picker != null ? picker.CurrentColor : Color.black;
        var     h         = picker != null ? picker.H : 0;
        var     s         = picker != null ? picker.S : 0;
        var     v         = picker != null ? picker.V : 0;
        var     vertical  = direction == Slider.Direction.BottomToTop || direction == Slider.Direction.TopToBottom;
        var     inverted  = direction == Slider.Direction.TopToBottom || direction == Slider.Direction.RightToLeft;
        int     size;

        switch (type)
        {
        case ColorValues.R:
        case ColorValues.G:
        case ColorValues.B:
        case ColorValues.A:
            size = 255;
            break;

        case ColorValues.Hue:
            size = 360;
            break;

        case ColorValues.Saturation:
        case ColorValues.Value:
            size = 100;
            break;

        default:
            throw new NotImplementedException("");
        }
        var texture = vertical
            ? new Texture2D(1, size)
            : new Texture2D(size, 1);

        texture.hideFlags = HideFlags.DontSave;
        var colors = new Color32[size];

        switch (type)
        {
        case ColorValues.R:
            for (byte i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = new Color32(i, baseColor.g, baseColor.b, 255);
            }
            break;

        case ColorValues.G:
            for (byte i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, i, baseColor.b, 255);
            }
            break;

        case ColorValues.B:
            for (byte i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, baseColor.g, i, 255);
            }
            break;

        case ColorValues.A:
            for (byte i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = new Color32(i, i, i, 255);
            }
            break;

        case ColorValues.Hue:
            for (var i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(i, 1, 1, 1);
            }
            break;

        case ColorValues.Saturation:
            for (var i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, (float)i / size, v, 1);
            }
            break;

        case ColorValues.Value:
            for (var i = 0; i < size; i++)
            {
                colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, s, (float)i / size, 1);
            }
            break;

        default:
            throw new NotImplementedException("");
        }
        texture.SetPixels32(colors);
        texture.Apply();
        if (image.texture != null)
        {
            DestroyImmediate(image.texture);
        }
        image.texture = texture;
        // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
        switch (direction)
        {
        case Slider.Direction.BottomToTop:
        case Slider.Direction.TopToBottom:
            image.uvRect = new Rect(0, 0, 2, 1);
            break;

        case Slider.Direction.LeftToRight:
        case Slider.Direction.RightToLeft:
            image.uvRect = new Rect(0, 0, 1, 2);
            break;
        }
    }