public static SKImage GetImage(FTexture2DMipMap inp, string pixel_format) { byte[] decoded; SKColorType color; switch (pixel_format) { case "PF_DXT5": decoded = DDSImage.DecompressDXT5(inp.data.data, DDSImage.PixelFormat.DXT5, (uint)inp.size_x, (uint)inp.size_y, (uint)inp.size_z); color = SKColorType.Rgba8888; break; case "PF_DXT1": decoded = DDSImage.DecompressDXT1(inp.data.data, DDSImage.PixelFormat.DXT1, (uint)inp.size_x, (uint)inp.size_y, (uint)inp.size_z); color = SKColorType.Rgba8888; break; case "PF_B8G8R8A8": decoded = inp.data.data; color = SKColorType.Bgra8888; break; case "PF_BC5": decoded = DecodeBC5(inp.data.data, inp.size_x, inp.size_y); color = SKColorType.Rgb888x; break; case "PF_BC4": decoded = DecodeBC4(inp.data.data, inp.size_x, inp.size_y); color = SKColorType.Rgb888x; break; case "PF_G8": decoded = inp.data.data; color = SKColorType.Gray8; break; case "PF_FloatRGBA": decoded = inp.data.data; color = SKColorType.RgbaF16; break; default: throw new IOException("Unknown image type: " + pixel_format); } var info = new SKImageInfo(inp.size_x, inp.size_y, color, SKAlphaType.Unpremul); using (SKBitmap bitmap = new SKBitmap(info)) { unsafe { fixed(byte *p = decoded) { bitmap.SetPixels(new IntPtr(p)); } } return(SKImage.FromBitmap(bitmap)); } }
internal FTexturePlatformData(BinaryReader reader, BinaryReader ubulk, long bulk_offset) { size_x = reader.ReadInt32(); size_y = reader.ReadInt32(); num_slices = reader.ReadInt32(); pixel_format = read_string(reader); first_mip = reader.ReadInt32(); mips = new FTexture2DMipMap[reader.ReadUInt32()]; for (int i = 0; i < mips.Length; i++) { mips[i] = new FTexture2DMipMap(reader, ubulk, bulk_offset); } is_virtual = reader.ReadInt32() == 1; if (is_virtual) { throw new IOException("Texture is virtual, unsupported for now"); } }