{"record":{"id":"0c09b060a29cd3bf","repo":"QL-Win/QuickLook","slug":"unsupported-pixelformat-pixelformat-0c09b0","errorCode":null,"errorMessage":"Unsupported PixelFormat: {pixelFormat}","messagePattern":"Unsupported PixelFormat: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/WebPProvider.cs","lineNumber":157,"sourceCode":"        return writeableBitmap;\n    }\n}\n\nfile static class Extension\n{\n    public static WriteableBitmap ToWriteableBitmap(this Bitmap bitmap)\n    {\n        if (bitmap == null) throw new ArgumentNullException(nameof(bitmap));\n\n        var pixelFormat = bitmap.PixelFormat;\n        var width = bitmap.Width;\n        var height = bitmap.Height;\n\n        var wpfPixelFormat = pixelFormat switch\n        {\n            System.Drawing.Imaging.PixelFormat.Format32bppArgb => PixelFormats.Bgra32,\n            System.Drawing.Imaging.PixelFormat.Format24bppRgb => PixelFormats.Bgr24,\n            _ => throw new NotSupportedException($\"Unsupported PixelFormat: {pixelFormat}\")\n        };\n\n        var writeableBitmap = new WriteableBitmap(width, height, 96, 96, wpfPixelFormat, null);\n\n        var bitmapData = bitmap.LockBits(\n            new Rectangle(0, 0, width, height),\n            ImageLockMode.ReadOnly,\n            pixelFormat);\n\n        try\n        {\n            writeableBitmap.Lock();\n            unsafe\n            {\n                Buffer.MemoryCopy(\n                    source: bitmapData.Scan0.ToPointer(),\n                    destination: writeableBitmap.BackBuffer.ToPointer(),\n                    destinationSizeInBytes: writeableBitmap.BackBufferStride * height,","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/QL-Win/QuickLook/blob/cb5d9c429c81d9796fac469da2a68efb5626946d/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/WebPProvider.cs#L139-L175","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Normalize the decoded bitmap to Format32bppArgb before conversion: bitmap.Clone(rect, PixelFormat.Format32bppArgb).","Configure the WebP decoder to always emit 32bpp ARGB output.","Extend the switch to handle the missing format with an explicit color-copy path.","Skip unsupported frames and continue with the next frame in an animation."],"exampleFix":"// before\n_ => throw new NotSupportedException($\"Unsupported PixelFormat: {pixelFormat}\")\n\n// after — normalize then continue\nif (pixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb\n && pixelFormat != System.Drawing.Imaging.PixelFormat.Format24bppRgb)\n    bitmap = bitmap.Clone(new Rectangle(0,0,bitmap.Width,bitmap.Height),\n                          System.Drawing.Imaging.PixelFormat.Format32bppArgb);","handlingStrategy":"validation","validationCode":"if (bitmap.PixelFormat is not (System.Drawing.Imaging.PixelFormat.Format32bppArgb or System.Drawing.Imaging.PixelFormat.Format24bppRgb))\n    bitmap = bitmap.Clone(new Rectangle(0,0,bitmap.Width,bitmap.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb);","typeGuard":"static bool IsSupportedWebpFormat(System.Drawing.Bitmap b) => b.PixelFormat is System.Drawing.Imaging.PixelFormat.Format32bppArgb or System.Drawing.Imaging.PixelFormat.Format24bppRgb;","tryCatchPattern":"try { wb = bitmap.ToWriteableBitmap(); }\ncatch (NotSupportedException) { wb = NormalizeTo32bpp(bitmap).ToWriteableBitmap(); }","preventionTips":["Configure the WebP decoder to emit 32bppArgb output.","Normalize palette/lossless WebP to 32bpp before WPF copy.","Extend the switch for additional formats when needed."],"tags":["webp","image","gdiplus","wpf","pixel-format"],"backgroundTag":null,"analyzedSha":"cb5d9c429c81d9796fac469da2a68efb5626946d","analyzedAt":"2026-08-13T11:51:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}