{"record":{"id":"4fe4492a168cbcc8","repo":"QL-Win/QuickLook","slug":"unsupport-mask-bit-depth-masktype-bitsperpixel","errorCode":null,"errorMessage":"Unsupport mask bit depth {maskType.BitsPerPixel}","messagePattern":"Unsupport mask bit depth (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/IcnsProvider.cs","lineNumber":442,"sourceCode":"                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);\n            }\n        }\n\n        image.UnlockBits(bitmapData);\n        return new IcnsImage(image, imageType);\n    }\n\n    public static IcnsImage[] DecodeAllImages(IcnsImageParser.IcnsElement[] icnsElements)\n    {\n        List<IcnsImage> result = [];\n\n        for (int i = 0; i < icnsElements.Length; i++)\n        {\n            IcnsImage image = DecodeImage(icnsElements[i], icnsElements);\n            if (image != null)\n                result.Add(image);\n        }\n        return [.. result];","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/QL-Win/QuickLook/blob/cb5d9c429c81d9796fac469da2a68efb5626946d/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/IcnsProvider.cs#L424-L460","documentation":"Thrown after the image is decoded when a separate mask element exists but its bit depth is neither 1 nor 8. The mask switch covers only 1BPP (Apply1BPPMask) and 8BPP (Apply8BPPMask); any other maskType.BitsPerPixel hits the default arm, which unlocks and disposes the image then throws NotSupportedException. Note the message typo 'Unsupport'.","triggerScenarios":"An ICNS whose mask element has a BitsPerPixel value other than 1 or 8 (e.g. a mask mis-typed as 32 or an unsupported compressed mask), so maskType.BitsPerPixel is not 1 and not 8.","commonSituations":"An ICNS with an alpha mask encoded in an unexpected depth; type-code mapping that assigns the wrong depth to the mask element; an exporter that wrote a non-standard mask channel.","solutions":["Re-export the ICNS so masks are standard 1-bit or 8-bit alpha (iconutil from PNG produces 8-bit alpha).","Treat the image's own alpha channel as authoritative and ignore the external mask element when its depth is unsupported.","Extend the mask switch with the missing depth (e.g. downscale a 32-bit mask to 8-bit before Apply8BPPMask).","Catch NotSupportedException during decoding and skip the mask application, keeping the unmasked image."],"exampleFix":"// before\ndefault:\n    image.UnlockBits(bitmapData);\n    image.Dispose();\n    throw new NotSupportedException(\"Unsupport mask bit depth \" + maskType.BitsPerPixel);\n\n// after — ignore non-standard mask instead of discarding the image\ndefault:\n    break; // keep decoded image, skip mask","handlingStrategy":"try-catch","validationCode":"if (maskElement != null && maskType.BitsPerPixel != 1 && maskType.BitsPerPixel != 8) {\n    maskElement = null; // rely on image alpha, ignore external mask\n}","typeGuard":"static bool IsSupportedMaskDepth(int bpp) => bpp==1 || bpp==8;","tryCatchPattern":"try { /* apply mask */ }\ncatch (NotSupportedException) { /* keep image without external mask */ }","preventionTips":["Prefer the image's own alpha channel; ignore non-standard external masks.","Re-export ICNS so masks are 1-bit or 8-bit alpha.","Extend the mask switch when a new mask depth is needed."],"tags":["icns","macos","icon","mask","bit-depth"],"backgroundTag":null,"analyzedSha":"cb5d9c429c81d9796fac469da2a68efb5626946d","analyzedAt":"2026-08-13T11:51:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}