# bradlarson/gpuimage3 architecture

> Architecture diagram of the GitHub repository bradlarson/gpuimage3, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bradlarson/gpuimage3
- Repository: https://github.com/bradlarson/gpuimage3

## Overview

This project is an image and video processing framework—GPUImage 3—that is built to operate as a real-time, GPU-accelerated processing pipeline for iOS, macOS, and potentially Linux. It is designed as an object‑oriented framework where image sources feed into a chain of processing operations (often composing custom Metal shader programs) that eventually deliver their output to a display, file, or video recorder. In other words, the entire framework implements a “processing pipeline” architecture.

##### Major Components
- Source/Input Components: Represent the various image or video sources such as Camera, MovieInput, PictureInput, and potentially raw data sources.
- Processing Operations: Central to the framework, these are encapsulated in classes like BasicOperation and its many subclasses (found under Sources/GPUImage/Operations). They represent the core image processing operations (e.g., brightness, contrast, hue, filters, edge detection, blending modes, etc.) as well as the chaining operator (the “-->” operator) that lets you build pipelines.
- Operation Groups: Show that several operations can be grouped together using OperationGroup so that a complex operation can be modularized.
- Output/Consumers: Image outputs are delivered to targets such as RenderView, MovieOutput, or PictureOutput.
- Metal Rendering Engine: Since the framework is reworked to use Metal, include components like MetalRendering, MetalRenderingDevice, and shared types (e.g., Texture, ShaderUniformSettings, etc.) that abstract and drive the GPU rendering pipeline.
- Integration and Examples: Although not part of the core engine, the examples folder demonstrates how the components are used in both iOS and macOS apps, highlighting real-world integration.

##### Representing the Relationships
- That the processing pipeline is a chain (or series) of operations. Each operation takes one or more inputs and produces output to either drive further operations or to deliver a final rendered result.
- A branch for “Operation Group,” which encapsulates and manages a sub-pipeline – showing that several operations can be bundled to act as one filter.

##### Architectural Patterns and Design Principles
- Pipeline Pattern: Emphasize the linear (and possibly branching) pipeline model where images move from source to consumer via sequential processing steps.
- Object-Oriented Modular Design: Classes encapsulate functionality (e.g., BasicOperation simplifying shader management); protocols define roles (ImageSource, ImageConsumer, ImageProcessingOperation).
- Separation of Concerns: Different types are responsible for input capture, processing via custom Metal shaders, and final output rendering.
- Metal Integration: Specifically show that the shader operations and Metal rendering classes serve as the low-level backbone supporting the high-level pipeline.

##### Technology & Frameworks
- Swift 5.5 and Xcode 13 or higher.
- Metal as the core graphics framework (instead of OpenGL ES) for GPU rendering.
- Use of Swift Package Manager (evident from Package.swift), demonstrating how the framework is integrated as a dependency.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Input Sources
    subgraph "Input Sources"
        camera("Camera"):::input
        movieInput("MovieInput"):::input
        pictureInput("PictureInput"):::input
        imageGenerator("ImageGenerator"):::input
    end

    %% Processing Operations
    subgraph "Processing Operations"
        basicOperation("BasicOperation"):::processing
        customFilters("Custom Filter Operations"):::processing
        operationGroup("OperationGroup"):::processing
    end

    %% Output Consumers
    subgraph "Output Consumers"
        renderView("RenderView"):::output
        pictureOutput("PictureOutput"):::output
        movieOutput("MovieOutput"):::output
    end

    %% Metal Rendering Engine
    subgraph "Metal Rendering Engine"
        metalRendering("MetalRendering"):::metal
        metalDevice("MetalRenderingDevice"):::metal
        texture("Texture"):::metal
        shaderUniform("ShaderUniformSettings"):::metal
    end

    %% Supporting Utilities
    subgraph "Supporting Utilities"
        matrix("Matrix"):::utility
        color("Color"):::utility
        position("Position"):::utility
        size("Size"):::utility
        timestamp("Timestamp"):::utility
        imageOrientation("ImageOrientation"):::utility
    end

    %% Integration & Examples
    subgraph "Integration & Examples"
        examples("Examples (iOS & Mac)"):::examples
    end

    %% Connections from Input Sources to Processing
    camera -->|"feeds"| basicOperation
    movieInput -->|"feeds"| basicOperation
    pictureInput -->|"feeds"| basicOperation
    imageGenerator -->|"feeds"| basicOperation

    %% Processing chain connections
    basicOperation -->|"chains"| customFilters
    customFilters -->|"bundled_in"| operationGroup

    %% Linking Processing to Outputs
    operationGroup -->|"renders_to"| renderView
    operationGroup -->|"renders_to"| pictureOutput
    operationGroup -->|"renders_to"| movieOutput

    %% Metal Rendering support connections
    basicOperation -->|"MetalSupport"| metalRendering
    customFilters -->|"MetalSupport"| metalRendering
    operationGroup -->|"MetalSupport"| metalRendering
    metalRendering -->|"uses_device"| metalDevice
    metalRendering -->|"manages"| texture
    metalRendering -->|"configures"| shaderUniform

    %% Utilities support to Processing and Metal Rendering
    matrix -->|"supports"| basicOperation
    color -->|"supports"| basicOperation
    position -->|"supports"| basicOperation
    size -->|"supports"| basicOperation
    timestamp -->|"supports"| basicOperation
    imageOrientation -->|"supports"| basicOperation
    matrix -->|"supports"| metalRendering
    color -->|"supports"| metalRendering
    position -->|"supports"| metalRendering
    size -->|"supports"| metalRendering

    %% Examples integration pointers
    examples -->|"demonstrates"| camera
    examples -->|"demonstrates"| renderView

    %% Styles
    classDef input fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef processing fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef output fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef metal fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef utility fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef examples fill:#FF69B4,stroke:#000,stroke-width:2px;

    %% Click Events
    click camera "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/Camera.swift"
    click movieInput "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/MovieInput.swift"
    click pictureInput "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/PictureInput.swift"
    click imageGenerator "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/ImageGenerator.swift"

    click basicOperation "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/BasicOperation.swift"
    click customFilters "https://github.com/bradlarson/gpuimage3/tree/main/Sources/GPUImage/Operations"
    click operationGroup "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/OperationGroup.swift"

    click renderView "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/RenderView.swift"
    click pictureOutput "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/PictureOutput.swift"
    click movieOutput "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/MovieOutput.swift"

    click metalRendering "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/MetalRendering.swift"
    click metalDevice "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/MetalRenderingDevice.swift"
    click texture "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/Texture.swift"
    click shaderUniform "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/ShaderUniformSettings.swift"

    click matrix "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/Matrix.swift"
    click color "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/Color.swift"
    click position "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/Position.swift"
    click size "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/Size.swift"
    click timestamp "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/Timestamp.swift"
    click imageOrientation "https://github.com/bradlarson/gpuimage3/blob/main/Sources/GPUImage/ImageOrientation.swift"

    click examples "https://github.com/bradlarson/gpuimage3/tree/main/examples"
```
