Пример #1
0
        public MCColor[] ExportPalette()
        {
            MCColor[] exportPalette = new MCColor[256];

            for (int i = 0; i < 256; i++)
            {
                exportPalette[i] = Get(i);
            }

            return(exportPalette);
        }
Пример #2
0
        /// <summary>
        /// Gets pixel DFColor from DFBitmap.
        /// </summary>
        /// <param name="bitmap">DFBitmap.</param>
        /// <param name="x">X position.</param>
        /// <param name="y">Y position.</param>
        /// <returns>DFColor.</returns>
        static public MCColor GetPixel(MCBitmap bitmap, int x, int y)
        {
            MCColor color  = new MCColor();
            int     srcPos = y * bitmap.Stride + x * bitmap.FormatWidth;

            color.R = bitmap.Data[srcPos++];
            color.G = bitmap.Data[srcPos++];
            color.B = bitmap.Data[srcPos++];
            color.A = bitmap.Data[srcPos++];

            return(color);
        }
Пример #3
0
        public static MCColor FromRGBA(byte r, byte g, byte b, byte a = 255)
        {
            MCColor color = new MCColor()
            {
                R = r,
                G = g,
                B = b,
                A = a,
            };

            return(color);
        }
Пример #4
0
        /// <summary>
        /// Gets colour at specified index.
        /// </summary>
        /// <param name="Index">Index into colour array.</param>
        /// <returns>DFColor object.</returns>
        public MCColor Get(int Index, bool SpecialColor = false)
        {
            if (SpecialColor && SpecialColors.ContainsKey(Index))
            {
                return(SpecialColors[Index]);
            }
            else
            {
                int     offset = HeaderLength + Index * 3;
                MCColor col    = new MCColor((byte)(PaletteBuffer[offset] * 4), (byte)(PaletteBuffer[offset + 1] * 4), (byte)(PaletteBuffer[offset + 2] * 4));

                return(col);
            }
        }
Пример #5
0
        /// <summary>
        /// Sets pixel in DFBitmap. Colour formats only.
        /// </summary>
        /// <param name="bitmap">DFBitmap.</param>
        /// <param name="x">X position.</param>
        /// <param name="y">Y position.</param>
        /// <param name="colour">Fill colour.</param>
        static public void SetPixel(MCBitmap bitmap, int x, int y, MCColor color)
        {
            int pos = y * bitmap.Stride + x * bitmap.FormatWidth;

            if (bitmap.Format == Formats.RGBA)
            {
                bitmap.Data[pos++] = color.R;
                bitmap.Data[pos++] = color.G;
                bitmap.Data[pos++] = color.B;
                bitmap.Data[pos]   = color.A;
            }
            else if (bitmap.Format == Formats.ARGB)
            {
                bitmap.Data[pos++] = color.A;
                bitmap.Data[pos++] = color.R;
                bitmap.Data[pos++] = color.G;
                bitmap.Data[pos]   = color.B;
            }
        }
Пример #6
0
 /// <summary>
 /// Sets pixel in DFBitmap. Colour formats only.
 /// </summary>
 /// <param name="bitmap">DFBitmap.</param>
 /// <param name="x">X position.</param>
 /// <param name="y">Y position.</param>
 /// <param name="r">Red value.</param>
 /// <param name="g">Green value.</param>
 /// <param name="b">Blue value.</param>
 /// <param name="a">Alpha value.</param>
 static public void SetPixel(MCBitmap bitmap, int x, int y, byte r, byte g, byte b, byte a)
 {
     SetPixel(bitmap, x, y, MCColor.FromRGBA(r, g, b, a));
 }
Пример #7
0
 /// <summary>
 /// Fills DFBitmap with specified colour.
 /// </summary>
 /// <param name="bitmap">DFBitmap to fill.</param>
 /// <param name="color">Source colour.</param>
 static public void Fill(MCBitmap bitmap, MCColor color)
 {
     Fill(bitmap, color.R, color.G, color.B, color.A);
 }
Пример #8
0
 /// <summary>
 /// Constructor.
 /// Creates a new DFBitmap with sized data array filled to specified colour.
 /// </summary>
 /// <param name="width">Image width.</param>
 /// <param name="height">Image height.</param>
 /// <param name="color">Fill colour.</param>
 public MCBitmap(int width, int height, MCColor color)
     : this(width, height)
 {
     Fill(this, color);
 }