Move Silica structures into their own file
This commit is contained in:
parent
5dd85f1989
commit
ac740e653a
3 changed files with 99 additions and 94 deletions
|
@ -12,6 +12,7 @@
|
|||
030F70112415C6B500A43F01 /* PreviewViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 030F700F2415C6B500A43F01 /* PreviewViewController.xib */; };
|
||||
030F70162415C6B500A43F01 /* QuickLook.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 030F70082415C6B500A43F01 /* QuickLook.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||
03328514285A2AB700AEEBF3 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03328513285A2AB700AEEBF3 /* Extensions.swift */; };
|
||||
03328516285A32FD00AEEBF3 /* SilicaDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03328515285A32FD00AEEBF3 /* SilicaDocument.swift */; };
|
||||
035D1A0426F0927200B332BE /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035D19F826F0927200B332BE /* ViewController.swift */; };
|
||||
035D1A0526F0927200B332BE /* cbridge.c in Sources */ = {isa = PBXBuildFile; fileRef = 035D19FA26F0927200B332BE /* cbridge.c */; };
|
||||
035D1A0626F0927200B332BE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 035D19FB26F0927200B332BE /* Assets.xcassets */; };
|
||||
|
@ -103,6 +104,7 @@
|
|||
030F70122415C6B500A43F01 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
030F70132415C6B500A43F01 /* Quicklook.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Quicklook.entitlements; sourceTree = "<group>"; };
|
||||
03328513285A2AB700AEEBF3 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
|
||||
03328515285A32FD00AEEBF3 /* SilicaDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilicaDocument.swift; sourceTree = "<group>"; };
|
||||
035D19F826F0927200B332BE /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
||||
035D19F926F0927200B332BE /* SilicaViewer.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = SilicaViewer.entitlements; sourceTree = "<group>"; };
|
||||
035D19FA26F0927200B332BE /* cbridge.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cbridge.c; sourceTree = "<group>"; };
|
||||
|
@ -248,6 +250,7 @@
|
|||
0371996627BACD8700EE1DFD /* ExportAccessoryView.xib */,
|
||||
0371996827BACDE800EE1DFD /* ExportAccessoryView.swift */,
|
||||
03328513285A2AB700AEEBF3 /* Extensions.swift */,
|
||||
03328515285A32FD00AEEBF3 /* SilicaDocument.swift */,
|
||||
);
|
||||
path = SilicaViewer;
|
||||
sourceTree = "<group>";
|
||||
|
@ -514,6 +517,7 @@
|
|||
035D1A0A26F0927200B332BE /* AppDelegate.swift in Sources */,
|
||||
03328514285A2AB700AEEBF3 /* Extensions.swift in Sources */,
|
||||
035D1A0B26F0927200B332BE /* TimelapseViewController.swift in Sources */,
|
||||
03328516285A32FD00AEEBF3 /* SilicaDocument.swift in Sources */,
|
||||
035D1A0426F0927200B332BE /* ViewController.swift in Sources */,
|
||||
035D1A0526F0927200B332BE /* cbridge.c in Sources */,
|
||||
035D1A0826F0927200B332BE /* InfoViewController.swift in Sources */,
|
||||
|
|
|
@ -4,100 +4,6 @@ import CoreFoundation
|
|||
import Accelerate
|
||||
import CoreMedia
|
||||
|
||||
/// Represents a image chunk
|
||||
struct SilicaChunk {
|
||||
var x: Int = 0
|
||||
var y: Int = 0
|
||||
var image: CGImage?
|
||||
}
|
||||
|
||||
/// Supported Silica blend modes, including extended blend modes
|
||||
enum BlendMode : Int {
|
||||
case Normal = 0,
|
||||
Multiply = 1,
|
||||
Screen = 2,
|
||||
Add = 3,
|
||||
Lighten = 4,
|
||||
Exclusion = 5,
|
||||
Difference = 6,
|
||||
Subtract = 7,
|
||||
LinearBurn = 8,
|
||||
ColorDodge = 9,
|
||||
ColorBurn = 10,
|
||||
Overlay = 11,
|
||||
HardLight = 12,
|
||||
Color = 13,
|
||||
Luminosity = 14,
|
||||
Hue = 15,
|
||||
Saturation = 16,
|
||||
SoftLight = 17,
|
||||
// TODO: where is 18?
|
||||
Darken = 19,
|
||||
|
||||
// extended modes
|
||||
HardMix = 20,
|
||||
VividLight = 21,
|
||||
LinearLight = 22,
|
||||
PinLight = 23,
|
||||
LighterColor = 24,
|
||||
DarkerColor = 25,
|
||||
Divide = 26
|
||||
}
|
||||
|
||||
/// Represents the image data for a Silica Layer, may not be an actual layer present to the user, such as a mask.
|
||||
struct SilicaLayerData {
|
||||
var blendMode: BlendMode = .Normal
|
||||
var chunks: [SilicaChunk] = []
|
||||
var opacity: Double = 1.0
|
||||
var hidden: Bool = false
|
||||
}
|
||||
|
||||
/// A Silica Layer, which equates to a real layer present in the document
|
||||
struct SilicaLayer : Equatable {
|
||||
static func == (lhs: SilicaLayer, rhs: SilicaLayer) -> Bool {
|
||||
return lhs.name == rhs.name && lhs.clipped == rhs.clipped
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
var data: SilicaLayerData = SilicaLayerData()
|
||||
var mask: SilicaLayerData?
|
||||
var clipped: Bool = false
|
||||
}
|
||||
|
||||
/// Container for the Silica Document format
|
||||
struct SilicaDocument {
|
||||
var trackedTime: Int = 0
|
||||
var tileSize: Int = 0
|
||||
var orientation: Int = 0
|
||||
var flippedHorizontally: Bool = false
|
||||
var flippedVertically: Bool = false
|
||||
var name: String = ""
|
||||
var authorName: String = ""
|
||||
var strokeCount: Int = 0
|
||||
|
||||
var backgroundColor: CGColor = .white
|
||||
var colorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB()
|
||||
|
||||
var width: Int = 0
|
||||
var height: Int = 0
|
||||
|
||||
var layers: [SilicaLayer] = []
|
||||
|
||||
var videoFrame: (Int, Int) = (0, 0)
|
||||
|
||||
lazy var nsSize = {
|
||||
return NSSize(width: width, height: height)
|
||||
}()
|
||||
|
||||
lazy var cgSize = {
|
||||
return CGSize(width: width, height: height)
|
||||
}()
|
||||
|
||||
lazy var cgRect = {
|
||||
return CGRect(origin: .zero, size: cgSize)
|
||||
}()
|
||||
}
|
||||
|
||||
func objectRefGetValue2(_ objectRef: CFTypeRef) -> UInt32 {
|
||||
let val = unsafeBitCast(objectRef, to: UInt64.self)
|
||||
|
||||
|
|
95
SilicaViewer/SilicaDocument.swift
Normal file
95
SilicaViewer/SilicaDocument.swift
Normal file
|
@ -0,0 +1,95 @@
|
|||
import Foundation
|
||||
|
||||
/// Represents a image chunk
|
||||
struct SilicaChunk {
|
||||
var x: Int = 0
|
||||
var y: Int = 0
|
||||
var image: CGImage?
|
||||
}
|
||||
|
||||
/// Supported Silica blend modes, including extended blend modes
|
||||
enum BlendMode : Int {
|
||||
case Normal = 0,
|
||||
Multiply = 1,
|
||||
Screen = 2,
|
||||
Add = 3,
|
||||
Lighten = 4,
|
||||
Exclusion = 5,
|
||||
Difference = 6,
|
||||
Subtract = 7,
|
||||
LinearBurn = 8,
|
||||
ColorDodge = 9,
|
||||
ColorBurn = 10,
|
||||
Overlay = 11,
|
||||
HardLight = 12,
|
||||
Color = 13,
|
||||
Luminosity = 14,
|
||||
Hue = 15,
|
||||
Saturation = 16,
|
||||
SoftLight = 17,
|
||||
// TODO: where is 18?
|
||||
Darken = 19,
|
||||
|
||||
// extended modes
|
||||
HardMix = 20,
|
||||
VividLight = 21,
|
||||
LinearLight = 22,
|
||||
PinLight = 23,
|
||||
LighterColor = 24,
|
||||
DarkerColor = 25,
|
||||
Divide = 26
|
||||
}
|
||||
|
||||
/// Represents the image data for a Silica Layer, may not be an actual layer present to the user, such as a mask.
|
||||
struct SilicaLayerData {
|
||||
var blendMode: BlendMode = .Normal
|
||||
var chunks: [SilicaChunk] = []
|
||||
var opacity: Double = 1.0
|
||||
var hidden: Bool = false
|
||||
}
|
||||
|
||||
/// A Silica Layer, which equates to a real layer present in the document
|
||||
struct SilicaLayer : Equatable {
|
||||
static func == (lhs: SilicaLayer, rhs: SilicaLayer) -> Bool {
|
||||
return lhs.name == rhs.name && lhs.clipped == rhs.clipped
|
||||
}
|
||||
|
||||
var name: String = ""
|
||||
var data: SilicaLayerData = SilicaLayerData()
|
||||
var mask: SilicaLayerData?
|
||||
var clipped: Bool = false
|
||||
}
|
||||
|
||||
/// Container for the Silica Document format
|
||||
struct SilicaDocument {
|
||||
var trackedTime: Int = 0
|
||||
var tileSize: Int = 0
|
||||
var orientation: Int = 0
|
||||
var flippedHorizontally: Bool = false
|
||||
var flippedVertically: Bool = false
|
||||
var name: String = ""
|
||||
var authorName: String = ""
|
||||
var strokeCount: Int = 0
|
||||
|
||||
var backgroundColor: CGColor = .white
|
||||
var colorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB()
|
||||
|
||||
var width: Int = 0
|
||||
var height: Int = 0
|
||||
|
||||
var layers: [SilicaLayer] = []
|
||||
|
||||
var videoFrame: (Int, Int) = (0, 0)
|
||||
|
||||
lazy var nsSize = {
|
||||
return NSSize(width: width, height: height)
|
||||
}()
|
||||
|
||||
lazy var cgSize = {
|
||||
return CGSize(width: width, height: height)
|
||||
}()
|
||||
|
||||
lazy var cgRect = {
|
||||
return CGRect(origin: .zero, size: cgSize)
|
||||
}()
|
||||
}
|
Reference in a new issue