AmaroK86.ImageFormat.DDS.DDS C# (CSharp) Method

DDS() public method

public DDS ( string fileName, ImageSize imgSize, string format, byte rawData ) : System
fileName string
imgSize ImageSize
format string
rawData byte
return System
        public DDS(string fileName, ImageSize imgSize, string format, byte[] rawData)
            : base(fileName, imgSize, format)
        {
            DDSHeader.magic = 0x20534444;
            DDSHeader.Size = 0x7C;
            DDSHeader.Flags = 0x081007;
            DDSHeader.Caps = 0x1000;
            DDSHeader.pfFlags = 0x4;
            DDSHeader.pfSize = 0x20;
            DDSHeader.Width = imgSize.width;
            DDSHeader.Height = imgSize.height;
            switch (format)
            {
                case "PF_DXT1":
                case "DXT1":
                    DDSHeader.FourCC = (int)FourCC.DXT1;
                    BPP = 0.5F;
                    break;
                case "PF_DXT5":
                case "DXT5":
                    DDSHeader.FourCC = (int)FourCC.DXT5;
                    BPP = 1;
                    break;
                case "PF_V8U8":
                case "V8U8":
                    DDSHeader.Flags = 0x001007;
                    DDSHeader.pfFlags = 0x80000;
                    DDSHeader.RGBBitCount = 0x10;
                    DDSHeader.RBitMask = 0x0000FF;
                    DDSHeader.GBitMask = 0x00FF00;
                    BPP = 2;
                    break;
                case "ATI2":
                case "PF_NormalMap_HQ":
                    DDSHeader.FourCC = (int)FourCC.ATI2;
                    BPP = 1;
                    break;
                case "PF_A8R8G8B8":
                case "A8R8G8B8":
                case "ARGB":
                    BPP = 4;
                    DDSHeader.pfFlags = 0x41;
                    DDSHeader.RGBBitCount = 0x20;
                    DDSHeader.RBitMask = 0xFF0000;
                    DDSHeader.GBitMask = 0xFF00;
                    DDSHeader.BBitMask = 0xFF;
                    DDSHeader.ABitMask = -16777216;
                    break;
                case "PF_R8G8B8":
                case "R8G8B8":
                    BPP = 3;
                    DDSHeader.pfFlags = 0x40;
                    DDSHeader.RGBBitCount = 0x18;
                    DDSHeader.RBitMask = 0xFF0000;
                    DDSHeader.GBitMask = 0xFF00;
                    DDSHeader.BBitMask = 0xFF;
                    DDSHeader.ABitMask = 0x0;
                    break;
                case "PF_G8":
                case "G8":
                case "G8_L8":
                    BPP = 1;
                    DDSHeader.pfFlags = 0x20000;
                    DDSHeader.RGBBitCount = 0x8;
                    DDSHeader.RBitMask = 0xFF;
                    break;
                default: throw new FormatException("Invalid DDS format");
            }
            imgData = rawData;

            // convert DDSHeader to byte array
            int headSize = Marshal.SizeOf(DDSHeader);
            headData = new byte[headSize];
            IntPtr ptr = Marshal.AllocHGlobal(headSize);
            Marshal.StructureToPtr(DDSHeader, ptr, true);
            Marshal.Copy(ptr, headData, 0, headData.Length);
            Marshal.FreeHGlobal(ptr);
        }

Same methods

DDS::DDS ( string fileName, byte data ) : System