GPUImage 重要類的介紹(4大類)

GPUImage 重要類的介紹(4大類)

本文僅作為翻閱資料使用,有錯誤請開發(fā)者自行修改

1,GPUImagePicture類 圖片處理類

GPUImagePicture是PGUImage的圖像處理類,繼承GPUImageOutput,一般作為響應(yīng)鏈的源頭。
GPUImagePicture類靜態(tài)圖像處理操作,它可以是需要處理的靜態(tài)圖像,也可以是一張作為紋理使用的圖片,調(diào)用向它發(fā)送processImage消息,進(jìn)行圖像濾鏡處理。

屬性介紹:

pixelSizeOfImage 圖像的像素大小。
hasProcessedImage 圖像是否已處理。
imageUpdateSemaphore 圖像處理的GCD信號量。

初始化方法:

- (id)initWithURL:(NSURL *)url
使用指定url的圖片來初始化GPUImagePicture

- (id)initWithImage:(UIImage *)newImageSource
使用指定的UIImage對象來初始化GPUImagePicture

- (id)initWithCGImage:(CGImageRef)newImageSource
使用指定的CGImageRef對象來初始化GPUImagePicture

- (id)initWithImage:(UIImage *)newImageSource smoothlyScaleOutput:(BOOL)smoothlyScaleOutput
使用指定的UIImage對象來初始化GPUImagePicture,是否按比例調(diào)整輸入圖像的尺寸

操作API

- (void)processImage;
進(jìn)行圖像處理實際操作。
- (CGSize)outputImageSize;
輸出image的大小

- (BOOL)processImageWithCompletionHandler:(void (^)(void))completion
進(jìn)行圖像處理實際的操作,completion為當(dāng)處理結(jié)束執(zhí)行的操作。

2, GPUImageFilter

濾鏡的基類
1.都遵守GPUImageInput的協(xié)議
2.獲得響應(yīng)鏈上游的紋理,經(jīng)過自己的處理,生成新的紋理,向響應(yīng)鏈的下一個對象傳遞
具體介紹

extern NSString *const kGPUImageVertexShaderString;//頂點(diǎn)著色器
extern NSString *const kGPUImagePassthroughFragmentShaderString;//片段著色器

struct GPUVector4 {//4維坐標(biāo)
    GLfloat one;
    GLfloat two;
    GLfloat three;
    GLfloat four;
};

typedef struct GPUVector4 GPUVector4;

struct GPUVector3 {//3維坐標(biāo)系
    GLfloat one;
    GLfloat two;
    GLfloat three;
};
typedef struct GPUVector3 GPUVector3;

struct GPUMatrix4x4 {//4x4矩陣
    GPUVector4 one;
    GPUVector4 two;
    GPUVector4 three;
    GPUVector4 four;
};
typedef struct GPUMatrix4x4 GPUMatrix4x4;

struct GPUMatrix3x3 {{//3x3矩陣
    GPUVector3 one;
    GPUVector3 two;
    GPUVector3 three;
};
typedef struct GPUMatrix3x3 GPUMatrix3x3;

成員變量:

    GPUImageFramebuffer *firstInputFramebuffer;//輸入幀緩存

    GLProgram *filterProgram;//openGL源程序
    GLint filterPositionAttribute, filterTextureCoordinateAttribute;//頂點(diǎn)屬性、紋理屬性
    GLint filterInputTextureUniform;//輸入紋理常量
    GLfloat backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha;//r  g  b  a

    BOOL isEndProcessing;//是否處理完成

    CGSize currentFilterSize;//當(dāng)前濾鏡的尺寸
    GPUImageRotationMode inputRotation;//旋轉(zhuǎn)模式

    BOOL currentlyReceivingMonochromeInput;//是否接受黑白輸入

    NSMutableDictionary *uniformStateRestorationBlocks;//
    dispatch_semaphore_t imageCaptureSemaphore;//信號量

屬性:

@property(readonly) CVPixelBufferRef renderTarget;//像素對象
@property(readwrite, nonatomic) BOOL preventRendering;//是否方式渲染
@property(readwrite, nonatomic) BOOL currentlyReceivingMonochromeInput;//是否接受黑白輸入

方法:

- (id)initWithVertexShaderFromString:(NSString *)vertexShaderString fragmentShaderFromString:(NSString *)fragmentShaderString;// init
- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString;// init
- (id)initWithFragmentShaderFromFile:(NSString *)fragmentShaderFilename;// init
- (void)initializeAttributes;// init屬性
- (void)setupFilterForSize:(CGSize)filterFrameSize;//設(shè)置濾鏡尺寸
- (CGSize)rotatedSize:(CGSize)sizeToRotate forIndex:(NSInteger)textureIndex;//旋轉(zhuǎn)尺寸
- (CGPoint)rotatedPoint:(CGPoint)pointToRotate forRotation:(GPUImageRotationMode)rotation;//旋轉(zhuǎn)頂點(diǎn)
- (CGSize)sizeOfFBO;//幀緩存大小
+ (const GLfloat *)textureCoordinatesForRotation:(GPUImageRotationMode)rotationMode;//紋理旋轉(zhuǎn)
- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates;//根據(jù)頂點(diǎn)和紋理渲染
- (void)informTargetsAboutNewFrameAtTime:(CMTime)frameTime;//通知響應(yīng)鏈下游的對象
- (CGSize)outputFrameSize;//輸出
/// 一些列set方法
- (void)setBackgroundColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent;
- (void)setInteger:(GLint)newInteger forUniformName:(NSString *)uniformName;
- (void)setFloat:(GLfloat)newFloat forUniformName:(NSString *)uniformName;
- (void)setSize:(CGSize)newSize forUniformName:(NSString *)uniformName;
- (void)setPoint:(CGPoint)newPoint forUniformName:(NSString *)uniformName;
- (void)setFloatVec3:(GPUVector3)newVec3 forUniformName:(NSString *)uniformName;
- (void)setFloatVec4:(GPUVector4)newVec4 forUniform:(NSString *)uniformName;
- (void)setFloatArray:(GLfloat *)array length:(GLsizei)count forUniform:(NSString*)uniformName;

- (void)setMatrix3f:(GPUMatrix3x3)matrix forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
- (void)setMatrix4f:(GPUMatrix4x4)matrix forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
- (void)setFloat:(GLfloat)floatValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
- (void)setPoint:(CGPoint)pointValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
- (void)setSize:(CGSize)sizeValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
- (void)setVec3:(GPUVector3)vectorValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
- (void)setVec4:(GPUVector4)vectorValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
- (void)setFloatArray:(GLfloat *)arrayValue length:(GLsizei)arrayLength forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;
- (void)setInteger:(GLint)intValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram;

- (void)setAndExecuteUniformStateCallbackAtIndex:(GLint)uniform forProgram:(GLProgram *)shaderProgram toBlock:(dispatch_block_t)uniformStateBlock;
- (void)setUniformsForProgramAtIndex:(NSUInteger)programIndex;

3, GPUImageFramebuffer

GPUmageFramebuffer類用于管理幀緩沖對象,負(fù)責(zé)幀緩沖對象的創(chuàng)建和銷毀,讀取幀緩沖內(nèi)容
屬性:

@property(readonly) CGSize size;//只讀屬性,在實現(xiàn)中,設(shè)置緩沖區(qū)的size
@property(readonly) GPUTextureOptions textureOptions;//紋理的選項
@property(readonly) GLuint texture;//管理紋理
@property(readonly) BOOL missingFramebuffer;//指示是否丟失幀緩沖對象

初始化:

// Initialization and teardown

創(chuàng)建一個size為framebufferSize大小的幀緩沖對象
參數(shù) framebuffer的size。
返回:創(chuàng)建成功的幀緩沖對象。
- (id)initWithSize:(CGSize)framebufferSize;

創(chuàng)建一個size為framebufferSize大小的幀緩沖對象
參數(shù):framebufferSize為framebuffer的size。fboTextureOptions是紋理的詳細(xì)配置。onlyGenerateTexture說明是否只創(chuàng)建紋理而不創(chuàng)建陳幀緩沖對象。
返回:創(chuàng)建成功的幀緩沖對象。

- (id)initWithSize:(CGSize)framebufferSize textureOptions:(GPUTextureOptions)fboTextureOptions onlyTexture:(BOOL)onlyGenerateTexture;

創(chuàng)建一個size為framebufferSize大小的幀緩沖對象
參數(shù):inputTexture為輸入的紋理,用于渲染圖片。
返回:創(chuàng)建成功的幀緩沖對象。

- (id)initWithSize:(CGSize)framebufferSize overriddenTexture:(GLuint)inputTexture;

激活

// Usage
- (void)activateFramebuffer;//激活剛創(chuàng)建的framebuffer對象。只有調(diào)用它后,才會起作用。

引用計數(shù)

- (void)lock;//引用計數(shù)管理 +1
- (void)unlock;//引用計數(shù)管理 -1
- (void)clearAllLocks;//引用計數(shù)管理 設(shè)置為0
- (void)disableReferenceCounting;//引用計數(shù)管理 禁用引用計數(shù)
- (void)enableReferenceCounting;//引用計數(shù)管理 啟用引用計數(shù)

圖片捕捉

- (CGImageRef)newCGImageFromFramebufferContents;
- (void)restoreRenderTarget;//還原渲染目標(biāo)對象

原始數(shù)據(jù)字節(jié)

- (void)lockForReading;//[鎖](http://www.liuhaihua.cn/archives/tag/%e9%94%81)定PixelBuffer
- (void)unlockAfterReading;//解鎖PixelBuffer
- (NSUInteger)bytesPerRow;//獲取pixel buffer的行字節(jié)數(shù)
- (GLubyte *)byteBuffer;//獲取pixel buffer的基地址

4, GPUImageFilterGroup (組合濾鏡)

GPUImageFilterGroup是多個filter的集合,terminalFilter為最終的filter,initialFilters為filter數(shù)組。GPUImageFilterGroup本身不繪制圖像,對GPUImageFilterGroup添加刪除Target操作的操作都會轉(zhuǎn)為terminalFilter的操作

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容