/// <summary>
        /// Gets a Color32 array as emission map based for window textures.
        /// </summary>
        /// <param name="srcBitmap">Source bitmap.</param>
        /// <param name="emissionIndex">Index to receive emission colour.</param>
        /// <returns>Color32 array.</returns>
        public Color32[] GetWindowColors32(DFBitmap srcBitmap, int emissionIndex = 0xff)
        {
            // Must be an indexed format
            if (srcBitmap.Format != DFBitmap.Formats.Indexed)
                return null;

            // Create target array
            DFSize sz = new DFSize(srcBitmap.Width, srcBitmap.Height);
            Color32[] emissionColors = new Color32[sz.Width * sz.Height];

            // Generate emissive parts of texture based on index
            int index, srcRow, dstRow;
            for (int y = 0; y < sz.Height; y++)
            {
                // Get row position
                srcRow = y * sz.Width;
                dstRow = (sz.Height - 1 - y) * sz.Width;

                // Write data for this row
                for (int x = 0; x < sz.Width; x++)
                {
                    index = srcBitmap.Data[srcRow + x];
                    if (index == emissionIndex)
                        emissionColors[dstRow + x] = Color.white;
                }
            }

            return emissionColors;
        }
        /// <summary>
        /// Get extracted heightmap data as an indexed image.
        /// </summary>
        /// <returns>DFBitmap object.</returns>
        public DFBitmap GetHeightMapDFBitmap()
        {
            DFBitmap DFBitmap = new DFBitmap();
            DFBitmap.Width = mapWidthValue;
            DFBitmap.Height = mapHeightValue;
            DFBitmap.Data = heightMapBuffer;

            return DFBitmap;
        }
 /// <summary>
 /// Gets a Color32 array for engine with minimum options.
 /// </summary>
 /// <param name="srcBitmap">Source DFBitmap.</param>
 /// <param name="alphaIndex">Index to receive transparent alpha.</param>
 /// <returns>Color32 array.</returns>
 public Color32[] GetColors32(DFBitmap srcBitmap, int alphaIndex = -1)
 {
     DFSize sz;
     return GetColors32(srcBitmap, alphaIndex, 0, out sz);
 }
        /// <summary>
        /// Gets a Color32 array for engine with a border.
        /// </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>
        public Color32[] GetColors32(DFBitmap srcBitmap, int alphaIndex, int border, out DFSize sizeOut)
        {
            // Must be an indexed format
            if (srcBitmap.Format != DFBitmap.Formats.Indexed)
            {
                sizeOut = new DFSize();
                return null;
            }

            // Calculate dimensions
            int srcWidth = srcBitmap.Width;
            int srcHeight = srcBitmap.Height;
            int dstWidth = srcWidth + border * 2;
            int dstHeight = srcHeight + border * 2;

            // Create target array
            Color32[] colors = new Color32[dstWidth * dstHeight];

            DFColor c;
            byte a;
            int index, srcRow, dstRow;
            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];
                    c = myPalette.Get(index);
                    if (alphaIndex == index) a = 0x00; else a = 0xff;

                    colors[dstRow + border + x] = new Color32(c.R, c.G, c.B, a);
                }
            }

            sizeOut = new DFSize(dstWidth, dstHeight);

            return colors;
        }
Beispiel #5
0
 /// <summary>
 /// Get extracted PAK data as an indexed image.
 /// </summary>
 /// <returns>DFBitmap object.</returns>
 public DFBitmap GetDFBitmap()
 {
     DFBitmap DFBitmap = new DFBitmap();
     DFBitmap.Width = pakWidthValue;
     DFBitmap.Height = PakRowCount;
     DFBitmap.Data = pakExtractedBuffer;
     return DFBitmap;
 }
        /// <summary>
        /// Get raw bytes for specified record and frame using a custom pixel format.
        /// </summary>
        /// <param name="record">Index of record.</param>
        /// <param name="frame">Index of frame.</param>
        /// <param name="alphaIndex">Index of alpha colour.</param>
        /// <param name="format">Specified pixel format to use.</param>
        /// <returns>DFBitmap object.</returns>
        public DFBitmap GetBitmapFormat(int record, int frame, byte alphaIndex, DFBitmap.Formats format)
        {
            // Get as indexed image
            if (format == DFBitmap.Formats.Indexed)
                return GetDFBitmap(record, frame);

            // Create new bitmap
            const int formatWidth = 4;
            DFBitmap srcBitmap = GetDFBitmap(record, frame);
            DFBitmap dstBitmap = new DFBitmap();
            dstBitmap.Format = format;
            dstBitmap.Width = srcBitmap.Width;
            dstBitmap.Height = srcBitmap.Height;
            dstBitmap.Stride = dstBitmap.Width * formatWidth;
            dstBitmap.Data = new byte[dstBitmap.Stride * dstBitmap.Height];

            // Write pixel data to array
            byte a, r, g, b;
            int srcPos = 0, dstPos = 0;
            for (int i = 0; i < dstBitmap.Width * dstBitmap.Height; i++)
            {
                // Write colour values
                byte index = srcBitmap.Data[srcPos++];
                if (index != alphaIndex)
                {
                    // Get colour values
                    a = 0xff;
                    r = myPalette.GetRed(index);
                    g = myPalette.GetGreen(index);
                    b = myPalette.GetBlue(index);

                    // Write colour values
                    switch (format)
                    {
                        case DFBitmap.Formats.RGBA:
                            dstBitmap.Data[dstPos++] = r;
                            dstBitmap.Data[dstPos++] = g;
                            dstBitmap.Data[dstPos++] = b;
                            dstBitmap.Data[dstPos++] = a;
                            break;
                        case DFBitmap.Formats.ARGB:
                            dstBitmap.Data[dstPos++] = a;
                            dstBitmap.Data[dstPos++] = r;
                            dstBitmap.Data[dstPos++] = g;
                            dstBitmap.Data[dstPos++] = b;
                            break;
                        default:
                            throw new Exception("Unknown output format.");
                    }
                }
                else
                {
                    // Step over alpha pixels
                    dstPos += formatWidth;
                }
            }

            return dstBitmap;
        }
        /// <summary>
        /// Gets block AutoMap by name.
        /// </summary>
        /// <param name="name">Name of block.</param>
        /// <param name="removeGroundFlats">Filters ground flat "speckles" from the AutoMap.</param>
        /// <returns>DFBitmap object.</returns>
        public DFBitmap GetBlockAutoMap(string name, bool removeGroundFlats)
        {
            // Test block is valid
            DFBlock dfBlock = GetBlock(name);
            if (string.IsNullOrEmpty(dfBlock.Name))
                return new DFBitmap();

            // Create DFBitmap and copy data
            DFBitmap dfBitmap = new DFBitmap();
            dfBitmap.Data = dfBlock.RmbBlock.FldHeader.AutoMapData;
            dfBitmap.Width = 64;
            dfBitmap.Height = 64;

            // Filter ground flats if specified
            if (removeGroundFlats)
            {
                for (int i = 0; i < dfBitmap.Data.Length; i++)
                {
                    if (dfBitmap.Data[i] == 0xfb)
                        dfBitmap.Data[i] = 0x00;
                }
            }

            return dfBitmap;
        }
        /// <summary>
        /// Reads image data.
        /// </summary>
        /// <param name="index">Index of image.</param>
        private bool ReadImageData(int index)
        {
            // Read image if not already stored
            if (null == bitmaps[index])
            {
                BinaryReader Reader = managedFile.GetReader(imageDataPosition + (frameDataLength * index));
                bitmaps[index] = new DFBitmap();
                bitmaps[index].Width = frameWidth;
                bitmaps[index].Height = frameHeight;
                bitmaps[index].Data = Reader.ReadBytes(frameDataLength);
            }

            return true;
        }
        /// <summary>
        /// Get extracted heightmap data as an indexed image.
        /// </summary>
        /// <returns>DFBitmap object.</returns>
        public DFBitmap GetHeightMapDFBitmap()
        {
            DFBitmap DFBitmap = new DFBitmap();
            DFBitmap.Format = DFBitmap.Formats.Indexed;
            DFBitmap.Width = mapWidthValue;
            DFBitmap.Height = mapHeightValue;
            DFBitmap.Stride = mapWidthValue;
            DFBitmap.Data = heightMapBuffer;

            return DFBitmap;
        }
Beispiel #10
0
 /// <summary>
 /// Get extracted PAK data as an indexed image.
 /// </summary>
 /// <returns>DFBitmap object.</returns>
 public DFBitmap GetDFBitmap()
 {
     DFBitmap DFBitmap = new DFBitmap();
     DFBitmap.Format = DFBitmap.Formats.Indexed;
     DFBitmap.Width = pakWidthValue;
     DFBitmap.Height = PakRowCount;
     DFBitmap.Stride = pakWidthValue;
     DFBitmap.Data = pakExtractedBuffer;
     return DFBitmap;
 }
        /// <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>
        public Color32[] GetColor32(DFBitmap srcBitmap, int alphaIndex, int border, out DFSize 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 = paletteData[offset];
                    c.g = paletteData[offset + 1];
                    c.b = paletteData[offset + 2];
                    c.a = (alphaIndex == index) ? (byte)0 : (byte)255;
                    colors[dstRow + border + x] = c;
                }
            }

            sizeOut = new DFSize(dstWidth, dstHeight);

            return colors;
        }