“Performing a costly unpadding operation!” — what is it, and how to fix it?

℡╲_俬逩灬. 提交于 2019-12-10 05:21:20

问题


The debug console for my Core Filters test application is showing this message:

CGImageRef 0x7a0e890 has row byte padding. Performing a costly unpadding operation!

I couldn't find a hit for that exact message (minus the pointer info) in the headers or in a Google search.

My questions are (1)what does that mean and (2)how can I rectify the situation?

The following is an example of how I am generating a filtered UIImage using a CIFilter.

- (UIImage*)sepia
{    
    CIImage *beginImage = [CIImage imageWithCGImage:[self CGImage]];
    CIContext *context = [CIContext contextWithOptions:nil];

    CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone" 
                                  keysAndValues: kCIInputImageKey, beginImage, 
                        @"inputIntensity", [NSNumber numberWithFloat:0.8], nil];
    CIImage *outputImage = [filter outputImage];

    CGImageRef cgimg = 
    [context createCGImage:outputImage fromRect:[outputImage extent]];
    UIImage *newImg = [UIImage imageWithCGImage:cgimg];

    self = newImg;

    CGImageRelease(cgimg);
    return self;
}

回答1:


Byte padding is extra bytes added to the end of each image row to ensure that each row starts on a 2^n byte multiple in memory. This increases memory access performance at the expense of image size. You can check this if you compare the result of CGImageGetBytesPerRow and the expected bytes per row calculated from the image dimensions and bytes per pixel.

As to how to rectify the unpadding - you need to find exactly which operation is triggering the unpadding and take it from there. Unpadding is expensive because basically the whole image memory needs to be shuffled up to remove all the end-of-row gaps.




回答2:


I would write a comment, but since I cannot do this due to the low reputation I've got, I'll post it as an answer here:

I just had the same error and tried to fix it by using Thuggish Nuggets' suggestion. Turned out it's the right approach, however the image size has to be a multitude of 8. I just aligned the width to the multitude of 8, I don't know if the height also has to be a multitude of 8 since the image I tested this approach with was quadratic anyways.

Here's the (probably not very efficient) algorithm to give you a basic idea on how to calculate the needed size:

UIImage *image = ...;
CGSize targetSize = image.frame.size; //e.g. 51 x 51
double aspectRatio = targetSize.width / targetSize.height;
targetSize.width = targetSize.width + 8 - ((int)targetSize.width % 8);
targetSize.height = targetSize.width / aspectRatio;



回答3:


I suspect the "costly unpadding operation" to be bogus. Reason: I get it on the Simulator but not on the device. Hence I believe it is a misleading artifact of the Simulator environment.



来源:https://stackoverflow.com/questions/8172838/performing-a-costly-unpadding-operation-what-is-it-and-how-to-fix-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!