Skip to content

Commit

Permalink
Got initial Swift Package Manager support working for Mac, Linux is s…
Browse files Browse the repository at this point in the history
…till non-functional.
  • Loading branch information
BradLarson committed Jun 7, 2019
1 parent 32875d8 commit bf19a4e
Show file tree
Hide file tree
Showing 35 changed files with 328 additions and 330 deletions.
33 changes: 33 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

#if os(macOS)
let platformDepedencies: [Package.Dependency] = []
let platformExcludes = ["iOS", "Linux", "Operations/Shaders"]
#elseif os(iOS)
let platformDepedencies: [Package.Dependency] = []
let platformExcludes = ["Linux", "Mac", "Operations/Shaders"]
#elseif os(Linux)
// TODO: Add back in RPi support
let platformDepedencies: [Package.Dependency] = [.package(url: "https://github.com/BradLarson/COpenGL.git", from: "1.0.2"), .package(url: "https://github.com/BradLarson/CFreeGLUT.git", from: "1.0.1"), .package(url: "https://github.com/BradLarson/CVideo4Linux.git", from: "1.0.2")]
let platformExcludes = ["iOS", "Mac", "Operations/Shaders", "Linux/RPiRenderWindow.swift", "Linux/OpenGLContext-RPi.swift", "Linux/V4LSupplement"]
#endif


let package = Package(
name: "GPUImage",
products: [
.library(
name: "GPUImage",
targets: ["GPUImage"]),
],
dependencies: platformDepedencies,
targets: [
.target(
name: "GPUImage",
path: "framework/Source",
exclude: platformExcludes),
]
)
9 changes: 5 additions & 4 deletions framework/GPUImage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@
BC1E12FD1C9F5283008F844F /* OpenGLContext_Shared.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = OpenGLContext_Shared.swift; path = Source/OpenGLContext_Shared.swift; sourceTree = "<group>"; };
BC1E13281C9F6282008F844F /* PictureInput.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PictureInput.swift; path = Source/Mac/PictureInput.swift; sourceTree = "<group>"; };
BC2C48031CB80E860085E4BC /* Crop.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Crop.swift; path = Source/Operations/Crop.swift; sourceTree = "<group>"; };
BC4C85ED1C9F042900FD95D8 /* ConvertedShaders_GL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConvertedShaders_GL.swift; path = Source/Operations/Shaders/ConvertedShaders_GL.swift; sourceTree = SOURCE_ROOT; };
BC4C85ED1C9F042900FD95D8 /* ConvertedShaders_GL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConvertedShaders_GL.swift; path = Source/Operations/ConvertedShaders_GL.swift; sourceTree = SOURCE_ROOT; };
BC4C85F01C9F054100FD95D8 /* Luminance_GL.fsh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.glsl; name = Luminance_GL.fsh; path = Source/Operations/Shaders/Luminance_GL.fsh; sourceTree = "<group>"; };
BC4C85F11C9F05EB00FD95D8 /* Luminance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Luminance.swift; path = Source/Operations/Luminance.swift; sourceTree = "<group>"; };
BC4C85F71C9F167B00FD95D8 /* Saturation_GL.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = Saturation_GL.fsh; path = Source/Operations/Shaders/Saturation_GL.fsh; sourceTree = "<group>"; };
Expand Down Expand Up @@ -582,7 +582,7 @@
BC9E35491E524DC100B8604F /* Crosshair_GLES.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = Crosshair_GLES.fsh; path = Source/Operations/Shaders/Crosshair_GLES.fsh; sourceTree = "<group>"; };
BC9E354B1E524DD400B8604F /* Line_GLES.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = Line_GLES.fsh; path = Source/Operations/Shaders/Line_GLES.fsh; sourceTree = "<group>"; };
BC9E354D1E524E0300B8604F /* Circle_GLES.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = Circle_GLES.fsh; path = Source/Operations/Shaders/Circle_GLES.fsh; sourceTree = "<group>"; };
BC9E35531E52521F00B8604F /* ConvertedShaders_GLES.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConvertedShaders_GLES.swift; path = Source/Operations/Shaders/ConvertedShaders_GLES.swift; sourceTree = SOURCE_ROOT; };
BC9E35531E52521F00B8604F /* ConvertedShaders_GLES.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConvertedShaders_GLES.swift; path = Source/Operations/ConvertedShaders_GLES.swift; sourceTree = SOURCE_ROOT; };
BC9E355C1E5252E900B8604F /* Passthrough_GLES.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = Passthrough_GLES.fsh; path = Source/Operations/Shaders/Passthrough_GLES.fsh; sourceTree = "<group>"; };
BCA4E22F1CC31276007B51BA /* Solarize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Solarize.swift; path = Source/Operations/Solarize.swift; sourceTree = "<group>"; };
BCA4E2311CC312EF007B51BA /* Solarize_GL.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = Solarize_GL.fsh; path = Source/Operations/Shaders/Solarize_GL.fsh; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1316,6 +1316,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = BC6E7CA11C39A9D8006DF678;
Expand Down Expand Up @@ -1799,7 +1800,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -1851,7 +1852,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.9;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down
51 changes: 0 additions & 51 deletions framework/Package.swift

This file was deleted.

19 changes: 10 additions & 9 deletions framework/Source/FillMode.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#if os(Linux)
import Glibc
#if GLES
import COpenGLES.gles2
#else
import COpenGL
#endif
#else
#if GLES
import OpenGLES
#else
import OpenGL.GL3

#if canImport(OpenGL)
import OpenGL.GL3
#endif

#if canImport(OpenGLES)
import OpenGLES
#endif

#if canImport(COpenGL)
import COpenGL
#endif


Expand Down
25 changes: 15 additions & 10 deletions framework/Source/Framebuffer.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#if os(Linux)
import Glibc
#if GLES
import COpenGLES.gles2
let GL_BGRA = GL_RGBA // A hack: Raspberry Pi needs this or framebuffer creation fails
#else
import COpenGL
#endif
#else
#if GLES
import OpenGLES
#else
import OpenGL.GL3

#if canImport(OpenGL)
import OpenGL.GL3
#endif

#if canImport(OpenGLES)
import OpenGLES
#endif

#if canImport(COpenGLES)
import COpenGLES.gles2
let GL_BGRA = GL_RGBA // A hack: Raspberry Pi needs this or framebuffer creation fails
#endif

#if canImport(COpenGL)
import COpenGL
#endif

import Foundation
Expand Down
22 changes: 12 additions & 10 deletions framework/Source/FramebufferCache.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#if os(Linux)
#if GLES
import COpenGLES.gles2
#else
import COpenGL
#if canImport(OpenGL)
import OpenGL.GL3
#endif
#else
#if GLES
import OpenGLES
#else
import OpenGL.GL3

#if canImport(OpenGLES)
import OpenGLES
#endif

#if canImport(COpenGLES)
import COpenGLES.gles2
#endif

#if canImport(COpenGL)
import COpenGL
#endif

// TODO: Add mechanism to purge framebuffers on low memory
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions framework/Source/Mac/MovieOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MovieOutput: ImageConsumer, AudioEncodingTarget {
return assetWriterVideoInput.transform
}
set {
assetWriterVideoInput.transform = transform
assetWriterVideoInput.transform = newValue
}
}

Expand Down Expand Up @@ -193,14 +193,14 @@ public class MovieOutput: ImageConsumer, AudioEncodingTarget {


public extension Timestamp {
public init(_ time:CMTime) {
init(_ time:CMTime) {
self.value = time.value
self.timescale = time.timescale
self.flags = TimestampFlags(rawValue:time.flags.rawValue)
self.epoch = time.epoch
}

public var asCMTime:CMTime {
var asCMTime:CMTime {
get {
return CMTimeMakeWithEpoch(value, timescale, epoch)
}
Expand Down
3 changes: 1 addition & 2 deletions framework/Source/Mac/PictureInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ public class PictureInput: ImageSource {
}

public convenience init(imageName:String, smoothlyScaleOutput:Bool = false, orientation:ImageOrientation = .portrait) {
let imageName = NSImage.Name(rawValue: imageName)
guard let image = NSImage(named:imageName) else { fatalError("No such image named: \(imageName) in your application bundle") }
guard let image = NSImage(named:NSImage.Name(imageName)) else { fatalError("No such image named: \(imageName) in your application bundle") }
self.init(image:image.cgImage(forProposedRect:nil, context:nil, hints:nil)!, smoothlyScaleOutput:smoothlyScaleOutput, orientation:orientation)
}

Expand Down
6 changes: 3 additions & 3 deletions framework/Source/Mac/PictureOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ public class PictureOutput: ImageConsumer {
}

public extension ImageSource {
public func saveNextFrameToURL(_ url:URL, format:PictureFileFormat) {
func saveNextFrameToURL(_ url:URL, format:PictureFileFormat) {
let pictureOutput = PictureOutput()
pictureOutput.saveNextFrameToURL(url, format:format)
self --> pictureOutput
}
}

public extension NSImage {
public func filterWithOperation<T:ImageProcessingOperation>(_ operation:T) -> NSImage {
func filterWithOperation<T:ImageProcessingOperation>(_ operation:T) -> NSImage {
return filterWithPipeline{input, output in
input --> operation --> output
}
}

public func filterWithPipeline(_ pipeline:(PictureInput, PictureOutput) -> ()) -> NSImage {
func filterWithPipeline(_ pipeline:(PictureInput, PictureOutput) -> ()) -> NSImage {
let picture = PictureInput(image:self)
var outputImage:NSImage?
let pictureOutput = PictureOutput()
Expand Down
4 changes: 2 additions & 2 deletions framework/Source/Matrix.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func orthographicMatrix(_ left:Float, right:Float, bottom:Float, top:Float, near

#if !os(Linux)
public extension Matrix4x4 {
public init (_ transform3D:CATransform3D) {
init (_ transform3D:CATransform3D) {
self.m11 = Float(transform3D.m11)
self.m12 = Float(transform3D.m12)
self.m13 = Float(transform3D.m13)
Expand All @@ -117,7 +117,7 @@ public extension Matrix4x4 {
self.m44 = Float(transform3D.m44)
}

public init (_ transform:CGAffineTransform) {
init (_ transform:CGAffineTransform) {
self.init(CATransform3DMakeAffineTransform(transform))
}
}
Expand Down
22 changes: 12 additions & 10 deletions framework/Source/OpenGLContext_Shared.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#if canImport(OpenGL)
import OpenGL.GL3
#endif

#if os(Linux)
#if GLES
import COpenGLES.gles2
#else
import COpenGL
#if canImport(OpenGLES)
import OpenGLES
#endif
#else
#if GLES
import OpenGLES
#else
import OpenGL.GL3

#if canImport(COpenGLES)
import COpenGLES.gles2
#endif

#if canImport(COpenGL)
import COpenGL
#endif


import Foundation

public let sharedImageProcessingContext = OpenGLContext()
Expand Down
28 changes: 15 additions & 13 deletions framework/Source/OpenGLRendering.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#if os(Linux)
#if GLES
import COpenGLES.gles2
let GL_DEPTH24_STENCIL8 = GL_DEPTH24_STENCIL8_OES
let GL_TRUE = GLboolean(1)
let GL_FALSE = GLboolean(0)
#else
import COpenGL
#if canImport(OpenGL)
import OpenGL.GL3
#endif
#else
#if GLES
import OpenGLES
#else
import OpenGL.GL3

#if canImport(OpenGLES)
import OpenGLES
#endif

#if canImport(COpenGLES)
import COpenGLES.gles2
let GL_DEPTH24_STENCIL8 = GL_DEPTH24_STENCIL8_OES
let GL_TRUE = GLboolean(1)
let GL_FALSE = GLboolean(0)
#endif

#if canImport(COpenGL)
import COpenGL
#endif

import Foundation
Expand Down
24 changes: 15 additions & 9 deletions framework/Source/Operations/AverageColorExtractor.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#if os(Linux)
import Glibc
#if GLES
import COpenGLES.gles2
#else
import COpenGL
#endif
#else
#if GLES
import OpenGLES
#else
import OpenGL.GL3

#if canImport(OpenGL)
import OpenGL.GL3
#endif

#if canImport(OpenGLES)
import OpenGLES
#endif

#if canImport(COpenGLES)
import COpenGLES.gles2
let GL_BGRA = GL_RGBA // A hack: Raspberry Pi needs this or framebuffer creation fails
#endif

#if canImport(COpenGL)
import COpenGL
#endif

import Foundation
Expand Down
Loading

0 comments on commit bf19a4e

Please sign in to comment.