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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
width = features.Width;
|
||||||
|
height = features.Height;
|
||||||
|
rgba = new byte[width * height * 4];
|
||||||
|
|
||||||
var decoderConfig = default(WebPDecoderConfig);
|
var decoderConfig = default(WebPDecoderConfig);
|
||||||
Native.WebPInitDecoderConfig(ref decoderConfig);
|
|
||||||
using var free = new OnDispose(() => Native.WebPFreeDecBuffer(ref decoderConfig.output));
|
|
||||||
decoderConfig.input = features;
|
decoderConfig.input = features;
|
||||||
decoderConfig.output.colorSpace = WebpCspMode.ModeRgba;
|
decoderConfig.output.colorSpace = WebpCspMode.ModeRgba;
|
||||||
|
decoderConfig.output.isExternalMemory = 1;
|
||||||
var code = Native.WebPDecode((nint) imagePtr, imageBytes.Length, ref decoderConfig);
|
decoderConfig.output.u.Rgba.size = (nuint) rgba.Length;
|
||||||
if (code != Vp8StatusCode.Ok) {
|
decoderConfig.output.u.Rgba.stride = height * 4;
|
||||||
Plugin.Log.Warning($"could not decode webp: {Enum.GetName(code)}");
|
fixed (byte* rgbaPtr = rgba) {
|
||||||
return null;
|
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