refactor: try decoding into managed memory
This commit is contained in:
parent
b1beba7c33
commit
8720d831ac
|
@ -23,24 +23,24 @@ internal static class WebPHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
width = features.Width;
|
||||
height = features.Height;
|
||||
rgba = new byte[width * height * 4];
|
||||
|
||||
var decoderConfig = default(WebPDecoderConfig);
|
||||
Native.WebPInitDecoderConfig(ref decoderConfig);
|
||||
using var free = new OnDispose(() => Native.WebPFreeDecBuffer(ref decoderConfig.output));
|
||||
decoderConfig.input = features;
|
||||
decoderConfig.output.colorSpace = WebpCspMode.ModeRgba;
|
||||
|
||||
var code = Native.WebPDecode((nint) imagePtr, imageBytes.Length, ref decoderConfig);
|
||||
if (code != Vp8StatusCode.Ok) {
|
||||
Plugin.Log.Warning($"could not decode webp: {Enum.GetName(code)}");
|
||||
return null;
|
||||
decoderConfig.output.isExternalMemory = 1;
|
||||
decoderConfig.output.u.Rgba.size = (nuint) rgba.Length;
|
||||
decoderConfig.output.u.Rgba.stride = height * 4;
|
||||
fixed (byte* rgbaPtr = rgba) {
|
||||
decoderConfig.output.u.Rgba.rgba = (nint) rgbaPtr;
|
||||
var code = Native.WebPDecode((nint) imagePtr, imageBytes.Length, ref decoderConfig);
|
||||
if (code != Vp8StatusCode.Ok) {
|
||||
Plugin.Log.Warning($"could not decode webp: {Enum.GetName(code)}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
height = decoderConfig.output.height;
|
||||
width = decoderConfig.output.width;
|
||||
rgba = MemoryHelper.ReadRaw(
|
||||
decoderConfig.output.private_memory,
|
||||
height * width * 4
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue