imazen / imazen/libwebp-net

Crashes on indexed images.

Open
#18 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
144
Forks
46
PR merge metrics
No merged PRs in 30d

Description

It crashes on indexed images. I believe the issue lies here in Encode(Bitmap b, float quality, out IntPtr result, out long length)
using (Bitmap b2 = b.Clone(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
Encode(b2, quality, out result, out length);
}
I've created a workaround that works nicely which is
if (b.PixelFormat.HasFlag(PixelFormat.Indexed))
{
using (var bitmap = new Bitmap(b.Width, b.Height, PixelFormat.Format32bppArgb))
{
using (var graphics = Graphics.FromImage(bitmap))
{
graphics.DrawImageUnscaled(b, 0, 0, b.Width, b.Height);
}
//this is using the stream to. it would have to be revised to reflect your out params
Encode(bitmap, to, quality);
}
}

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at Encode(Bitmap b, float quality, out IntPtr result, out long length) and reproduce the crash with an indexed Bitmap. Compare that path with the provided Format32bppArgb conversion workaround. Done means indexed images encode without crashing and existing image encoding still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
computer-graphics
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.