コード例 #1
0
ファイル: Color.cs プロジェクト: LexouDuck/Emblem-Magic
        /// <summary>
        /// Returns the index of the color nearest to the one given (possibly -1)
        /// </summary>
        public static int GetNearest(Palette palette, Color color)
        {
            byte R = color.GetValueR();
            byte G = color.GetValueG();
            byte B = color.GetValueB();
            int  r;
            int  g;
            int  b;
            int  sum;
            int  min    = 65536;
            int  result = -1;

            for (int i = 0; i < palette.Count; i++)
            {
                r   = Math.Abs(R - palette[i].GetValueR());
                g   = Math.Abs(G - palette[i].GetValueG());
                b   = Math.Abs(B - palette[i].GetValueB());
                sum = r + g + b;
                if (sum < min)
                {
                    min    = sum;
                    result = i;
                }
            }
            return(result);
        }
コード例 #2
0
ファイル: Color.cs プロジェクト: LexouDuck/Emblem-Magic
        /// <summary>
        /// Returns a blend of this Color and the one given
        /// </summary>
        public Color Blend(Color color)
        {
            byte  r1 = GetValueR(); byte r2 = color.GetValueR();
            byte  g1 = GetValueG(); byte g2 = color.GetValueG();
            byte  b1 = GetValueB(); byte b2 = color.GetValueB();
            Color result = new Color();

            result.Value |= (UInt16)((r1 + r2) / 2);
            result.Value |= (UInt16)(((g1 + g2) / 2) << 5);
            result.Value |= (UInt16)(((b1 + b2) / 2) << 10);
            return(result);
        }
コード例 #3
0
        public void Core_LoadValues()
        {
            AlphaCheckBox.CheckedChanged -= AlphaCheckBox_CheckedChanged;
            NumBox_16bit.ValueChanged    -= NumBox_16bit_ValueChanged;
            NumBox_32bit.ValueChanged    -= NumBox_32bit_ValueChanged;
            NumBox_R.ValueChanged        -= NumBox_R_ValueChanged;
            NumBox_G.ValueChanged        -= NumBox_G_ValueChanged;
            NumBox_B.ValueChanged        -= NumBox_B_ValueChanged;
            TrackBar_R.Scroll            -= TrackBar_R_Scroll;
            TrackBar_G.Scroll            -= TrackBar_G_Scroll;
            TrackBar_B.Scroll            -= TrackBar_B_Scroll;

            if (Current == null || CurrentIndex >= Current.Count)
            {
                AlphaCheckBox.Checked = false;
                NumBox_16bit.Value    = 0;
                NumBox_32bit.Value    = 0;
                TrackBar_R.Value      = 0;
                TrackBar_G.Value      = 0;
                TrackBar_B.Value      = 0;
                NumBox_R.Value        = 0;
                NumBox_G.Value        = 0;
                NumBox_B.Value        = 0;
            }
            else
            {
                GBA.Color color = Current[CurrentIndex];

                AlphaCheckBox.Checked = color.GetAlpha();
                NumBox_16bit.Value    = color.To16bit();
                NumBox_32bit.Value    = color.To32bit();
                TrackBar_R.Value      = color.GetValueR();
                TrackBar_G.Value      = color.GetValueG();
                TrackBar_B.Value      = color.GetValueB();
                NumBox_R.Value        = TrackBar_R.Value;
                NumBox_G.Value        = TrackBar_G.Value;
                NumBox_B.Value        = TrackBar_B.Value;
            }

            AlphaCheckBox.CheckedChanged += AlphaCheckBox_CheckedChanged;
            NumBox_16bit.ValueChanged    += NumBox_16bit_ValueChanged;
            NumBox_32bit.ValueChanged    += NumBox_32bit_ValueChanged;
            NumBox_R.ValueChanged        += NumBox_R_ValueChanged;
            NumBox_G.ValueChanged        += NumBox_G_ValueChanged;
            NumBox_B.ValueChanged        += NumBox_B_ValueChanged;
            TrackBar_R.Scroll            += TrackBar_R_Scroll;
            TrackBar_G.Scroll            += TrackBar_G_Scroll;
            TrackBar_B.Scroll            += TrackBar_B_Scroll;
        }