{"record":{"id":"3ffa075db590ac78","repo":"QL-Win/QuickLook","slug":"unsupported-bit-depth-imagetype-bitsperpixel","errorCode":null,"errorMessage":"Unsupported bit depth {imageType.BitsPerPixel}","messagePattern":"Unsupported bit depth (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/IcnsProvider.cs","lineNumber":424,"sourceCode":"            case 4:\n                Decode4BPPImage(imageType, imageData, bitmapData);\n                break;\n\n            case 8:\n                Decode8BPPImage(imageType, imageData, bitmapData);\n                break;\n\n            case 32:\n                if (imageType.Details == IcnsType.TypeDetails.ARGB)\n                    Decode32BPPImageARGB(imageType, imageData, bitmapData);\n                else\n                    Decode32BPPImage(imageType, imageData, bitmapData);\n                break;\n\n            default:\n                image.UnlockBits(bitmapData);\n                image.Dispose();\n                throw new NotSupportedException(\"Unsupported bit depth \" + imageType.BitsPerPixel);\n        }\n\n        if (maskElement != null)\n        {\n            switch (maskType.BitsPerPixel)\n            {\n                case 1:\n                    Apply1BPPMask(maskElement.data, bitmapData);\n                    break;\n\n                case 8:\n                    Apply8BPPMask(maskElement.data, bitmapData);\n                    break;\n\n                default:\n                    image.UnlockBits(bitmapData);\n                    image.Dispose();\n                    throw new NotSupportedException(\"Unsupport mask bit depth \" + maskType.BitsPerPixel);","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/QL-Win/QuickLook/blob/cb5d9c429c81d9796fac469da2a68efb5626946d/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/IcnsProvider.cs#L406-L442","documentation":"Thrown by the ICNS image decoder after dispatching on bit depth: the supported cases are 1, 8, and 32 (plus whatever earlier cases the switch covers). If imageType.BitsPerPixel is anything else, the default arm unlocks the bitmap, disposes it, and throws NotSupportedException. This guards against ICNS type codes whose bit depth this decoder never implemented.","triggerScenarios":"An ICNS entry whose mapped imageType.BitsPerPixel is not in the implemented set (e.g. a 4-bit or compressed/ARGB variant not handled). The switch falls through to default.","commonSituations":"A newer macOS icon format (compressed JPEG-2000/PNG-backed types, or HEIC-based 'ic12'/'ic13' whose decoded depth differs); an ICNS produced by an unusual exporter; misclassification of a depth during type-code resolution.","solutions":["Pre-decode the entry as PNG/JPEG when the ICNS type is one of the compressed types instead of routing through the bit-depth decoder.","Extend the switch to handle the missing depth (e.g. add a 4-bit or depth-from-compressed-image case).","Wrap DecodeAllImages and skip icons whose depth is unsupported, returning the rest.","Re-encode the ICNS with iconutil from PNG sources so all entries are standard depths."],"exampleFix":"// before\ndefault:\n    image.UnlockBits(bitmapData);\n    image.Dispose();\n    throw new NotSupportedException(\"Unsupported bit depth \" + imageType.BitsPerPixel);\n\n// after — fall back to PNG/JPEG decode for compressed types\ndefault:\n    return DecodeCompressedEntry(imageType, imageData);","handlingStrategy":"try-catch","validationCode":"static readonly HashSet<int> SupportedBpp = new(){1,8,32};\nif (!SupportedBpp.Contains(imageType.BitsPerPixel)) { /* route to compressed/PNG decode path or skip */ }","typeGuard":"static bool IsSupportedIcnsDepth(int bpp) => bpp==1 || bpp==8 || bpp==32;","tryCatchPattern":"try { Decode(imageType, data, bd); }\ncatch (NotSupportedException) { /* skip this icon, try next */ }","preventionTips":["Map compressed ICNS type codes to PNG/JPEG decode, not the bit-depth path.","Skip unsupported-depth icons instead of failing the whole file.","Re-encode ICNS from PNG sources with iconutil."],"tags":["icns","macos","icon","bit-depth","decoder"],"backgroundTag":null,"analyzedSha":"cb5d9c429c81d9796fac469da2a68efb5626946d","analyzedAt":"2026-08-13T11:51:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}