GPUImage在过滤器链中与self混合

时间:2014-01-26 14:13:08

标签: iphone gpuimage

我正在尝试创建一个过滤器链,其中一步获取输出并将其与自身混合。当我尝试这样做时,我收到错误“不完整的过滤器FBO:36054”。我需要做些什么才能使这个混合使用前两个输入的输出?

+ (UIImage *)filter:(UIImage*)image {

    GPUImagePicture *picture = [[GPUImagePicture alloc] initWithImage:image];

    // SETUP FILTERS
    GPUImageBilateralFilter *bilateralFilter = [[GPUImageBilateralFilter alloc] init];
    bilateralFilter.texelSpacingMultiplier = 2;
    bilateralFilter.distanceNormalizationFactor = 10;

    GPUImageSoftLightBlendFilter *softLightBlend = [[GPUImageSoftLightBlendFilter alloc] init];

    GPUImageNormalBlendWithAlphaFilter *masterBlend = [[GPUImageNormalBlendWithAlphaFilter alloc] init];
    masterBlend.alpha = 0;

    // SETUP PIPELINE
    [picture addTarget:bilateralFilter];
    [bilateralFilter addTarget:softLightBlend];
#if true
    [bilateralFilter addTarget:softLightBlend]; // doesn't work
#else
    [picture addTarget:softLightBlend]; // works
#endif

    [softLightBlend addTarget:masterBlend];
    [picture addTarget:masterBlend];

    // PROCESS PIPELINE
    [picture processImage];

    UIImage *result = [masterBlend imageFromCurrentlyProcessedOutputWithOrientation:UIImageOrientationUp];
    return result;
}

这个更简单的版本也会导致同样的错误:

+ (UIImage *)test:(UIImage*)image {

    GPUImagePicture *picture = [[GPUImagePicture alloc] initWithImage:image];

    // SETUP FILTERS
    GPUImageSoftLightBlendFilter *softlightBlend = [[GPUImageSoftLightBlendFilter alloc] init];

    GPUImageNormalBlendWithAlphaFilter *masterBlend = [[GPUImageNormalBlendWithAlphaFilter alloc] init];
    masterBlend.alpha = .5;

    // SETUP PIPELINE
    [picture addTarget:softlightBlend];
    [picture addTarget:softlightBlend];

    [softlightBlend addTarget:masterBlend];
    [picture addTarget:masterBlend];

    // PROCESS PIPELINE
    [picture processImage];

    UIImage *result = [masterBlend imageFromCurrentlyProcessedOutputWithOrientation:UIImageOrientationUp];
    return result;
}

1 个答案:

答案 0 :(得分:0)

我不确定是否有更好的方法......但我要做的是从相同的 UIImage创建两个不同的GPUImagePicture对象......然后将它们混合在一起。

如果您需要将过滤器的输出与其自身混合,这也意味着什么...您实际上必须运行该过程直到该点并获得带有imageFromCurrentlyProcessedOutputWithOrientation的UIImage ...然后继续... for例如,像这样:

[picture addTarget:surfaceBlur];
[picture processImage];

UIImage *surfaceBlurResult = [surfaceBlur imageFromCurrentlyProcessedOutputWithOrientation:UIImageOrientationUp];

GPUImagePicture *picture3 = [[GPUImagePicture alloc] initWithImage:surfaceBlurResult];
GPUImagePicture *picture4 = [[GPUImagePicture alloc] initWithImage:surfaceBlurResult];

// picture3 & picture4 are the same image (the result of surfaceBlur)
[picture3 addTarget:softlightBlendWithSelf];
[picture4 addTarget:softlightBlendWithSelf];

[picture3 processImage];
[picture4 processImage];