public void Read(BinaryReaderExt reader) { reader.ReadChars(4); dwSize = reader.ReadUInt32(); dwFlags = (DDSD)reader.ReadUInt32(); dwHeight = reader.ReadInt32(); dwWidth = reader.ReadInt32(); dwPitchOrLinearSize = reader.ReadInt32(); dwDepth = reader.ReadInt32(); dwMipMapCount = reader.ReadInt32(); dwReserved1 = new uint[11]; for (int i = 0; i < 11; i++) { dwReserved1[i] = reader.ReadUInt32(); } ddspf.Read(reader); dwCaps = (DDSCAPS)reader.ReadInt32(); dwCaps2 = (DDSCAPS2)reader.ReadInt32(); dwCaps3 = reader.ReadUInt32(); dwCaps4 = reader.ReadUInt32(); dwReserved2 = reader.ReadUInt32(); if (ddspf.dwFlags.HasFlag(DDPF.FOURCC) && ddspf.dwFourCC == 0x30315844) { DXT10Header.Read(reader); } }
/// <summary> /// Read a DDS header from an array of bytes. /// </summary> public DDS(byte[] bytes) { BinaryReaderEx br = new BinaryReaderEx(false, bytes); // dwMagic br.AssertASCII("DDS "); // dwSize br.AssertInt32(0x7C); dwFlags = (DDSD)br.ReadUInt32(); dwHeight = br.ReadInt32(); dwWidth = br.ReadInt32(); dwPitchOrLinearSize = br.ReadInt32(); dwDepth = br.ReadInt32(); dwMipMapCount = br.ReadInt32(); // dwReserved1 br.Skip(4 * 11); ddspf = new PIXELFORMAT(br); dwCaps = (DDSCAPS)br.ReadUInt32(); dwCaps2 = (DDSCAPS2)br.ReadUInt32(); // dwCaps3, dwCaps4, dwReserved2 br.Skip(4 * 3); if (ddspf.dwFourCC == PIXELFORMAT.FourCCDX10) { header10 = new HEADER_DXT10(br); } else { header10 = null; } }
/// <summary> /// /// </summary> /// <returns></returns> public IGraphicsSurface GetBackBufferSurface() { var ddsCaps = new DDSCAPS2(); ddsCaps.lCaps = CONST_DDSURFACECAPSFLAGS.DDSCAPS_BACKBUFFER; return(new DirectDrawSurface(_surface.GetAttachedSurface(ref ddsCaps))); }
/// <summary> /// Create a new DDS header with default values and no DX10 header. /// </summary> public DDS() { dwFlags = HEADER_FLAGS_TEXTURE; dwHeight = 0; dwWidth = 0; dwPitchOrLinearSize = 0; dwDepth = 0; dwMipMapCount = 0; ddspf = new PIXELFORMAT(); dwCaps = DDSCAPS.TEXTURE; dwCaps2 = 0; header10 = null; }
public void Read(BinaryReader br) { dwMagic = br.ReadInt32(); // DDSURFACEDESC2 dwSize = br.ReadInt32(); dwFlags = (DDSD)br.ReadInt32(); dwHeight = br.ReadInt32(); dwWidth = br.ReadInt32(); dwPitchOrLinearSize = br.ReadInt32(); dwDepth = br.ReadInt32(); dwMipMapCount = br.ReadInt32(); dwReserved1 = new int[11]; for (int x = 0; x < dwReserved1.Length; x++) { dwReserved1[x] = br.ReadInt32(); } // DDPIXELFORMAT dwSize2 = br.ReadInt32(); dwFlags2 = (DDPF)br.ReadInt32(); dwFourCC = (FourCC)br.ReadInt32(); dwRGBBitCount = br.ReadInt32(); dwRBitMask = br.ReadInt32(); dwGBitMask = br.ReadInt32(); dwBBitMask = br.ReadInt32(); dwRGBAlphaBitMask = br.ReadUInt32(); // DDSCAPS2; dwCaps1 = (DDSCAPS)br.ReadInt32(); dwCaps2 = (DDSCAPS2)br.ReadInt32(); Reserved2 = new int[2]; for (int x = 0; x < Reserved2.Length; x++) { Reserved2[x] = br.ReadInt32(); } dwReserved3 = br.ReadInt32(); }
public void Read(BinaryReader br) { int num; dwMagic = br.ReadInt32(); dwSize = br.ReadInt32(); dwFlags = (DDSD)br.ReadInt32(); dwHeight = br.ReadInt32(); dwWidth = br.ReadInt32(); dwPitchOrLinearSize = br.ReadInt32(); dwDepth = br.ReadInt32(); dwMipMapCount = br.ReadInt32(); dwReserved1 = new int[11]; for (num = 0; num < dwReserved1.Length; num++) { dwReserved1[num] = br.ReadInt32(); } dwSize2 = br.ReadInt32(); dwFlags2 = (DDPF)br.ReadInt32(); dwFourCC = (FourCC)br.ReadInt32(); dwRGBBitCount = br.ReadInt32(); dwRBitMask = br.ReadInt32(); dwGBitMask = br.ReadInt32(); dwBBitMask = br.ReadInt32(); dwRGBAlphaBitMask = br.ReadUInt32(); dwCaps1 = (DDSCAPS)br.ReadInt32(); dwCaps2 = (DDSCAPS2)br.ReadInt32(); Reserved2 = new int[2]; for (num = 0; num < Reserved2.Length; num++) { Reserved2[num] = br.ReadInt32(); } dwReserved3 = br.ReadInt32(); }
public DDS(bitmap.BitmapData BitmapInfo) { dwMagic = 0x20534444; dwSize = 0x7c; dwFlags = 0; dwFlags |= DDSD.CAPS; dwFlags |= DDSD.HEIGHT; dwFlags |= DDSD.WIDTH; dwFlags |= DDSD.PIXELFORMAT; dwHeight = BitmapInfo.VirtualHeight; dwWidth = BitmapInfo.VirtualWidth; if (BitmapInfo.Format == BitmapFormat.A8R8G8B8) { dwFlags |= DDSD.PITCH; dwPitchOrLinearSize = dwWidth * 4; } else { dwFlags |= DDSD.LINEARSIZE; dwPitchOrLinearSize = BitmapInfo.RawSize; } dwDepth = 0; dwMipMapCount = 0; dwReserved1 = new int[11]; dwSize2 = 0x20; dwFlags2 = 0; dwFourCC = FourCC.None; switch (BitmapInfo.Format) { case BitmapFormat.A8R8G8B8: dwFlags2 |= DDPF.RGB; dwFlags2 |= DDPF.ALPHAPIXELS; break; case BitmapFormat.Dxt1: dwFlags2 |= DDPF.FOURCC; dwFourCC = FourCC.DXT1; break; case BitmapFormat.Dxt3: dwFlags2 |= DDPF.FOURCC; dwFourCC = FourCC.DXT3; break; case BitmapFormat.Dxt5: dwFlags2 |= DDPF.FOURCC; dwFourCC = FourCC.DXT5; break; } if (BitmapInfo.Format == BitmapFormat.A8R8G8B8) { dwRGBBitCount = 0x20; dwRBitMask = 0xff0000; dwGBitMask = 0xff00; dwBBitMask = 0xff; dwRGBAlphaBitMask = 0xff000000; } else { dwRGBBitCount = 0; dwRBitMask = 0; dwGBitMask = 0; dwBBitMask = 0; dwRGBAlphaBitMask = 0; } dwCaps1 = 0; dwCaps1 |= DDSCAPS.TEXTURE; dwCaps2 = 0; Reserved2 = new int[2]; dwReserved3 = 0; }
private byte[] ReadPixels(ref DDSURFACEDESC2 ddsd, BinaryReader reader, out int glPixelFormat, out int elementsPerPixel) { // How big will the buffer need to be to load all of the pixel data including mip-maps? int bufferSize; int compressionFactor; PixelFormatConverter converter; CalculateImageSettings( ref ddsd, out compressionFactor, out glPixelFormat, out elementsPerPixel, out converter); DDSCAPS2 ddsCaps = ddsd.ddsCaps; bool isCubeMap = (ddsCaps.dwCaps2 & DDSURFACEDESC2.DDSCAPS2_CUBEMAP) != 0; int mipMapCount = ddsd.HasMipMapCount ? ddsd.dwMipMapCount : 1; byte[] pixels; if (isCubeMap) { // image is a cubemap bufferSize = 0; for (int face = 0; face < 6; face++) { int width = ddsd.dwWidth; int height = ddsd.dwHeight; for (int level = 0; level < mipMapCount; level++) { //calculate the bufferSize we are going to read bufferSize += ((width + 3) >> 2) * ((height + 3) >> 2) * 8; width = width >> 1; if (width < 1) { width = 1; } height = height >> 1; if (height < 1) { height = 1; } } } //read the data into pixels: note that all faces and mipmaps are being read pixels = reader.ReadBytes(bufferSize); } else { // image is not a cubemap if (ddsd.HasPitch) { if (mipMapCount > 1) { throw new NotSupportedException("please request support for DDS textures with pitch specified and more than one mipmap"); } bufferSize = ddsd.lPitch * ddsd.dwHeight; } else if (ddsd.HasLinearSize && ddsd.dwLinearSize > 0 && (mipMapCount == 1 || compressionFactor > 0)) { if (mipMapCount > 1) { bufferSize = ddsd.dwLinearSize * compressionFactor; } else { bufferSize = ddsd.dwLinearSize; } } else { // Read until end of file. DDS files with multiple mipmaps come through here. long cur = reader.BaseStream.Position; long eof = reader.BaseStream.Length; bufferSize = (int)(eof - cur); } pixels = reader.ReadBytes(bufferSize); } pixels = converter(pixels); return(pixels); }
/// <summary> /// /// </summary> /// <returns></returns> public IGraphicsSurface GetBackBufferSurface() { DDSCAPS2 ddsCaps = new DDSCAPS2(); ddsCaps.lCaps = CONST_DDSURFACECAPSFLAGS.DDSCAPS_BACKBUFFER; return new DirectDrawSurface(Surface.GetAttachedSurface(ref ddsCaps)); }
public DDS(HaloDeveloper.Raw.BitmapRaw.BitmapSubmap BitmapInfo) { dwMagic = 0x20534444; // "DDS " dwSize = 0x7C; // Size of DDSURFACEDESC2 struct // Setup the basic flags that we know we will always have dwFlags = 0; dwFlags |= DDSD.CAPS; dwFlags |= DDSD.HEIGHT; dwFlags |= DDSD.WIDTH; dwFlags |= DDSD.PIXELFORMAT; // Set our height and width dwHeight = BitmapInfo.vHeight; dwWidth = BitmapInfo.vWidth; // We will provide a pitch or linear size if (BitmapInfo.Format == TextureFormat.A8R8G8B8) { dwFlags |= DDSD.PITCH; dwPitchOrLinearSize = dwWidth * 4; } else { dwFlags |= DDSD.LINEARSIZE; dwPitchOrLinearSize = BitmapInfo.RawLength; // Size of first mip } dwDepth = 0; // I havent seen this used yet in xtd's // We will provide a mipmap count if theres more then 1 level //if (BitmapInfo.Levels > 1) //{ // dwFlags |= DDSD.MIPMAPCOUNT; // dwMipMapCount = BitmapInfo.Levels; //} //else dwMipMapCount = 0; dwReserved1 = new int[11]; // Reserved dwSize2 = 0x00000020; // Size of DDPIXELFORMAT struct // Fill out our flags and fourcc dwFlags2 = 0; dwFourCC = FourCC.None; switch (BitmapInfo.Format) { case TextureFormat.DXT1: dwFlags2 |= DDPF.FOURCC; dwFourCC = FourCC.DXT1; break; case TextureFormat.DXT3: dwFlags2 |= DDPF.FOURCC; dwFourCC = FourCC.DXT3; break; case TextureFormat.DXT5: dwFlags2 |= DDPF.FOURCC; dwFourCC = FourCC.DXT5; break; case TextureFormat.A8R8G8B8: dwFlags2 |= DDPF.RGB; dwFlags2 |= DDPF.ALPHAPIXELS; break; } // Fill in the rest of the struct if (BitmapInfo.Format == TextureFormat.A8R8G8B8) { dwRGBBitCount = 0x20; dwRBitMask = 0x00ff0000; dwGBitMask = 0x0000ff00; dwBBitMask = 0x000000ff; dwRGBAlphaBitMask = 0xff000000; } else { dwRGBBitCount = 0x00000000; dwRBitMask = 0x00000000; dwGBitMask = 0x00000000; dwBBitMask = 0x00000000; dwRGBAlphaBitMask = 0x00000000; } // Fill in our DDSCAPS2 info dwCaps1 = 0; dwCaps1 |= DDSCAPS.TEXTURE; //if (BitmapInfo.Levels > 1) //{ // dwCaps1 |= DDSCAPS.COMPLEX; // dwCaps1 |= DDSCAPS.MIPMAP; //} dwCaps2 = 0; Reserved2 = new int[2]; dwReserved3 = 0x00000000; }