Image drawn to alpha-only bitmap graphics context rendered incorrectly

Originator:PicnicBob
Number:rdar://24368240 Date Originated:27-Jan-2016 10:56 AM
Status:Duplicate of 24208048 (Closed) Resolved:
Product:iOS Product Version:9.3 Beta 2
Classification:2 - Important Reproducible:Yes
 
Summary:
This only seems to affect older simulated devices (iPhone 5 and earlier) running iOS 9.3 beta 2 (not sure about beta 1 and don't have actual old devices to test on).
Newer devices running 9.3b2 and all simulators running iOS 9.2 behave correctly.
This code has been in use for a long time with no problems (since iOS 7).
I create a grayscale kCGImageAlphaOnly bitmap graphics context to be used as an image mask and draw an image with transparency into the context using CGContextDrawImage. On newer devices the graphics context correctly contains the opaque pixels of the image. On older devices the graphcs context sometimes remains empty, and sometimes contains a solid rectangle within the rendered image bounds.
In the following excerpt sample1 is always an empty image and sample2 is sometimes empty and sometimes contains a black rectangle where the image should have been drawn. On newer devices or devices running iOS 9.2, sample2 is always correctly rendered as the alpha channel info of 'image'.

unsigned char *bitmapImageData = calloc(bytesPerRow * scaledImageSize.height, sizeof(unsigned char));  
  CGContextRef imageCtx = CGBitmapContextCreate(bitmapImageData, scaledImageSize.width, scaledImageSize.height, bitsPerComponent, bytesPerRow, NULL, (CGBitmapInfo)kCGImageAlphaOnly);  
  UIImage *sample1 = [UIImage imageWithCGImage:CGBitmapContextCreateImage(imageCtx)];  
  CGContextDrawImage(imageCtx, CGRectMake(outerStroke, outerStroke, scaledImageSize.width-outerStroke*2, scaledImageSize.height-outerStroke*2), image.CGImage);  
  UIImage *sample2 = [UIImage imageWithCGImage:CGBitmapContextCreateImage(imageCtx)];

Steps to Reproduce:
Create a grayscale alpha-only bitmap graphics context on an older device
Draw an image with transparency to the context

Expected Results:
The alpha channel should be drawn to the bitmap context

Actual Results:
On newer devices (iPhone 5S and later) the expected behavior is seen.
On older devices either an opaque rectangle is drawn or nothing is drawn.

Version:
iOS 9.3 beta 2

Notes:


Configuration:
iPhone 5 simulator, iPhone 4S simulator, iPad 2 simulator

Comments


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!