예제 #1
0
        // Read Functions
        private static void ReadPalette(BinaryReader reader, ArtFile artFile)
        {
            SectionHeader paletteSectionHeader = new SectionHeader(reader);

            paletteSectionHeader.Validate(TagPalette);

            artFile.palettes = new List <Palette>((int)paletteSectionHeader.length);

            for (int i = 0; i < paletteSectionHeader.length; ++i)
            {
                PaletteHeader paletteHeader = new PaletteHeader(reader);

                paletteHeader.Validate();

                Palette palette = new Palette(reader);

                // Rearrange color into standard format. Outpost 2 uses custom color order.
                for (int j = 0; j < palette.colors.Length; ++j)
                {
                    byte temp = palette.colors[j].red;
                    palette.colors[j].red  = palette.colors[j].blue;
                    palette.colors[j].blue = temp;
                }

                artFile.palettes.Add(palette);
            }
        }
예제 #2
0
        // Write Functions
        private void WritePalettes(BinaryWriter writer)
        {
            //if (palettes.Count > uint.MaxValue) {
            //	throw new System.Exception("Art file contains too many palettes.");
            //}

            new SectionHeader(TagPalette, (uint)palettes.Count).Serialize(writer);

            // Intentially do not pass palette as reference to allow local modification
            // Switch red and blue color to match Outpost 2 custom format.
            foreach (Palette palette in palettes)
            {
                PaletteHeader.CreatePaletteHeader().Serialize(writer);

                Palette clonedPalette = new Palette(palette);

                for (int i = 0; i < clonedPalette.colors.Length; ++i)
                {
                    byte swap = clonedPalette.colors[i].red;
                    clonedPalette.colors[i].red  = clonedPalette.colors[i].blue;
                    clonedPalette.colors[i].blue = swap;
                }

                clonedPalette.Serialize(writer);
            }
        }
예제 #3
0
        public static PaletteHeader CreatePaletteHeader()
        {
            PaletteHeader paletteHeader = new PaletteHeader();

            paletteHeader.remainingTagCount = 1;

            ulong dataSize = Bitmap.Palette.SizeInBytes;

            ulong overallSize = 4 + SectionHeader.SizeInBytes +
                                SectionHeader.SizeInBytes + sizeof(uint) + dataSize;

            if (overallSize > uint.MaxValue)
            {
                throw new System.Exception("PRT palettes section is too large.");
            }

            paletteHeader.overallHeader = new SectionHeader(TagSection, (uint)overallSize);
            paletteHeader.sectionHeader = new SectionHeader(TagHeader, sizeof(uint));
            paletteHeader.dataHeader    = new SectionHeader(TagData, (uint)dataSize);

            return(paletteHeader);
        }