• Stars
    star
    230
  • Rank 174,053 (Top 4 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Edit images and video with async / await in Swift, powered by Metal.

AsyncGraphics

AsyncGraphics is a Swift package for working with images and video with async / await. The core type is simply just called Graphic, it's like an image and is backed by a MTLTexture.

Documentation

Documentation (DocC)

See the Graphic docs for all effects.

Articles

Content

Resources: Image, Video, Camera, Maps, Screen, Text, View

Shapes: Circle, Rectangle, Arc, Polygon, Star, Line

Solid: Color, Gradient, Noise, Metal

Particles: UV Particles, UV Color Particles

Effects

Direct: Blur, Zoom Blur, Angle Blur, Circle Blur, Rainbow Blur, Random Blur, Channel Mix, Chroma Key, Clamp, Color Convert, Hue, Saturation, Monochrome, Tint, Corner Pin, Edge, Kaleidoscope, Brightness, Contrast, Gamma, Inverted, Opacity, Morph, Pixelate, Quantize, Sharpen, Slope, Threshold, Offset, Rotate, Scale, Metal

Dual: Blend, Cross, Displace, Lookup, Luma Blur, Luma Rainbow Blur, Luma Hue, Luma Saturation, Luma Brightness, Luma Contrast, Luma Gamma, Luma Translate, Luma Rotate, Luma Scale, Remap, Metal

Array: HStack, VStack, ZStack, Layers, Metal

Technical: Add, Average, Bits, Color Space, Crop, Inspect, Polar, Reduce, Resize, Coordinate Space, LUT

Install

.package(url: "https://github.com/heestand-xyz/AsyncGraphics", from: "2.0.0")

Views

In AsyncGraphics there are a couple ways to present a graphic.

Examples

Blending

First we create an AGView, this is the container for all AGGraphs. In this example we have a AGZStack with 3 AGHStacks. Each graph has a blend mode (AGBlendMode), in this case .screen.

import SwiftUI
import AsyncGraphics

struct ContentView: View {
    var body: some View {
        AGView {
            AGZStack {
                AGHStack {
                    AGSpacer()
                    AGCircle()
                        .foregroundColor(.red)
                }
                AGHStack {
                    AGSpacer()
                    AGCircle()
                        .foregroundColor(.green)
                    AGSpacer()
                }
                .blendMode(.screen)
                AGHStack {
                    AGCircle()
                        .foregroundColor(.blue)
                    AGSpacer()
                }
                .blendMode(.screen)
            }
        }
    }
}

Layout

First we create an AGView, this is the container for all AGGraphs. In this example we create an AGHStack to contain out boxes, then we loop 3 times with an AGForEach, calculate the width and create AGRoundedRectangles. After that we set the frame to get a fixed size and apply a color. After the stack we apply some padding and finally add a background.

import SwiftUI
import AsyncGraphics

struct ContentView: View {
    var body: some View {
        AGView {
            AGHStack(alignment: .top, spacing: 15) {
                AGForEach(0..<3) { index in
                    let width = 50 * CGFloat(index + 1)
                    AGRoundedRectangle(cornerRadius: 15)
                        .frame(width: width, height: width)
                        .foregroundColor(Color(hue: Double(index) / 3,
                                               saturation: 0.5,
                                               brightness: 1.0))
                }
            }
            .padding(15)
            .background {
                AGRoundedRectangle(cornerRadius: 30)
                    .opacity(0.1)
            }
        }
    }
}

Camera

import SwiftUI
import AsyncGraphics

struct ContentView: View {
    
    var body: some View {
        AGView {
            AGZStack {
                AGCamera(.front)
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                AGCircle()
                    .blendMode(.multiply)
            }
        }
    }
}

You can also do the same with Graphics:

import SwiftUI
import AsyncGraphics

struct ContentView: View {
    
    @State private var graphic: Graphic?
    
    var body: some View {
        ZStack {
            if let graphic {
                GraphicView(graphic: graphic)
            }
        }
        .task {
            do {
                let resolution = CGSize(width: 1_000, height: 1_000)
                let circleGraphic: Graphic = try await .circle(radius: 500,
                                                               backgroundColor: .clear,
                                                               resolution: resolution)
                for await cameraGraphic in try Graphic.camera(.front) {
                    graphic = try await circleGraphic
                        .blended(with: cameraGraphic,
                                 blendingMode: .multiply,
                                 placement: .fill)
                }
            } catch {
                print(error)
            }
        }
    }
}

Remember to set the Info.plist key NSCameraUsageDescription "Privacy - Camera Usage Description"

Metal

There is the option to write high level metal code in AsyncGraphics. No need to setup a pipeline.

Colors

Colors are represented with the PixelColor type.
import PixelColor to create custom colors with hex values.

PixelColor on GitHub.

About

AsyncGraphics is a work in progress project, there is more features to come! Feel free to submit a PR!

More Repositories

1

PixelKit

Live Graphics in Swift & Metal
Swift
808
star
2

UI3

3D UI layout lib for SwiftUI
Swift
78
star
3

SwiftFX

SwiftUI Effects
Swift
62
star
4

SwiftMetal

Write Metal in Swift
Swift
56
star
5

VertexKit

a Framework for iOS & macOS
Swift
50
star
6

VoxelKit

Volumetric realtime graphics
Swift
46
star
7

RenderKit

Realtime Render Engine Protocol
Swift
45
star
8

PolyKit

Rounded Polygons in SwiftUI
Swift
44
star
9

PixelUI

Create Live Graphics in SwiftUI (iOS, tvOS & macOS)
Swift
35
star
10

AirKit

AirPlay SwiftUI Views
Swift
23
star
11

cook_bar

A 'Health Bar' over each op indicating cook time. (now with GPU info)
19
star
12

Trails

Trails of values over time in SwiftUI
Swift
18
star
13

GeometryWriter

The opposite of a GeometryReader in SwiftUI
Swift
17
star
14

SwiftUIOSC

OSC Property Wrapper
Swift
14
star
15

Tabs

Tabs in SwiftUI
Swift
13
star
16

HDR-Camera

HDR Camera iOS App
Swift
10
star
17

TextureMap

Map textures in different formats like UIImage, NSImage, CGImage, CIImage and MTLTexture
Swift
9
star
18

Noise

*Random Smooth Cloudy* Noise for SwiftUI
Swift
8
star
19

Game-of-Life

Made in Swift & Metal with PixelKit
Swift
8
star
20

ImageFX

Async Image Effects
Swift
7
star
21

LiveValues

LiveValues for iOS, tvOS & macOS
Swift
7
star
22

RoundedPath

Round Paths in SwiftUI
Swift
7
star
23

MetalShaders

Shared Metal Shaders
Metal
7
star
24

VJ

hexagons and circles
Swift
6
star
25

KanjiGrid

An app for exploring Kanji
Swift
6
star
26

BottomSheet

Made in SwiftUI
Swift
5
star
27

PixelKit-SwiftUI

PixelKit with SwiftUI
Swift
5
star
28

pixtools

Pixel Command Line Tools
Swift
5
star
29

LUMA-FACE

LUMA FACE
Swift
5
star
30

MultiViews

SwiftUI Views for iOS, tvOS & macOS
Swift
5
star
31

pixlab

Pixel Command Line Lab
Swift
4
star
32

VoxelView

Metal 3D Texture Voxel Viewer
Swift
4
star
33

Shapes

SwiftUI Shapes
Swift
4
star
34

Hello-Pixels

The Hello World of Pixels
Swift
4
star
35

EuclidDemo

RealityKit Bool Demo with Euclid
Swift
4
star
36

BindingOperators

SwiftUI Binding Operators
Swift
4
star
37

Resolution

4K, 1080p and iPhone Resolutions
Swift
3
star
38

DisplayLink

iOS, tvOS, watchOS & macOS
Swift
3
star
39

Source-Calculator

Xcode Extension
Swift
3
star
40

tox_diff

This is a TouchDesigner .tox diff tool.
3
star
41

PixelTransitions

Transitions for Views in iOS
Swift
3
star
42

CodableGraphics

Codabillity for AsyncGraphics
Swift
3
star
43

manabi

学び
Swift
2
star
44

Sora

Swift
2
star
45

CoreGraphicsExtensions

Common Operator Overloading
Swift
2
star
46

Live-Graphics

Swift Package Collection
2
star
47

PixelMerger

Merge Videos with custom Resolution & FPS
Swift
2
star
48

WebsiteResultBuilder

Write HTML & CSS in Swift
Swift
2
star
49

ref_scan

op reference search scan
Python
2
star
50

Pixels-HDR

HDR Exposure stacking with Pixels
Swift
2
star
51

dome_calibration_pattern

2
star
52

geo__bezier_curve

TouchDesigner - Bezier Curve
2
star
53

PixelColor

Codable Color Struct
Swift
2
star
54

AssetManager

Import, export and share files on iOS and macOS
Swift
2
star
55

KeyColor

Extract Key Colors of an Image
Swift
2
star
56

LiveColorPIX

PixelKit Demo
Swift
2
star
57

heestand-xyz

Heestand XYZ
1
star
58

Transparency

Transparent Images
Swift
1
star
59

Xcode-Progress

Live Build Progress from Xcode
C
1
star
60

3d360

scripts to manage slicing and merging of raw images to generate a 3d equirectangular map for vr
Python
1
star
61

VideoFrames

Convert between Video and Image Frames
Swift
1
star
62

oneline

compress code to one line
Python
1
star
63

GEO3D

a 3D Protocol
Swift
1
star
64

Frequent-Finder

a "Finder" that sorts files and folders based on frequent visits
Swift
1
star