private static SurfaceInfo GetSurfaceInfo(uint width, uint height, DdsImageFormat format, DdsHeader header) { uint rowBytes = 0; switch (format) { case DdsImageFormat.Rg8SNorm: rowBytes = (width * 16 + 7) / 8; // round up to nearest byte break; case DdsImageFormat.Rgba8: rowBytes = width * (header.PixelFormat.RgbBitCount / 8); break; case DdsImageFormat.Rgba16Float: rowBytes = width * 8; break; } if (rowBytes > 0) { return(new SurfaceInfo { RowBytes = rowBytes, NumRows = height, NumBytes = rowBytes * height }); } uint blockSize; switch (format) { case DdsImageFormat.Bc1: blockSize = 8; break; case DdsImageFormat.Bc2: case DdsImageFormat.Bc3: blockSize = 16; break; default: throw new ArgumentOutOfRangeException(); } var numBlocksWide = width / 4; var numBlocksHigh = height / 4; return(new SurfaceInfo { RowBytes = numBlocksWide * blockSize, NumRows = numBlocksHigh, NumBytes = numBlocksWide * blockSize * numBlocksHigh }); }
private static SurfaceInfo GetSurfaceInfo(uint width, uint height, DdsImageFormat format) { if (format == DdsImageFormat.Rg8SNorm) { var rowBytes = (width * 16 + 7) / 8; // round up to nearest byte return(new SurfaceInfo { RowBytes = rowBytes, NumRows = height, NumBytes = rowBytes * height }); } uint blockSize; switch (format) { case DdsImageFormat.Bc1: blockSize = 8; break; case DdsImageFormat.Bc2: case DdsImageFormat.Bc3: blockSize = 16; break; default: throw new ArgumentOutOfRangeException(); } var numBlocksWide = 0u; if (width > 0) { numBlocksWide = Math.Max(1, (width + 3) / 4); } var numBlocksHigh = 0u; if (height > 0) { numBlocksHigh = Math.Max(1, (height + 3) / 4); } return(new SurfaceInfo { RowBytes = numBlocksWide * blockSize, NumRows = numBlocksHigh, NumBytes = numBlocksWide * blockSize * numBlocksHigh }); }
private static PixelFormat ToPixelFormat(DdsImageFormat imageFormat) { switch (imageFormat) { case DdsImageFormat.Bc1: return(PixelFormat.Bc1); case DdsImageFormat.Bc2: return(PixelFormat.Bc2); case DdsImageFormat.Bc3: return(PixelFormat.Bc3); default: throw new ArgumentOutOfRangeException(nameof(imageFormat)); } }
private static SurfaceInfo GetSurfaceInfo(uint width, uint height, DdsImageFormat format) { uint blockSize; switch (format) { case DdsImageFormat.Bc1: blockSize = 8; break; case DdsImageFormat.Bc2: case DdsImageFormat.Bc3: blockSize = 16; break; default: throw new ArgumentOutOfRangeException(); } var numBlocksWide = 0u; if (width > 0) { numBlocksWide = Math.Max(1, (width + 3) / 4); } var numBlocksHigh = 0u; if (height > 0) { numBlocksHigh = Math.Max(1, (height + 3) / 4); } return(new SurfaceInfo { RowBytes = numBlocksWide * blockSize, NumRows = numBlocksHigh, NumBytes = numBlocksWide * blockSize * numBlocksHigh }); }