Skip to content

Commit

Permalink
Fixed an issue with the two-pass filters where they wouldn't save ima…
Browse files Browse the repository at this point in the history
…ges correctly. Added an option to rotate for the front-facing camera.
  • Loading branch information
BradLarson committed Mar 6, 2012
1 parent e77fc9d commit 248b817
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 10 deletions.
17 changes: 17 additions & 0 deletions examples/CubeExample/CubeExample-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,22 @@
<string>MainWindow</string>
<key>UIStatusBarHidden</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
2 changes: 2 additions & 0 deletions examples/CubeExample/CubeExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
HEADER_SEARCH_PATHS = "../../framework/**";
PREBINDING = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
Expand All @@ -346,6 +347,7 @@
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
PREBINDING = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ - (void)setupImageFilteringToDisk;
UIImage *inputImage = [UIImage imageNamed:@"Lambeau.jpg"];

GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];
// GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];
GPUImageSketchFilter *stillImageFilter = [[GPUImageSketchFilter alloc] init];

[stillImageSource addTarget:stillImageFilter];
[stillImageSource processImage];

UIImage *currentFilteredVideoFrame = [stillImageFilter imageFromCurrentlyProcessedOutput];

// Do a simpler image filtering
GPUImageSepiaFilter *stillImageFilter2 = [[GPUImageSepiaFilter alloc] init];
// GPUImageSepiaFilter *stillImageFilter2 = [[GPUImageSepiaFilter alloc] init];
GPUImageSketchFilter *stillImageFilter2 = [[GPUImageSketchFilter alloc] init];
UIImage *quickFilteredImage = [stillImageFilter2 imageByFilteringImage:inputImage];


Expand Down
1 change: 1 addition & 0 deletions framework/Source/GPUImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ typedef struct GPUMatrix4x4 GPUMatrix4x4;
- (void)createFilterFBOofSize:(CGSize)currentFBOSize;
- (void)destroyFilterFBO;
- (void)setFilterFBO;
- (void)setOutputFBO;

// Rendering
- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates sourceTexture:(GLuint)sourceTexture;
Expand Down
8 changes: 7 additions & 1 deletion framework/Source/GPUImageFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void dataProviderReleaseCallback (void *info, const void *data, size_t size)
- (UIImage *)imageFromCurrentlyProcessedOutput;
{
[GPUImageOpenGLESContext useImageProcessingContext];
[self setFilterFBO];
[self setOutputFBO];

CGSize currentFBOSize = [self sizeOfFBO];

Expand Down Expand Up @@ -205,6 +205,12 @@ - (void)setFilterFBO;
glViewport(0, 0, (int)currentFBOSize.width, (int)currentFBOSize.height);
}

- (void)setOutputFBO;
{
// Override this for filters that have multiple framebuffers
[self setFilterFBO];
}

#pragma mark -
#pragma mark Rendering

Expand Down
2 changes: 1 addition & 1 deletion framework/Source/GPUImageRotationFilter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "GPUImageFilter.h"

typedef enum { kGPUImageRotateLeft, kGPUImageRotateRight, kGPUImageFlipVertical, kGPUImageFlipHorizonal} GPUImageRotationMode;
typedef enum { kGPUImageRotateLeft, kGPUImageRotateRight, kGPUImageFlipVertical, kGPUImageFlipHorizonal, kGPUImageRotateRightFlipVertical} GPUImageRotationMode;

@interface GPUImageRotationFilter : GPUImageFilter
{
Expand Down
9 changes: 9 additions & 0 deletions framework/Source/GPUImageRotationFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,22 @@ - (void)newFrameReady;
1.0f, 1.0f,
0.0f, 1.0f,
};

static const GLfloat rotateRightVerticalFlipTextureCoordinates[] = {
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,
};


switch (rotationMode)
{
case kGPUImageRotateLeft: [self renderToTextureWithVertices:rotationSquareVertices textureCoordinates:rotateLeftTextureCoordinates sourceTexture:filterSourceTexture]; break;
case kGPUImageRotateRight: [self renderToTextureWithVertices:rotationSquareVertices textureCoordinates:rotateRightTextureCoordinates sourceTexture:filterSourceTexture]; break;
case kGPUImageFlipHorizonal: [self renderToTextureWithVertices:rotationSquareVertices textureCoordinates:verticalFlipTextureCoordinates sourceTexture:filterSourceTexture]; break;
case kGPUImageFlipVertical: [self renderToTextureWithVertices:rotationSquareVertices textureCoordinates:horizontalFlipTextureCoordinates sourceTexture:filterSourceTexture]; break;
case kGPUImageRotateRightFlipVertical: [self renderToTextureWithVertices:rotationSquareVertices textureCoordinates:rotateRightVerticalFlipTextureCoordinates sourceTexture:filterSourceTexture]; break;
}
[self informTargetsAboutNewFrame];
}
Expand Down
13 changes: 7 additions & 6 deletions framework/Source/GPUImageSobelEdgeDetectionFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void main()
attribute vec4 position;
attribute vec4 inputTextureCoordinate;

uniform mediump float imageWidthFactor;
uniform mediump float imageHeightFactor;
uniform highp float imageWidthFactor;
uniform highp float imageHeightFactor;

varying vec2 textureCoordinate;
varying vec2 leftTextureCoordinate;
Expand All @@ -44,10 +44,10 @@ void main()
{
gl_Position = position;

mediump vec2 widthStep = vec2(imageWidthFactor, 0.0);
mediump vec2 heightStep = vec2(0.0, imageHeightFactor);
mediump vec2 widthHeightStep = vec2(imageWidthFactor, imageHeightFactor);
mediump vec2 widthNegativeHeightStep = vec2(imageWidthFactor, -imageHeightFactor);
vec2 widthStep = vec2(imageWidthFactor, 0.0);
vec2 heightStep = vec2(0.0, imageHeightFactor);
vec2 widthHeightStep = vec2(imageWidthFactor, imageHeightFactor);
vec2 widthNegativeHeightStep = vec2(imageWidthFactor, -imageHeightFactor);

textureCoordinate = inputTextureCoordinate.xy;
leftTextureCoordinate = inputTextureCoordinate.xy - widthStep;
Expand Down Expand Up @@ -138,6 +138,7 @@ - (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString;

- (void)setupFilterForSize:(CGSize)filterFrameSize;
{
NSLog(@"Setting up Sobel filter for size: %f, %f", filterFrameSize.width, filterFrameSize.height);
if (!hasOverriddenImageSizeFactor)
{
_imageWidthFactor = filterFrameSize.width;
Expand Down
6 changes: 6 additions & 0 deletions framework/Source/GPUImageTwoPassFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ - (void)setSecondFilterFBO;
// glViewport(0, 0, (int)currentFBOSize.width, (int)currentFBOSize.height);
}

- (void)setOutputFBO;
{
// Override this for filters that have multiple framebuffers
[self setSecondFilterFBO];
}

#pragma mark -
#pragma mark Rendering

Expand Down

0 comments on commit 248b817

Please sign in to comment.