diff --git a/examples/Mac/FilterShowcaseSwift/FilterShowcaseSwift.xcodeproj/project.pbxproj b/examples/Mac/FilterShowcaseSwift/FilterShowcaseSwift.xcodeproj/project.pbxproj index 09e483c97..09f107c26 100644 --- a/examples/Mac/FilterShowcaseSwift/FilterShowcaseSwift.xcodeproj/project.pbxproj +++ b/examples/Mac/FilterShowcaseSwift/FilterShowcaseSwift.xcodeproj/project.pbxproj @@ -244,6 +244,7 @@ BC0B246E197DF612009AC707 /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftUpdateCheck = 0700; LastUpgradeCheck = 0600; ORGANIZATIONNAME = "Sunset Lake Software"; TargetAttributes = { diff --git a/examples/iOS/FilterShowcaseSwift/FilterShowcaseSwift/FilterOperations.swift b/examples/iOS/FilterShowcaseSwift/FilterShowcaseSwift/FilterOperations.swift index ecde15cd5..585a183a0 100644 --- a/examples/iOS/FilterShowcaseSwift/FilterShowcaseSwift/FilterOperations.swift +++ b/examples/iOS/FilterShowcaseSwift/FilterShowcaseSwift/FilterOperations.swift @@ -352,6 +352,15 @@ let filterOperations: Array = [ }, filterOperationType:.SingleInput ), + FilterOperation ( + listName:"Solarize", + titleName:"Solarize", + sliderConfiguration:.Enabled(minimumValue:0.0, maximumValue:1.0, initialValue:0.5), + sliderUpdateCallback: {(filter, sliderValue) in + filter.threshold = sliderValue + }, + filterOperationType:.SingleInput + ), FilterOperation ( listName:"Pixellate", titleName:"Pixellate", diff --git a/framework/GPUImage.xcodeproj/project.pbxproj b/framework/GPUImage.xcodeproj/project.pbxproj index 828659af6..52ba2185e 100644 --- a/framework/GPUImage.xcodeproj/project.pbxproj +++ b/framework/GPUImage.xcodeproj/project.pbxproj @@ -37,6 +37,10 @@ 6D13DBE7151AA804000B23BA /* GPUImageHazeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D13DBE5151AA804000B23BA /* GPUImageHazeFilter.m */; }; 6EE27493150E8FC60040DDB6 /* GPUImageGrayscaleFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EE27491150E8FC50040DDB6 /* GPUImageGrayscaleFilter.h */; }; 6EE27494150E8FC60040DDB6 /* GPUImageGrayscaleFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EE27492150E8FC50040DDB6 /* GPUImageGrayscaleFilter.m */; }; + 79F8FD151C8B2A620095AB3E /* GPUImageSolarizeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 79F8FD131C8B2A620095AB3E /* GPUImageSolarizeFilter.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 79F8FD161C8B2A620095AB3E /* GPUImageSolarizeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 79F8FD141C8B2A620095AB3E /* GPUImageSolarizeFilter.m */; settings = {ASSET_TAGS = (); }; }; + 79F8FD171C8B2AA00095AB3E /* GPUImageSolarizeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 79F8FD131C8B2A620095AB3E /* GPUImageSolarizeFilter.h */; settings = {ASSET_TAGS = (); }; }; + 79F8FD181C8B2AA60095AB3E /* GPUImageSolarizeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 79F8FD141C8B2A620095AB3E /* GPUImageSolarizeFilter.m */; settings = {ASSET_TAGS = (); }; }; 83AE9F981540DFE500F7FC13 /* GPUImageSubtractBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 83AE9F961540DFE400F7FC13 /* GPUImageSubtractBlendFilter.h */; }; 83AE9F991540DFE500F7FC13 /* GPUImageSubtractBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 83AE9F971540DFE500F7FC13 /* GPUImageSubtractBlendFilter.m */; }; 83AE9FCD1540E92800F7FC13 /* GPUImageMaskFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 83AE9FCB1540E92800F7FC13 /* GPUImageMaskFilter.h */; }; @@ -735,6 +739,8 @@ 6D13DBE5151AA804000B23BA /* GPUImageHazeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageHazeFilter.m; path = Source/GPUImageHazeFilter.m; sourceTree = SOURCE_ROOT; }; 6EE27491150E8FC50040DDB6 /* GPUImageGrayscaleFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageGrayscaleFilter.h; path = Source/GPUImageGrayscaleFilter.h; sourceTree = SOURCE_ROOT; }; 6EE27492150E8FC50040DDB6 /* GPUImageGrayscaleFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageGrayscaleFilter.m; path = Source/GPUImageGrayscaleFilter.m; sourceTree = SOURCE_ROOT; }; + 79F8FD131C8B2A620095AB3E /* GPUImageSolarizeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageSolarizeFilter.h; path = Source/GPUImageSolarizeFilter.h; sourceTree = SOURCE_ROOT; }; + 79F8FD141C8B2A620095AB3E /* GPUImageSolarizeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageSolarizeFilter.m; path = Source/GPUImageSolarizeFilter.m; sourceTree = SOURCE_ROOT; }; 83AE9F961540DFE400F7FC13 /* GPUImageSubtractBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageSubtractBlendFilter.h; path = Source/GPUImageSubtractBlendFilter.h; sourceTree = SOURCE_ROOT; }; 83AE9F971540DFE500F7FC13 /* GPUImageSubtractBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageSubtractBlendFilter.m; path = Source/GPUImageSubtractBlendFilter.m; sourceTree = SOURCE_ROOT; }; 83AE9FCB1540E92800F7FC13 /* GPUImageMaskFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageMaskFilter.h; path = Source/GPUImageMaskFilter.h; sourceTree = SOURCE_ROOT; }; @@ -1147,6 +1153,8 @@ BCC94ABA151E4FD6008554B4 /* GPUImageLuminanceThresholdFilter.m */, BCC1E5CA151EA6610006EFA5 /* GPUImageAdaptiveThresholdFilter.h */, BCC1E5CB151EA6610006EFA5 /* GPUImageAdaptiveThresholdFilter.m */, + 79F8FD131C8B2A620095AB3E /* GPUImageSolarizeFilter.h */, + 79F8FD141C8B2A620095AB3E /* GPUImageSolarizeFilter.m */, BCB79E7815EC2A8300965D92 /* GPUImageAverageLuminanceThresholdFilter.h */, BCB79E7915EC2A8300965D92 /* GPUImageAverageLuminanceThresholdFilter.m */, BC6ED9C01549CA0600966798 /* GPUImageHistogramFilter.h */, @@ -1567,6 +1575,7 @@ BCD81E8D19440418007133DB /* GPUImageFramebuffer.h in Headers */, BCD81E8F19440425007133DB /* GPUImageOutput.h in Headers */, BCD81E9019440428007133DB /* GPUImageVideoCamera.h in Headers */, + 79F8FD171C8B2AA00095AB3E /* GPUImageSolarizeFilter.h in Headers */, BCD81E911944042B007133DB /* GPUImageStillCamera.h in Headers */, BCD81E921944042E007133DB /* GPUImagePicture.h in Headers */, BCD81E9319440430007133DB /* GPUImageMovie.h in Headers */, @@ -1807,6 +1816,7 @@ BCABED9015263CF20098A93E /* GPUImageStretchDistortionFilter.h in Headers */, BCF3D68B153CC124009A1FE5 /* GPUImageTextureInput.h in Headers */, BCF3D6DD153CFF61009A1FE5 /* GPUImageTiltShiftFilter.h in Headers */, + 79F8FD151C8B2A620095AB3E /* GPUImageSolarizeFilter.h in Headers */, BCF3D70A153DCC9A009A1FE5 /* GPUImage3x3ConvolutionFilter.h in Headers */, BCF3D70F153DF9E7009A1FE5 /* GPUImageEmbossFilter.h in Headers */, BCF3D71D153E06C3009A1FE5 /* GPUImageCannyEdgeDetectionFilter.h in Headers */, @@ -2045,6 +2055,7 @@ BCD81F4B19440604007133DB /* GPUImageRGBFilter.m in Sources */, BCD81F4C19440604007133DB /* GPUImageHSBFilter.m in Sources */, BCD81F4D19440604007133DB /* GPUImageHueFilter.m in Sources */, + 79F8FD181C8B2AA60095AB3E /* GPUImageSolarizeFilter.m in Sources */, BCD81F4E19440604007133DB /* GPUImageMonochromeFilter.m in Sources */, BCD81F4F19440604007133DB /* GPUImageFalseColorFilter.m in Sources */, BCD81F5019440604007133DB /* GPUImageHazeFilter.m in Sources */, @@ -2347,6 +2358,7 @@ 84FFC80C1936408F00994258 /* GPUImagePicture+TextureSubimage.m in Sources */, BCBC604E16C58B0900B11741 /* GPUImageMotionBlurFilter.m in Sources */, BCBC605816C8527C00B11741 /* GPUImageZoomBlurFilter.m in Sources */, + 79F8FD161C8B2A620095AB3E /* GPUImageSolarizeFilter.m in Sources */, BCBF617B16E4F44700E2784A /* GPUImageKuwaharaRadius3Filter.m in Sources */, BC6C55411730679D00EB222D /* GPUImageLaplacianFilter.m in Sources */, BCB030BF173400BC001A1A20 /* GPUImageThreeInputFilter.m in Sources */, diff --git a/framework/GPUImageMac.xcodeproj/project.pbxproj b/framework/GPUImageMac.xcodeproj/project.pbxproj index 831448d92..91b83cffc 100644 --- a/framework/GPUImageMac.xcodeproj/project.pbxproj +++ b/framework/GPUImageMac.xcodeproj/project.pbxproj @@ -11,6 +11,8 @@ 574B5D871BE9346800F4EC5A /* GPUImageMovie.m in Sources */ = {isa = PBXBuildFile; fileRef = 574B5D851BE9346800F4EC5A /* GPUImageMovie.m */; }; 574B5D911BEA3E7900F4EC5A /* GPUImageColorConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 574B5D8F1BEA3E7900F4EC5A /* GPUImageColorConversion.h */; settings = {ATTRIBUTES = (Public, ); }; }; 574B5D921BEA3E7900F4EC5A /* GPUImageColorConversion.m in Sources */ = {isa = PBXBuildFile; fileRef = 574B5D901BEA3E7900F4EC5A /* GPUImageColorConversion.m */; }; + 79840B831C8B29240079A83B /* GPUImageSolarizeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 79840B811C8B29240079A83B /* GPUImageSolarizeFilter.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 79840B841C8B29240079A83B /* GPUImageSolarizeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 79840B821C8B29240079A83B /* GPUImageSolarizeFilter.m */; settings = {ASSET_TAGS = (); }; }; A4741D5A19A92098005EE1A4 /* GPUImageHistogramEqualizationFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A4741D5819A92098005EE1A4 /* GPUImageHistogramEqualizationFilter.h */; }; A4741D5B19A92098005EE1A4 /* GPUImageHistogramEqualizationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = A4741D5919A92098005EE1A4 /* GPUImageHistogramEqualizationFilter.m */; }; A87E5E12177648F3007FD5B1 /* GPUImageRawDataOutput.h in Headers */ = {isa = PBXBuildFile; fileRef = A87E5E10177648F3007FD5B1 /* GPUImageRawDataOutput.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -336,6 +338,8 @@ 574B5D851BE9346800F4EC5A /* GPUImageMovie.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageMovie.m; path = Source/GPUImageMovie.m; sourceTree = SOURCE_ROOT; }; 574B5D8F1BEA3E7900F4EC5A /* GPUImageColorConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageColorConversion.h; path = Source/GPUImageColorConversion.h; sourceTree = SOURCE_ROOT; }; 574B5D901BEA3E7900F4EC5A /* GPUImageColorConversion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageColorConversion.m; path = Source/GPUImageColorConversion.m; sourceTree = SOURCE_ROOT; }; + 79840B811C8B29240079A83B /* GPUImageSolarizeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageSolarizeFilter.h; path = Source/GPUImageSolarizeFilter.h; sourceTree = SOURCE_ROOT; }; + 79840B821C8B29240079A83B /* GPUImageSolarizeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageSolarizeFilter.m; path = Source/GPUImageSolarizeFilter.m; sourceTree = SOURCE_ROOT; }; A4741D5819A92098005EE1A4 /* GPUImageHistogramEqualizationFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageHistogramEqualizationFilter.h; path = Source/GPUImageHistogramEqualizationFilter.h; sourceTree = SOURCE_ROOT; }; A4741D5919A92098005EE1A4 /* GPUImageHistogramEqualizationFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageHistogramEqualizationFilter.m; path = Source/GPUImageHistogramEqualizationFilter.m; sourceTree = SOURCE_ROOT; }; A87E5E10177648F3007FD5B1 /* GPUImageRawDataOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageRawDataOutput.h; path = Source/GPUImageRawDataOutput.h; sourceTree = SOURCE_ROOT; }; @@ -873,6 +877,8 @@ BCC0DF6117359F42007C485F /* GPUImageLuminanceThresholdFilter.m */, BCC0DF5C173596B9007C485F /* GPUImageAverageLuminanceThresholdFilter.h */, BCC0DF5D173596B9007C485F /* GPUImageAverageLuminanceThresholdFilter.m */, + 79840B811C8B29240079A83B /* GPUImageSolarizeFilter.h */, + 79840B821C8B29240079A83B /* GPUImageSolarizeFilter.m */, BCE817A01735FDC60071D084 /* GPUImageHalftoneFilter.h */, BCE817A11735FDC60071D084 /* GPUImageHalftoneFilter.m */, BCE817A21735FDC60071D084 /* GPUImagePixellatePositionFilter.h */, @@ -1191,6 +1197,7 @@ BCF8689D1728862100912E34 /* GPUImageOpacityFilter.h in Headers */, BCF868A11728866400912E34 /* GPUImageAlphaBlendFilter.h in Headers */, BCB009E6172A1BBD00DB804C /* GPUImageGammaFilter.h in Headers */, + 79840B831C8B29240079A83B /* GPUImageSolarizeFilter.h in Headers */, BCB009EA172A1BE800DB804C /* GPUImageToneCurveFilter.h in Headers */, BCB009F0172A23AA00DB804C /* GPUImageHazeFilter.h in Headers */, BCB009F2172A23AA00DB804C /* GPUImageHighlightShadowFilter.h in Headers */, @@ -1357,6 +1364,7 @@ BCF867BA1727791200912E34 /* GPUImageLevelsFilter.m in Sources */, BCF867C01727794000912E34 /* GPUImageMonochromeFilter.m in Sources */, BCF867C21727794000912E34 /* GPUImageRGBFilter.m in Sources */, + 79840B841C8B29240079A83B /* GPUImageSolarizeFilter.m in Sources */, BCF867C81727872D00912E34 /* GPUImagePixellateFilter.m in Sources */, BCF867CC172788F100912E34 /* GPUImage3x3TextureSamplingFilter.m in Sources */, BCF867D0172789B200912E34 /* GPUImageSketchFilter.m in Sources */, diff --git a/framework/Source/GPUImage.h b/framework/Source/GPUImage.h index 1609edf40..3e91c29cd 100755 --- a/framework/Source/GPUImage.h +++ b/framework/Source/GPUImage.h @@ -72,6 +72,7 @@ #import "GPUImagePosterizeFilter.h" #import "GPUImageBoxBlurFilter.h" #import "GPUImageAdaptiveThresholdFilter.h" +#import "GPUImageSolarizeFilter.h" #import "GPUImageUnsharpMaskFilter.h" #import "GPUImageBulgeDistortionFilter.h" #import "GPUImagePinchDistortionFilter.h" diff --git a/framework/Source/GPUImageSolarizeFilter.h b/framework/Source/GPUImageSolarizeFilter.h new file mode 100644 index 000000000..ba01c15a9 --- /dev/null +++ b/framework/Source/GPUImageSolarizeFilter.h @@ -0,0 +1,14 @@ +#import "GPUImageFilter.h" + +/** Pixels with a luminance above the threshold will invert their color + */ +@interface GPUImageSolarizeFilter : GPUImageFilter +{ + GLint thresholdUniform; +} + +/** Anything above this luminance will be inverted, and anything below normal. Ranges from 0.0 to 1.0, with 0.5 as the default + */ +@property(readwrite, nonatomic) CGFloat threshold; + +@end \ No newline at end of file diff --git a/framework/Source/GPUImageSolarizeFilter.m b/framework/Source/GPUImageSolarizeFilter.m new file mode 100644 index 000000000..616cb5b21 --- /dev/null +++ b/framework/Source/GPUImageSolarizeFilter.m @@ -0,0 +1,76 @@ +#import "GPUImageSolarizeFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSolarizeFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform highp float threshold; + + const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + highp float luminance = dot(textureColor.rgb, W); + highp float thresholdResult = step(luminance, threshold); + highp vec3 finalColor = abs(thresholdResult - textureColor.rgb); + + gl_FragColor = vec4(finalColor, textureColor.w); + } +); +#else +NSString *const kGPUImageSolarizeFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float threshold; + + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, W); + float thresholdResult = step(luminance, threshold); + vec3 finalColor = abs(thresholdResult - textureColor.rgb); + + gl_FragColor = vec4(vec3(finalColor), textureColor.w); + } +); +#endif + +@implementation GPUImageSolarizeFilter; + +@synthesize threshold = _threshold; + +#pragma mark - +#pragma mark Initialization + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageSolarizeFragmentShaderString])) + { + return nil; + } + + thresholdUniform = [filterProgram uniformIndex:@"threshold"]; + self.threshold = 0.5; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setThreshold:(CGFloat)newValue; +{ + _threshold = newValue; + + [self setFloat:_threshold forUniform:thresholdUniform program:filterProgram]; +} + + +@end \ No newline at end of file diff --git a/framework/Source/Mac/GPUImage.h b/framework/Source/Mac/GPUImage.h index 0760fc78a..8bc072efb 100755 --- a/framework/Source/Mac/GPUImage.h +++ b/framework/Source/Mac/GPUImage.h @@ -101,6 +101,7 @@ #import #import #import +#import #import #import #import