forked from tapsquare/GPUImage
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a raw data output type for reading image bytes and textures. Ad…
…ded a sketch effect filter.
- Loading branch information
1 parent
a051287
commit fe84406
Showing
9 changed files
with
323 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#import <Foundation/Foundation.h> | ||
#import "GPUImageOpenGLESContext.h" | ||
|
||
struct GPUByteColorVector { | ||
GLubyte red; | ||
GLubyte green; | ||
GLubyte blue; | ||
GLubyte alphe; | ||
}; | ||
typedef struct GPUByteColorVector GPUByteColorVector; | ||
|
||
@protocol GPUImageRawDataProcessor; | ||
|
||
@interface GPUImageRawData : NSObject <GPUImageInput> | ||
|
||
@property(readwrite, unsafe_unretained, nonatomic) id<GPUImageRawDataProcessor> delegate; | ||
@property(readonly) GLubyte *rawBytesForImage; | ||
@property(readonly) GLint openGLTexture; | ||
|
||
// Initialization and teardown | ||
- (id)initWithImageSize:(CGSize)newImageSize; | ||
|
||
// Data access | ||
- (GPUByteColorVector)colorAtLocation:(CGPoint)locationInImage; | ||
|
||
@end | ||
|
||
@protocol GPUImageRawDataProcessor | ||
- (void)newImageFrameAvailableFromDataSource:(GPUImageRawData *)rawDataSource; | ||
@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,108 @@ | ||
#import "GPUImageRawData.h" | ||
|
||
@interface GPUImageRawData () | ||
{ | ||
CGSize imageSize; | ||
BOOL hasReadFromTheCurrentFrame; | ||
} | ||
@end | ||
|
||
@implementation GPUImageRawData | ||
|
||
#pragma mark - | ||
#pragma mark Initialization and teardown | ||
|
||
- (id)initWithImageSize:(CGSize)newImageSize; | ||
{ | ||
if (!(self = [super init])) | ||
{ | ||
return nil; | ||
} | ||
|
||
imageSize = newImageSize; | ||
|
||
hasReadFromTheCurrentFrame = NO; | ||
_rawBytesForImage = NULL; | ||
|
||
return self; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
if (_rawBytesForImage != NULL) | ||
{ | ||
free(_rawBytesForImage); | ||
_rawBytesForImage = NULL; | ||
} | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark Data access | ||
|
||
- (GPUByteColorVector)colorAtLocation:(CGPoint)locationInImage; | ||
{ | ||
GPUByteColorVector *imageColorBytes = (GPUByteColorVector *)self.rawBytesForImage; | ||
|
||
CGPoint locationToPickFrom = CGPointZero; | ||
locationToPickFrom.x = MIN(MAX(locationInImage.x, 0.0), (imageSize.width - 1.0)); | ||
locationToPickFrom.y = MIN(MAX(locationInImage.y, 0.0), (imageSize.height - 1.0)); | ||
|
||
return imageColorBytes[(int)(round(locationToPickFrom.x * locationToPickFrom.y))]; | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark GPUImageInput protocol | ||
|
||
- (void)newFrameReady; | ||
{ | ||
hasReadFromTheCurrentFrame = NO; | ||
|
||
[self.delegate newImageFrameAvailableFromDataSource:self]; | ||
} | ||
|
||
- (void)setInputTexture:(GLuint)newInputTexture; | ||
{ | ||
_openGLTexture = newInputTexture; | ||
} | ||
|
||
- (void)setInputSize:(CGSize)newSize; | ||
{ | ||
|
||
} | ||
|
||
- (CGSize)maximumOutputSize; | ||
{ | ||
return imageSize; | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark Accessors | ||
|
||
@synthesize rawBytesForImage = _rawBytesForImage; | ||
@synthesize openGLTexture = _openGLTexture; | ||
@synthesize delegate = _delegate; | ||
|
||
- (GLubyte *)rawBytesForImage; | ||
{ | ||
if (_rawBytesForImage == NULL) | ||
{ | ||
_rawBytesForImage = (GLubyte *) calloc(imageSize.width * imageSize.height * 4, sizeof(GLubyte)); | ||
hasReadFromTheCurrentFrame = NO; | ||
} | ||
|
||
if (hasReadFromTheCurrentFrame) | ||
{ | ||
return _rawBytesForImage; | ||
} | ||
else | ||
{ | ||
[GPUImageOpenGLESContext useImageProcessingContext]; | ||
// This might require a re-rendering of the previous frame in order for the reading of the pixels to work | ||
glReadPixels(0, 0, imageSize.width, imageSize.height, GL_RGBA, GL_UNSIGNED_BYTE, _rawBytesForImage); | ||
|
||
return _rawBytesForImage; | ||
} | ||
|
||
} | ||
|
||
@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,14 @@ | ||
#import "GPUImageFilter.h" | ||
|
||
@interface GPUImageSketchFilter : GPUImageFilter | ||
{ | ||
GLint intensityUniform, imageWidthFactorUniform, imageHeightFactorUniform; | ||
} | ||
|
||
// Intensity is the degree to which the edges are overlaid on the image. 1.0 is the default, and is complete visibility for them | ||
@property(readwrite, nonatomic) CGFloat intensity; | ||
// The image width and height factors tweak the appearance of the edges. Normally, they are close to the image size in pixels | ||
@property(readwrite, nonatomic) CGFloat imageWidthFactor; | ||
@property(readwrite, nonatomic) CGFloat imageHeightFactor; | ||
|
||
@end |
Oops, something went wrong.