Getting message in console: "CreateWrappedSurface() failed for a dataprovider-backed CGImageRef."
Asked Answered
L

1

7

Updated to Xcode 7 and getting this (warning?) message while an image was being rendered in an operation:

CreateWrappedSurface() failed for a dataprovider-backed CGImageRef.

There was no message like this under Xcode 6.4.

Got which code part threw the message:

if (!self.originalImage) // @property (nonatomic, strong) UIImage *originalImage;
        return;

CGImageRef originalCGImage = self.originalImage.CGImage;
NSAssert(originalCGImage, @"Cannot get CGImage from original image");
CIImage *inputCoreImage = [CIImage imageWithCGImage:originalCGImage]; // this results the console message

I replaced my CIIImage creator to get it directly from the UIImage:

CIImage *originalCIImage = self.originalImage.CIImage;
NSAssert(originalCIImage, @"Cannot build CIImage from original image");

In this case I didn't get any console message, but had an assert: originalCIImage was nil.

The class reference of UIImage says:

@property(nonatomic, readonly) CIImage *CIImage

If the UIImage object was initialized using a CGImageRef, the value of the property is nil.

So I'm using the original code as fallback:

CIImage *originalCIImage = self.originalImage.CIImage;
if (!originalCIImage) {
    CGImageRef originalCGImageRef = self.originalImage.CGImage;
    NSAssert(originalCGImageRef, @"Unable to get CGimageRef of originalImage");
    originalCIImage = [CIImage imageWithCGImage:originalCGImageRef];
}
NSAssert(originalCIImage, @"Cannot build CIImage from original image");

The problem is, I'm still getting the warning messages in console.

Has anybody got this message before? What's the solution to nuke that warning(?) message?

Thanks, Adam

Lsd answered 17/9, 2015 at 13:52 Comment(3)
I started getting this (iOS9) when I started running my CIFilters in background threads because they are so slow (and also in an autoReleasePool). Didn't seem to cause any negative effects, just that message itself, but I'm researching for answers still.Ungula
I seem to only get it on simulator too, not on device. HmmmUngula
Just convert your image from RGB to RGBAUngula
U
8

Finally figured out the answer. Curious by the error I studied up on how CIImage works (https://uncorkedstudios.com/blog/image-filters-with-core-graphics)

I noticed that the CGImageRef is dataprovider-backed with premultiplied values (RGB and A)

I thought to myself that the CGImage I am loading into a CIImage (using [CIImage imageWithCGImage:originalCGImage]; is only RGB and not RGBA). Sure enough, I was creating this image by taking a snapshot of a view using the standard UIGraphicsBeginImageContextWithOptions and I had the opaque parameter set to "YES".

I simply changed:

UIGraphicsBeginImageContextWithOptions(bounds, YES, 1.0f);

to

UIGraphicsBeginImageContextWithOptions(bounds, NO, 1.0f);

So that I am now creating a RGBA image, not an RGB image.

Now I convert my CGImage to CIImage and the CIImage NOW has proper dataprovider backing and the error goes away.


NOTE:

I was using a CIClamp filter for gaussian blur purposes, and with opaque set to NO the clamp doesn't work as effectively. I decided to just keep the opaque at YES and ignore the log warnings, they don't seem to actually do anything.)

Ungula answered 21/9, 2015 at 6:11 Comment(2)
Thanks for the advice! Is this the only way to avoid that warning/error message? I mean I'm using CIContext and CIFilter(s) for manipulation and bringing CGContext in this method feels like an overhead a bit.Lsd
@AdamSzabo you can still do all of that, just make sure your CGContext is not opaque but has an alpha channel.Ungula

© 2022 - 2024 — McMap. All rights reserved.