QL-Win/QuickLook · error · NotSupportedException

Unsupported PixelFormat: {pixelFormat}

Error message

Unsupported PixelFormat: {pixelFormat}

What it means

Identical logic to CursorProvider.ToWriteableBitmap but applied to WebP-decoded bitmaps: if the decoded System.Drawing.Bitmap is not Format32bppArgb or Format24bppRgb, the switch throws NotSupportedException. WebP images can decode to other pixel layouts (e.g. Format8bppIndexed for palette WebP, or RGB without alpha), none of which this copy path supports.

Source

Thrown at QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/WebPProvider.cs:157

        return writeableBitmap;
    }
}

file static class Extension
{
    public static WriteableBitmap ToWriteableBitmap(this Bitmap bitmap)
    {
        if (bitmap == null) throw new ArgumentNullException(nameof(bitmap));

        var pixelFormat = bitmap.PixelFormat;
        var width = bitmap.Width;
        var height = bitmap.Height;

        var wpfPixelFormat = pixelFormat switch
        {
            System.Drawing.Imaging.PixelFormat.Format32bppArgb => PixelFormats.Bgra32,
            System.Drawing.Imaging.PixelFormat.Format24bppRgb => PixelFormats.Bgr24,
            _ => throw new NotSupportedException($"Unsupported PixelFormat: {pixelFormat}")
        };

        var writeableBitmap = new WriteableBitmap(width, height, 96, 96, wpfPixelFormat, null);

        var bitmapData = bitmap.LockBits(
            new Rectangle(0, 0, width, height),
            ImageLockMode.ReadOnly,
            pixelFormat);

        try
        {
            writeableBitmap.Lock();
            unsafe
            {
                Buffer.MemoryCopy(
                    source: bitmapData.Scan0.ToPointer(),
                    destination: writeableBitmap.BackBuffer.ToPointer(),
                    destinationSizeInBytes: writeableBitmap.BackBufferStride * height,

View on GitHub (pinned to cb5d9c429c)

Solutions

  1. Normalize the decoded bitmap to Format32bppArgb before conversion: bitmap.Clone(rect, PixelFormat.Format32bppArgb).
  2. Configure the WebP decoder to always emit 32bpp ARGB output.
  3. Extend the switch to handle the missing format with an explicit color-copy path.
  4. Skip unsupported frames and continue with the next frame in an animation.

Example fix

// before
_ => throw new NotSupportedException($"Unsupported PixelFormat: {pixelFormat}")

// after — normalize then continue
if (pixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb
 && pixelFormat != System.Drawing.Imaging.PixelFormat.Format24bppRgb)
    bitmap = bitmap.Clone(new Rectangle(0,0,bitmap.Width,bitmap.Height),
                          System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Defensive patterns

Strategy: validation

Validate before calling

if (bitmap.PixelFormat is not (System.Drawing.Imaging.PixelFormat.Format32bppArgb or System.Drawing.Imaging.PixelFormat.Format24bppRgb))
    bitmap = bitmap.Clone(new Rectangle(0,0,bitmap.Width,bitmap.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb);

Type guard

static bool IsSupportedWebpFormat(System.Drawing.Bitmap b) => b.PixelFormat is System.Drawing.Imaging.PixelFormat.Format32bppArgb or System.Drawing.Imaging.PixelFormat.Format24bppRgb;

Try / catch

try { wb = bitmap.ToWriteableBitmap(); }
catch (NotSupportedException) { wb = NormalizeTo32bpp(bitmap).ToWriteableBitmap(); }

Prevention

When it happens

Trigger: A WebP decoder returns a Bitmap whose PixelFormat is outside {Format32bppArgb, Format24bppRgb} (common for lossless palette-based WebP or 16-bit variants), hitting the '_' arm.

Common situations: Palette/indexed WebP (lossless with small color count); a WebP decoder that returns the native pixel format rather than normalizing to 32bpp; animated WebP frames with non-standard layouts.

Related errors


AI-assisted analysis of QL-Win/QuickLook@cb5d9c429c (2026-08-13). Data as JSON: /api/errors/0c09b060a29cd3bf. Report an issue: GitHub.