Beispiel #1
0
        public void SetPixel(int x, int y, ref IntColor colour)
        {
            int index = x + (y * Width);
            int col   = colour.ToArgb();

            Bits[index] = col;
        }
Beispiel #2
0
        public IntColor GetPixel(int x, int y)
        {
            int      index  = x + (y * Width);
            int      col    = Bits[index];
            IntColor result = IntColor.FromArgb(col);

            return(result);
        }
Beispiel #3
0
 public void CopyFromBitmap(Bitmap src)
 {
     for (int y = 0; y < Height; ++y)
     {
         for (int x = 0; x < Width; ++x)
         {
             Color    c  = src.GetPixel(x, y);
             IntColor ic = IntColor.FromArgb(c.A, c.R, c.G, c.B);
             SetPixel(x, y, ref ic);
         }
     }
 }
Beispiel #4
0
        public IntColor ToIntColor(int withAlpha = 255)
        {
            int r;
            int g;
            int b;

            if (S <= float.Epsilon)
            {
                r = g = b = (int)Math.Round(L * 255f);
            }
            else
            {
                float t1, t2;
                float th = H / 6.0f;

                if (L < 0.5f)
                {
                    t2 = L * (1f + S);
                }
                else
                {
                    t2 = (L + S) - (L * S);
                }

                t1 = 2f * L - t2;

                float tr, tg, tb;
                tr = th + (1f / 3f);
                tg = th;
                tb = th - (1f / 3f);

                tr = ColorCalc(tr, t1, t2);
                tg = ColorCalc(tg, t1, t2);
                tb = ColorCalc(tb, t1, t2);

                r = (int)Math.Round(tr * 255f);
                g = (int)Math.Round(tg * 255f);
                b = (int)Math.Round(tb * 255f);
            }

            return(IntColor.FromArgb(withAlpha, r, g, b));
        }
Beispiel #5
0
        public static HslColor FromIntColor(ref IntColor c)
        {
            float r = c.r;
            float g = c.g;
            float b = c.b;

            float min   = Math.Min(Math.Min(r, g), b);
            float max   = Math.Max(Math.Max(r, g), b);
            float delta = max - min;

            float h = 0;
            float s = 0;
            float l = (max + min) * 0.5f;

            if (delta > float.Epsilon)
            {
                if (l < 0.5f)
                {
                    s = (delta / (max + min));
                }
                else
                {
                    s = (delta / (2.0f - max - min));
                }

                if (r == max)
                {
                    h = (g - b) / delta;
                }
                else if (g == max)
                {
                    h = 2f + (b - r) / delta;
                }
                else if (b == max)
                {
                    h = 4f + (r - g) / delta;
                }
            }

            return(new HslColor(h, s, l));
        }