├── ChromaKeyEffect.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── c4q.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist └── ChromaKeyEffect ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json ├── Contents.json ├── down_arrow.imageset │ ├── Contents.json │ └── icons8-double_down_filled.png ├── squidward_green_screen.imageset │ ├── Contents.json │ └── Screen_Shot_2019-03-18_at_5.26.53_PM.jpg ├── underwater.imageset │ ├── Contents.json │ └── yannis-papanastasopoulos-340526-unsplash.jpg └── up_arrow.imageset │ ├── Contents.json │ └── icons8-double_up_filled.png ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── README.md ├── Utilities └── ChromaKey.swift ├── View Controllers ├── CompositeImageViewController.swift ├── ForegroundViewController.swift └── PixelMapViewController.swift └── Views ├── CompositedImageView.swift ├── ForegroundView.swift └── MappedImageView.swift /ChromaKeyEffect.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 814272AE225CEA0A00157A24 /* ForegroundView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 814272AD225CEA0A00157A24 /* ForegroundView.swift */; }; 11 | 814272B0225D16DC00157A24 /* PixelMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 814272AF225D16DC00157A24 /* PixelMapViewController.swift */; }; 12 | 814272B2225D184300157A24 /* CompositeImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 814272B1225D184300157A24 /* CompositeImageViewController.swift */; }; 13 | 814272B4225D189F00157A24 /* MappedImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 814272B3225D189F00157A24 /* MappedImageView.swift */; }; 14 | 814272B6225D18B600157A24 /* CompositedImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 814272B5225D18B600157A24 /* CompositedImageView.swift */; }; 15 | 816A0A1B225A6CAA00F4A38C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 816A0A1A225A6CAA00F4A38C /* AppDelegate.swift */; }; 16 | 816A0A20225A6CAA00F4A38C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 816A0A1E225A6CAA00F4A38C /* Main.storyboard */; }; 17 | 816A0A22225A6CAE00F4A38C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 816A0A21225A6CAE00F4A38C /* Assets.xcassets */; }; 18 | 816A0A25225A6CAE00F4A38C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 816A0A23225A6CAE00F4A38C /* LaunchScreen.storyboard */; }; 19 | 816A0A35225A967400F4A38C /* ChromaKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 816A0A34225A967400F4A38C /* ChromaKey.swift */; }; 20 | 81B512C7226959A0007C71B5 /* ForegroundViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81B512C6226959A0007C71B5 /* ForegroundViewController.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXFileReference section */ 24 | 814272AD225CEA0A00157A24 /* ForegroundView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForegroundView.swift; sourceTree = ""; }; 25 | 814272AF225D16DC00157A24 /* PixelMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PixelMapViewController.swift; sourceTree = ""; }; 26 | 814272B1225D184300157A24 /* CompositeImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompositeImageViewController.swift; sourceTree = ""; }; 27 | 814272B3225D189F00157A24 /* MappedImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MappedImageView.swift; sourceTree = ""; }; 28 | 814272B5225D18B600157A24 /* CompositedImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompositedImageView.swift; sourceTree = ""; }; 29 | 816A0A17225A6CAA00F4A38C /* ChromaKeyEffect.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ChromaKeyEffect.app; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 816A0A1A225A6CAA00F4A38C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 31 | 816A0A1F225A6CAA00F4A38C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 32 | 816A0A21225A6CAE00F4A38C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 33 | 816A0A24225A6CAE00F4A38C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 34 | 816A0A26225A6CAE00F4A38C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 816A0A34225A967400F4A38C /* ChromaKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChromaKey.swift; sourceTree = ""; }; 36 | 81B512C6226959A0007C71B5 /* ForegroundViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForegroundViewController.swift; sourceTree = ""; }; 37 | /* End PBXFileReference section */ 38 | 39 | /* Begin PBXFrameworksBuildPhase section */ 40 | 816A0A14225A6CAA00F4A38C /* Frameworks */ = { 41 | isa = PBXFrameworksBuildPhase; 42 | buildActionMask = 2147483647; 43 | files = ( 44 | ); 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXFrameworksBuildPhase section */ 48 | 49 | /* Begin PBXGroup section */ 50 | 814272AA225CE9AC00157A24 /* View Controllers */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 81B512C6226959A0007C71B5 /* ForegroundViewController.swift */, 54 | 814272AF225D16DC00157A24 /* PixelMapViewController.swift */, 55 | 814272B1225D184300157A24 /* CompositeImageViewController.swift */, 56 | ); 57 | path = "View Controllers"; 58 | sourceTree = ""; 59 | }; 60 | 814272AB225CE9D800157A24 /* Utilities */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 816A0A34225A967400F4A38C /* ChromaKey.swift */, 64 | ); 65 | path = Utilities; 66 | sourceTree = ""; 67 | }; 68 | 814272AC225CE9E200157A24 /* Views */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 814272AD225CEA0A00157A24 /* ForegroundView.swift */, 72 | 814272B3225D189F00157A24 /* MappedImageView.swift */, 73 | 814272B5225D18B600157A24 /* CompositedImageView.swift */, 74 | ); 75 | path = Views; 76 | sourceTree = ""; 77 | }; 78 | 816A0A0E225A6CAA00F4A38C = { 79 | isa = PBXGroup; 80 | children = ( 81 | 816A0A19225A6CAA00F4A38C /* ChromaKeyEffect */, 82 | 816A0A18225A6CAA00F4A38C /* Products */, 83 | ); 84 | sourceTree = ""; 85 | }; 86 | 816A0A18225A6CAA00F4A38C /* Products */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 816A0A17225A6CAA00F4A38C /* ChromaKeyEffect.app */, 90 | ); 91 | name = Products; 92 | sourceTree = ""; 93 | }; 94 | 816A0A19225A6CAA00F4A38C /* ChromaKeyEffect */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 816A0A1A225A6CAA00F4A38C /* AppDelegate.swift */, 98 | 814272AB225CE9D800157A24 /* Utilities */, 99 | 814272AC225CE9E200157A24 /* Views */, 100 | 814272AA225CE9AC00157A24 /* View Controllers */, 101 | 816A0A1E225A6CAA00F4A38C /* Main.storyboard */, 102 | 816A0A21225A6CAE00F4A38C /* Assets.xcassets */, 103 | 816A0A23225A6CAE00F4A38C /* LaunchScreen.storyboard */, 104 | 816A0A26225A6CAE00F4A38C /* Info.plist */, 105 | ); 106 | path = ChromaKeyEffect; 107 | sourceTree = ""; 108 | }; 109 | /* End PBXGroup section */ 110 | 111 | /* Begin PBXNativeTarget section */ 112 | 816A0A16225A6CAA00F4A38C /* ChromaKeyEffect */ = { 113 | isa = PBXNativeTarget; 114 | buildConfigurationList = 816A0A29225A6CAE00F4A38C /* Build configuration list for PBXNativeTarget "ChromaKeyEffect" */; 115 | buildPhases = ( 116 | 816A0A13225A6CAA00F4A38C /* Sources */, 117 | 816A0A14225A6CAA00F4A38C /* Frameworks */, 118 | 816A0A15225A6CAA00F4A38C /* Resources */, 119 | ); 120 | buildRules = ( 121 | ); 122 | dependencies = ( 123 | ); 124 | name = ChromaKeyEffect; 125 | productName = ChromaKeyEffect; 126 | productReference = 816A0A17225A6CAA00F4A38C /* ChromaKeyEffect.app */; 127 | productType = "com.apple.product-type.application"; 128 | }; 129 | /* End PBXNativeTarget section */ 130 | 131 | /* Begin PBXProject section */ 132 | 816A0A0F225A6CAA00F4A38C /* Project object */ = { 133 | isa = PBXProject; 134 | attributes = { 135 | LastSwiftUpdateCheck = 1010; 136 | LastUpgradeCheck = 1010; 137 | ORGANIZATIONNAME = "Vikash Hart"; 138 | TargetAttributes = { 139 | 816A0A16225A6CAA00F4A38C = { 140 | CreatedOnToolsVersion = 10.1; 141 | }; 142 | }; 143 | }; 144 | buildConfigurationList = 816A0A12225A6CAA00F4A38C /* Build configuration list for PBXProject "ChromaKeyEffect" */; 145 | compatibilityVersion = "Xcode 9.3"; 146 | developmentRegion = en; 147 | hasScannedForEncodings = 0; 148 | knownRegions = ( 149 | en, 150 | Base, 151 | ); 152 | mainGroup = 816A0A0E225A6CAA00F4A38C; 153 | productRefGroup = 816A0A18225A6CAA00F4A38C /* Products */; 154 | projectDirPath = ""; 155 | projectRoot = ""; 156 | targets = ( 157 | 816A0A16225A6CAA00F4A38C /* ChromaKeyEffect */, 158 | ); 159 | }; 160 | /* End PBXProject section */ 161 | 162 | /* Begin PBXResourcesBuildPhase section */ 163 | 816A0A15225A6CAA00F4A38C /* Resources */ = { 164 | isa = PBXResourcesBuildPhase; 165 | buildActionMask = 2147483647; 166 | files = ( 167 | 816A0A25225A6CAE00F4A38C /* LaunchScreen.storyboard in Resources */, 168 | 816A0A22225A6CAE00F4A38C /* Assets.xcassets in Resources */, 169 | 816A0A20225A6CAA00F4A38C /* Main.storyboard in Resources */, 170 | ); 171 | runOnlyForDeploymentPostprocessing = 0; 172 | }; 173 | /* End PBXResourcesBuildPhase section */ 174 | 175 | /* Begin PBXSourcesBuildPhase section */ 176 | 816A0A13225A6CAA00F4A38C /* Sources */ = { 177 | isa = PBXSourcesBuildPhase; 178 | buildActionMask = 2147483647; 179 | files = ( 180 | 814272AE225CEA0A00157A24 /* ForegroundView.swift in Sources */, 181 | 816A0A35225A967400F4A38C /* ChromaKey.swift in Sources */, 182 | 814272B0225D16DC00157A24 /* PixelMapViewController.swift in Sources */, 183 | 81B512C7226959A0007C71B5 /* ForegroundViewController.swift in Sources */, 184 | 814272B6225D18B600157A24 /* CompositedImageView.swift in Sources */, 185 | 816A0A1B225A6CAA00F4A38C /* AppDelegate.swift in Sources */, 186 | 814272B4225D189F00157A24 /* MappedImageView.swift in Sources */, 187 | 814272B2225D184300157A24 /* CompositeImageViewController.swift in Sources */, 188 | ); 189 | runOnlyForDeploymentPostprocessing = 0; 190 | }; 191 | /* End PBXSourcesBuildPhase section */ 192 | 193 | /* Begin PBXVariantGroup section */ 194 | 816A0A1E225A6CAA00F4A38C /* Main.storyboard */ = { 195 | isa = PBXVariantGroup; 196 | children = ( 197 | 816A0A1F225A6CAA00F4A38C /* Base */, 198 | ); 199 | name = Main.storyboard; 200 | sourceTree = ""; 201 | }; 202 | 816A0A23225A6CAE00F4A38C /* LaunchScreen.storyboard */ = { 203 | isa = PBXVariantGroup; 204 | children = ( 205 | 816A0A24225A6CAE00F4A38C /* Base */, 206 | ); 207 | name = LaunchScreen.storyboard; 208 | sourceTree = ""; 209 | }; 210 | /* End PBXVariantGroup section */ 211 | 212 | /* Begin XCBuildConfiguration section */ 213 | 816A0A27225A6CAE00F4A38C /* Debug */ = { 214 | isa = XCBuildConfiguration; 215 | buildSettings = { 216 | ALWAYS_SEARCH_USER_PATHS = NO; 217 | CLANG_ANALYZER_NONNULL = YES; 218 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 219 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 220 | CLANG_CXX_LIBRARY = "libc++"; 221 | CLANG_ENABLE_MODULES = YES; 222 | CLANG_ENABLE_OBJC_ARC = YES; 223 | CLANG_ENABLE_OBJC_WEAK = YES; 224 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 225 | CLANG_WARN_BOOL_CONVERSION = YES; 226 | CLANG_WARN_COMMA = YES; 227 | CLANG_WARN_CONSTANT_CONVERSION = YES; 228 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 229 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 230 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 231 | CLANG_WARN_EMPTY_BODY = YES; 232 | CLANG_WARN_ENUM_CONVERSION = YES; 233 | CLANG_WARN_INFINITE_RECURSION = YES; 234 | CLANG_WARN_INT_CONVERSION = YES; 235 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 236 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 237 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 238 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 239 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 240 | CLANG_WARN_STRICT_PROTOTYPES = YES; 241 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 242 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 243 | CLANG_WARN_UNREACHABLE_CODE = YES; 244 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 245 | CODE_SIGN_IDENTITY = "iPhone Developer"; 246 | COPY_PHASE_STRIP = NO; 247 | DEBUG_INFORMATION_FORMAT = dwarf; 248 | ENABLE_STRICT_OBJC_MSGSEND = YES; 249 | ENABLE_TESTABILITY = YES; 250 | GCC_C_LANGUAGE_STANDARD = gnu11; 251 | GCC_DYNAMIC_NO_PIC = NO; 252 | GCC_NO_COMMON_BLOCKS = YES; 253 | GCC_OPTIMIZATION_LEVEL = 0; 254 | GCC_PREPROCESSOR_DEFINITIONS = ( 255 | "DEBUG=1", 256 | "$(inherited)", 257 | ); 258 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 259 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 260 | GCC_WARN_UNDECLARED_SELECTOR = YES; 261 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 262 | GCC_WARN_UNUSED_FUNCTION = YES; 263 | GCC_WARN_UNUSED_VARIABLE = YES; 264 | IPHONEOS_DEPLOYMENT_TARGET = 12.1; 265 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 266 | MTL_FAST_MATH = YES; 267 | ONLY_ACTIVE_ARCH = YES; 268 | SDKROOT = iphoneos; 269 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 270 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 271 | }; 272 | name = Debug; 273 | }; 274 | 816A0A28225A6CAE00F4A38C /* Release */ = { 275 | isa = XCBuildConfiguration; 276 | buildSettings = { 277 | ALWAYS_SEARCH_USER_PATHS = NO; 278 | CLANG_ANALYZER_NONNULL = YES; 279 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 280 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 281 | CLANG_CXX_LIBRARY = "libc++"; 282 | CLANG_ENABLE_MODULES = YES; 283 | CLANG_ENABLE_OBJC_ARC = YES; 284 | CLANG_ENABLE_OBJC_WEAK = YES; 285 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 286 | CLANG_WARN_BOOL_CONVERSION = YES; 287 | CLANG_WARN_COMMA = YES; 288 | CLANG_WARN_CONSTANT_CONVERSION = YES; 289 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 290 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 291 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 292 | CLANG_WARN_EMPTY_BODY = YES; 293 | CLANG_WARN_ENUM_CONVERSION = YES; 294 | CLANG_WARN_INFINITE_RECURSION = YES; 295 | CLANG_WARN_INT_CONVERSION = YES; 296 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 297 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 298 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 299 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 300 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 301 | CLANG_WARN_STRICT_PROTOTYPES = YES; 302 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 303 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 304 | CLANG_WARN_UNREACHABLE_CODE = YES; 305 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 306 | CODE_SIGN_IDENTITY = "iPhone Developer"; 307 | COPY_PHASE_STRIP = NO; 308 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 309 | ENABLE_NS_ASSERTIONS = NO; 310 | ENABLE_STRICT_OBJC_MSGSEND = YES; 311 | GCC_C_LANGUAGE_STANDARD = gnu11; 312 | GCC_NO_COMMON_BLOCKS = YES; 313 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 314 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 315 | GCC_WARN_UNDECLARED_SELECTOR = YES; 316 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 317 | GCC_WARN_UNUSED_FUNCTION = YES; 318 | GCC_WARN_UNUSED_VARIABLE = YES; 319 | IPHONEOS_DEPLOYMENT_TARGET = 12.1; 320 | MTL_ENABLE_DEBUG_INFO = NO; 321 | MTL_FAST_MATH = YES; 322 | SDKROOT = iphoneos; 323 | SWIFT_COMPILATION_MODE = wholemodule; 324 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 325 | VALIDATE_PRODUCT = YES; 326 | }; 327 | name = Release; 328 | }; 329 | 816A0A2A225A6CAE00F4A38C /* Debug */ = { 330 | isa = XCBuildConfiguration; 331 | buildSettings = { 332 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 333 | CODE_SIGN_STYLE = Automatic; 334 | DEVELOPMENT_TEAM = 63X7US2LVV; 335 | INFOPLIST_FILE = ChromaKeyEffect/Info.plist; 336 | LD_RUNPATH_SEARCH_PATHS = ( 337 | "$(inherited)", 338 | "@executable_path/Frameworks", 339 | ); 340 | PRODUCT_BUNDLE_IDENTIFIER = "Vikash-Hart.ChromaKeyEffect"; 341 | PRODUCT_NAME = "$(TARGET_NAME)"; 342 | SWIFT_VERSION = 4.2; 343 | TARGETED_DEVICE_FAMILY = "1,2"; 344 | }; 345 | name = Debug; 346 | }; 347 | 816A0A2B225A6CAE00F4A38C /* Release */ = { 348 | isa = XCBuildConfiguration; 349 | buildSettings = { 350 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 351 | CODE_SIGN_STYLE = Automatic; 352 | DEVELOPMENT_TEAM = 63X7US2LVV; 353 | INFOPLIST_FILE = ChromaKeyEffect/Info.plist; 354 | LD_RUNPATH_SEARCH_PATHS = ( 355 | "$(inherited)", 356 | "@executable_path/Frameworks", 357 | ); 358 | PRODUCT_BUNDLE_IDENTIFIER = "Vikash-Hart.ChromaKeyEffect"; 359 | PRODUCT_NAME = "$(TARGET_NAME)"; 360 | SWIFT_VERSION = 4.2; 361 | TARGETED_DEVICE_FAMILY = "1,2"; 362 | }; 363 | name = Release; 364 | }; 365 | /* End XCBuildConfiguration section */ 366 | 367 | /* Begin XCConfigurationList section */ 368 | 816A0A12225A6CAA00F4A38C /* Build configuration list for PBXProject "ChromaKeyEffect" */ = { 369 | isa = XCConfigurationList; 370 | buildConfigurations = ( 371 | 816A0A27225A6CAE00F4A38C /* Debug */, 372 | 816A0A28225A6CAE00F4A38C /* Release */, 373 | ); 374 | defaultConfigurationIsVisible = 0; 375 | defaultConfigurationName = Release; 376 | }; 377 | 816A0A29225A6CAE00F4A38C /* Build configuration list for PBXNativeTarget "ChromaKeyEffect" */ = { 378 | isa = XCConfigurationList; 379 | buildConfigurations = ( 380 | 816A0A2A225A6CAE00F4A38C /* Debug */, 381 | 816A0A2B225A6CAE00F4A38C /* Release */, 382 | ); 383 | defaultConfigurationIsVisible = 0; 384 | defaultConfigurationName = Release; 385 | }; 386 | /* End XCConfigurationList section */ 387 | }; 388 | rootObject = 816A0A0F225A6CAA00F4A38C /* Project object */; 389 | } 390 | -------------------------------------------------------------------------------- /ChromaKeyEffect.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ChromaKeyEffect.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ChromaKeyEffect.xcodeproj/xcuserdata/c4q.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ChromaKeyEffect.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ChromaKeyEffect/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | @UIApplicationMain 4 | class AppDelegate: UIResponder, UIApplicationDelegate { 5 | 6 | var window: UIWindow? 7 | 8 | 9 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 10 | // Override point for customization after application launch. 11 | 12 | return true 13 | } 14 | 15 | func applicationWillResignActive(_ application: UIApplication) { 16 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 17 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 18 | } 19 | 20 | func applicationDidEnterBackground(_ application: UIApplication) { 21 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 22 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 23 | } 24 | 25 | func applicationWillEnterForeground(_ application: UIApplication) { 26 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 27 | } 28 | 29 | func applicationDidBecomeActive(_ application: UIApplication) { 30 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 31 | } 32 | 33 | func applicationWillTerminate(_ application: UIApplication) { 34 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 35 | } 36 | 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /ChromaKeyEffect/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /ChromaKeyEffect/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ChromaKeyEffect/Assets.xcassets/down_arrow.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icons8-double_down_filled.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /ChromaKeyEffect/Assets.xcassets/down_arrow.imageset/icons8-double_down_filled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VikashHart/ChromaKeyEffect/a0ad47756e961af1c703c19e9053dce40cbcb5de/ChromaKeyEffect/Assets.xcassets/down_arrow.imageset/icons8-double_down_filled.png -------------------------------------------------------------------------------- /ChromaKeyEffect/Assets.xcassets/squidward_green_screen.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Screen_Shot_2019-03-18_at_5.26.53_PM.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /ChromaKeyEffect/Assets.xcassets/squidward_green_screen.imageset/Screen_Shot_2019-03-18_at_5.26.53_PM.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VikashHart/ChromaKeyEffect/a0ad47756e961af1c703c19e9053dce40cbcb5de/ChromaKeyEffect/Assets.xcassets/squidward_green_screen.imageset/Screen_Shot_2019-03-18_at_5.26.53_PM.jpg -------------------------------------------------------------------------------- /ChromaKeyEffect/Assets.xcassets/underwater.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "yannis-papanastasopoulos-340526-unsplash.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /ChromaKeyEffect/Assets.xcassets/underwater.imageset/yannis-papanastasopoulos-340526-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VikashHart/ChromaKeyEffect/a0ad47756e961af1c703c19e9053dce40cbcb5de/ChromaKeyEffect/Assets.xcassets/underwater.imageset/yannis-papanastasopoulos-340526-unsplash.jpg -------------------------------------------------------------------------------- /ChromaKeyEffect/Assets.xcassets/up_arrow.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icons8-double_up_filled.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /ChromaKeyEffect/Assets.xcassets/up_arrow.imageset/icons8-double_up_filled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VikashHart/ChromaKeyEffect/a0ad47756e961af1c703c19e9053dce40cbcb5de/ChromaKeyEffect/Assets.xcassets/up_arrow.imageset/icons8-double_up_filled.png -------------------------------------------------------------------------------- /ChromaKeyEffect/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ChromaKeyEffect/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ChromaKeyEffect/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /ChromaKeyEffect/README.md: -------------------------------------------------------------------------------- 1 | Chroma Key Effect Green Screen App 2 | 3 | Sample App to show how to create a green screen app using the Chroma Key Effect in the CoreImage framework. 4 | -------------------------------------------------------------------------------- /ChromaKeyEffect/Utilities/ChromaKey.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class ChromaKey { 4 | 5 | // Hue ranges from and to values 6 | let startRange: CGFloat = 0.3 7 | let endRange: CGFloat = 0.4 8 | 9 | // Get hue function 10 | func getHue(red: CGFloat, green: CGFloat, blue: CGFloat) -> CGFloat { 11 | let color = UIColor(red: red, green: green, blue: blue, alpha: 1) 12 | var hue: CGFloat = 0 13 | color.getHue(&hue, saturation: nil, brightness: nil, alpha: nil) 14 | return hue 15 | } 16 | 17 | // Create Chroma Key Filter function 18 | func chromaKeyFilter(fromHue: CGFloat, toHue: CGFloat) -> CIFilter? { 19 | // 1 20 | let size = 64 21 | var cubeRGB = [Float]() 22 | 23 | // 2 24 | for z in 0 ..< size { 25 | let blue = CGFloat(z) / CGFloat(size-1) 26 | for y in 0 ..< size { 27 | let green = CGFloat(y) / CGFloat(size-1) 28 | for x in 0 ..< size { 29 | let red = CGFloat(x) / CGFloat(size-1) 30 | 31 | // 3 32 | let hue = getHue(red: red, green: green, blue: blue) 33 | let alpha: CGFloat = (hue >= fromHue && hue <= toHue) ? 0: 1 34 | 35 | // 4 36 | cubeRGB.append(Float(red * alpha)) 37 | cubeRGB.append(Float(green * alpha)) 38 | cubeRGB.append(Float(blue * alpha)) 39 | cubeRGB.append(Float(alpha)) 40 | } 41 | } 42 | } 43 | 44 | let data = Data(buffer: UnsafeBufferPointer(start: &cubeRGB, count: cubeRGB.count)) 45 | 46 | // 5 47 | let colorCubeFilter = CIFilter(name: "CIColorCube", parameters: ["inputCubeDimension": size, "inputCubeData": data]) 48 | return colorCubeFilter 49 | } 50 | 51 | // Separated code 52 | // Pixel filtering function 53 | func filterPixels(foregroundCIImage: CIImage) -> CIImage { 54 | // Remove Green from the Source Image 55 | let chromaCIFilter = self.chromaKeyFilter(fromHue: startRange, toHue: endRange) 56 | chromaCIFilter?.setValue(foregroundCIImage, forKey: kCIInputImageKey) 57 | let sourceCIImageWithoutBackground = chromaCIFilter?.outputImage 58 | var image = CIImage() 59 | if let filteredImage = sourceCIImageWithoutBackground { 60 | image = filteredImage 61 | } 62 | return image 63 | } 64 | 65 | // Image compositing function 66 | func compositeImages(foregroundCIImage: CIImage, backgroundCIImage: CIImage) -> CIImage { 67 | // Composite over a Background Image 68 | let compositor = CIFilter(name:"CISourceOverCompositing") 69 | compositor?.setValue(foregroundCIImage, forKey: kCIInputImageKey) 70 | compositor?.setValue(backgroundCIImage, forKey: kCIInputBackgroundImageKey) 71 | let compositedCIImage = compositor?.outputImage 72 | var image = CIImage() 73 | if let compositeImage = compositedCIImage { 74 | image = compositeImage 75 | } 76 | return image 77 | } 78 | 79 | // Complete combined filtering and compositing function 80 | func filterAndComposite(foregroundCIImage: CIImage, backgroundCIImage: CIImage) -> CIImage? { 81 | // Remove Green from the Source Image 82 | let chromaCIFilter = self.chromaKeyFilter(fromHue: startRange, toHue: endRange) 83 | chromaCIFilter?.setValue(foregroundCIImage, forKey: kCIInputImageKey) 84 | let sourceCIImageWithoutBackground = chromaCIFilter?.outputImage 85 | 86 | // Composite over a Background Image 87 | let compositor = CIFilter(name:"CISourceOverCompositing") 88 | compositor?.setValue(sourceCIImageWithoutBackground, forKey: kCIInputImageKey) 89 | compositor?.setValue(backgroundCIImage, forKey: kCIInputBackgroundImageKey) 90 | let compositedCIImage = compositor?.outputImage 91 | 92 | return compositedCIImage 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /ChromaKeyEffect/View Controllers/CompositeImageViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class CompositeImageViewController: UIViewController { 4 | 5 | var formattedImage: CIImage? 6 | let chromaKey = ChromaKey() 7 | let compositedImageView = CompositedImageView() 8 | 9 | override func viewDidLoad() { 10 | super.viewDidLoad() 11 | view.backgroundColor = .white 12 | setupViews() 13 | } 14 | 15 | override func viewWillAppear(_ animated: Bool) { 16 | super.viewWillAppear(true) 17 | DispatchQueue.main.async { 18 | if let image = UIImage(named: "underwater"), 19 | let backgroundImage = CIImage(image: image), 20 | let filteredImage = self.formattedImage { 21 | let compositedImage = self.chromaKey.compositeImages(foregroundCIImage: filteredImage, backgroundCIImage: backgroundImage) 22 | self.compositedImageView.compositedImageView.image = UIImage(ciImage: compositedImage) 23 | } 24 | } 25 | } 26 | 27 | init(image: CIImage) { 28 | super.init(nibName: nil, bundle: nil) 29 | self.formattedImage = image 30 | } 31 | 32 | required init?(coder aDecoder: NSCoder) { 33 | fatalError() 34 | } 35 | 36 | private func setupViews() { 37 | setupCompositedImageView() 38 | } 39 | 40 | private func setupCompositedImageView() { 41 | view.addSubview(compositedImageView) 42 | compositedImageView.translatesAutoresizingMaskIntoConstraints = false 43 | NSLayoutConstraint.activate([ 44 | compositedImageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), 45 | compositedImageView.leadingAnchor.constraint(equalTo: view.leadingAnchor), 46 | compositedImageView.trailingAnchor.constraint(equalTo: view.trailingAnchor), 47 | compositedImageView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor) 48 | ]) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ChromaKeyEffect/View Controllers/ForegroundViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class ForegroundViewController: UIViewController { 4 | 5 | private let foregroundView = ForegroundView() 6 | 7 | override func viewDidLoad() { 8 | super.viewDidLoad() 9 | view.backgroundColor = .white 10 | setupViews() 11 | self.foregroundView.removeGreenButton.addTarget(self, action: #selector(removeGreen), for: .touchUpInside) 12 | } 13 | 14 | @objc func removeGreen() { 15 | guard let originalImage = foregroundView.greenScreenImage, let image = CIImage(image: originalImage) else { return } 16 | let pixelFilterVC = PixelMapViewController(image: image) 17 | self.present(pixelFilterVC, animated: true, completion: nil) 18 | } 19 | 20 | private func setupViews() { 21 | setupForegroundView() 22 | } 23 | 24 | private func setupForegroundView() { 25 | view.addSubview(foregroundView) 26 | foregroundView.translatesAutoresizingMaskIntoConstraints = false 27 | NSLayoutConstraint.activate([ 28 | foregroundView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), 29 | foregroundView.leadingAnchor.constraint(equalTo: view.leadingAnchor), 30 | foregroundView.trailingAnchor.constraint(equalTo: view.trailingAnchor), 31 | foregroundView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor) 32 | ]) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ChromaKeyEffect/View Controllers/PixelMapViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class PixelMapViewController: UIViewController { 4 | 5 | var unformattedImage: CIImage? 6 | var mappedImage = CIImage() 7 | let chromaKey = ChromaKey() 8 | let mappedImageView = MappedImageView() 9 | 10 | override func viewDidLoad() { 11 | super.viewDidLoad() 12 | view.backgroundColor = .white 13 | setupViews() 14 | self.mappedImageView.createCompositeButton.addTarget(self, action: #selector(createCompositeImage), for: .touchUpInside) 15 | } 16 | 17 | override func viewWillAppear(_ animated: Bool) { 18 | super.viewWillAppear(true) 19 | if let unfilteredImage = unformattedImage { 20 | let filteredImage = self.chromaKey.filterPixels(foregroundCIImage: unfilteredImage) 21 | mappedImage = filteredImage 22 | 23 | mappedImageView.processedImageView.image = UIImage(ciImage: filteredImage) 24 | } 25 | } 26 | 27 | init(image: CIImage) { 28 | super.init(nibName: nil, bundle: nil) 29 | self.unformattedImage = image 30 | } 31 | 32 | required init?(coder aDecoder: NSCoder) { 33 | fatalError() 34 | } 35 | 36 | @objc func createCompositeImage() { 37 | print("processing") 38 | let compositeImageVC = CompositeImageViewController(image: mappedImage) 39 | print("completed") 40 | self.present(compositeImageVC, animated: true, completion: nil) 41 | } 42 | 43 | private func setupViews() { 44 | setupMappedImageView() 45 | } 46 | 47 | private func setupMappedImageView() { 48 | view.addSubview(mappedImageView) 49 | mappedImageView.translatesAutoresizingMaskIntoConstraints = false 50 | NSLayoutConstraint.activate([ 51 | mappedImageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), 52 | mappedImageView.leadingAnchor.constraint(equalTo: view.leadingAnchor), 53 | mappedImageView.trailingAnchor.constraint(equalTo: view.trailingAnchor), 54 | mappedImageView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor) 55 | ]) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ChromaKeyEffect/Views/CompositedImageView.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class CompositedImageView: UIView { 4 | 5 | lazy var originalImageView: UIImageView = { 6 | let imageView = UIImageView() 7 | let image = UIImage(named: "squidward_green_screen") 8 | imageView.image = image 9 | imageView.contentMode = .scaleAspectFit 10 | imageView.backgroundColor = .clear 11 | imageView.layer.masksToBounds = true 12 | imageView.layer.borderColor = UIColor.red.cgColor 13 | imageView.layer.borderWidth = 4 14 | imageView.translatesAutoresizingMaskIntoConstraints = false 15 | return imageView 16 | }() 17 | 18 | lazy var downArrowImageView: UIImageView = { 19 | let imageView = UIImageView() 20 | let image = UIImage(named: "down_arrow")?.withRenderingMode(.alwaysTemplate) 21 | imageView.image = image 22 | imageView.tintColor = .black 23 | imageView.contentMode = .scaleAspectFit 24 | imageView.backgroundColor = .clear 25 | imageView.layer.masksToBounds = true 26 | imageView.translatesAutoresizingMaskIntoConstraints = false 27 | return imageView 28 | }() 29 | 30 | lazy var compositedImageView: UIImageView = { 31 | let imageView = UIImageView() 32 | imageView.contentMode = .scaleAspectFit 33 | imageView.backgroundColor = .clear 34 | imageView.layer.masksToBounds = true 35 | imageView.layer.borderColor = UIColor.green.cgColor 36 | imageView.layer.borderWidth = 5 37 | imageView.translatesAutoresizingMaskIntoConstraints = false 38 | return imageView 39 | }() 40 | 41 | lazy var upArrowImageView: UIImageView = { 42 | let imageView = UIImageView() 43 | let image = UIImage(named: "up_arrow")?.withRenderingMode(.alwaysTemplate) 44 | imageView.image = image 45 | imageView.tintColor = .black 46 | imageView.contentMode = .scaleAspectFit 47 | imageView.backgroundColor = .clear 48 | imageView.layer.masksToBounds = true 49 | imageView.translatesAutoresizingMaskIntoConstraints = false 50 | return imageView 51 | }() 52 | 53 | lazy var backgroundImageView: UIImageView = { 54 | let imageView = UIImageView() 55 | let image = UIImage(named: "underwater") 56 | imageView.image = image 57 | imageView.contentMode = .scaleAspectFit 58 | imageView.backgroundColor = .clear 59 | imageView.layer.masksToBounds = true 60 | imageView.layer.borderColor = UIColor.red.cgColor 61 | imageView.layer.borderWidth = 4 62 | imageView.translatesAutoresizingMaskIntoConstraints = false 63 | return imageView 64 | }() 65 | 66 | required init?(coder aDecoder: NSCoder) { 67 | super.init(coder: aDecoder) 68 | commonInit() 69 | } 70 | 71 | override init(frame: CGRect) { 72 | super.init(frame: .zero) 73 | commonInit() 74 | } 75 | 76 | private func commonInit() { 77 | backgroundColor = .white 78 | setupViews() 79 | } 80 | 81 | private func setupViews() { 82 | setupCompositeImageView() 83 | setupDownArrowImageView() 84 | setupUpArrowImageView() 85 | setupOriginalImageView() 86 | setupBackgroundImageView() 87 | } 88 | 89 | private func setupCompositeImageView() { 90 | addSubview(compositedImageView) 91 | NSLayoutConstraint.activate([ 92 | compositedImageView.centerXAnchor.constraint(equalTo: centerXAnchor), 93 | compositedImageView.centerYAnchor.constraint(equalTo: centerYAnchor), 94 | compositedImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20), 95 | compositedImageView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20), 96 | compositedImageView.heightAnchor.constraint(equalToConstant: 205) 97 | ]) 98 | } 99 | 100 | private func setupDownArrowImageView() { 101 | addSubview(downArrowImageView) 102 | NSLayoutConstraint.activate([ 103 | downArrowImageView.bottomAnchor.constraint(equalTo: compositedImageView.topAnchor, constant: -20), 104 | downArrowImageView.heightAnchor.constraint(equalToConstant: 40), 105 | downArrowImageView.widthAnchor.constraint(equalToConstant: 40), 106 | downArrowImageView.centerXAnchor.constraint(equalTo: centerXAnchor) 107 | ]) 108 | } 109 | 110 | private func setupUpArrowImageView() { 111 | addSubview(upArrowImageView) 112 | NSLayoutConstraint.activate([ 113 | upArrowImageView.topAnchor.constraint(equalTo: compositedImageView.bottomAnchor, constant: 20), 114 | upArrowImageView.heightAnchor.constraint(equalToConstant: 40), 115 | upArrowImageView.widthAnchor.constraint(equalToConstant: 40), 116 | upArrowImageView.centerXAnchor.constraint(equalTo: centerXAnchor) 117 | ]) 118 | } 119 | 120 | private func setupOriginalImageView() { 121 | addSubview(originalImageView) 122 | NSLayoutConstraint.activate([ 123 | originalImageView.bottomAnchor.constraint(equalTo: downArrowImageView.topAnchor, constant: -20), 124 | originalImageView.heightAnchor.constraint(equalToConstant: 180), 125 | originalImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 40), 126 | originalImageView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -40), 127 | originalImageView.centerXAnchor.constraint(equalTo: centerXAnchor) 128 | ]) 129 | } 130 | 131 | private func setupBackgroundImageView() { 132 | addSubview(backgroundImageView) 133 | NSLayoutConstraint.activate([ 134 | backgroundImageView.topAnchor.constraint(equalTo: upArrowImageView.bottomAnchor, constant: 20), 135 | backgroundImageView.heightAnchor.constraint(equalToConstant: 180), 136 | backgroundImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 40), 137 | backgroundImageView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -40), 138 | backgroundImageView.centerXAnchor.constraint(equalTo: centerXAnchor) 139 | ]) 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /ChromaKeyEffect/Views/ForegroundView.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class ForegroundView: UIView { 4 | 5 | let greenScreenImage = UIImage(named: "squidward_green_screen") 6 | 7 | lazy var foregroundImageView: UIImageView = { 8 | let imageView = UIImageView() 9 | let image = greenScreenImage 10 | imageView.image = image 11 | imageView.contentMode = .scaleAspectFit 12 | imageView.backgroundColor = .red 13 | imageView.layer.masksToBounds = true 14 | imageView.layer.borderColor = UIColor.black.cgColor 15 | imageView.layer.borderWidth = 1 16 | imageView.translatesAutoresizingMaskIntoConstraints = false 17 | return imageView 18 | }() 19 | 20 | lazy var removeGreenButton: UIButton = { 21 | let button = UIButton() 22 | button.setTitle("Remove Green", for: .normal) 23 | button.setTitleColor(.black, for: .normal) 24 | button.titleEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5) 25 | button.titleLabel?.adjustsFontSizeToFitWidth = true 26 | button.backgroundColor = .clear 27 | button.layer.cornerRadius = 10 28 | button.layer.masksToBounds = true 29 | button.layer.borderColor = UIColor.black.cgColor 30 | button.layer.borderWidth = 2 31 | button.translatesAutoresizingMaskIntoConstraints = false 32 | return button 33 | }() 34 | 35 | required init?(coder aDecoder: NSCoder) { 36 | super.init(coder: aDecoder) 37 | commonInit() 38 | } 39 | 40 | override init(frame: CGRect) { 41 | super.init(frame: .zero) 42 | commonInit() 43 | } 44 | 45 | private func commonInit() { 46 | backgroundColor = .white 47 | setupViews() 48 | } 49 | 50 | private func setupViews() { 51 | setupImageView() 52 | setupButton() 53 | } 54 | 55 | private func setupImageView() { 56 | addSubview(foregroundImageView) 57 | NSLayoutConstraint.activate([ 58 | foregroundImageView.centerXAnchor.constraint(equalTo: centerXAnchor), 59 | foregroundImageView.centerYAnchor.constraint(equalTo: centerYAnchor), 60 | foregroundImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20), 61 | foregroundImageView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20), 62 | foregroundImageView.heightAnchor.constraint(equalToConstant: 205) 63 | ]) 64 | } 65 | 66 | private func setupButton() { 67 | addSubview(removeGreenButton) 68 | NSLayoutConstraint.activate([ 69 | removeGreenButton.topAnchor.constraint(equalTo: foregroundImageView.bottomAnchor, constant: 30), 70 | removeGreenButton.centerXAnchor.constraint(equalTo: centerXAnchor) 71 | ]) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ChromaKeyEffect/Views/MappedImageView.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class MappedImageView: UIView { 4 | 5 | lazy var processedImageView: UIImageView = { 6 | let imageView = UIImageView() 7 | imageView.contentMode = .scaleAspectFit 8 | imageView.backgroundColor = .red 9 | imageView.layer.masksToBounds = true 10 | imageView.layer.borderColor = UIColor.black.cgColor 11 | imageView.layer.borderWidth = 1 12 | imageView.translatesAutoresizingMaskIntoConstraints = false 13 | return imageView 14 | }() 15 | 16 | lazy var createCompositeButton: UIButton = { 17 | let button = UIButton() 18 | button.setTitle("Create Composite Image", for: .normal) 19 | button.setTitleColor(.black, for: .normal) 20 | button.titleEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5) 21 | button.titleLabel?.adjustsFontSizeToFitWidth = true 22 | button.backgroundColor = .clear 23 | button.layer.cornerRadius = 10 24 | button.layer.masksToBounds = true 25 | button.layer.borderColor = UIColor.black.cgColor 26 | button.layer.borderWidth = 2 27 | button.translatesAutoresizingMaskIntoConstraints = false 28 | return button 29 | }() 30 | 31 | required init?(coder aDecoder: NSCoder) { 32 | super.init(coder: aDecoder) 33 | commonInit() 34 | } 35 | 36 | override init(frame: CGRect) { 37 | super.init(frame: .zero) 38 | commonInit() 39 | } 40 | 41 | private func commonInit() { 42 | backgroundColor = .white 43 | setupViews() 44 | } 45 | 46 | private func setupViews() { 47 | setupImageView() 48 | setupButton() 49 | } 50 | 51 | private func setupImageView() { 52 | addSubview(processedImageView) 53 | NSLayoutConstraint.activate([ 54 | processedImageView.centerXAnchor.constraint(equalTo: centerXAnchor), 55 | processedImageView.centerYAnchor.constraint(equalTo: centerYAnchor), 56 | processedImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20), 57 | processedImageView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20), 58 | processedImageView.heightAnchor.constraint(equalToConstant: 205) 59 | ]) 60 | } 61 | 62 | private func setupButton() { 63 | addSubview(createCompositeButton) 64 | NSLayoutConstraint.activate([ 65 | createCompositeButton.topAnchor.constraint(equalTo: processedImageView.bottomAnchor, constant: 30), 66 | createCompositeButton.centerXAnchor.constraint(equalTo: centerXAnchor) 67 | ]) 68 | } 69 | } 70 | --------------------------------------------------------------------------------