Beispiel #1
0
        public void Save(TextureFormat txt, System.IO.Stream outFormatData)
        {
            TX48Texture texture = txt as TX48Texture;

            if (texture == null)
            {
                throw new TextureFormatException("Not a valid TX48Texture!");
            }

            BinaryWriter writer = new BinaryWriter(outFormatData);

            PalettedTextureFormat segment = texture.TextureFormats.First() as PalettedTextureFormat;

            byte[] img = segment.GetImageData();

            byte[] pal = segment.GetPaletteData().First();

            int widths  = segment.Width;
            int heights = segment.Height;
            int bpps    = segment.Bpp;


            writer.Write(MAGIC.ToCharArray());
            writer.Write(bpps / 4 - 1);

            writer.Write(widths);
            writer.Write(heights);

            writer.Write(0x40);
            writer.Write(pal.Length);

            writer.Write(0x40 + pal.Length);
            writer.Write(img.Length);

            for (int j = 0; j < 8; j++)
            {
                writer.Write(0);
            }

            writer.Write(pal);
            writer.Write(img);
        }
Beispiel #2
0
        public override void Save(TextureFormat texture, System.IO.Stream outFormatData)
        {
            TacticsOgreEFXTexture efxTexture = texture as TacticsOgreEFXTexture;

            if (efxTexture == null)
            {
                throw new TextureFormatException("Not a valid EFX Testure!");
            }

            BinaryWriter writer = new BinaryWriter(new MemoryStream());

            writer.Write(magic);
            writer.Write((byte)0);

            writer.Write(efxTexture.FormatSpecificData.Get <float>(SCALE_KEY));

            writer.Write((uint)0); //temporarily write dummy file size

            int fileSize = 0x10;

            foreach (TextureFormat segment in efxTexture.TextureFormats)
            {
                byte[] entryData            = null;
                int    fullEntrySize        = 0;
                int    sizeOfEntryNoHeader1 = 0;

                byte[] imgData = null, palData = null;
                PalettedTextureFormat palSegment   = segment as PalettedTextureFormat;
                DummyTexture          dummySegment = segment as DummyTexture;

                if (palSegment != null)
                {
                    imgData = palSegment.GetImageData();
                    IList <byte[]> palettes = palSegment.GetPaletteData();
                    if (palettes.Count > 1)
                    {
                        throw new TextureFormatException("EFX should not support multi palette images!");
                    }

                    palData = palettes.First();

                    fullEntrySize = 0x30 + imgData.Length + palData.Length;

                    entryData = imgData.Concat(palData).ToArray();
                }
                else if (dummySegment != null)
                {
                    entryData = dummySegment.FormatSpecificData.Get <byte[]>(RAW_DATA_KEY);

                    fullEntrySize = 0x10 + entryData.Length;
                }
                else
                {
                    throw new TextureFormatException("EFX segments should be Paletted or dummy!");
                }

                writer.Write(fullEntrySize);

                writer.Write(segment.FormatSpecificData.Get <ushort>(UNK1_KEY));
                writer.Write(segment.FormatSpecificData.Get <ushort>(UNK2_KEY));

                sizeOfEntryNoHeader1 = fullEntrySize - 0x10;

                if (palSegment != null)
                {
                    writer.Write((uint)sizeOfEntryNoHeader1);
                }
                else
                {
                    writer.Write(segment.FormatSpecificData.Get <uint>(ENTRY_NO_HEADER_KEY));
                }

                writer.Write(segment.FormatSpecificData.Get <ushort>(ID_KEY));
                writer.Write(segment.FormatSpecificData.Get <byte>(ENTRY_TYPE_KEY));
                writer.Write(segment.FormatSpecificData.Get <byte>(UNK3_KEY));

                if (palSegment != null)
                {
                    byte bpp = segment.FormatSpecificData.Get <byte>(BPP_KEY);
                    writer.Write(bpp);
                    writer.Write(segment.FormatSpecificData.Get <byte>(UNK4_KEY));
                    writer.Write(segment.FormatSpecificData.Get <ushort>(UNK5_KEY));
                    writer.Write((ushort)(1 << bpp));
                    writer.Write((ushort)segment.Width);
                    writer.Write((ushort)segment.Height);
                    writer.Write((ushort)segment.Width);
                    writer.Write((ushort)segment.Height);
                    writer.Write((ushort)0);
                    writer.Write(segment.FormatSpecificData.Get <uint>(UNK6_KEY));

                    int header2AndImgSize = 0x20 + imgData.Length;

                    writer.Write((uint)header2AndImgSize);
                    writer.Write((uint)sizeOfEntryNoHeader1);
                    writer.Write((uint)0);
                }

                writer.Write(entryData);

                fileSize += fullEntrySize;

                if (fullEntrySize % 4 != 0)
                {
                    fileSize = fileSize + 4 - fullEntrySize % 4;
                    writer.Write(Enumerable.Repeat((byte)0, 4 - fullEntrySize % 4).ToArray());
                }
            }
            writer.BaseStream.Position = 0x0C;
            writer.Write((uint)fileSize);

            byte[] finalData = (writer.BaseStream as MemoryStream).ToArray();
            outFormatData.Write(finalData, 0, finalData.Length);

            writer.Close();
        }