CSharpImageLibrary.Headers.DDS_Header.Load C# (CSharp) Method

Load() protected method

Reads DDS header from stream.
protected Load ( Stream stream ) : long
stream Stream Fully formatted DDS image.
return long
        protected override long Load(Stream stream)
        {
            base.Load(stream);
            var temp = stream.ReadBytes(HeaderSize);

            if (!CheckIdentifier(temp))
                throw new FormatException("Stream is not a recognised DDS image.");

            // Start header
            dwSize = BitConverter.ToInt32(temp, 4);
            dwFlags = (DDSdwFlags)BitConverter.ToInt32(temp, 8);
            Height = BitConverter.ToInt32(temp, 12);
            Width = BitConverter.ToInt32(temp, 16);
            dwPitchOrLinearSize = BitConverter.ToInt32(temp, 20);
            dwDepth = BitConverter.ToInt32(temp, 24);
            dwMipMapCount = BitConverter.ToInt32(temp, 28);
            for (int i = 0; i < 11; ++i)
                dwReserved1[i] = BitConverter.ToInt32(temp, 32 + (i * 4));

            // DDS PixelFormat
            ddspf = new DDS_PIXELFORMAT(temp);

            dwCaps = (DDSdwCaps)BitConverter.ToInt32(temp, 108);
            dwCaps2 = BitConverter.ToInt32(temp, 112);
            dwCaps3 = BitConverter.ToInt32(temp, 116);
            dwCaps4 = BitConverter.ToInt32(temp, 120);
            dwReserved2 = BitConverter.ToInt32(temp, 124);

            // DX10 Additional header
            if (ddspf.dwFourCC == FourCC.DX10)
                DX10_DXGI_AdditionalHeader = new DDS_DXGI_DX10_Additional(temp);

            return HeaderSize;
        }