private static unsafe byte[] DecompressFloat(DDSStruct header, byte[] data, DDSPixelFormat pixelFormat) { // allocate bitmap int bpp = (int)(DDSHelper.PixelFormatToBpp(pixelFormat, header.pixelformat.rgbbitcount)); int bps = (int)(header.width * bpp * DDSHelper.PixelFormatToBpc(pixelFormat)); int sizeofplane = (int)(bps * header.height); int width = (int)header.width; int height = (int)header.height; int depth = (int)header.depth; byte[] rawData = new byte[depth * sizeofplane + height * bps + width * bpp]; int size = 0; fixed(byte *bytePtr = data) { byte *temp = bytePtr; fixed(byte *destPtr = rawData) { byte *destData = destPtr; switch (pixelFormat) { case DDSPixelFormat.R32F: // Red float, green = blue = max size = width * height * depth * 3; for (int i = 0, j = 0; i < size; i += 3, j++) { ((float *)destData)[i] = ((float *)temp)[j]; ((float *)destData)[i + 1] = 1.0f; ((float *)destData)[i + 2] = 1.0f; } break; case DDSPixelFormat.A32B32G32R32F: // Direct copy of float RGBA data Array.Copy(data, rawData, data.Length); break; case DDSPixelFormat.G32R32F: // Red float, green float, blue = max size = width * height * depth * 3; for (int i = 0, j = 0; i < size; i += 3, j += 2) { ((float *)destData)[i] = ((float *)temp)[j]; ((float *)destData)[i + 1] = ((float *)temp)[j + 1]; ((float *)destData)[i + 2] = 1.0f; } break; case DDSPixelFormat.R16F: // Red float, green = blue = max size = width * height * depth * bpp; DDSHelper.ConvR16ToFloat32((uint *)destData, (ushort *)temp, (uint)size); break; case DDSPixelFormat.A16B16G16R16F: // Just convert from half to float. size = width * height * depth * bpp; DDSHelper.ConvFloat16ToFloat32((uint *)destData, (ushort *)temp, (uint)size); break; case DDSPixelFormat.G16R16F: // Convert from half to float, set blue = max. size = width * height * depth * bpp; DDSHelper.ConvG16R16ToFloat32((uint *)destData, (ushort *)temp, (uint)size); break; default: break; } } } return(rawData); }