Inconsistent filter offset
| Originator: | bmwray0 | ||
| Number: | rdar://14521283 | Date Originated: | 7/23/2013 |
| Status: | Closed | Resolved: | Insufficient information |
| Product: | iOS SDK | Product Version: | 6.1.3 |
| Classification: | UI/Usability | Reproducible: | Rarely |
Summary:
When applying a filter to a blurred screenshot on applicationWillResignActive:, the image produced can be offset from the image that is typically reproduced.
Steps to Reproduce:
Send the app to the background, typically by 4-finger swipe to the side to switch apps. Return to the app to display the image with the filter applied.
Expected Results:
The filter is applied in a consistent manner and the resulting image is not offset.
Actual Results:
In some cases, the filter image is offset from the frame it is drawn in.
Regression:
Notes:
I have attached a sample app in which I was able to reproduce the bug very rarely when building on a device. Included are two screenshots, one showing the standard image, and one showing the offset image. Below is my investigation of the issue in the original app.
Through my investigation, I've narrowed this down to the blurWithRadius: method:
- (UIImage *)blurWithRadius:(NSNumber *)radius
{
/* Blur the image */
CIImage* ciImage = [[CIImage alloc] initWithCGImage:self.CGImage options:nil]; // 2
CIFilter *gaussianFilter = [CIFilter filterWithName:@"CIGaussianBlur"
keysAndValues:kCIInputImageKey, ciImage, @"inputRadius", radius, nil]; // 3
CIImage *blurCIImage = [gaussianFilter valueForKey:kCIOutputImageKey]; // 4
CIContext *context = [CIContext contextWithOptions:nil]; // 1
CGImageRef cgImage = [context createCGImage:blurCIImage fromRect:[ciImage extent]]; // 5
UIImage *resizedBlurImage = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
return resizedBlurImage;
}
The offset is proportional to the radius but is independent of the filter (I was also able to reproduce using the CIBloom filter).
The blurWithRadius: method follows almost exactly the Core Image programming guide example on processing images (https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/CoreImaging/ci_tasks/ci_tasks.html):
CIContext *context = [CIContext contextWithOptions:nil]; // 1
CIImage *image = [CIImage imageWithContentsOfURL:myURL]; // 2
CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"]; // 3
[filter setValue:image forKey:kCIInputImgeKey];
[filter setValue:[NSNumber numberWithFloat:0.8f] forKey:@"InputIntensity"];
CIImage *result = [filter valueForKey:kCIOutputImageKey]; // 4
CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]; // 5
Moving statement 1 to the top of the blurWithRadius: method to exactly mimic the reference does not affect the offset.
The only other apparent difference is in statement 5, where [ciImage extent] is used rather than [blurCIImage extent]. Using the [blurCIImage extent] causes a gap on either side and the image to be shifted down a bit because the difference in the CGRects is:
[ciImage extent] = origin=(x= 0, y= 0) size=(width=1496, height=2048)
[blurCIImage extent] = origin=(x=-24, y=-24) size=(width=1562, height=2114)
// x and y offset by 3*radius, width and height offset by 6*radius after testing with radius=4,8,11
These CGRects are the same as listed above both when the blur screen fits exactly and when it is offset.
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!