Exemplo n.º 1
0
        /// <summary>
        /// Converts CMYK to RGB
        /// </summary>
        /// <param name="_cmyk">A color to convert</param>
        /// <returns>A Color object</returns>
        public static Color CMYK_to_RGB(CMYK _cmyk)
        {
            int red, green, blue;

            red =	Round(255 - (255 * _cmyk.C));
            green =	Round(255 - (255 * _cmyk.M));
            blue =	Round(255 - (255 * _cmyk.Y));

            return Color.FromArgb(red, green, blue);
        }
Exemplo n.º 2
0
        public static CMYK ConvertRGBToCMYK(Color color)
        {
            CMYK cmyk = new CMYK();

            cmyk.K = new double[] { 1 - color.R / 255d, 1 - color.G / 255d, 1 - color.B / 255d }.Min();
            cmyk.C = (1 - color.R / 255d - cmyk.K) / (1 - cmyk.K);
            cmyk.M = (1 - color.G / 255d - cmyk.K) / (1 - cmyk.K);
            cmyk.Y = (1 - color.B / 255d - cmyk.K) / (1 - cmyk.K);

            return(cmyk);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts CMYK to RGB</summary>
        /// <param name="_cmyk">Color to convert</param>
        /// <returns>Color object</returns>
        public static Color CMYK_to_RGB(CMYK _cmyk)
        {
            int alpha, red, green, blue;

            alpha = Round(255 * _cmyk.A);
            red   = Round(255 - (255 * _cmyk.C));
            green = Round(255 - (255 * _cmyk.M));
            blue  = Round(255 - (255 * _cmyk.Y));

            return(Color.FromArgb(alpha, red, green, blue));
        }
Exemplo n.º 4
0
        public void RgbToCmykShouldConvert()
        {
            CMYK expected = new CMYK(0, 0, 0, 0);

            CMYK actual = new RGB(255, 255, 255).ToCMYK();

            Assert.Equal(expected.C, actual.C);
            Assert.Equal(expected.M, actual.M);
            Assert.Equal(expected.Y, actual.Y);
            Assert.Equal(expected.K, actual.K);
        }
 public ColorTestCase(
     byte red, byte green, byte blue,
     double cyanPercent, double magentaPercent, double yellowPercent, double blackPercent,
     double hue, double lightnessPercent, double saturationPercent,
     double brightnessPercent, byte alpha = 255)
 {
     Color = new CommonColor(red, green, blue, alpha);
     CMYK  = new CMYK(cyanPercent / 100, magentaPercent / 100, yellowPercent / 100, blackPercent / 100);
     HLS   = new HLS(hue, lightnessPercent / 100, saturationPercent / 100);
     HSB   = new HSB(hue, saturationPercent / 100, brightnessPercent / 100);
 }
Exemplo n.º 6
0
 public static BGRA ToBgra(this CMYK cmyk)
 {
     return(CmykToX(cmyk, (R, G, B) =>
                    new BGRA()
     {
         R = (byte)R,
         G = (byte)G,
         B = (byte)B,
         A = byte.MaxValue
     }));
 }
    public Color CMYKtoRGB(CMYK cmyk)
    {
        Color rgb = Color.white;

        rgb.r = (1 - cmyk.c) * (1 - cmyk.k);
        rgb.g = (1 - cmyk.m) * (1 - cmyk.k);
        rgb.b = (1 - cmyk.y) * (1 - cmyk.k);
        rgb.a = 1.0f;

        return(rgb);
    }
Exemplo n.º 8
0
    public static Color CMYK_TO_RGB(CMYK color)
    {
        Color c = Color.white;;

        c.r = (1 - color.C) * (1 - color.K);
        c.g = (1 - color.M) * (1 - color.K);
        c.b = (1 - color.Y) * (1 - color.K);



        return(c);
    }
Exemplo n.º 9
0
 public override void UpdateColorPickerValues()
 {
     if (_updating == false && ColorPicker != null)
     {
         _updating = true;
         CMYK cmyk = new CMYK(Cyan, Magenta, Yellow, BlackKey);
         HSV  hsv  = cmyk.ToHSV();
         ColorPicker.Value1 = hsv.H;
         ColorPicker.Value2 = hsv.S;
         ColorPicker.Value3 = hsv.V;
         _updating          = false;
     }
 }
Exemplo n.º 10
0
 public override void UpdatePropertyValues()
 {
     if (_updating == false && ColorPicker != null)
     {
         _updating = true;
         HSV  hsv  = new HSV(ColorPicker.Value1, ColorPicker.Value2, ColorPicker.Value3);
         CMYK cmyk = hsv.ToCMYK();
         Cyan      = cmyk.C;
         Magenta   = cmyk.M;
         Yellow    = cmyk.Y;
         BlackKey  = cmyk.K;
         _updating = false;
     }
 }
Exemplo n.º 11
0
        public static Color CMYK2RGB(CMYK cmyk)
        {
            // 从CMYK转换到CMY
            double k = cmyk.K;
            double c = cmyk.C * (1 - k) + k;
            double m = cmyk.M * (1 - k) + k;
            double y = cmyk.Y * (1 - k) + k;

            // CMY转换到RGB
            int red   = Round((1 - c) * 255);
            int green = Round((1 - m) * 255);
            int blue  = Round((1 - y) * 255);

            return Color.FromArgb(red, green, blue);
        }
Exemplo n.º 12
0
        private COLOR GetColor()
        {
            COLOR mycolor = Color.White;

            switch (this.colorFormat)
            {
            case ColorFormat.RGB:
                mycolor = new COLOR((short)values[0], (short)values[1], (short)values[2]);
                break;

            case ColorFormat.ARGB:
                mycolor = new COLOR((short)values[0], (short)values[1], (short)values[2], (short)values[3]);
                break;

            case ColorFormat.CMYK:
                CMYK c = new CMYK(0, 0, 0, 0);
                c.C100 = (float)values[0];
                c.M100 = (float)values[1];
                c.Y100 = (float)values[2];
                c.K100 = (float)values[3];

                mycolor = c.ToColor();
                break;

            case ColorFormat.HSB:
            case ColorFormat.HSV:
                HSB hsb = new HSB(0, 0, 0);

                hsb.Hue360        = (float)values[0];
                hsb.Saturation100 = (float)values[1];
                hsb.Brightness100 = (float)values[2];

                mycolor = hsb.ToColor();
                break;

            case ColorFormat.HSL:
                HSL hsl = new HSL(0, 0, 0);

                hsl.Hue360        = (float)values[0];
                hsl.Saturation100 = (float)values[1];
                hsl.Lightness100  = (float)values[2];

                mycolor = hsl.ToColor();
                break;
            }

            return(mycolor);
        }
Exemplo n.º 13
0
        public Form()
        {
            InitializeComponent();

            colorDialog.FullOpen = true;

            _rgb  = new RGB();
            _cmyk = new CMYK();
            _hsv  = new HSV();

            _manager = new ColorsManager(
                _rgb,
                _cmyk,
                _hsv,
                resultColorBox);
        }
Exemplo n.º 14
0
        public void CMYK_get_converted_to_RGB()
        {
            CMYK cmyk = new CMYK()
            {
                Cyan    = 0,
                Black   = 0,
                Magenta = 0.741,
                Yellow  = 0.608
            };

            var result = cmyk.ConvertToRgb();

            Assert.AreEqual(255, result.Red);
            Assert.AreEqual(66, result.Green);
            Assert.AreEqual(100, result.Blue);
        }
Exemplo n.º 15
0
    CMYK RGBtoCMYK(UnityEngine.Color c)
    {
        CMYK res = new CMYK(0, 0, 0, 0);

        UnityEngine.Color cp = c / 255;

        float max = (cp.r < cp.g) ? cp.r : cp.g;

        max = (max < cp.b) ? max : cp.b;

        res.k = 1 - max;
        res.c = (1 - cp.r - res.k) / (1 - res.k);
        res.m = (1 - cp.g - res.k) / (1 - res.k);
        res.y = (1 - cp.b - res.k) / (1 - res.k);

        return(res);
    }
Exemplo n.º 16
0
        public static Color CMYKToColor(CMYK cmyk)
        {
            if (cmyk.Cyan == 0 && cmyk.Magenta == 0 && cmyk.Yellow == 0 && cmyk.Key == 1)
            {
                return Color.FromArgb(cmyk.Alpha, 0, 0, 0);
            }

            double c = cmyk.Cyan * (1 - cmyk.Key) + cmyk.Key;
            double m = cmyk.Magenta * (1 - cmyk.Key) + cmyk.Key;
            double y = cmyk.Yellow * (1 - cmyk.Key) + cmyk.Key;

            int r = (int)Math.Round((1 - c) * 255);
            int g = (int)Math.Round((1 - m) * 255);
            int b = (int)Math.Round((1 - y) * 255);

            return Color.FromArgb(cmyk.Alpha, r, g, b);
        }
Exemplo n.º 17
0
        private static ColorResult ConvertLAB(ColorSpace resultSpace, ColorSource source)
        {
            ColorResult color;

            double l = source.component0;
            double a = source.component1;
            double b = source.component2;

            switch (resultSpace)
            {
            case ColorSpace.RGBSpace:
                RGB rgb = ColorConverter.LabtoRGB(l, a, b);
                color = new ColorResult(rgb.Red, rgb.Green, rgb.Blue);
                break;

            case ColorSpace.CMYKSpace:
                CMYK cmyk = ColorConverter.LabtoCMYK(l, a, b);
                color = new ColorResult(cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black);
                break;

            case ColorSpace.HSBSpace:
                HSB hsb = ColorConverter.LabtoHSB(l, a, b);
                color = new ColorResult(hsb.Hue, hsb.Saturation, hsb.Brightness);
                break;

            case ColorSpace.HSLSpace:
                HSL hsl = ColorConverter.LabtoHSL(l, a, b);
                color = new ColorResult(hsl.Hue, hsl.Saturation, hsl.Luminance);
                break;

            case ColorSpace.XYZSpace:
                XYZ xyz = ColorConverter.LabtoXYZ(l, a, b);
                color = new ColorResult(xyz.X, xyz.Y, xyz.Z);
                break;

            case ColorSpace.GraySpace:
                color = new ColorResult(ColorConverter.LabtoRGB(l, a, b).GetIntensity(source.maxChannelValue));
                break;

            default:
                throw new InvalidEnumArgumentException("Unsupported color space conversion", (int)resultSpace, typeof(ColorSpace));
            }

            return(color);
        }
Exemplo n.º 18
0
        private static ColorResult ConvertXYZ(ColorSpace resultSpace, ColorSource source)
        {
            ColorResult color;

            double x = source.component0;
            double y = source.component1;
            double z = source.component2;

            switch (resultSpace)
            {
            case ColorSpace.RGBSpace:
                RGB rgb = ColorConverter.XYZtoRGB(x, y, z);
                color = new ColorResult(rgb.Red, rgb.Green, rgb.Blue);
                break;

            case ColorSpace.CMYKSpace:
                CMYK cmyk = ColorConverter.XYZtoCMYK(x, y, z);
                color = new ColorResult(cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black);
                break;

            case ColorSpace.HSBSpace:
                HSB hsb = ColorConverter.XYZtoHSB(x, y, z);
                color = new ColorResult(hsb.Hue, hsb.Saturation, hsb.Brightness);
                break;

            case ColorSpace.HSLSpace:
                HSL hsl = ColorConverter.XYZtoHSL(x, y, z);
                color = new ColorResult(hsl.Hue, hsl.Saturation, hsl.Luminance);
                break;

            case ColorSpace.LabSpace:
                Lab lab = ColorConverter.XYZtoLab(x, y, z);
                color = ScaleCIELabOutputRange(lab);
                break;

            case ColorSpace.GraySpace:
                color = new ColorResult(ColorConverter.XYZtoRGB(x, y, z).GetIntensity(source.maxChannelValue));
                break;

            default:
                throw new InvalidEnumArgumentException("Unsupported color space conversion", (int)resultSpace, typeof(ColorSpace));
            }

            return(color);
        }
Exemplo n.º 19
0
        private static ColorResult ConvertHSL(ColorSpace resultSpace, ColorSource source)
        {
            ColorResult color;

            double h = source.component0;
            double s = source.component1;
            double l = source.component2;

            switch (resultSpace)
            {
            case ColorSpace.RGBSpace:
                RGB rgb = ColorConverter.HSLtoRGB(h, s, l);
                color = new ColorResult(rgb.Red, rgb.Green, rgb.Blue);
                break;

            case ColorSpace.CMYKSpace:
                CMYK cmyk = ColorConverter.HSLtoCMYK(h, s, l);
                color = new ColorResult(cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black);
                break;

            case ColorSpace.HSBSpace:
                HSB hsb = ColorConverter.HSLtoHSB(h, s, l);
                color = new ColorResult(hsb.Hue, hsb.Saturation, hsb.Brightness);
                break;

            case ColorSpace.LabSpace:
                Lab lab = ColorConverter.HSLToLab(h, s, l);
                color = ScaleCIELabOutputRange(lab);
                break;

            case ColorSpace.XYZSpace:
                XYZ xyz = ColorConverter.HSLtoXYZ(h, s, l);
                color = new ColorResult(xyz.X, xyz.Y, xyz.Z);
                break;

            case ColorSpace.GraySpace:
                color = new ColorResult(ColorConverter.HSLtoRGB(h, s, l).GetIntensity(source.maxChannelValue));
                break;

            default:
                throw new InvalidEnumArgumentException(nameof(resultSpace), (int)resultSpace, typeof(ColorSpace));
            }

            return(color);
        }
Exemplo n.º 20
0
        private static ColorResult ConvertRGB(ColorSpace resultSpace, ColorSource source)
        {
            ColorResult color;

            double red   = source.component0;
            double green = source.component1;
            double blue  = source.component2;

            switch (resultSpace)
            {
            case ColorSpace.CMYKSpace:
                CMYK cmyk = ColorConverter.RGBtoCMYK(red, green, blue);
                color = new ColorResult(cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black);
                break;

            case ColorSpace.GraySpace:
                color = new ColorResult(ColorConverter.GetRGBIntensity(red, green, blue, source.maxChannelValue));
                break;

            case ColorSpace.HSBSpace:
                HSB hsb = ColorConverter.RGBtoHSB(red, green, blue);
                color = new ColorResult(hsb.Hue, hsb.Saturation, hsb.Brightness);
                break;

            case ColorSpace.HSLSpace:
                HSL hsl = ColorConverter.RGBtoHSL(red, green, blue);
                color = new ColorResult(hsl.Hue, hsl.Saturation, hsl.Luminance);
                break;

            case ColorSpace.LabSpace:
                Lab lab = ColorConverter.RGBtoLab(red, green, blue);
                color = ScaleCIELabOutputRange(lab);
                break;

            case ColorSpace.XYZSpace:
                XYZ xyz = ColorConverter.RGBtoXYZ(red, green, blue);
                color = new ColorResult(xyz.X, xyz.Y, xyz.Z);
                break;

            default:
                throw new InvalidEnumArgumentException("Unsupported color space conversion", (int)resultSpace, typeof(ColorSpace));
            }

            return(color);
        }
Exemplo n.º 21
0
    // Use this for initialization
    void Start()
    {
        GameObject.Find("Main Camera").SetActive(false);
        gameManager           = GameObject.Find("GameManager").GetComponent <GameManager>();
        cmyk                  = new CMYK(Color.white);
        rigidbody             = GetComponent <Rigidbody>();
        speed                 = 0.15f;
        angle                 = 2.0f;
        isFalling             = true;
        canMove               = true;
        rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
        isStarted             = false;

        RaycastHit hit;

        Physics.Raycast(transform.position, transform.up * (-1), out hit);
        DrawingScope(hit.point + new Vector3(0, 0.001f, 0));
    }
Exemplo n.º 22
0
        private static ColorResult ConvertGray(ColorSpace resultSpace, ColorSource source)
        {
            ColorResult color;

            double gray = source.component0;

            switch (resultSpace)
            {
            case ColorSpace.RGBSpace:
                color = new ColorResult(gray, gray, gray);
                break;

            case ColorSpace.CMYKSpace:
                CMYK cmyk = ColorConverter.RGBtoCMYK(gray, gray, gray);
                color = new ColorResult(cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black);
                break;

            case ColorSpace.HSBSpace:
                HSB hsb = ColorConverter.RGBtoHSB(gray, gray, gray);
                color = new ColorResult(hsb.Hue, hsb.Saturation, hsb.Brightness);
                break;

            case ColorSpace.HSLSpace:
                HSL hsl = ColorConverter.RGBtoHSL(gray, gray, gray);
                color = new ColorResult(hsl.Hue, hsl.Saturation, hsl.Luminance);
                break;

            case ColorSpace.LabSpace:
                Lab lab = ColorConverter.RGBtoLab(gray, gray, gray);
                color = ScaleCIELabOutputRange(lab);
                break;

            case ColorSpace.XYZSpace:
                XYZ xyz = ColorConverter.RGBtoXYZ(gray, gray, gray);
                color = new ColorResult(xyz.X, xyz.Y, xyz.Z);
                break;

            default:
                throw new InvalidEnumArgumentException(nameof(resultSpace), (int)resultSpace, typeof(ColorSpace));
            }

            return(color);
        }
Exemplo n.º 23
0
        private void CreateCMYKLayout()
        {
            Show4Elements();

            CMYK CmykColor = new CMYK(current_color);

            label1.Text = "C";
            label2.Text = "M";
            label3.Text = "Y";
            label4.Text = "K";

            setting_tb_and_nup = true;

            numericUpDown1.Maximum   = 1;
            numericUpDown2.Maximum   = 1;
            numericUpDown3.Maximum   = 1;
            numericUpDown4.Maximum   = 1;
            numericUpDown1.Minimum   = 0;
            numericUpDown2.Minimum   = 0;
            numericUpDown3.Minimum   = 0;
            numericUpDown4.Minimum   = 0;
            numericUpDown1.Increment = new decimal(0.01);
            numericUpDown2.Increment = new decimal(0.01);
            numericUpDown3.Increment = new decimal(0.01);
            numericUpDown4.Increment = new decimal(0.01);

            trackBar1.Value = (int)(CmykColor.C * 255);
            trackBar2.Value = (int)(CmykColor.M * 255);
            trackBar3.Value = (int)(CmykColor.Y * 255);
            trackBar4.Value = (int)(CmykColor.K * 255);

            setting_tb_and_nup = false;

            numericUpDown1.Value = (decimal)CmykColor.C;
            numericUpDown2.Value = (decimal)CmykColor.M;
            numericUpDown3.Value = (decimal)CmykColor.Y;
            numericUpDown4.Value = (decimal)CmykColor.K;

            SetDecimalPlaces(3);

            SetCMYKLabels();
        }
Exemplo n.º 24
0
        public CMYK ToCMYK()
        {
            CMYK cmyk = new CMYK();

            cmyk.C = (255 - color.R) / 255.0;
            cmyk.M = (0xFF - color.G) / 255.0;
            cmyk.Y = (0xFF - color.B) / 255.0;
            cmyk.K = Math.Min(cmyk.C, Math.Min(cmyk.M, cmyk.Y));

            if (cmyk.K == 1.0)
            {
                cmyk.C = cmyk.M = cmyk.Y = 0;
            }
            else
            {
                cmyk.C = (cmyk.C - cmyk.K) / (1 - cmyk.K);
                cmyk.M = (cmyk.M - cmyk.K) / (1 - cmyk.K);
                cmyk.Y = (cmyk.Y - cmyk.K) / (1 - cmyk.K);
            }

            return(cmyk);
        }
Exemplo n.º 25
0
    public CMYK PickSliderColor()
    {
        var value = (int)this.ColorSlider.value;

        CMYK result = null;


        if (value >= 0 && value <= 100)
        {
            result = new CMYK(0, 100 - value, 100, 1);
        }

        if (value > 100 && value <= 200)
        {
            result = new CMYK(value - 100, 0, 100, 1);
        }

        if (value > 200 && value <= 300)
        {
            result = new CMYK(100, 0, 300 - value, 1);
        }

        if (value > 300 && value <= 400)
        {
            result = new CMYK(100, value - 300, 0, 1);
        }

        if (value > 400 && value <= 500)
        {
            result = new CMYK(500 - value, 100, 0, 1);
        }

        if (value > 500 && value <= 600)
        {
            result = new CMYK(0, 100, value - 500, 1);
        }

        return(result);
    }
Exemplo n.º 26
0
    void Eyedropping()
    {
        Ray        ray = new Ray(transform.FindChild("Next").transform.position, Vector3.down);
        RaycastHit hit;
        LayerMask  mask = 9;

        if (Physics.Raycast(ray, out hit, mask))
        {
            try{
                CMYK t = ColorManager.I.RGBtoCMYK(hit.transform.gameObject.GetComponent <Renderer>().material.color);
                UIManager.I.ChangeEyedropperText(t);
            }
            catch (Exception ex) {
                Debug.LogError(ex);
            }

            //UIManager.I.ChangeEyedropperText( t.c, t.m, t.y);
        }         //else {

        //	UIManager.I.ChangeEyedropperText( null );

        //	}
    }
Exemplo n.º 27
0
    public CMYK RGBtoCMYK(Color rgb)
    {
        CMYK cmyk = CMYK.white;

        if (rgb != null)
        {
            cmyk.k = 1 - Mathf.Max(rgb.r, rgb.g, rgb.b);

            if (cmyk.k != 1)
            {
                cmyk.c = (1 - rgb.r - cmyk.k) / (1 - cmyk.k);
                cmyk.m = (1 - rgb.g - cmyk.k) / (1 - cmyk.k);
                cmyk.y = (1 - rgb.b - cmyk.k) / (1 - cmyk.k);
            }
            else
            {
                cmyk.c = cmyk.m = cmyk.y = 1f;
                cmyk.k = 0f;
            }
        }

        return(cmyk);
    }
Exemplo n.º 28
0
    bool CalculateScore(CMYK tile, CMYK player)
    {
        Vector3 v1 = new Vector3(tile.c, tile.m, tile.y);
        Vector3 v2 = new Vector3(player.c, player.m, player.y);

        v2 = v2 / v2.magnitude;
        float score = v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;

        Debug.Log(score);
        gameManager.score = score;
        if (score >= 0.99f)
        {
            Debug.Log("Complete");
            return(true);
        }
        else if (score > 0.7f && score < 0.99f)
        {
            Debug.Log("Clear");
            return(true);
        }

        Debug.Log("Fail");
        return(false);
    }
Exemplo n.º 29
0
 public void CollideWith(CMYK color, PlayerController player)
 {
     player.Paint(delpoyingColor);
     source.Play();
 }
Exemplo n.º 30
0
        public static CMYK RGB2CMYK(Color rgb)
        {
            // 从RGB转到CMY
            double c = 1.0 - rgb.R / 255.0;
            double m = 1.0 - rgb.G / 255.0;
            double y = 1.0 - rgb.B / 255.0;

            // 计算K分量
            double k = 1.0;
            k = c < k ? c : k;
            k = m < k ? m : k;
            k = y < k ? y : k;

            if (k == 1.0)
            {
                return new CMYK(0, 0, 0, 1.0);
            }
            else
            {
                CMYK cmyk = new CMYK();
                cmyk.C = (c - k) / (1 - k);
                cmyk.M = (m - k) / (1 - k);
                cmyk.Y = (y - k) / (1 - k);
                cmyk.K = k;

                return cmyk;
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// Converts RGB to CMYK
        /// </summary>
        /// <param name="c">A color to convert.</param>
        /// <returns>A CMYK object</returns>
        public static CMYK RGB_to_CMYK(Color c)
        {
            CMYK _cmyk = new CMYK();
            double low = 1.0;

            _cmyk.C = (double)(255 - c.R)/255;
            if ( low > _cmyk.C )
                low = _cmyk.C;

            _cmyk.M = (double)(255 - c.G)/255;
            if ( low > _cmyk.M )
                low = _cmyk.M;

            _cmyk.Y = (double)(255 - c.B)/255;
            if ( low > _cmyk.Y )
                low = _cmyk.Y;

            if ( low > 0.0 )
            {
                _cmyk.K = low;
            }

            return _cmyk;
        }
Exemplo n.º 32
0
 public static RGB CMYK2RGB(CMYK cmyk)
 {
     float R = (float)Math.Round(255 * (1 - (cmyk.Cyan / 100)) * (1 - (cmyk.Black / 100)));
     float G = (float)Math.Round(255 * (1 - cmyk.Magenta / 100) * (1 - cmyk.Black / 100));
     float B = (float)Math.Round(255 * (1 - cmyk.Yellow / 100) * (1 - cmyk.Black / 100));
     return new RGB(R, G, B);
 }
Exemplo n.º 33
0
 public void HSBUpdate()
 {
     RGBA = HSB;
     CMYK = HSB;
 }
Exemplo n.º 34
0
 public void RGBAUpdate()
 {
     HSB = RGBA;
     CMYK = RGBA;
 }
Exemplo n.º 35
0
        /// <summary>
        /// Descriptive user interface core for cloning the Content
        /// </summary>
        /// <param name="key">漢字色名</param>
        /// <param name="name">読み</param>
        /// <param name="brush">色SolidColorBrush</param>
        /// <returns></returns>
        protected virtual UIElement plateOf(string key, string name, Brush brush)
        {
            SolidColorBrush B    = brush as SolidColorBrush;
            CMYK            cmyk = new CMYK(B.Color);
            HSL             hsl  = new HSL(B.Color);
            HSV             hsv  = new HSV(B.Color);
            TextBlock       one  = new TextBlock();
            TextBlock       two  = new TextBlock();
            TextBlock       san  = new TextBlock();
            TextBlock       yon  = new TextBlock();
            TextBlock       goh  = new TextBlock();
            TextBlock       txl  = new TextBlock();
            TextBlock       txv  = new TextBlock();

            one.Text = key;
            two.Text = name;
            //san.Text=rgb(B.Color);
            san.Inlines.Add(ofR(B.Color));
            san.Inlines.Add(new Run(","));
            san.Inlines.Add(ofG(B.Color));
            san.Inlines.Add(new Run(","));
            san.Inlines.Add(ofB(B.Color));
            //yon.Text=rgb(B.Color,true);
            yon.Inlines.Add(new Run("#"));
            yon.Inlines.Add(ofR(B.Color, true));
            yon.Inlines.Add(ofG(B.Color, true));
            yon.Inlines.Add(ofB(B.Color, true));
            goh.Text = cmyk.ToString(false);
            txl.Text = hsl.ToString(false);
            txv.Text = hsv.ToString(false);
            switch (NamedSolidColorBrush.howCompare)
            {
            case NamedSolidColorBrush.HowCompare.Kanji:
                one.FontWeight = FontWeights.Bold;
                break;

            case NamedSolidColorBrush.HowCompare.Yomi:
                two.FontWeight = FontWeights.Bold;
                break;

            case NamedSolidColorBrush.HowCompare.R:
                int i = 0;
                foreach (Inline iline in san.Inlines)
                {
                    if (i == 0)
                    {
                        iline.FontWeight = FontWeights.Bold;
                        break;
                    }
                    ++i;
                }
                int yi = 0;
                foreach (Inline iline in yon.Inlines)
                {
                    if (yi == 1)
                    {
                        iline.FontWeight = FontWeights.Bold;
                    }
                    ++yi;
                }
                break;

            case NamedSolidColorBrush.HowCompare.nR:
                int iR = 0;
                foreach (Inline iline in san.Inlines)
                {
                    if (iR == 2 || iR == 4)
                    {
                        iline.FontWeight = FontWeights.Bold;
                    }
                    ++iR;
                }
                int yiR = 0;
                foreach (Inline iline in yon.Inlines)
                {
                    if (yiR == 2 || yiR == 3)
                    {
                        iline.FontWeight = FontWeights.Bold;
                    }
                    ++yiR;
                }
                break;

            case NamedSolidColorBrush.HowCompare.G:
                int ii = 0;
                foreach (Inline iline in san.Inlines)
                {
                    if (ii == 2)
                    {
                        iline.FontWeight = FontWeights.Bold;
                        break;
                    }
                    ++ii;
                }
                int iG = 0;
                foreach (Inline iline in yon.Inlines)
                {
                    if (iG == 2)
                    {
                        iline.FontWeight = FontWeights.Bold;
                        break;
                    }
                    ++iG;
                }
                break;

            case NamedSolidColorBrush.HowCompare.nG:
                int siG = 0;
                foreach (Inline iline in san.Inlines)
                {
                    if (siG == 0 || siG == 4)
                    {
                        iline.FontWeight = FontWeights.Bold;
                    }
                    ++siG;
                }
                int yiG = 0;
                foreach (Inline iline in yon.Inlines)
                {
                    if (yiG == 1 || yiG == 3)
                    {
                        iline.FontWeight = FontWeights.Bold;
                    }
                    ++yiG;
                }
                break;

            case NamedSolidColorBrush.HowCompare.B:
                int iii = 0;
                foreach (Inline iline in san.Inlines)
                {
                    if (iii == 4)
                    {
                        iline.FontWeight = FontWeights.Bold;
                        break;
                    }
                    ++iii;
                }
                int iB = 0;
                foreach (Inline iline in yon.Inlines)
                {
                    if (iB == 3)
                    {
                        iline.FontWeight = FontWeights.Bold;
                        break;
                    }
                    ++iB;
                }
                break;

            case NamedSolidColorBrush.HowCompare.nB:
                int siB = 0;
                foreach (Inline iline in san.Inlines)
                {
                    if (siB == 0 || siB == 2)
                    {
                        iline.FontWeight = FontWeights.Bold;
                    }
                    ++siB;
                }
                int yiB = 0;
                foreach (Inline iline in yon.Inlines)
                {
                    if (yiB == 1 || yiB == 2)
                    {
                        iline.FontWeight = FontWeights.Bold;
                    }
                    ++yiB;
                }
                break;

            case NamedSolidColorBrush.HowCompare.RGB:
                san.FontWeight = yon.FontWeight = FontWeights.Bold;
                break;

            case NamedSolidColorBrush.HowCompare.CMYK:
                goh.FontWeight = FontWeights.Bold;
                break;

            case NamedSolidColorBrush.HowCompare.HSL:
                txl.FontWeight = FontWeights.Bold;
                break;

            case NamedSolidColorBrush.HowCompare.HSV:
                txv.FontWeight = FontWeights.Bold;
                break;
            }
            UniformGrid ug = new UniformGrid {
                Background = brush
            };

            ug.Children.Add(one);
            ug.Children.Add(two);
            ug.Children.Add(san);
            ug.Children.Add(yon);
            ug.Children.Add(goh);
            ug.Children.Add(txl);
            ug.Children.Add(txv);
            one.TextAlignment = TextAlignment.Right;
            two.TextAlignment = TextAlignment.Left;
            //san.FontWeight=FontWeights.Bold;
            ug.Columns = ug.Children.Count;
            //ug.HorizontalAlignment=HorizontalAlignment.Stretch;
            one.Foreground = two.Foreground = san.Foreground = yon.Foreground = goh.Foreground = txl.Foreground = txv.Foreground = invert(brush);
            one.Margin     = two.Margin = san.Margin = yon.Margin = goh.Margin = txl.Margin = txv.Margin = new Thickness(6);
            ug.Tag         = one.Text;
            return(ug);
        }
Exemplo n.º 36
0
        private void tsmiCopyCMYK_Click(object sender, EventArgs e)
        {
            CMYK cmyk = colorPicker.SelectedColor.CMYK;

            ClipboardHelpers.CopyText($"{cmyk.Cyan100:0.0}%, {cmyk.Magenta100:0.0}%, {cmyk.Yellow100:0.0}%, {cmyk.Key100:0.0}%");
        }
Exemplo n.º 37
0
 public MyColor(Color color)
 {
     RGBA = color;
     HSB = color;
     CMYK = color;
 }
 public CommonColor ColorFromCMYKTest(CMYK cmyk) => CommonColor.FromCMYK(cmyk.C, cmyk.M, cmyk.Y, cmyk.K);
        public int CompareTo(NamedSolidColorBrush other)
        {
            if (other == null)
            {
                return(1);
            }
            long lV, rV;

            switch (howCompare)
            {
            case HowCompare.R:
                if (this.R < other.R)
                {
                    return(-1 * reverse);
                }
                else if (this.R > other.R)
                {
                    return(1 * reverse);
                }
                else if (CompareR(other) == 0)
                {
                    goto case HowCompare.G;
                }
                break;

            case HowCompare.G:
                if (this.G < other.G)
                {
                    return(-1 * reverse);
                }
                else if (this.G > other.G)
                {
                    return(1 * reverse);
                }
                else if (CompareG(other) == 0)
                {
                    goto case HowCompare.B;
                }
                break;

            case HowCompare.B:
                if (this.B < other.B)
                {
                    return(-1 * reverse);
                }
                else if (this.B > other.B)
                {
                    return(1 * reverse);
                }
                else
                {
                    return(CompareB(other));
                }

            //break;
            case HowCompare.nR:
                lV = (this.G << 8) | this.B;
                rV = (other.G << 8) | other.B;
                if (lV < rV)
                {
                    return(-1 * reverse);
                }
                if (lV > rV)
                {
                    return(1 * reverse);
                }
                goto case HowCompare.R;

            case HowCompare.nG:
                lV = (this.R << 16) | this.B;
                rV = (other.R << 16) | other.B;
                if (lV < rV)
                {
                    return(-1 * reverse);
                }
                if (lV > rV)
                {
                    return(1 * reverse);
                }
                goto case HowCompare.G;

            case HowCompare.nB:
                lV = (this.R << 16) | (this.G << 8);
                rV = (other.R << 16) | (other.G << 8);
                if (lV < rV)
                {
                    return(-1 * reverse);
                }
                if (lV > rV)
                {
                    return(1 * reverse);
                }
                goto case HowCompare.B;

            case HowCompare.RGB:
                lV = (this.R << 16) | (this.G << 8) | this.B;
                rV = (other.R << 16) | (other.G << 8) | other.B;
                if (lV < rV)
                {
                    return(-1 * reverse);
                }
                if (lV > rV)
                {
                    return(1 * reverse);
                }
                break;

            case HowCompare.CMYK:
                CMYK L = new CMYK(this.Brush.Color);
                CMYK R = new CMYK(other.Brush.Color);
                return(L.CompareTo(R));

            //break;
            case HowCompare.HSL:
                HSL hL = new HSL(this.Brush.Color);
                HSL hR = new HSL(other.Brush.Color);
                return(hL.CompareTo(hR));

            //break;
            case HowCompare.HSV:
                HSV vL = new HSV(this.Brush.Color);
                HSV vR = new HSV(other.Brush.Color);
                return(vL.CompareTo(vR));

            //break;
            case HowCompare.Kanji:
                return(this.Kanji.CompareTo(other.Kanji) * reverse);

            //break;
            case HowCompare.Yomi:
                int ii = this.Name.CompareTo(other.Name) * reverse;
                if (ii == 0)
                {
                    if (!String.IsNullOrEmpty(this.Kanji) && !String.IsNullOrEmpty(other.Kanji))
                    {
                        goto case HowCompare.Kanji;
                    }
                }
                return(ii);
            }
            return(0);
        }