From ac740e653a4b6917f8ef7c9a321aa0533589cc5d Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 15 Jun 2022 11:34:54 -0400 Subject: [PATCH] Move Silica structures into their own file --- SilicaViewer.xcodeproj/project.pbxproj | 4 ++ SilicaViewer/Document.swift | 94 ------------------------- SilicaViewer/SilicaDocument.swift | 95 ++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 94 deletions(-) create mode 100644 SilicaViewer/SilicaDocument.swift diff --git a/SilicaViewer.xcodeproj/project.pbxproj b/SilicaViewer.xcodeproj/project.pbxproj index 77d7a48..9333a00 100644 --- a/SilicaViewer.xcodeproj/project.pbxproj +++ b/SilicaViewer.xcodeproj/project.pbxproj @@ -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 = ""; }; 030F70132415C6B500A43F01 /* Quicklook.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Quicklook.entitlements; sourceTree = ""; }; 03328513285A2AB700AEEBF3 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = ""; }; + 03328515285A32FD00AEEBF3 /* SilicaDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilicaDocument.swift; sourceTree = ""; }; 035D19F826F0927200B332BE /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 035D19F926F0927200B332BE /* SilicaViewer.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = SilicaViewer.entitlements; sourceTree = ""; }; 035D19FA26F0927200B332BE /* cbridge.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cbridge.c; sourceTree = ""; }; @@ -248,6 +250,7 @@ 0371996627BACD8700EE1DFD /* ExportAccessoryView.xib */, 0371996827BACDE800EE1DFD /* ExportAccessoryView.swift */, 03328513285A2AB700AEEBF3 /* Extensions.swift */, + 03328515285A32FD00AEEBF3 /* SilicaDocument.swift */, ); path = SilicaViewer; sourceTree = ""; @@ -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 */, diff --git a/SilicaViewer/Document.swift b/SilicaViewer/Document.swift index b660db6..aa03594 100644 --- a/SilicaViewer/Document.swift +++ b/SilicaViewer/Document.swift @@ -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) diff --git a/SilicaViewer/SilicaDocument.swift b/SilicaViewer/SilicaDocument.swift new file mode 100644 index 0000000..f1bb0be --- /dev/null +++ b/SilicaViewer/SilicaDocument.swift @@ -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) + }() +}