Skip to content

Commit

Permalink
Added a three-input filter type, fixed scaling issues with the Lanczo…
Browse files Browse the repository at this point in the history
…s resampling, and started adding multiple AV camera support to the Mac.
  • Loading branch information
BradLarson committed May 3, 2013
1 parent c4795d0 commit d5c1ddc
Show file tree
Hide file tree
Showing 12 changed files with 563 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ - (void)windowDidLoad
{
[super windowDidLoad];

inputCamera = [[GPUImageAVCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionUnspecified];
inputCamera = [[GPUImageAVCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraDevice:nil];
inputCamera.runBenchmark = YES;

currentlySelectedRow = 1;
Expand Down
8 changes: 8 additions & 0 deletions framework/GPUImage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@
BCAD4D1D1571B410001E50E1 /* GPUImageDirectionalNonMaximumSuppressionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCAD4D1B1571B410001E50E1 /* GPUImageDirectionalNonMaximumSuppressionFilter.m */; };
BCAD4D201571CB50001E50E1 /* GPUImageWeakPixelInclusionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCAD4D1E1571CB48001E50E1 /* GPUImageWeakPixelInclusionFilter.h */; settings = {ATTRIBUTES = (); }; };
BCAD4D211571CB50001E50E1 /* GPUImageWeakPixelInclusionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCAD4D1F1571CB4C001E50E1 /* GPUImageWeakPixelInclusionFilter.m */; };
BCB030BE173400BC001A1A20 /* GPUImageThreeInputFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB030BC173400BC001A1A20 /* GPUImageThreeInputFilter.h */; };
BCB030BF173400BC001A1A20 /* GPUImageThreeInputFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCB030BD173400BC001A1A20 /* GPUImageThreeInputFilter.m */; };
BCB3B46515F2BA9300EDA3BE /* GPUImageLowPassFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB3B46315F2BA9300EDA3BE /* GPUImageLowPassFilter.h */; settings = {ATTRIBUTES = (); }; };
BCB3B46615F2BA9300EDA3BE /* GPUImageLowPassFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCB3B46415F2BA9300EDA3BE /* GPUImageLowPassFilter.m */; };
BCB3B46A15F2FD1B00EDA3BE /* GPUImageHighPassFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB3B46815F2FD1B00EDA3BE /* GPUImageHighPassFilter.h */; settings = {ATTRIBUTES = (); }; };
Expand Down Expand Up @@ -538,6 +540,8 @@
BCAD4D1B1571B410001E50E1 /* GPUImageDirectionalNonMaximumSuppressionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageDirectionalNonMaximumSuppressionFilter.m; path = Source/GPUImageDirectionalNonMaximumSuppressionFilter.m; sourceTree = SOURCE_ROOT; };
BCAD4D1E1571CB48001E50E1 /* GPUImageWeakPixelInclusionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageWeakPixelInclusionFilter.h; path = Source/GPUImageWeakPixelInclusionFilter.h; sourceTree = SOURCE_ROOT; };
BCAD4D1F1571CB4C001E50E1 /* GPUImageWeakPixelInclusionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageWeakPixelInclusionFilter.m; path = Source/GPUImageWeakPixelInclusionFilter.m; sourceTree = SOURCE_ROOT; };
BCB030BC173400BC001A1A20 /* GPUImageThreeInputFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageThreeInputFilter.h; path = Source/GPUImageThreeInputFilter.h; sourceTree = SOURCE_ROOT; };
BCB030BD173400BC001A1A20 /* GPUImageThreeInputFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageThreeInputFilter.m; path = Source/GPUImageThreeInputFilter.m; sourceTree = SOURCE_ROOT; };
BCB3B46315F2BA9300EDA3BE /* GPUImageLowPassFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageLowPassFilter.h; path = Source/GPUImageLowPassFilter.h; sourceTree = SOURCE_ROOT; };
BCB3B46415F2BA9300EDA3BE /* GPUImageLowPassFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageLowPassFilter.m; path = Source/GPUImageLowPassFilter.m; sourceTree = SOURCE_ROOT; };
BCB3B46815F2FD1B00EDA3BE /* GPUImageHighPassFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageHighPassFilter.h; path = Source/GPUImageHighPassFilter.h; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -922,6 +926,8 @@
BC245DC914DDBED7009FE7EB /* GPUImageFilter.m */,
BC114896155AF65400F107AF /* GPUImageTwoInputFilter.h */,
BC114897155AF65400F107AF /* GPUImageTwoInputFilter.m */,
BCB030BC173400BC001A1A20 /* GPUImageThreeInputFilter.h */,
BCB030BD173400BC001A1A20 /* GPUImageThreeInputFilter.m */,
BCC93A1C1501E42E00958B26 /* GPUImageTwoPassFilter.h */,
BCC93A1D1501E42F00958B26 /* GPUImageTwoPassFilter.m */,
BC0690B6157C0C27009274F9 /* GPUImageTwoPassTextureSamplingFilter.h */,
Expand Down Expand Up @@ -1327,6 +1333,7 @@
BCBC604D16C58B0900B11741 /* GPUImageMotionBlurFilter.h in Headers */,
BCBC605716C8527C00B11741 /* GPUImageZoomBlurFilter.h in Headers */,
BC6C55401730679D00EB222D /* GPUImageLaplacianFilter.h in Headers */,
BCB030BE173400BC001A1A20 /* GPUImageThreeInputFilter.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1598,6 +1605,7 @@
BCBC605816C8527C00B11741 /* GPUImageZoomBlurFilter.m in Sources */,
BCBF617B16E4F44700E2784A /* GPUImageKuwaharaRadius3Filter.m in Sources */,
BC6C55411730679D00EB222D /* GPUImageLaplacianFilter.m in Sources */,
BCB030BF173400BC001A1A20 /* GPUImageThreeInputFilter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
16 changes: 16 additions & 0 deletions framework/GPUImageMac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
BC6C553C1730636600EB222D /* GPUImageLaplacianFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BC6C553A1730636600EB222D /* GPUImageLaplacianFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
BC6C553D1730636600EB222D /* GPUImageLaplacianFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BC6C553B1730636600EB222D /* GPUImageLaplacianFilter.m */; };
BC6C55461730BDCF00EB222D /* GPUImageLanczosResamplingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BC6C55441730BDCF00EB222D /* GPUImageLanczosResamplingFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
BC6C55471730BDCF00EB222D /* GPUImageLanczosResamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BC6C55451730BDCF00EB222D /* GPUImageLanczosResamplingFilter.m */; };
BC78B70E172DCCB800342C6A /* GPUImageAmatorkaFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BC78B706172DCCB800342C6A /* GPUImageAmatorkaFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
BC78B70F172DCCB800342C6A /* GPUImageAmatorkaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BC78B707172DCCB800342C6A /* GPUImageAmatorkaFilter.m */; };
BC78B710172DCCB800342C6A /* GPUImageLookupFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BC78B708172DCCB800342C6A /* GPUImageLookupFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand All @@ -21,6 +23,8 @@
BCA3F3621723A8FA00E28AEC /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BCA3F3601723A8FA00E28AEC /* OpenGL.framework */; };
BCA3F3631723A8FA00E28AEC /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BCA3F3611723A8FA00E28AEC /* QuartzCore.framework */; };
BCA3F3651723A96600E28AEC /* GPUImage.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA3F3641723A96600E28AEC /* GPUImage.h */; settings = {ATTRIBUTES = (Public, ); }; };
BCAE41E41731C3000020F80D /* GPUImageThreeInputFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCAE41E21731C3000020F80D /* GPUImageThreeInputFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
BCAE41E51731C3000020F80D /* GPUImageThreeInputFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCAE41E31731C3000020F80D /* GPUImageThreeInputFilter.m */; };
BCB009E6172A1BBD00DB804C /* GPUImageGammaFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB009E4172A1BBD00DB804C /* GPUImageGammaFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
BCB009E7172A1BBD00DB804C /* GPUImageGammaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = BCB009E5172A1BBD00DB804C /* GPUImageGammaFilter.m */; };
BCB009EA172A1BE800DB804C /* GPUImageToneCurveFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB009E8172A1BE800DB804C /* GPUImageToneCurveFilter.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -184,6 +188,8 @@
/* Begin PBXFileReference section */
BC6C553A1730636600EB222D /* GPUImageLaplacianFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageLaplacianFilter.h; path = Source/GPUImageLaplacianFilter.h; sourceTree = SOURCE_ROOT; };
BC6C553B1730636600EB222D /* GPUImageLaplacianFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageLaplacianFilter.m; path = Source/GPUImageLaplacianFilter.m; sourceTree = SOURCE_ROOT; };
BC6C55441730BDCF00EB222D /* GPUImageLanczosResamplingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageLanczosResamplingFilter.h; path = Source/GPUImageLanczosResamplingFilter.h; sourceTree = SOURCE_ROOT; };
BC6C55451730BDCF00EB222D /* GPUImageLanczosResamplingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageLanczosResamplingFilter.m; path = Source/GPUImageLanczosResamplingFilter.m; sourceTree = SOURCE_ROOT; };
BC78B706172DCCB800342C6A /* GPUImageAmatorkaFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageAmatorkaFilter.h; path = Source/GPUImageAmatorkaFilter.h; sourceTree = SOURCE_ROOT; };
BC78B707172DCCB800342C6A /* GPUImageAmatorkaFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageAmatorkaFilter.m; path = Source/GPUImageAmatorkaFilter.m; sourceTree = SOURCE_ROOT; };
BC78B708172DCCB800342C6A /* GPUImageLookupFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageLookupFilter.h; path = Source/GPUImageLookupFilter.h; sourceTree = SOURCE_ROOT; };
Expand All @@ -202,6 +208,8 @@
BCA3F3601723A8FA00E28AEC /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
BCA3F3611723A8FA00E28AEC /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
BCA3F3641723A96600E28AEC /* GPUImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImage.h; path = Source/Mac/GPUImage.h; sourceTree = SOURCE_ROOT; };
BCAE41E21731C3000020F80D /* GPUImageThreeInputFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageThreeInputFilter.h; path = Source/GPUImageThreeInputFilter.h; sourceTree = SOURCE_ROOT; };
BCAE41E31731C3000020F80D /* GPUImageThreeInputFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageThreeInputFilter.m; path = Source/GPUImageThreeInputFilter.m; sourceTree = SOURCE_ROOT; };
BCB009E4172A1BBD00DB804C /* GPUImageGammaFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageGammaFilter.h; path = Source/GPUImageGammaFilter.h; sourceTree = SOURCE_ROOT; };
BCB009E5172A1BBD00DB804C /* GPUImageGammaFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageGammaFilter.m; path = Source/GPUImageGammaFilter.m; sourceTree = SOURCE_ROOT; };
BCB009E8172A1BE800DB804C /* GPUImageToneCurveFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageToneCurveFilter.h; path = Source/GPUImageToneCurveFilter.h; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -471,6 +479,8 @@
BCF868841728772600912E34 /* GPUImageTwoInputCrossTextureSamplingFilter.m */,
BCF867F21728490300912E34 /* GPUImageTwoInputFilter.h */,
BCF867F31728490500912E34 /* GPUImageTwoInputFilter.m */,
BCAE41E21731C3000020F80D /* GPUImageThreeInputFilter.h */,
BCAE41E31731C3000020F80D /* GPUImageThreeInputFilter.m */,
BCF867C9172788F100912E34 /* GPUImage3x3TextureSamplingFilter.h */,
BCF867CA172788F100912E34 /* GPUImage3x3TextureSamplingFilter.m */,
BCF867C31727820100912E34 /* Color processing */,
Expand Down Expand Up @@ -595,6 +605,8 @@
BCF86825172857B000912E34 /* GPUImageMotionBlurFilter.m */,
BCF86826172857B200912E34 /* GPUImageZoomBlurFilter.h */,
BCF86827172857B600912E34 /* GPUImageZoomBlurFilter.m */,
BC6C55441730BDCF00EB222D /* GPUImageLanczosResamplingFilter.h */,
BC6C55451730BDCF00EB222D /* GPUImageLanczosResamplingFilter.m */,
);
name = "Image processing";
sourceTree = "<group>";
Expand Down Expand Up @@ -749,6 +761,8 @@
BCBF6931173061D200E5792A /* GPUImage3x3ConvolutionFilter.h in Headers */,
BCBF69351730623200E5792A /* GPUImageEmbossFilter.h in Headers */,
BC6C553C1730636600EB222D /* GPUImageLaplacianFilter.h in Headers */,
BC6C55461730BDCF00EB222D /* GPUImageLanczosResamplingFilter.h in Headers */,
BCAE41E41731C3000020F80D /* GPUImageThreeInputFilter.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -897,6 +911,8 @@
BCBF6932173061D200E5792A /* GPUImage3x3ConvolutionFilter.m in Sources */,
BCBF69361730623200E5792A /* GPUImageEmbossFilter.m in Sources */,
BC6C553D1730636600EB222D /* GPUImageLaplacianFilter.m in Sources */,
BC6C55471730BDCF00EB222D /* GPUImageLanczosResamplingFilter.m in Sources */,
BCAE41E51731C3000020F80D /* GPUImageThreeInputFilter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
56 changes: 54 additions & 2 deletions framework/Source/GPUImageLanczosResamplingFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void main()
}
);


#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageLanczosFragmentShaderString = SHADER_STRING
(
precision highp float;
Expand Down Expand Up @@ -77,7 +77,45 @@ void main()

gl_FragColor = fragmentColor;
}
);
);
#else
NSString *const kGPUImageLanczosFragmentShaderString = SHADER_STRING
(
uniform sampler2D inputImageTexture;

varying vec2 centerTextureCoordinate;
varying vec2 oneStepLeftTextureCoordinate;
varying vec2 twoStepsLeftTextureCoordinate;
varying vec2 threeStepsLeftTextureCoordinate;
varying vec2 fourStepsLeftTextureCoordinate;
varying vec2 oneStepRightTextureCoordinate;
varying vec2 twoStepsRightTextureCoordinate;
varying vec2 threeStepsRightTextureCoordinate;
varying vec2 fourStepsRightTextureCoordinate;

// sinc(x) * sinc(x/a) = (a * sin(pi * x) * sin(pi * x / a)) / (pi^2 * x^2)
// Assuming a Lanczos constant of 2.0, and scaling values to max out at x = +/- 1.5

void main()
{
vec4 fragmentColor = texture2D(inputImageTexture, centerTextureCoordinate) * 0.38026;

fragmentColor += texture2D(inputImageTexture, oneStepLeftTextureCoordinate) * 0.27667;
fragmentColor += texture2D(inputImageTexture, oneStepRightTextureCoordinate) * 0.27667;

fragmentColor += texture2D(inputImageTexture, twoStepsLeftTextureCoordinate) * 0.08074;
fragmentColor += texture2D(inputImageTexture, twoStepsRightTextureCoordinate) * 0.08074;

fragmentColor += texture2D(inputImageTexture, threeStepsLeftTextureCoordinate) * -0.02612;
fragmentColor += texture2D(inputImageTexture, threeStepsRightTextureCoordinate) * -0.02612;

fragmentColor += texture2D(inputImageTexture, fourStepsLeftTextureCoordinate) * -0.02143;
fragmentColor += texture2D(inputImageTexture, fourStepsRightTextureCoordinate) * -0.02143;

gl_FragColor = fragmentColor;
}
);
#endif

@implementation GPUImageLanczosResamplingFilter

Expand Down Expand Up @@ -147,4 +185,18 @@ - (void)setFilterFBO;
glViewport(0, 0, (int)currentFBOSize.width, (int)currentFBOSize.height);
}

- (void)setSecondFilterFBO;
{
CGSize currentFBOSize = [self sizeOfFBO];
if (!secondFilterFramebuffer)
{
[self createFilterFBOofSize:currentFBOSize];
[self setupFilterForSize:currentFBOSize];
}

glBindFramebuffer(GL_FRAMEBUFFER, secondFilterFramebuffer);

glViewport(0, 0, (int)currentFBOSize.width, (int)currentFBOSize.height);
}

@end
4 changes: 2 additions & 2 deletions framework/Source/GPUImageLaplacianFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void main()
resultColor += bottomLeftColor * convolutionMatrix[2][0] + bottomColor * convolutionMatrix[2][1] + bottomRightColor * convolutionMatrix[2][2];

// Normalize the results to allow for negative gradients in the 0.0-1.0 colorspace
resultColor = (resultColor + 1.0) / 2.0;
resultColor = resultColor + 0.5;

gl_FragColor = vec4(resultColor, centerColor.a);
}
Expand Down Expand Up @@ -78,7 +78,7 @@ void main()
resultColor += bottomLeftColor * convolutionMatrix[2][0] + bottomColor * convolutionMatrix[2][1] + bottomRightColor * convolutionMatrix[2][2];

// Normalize the results to allow for negative gradients in the 0.0-1.0 colorspace
resultColor = (resultColor + 1.0) / 2.0;
resultColor = resultColor + 0.5;

gl_FragColor = vec4(resultColor, centerColor.a);
}
Expand Down
21 changes: 21 additions & 0 deletions framework/Source/GPUImageThreeInputFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#import "GPUImageTwoInputFilter.h"

extern NSString *const kGPUImageThreeInputTextureVertexShaderString;

@interface GPUImageThreeInputFilter : GPUImageTwoInputFilter
{
GLint filterThirdTextureCoordinateAttribute;
GLint filterInputTextureUniform3;
GPUImageRotationMode inputRotation3;
GLuint filterSourceTexture3;
CMTime thirdFrameTime;

BOOL hasSetSecondTexture, hasReceivedThirdFrame, thirdFrameWasVideo;
BOOL thirdFrameCheckDisabled;

__unsafe_unretained id<GPUImageTextureDelegate> thirdTextureDelegate;
}

- (void)disableThirdFrameCheck;

@end
Loading

0 comments on commit d5c1ddc

Please sign in to comment.