Exemple #1
0
        public PakFile(string filePath, byte[] paletteData)
        {
            DataOffsets     = new int[0];
            DataSizes       = new int[0];
            SkipFlags       = new int[0];
            CompressedFlags = new int[0];
            myPalette       = new MCPalette(paletteData);

            Load(filePath);
        }
Exemple #2
0
        public PakFile(byte[] data, byte[] paletteData)
        {
            DataOffsets     = new int[0];
            DataSizes       = new int[0];
            SkipFlags       = new int[0];
            CompressedFlags = new int[0];
            myPalette       = new MCPalette(paletteData);

            Load(data);
        }
Exemple #3
0
        /// <summary>
        /// Gets a Color32 array for engine.
        /// </summary>
        /// <param name="srcBitmap">Source DFBitmap.</param>
        /// <param name="alphaIndex">Index to receive transparent alpha.</param>
        /// <param name="border">Number of pixels border to add around image.</param>
        /// <param name="sizeOut">Receives image dimensions with borders included.</param>
        /// <returns>Color32 array.</returns>
        static public Color32[] GetColor32(MCBitmap srcBitmap, MCPalette myPalette, int alphaIndex, int border, out MCSize sizeOut)
        {
            // Calculate dimensions
            int srcWidth  = srcBitmap.Width;
            int srcHeight = srcBitmap.Height;
            int dstWidth  = srcWidth + border * 2;
            int dstHeight = srcHeight + border * 2;

            Color32[] colors = new Color32[dstWidth * dstHeight];

            Color32 c = new Color32();
            int     index, offset, srcRow, dstRow;

            byte[] paletteData = myPalette.PaletteBuffer;
            for (int y = 0; y < srcHeight; y++)
            {
                // Get row position
                srcRow = y * srcWidth;
                dstRow = (dstHeight - 1 - border - y) * dstWidth;

                // Write data for this row
                for (int x = 0; x < srcWidth; x++)
                {
                    index  = srcBitmap.Data[srcRow + x];
                    offset = myPalette.HeaderLength + index * 3;
                    c.r    = (byte)(paletteData[offset] * 4);
                    c.g    = (byte)(paletteData[offset + 1] * 4);
                    c.b    = (byte)(paletteData[offset + 2] * 4);
                    c.a    = (alphaIndex == index) ? (byte)0 : (byte)255;
                    colors[dstRow + border + x] = c;
                }
            }

            sizeOut = new MCSize(dstWidth, dstHeight);

            return(colors);
        }