forked from BradLarson/GPUImage
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
248b817
commit 0bdd101
Showing
11 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/FilterShowcase/FilterShowcase/ShowcaseFilterViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#import "GPUImageFilter.h" | ||
|
||
@interface GPUImageCropFilter : GPUImageFilter | ||
{ | ||
} | ||
|
||
// The crop region is the rectangle within the image to crop. It is normalized to a coordinate space from 0.0 to 1.0, with 0.0, 0.0 being the upper left corner of the image | ||
@property(readwrite, nonatomic) CGRect cropRegion; | ||
|
||
// Initialization and teardown | ||
- (id)initWithCropRegion:(CGRect)newCropRegion; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#import "GPUImageCropFilter.h" | ||
|
||
NSString *const kGPUImageCropFragmentShaderString = SHADER_STRING | ||
( | ||
varying highp vec2 textureCoordinate; | ||
|
||
uniform sampler2D inputImageTexture; | ||
|
||
void main() | ||
{ | ||
gl_FragColor = texture2D(inputImageTexture, textureCoordinate); | ||
} | ||
); | ||
|
||
@implementation GPUImageCropFilter | ||
|
||
@synthesize cropRegion = _cropRegion; | ||
|
||
#pragma mark - | ||
#pragma mark Initialization and teardown | ||
|
||
- (id)initWithCropRegion:(CGRect)newCropRegion; | ||
{ | ||
if (!(self = [super initWithFragmentShaderFromString:kGPUImageCropFragmentShaderString])) | ||
{ | ||
return nil; | ||
} | ||
|
||
self.cropRegion = newCropRegion; | ||
|
||
return self; | ||
} | ||
|
||
- (id)init; | ||
{ | ||
if (!(self = [self initWithCropRegion:CGRectMake(0.0, 0.0, 1.0, 1.0)])) | ||
{ | ||
return nil; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark GPUImageInput | ||
|
||
//- (void)setInputSize:(CGSize)newSize; | ||
//{ | ||
// CGSize croppedSize; | ||
// croppedSize.width = newSize.width * _cropRegion.size.width; | ||
// croppedSize.height = newSize.height * _cropRegion.size.height; | ||
// | ||
// inputTextureSize = croppedSize; | ||
//} | ||
// | ||
- (void)newFrameReady; | ||
{ | ||
static const GLfloat cropSquareVertices[] = { | ||
-1.0f, -1.0f, | ||
1.0f, -1.0f, | ||
-1.0f, 1.0f, | ||
1.0f, 1.0f, | ||
}; | ||
|
||
GLfloat cropTextureCoordinates[] = { | ||
_cropRegion.origin.x, _cropRegion.origin.y, | ||
CGRectGetMaxX(_cropRegion), _cropRegion.origin.y, | ||
_cropRegion.origin.x, CGRectGetMaxY(_cropRegion), | ||
CGRectGetMaxX(_cropRegion), CGRectGetMaxY(_cropRegion), | ||
}; | ||
|
||
[self renderToTextureWithVertices:cropSquareVertices textureCoordinates:cropTextureCoordinates sourceTexture:filterSourceTexture]; | ||
|
||
[self informTargetsAboutNewFrame]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters