For sure. Here is the image I used for tests (Preset Photo, Quality 75).
In the lossless case it stays at 5% nearly
forever.
I created a c# interface. Nothing special...The progress_hook uses a lambda method. The encoding works fine.
var libwebp = new LIBWEBP();
LIBWEBP.WebPPicture frame = new LIBWEBP.WebPPicture();
LIBWEBP.WebPMemoryWriter* memWriter = (LIBWEBP.WebPMemoryWriter*)IntPtr.Zero;
var webp_data = new LIBWEBP.WebPData();
var webp_data_assemble = new LIBWEBP.WebPData();
IntPtr muxer = IntPtr.Zero;
try
{
bool ok;
// Prepare the WebPPicture
ok = libwebp.WebPPictureInit(ref frame);
if (!ok) throw new Exception( "WebPPictureInit: failed");
ok = SetPictureFromBitmap(libwebp, ref frame, webpFrameList.Frames[0].Image);
if (!ok) throw new Exception(WebPEncodingErrorToString(frame.error_code));
Exception EncodeException = null;
frame.progress_hook = new LIBWEBP.Delegates.WebPProgressHook((int percent, ref LIBWEBP.WebPPicture picture) =>
{
try
{
progress.Call(percent);
}
catch (Exception ex)
{
EncodeException = ex;
}
return (EncodeException == null);
});
memWriter = (LIBWEBP.WebPMemoryWriter*)Marshal.AllocHGlobal(sizeof(LIBWEBP.WebPMemoryWriter));
libwebp.WebPMemoryWriterInit(memWriter);
frame.writer = libwebp.WebPMemoryWrite;
frame.custom_ptr = (IntPtr)memWriter;
var config = new LIBWEBP.WebPConfig();
ok = libwebp.WebPConfigPreset(ref config, (LIBWEBP.WebPPreset)webpFrameList.Preset, webpFrameList.Quality);
if (!ok) throw new Exception("WebPConfigPreset: failed");
// Tune 'config' as needed.
config.lossless = webpFrameList.Lossless;
System.Diagnostics.Trace.WriteLine("AWEBP: Save: Encode image");
ok = libwebp.WebPEncode(ref config, ref frame);
if (!ok)
{
if (EncodeException != null) throw EncodeException;
throw new Exception(WebPEncodingErrorToString(frame.error_code));
}
...