Encoding certain images transforms them in an unsupported format

Originator:michaelhochs
Number:rdar://33404326 Date Originated:19-Jul-2017 06:43 PM
Status:Open Resolved:
Product:iOS + SDK Product Version:10.3 + 11b3
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
When creating a monochrome bitmap context with `kCGImageAlphaPremultipliedLast`, generating a UIImage out of that and then encoding and decoding that image with `NSKeyedArchiver` and `NSKeyedUnarchiver`, the resulting image (or rather its backing CGImage) has an alpha info of `kCGImageAlphaLast`.

The problem here is that this is not supported by CoreGraphics when using a monochrome color space. Therefore when trying to create a core graphics context, it will log an error message complaining about this when doing so and no image context will be created.

Steps to Reproduce:
0. Open the attached sample
1. Run the sample
2. Notice both images are drawn on screen without any issue
3. Check the console logs

Expected Results:
The console should state that the original image and the redrawn image both should have an alpha info of 1 before and after archiving & unarchiving.

Actual Results:
The original image has an alpha info of 1 before and after the archiving-unarchiving roundtrip. However the image that has been redrawn before has an alpha info of 1 before archiving and an alpha info of 3 after redrawing.

Furthermore core graphics logs a detailed error about the parameter combination being unsupported. (I added the environment variable for that).

Version:
10.3 + 11b3

Notes:
I also added a shared breakpoint for the cg error log for your convenience which currently is disabled.

I am not really sure if this is a bug or an enhancement request, as I guess technically there is nothing saying that you should only ever get `CGImage`s with parameters that are supported by bitmap contexts, however it at least seems like a bug to me that `UIImage`s are altered when being archived / unarchived.

Comments

Sample Code

https://github.com/PSPDFKit-labs/radar.apple.com/tree/master/33404326%20-%20CoreGraphicsGrayscaleImage

By michaelhochs at July 19, 2017, 4:49 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!