Beispiel #1
0
        private void Read(StreamPart streamPart)
        {
            streamPart.Stream.Position = streamPart.Position;
            using (BinaryReader reader = IOTools.OpenReadFile(streamPart.Stream, IsLittleEndian))
            {
                int tempsize = 0;

                byte[] imageData;

                header = ReadHeader(reader.ReadBytes(0x40));

                ImageFormat   = TMXHelper.PS2ToAux(header.PixelFormat);
                PaletteFormat = TMXHelper.PS2ToAux(header.PaletteFormat);

                tempsize += 0x40;
                System.Drawing.Color[] colors = null;
                if (header.PaletteCount == 1)
                {
                    tempsize += TMXHelper.ReadPalette(reader, header.PixelFormat, header.PaletteFormat, out colors);
                }

                int datasize = header.Height * ImageHelper.GetStride(ImageFormat, header.Width);
                imageData = reader.ReadBytes(datasize);

                tempsize += datasize;

                if (header.FileSize != tempsize)
                {
                    throw new Exception("TMX: filesize not equal");
                }

                bitmap = new Bitmap(header.Width, header.Height, ImageFormat, imageData, colors);
            }
        }
Beispiel #2
0
        public byte[] GetData()
        {
            byte[] returned = new byte[0];

            using (MemoryStream MS = new MemoryStream())
            {
                BinaryWriter writer = IOTools.OpenWriteFile(MS, IsLittleEndian);

                writer.Write(IOTools.GetBytes(header));

                if (ImageFormat.IsIndexed)
                {
                    TMXHelper.WritePalette(writer, header.PixelFormat, header.PaletteFormat, bitmap.CopyPalette());
                }

                writer.Write(bitmap.CopyData());


                returned = MS.ToArray();
            }

            return(returned);
        }