当前位置: 首页>>代码示例>>C#>>正文


C# PixelFormat.MatchMasks方法代码示例

本文整理汇总了C#中PixelFormat.MatchMasks方法的典型用法代码示例。如果您正苦于以下问题:C# PixelFormat.MatchMasks方法的具体用法?C# PixelFormat.MatchMasks怎么用?C# PixelFormat.MatchMasks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PixelFormat的用法示例。


在下文中一共展示了PixelFormat.MatchMasks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

        /// <summary>Load the DDS file.</summary>
        /// <param name="loader"></param>
        /// <returns></returns>
        public override Asset Load(AssetLoader loader)
        {
            using (BinaryReader reader = loader.Reader) {
                reader.RequireMagic(Magic);

                int headerSize = reader.ReadInt32();
                if (headerSize != HeaderSize)
                    throw new InvalidDataException();
                Flags flags = (Flags)reader.ReadInt32();
                if ((flags & RequiredFlags) != RequiredFlags)
                    throw new InvalidDataException();
                int height = reader.ReadInt32();
                int width = reader.ReadInt32();
                int pitchOrLinearSize = reader.ReadInt32();
                int depth = reader.ReadInt32();
                int mipMapCount = reader.ReadInt32();
                reader.BaseStream.Seek(4 * 11, SeekOrigin.Current); // Reserved
                var pixelFormat = new PixelFormat(reader);
                Caps caps = (Caps)reader.ReadInt32(); // Surface complexity
                if ((caps & Caps.Texture) == 0)
                    throw new InvalidDataException();
                Caps2 caps2 = (Caps2)reader.ReadInt32(); // Surface type
                int caps3 = reader.ReadInt32();
                int caps4 = reader.ReadInt32();
                int reserved2 = reader.ReadInt32();

                Format format = null;

                if (pixelFormat.HasFourCC) {
                    if (pixelFormat.FourCC == "DX10")
                        throw new NotSupportedException();
                    format = FormatFourCCs[pixelFormat.FourCC];
                } else if (pixelFormat.HasRGB) {
                    int b0 = 255, b1 = 255 << 8, b2 = 255 << 16, b3 = 255 << 24;

                    if (pixelFormat.HasAlphaPixels && pixelFormat.RGBBitCount == 32) {
                        if (pixelFormat.MatchMasks(b2, b1, b0, b3))
                            format = Glare.Graphics.Formats.Vector4nbBGRA;
                        else if (pixelFormat.MatchMasks(b0, b1, b2, b3))
                            format = Glare.Graphics.Formats.Vector4nb;
                    }
                }

                if (format == null)
                    throw new NotSupportedException();

                if (caps2 != Caps2.None)
                    throw new NotSupportedException("Cube maps or volume textures not supported.");

                int linearSize;

                if ((flags & Flags.Pitch) != 0)
                    linearSize = pitchOrLinearSize * height;
                else if ((flags & Flags.LinearSize) != 0)
                    linearSize = pitchOrLinearSize;
                else
                    linearSize = format.AlignedByteSize(new Vector2i(width, height));

                byte[] data = new byte[linearSize];

                if ((flags & Flags.MipMapCount) == 0)
                    mipMapCount = 1;

                Texture2D texture = new Texture2D();//format, new Vector2i(width, height));
                for (int level = 0; level < mipMapCount; level++) {
                    if (reader.Read(data, 0, linearSize) != linearSize)
                        throw new InvalidDataException();
                    texture.Surface.Levels[level].DataCompressed(format, new Vector2i(width, height), data);

                    width = Math.Max(1, (width + 1) / 2);
                    height = Math.Max(1, (height + 1) / 2);
                    linearSize = format.AlignedByteSize(width, height);
                }

                texture.Name = loader.Name;
                return new TextureAsset(loader, texture);
            }
        }
开发者ID:Burton-Radons,项目名称:Alexandria,代码行数:81,代码来源:DdsFormat.cs


注:本文中的PixelFormat.MatchMasks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。