yackle / CLImageEditor

MIT License
2.21k stars 573 forks source link

GPUImage Support? #18

Closed ChristopherDoherty closed 10 years ago

ChristopherDoherty commented 10 years ago

Hello,

Has anyone got any idea how to implement GPUImage [https://github.com/BradLarson/GPUImage] as an Optional ImageTool for more advanced image filters and manipulations. I've been trying for the last week to implement this feature, to little success.

Any response is greatly appreciated.

Christopher

yackle commented 10 years ago

Hi.

What are you trying to do and what problem are you getting there?

ChristopherDoherty commented 10 years ago

I am trying to replace the CLFilters with my more advanced and extensive GPUImage, and since the CLFilterBase is made around CLFilters, I am unsure how to implement GPUImage filters, as in, how to replace the CLDefaultVignetteFilter with the GPUImageVignetteFilter, for example. Do you think a Switch case statement could be a suitable replacement for NSDictionary for my custom class? I don't have to much time to check as i'm busy at school at the moment.

Regards, Christopher

yackle commented 10 years ago

Currently, It's difficult to replace existing filters with new filters. But you can add it easily as additional filters. In order to do this, you must create a subclass of CLFilterBase.

Here is a simple example with GPUImage. If GPUImage was installed, by creating these files, CLGPUImageVignetteFilter becomes effective in the filter menu.

CLGPUImageVignetteFilter.h

#if __has_include("GPUImage.h")

#import "CLFilterBase.h"

@interface CLGPUImageVignetteFilter : CLFilterBase

@end

#endif

CLGPUImageVignetteFilter.m

#if __has_include("GPUImage.h")

#import "CLGPUImageVignetteFilter.h"

#import "GPUImage.h"

@implementation CLGPUImageVignetteFilter

+ (CGFloat)defaultDockedNumber
{
    return 2.5;
}

+ (NSString*)defaultTitle
{
    return NSLocalizedStringWithDefaultValue(@"CLGPUImageVignetteFilter_DefaultTitle", nil, [CLImageEditorTheme bundle], @"Vignette2", @"");
}

+ (BOOL)isAvailable
{
    return ([UIDevice iosVersion] >= 5);
}

#pragma mark-

+ (UIImage*)applyFilter:(UIImage*)image
{
    GPUImagePicture *imageSource = [[GPUImagePicture alloc] initWithImage:image];
    GPUImageVignetteFilter *filter = [[GPUImageVignetteFilter alloc] init];

    [imageSource addTarget:filter];
    [imageSource processImage];

    return [filter imageFromCurrentlyProcessedOutput];
}

@end

#endif
ChristopherDoherty commented 10 years ago

Wow, I was not expecting to get home to this! Thank you very much! You are a fantastic help.

yackle commented 10 years ago

:thumbsup:

sohilmultani commented 4 years ago

Hello i am adding GPUImage in my project but i can't add "CLGPUImageVignetteFilter" .

I am adding this code

import "CLFilterBase.h"

}

@interface CLGPUImageVignetteFilter : CLDefaultEmptyFilter @end @implementation CLGPUImageVignetteFilter @end

the output image is nill.

Can you explain step by step please how to add "CLGPUImageVignetteFilter"

Thank you.