Skip to content

Commit

Permalink
Merge pull request BradLarson#1044 from 0x4d52/master
Browse files Browse the repository at this point in the history
Add GPUImageRawDataOutput/Input to Mac port
  • Loading branch information
BradLarson committed Jun 25, 2013
2 parents 3c66326 + fd893ff commit b01c87d
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
16 changes: 16 additions & 0 deletions framework/GPUImageMac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
A87E5E12177648F3007FD5B1 /* GPUImageRawDataOutput.h in Headers */ = {isa = PBXBuildFile; fileRef = A87E5E10177648F3007FD5B1 /* GPUImageRawDataOutput.h */; settings = {ATTRIBUTES = (Public, ); }; };
A87E5E13177648F3007FD5B1 /* GPUImageRawDataOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = A87E5E11177648F3007FD5B1 /* GPUImageRawDataOutput.m */; };
A87E5E1617764B16007FD5B1 /* GPUImageRawDataInput.h in Headers */ = {isa = PBXBuildFile; fileRef = A87E5E1417764B16007FD5B1 /* GPUImageRawDataInput.h */; settings = {ATTRIBUTES = (Public, ); }; };
A87E5E1717764B16007FD5B1 /* GPUImageRawDataInput.m in Sources */ = {isa = PBXBuildFile; fileRef = A87E5E1517764B16007FD5B1 /* GPUImageRawDataInput.m */; };
BC56957A174683620081491B /* GPUImageCrosshairGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = BC569576174683620081491B /* GPUImageCrosshairGenerator.h */; settings = {ATTRIBUTES = (Public, ); }; };
BC56957B174683620081491B /* GPUImageCrosshairGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = BC569577174683620081491B /* GPUImageCrosshairGenerator.m */; };
BC56957C174683620081491B /* GPUImageLineGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = BC569578174683620081491B /* GPUImageLineGenerator.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -312,6 +316,10 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
A87E5E10177648F3007FD5B1 /* GPUImageRawDataOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageRawDataOutput.h; path = Source/GPUImageRawDataOutput.h; sourceTree = SOURCE_ROOT; };
A87E5E11177648F3007FD5B1 /* GPUImageRawDataOutput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageRawDataOutput.m; path = Source/GPUImageRawDataOutput.m; sourceTree = SOURCE_ROOT; };
A87E5E1417764B16007FD5B1 /* GPUImageRawDataInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageRawDataInput.h; path = Source/GPUImageRawDataInput.h; sourceTree = SOURCE_ROOT; };
A87E5E1517764B16007FD5B1 /* GPUImageRawDataInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageRawDataInput.m; path = Source/GPUImageRawDataInput.m; sourceTree = SOURCE_ROOT; };
BC569576174683620081491B /* GPUImageCrosshairGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageCrosshairGenerator.h; path = Source/GPUImageCrosshairGenerator.h; sourceTree = SOURCE_ROOT; };
BC569577174683620081491B /* GPUImageCrosshairGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUImageCrosshairGenerator.m; path = Source/GPUImageCrosshairGenerator.m; sourceTree = SOURCE_ROOT; };
BC569578174683620081491B /* GPUImageLineGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GPUImageLineGenerator.h; path = Source/GPUImageLineGenerator.h; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -706,6 +714,8 @@
BCF40F1817248286005AE36A /* Sources */ = {
isa = PBXGroup;
children = (
A87E5E1417764B16007FD5B1 /* GPUImageRawDataInput.h */,
A87E5E1517764B16007FD5B1 /* GPUImageRawDataInput.m */,
BCF40F191724829B005AE36A /* GPUImageOutput.h */,
BCF40F1A1724829B005AE36A /* GPUImageOutput.m */,
BCF8679B1727585D00912E34 /* GPUImageAVCamera.h */,
Expand Down Expand Up @@ -746,6 +756,8 @@
BCF40F2217248811005AE36A /* Outputs */ = {
isa = PBXGroup;
children = (
A87E5E10177648F3007FD5B1 /* GPUImageRawDataOutput.h */,
A87E5E11177648F3007FD5B1 /* GPUImageRawDataOutput.m */,
BCF40F2317248836005AE36A /* GPUImageView.h */,
BCF40F2417248836005AE36A /* GPUImageView.m */,
BCF867521725AF9300912E34 /* GPUImageMovieWriter.h */,
Expand Down Expand Up @@ -1056,6 +1068,8 @@
buildActionMask = 2147483647;
files = (
BCA3F3651723A96600E28AEC /* GPUImage.h in Headers */,
A87E5E1617764B16007FD5B1 /* GPUImageRawDataInput.h in Headers */,
A87E5E12177648F3007FD5B1 /* GPUImageRawDataOutput.h in Headers */,
BCF40F1217247D68005AE36A /* GPUImageContext.h in Headers */,
BCF40F1617247FD8005AE36A /* GLProgram.h in Headers */,
BCF40F1B1724829B005AE36A /* GPUImageOutput.h in Headers */,
Expand Down Expand Up @@ -1417,6 +1431,8 @@
BCA20BC817471C4B0097C84A /* GPUImagePerlinNoiseFilter.m in Sources */,
BCA20BCA17471C4B0097C84A /* GPUImageVoronoiConsumerFilter.m in Sources */,
BC96A4F2176563C300F215A2 /* GPUImageNonMaximumSuppressionFilter.m in Sources */,
A87E5E13177648F3007FD5B1 /* GPUImageRawDataOutput.m in Sources */,
A87E5E1717764B16007FD5B1 /* GPUImageRawDataInput.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
13 changes: 13 additions & 0 deletions framework/Source/GPUImageRawDataOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ typedef struct GPUByteColorVector GPUByteColorVector;

@protocol GPUImageRawDataProcessor;

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
@interface GPUImageRawDataOutput : NSObject <GPUImageInput> {
CGSize imageSize;
CVOpenGLESTextureCacheRef rawDataTextureCache;
Expand All @@ -21,6 +22,18 @@ typedef struct GPUByteColorVector GPUByteColorVector;

__unsafe_unretained id<GPUImageTextureDelegate> textureDelegate;
}
#else
@interface GPUImageRawDataOutput : NSObject <GPUImageInput> {
CGSize imageSize;
CVOpenGLTextureCacheRef rawDataTextureCache;
CVPixelBufferRef renderTarget;
GPUImageRotationMode inputRotation;
BOOL outputBGRA;
CVOpenGLTextureRef renderTexture;

__unsafe_unretained id<GPUImageTextureDelegate> textureDelegate;
}
#endif

@property(readonly) GLubyte *rawBytesForImage;
@property(nonatomic, copy) void(^newFrameAvailableBlock)(void);
Expand Down
40 changes: 37 additions & 3 deletions framework/Source/GPUImageRawDataOutput.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,25 @@ - (void)createDataFBO;

if ([GPUImageContext supportsFastTextureUpload])
{
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
#if defined(__IPHONE_6_0)
CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, [[GPUImageContext sharedImageProcessingContext] context], NULL, &rawDataTextureCache);
#else
CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, (__bridge void *)[[GPUImageContext sharedImageProcessingContext] context], NULL, &rawDataTextureCache);
#endif
if (err)
#else
CGLContextObj context = (__bridge void *)[[GPUImageContext sharedImageProcessingContext] context];
CVReturn err = CVOpenGLTextureCacheCreate(kCFAllocatorDefault,
NULL,
context,
CGLGetPixelFormat(context),
NULL,
&rawDataTextureCache);
#endif

if (err)
{
NSAssert(NO, @"Error at CVOpenGLESTextureCacheCreate %d", err);
NSAssert(NO, @"Error at CVOpenGL(ES)TextureCacheCreate %d", err);
}

// Code originally sourced from http://allmybrain.com/2011/12/08/rendering-to-a-texture-with-ios-5-texture-cache-api/
Expand Down Expand Up @@ -154,6 +165,7 @@ - (void)createDataFBO;
attrs,
&renderTarget);

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
CVOpenGLESTextureCacheCreateTextureFromImage (kCFAllocatorDefault,
rawDataTextureCache, renderTarget,
NULL, // texture attributes
Expand All @@ -165,22 +177,44 @@ - (void)createDataFBO;
GL_UNSIGNED_BYTE,
0,
&renderTexture);
#else
CVOpenGLTextureCacheCreateTextureFromImage (kCFAllocatorDefault,
rawDataTextureCache, renderTarget,
NULL,
&renderTexture);
#endif

CFRelease(attrs);
CFRelease(empty);

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
glBindTexture(CVOpenGLESTextureGetTarget(renderTexture), CVOpenGLESTextureGetName(renderTexture));
#else
glBindTexture(CVOpenGLTextureGetTarget(renderTexture), CVOpenGLTextureGetName(renderTexture));
#endif

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, CVOpenGLESTextureGetName(renderTexture), 0);
#else
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, CVOpenGLTextureGetName(renderTexture), 0);
#endif
}
else
{

glGenRenderbuffers(1, &dataRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, dataRenderbuffer);

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_OES, (int)imageSize.width, (int)imageSize.height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, dataRenderbuffer);
#else
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, (int)imageSize.width, (int)imageSize.height);
#endif

glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, dataRenderbuffer);
}
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

Expand Down
2 changes: 2 additions & 0 deletions framework/Source/Mac/GPUImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#import <GPUImage/GPUImageOutput.h>
#import <GPUImage/GPUImageAVCamera.h>
#import <GPUImage/GPUImagePicture.h>
#import <GPUImage/GPUImageRawDataInput.h>
#import <GPUImage/GPUImageRawDataOutput.h>

// Filters
#import <GPUImage/GPUImageFilter.h>
Expand Down
16 changes: 15 additions & 1 deletion framework/Source/Mac/GPUImageMovieWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import "GLProgram.h"
#import "GPUImageFilter.h"

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageColorSwizzlingFragmentShaderString = SHADER_STRING
(
varying highp vec2 textureCoordinate;
Expand All @@ -14,7 +15,20 @@ void main()
{
gl_FragColor = texture2D(inputImageTexture, textureCoordinate).bgra;
}
);
);
#else
NSString *const kGPUImageColorSwizzlingFragmentShaderString = SHADER_STRING
(
varying vec2 textureCoordinate;

uniform sampler2D inputImageTexture;

void main()
{
gl_FragColor = texture2D(inputImageTexture, textureCoordinate).bgra;
}
);
#endif


@interface GPUImageMovieWriter ()
Expand Down

0 comments on commit b01c87d

Please sign in to comment.