Exemplo n.º 1
0
        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));
            }
        }