Пример #1
0
 public TilesetHeader(BinaryReader reader)
 {
     sectionHead = new SectionHeader(reader);
     tagCount    = reader.ReadUInt32();
     pixelWidth  = reader.ReadUInt32();
     pixelHeight = reader.ReadUInt32();
     bitDepth    = reader.ReadUInt32();
     flags       = reader.ReadUInt32();
 }
Пример #2
0
        private static void ValidatePaletteHeader(SectionHeader paletteHeader)
        {
            if (paletteHeader.tag != TilesetCommon.DefaultTagData)
            {
                TilesetCommon.throwReadError("Palette Header Tag", paletteHeader.tag, TilesetCommon.DefaultTagData);
            }

            if (paletteHeader.length != TilesetCommon.DefaultPaletteHeaderSize)
            {
                TilesetCommon.throwReadError("Palette Header Section Size", paletteHeader.length, TilesetCommon.DefaultPaletteHeaderSize);
            }
        }
Пример #3
0
        private static void ValidateFileSignatureHeader(SectionHeader fileSignatureHeader)
        {
            if (fileSignatureHeader.tag != TagFileSignature)
            {
                TilesetCommon.throwReadError("File Signature", fileSignatureHeader.tag, TagFileSignature);
            }

            if (fileSignatureHeader.length == 0)
            {
                throw new System.Exception("Tileset property File Length reads " +
                                           fileSignatureHeader.length + ", which is too small.");
            }
        }
Пример #4
0
        private static void ValidatePixelHeader(SectionHeader pixelHeader, uint height)
        {
            if (pixelHeader.tag != TilesetCommon.DefaultTagData)
            {
                TilesetCommon.throwReadError("Pixel Header Tag", pixelHeader.tag, TilesetCommon.DefaultTagData);
            }

            uint expectedLength = CalculatePixelHeaderLength(height);

            if (pixelHeader.length != expectedLength)
            {
                TilesetCommon.throwReadError("Pixel Header Length", pixelHeader.length, expectedLength);
            }
        }
Пример #5
0
        // Write tileset in Outpost 2's custom bitmap format.
        // To write tileset in standard bitmap format, use BitmapFile::WriteIndexed
        public static void WriteCustomTileset(Stream streamToWrite, BitmapFile tileset)
        {
            tileset = tileset.Clone();

            ValidateTileset(tileset);

            // OP2 Custom Tileset assumes a positive height and TopDown Scan Line (Contradicts Windows Bitmap File Format)
            if (tileset.GetScanLineOrientation() == ScanLineOrientation.BottomUp)
            {
                tileset.InvertScanLines();
            }
            uint absoluteHeight = (uint)tileset.AbsoluteHeight();

            SectionHeader fileSignature = new SectionHeader(TagFileSignature, CalculatePbmpSectionSize(absoluteHeight));
            TilesetHeader tilesetHeader = TilesetHeader.Create(absoluteHeight / TilesetHeader.DefaultPixelHeightMultiple);
            PpalHeader    ppalHeader    = PpalHeader.Create();

            SectionHeader paletteHeader = new SectionHeader(TilesetCommon.DefaultTagData, TilesetCommon.DefaultPaletteHeaderSize);

            SwapPaletteRedAndBlue(tileset.palette);

            SectionHeader pixelHeader = new SectionHeader(TilesetCommon.DefaultTagData, CalculatePixelHeaderLength(absoluteHeight));

            using (BinaryWriter writer = new BinaryWriter(streamToWrite, System.Text.Encoding.UTF8, true))
            {
                fileSignature.Serialize(writer);
                tilesetHeader.Serialize(writer);
                ppalHeader.Serialize(writer);
                paletteHeader.Serialize(writer);
                for (int i = 0; i < tileset.palette.Length; ++i)
                {
                    tileset.palette[i].Serialize(writer);
                }
                pixelHeader.Serialize(writer);
                writer.Write(tileset.pixels);
            }
        }
Пример #6
0
 public PpalHeader(BinaryReader reader)
 {
     ppal     = new SectionHeader(reader);
     head     = new SectionHeader(reader);
     tagCount = reader.ReadUInt32();
 }