コード例 #1
0
        public void WriteAndRead()
        {
            string filename = Data.MakeOutputPath("blark.out");

            ImageHeader w = new ImageHeader(new Dimensions(10, 20),
                                            System.TypeCode.Byte,
                                            0,
                                            null
                                            );

            w.Write(filename);

            ImageHeader r = new ImageHeader();

            r.Read(filename);

            Assert.AreEqual(r.Dimensions.Rows, w.Dimensions.Rows);
            Assert.AreEqual(r.Dimensions.Columns, w.Dimensions.Columns);
            Assert.AreEqual(r.BandType, w.BandType);
            Assert.AreEqual(r.BandCount, w.BandCount);
            Assert.AreEqual(r.BandSize, w.BandSize);
        }
コード例 #2
0
        public void Load(System.IO.Stream stream)
        {
            Text = FileName;

            using (var reader = new FileReader(stream))
            {
                reader.SetByteOrder(true);

                uint Identifier = reader.ReadUInt32();

                //TPL has multiple versions i assume? Some games like F Zero use a custom one so try that
                if (Identifier != 0x0020AF30)
                {
                    reader.Position = 0;
                    uint ImageCount = reader.ReadUInt32();
                    Console.WriteLine("ImageCount" + ImageCount);
                    for (int i = 0; i < ImageCount; i++)
                    {
                        reader.SeekBegin(4 + (i * 0x10));

                        uint   format   = reader.ReadUInt32();
                        uint   offset   = reader.ReadUInt32();
                        uint   width    = reader.ReadUInt16();
                        uint   height   = reader.ReadUInt16();
                        uint   mipCount = reader.ReadUInt16();
                        ushort unknown  = reader.ReadUInt16();

                        if (format == 256)
                        {
                            break;
                        }

                        Console.WriteLine(offset);
                        Console.WriteLine(format);

                        var GXFormat = (Decode_Gamecube.TextureFormats)format;

                        //Now create a wrapper
                        var texWrapper = new TplTextureWrapper();
                        texWrapper.Text             = $"Texture {i}";
                        texWrapper.ImageKey         = "Texture";
                        texWrapper.SelectedImageKey = "Texture";
                        texWrapper.Format           = Decode_Gamecube.ToGenericFormat(GXFormat);
                        texWrapper.Width            = width;
                        texWrapper.Height           = height;
                        texWrapper.MipCount         = mipCount;
                        texWrapper.ImageData        = reader.getSection(offset, (uint)Decode_Gamecube.GetDataSize(GXFormat, (int)width, (int)height));
                        texWrapper.PlatformSwizzle  = PlatformSwizzle.Platform_Gamecube;
                        Nodes.Add(texWrapper);
                    }
                }
                else
                {
                    uint ImageCount       = reader.ReadUInt32();
                    uint ImageOffsetTable = reader.ReadUInt32();

                    for (int i = 0; i < ImageCount; i++)
                    {
                        reader.SeekBegin(ImageOffsetTable + (i * 8));

                        uint ImageHeaderOffset   = reader.ReadUInt32();
                        uint PaletteHeaderOffset = reader.ReadUInt32();

                        reader.SeekBegin(ImageHeaderOffset);
                        var image = new ImageHeader();
                        image.Read(reader);
                        ImageHeaders.Add(image);

                        var GXFormat = (Decode_Gamecube.TextureFormats)image.Format;

                        Console.WriteLine($"ImageOffset {image.ImageOffset}");

                        //Now create a wrapper
                        var texWrapper = new TplTextureWrapper();
                        texWrapper.Text             = $"Texture {i}";
                        texWrapper.ImageKey         = "Texture";
                        texWrapper.SelectedImageKey = "Texture";
                        texWrapper.Format           = Decode_Gamecube.ToGenericFormat(GXFormat);
                        texWrapper.Width            = image.Width;
                        texWrapper.Height           = image.Height;
                        texWrapper.MipCount         = 1;
                        texWrapper.PlatformSwizzle  = PlatformSwizzle.Platform_Gamecube;
                        texWrapper.ImageData        = reader.getSection(image.ImageOffset,
                                                                        (uint)Decode_Gamecube.GetDataSize(GXFormat, (int)image.Width, (int)image.Height));

                        //Palette is sometimes unused to check
                        if (PaletteHeaderOffset != 0)
                        {
                            reader.SeekBegin(PaletteHeaderOffset);
                            var palette = new PaletteHeader();
                            palette.Read(reader);
                            PaletteHeaders.Add(palette);

                            var GXPaletteFormat = (Decode_Gamecube.PaletteFormats)palette.PaletteFormat;

                            Console.WriteLine($"GXPaletteFormat {GXPaletteFormat}");
                            texWrapper.SetPaletteData(palette.Data, Decode_Gamecube.ToGenericPaletteFormat(GXPaletteFormat));
                        }

                        Nodes.Add(texWrapper);
                    }
                }
            }
        }