Exemple #1
0
        public void TestPfA8R8G8B8()
        {
            DdsTestCase[] testCases =
            {
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(), 1024, 1024,  1), "A8R8G8B8 1 mip"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(), 1024, 1024,  2), "A8R8G8B8 2 mip"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(), 1024, 1024,  5), "A8R8G8B8 5 mip"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(), 1024, 1024, 10), "A8R8G8B8 10 mip"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(), 1024, 1024, 15), "A8R8G8B8 15 mip"),

                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(),    1,    1,  1), "A8R8G8B8 1x1"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(),    2,    2,  2), "A8R8G8B8 2x2"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(),    4,    4,  3), "A8R8G8B8 4x4"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(),    8,    8,  4), "A8R8G8B8 8x8"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(),   16,   16,  5), "A8R8G8B8 16x16"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(),   32,   32,  6), "A8R8G8B8 32x32"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(),   64,   64,  7), "A8R8G8B8 64x63"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(),  128,  128,  8), "A8R8G8B8 128x128"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(),  256,  256,  9), "A8R8G8B8 256x256"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(),  512,  512, 10), "A8R8G8B8 512x512"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(), 1024, 1024, 11), "A8R8G8B8 1024x1024"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(), 2048, 2048, 12), "A8R8G8B8 2048x2048"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(), 4096, 4096, 13), "A8R8G8B8 4096x4096"),
                new DdsTestCase(new DdsOptions(DdsPixelFormat.DdsPfA8R8G8B8(), 8192, 8192, 14), "A8R8G8B8 8192x8192")
            };

            RunDdsTestCase(testCases);
        }
Exemple #2
0
        public static DdsFile ConvertToDds(FtexFile file)
        {
            DdsFile result = new DdsFile
            {
                Header = new DdsFileHeader
                {
                    Size        = DdsFileHeader.DefaultHeaderSize,
                    Flags       = DdsFileHeaderFlags.Texture,
                    Height      = file.Height,
                    Width       = file.Width,
                    Depth       = file.Depth,
                    MipMapCount = file.MipMapCount,
                    Caps        = DdsSurfaceFlags.Texture
                }
            };

            if (result.Header.Depth == 1)
            {
                result.Header.Depth = 0;
            }
            else if (result.Header.Depth > 1)
            {
                result.Header.Flags |= DdsFileHeaderFlags.Volume;
            }

            if (result.Header.MipMapCount == 1)
            {
                result.Header.MipMapCount = 0;
            }
            else if (result.Header.MipMapCount > 1)
            {
                result.Header.Flags |= DdsFileHeaderFlags.MipMap;
                result.Header.Caps  |= DdsSurfaceFlags.MipMap;
            }

            switch (file.PixelFormatType)
            {
            case 0:
                result.Header.PixelFormat = DdsPixelFormat.DdsPfA8R8G8B8();
                break;

            case 1:
                result.Header.PixelFormat = DdsPixelFormat.DdsLuminance();
                break;

            case 2:
                result.Header.PixelFormat = DdsPixelFormat.DdsPfDxt1();
                break;

            case 4:
                result.Header.PixelFormat = DdsPixelFormat.DdsPfDxt5();
                break;

            default:
                throw new ArgumentException($"Unknown PixelFormatType {file.PixelFormatType}");
            }

            result.Data = file.Data;
            return(result);
        }
Exemple #3
0
        public static FtexFile ConvertToFtex(DdsFile file, FtexTextureType textureType, FtexUnknownFlags flags, int?ftexsFileCount)
        {
            FtexFile result = new FtexFile();

            if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfA8R8G8B8()))
            {
                result.PixelFormatType = 0;
            }
            else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsLuminance()))
            {
                result.PixelFormatType = 1;
            }
            else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfDxt1()))
            {
                result.PixelFormatType = 2;
            }
            else if (file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfDxt3()) ||
                     file.Header.PixelFormat.Equals(DdsPixelFormat.DdsPfDxt5()))
            {
                result.PixelFormatType = 4;
            }
            else
            {
                throw new ArgumentException($"Unknown PixelFormatType {file.Header.PixelFormat}");
            }

            result.Height = Convert.ToInt16(file.Header.Height);
            result.Width  = Convert.ToInt16(file.Header.Width);
            result.Depth  = Convert.ToInt16(file.Header.Depth == 0 ? 1 : file.Header.Depth);

            var mipMapData = GetMipMapData(file);
            var mipMaps    = GetMipMapInfos(mipMapData, ftexsFileCount);
            var ftexsFiles = GetFtexsFiles(mipMaps, mipMapData);

            result.MipMapCount = Convert.ToByte(mipMaps.Count);
            result.NrtFlag     = 2;
            result.AddMipMapInfos(mipMaps);
            result.AddFtexsFiles(ftexsFiles);
            result.FtexsFileCount = ftexsFileCount == 0
                ? (byte)0
                : Convert.ToByte(ftexsFiles.Count);
            result.AdditionalFtexsFileCount = ftexsFileCount == 0
                ? (byte)0
                : Convert.ToByte(ftexsFiles.Count - 1);
            result.UnknownFlags = flags;
            result.TextureType  = textureType;
            return(result);
        }