Пример #1
0
        public static DdsHeader Parse(Span <byte> data)
        {
            uint[] reserved1 =
            {
                BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(28, 4)),
                BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(32, 4)),
                BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(36, 4)),
                BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(40, 4)),
                BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(44, 4)),
                BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(48, 4)),
                BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(52, 4)),
                BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(56, 4)),
                BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(60, 4)),
                BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(64, 4)),
                BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(68, 4))
            };

            return(new DdsHeader(
                       size: BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(0, 4)),
                       flags: (DdsFlags)BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(4, 4)),
                       height: BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(8, 4)),
                       width: BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(12, 4)),
                       pitchOrLinearSize: BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(16, 4)),
                       depth: BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(20, 4)),
                       mipMapCount: BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(24, 4)),
                       reserved1: reserved1,
                       pixelFormat: DdsPixelFormat.Parse(data, 72),
                       caps1: (DdsCaps1)BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(104, 4)),
                       caps2: (DdsCaps2)BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(108, 4)),
                       caps3: BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(112, 4)),
                       caps4: BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(116, 4)),
                       reserved2: BinaryPrimitives.ReadUInt32LittleEndian(data.Slice(120, 4))));
        }
Пример #2
0
 public DdsHeader(
     uint size,
     DdsFlags flags,
     uint height,
     uint width,
     uint pitchOrLinearSize,
     uint depth,
     uint mipMapCount,
     uint[] reserved1,
     DdsPixelFormat pixelFormat,
     DdsCaps1 caps1,
     DdsCaps2 caps2,
     uint caps3,
     uint caps4,
     uint reserved2)
 {
     this.Size              = size;
     this.Flags             = flags;
     this.Height            = height;
     this.Width             = width;
     this.PitchOrLinearSize = pitchOrLinearSize;
     this.Depth             = depth;
     this.MipMapCount       = mipMapCount;
     this.Reserved1         = reserved1;
     this.PixelFormat       = pixelFormat;
     this.Caps1             = caps1;
     this.Caps2             = caps2;
     this.Caps3             = caps3;
     this.Caps4             = caps4;
     this.Reserved2         = reserved2;
 }
Пример #3
0
        private MipMap[] ThirtyTwoBitImageFormat(Stream stream, int width, int height, int count)
        {
            DdsPixelFormat pixelFormat = this.DdsHeader.PixelFormat;

            bool hasAlpha = pixelFormat.Flags.HasFlag(DdsPixelFormatFlags.AlphaPixels);

            if (hasAlpha && pixelFormat.RBitMask == 0xFF0000 && pixelFormat.GBitMask == 0xFF00 && pixelFormat.BBitMask == 0xFF)
            {
                return(this.AllocateMipMaps <Bgra32>(stream, width, height, count));
            }

            if (hasAlpha && pixelFormat.RBitMask == 0xFF && pixelFormat.GBitMask == 0xFF00 && pixelFormat.BBitMask == 0xFF0000)
            {
                return(this.AllocateMipMaps <Rgba32>(stream, width, height, count));
            }

            if (!hasAlpha && pixelFormat.RBitMask == 0xFF0000 && pixelFormat.GBitMask == 0xFF00 && pixelFormat.BBitMask == 0xFF)
            {
                return(this.AllocateMipMaps <Bgr32>(stream, width, height, count));
            }

            if (!hasAlpha && pixelFormat.RBitMask == 0xFF && pixelFormat.GBitMask == 0xFF00 && pixelFormat.BBitMask == 0xFF0000)
            {
                return(this.AllocateMipMaps <Rgb32>(stream, width, height, count));
            }

            if (!hasAlpha && pixelFormat.RBitMask == 0xFFFF && pixelFormat.GBitMask == 0xFFFF0000 && pixelFormat.BBitMask == 0x0)
            {
                return(this.AllocateMipMaps <Rg32>(stream, width, height, count));
            }

            if (pixelFormat.FourCC == DdsFourCc.R32FLOAT)
            {
                return(this.AllocateMipMaps <Fp32>(stream, width, height, count));
            }

            if (pixelFormat.FourCC == DdsFourCc.R16G16FLOAT)
            {
                return(this.AllocateMipMaps <Rg32Float>(stream, width, height, count));
            }

            if (pixelFormat.FourCC == DdsFourCc.YUY2)
            {
                return(this.AllocateMipMaps <Yuy2>(stream, width, height, count));
            }

            if (pixelFormat.FourCC == DdsFourCc.RGBG)
            {
                return(this.AllocateMipMaps <Rgbg32>(stream, width, height, count));
            }

            if (pixelFormat.FourCC == DdsFourCc.GRGB)
            {
                return(this.AllocateMipMaps <Grgb32>(stream, width, height, count));
            }

            throw new Exception("Unsupported 32 bit format");
        }
Пример #4
0
        private MipMap[] HundredTwentyEightBitImageFormat(Stream stream, int width, int height, int count)
        {
            DdsPixelFormat pixelFormat = this.DdsHeader.PixelFormat;

            if (pixelFormat.FourCC == DdsFourCc.R32G32B32A32FLOAT || pixelFormat.FourCC == DdsFourCc.R32FLOAT)
            {
                return(this.AllocateMipMaps <Rgba128Float>(stream, width, height, count));
            }

            throw new Exception("Unsupported 128 bit format");
        }
Пример #5
0
        private MipMap[] TwentyFourBitImageFormat(Stream stream, int width, int height, int count)
        {
            DdsPixelFormat pixelFormat = this.DdsHeader.PixelFormat;

            bool hasAlpha = pixelFormat.Flags.HasFlag(DdsPixelFormatFlags.AlphaPixels);

            if (!hasAlpha && pixelFormat.RBitMask == 0xFF0000 && pixelFormat.GBitMask == 0xFF00 && pixelFormat.BBitMask == 0xFF)
            {
                return(this.AllocateMipMaps <Bgr24>(stream, width, height, count));
            }

            throw new Exception("Unsupported 24 bit format");
        }
Пример #6
0
        private MipMap[] SixteenBitImageFormat(Stream stream, int width, int height, int count)
        {
            DdsPixelFormat pixelFormat = this.DdsHeader.PixelFormat;

            bool hasAlpha = pixelFormat.Flags.HasFlag(DdsPixelFormatFlags.AlphaPixels);

            if (hasAlpha && pixelFormat.RBitMask == 0xF00 && pixelFormat.GBitMask == 0xF0 && pixelFormat.BBitMask == 0xF)
            {
                return(this.AllocateMipMaps <Bgra16>(stream, width, height, count));
            }

            if (!hasAlpha && pixelFormat.RBitMask == 0x7C00 && pixelFormat.GBitMask == 0x3E0 && pixelFormat.BBitMask == 0x1F)
            {
                return(this.AllocateMipMaps <Bgr555>(stream, width, height, count));
            }

            if (hasAlpha && pixelFormat.RBitMask == 0x7C00 && pixelFormat.GBitMask == 0x3E0 && pixelFormat.BBitMask == 0x1F)
            {
                return(this.AllocateMipMaps <Bgra5551>(stream, width, height, count));
            }

            if (!hasAlpha && pixelFormat.RBitMask == 0xF800 && pixelFormat.GBitMask == 0x7E0 && pixelFormat.BBitMask == 0x1F)
            {
                return(this.AllocateMipMaps <Bgr565>(stream, width, height, count));
            }

            if (hasAlpha && pixelFormat.RBitMask == 0xFF && pixelFormat.GBitMask == 0x0 && pixelFormat.BBitMask == 0x0)
            {
                return(this.AllocateMipMaps <La16>(stream, width, height, count));
            }

            if (!hasAlpha && pixelFormat.RBitMask == 0xFFFF && pixelFormat.GBitMask == 0x0 && pixelFormat.BBitMask == 0x0)
            {
                return(this.AllocateMipMaps <La16>(stream, width, height, count));
            }

            if (!hasAlpha && pixelFormat.RBitMask == 0xFF && pixelFormat.GBitMask == 0xFF00 && pixelFormat.BBitMask == 0x0)
            {
                return(this.AllocateMipMaps <Rg16>(stream, width, height, count));
            }

            if (pixelFormat.FourCC == DdsFourCc.R16FLOAT)
            {
                return(this.AllocateMipMaps <R16Float>(stream, width, height, count));
            }

            throw new Exception("Unsupported 16 bit format");
        }
Пример #7
0
        private MipMap[] SixtyFourBitImageFormat(Stream stream, int width, int height, int count)
        {
            DdsPixelFormat pixelFormat = this.DdsHeader.PixelFormat;

            if (pixelFormat.FourCC == DdsFourCc.R16G16B16A16SNORM || pixelFormat.FourCC == DdsFourCc.R16G16B16A16UNORM)
            {
                return(this.AllocateMipMaps <Rgba64>(stream, width, height, count));
            }

            if (pixelFormat.FourCC == DdsFourCc.R32G32FLOAT)
            {
                return(this.AllocateMipMaps <Rg64Float>(stream, width, height, count));
            }

            if (pixelFormat.FourCC == DdsFourCc.R16G16B16A16FLOAT)
            {
                return(this.AllocateMipMaps <Rgba64Float>(stream, width, height, count));
            }

            throw new Exception("Unsupported 64 bit format");
        }