# GPUImage源码解读(一)

系列文章会从结构到使用,细化到每一个变量, 使用方法全有对应 DEMO.也会有相对应的技术点扩展如(AVFoundation,OpenGL shader,CAEAGLLayer)等,目前是 Objective-C 版本的,后面会有Swift版本.\
[GPUImage-Objective-C 官方源码](https://github.com/BradLarson/GPUImage)

[GPUImage-Swift 官方源码](https://github.com/BradLarson/GPUImage2)

[GPUImage-Objective-C 添加注释说明源码 ](https://www.svnchina.com/svn/akgpuimage)

## 关于GPUImage

GPUImage框架是一个开源iOS类库，基于OpenGL进行图像和视频处理，借助GPU加速实现各种滤镜效果，并支持摄像头拍摄实时渲染。它具有以下特性：

* 丰富的输入组件

  摄像头、图片、视频、OpenGL纹理、二进制数据、UIElement(UIView, CALayer)
* 大量现成的内置滤镜（4大类）

  1\). 颜色类（亮度、色度、饱和度、对比度、曲线、白平衡...）

  2\). 图像类（仿射变换、裁剪、高斯模糊、毛玻璃效果...）

  3\). 颜色混合类（差异混合、alpha混合、遮罩混合...）

  4\). 效果类（像素化、素描效果、压花效果、球形玻璃效果...）
* 丰富的输出组件

  UIView、视频文件、GPU纹理、二进制数据
* 灵活的滤镜链

  滤镜效果之间可以相互串联、并联，调用管理相当灵活。
* 接口易用

  滤镜和OpenGL资源的创建及使用都做了统一的封装，简单易用，并且内置了一个cache模块实现了framebuffer的复用。
* 线程管理

  OpenGLContext不是多线程安全的，GPUImage创建了专门的contextQueue，所有的滤镜都会扔到统一的线程中处理。

  轻松实现自定义滤镜效果

  继承GPUImageFilter自动获得上面全部特性，无需关注上下文的环境搭建，专注于效果的核心算法实现即可。

## 目录结构

ps:源代码source都在同一级目录不能使用tree @^@ ![](/files/-LAdZQgc0wCpFtcbqp7a)

## 核心架构(待续)

GPUImage功能的实现依赖四个部分：资源管理、Sources、Filters、Outputs。核心架构用下图概括 ![](/files/-LAdZQhgYUYKuj13unzF)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://philm.gitbook.io/philm-ios-wiki/mei-zhou-yue-du/gpuimage-yuan-ma-jie-du-yi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
