Open Pranoy1c opened 5 years ago
GPUImageRGBReplaceFilter.h
#import "GPUImageFilter.h"
@interface GPUImageRGBReplaceFilter : GPUImageFilter
@end
GPUImageRGBReplaceFilter.m
#import "GPUImageRGBReplaceFilter.h"
@implementation GPUImageRGBReplaceFilter
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageRGBReplaceFragmentShaderString = SHADER_STRING
(
varying highp vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
void main()
{
lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
if (textureColor.r >= 0.078) textureColor.r = 0.392;
if (textureColor.g >= 0.392) textureColor.g = 0.784;
if (textureColor.b >= 0.157) textureColor.b = 0.000;
gl_FragColor = textureColor;
}
);
#else
NSString *const kGPUImageRGBReplaceFragmentShaderString = SHADER_STRING
(
varying vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
void main()
{
vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
if (textureColor.r >= 0.078) textureColor.r = 0.392;
if (textureColor.g >= 0.392) textureColor.g = 0.784;
if (textureColor.b >= 0.157) textureColor.b = 0.000;
gl_FragColor = textureColor.rgb;
}
);
#endif
#pragma mark -
#pragma mark Initialization and teardown
- (id)init;
{
if (!(self = [super initWithFragmentShaderFromString:kGPUImageRGBReplaceFragmentShaderString]))
{
return nil;
}
return self;
}
@end
Please bear with me as I am pretty new to iOS and GPUImage too. I am trying to figure out how to replace all pixels in an image which have R, G and B values over a certain value with another R,G,B value.
So let's say I need to replace all pixels which have an:
I am able to do this the old school way but it is very slow and I need to do it as fast as possible:
So I came across GPUImage which seems to have VERY good performance. I think I need to use
GPUImageColorMatrixFilter
but I can't seem to understand how exactly thecolorMatrix
are formed.For example, for sepia, I was able to get this to work by looking at examples:
I can't seem to understand the formation of
conversionFilter.colorMatrix
line. Why were those values used in that matrix?How can I get the values for my sort of need where I need to replace threshold values with other values?