public ctrlVerticalColorSlider()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            //	Initialize Colors
            _hsb   = new AdobeColors.HSB();
            _hsb.H = 1.0;
            _hsb.S = 1.0;
            _hsb.B = 1.0;
            _rgb   = AdobeColors.HSB_to_RGB(_hsb);
            _baseColorComponent = ColorComponent.Hue;
        }
Exemple #2
0
        private void m_ctrl_ThinBox_SelectionChanged(object sender, System.EventArgs e)
        {
            _hsl  = m_ctrl_ThinBox.HSB;
            _rgb  = AdobeColors.HSB_to_RGB(_hsl);
            _cmyk = AdobeColors.RGB_to_CMYK(_rgb);

            UpdateTextBoxes();

            m_ctrl_BigBox.HSB = _hsl;

            m_lbl_Primary_Color.BackColor = _rgb;
            m_lbl_Primary_Color.Update();
        }
Exemple #3
0
        public ColorPicker(Color starting_color)
        {
            InitializeComponent();

            _rgb  = starting_color;
            _hsl  = AdobeColors.RGB_to_HSB(_rgb);
            _cmyk = AdobeColors.RGB_to_CMYK(_rgb);

            UpdateTextBoxes();

            m_ctrl_BigBox.HSB  = _hsl;
            m_ctrl_ThinBox.HSB = _hsl;

            m_lbl_Primary_Color.BackColor = starting_color;
        }
Exemple #4
0
        private void ResetHSLRGB()
        {
            int red,
                green,
                blue;

            switch (_baseColorComponent)
            {
            case ColorComponent.Hue:
                _hsb.S = _markerX / 255.0;
                _hsb.B = 1.0 - _markerY / 255.0;
                _rgb   = AdobeColors.HSB_to_RGB(_hsb);
                break;

            case ColorComponent.Saturation:
                _hsb.H = _markerX / 255.0;
                _hsb.B = 1.0 - _markerY / 255.0;
                _rgb   = AdobeColors.HSB_to_RGB(_hsb);
                break;

            case ColorComponent.Brightness:
                _hsb.H = _markerX / 255.0;
                _hsb.S = 1.0 - _markerY / 255.0;
                _rgb   = AdobeColors.HSB_to_RGB(_hsb);
                break;

            case ColorComponent.Red:
                blue  = _markerX;
                green = 255 - _markerY;
                _rgb  = Color.FromArgb(_rgb.R, green, blue);
                _hsb  = AdobeColors.RGB_to_HSB(_rgb);
                break;

            case ColorComponent.Green:
                blue = _markerX;
                red  = 255 - _markerY;
                _rgb = Color.FromArgb(red, _rgb.G, blue);
                _hsb = AdobeColors.RGB_to_HSB(_rgb);
                break;

            case ColorComponent.Blue:
                red   = _markerX;
                green = 255 - _markerY;
                _rgb  = Color.FromArgb(red, green, _rgb.B);
                _hsb  = AdobeColors.RGB_to_HSB(_rgb);
                break;
            }
        }
Exemple #5
0
        private AdobeColors.HSB GetColor(int x, int y)
        {
            AdobeColors.HSB _hsb = new AdobeColors.HSB();

            switch (_baseColorComponent)
            {
            case ColorComponent.Hue:
                _hsb.H = _hsb.H;
                _hsb.S = x / 255.0;
                _hsb.B = 1.0 - y / 255.0;
                break;

            case ColorComponent.Saturation:
                _hsb.S = _hsb.S;
                _hsb.H = x / 255.0;
                _hsb.B = 1.0 - (double)y / 255;
                break;

            case ColorComponent.Brightness:
                _hsb.B = _hsb.B;
                _hsb.H = x / 255.0;
                _hsb.S = 1.0 - (double)y / 255;
                break;

            case ColorComponent.Red:
                _hsb = AdobeColors.RGB_to_HSB(Color.FromArgb(_rgb.R, 255 - y, x));
                break;

            case ColorComponent.Green:
                _hsb = AdobeColors.RGB_to_HSB(Color.FromArgb(255 - y, _rgb.G, x));
                break;

            case ColorComponent.Blue:
                _hsb = AdobeColors.RGB_to_HSB(Color.FromArgb(x, 255 - y, _rgb.B));
                break;
            }

            return(_hsb);
        }
Exemple #6
0
        private void m_txt_Hex_Leave(object sender, System.EventArgs e)
        {
            string text = m_txt_Hex.Text.ToUpper();
            bool   has_illegal_chars = false;

            if (text.Length <= 0)
            {
                has_illegal_chars = true;
            }
            foreach (char letter in text)
            {
                if (!char.IsNumber(letter))
                {
                    if (letter >= 'A' && letter <= 'F')
                    {
                        continue;
                    }
                    has_illegal_chars = true;
                    break;
                }
            }

            if (has_illegal_chars)
            {
                MessageBox.Show("Hex must be a hex value between 0x000000 and 0xFFFFFF");
                WriteHexData(_rgb);
                return;
            }

            _rgb  = ParseHexData(text);
            _hsl  = AdobeColors.RGB_to_HSB(_rgb);
            _cmyk = AdobeColors.RGB_to_CMYK(_rgb);

            m_ctrl_BigBox.HSB             = _hsl;
            m_ctrl_ThinBox.HSB            = _hsl;
            m_lbl_Primary_Color.BackColor = _rgb;

            UpdateTextBoxes();
        }
        /// <summary>
        /// Resets the controls color (both HSL and RGB variables) based on the current slider position
        /// </summary>
        private void ResetHSLRGB()
        {
            int height = this.Height - 9;

            switch (_baseColorComponent)
            {
            case ColorComponent.Hue:
                _hsb.H = 1.0 - (double)_markerStartY / height;
                _rgb   = AdobeColors.HSB_to_RGB(_hsb);
                break;

            case ColorComponent.Saturation:
                _hsb.S = 1.0 - (double)_markerStartY / height;
                _rgb   = AdobeColors.HSB_to_RGB(_hsb);
                break;

            case ColorComponent.Brightness:
                _hsb.B = 1.0 - (double)_markerStartY / height;
                _rgb   = AdobeColors.HSB_to_RGB(_hsb);
                break;

            case ColorComponent.Red:
                _rgb = Color.FromArgb(255 - (int)Math.Round(255 * (double)_markerStartY / height), _rgb.G, _rgb.B);
                _hsb = AdobeColors.RGB_to_HSB(_rgb);
                break;

            case ColorComponent.Green:
                _rgb = Color.FromArgb(_rgb.R, 255 - (int)Math.Round(255 * (double)_markerStartY / height), _rgb.B);
                _hsb = AdobeColors.RGB_to_HSB(_rgb);
                break;

            case ColorComponent.Blue:
                _rgb = Color.FromArgb(_rgb.R, _rgb.G, 255 - (int)Math.Round(255 * (double)_markerStartY / height));
                _hsb = AdobeColors.RGB_to_HSB(_rgb);
                break;
            }
        }
Exemple #8
0
        private Bitmap GetColorPlaneBitmap(Rectangle rect, ColorComponent comp)
        {
            Bitmap     map     = new Bitmap(rect.Width, rect.Height, PixelFormat.Format24bppRgb);
            BitmapData mapData = map.LockBits(
                new Rectangle(0, 0, map.Width, map.Height),
                ImageLockMode.WriteOnly,
                PixelFormat.Format24bppRgb);

            unsafe
            {
                byte *pt0 = (byte *)mapData.Scan0;

                Parallel.For(rect.Top, rect.Bottom, y =>
                {
                    int bitmapY = y - rect.Top;

                    for (int x = rect.Left; x < rect.Right; x++)
                    {
                        int bitmapX = x - rect.Left;

                        Color color;
                        switch (comp)
                        {
                        case ColorComponent.Hue:
                            color = AdobeColors.HSB_to_RGB(new AdobeColors.HSB(
                                                               _hsb.H,
                                                               x / 255.0,
                                                               1 - y / 255.0));
                            break;

                        case ColorComponent.Saturation:
                            color = AdobeColors.HSB_to_RGB(new AdobeColors.HSB(
                                                               x / 255.0,
                                                               _hsb.S,
                                                               1 - y / 255.0));
                            break;

                        case ColorComponent.Brightness:
                            color = AdobeColors.HSB_to_RGB(new AdobeColors.HSB(
                                                               x / 255.0,
                                                               1 - y / 255.0,
                                                               _hsb.B));
                            break;

                        case ColorComponent.Red:
                            color = Color.FromArgb(
                                _rgb.R,
                                x,
                                255 - y);
                            break;

                        case ColorComponent.Green:
                            color = Color.FromArgb(
                                x,
                                _rgb.G,
                                255 - y);
                            break;

                        case ColorComponent.Blue:
                            color = Color.FromArgb(
                                x,
                                255 - y,
                                _rgb.B);
                            break;

                        default:
                            throw new ArgumentException();
                        }

                        if (_webSafeColorsOnly)
                        {
                            color = AdobeColors.GetNearestWebSafeColor(color);
                        }

                        byte *pt = pt0 + mapData.Stride * bitmapY + 3 * bitmapX;
                        pt[2]    = color.R;
                        pt[1]    = color.G;
                        pt[0]    = color.B;
                    }
                });
            }

            map.UnlockBits(mapData);
            return(map);
        }
        private Bitmap GetColorStripBitmap(Rectangle rect, ColorComponent comp)
        {
            Bitmap     map     = new Bitmap(rect.Width, rect.Height, PixelFormat.Format24bppRgb);
            BitmapData mapData = map.LockBits(
                new Rectangle(0, 0, map.Width, map.Height),
                ImageLockMode.WriteOnly,
                PixelFormat.Format24bppRgb);

            int height = this.Height - 8;

            unsafe
            {
                byte *pt0 = (byte *)mapData.Scan0;

                Parallel.For(rect.Top, rect.Bottom, y =>
                {
                    int bitmapY = y - rect.Top;

                    Color color;
                    switch (comp)
                    {
                    case ColorComponent.Hue:
                        color = AdobeColors.HSB_to_RGB(new AdobeColors.HSB(
                                                           1.0 - (double)y / height,
                                                           1,
                                                           1));
                        break;

                    case ColorComponent.Saturation:
                        color = AdobeColors.HSB_to_RGB(new AdobeColors.HSB(
                                                           _hsb.H,
                                                           1.0 - (double)y / height,
                                                           _hsb.B));
                        break;

                    case ColorComponent.Brightness:
                        color = AdobeColors.HSB_to_RGB(new AdobeColors.HSB(
                                                           _hsb.H,
                                                           _hsb.S,
                                                           1.0 - (double)y / height));
                        break;

                    case ColorComponent.Red:
                        int red = 255 - (int)Math.Round(255 * (double)y / height);
                        color   = Color.FromArgb(
                            red,
                            _rgb.G,
                            _rgb.B);
                        break;

                    case ColorComponent.Green:
                        int green = 255 - (int)Math.Round(255 * (double)y / height);
                        color     = Color.FromArgb(
                            _rgb.R,
                            green,
                            _rgb.B);
                        break;

                    case ColorComponent.Blue:
                        int blue = 255 - (int)Math.Round(255 * (double)y / height);
                        color    = Color.FromArgb(
                            _rgb.R,
                            _rgb.G,
                            blue);
                        break;

                    default:
                        throw new ArgumentException();
                    }

                    if (_webSafeColorsOnly)
                    {
                        color = AdobeColors.GetNearestWebSafeColor(color);
                    }

                    for (int x = rect.Left; x < rect.Right; x++)
                    {
                        int bitmapX = x - rect.Left;

                        byte *pt = pt0 + mapData.Stride * bitmapY + 3 * bitmapX;
                        pt[2]    = color.R;
                        pt[1]    = color.G;
                        pt[0]    = color.B;
                    }
                });
            }

            map.UnlockBits(mapData);
            return(map);
        }