示例#1
0
        private void ReadData(Ibasa.IO.BinaryReader reader)
        {
            int depth = (HeaderFlags.HasFlag(HeaderFlagsEnum.Depth) ? Depth : 1);
            int mipmapCount = (HeaderFlags.HasFlag(HeaderFlagsEnum.MipmapCount) ? MipmapCount : 1);

            if (IsDX10Mode)
            {
                int arraySize = (CubemapFlags.HasFlag(CubemapFlagsEnum.Cubemap) ? 6 : 1) * ArraySize;

                Image = new Resource(new Size3i(Width, Height, depth), mipmapCount, arraySize, SelectLoadFormat());

                for (int arraySlice = 0; arraySlice < Image.ArraySize; ++arraySlice)
                {
                    for (int mipSlice = 0; mipSlice < Image.MipLevels; ++mipSlice)
                    {
                        byte[] subresource = Image[mipSlice, arraySlice];
                        reader.Read(subresource, 0, subresource.Length);
                    }
                }
            }
            else if (PixelFlags.HasFlag(PixelFlagsEnum.FourCC))
            {
                int arraySize = (CubemapFlags.HasFlag(CubemapFlagsEnum.Cubemap) ? 6 : 1);

                Image = new Resource(new Size3i(Width, Height, depth), mipmapCount, arraySize, SelectLoadFormat());

                for (int arraySlice = 0; arraySlice < Image.ArraySize; ++arraySlice)
                {
                    for (int mipSlice = 0; mipSlice < Image.MipLevels; ++mipSlice)
                    {
                        byte[] subresource = Image[mipSlice, arraySlice];
                        reader.Read(subresource, 0, subresource.Length);
                    }
                }
            }
        }
示例#2
0
文件: Vtf.cs 项目: Frassle/Ibasa
        private void ReadData(Ibasa.IO.BinaryReader reader)
        {
            LowResImage = new SharpIL.Resource(
                new Size3i(LowResImageWidth, LowResImageHeight, 1), 1, 1, EncodingFromFormat(LowResImageFormat));
            HighResImage = new SharpIL.Resource(
                new Size3i(Width, Height, Depth), MipmapCount, Frames * Faces, EncodingFromFormat(ImageFormat));

            if (VersionMinor < 3)
            {
                reader.Read(LowResImage[0, 0], 0, LowResImage[0, 0].Length);

                for (int mip = MipmapCount-1; mip >=0 ; --mip)
                {
                    Size3f size = HighResImage.ComputeMipSliceSize(mip);

                    for (int frame = 0; frame < Frames; ++frame)
                    {
                        for (int face = 0; face < Faces; ++face)
                        {
                            int array = face + (Faces * frame);
                            reader.Read(
                                HighResImage[mip, array], 0,
                                HighResImage[mip, array].Length);
                        }
                    }
                }
            }
            else
            {
                //low res
                int lowResOffset = Resources.Find((resource) => resource.Type == ResourceType.LowResImage).Data;
                reader.Seek((uint)lowResOffset, SeekOrigin.Begin);
                reader.Read(LowResImage[0, 0], 0, LowResImage[0, 0].Length);

                //high res
                int highResOffset = Resources.Find((resource) => resource.Type == ResourceType.Image).Data;
                reader.Seek((uint)highResOffset, SeekOrigin.Begin);

                for (int mip = MipmapCount - 1; mip >= 0; --mip)
                {
                    Size3f size = HighResImage.ComputeMipSliceSize(mip);

                    for (int frame = 0; frame < Frames; ++frame)
                    {
                        for (int face = 0; face < Faces; ++face)
                        {
                            byte[] data = HighResImage[mip, face + (Faces * frame)];
                            reader.Read(data, 0, data.Length);
                        }
                    }
                }
            }
        }