コード例 #1
0
        public void IsWritingBackCorrectly(string fileName) => File.OpenRead($"Imaging/res/{fileName}.tm2").Using(x =>
                                                                                                                  Helpers.AssertStream(x, stream =>
        {
            var images = Tm2.Read(stream);

            var newStream = new MemoryStream();
            Tm2.Write(newStream, images);

            return(newStream);
        }));
コード例 #2
0
        public void ReadImagePropertiesTest(
            string fileName,
            int width,
            int height,
            PixelFormat pixelFormat) => File.OpenRead($"Imaging/res/{fileName}.tm2").Using(stream =>
        {
            var image = Tm2.Read(stream).Single();

            Assert.Equal(width, image.Size.Width);
            Assert.Equal(height, image.Size.Height);
            Assert.Equal(pixelFormat, image.PixelFormat);
        });
コード例 #3
0
        public static Pmo Read(Stream stream)
        {
            Pmo pmo = new Pmo();

            pmo.PMO_StartPosition = (uint)stream.Position;

            ReadHeader(stream, pmo);
            ReadTextureSection(stream, pmo);

            // Read all data
            if (pmo.header.MeshOffset0 != 0)
            {
                ReadMeshData(stream, pmo, 0);
            }
            if (pmo.header.MeshOffset1 != 0)
            {
                ReadMeshData(stream, pmo, 1);
            }

            // Read textures.
            for (int i = 0; i < pmo.textureInfo.Length; i++)
            {
                if (pmo.textureInfo[i].TextureOffset != 0)
                {
                    stream.Seek(pmo.textureInfo[i].TextureOffset + 0x10, SeekOrigin.Begin);
                    uint tm2size = stream.ReadUInt32() + 0x10;
                    stream.Seek(pmo.textureInfo[i].TextureOffset, SeekOrigin.Begin);
                    Tm2 tm2 = Tm2.Read(stream, true).First();

                    pmo.texturesData.Add(tm2);
                }
            }

            // Read Skeleton.
            if (pmo.header.SkeletonOffset != 0)
            {
                stream.Seek(pmo.PMO_StartPosition + pmo.header.SkeletonOffset, SeekOrigin.Begin);
                pmo.skeletonHeader = Mapping.ReadObject <SkeletonHeader>(stream);
                pmo.boneList       = new BoneData[pmo.skeletonHeader.BoneCount];
                for (int j = 0; j < pmo.skeletonHeader.BoneCount; j++)
                {
                    pmo.boneList[j] = Mapping.ReadObject <BoneData>(stream);
                }
            }

            return(pmo);
        }
コード例 #4
0
ファイル: Pmp.cs プロジェクト: osdanova/OpenKh
        public static Pmp Read(Stream stream)
        {
            Pmp pmp = new Pmp();

            pmp.header = BinaryMapping.ReadObject <Header>(stream);

            // Read Object List.
            for (int i = 0; i < pmp.header.ObjectCount; i++)
            {
                pmp.objectInfo.Add(Mapping.ReadObject <ObjectInfo>(stream));
                pmp.hasDifferentMatrix.Add(BitsUtil.Int.GetBit(pmp.objectInfo[i].ObjectFlags, 0));
            }

            // Read PMO list.
            for (int p = 0; p < pmp.header.ObjectCount; p++)
            {
                ObjectInfo currentPmoInfo = pmp.objectInfo[p];
                if (currentPmoInfo.PMO_Offset != 0)
                {
                    stream.Seek(currentPmoInfo.PMO_Offset, SeekOrigin.Begin);
                    pmp.PmoList.Add(Pmo.Read(stream));
                }
                else
                {
                    pmp.PmoList.Add(null);
                }
            }

            stream.Seek(pmp.header.TextureListOffset, SeekOrigin.Begin);

            for (int t = 0; t < pmp.header.TextureCount; t++)
            {
                pmp.TextureList.Add(BinaryMapping.ReadObject <PMPTextureInfo>(stream));
            }

            // Read textures.
            for (int k = 0; k < pmp.TextureList.Count; k++)
            {
                stream.Seek(pmp.TextureList[k].Offset + 0x10, SeekOrigin.Begin);
                uint tm2size = stream.ReadUInt32() + 0x10;
                stream.Seek(pmp.TextureList[k].Offset, SeekOrigin.Begin);

                pmp.TextureDataList.Add(Tm2.Read(stream, true).First());
            }

            return(pmp);
        }
コード例 #5
0
        static ImageFormatService()
        {
            imageFormat = new IImageFormat[]
            {
                GetImageFormat("PNG", "png", true, Png.IsValid, Png.Read, (stream, image) => Png.Write(stream, image)),
                GetImageFormat("BMP", "bmp", true, Bmp.IsValid, Bmp.Read, (stream, image) => Bmp.Write(stream, image)),
                GetImageFormat("TIFF", "tiff", true, Tiff.IsValid, Tiff.Read, (stream, image) => Tiff.Write(stream, image)),

                GetImageFormat("FAC", "fac", true, Imgd.IsFac, s => Imgd.ReadAsFac(s), (stream, images) =>
                               Imgd.WriteAsFac(stream, images.Select(x => x.AsImgd()))),

                GetImageFormat("IMGD", "imd", true, Imgd.IsValid, Imgd.Read, (stream, image) => image.AsImgd().Write(stream)),

                GetImageFormat("IMGZ", "imz", true, Imgz.IsValid, s => Imgz.Read(s), (stream, images) =>
                               Imgz.Write(stream, images.Select(x => x.AsImgd()))),

                GetImageFormat("KH2 Font", "bar", true, IsKh2Font, ReadKh2Font, WriteKh2Font),

                GetImageFormat("Font ARC", "arc", false, FontsArc.IsValid, s =>
                {
                    var fonts = FontsArc.Read(s);
                    return(new[]
                    {
                        fonts.FontCmd.Image1,
                        fonts.FontCmd.Image2,
                        fonts.FontHelp.Image1,
                        fonts.FontHelp.Image2,
                        fonts.FontMenu.Image1,
                        fonts.FontMenu.Image2,
                        fonts.FontMes.Image1,
                        fonts.FontMes.Image2,
                        fonts.FontNumeral.Image1,
                        fonts.FontNumeral.Image2,
                        fonts.FontIcon,
                    });
                }, (stream, images) =>
                               throw new NotImplementedException()),

                GetImageFormat("TIM2", "tm2", false, Tm2.IsValid, s => Tm2.Read(s), (stream, images) =>
                               throw new NotImplementedException()),

                GetImageFormat("KH2TIM", "tex", false, _ => true,
                               s => ModelTexture.Read(s).Images.Cast <IImageRead>(),
                               (stream, images) => throw new NotImplementedException()),
            };
コード例 #6
0
        static ImageFormatService()
        {
            imageFormat = new IImageFormat[]
            {
                GetImageFormat("PNG", "png", true, Png.IsValid, Png.Read, (stream, image) => Png.Write(stream, image)),
                GetImageFormat("BMP", "bmp", true, Bmp.IsValid, Bmp.Read, (stream, image) => Bmp.Write(stream, image)),
                GetImageFormat("TIFF", "tiff", true, Tiff.IsValid, Tiff.Read, (stream, image) => Tiff.Write(stream, image)),
                GetImageFormat("IMGD", "imd", true, Imgd.IsValid, Imgd.Read, (stream, image) => image.AsImgd().Write(stream)),

                GetImageFormat("IMGZ", "imz", true, Imgz.IsValid, s => Imgz.Read(s), (stream, images) =>
                               Imgz.Write(stream, images.Select(x => x.AsImgd()))),

                GetImageFormat("TIM2", "tm2", false, Tm2.IsValid, s => Tm2.Read(s), (stream, images) =>
                               throw new NotImplementedException()),

                GetImageFormat("KH2TIM", "tex", true, _ => true,
                               s => ModelTexture.Read(s).Images.Cast <IImageRead>(),
                               (stream, images) => throw new NotImplementedException()),
            };
コード例 #7
0
        //[InlineData(".tests/kh2_data/map/jp")]
        public void ValidateAllKH2MapRadarImages(string mapFilesDir)
        {
            Directory.GetFiles(mapFilesDir, "*.map").ToList().ForEach(
                file =>
            {
                File.OpenRead(file).Using(
                    stream =>
                {
                    Bar.Read(stream)
                    // rada may be multiple occurrence like al06.map
                    .Where(
                        entry => true &&
                        entry.Name == "rada" &&
                        entry.Type == Bar.EntryType.Tim2
                        )
                    .ToList()
                    .ForEach(
                        entry =>
                    {
                        Assert.True(Tm2.IsValid(entry.Stream), "Should be TM2");

                        var imageSet = Tm2.Read(entry.Stream);

                        imageSet.ToList().ForEach(
                            texture =>
                        {
                            // All radar images are 4-bpp
                            Assert.NotEmpty(texture.GetData());
                            Assert.Equal(4 * 16, texture.GetClut().Length);
                        }
                            );
                    }
                        );
                }
                    );
            }
                );
        }
コード例 #8
0
ファイル: KingdomTexture.cs プロジェクト: PlancakeJB/OpenKh
 public Tim2KingdomTexture(byte[] texture, GraphicsDevice graphics)
 {
     Texture2D = Tm2.Read(new MemoryStream(texture)).First().CreateTexture(graphics);
 }