├── .gitignore ├── Example ├── UIImageEffects.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── UIImageEffects │ ├── AppDelegate.swift │ ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard │ ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── DisplayImage.imageset │ │ ├── 1136.png │ │ ├── 480.png │ │ ├── 960.png │ │ └── Contents.json │ ├── Info.plist │ └── ViewController.swift ├── README.md └── Source └── UIImageEffects.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | .DS_Store -------------------------------------------------------------------------------- /Example/UIImageEffects.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 117CCB241CABC5FF007AE2DD /* UIImageEffects.swift in Sources */ = {isa = PBXBuildFile; fileRef = 117CCB231CABC5FF007AE2DD /* UIImageEffects.swift */; }; 11 | 1198FE7A19C813930006983C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1198FE7919C813930006983C /* AppDelegate.swift */; }; 12 | 1198FE7C19C813930006983C /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1198FE7B19C813930006983C /* ViewController.swift */; }; 13 | 1198FE7F19C813930006983C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1198FE7D19C813930006983C /* Main.storyboard */; }; 14 | 1198FE8119C813930006983C /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1198FE8019C813930006983C /* Images.xcassets */; }; 15 | 1198FE8419C813930006983C /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1198FE8219C813930006983C /* LaunchScreen.xib */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 117CCB231CABC5FF007AE2DD /* UIImageEffects.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIImageEffects.swift; path = ../../Source/UIImageEffects.swift; sourceTree = ""; }; 20 | 1198FE7419C813930006983C /* UIImageEffects.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UIImageEffects.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 1198FE7819C813930006983C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 22 | 1198FE7919C813930006983C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 1198FE7B19C813930006983C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | 1198FE7E19C813930006983C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | 1198FE8019C813930006983C /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 26 | 1198FE8319C813930006983C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 1198FE7119C813930006983C /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | 1198FE6B19C813930006983C = { 41 | isa = PBXGroup; 42 | children = ( 43 | 1198FE7619C813930006983C /* UIImageEffects */, 44 | 1198FE7519C813930006983C /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | 1198FE7519C813930006983C /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | 1198FE7419C813930006983C /* UIImageEffects.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | 1198FE7619C813930006983C /* UIImageEffects */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 1198FE7919C813930006983C /* AppDelegate.swift */, 60 | 1198FE7B19C813930006983C /* ViewController.swift */, 61 | 117CCB231CABC5FF007AE2DD /* UIImageEffects.swift */, 62 | 1198FE7D19C813930006983C /* Main.storyboard */, 63 | 1198FE8019C813930006983C /* Images.xcassets */, 64 | 1198FE8219C813930006983C /* LaunchScreen.xib */, 65 | 1198FE7719C813930006983C /* Supporting Files */, 66 | ); 67 | path = UIImageEffects; 68 | sourceTree = ""; 69 | }; 70 | 1198FE7719C813930006983C /* Supporting Files */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 1198FE7819C813930006983C /* Info.plist */, 74 | ); 75 | name = "Supporting Files"; 76 | sourceTree = ""; 77 | }; 78 | /* End PBXGroup section */ 79 | 80 | /* Begin PBXNativeTarget section */ 81 | 1198FE7319C813930006983C /* UIImageEffects */ = { 82 | isa = PBXNativeTarget; 83 | buildConfigurationList = 1198FE9319C813930006983C /* Build configuration list for PBXNativeTarget "UIImageEffects" */; 84 | buildPhases = ( 85 | 1198FE7019C813930006983C /* Sources */, 86 | 1198FE7119C813930006983C /* Frameworks */, 87 | 1198FE7219C813930006983C /* Resources */, 88 | ); 89 | buildRules = ( 90 | ); 91 | dependencies = ( 92 | ); 93 | name = UIImageEffects; 94 | productName = UIImageEffects; 95 | productReference = 1198FE7419C813930006983C /* UIImageEffects.app */; 96 | productType = "com.apple.product-type.application"; 97 | }; 98 | /* End PBXNativeTarget section */ 99 | 100 | /* Begin PBXProject section */ 101 | 1198FE6C19C813930006983C /* Project object */ = { 102 | isa = PBXProject; 103 | attributes = { 104 | LastSwiftUpdateCheck = 0730; 105 | LastUpgradeCheck = 0910; 106 | ORGANIZATIONNAME = "Alexey Globchastyy"; 107 | TargetAttributes = { 108 | 1198FE7319C813930006983C = { 109 | CreatedOnToolsVersion = 6.1; 110 | DevelopmentTeam = 59UVCLB6AQ; 111 | LastSwiftMigration = 0800; 112 | }; 113 | }; 114 | }; 115 | buildConfigurationList = 1198FE6F19C813930006983C /* Build configuration list for PBXProject "UIImageEffects" */; 116 | compatibilityVersion = "Xcode 3.2"; 117 | developmentRegion = English; 118 | hasScannedForEncodings = 0; 119 | knownRegions = ( 120 | en, 121 | Base, 122 | ); 123 | mainGroup = 1198FE6B19C813930006983C; 124 | productRefGroup = 1198FE7519C813930006983C /* Products */; 125 | projectDirPath = ""; 126 | projectRoot = ""; 127 | targets = ( 128 | 1198FE7319C813930006983C /* UIImageEffects */, 129 | ); 130 | }; 131 | /* End PBXProject section */ 132 | 133 | /* Begin PBXResourcesBuildPhase section */ 134 | 1198FE7219C813930006983C /* Resources */ = { 135 | isa = PBXResourcesBuildPhase; 136 | buildActionMask = 2147483647; 137 | files = ( 138 | 1198FE7F19C813930006983C /* Main.storyboard in Resources */, 139 | 1198FE8419C813930006983C /* LaunchScreen.xib in Resources */, 140 | 1198FE8119C813930006983C /* Images.xcassets in Resources */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | /* End PBXResourcesBuildPhase section */ 145 | 146 | /* Begin PBXSourcesBuildPhase section */ 147 | 1198FE7019C813930006983C /* Sources */ = { 148 | isa = PBXSourcesBuildPhase; 149 | buildActionMask = 2147483647; 150 | files = ( 151 | 117CCB241CABC5FF007AE2DD /* UIImageEffects.swift in Sources */, 152 | 1198FE7C19C813930006983C /* ViewController.swift in Sources */, 153 | 1198FE7A19C813930006983C /* AppDelegate.swift in Sources */, 154 | ); 155 | runOnlyForDeploymentPostprocessing = 0; 156 | }; 157 | /* End PBXSourcesBuildPhase section */ 158 | 159 | /* Begin PBXVariantGroup section */ 160 | 1198FE7D19C813930006983C /* Main.storyboard */ = { 161 | isa = PBXVariantGroup; 162 | children = ( 163 | 1198FE7E19C813930006983C /* Base */, 164 | ); 165 | name = Main.storyboard; 166 | sourceTree = ""; 167 | }; 168 | 1198FE8219C813930006983C /* LaunchScreen.xib */ = { 169 | isa = PBXVariantGroup; 170 | children = ( 171 | 1198FE8319C813930006983C /* Base */, 172 | ); 173 | name = LaunchScreen.xib; 174 | sourceTree = ""; 175 | }; 176 | /* End PBXVariantGroup section */ 177 | 178 | /* Begin XCBuildConfiguration section */ 179 | 1198FE9119C813930006983C /* Debug */ = { 180 | isa = XCBuildConfiguration; 181 | buildSettings = { 182 | ALWAYS_SEARCH_USER_PATHS = NO; 183 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 184 | CLANG_CXX_LIBRARY = "libc++"; 185 | CLANG_ENABLE_MODULES = YES; 186 | CLANG_ENABLE_OBJC_ARC = YES; 187 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 188 | CLANG_WARN_BOOL_CONVERSION = YES; 189 | CLANG_WARN_COMMA = YES; 190 | CLANG_WARN_CONSTANT_CONVERSION = YES; 191 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 192 | CLANG_WARN_EMPTY_BODY = YES; 193 | CLANG_WARN_ENUM_CONVERSION = YES; 194 | CLANG_WARN_INFINITE_RECURSION = YES; 195 | CLANG_WARN_INT_CONVERSION = YES; 196 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 197 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 198 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 199 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 200 | CLANG_WARN_STRICT_PROTOTYPES = YES; 201 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 202 | CLANG_WARN_UNREACHABLE_CODE = YES; 203 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 204 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 205 | COPY_PHASE_STRIP = NO; 206 | ENABLE_STRICT_OBJC_MSGSEND = YES; 207 | ENABLE_TESTABILITY = YES; 208 | GCC_C_LANGUAGE_STANDARD = gnu99; 209 | GCC_DYNAMIC_NO_PIC = NO; 210 | GCC_NO_COMMON_BLOCKS = YES; 211 | GCC_OPTIMIZATION_LEVEL = 0; 212 | GCC_PREPROCESSOR_DEFINITIONS = ( 213 | "DEBUG=1", 214 | "$(inherited)", 215 | ); 216 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 217 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 218 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 219 | GCC_WARN_UNDECLARED_SELECTOR = YES; 220 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 221 | GCC_WARN_UNUSED_FUNCTION = YES; 222 | GCC_WARN_UNUSED_VARIABLE = YES; 223 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 224 | MTL_ENABLE_DEBUG_INFO = YES; 225 | ONLY_ACTIVE_ARCH = YES; 226 | SDKROOT = iphoneos; 227 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 228 | }; 229 | name = Debug; 230 | }; 231 | 1198FE9219C813930006983C /* Release */ = { 232 | isa = XCBuildConfiguration; 233 | buildSettings = { 234 | ALWAYS_SEARCH_USER_PATHS = NO; 235 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 236 | CLANG_CXX_LIBRARY = "libc++"; 237 | CLANG_ENABLE_MODULES = YES; 238 | CLANG_ENABLE_OBJC_ARC = YES; 239 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 240 | CLANG_WARN_BOOL_CONVERSION = YES; 241 | CLANG_WARN_COMMA = YES; 242 | CLANG_WARN_CONSTANT_CONVERSION = YES; 243 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 244 | CLANG_WARN_EMPTY_BODY = YES; 245 | CLANG_WARN_ENUM_CONVERSION = YES; 246 | CLANG_WARN_INFINITE_RECURSION = YES; 247 | CLANG_WARN_INT_CONVERSION = YES; 248 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 249 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 250 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 251 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 252 | CLANG_WARN_STRICT_PROTOTYPES = YES; 253 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 254 | CLANG_WARN_UNREACHABLE_CODE = YES; 255 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 256 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 257 | COPY_PHASE_STRIP = YES; 258 | ENABLE_NS_ASSERTIONS = NO; 259 | ENABLE_STRICT_OBJC_MSGSEND = YES; 260 | GCC_C_LANGUAGE_STANDARD = gnu99; 261 | GCC_NO_COMMON_BLOCKS = YES; 262 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 263 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 264 | GCC_WARN_UNDECLARED_SELECTOR = YES; 265 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 266 | GCC_WARN_UNUSED_FUNCTION = YES; 267 | GCC_WARN_UNUSED_VARIABLE = YES; 268 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 269 | MTL_ENABLE_DEBUG_INFO = NO; 270 | SDKROOT = iphoneos; 271 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 272 | VALIDATE_PRODUCT = YES; 273 | }; 274 | name = Release; 275 | }; 276 | 1198FE9419C813930006983C /* Debug */ = { 277 | isa = XCBuildConfiguration; 278 | buildSettings = { 279 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 280 | CODE_SIGN_IDENTITY = "iPhone Developer"; 281 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 282 | INFOPLIST_FILE = UIImageEffects/Info.plist; 283 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 284 | PRODUCT_BUNDLE_IDENTIFIER = "com.globchastyy.$(PRODUCT_NAME:rfc1034identifier)"; 285 | PRODUCT_NAME = "$(TARGET_NAME)"; 286 | PROVISIONING_PROFILE = ""; 287 | SWIFT_VERSION = 4.0; 288 | }; 289 | name = Debug; 290 | }; 291 | 1198FE9519C813930006983C /* Release */ = { 292 | isa = XCBuildConfiguration; 293 | buildSettings = { 294 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 295 | CODE_SIGN_IDENTITY = "iPhone Developer"; 296 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 297 | INFOPLIST_FILE = UIImageEffects/Info.plist; 298 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 299 | PRODUCT_BUNDLE_IDENTIFIER = "com.globchastyy.$(PRODUCT_NAME:rfc1034identifier)"; 300 | PRODUCT_NAME = "$(TARGET_NAME)"; 301 | PROVISIONING_PROFILE = ""; 302 | SWIFT_VERSION = 4.0; 303 | }; 304 | name = Release; 305 | }; 306 | /* End XCBuildConfiguration section */ 307 | 308 | /* Begin XCConfigurationList section */ 309 | 1198FE6F19C813930006983C /* Build configuration list for PBXProject "UIImageEffects" */ = { 310 | isa = XCConfigurationList; 311 | buildConfigurations = ( 312 | 1198FE9119C813930006983C /* Debug */, 313 | 1198FE9219C813930006983C /* Release */, 314 | ); 315 | defaultConfigurationIsVisible = 0; 316 | defaultConfigurationName = Release; 317 | }; 318 | 1198FE9319C813930006983C /* Build configuration list for PBXNativeTarget "UIImageEffects" */ = { 319 | isa = XCConfigurationList; 320 | buildConfigurations = ( 321 | 1198FE9419C813930006983C /* Debug */, 322 | 1198FE9519C813930006983C /* Release */, 323 | ); 324 | defaultConfigurationIsVisible = 0; 325 | defaultConfigurationName = Release; 326 | }; 327 | /* End XCConfigurationList section */ 328 | }; 329 | rootObject = 1198FE6C19C813930006983C /* Project object */; 330 | } 331 | -------------------------------------------------------------------------------- /Example/UIImageEffects.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/UIImageEffects/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // UIImageEffects 4 | // 5 | // Created by Alexey Globchastyy on 16/09/14. 6 | // Copyright (c) 2014 Alexey Globchastyy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // 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. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/UIImageEffects/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Example/UIImageEffects/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 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /Example/UIImageEffects/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Example/UIImageEffects/Images.xcassets/DisplayImage.imageset/1136.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/globchastyy/SwiftUIImageEffects/a73d4d70261c1dcc7ad7f4cac69cb0ceb474e66e/Example/UIImageEffects/Images.xcassets/DisplayImage.imageset/1136.png -------------------------------------------------------------------------------- /Example/UIImageEffects/Images.xcassets/DisplayImage.imageset/480.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/globchastyy/SwiftUIImageEffects/a73d4d70261c1dcc7ad7f4cac69cb0ceb474e66e/Example/UIImageEffects/Images.xcassets/DisplayImage.imageset/480.png -------------------------------------------------------------------------------- /Example/UIImageEffects/Images.xcassets/DisplayImage.imageset/960.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/globchastyy/SwiftUIImageEffects/a73d4d70261c1dcc7ad7f4cac69cb0ceb474e66e/Example/UIImageEffects/Images.xcassets/DisplayImage.imageset/960.png -------------------------------------------------------------------------------- /Example/UIImageEffects/Images.xcassets/DisplayImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "1x", 6 | "filename" : "480.png" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "2x", 11 | "filename" : "960.png" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "filename" : "1136.png", 16 | "subtype" : "retina4", 17 | "scale" : "2x" 18 | }, 19 | { 20 | "idiom" : "iphone", 21 | "scale" : "3x" 22 | } 23 | ], 24 | "info" : { 25 | "version" : 1, 26 | "author" : "xcode" 27 | } 28 | } -------------------------------------------------------------------------------- /Example/UIImageEffects/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Example/UIImageEffects/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // UIImageEffects 4 | // 5 | // Created by Alexey Globchastyy on 16/09/14. 6 | // Copyright (c) 2014 Alexey Globchastyy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | @IBOutlet weak var imageView: UIImageView! 13 | @IBOutlet weak var effectLabel: UILabel! 14 | 15 | var image: UIImage! 16 | var imageIndex: Int = 0 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | 21 | image = UIImage(named: "DisplayImage") 22 | updateImage() 23 | } 24 | 25 | @IBAction func updateImage(_ sender: UITapGestureRecognizer? = nil) { 26 | if (imageIndex > 4) { 27 | imageIndex = 0 28 | } 29 | 30 | switch(imageIndex) { 31 | case 0: 32 | imageView.image = image 33 | effectLabel.text = "None" 34 | effectLabel.textColor = UIColor.white 35 | case 1: 36 | imageView.image = image.applyLightEffect() 37 | effectLabel.text = "Light" 38 | effectLabel.textColor = UIColor.white 39 | case 2: 40 | imageView.image = image.applyExtraLightEffect() 41 | effectLabel.text = "Extra light" 42 | effectLabel.textColor = UIColor.lightGray 43 | case 3: 44 | imageView.image = image.applyDarkEffect() 45 | effectLabel.text = "Dark" 46 | effectLabel.textColor = UIColor.darkGray 47 | case 4: 48 | imageView.image = image.applyTintEffectWithColor(UIColor.blue) 49 | effectLabel.text = "Color tint" 50 | self.effectLabel.textColor = UIColor.darkGray 51 | default: 52 | break 53 | } 54 | 55 | imageIndex += 1 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SwiftUIImageEffects is swift port from Apple UIImage+ImageEffects category. Made for practicing purpose. 2 | 3 | ### Usage 4 | 5 | To use this extension just add file Source/UIImageEffects.swift to your project. See example project. 6 | 7 | ```swift 8 | image = image.applyLightEffect() 9 | image = image.applyExtraLightEffect() 10 | image = image.applyTintEffectWithColor(UIColor.blueColor()) 11 | image = image.applyBlurWithRadius(20, tintColor: UIColor(white: 0.11, alpha: 0.73), saturationDeltaFactor: 1.8) 12 | ``` 13 | 14 | ### Desription from original project: 15 | 16 | >Blurring and Tinting an Image Using the Accelerate Framework 17 | >============================================================= 18 | > 19 | >UIImageEffects shows how to create and apply blur and tint effects to an image using the vImage, Quartz, and UIKit frameworks. The vImage 20 | >framework is suited for high-performance image processing. Using vImage, your app gets all the benefits of vector processing without the need 21 | >for you to write vectorized code. 22 | > 23 | >Using the Sample 24 | >---------------- 25 | >1. Launch the UIImageEffects project using Xcode. 26 | >2. Make sure the project's current target is set to UIImageEffects. 27 | >3. Build and run the UIImageEffects target. 28 | >4. Tap the device screen (or click the simulator screen) to cycle through the effects. 29 | 30 | >You’ll notice that the app is very responsive despite the calculation-intense blur effects. 31 | > 32 | >... 33 | > 34 | >================================================== 35 | >Copyright (C) 2013 Apple Inc. All rights reserved. -------------------------------------------------------------------------------- /Source/UIImageEffects.swift: -------------------------------------------------------------------------------- 1 | /* 2 | File: UIImage+ImageEffects.m 3 | Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code you’ll want to look out to find out how to use vImage to efficiently calculate a blur. 4 | Version: 1.0 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2013 Apple Inc. All Rights Reserved. 45 | 46 | 47 | Copyright © 2013 Apple Inc. All rights reserved. 48 | WWDC 2013 License 49 | 50 | NOTE: This Apple Software was supplied by Apple as part of a WWDC 2013 51 | Session. Please refer to the applicable WWDC 2013 Session for further 52 | information. 53 | 54 | IMPORTANT: This Apple software is supplied to you by Apple Inc. 55 | ("Apple") in consideration of your agreement to the following terms, and 56 | your use, installation, modification or redistribution of this Apple 57 | software constitutes acceptance of these terms. If you do not agree with 58 | these terms, please do not use, install, modify or redistribute this 59 | Apple software. 60 | 61 | In consideration of your agreement to abide by the following terms, and 62 | subject to these terms, Apple grants you a non-exclusive license, under 63 | Apple's copyrights in this original Apple software (the "Apple 64 | Software"), to use, reproduce, modify and redistribute the Apple 65 | Software, with or without modifications, in source and/or binary forms; 66 | provided that if you redistribute the Apple Software in its entirety and 67 | without modifications, you must retain this notice and the following 68 | text and disclaimers in all such redistributions of the Apple Software. 69 | Neither the name, trademarks, service marks or logos of Apple Inc. may 70 | be used to endorse or promote products derived from the Apple Software 71 | without specific prior written permission from Apple. Except as 72 | expressly stated in this notice, no other rights or licenses, express or 73 | implied, are granted by Apple herein, including but not limited to any 74 | patent rights that may be infringed by your derivative works or by other 75 | works in which the Apple Software may be incorporated. 76 | 77 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES 78 | NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE 79 | IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR 80 | A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 81 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 82 | 83 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 84 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 85 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 86 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 87 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 88 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 89 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 90 | POSSIBILITY OF SUCH DAMAGE. 91 | 92 | EA1002 93 | 5/3/2013 94 | */ 95 | 96 | // 97 | // UIImage.swift 98 | // Today 99 | // 100 | // Created by Alexey Globchastyy on 15/09/14. 101 | // Copyright (c) 2014 Alexey Globchastyy. All rights reserved. 102 | // 103 | 104 | import UIKit 105 | import Accelerate 106 | 107 | public extension UIImage { 108 | public func applyLightEffect() -> UIImage? { 109 | return applyBlurWithRadius(30, tintColor: UIColor(white: 1.0, alpha: 0.3), saturationDeltaFactor: 1.8) 110 | } 111 | 112 | public func applyExtraLightEffect() -> UIImage? { 113 | return applyBlurWithRadius(20, tintColor: UIColor(white: 0.97, alpha: 0.82), saturationDeltaFactor: 1.8) 114 | } 115 | 116 | public func applyDarkEffect() -> UIImage? { 117 | return applyBlurWithRadius(20, tintColor: UIColor(white: 0.11, alpha: 0.73), saturationDeltaFactor: 1.8) 118 | } 119 | 120 | public func applyTintEffectWithColor(_ tintColor: UIColor) -> UIImage? { 121 | let effectColorAlpha: CGFloat = 0.6 122 | var effectColor = tintColor 123 | 124 | let componentCount = tintColor.cgColor.numberOfComponents 125 | 126 | if componentCount == 2 { 127 | var b: CGFloat = 0 128 | if tintColor.getWhite(&b, alpha: nil) { 129 | effectColor = UIColor(white: b, alpha: effectColorAlpha) 130 | } 131 | } else { 132 | var red: CGFloat = 0 133 | var green: CGFloat = 0 134 | var blue: CGFloat = 0 135 | 136 | if tintColor.getRed(&red, green: &green, blue: &blue, alpha: nil) { 137 | effectColor = UIColor(red: red, green: green, blue: blue, alpha: effectColorAlpha) 138 | } 139 | } 140 | 141 | return applyBlurWithRadius(10, tintColor: effectColor, saturationDeltaFactor: -1.0, maskImage: nil) 142 | } 143 | 144 | public func applyBlurWithRadius(_ blurRadius: CGFloat, tintColor: UIColor?, saturationDeltaFactor: CGFloat, maskImage: UIImage? = nil) -> UIImage? { 145 | // Check pre-conditions. 146 | if (size.width < 1 || size.height < 1) { 147 | print("*** error: invalid size: \(size.width) x \(size.height). Both dimensions must be >= 1: \(self)") 148 | return nil 149 | } 150 | guard let cgImage = self.cgImage else { 151 | print("*** error: image must be backed by a CGImage: \(self)") 152 | return nil 153 | } 154 | if maskImage != nil && maskImage!.cgImage == nil { 155 | print("*** error: maskImage must be backed by a CGImage: \(String(describing: maskImage))") 156 | return nil 157 | } 158 | 159 | let __FLT_EPSILON__ = CGFloat(Float.ulpOfOne) 160 | let screenScale = UIScreen.main.scale 161 | let imageRect = CGRect(origin: CGPoint.zero, size: size) 162 | var effectImage = self 163 | 164 | let hasBlur = blurRadius > __FLT_EPSILON__ 165 | let hasSaturationChange = fabs(saturationDeltaFactor - 1.0) > __FLT_EPSILON__ 166 | 167 | if hasBlur || hasSaturationChange { 168 | func createEffectBuffer(_ context: CGContext) -> vImage_Buffer { 169 | let data = context.data 170 | let width = vImagePixelCount(context.width) 171 | let height = vImagePixelCount(context.height) 172 | let rowBytes = context.bytesPerRow 173 | 174 | return vImage_Buffer(data: data, height: height, width: width, rowBytes: rowBytes) 175 | } 176 | 177 | UIGraphicsBeginImageContextWithOptions(size, false, screenScale) 178 | guard let effectInContext = UIGraphicsGetCurrentContext() else { return nil } 179 | 180 | effectInContext.scaleBy(x: 1.0, y: -1.0) 181 | effectInContext.translateBy(x: 0, y: -size.height) 182 | effectInContext.draw(cgImage, in: imageRect) 183 | 184 | var effectInBuffer = createEffectBuffer(effectInContext) 185 | 186 | 187 | UIGraphicsBeginImageContextWithOptions(size, false, screenScale) 188 | 189 | guard let effectOutContext = UIGraphicsGetCurrentContext() else { return nil } 190 | var effectOutBuffer = createEffectBuffer(effectOutContext) 191 | 192 | 193 | if hasBlur { 194 | // A description of how to compute the box kernel width from the Gaussian 195 | // radius (aka standard deviation) appears in the SVG spec: 196 | // http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement 197 | // 198 | // For larger values of 's' (s >= 2.0), an approximation can be used: Three 199 | // successive box-blurs build a piece-wise quadratic convolution kernel, which 200 | // approximates the Gaussian kernel to within roughly 3%. 201 | // 202 | // let d = floor(s * 3*sqrt(2*pi)/4 + 0.5) 203 | // 204 | // ... if d is odd, use three box-blurs of size 'd', centered on the output pixel. 205 | // 206 | 207 | let inputRadius = blurRadius * screenScale 208 | let d = floor(inputRadius * 3.0 * CGFloat(sqrt(2 * .pi) / 4 + 0.5)) 209 | var radius = UInt32(d) 210 | if radius % 2 != 1 { 211 | radius += 1 // force radius to be odd so that the three box-blur methodology works. 212 | } 213 | 214 | let imageEdgeExtendFlags = vImage_Flags(kvImageEdgeExtend) 215 | 216 | vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, nil, 0, 0, radius, radius, nil, imageEdgeExtendFlags) 217 | vImageBoxConvolve_ARGB8888(&effectOutBuffer, &effectInBuffer, nil, 0, 0, radius, radius, nil, imageEdgeExtendFlags) 218 | vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, nil, 0, 0, radius, radius, nil, imageEdgeExtendFlags) 219 | } 220 | 221 | var effectImageBuffersAreSwapped = false 222 | 223 | if hasSaturationChange { 224 | let s: CGFloat = saturationDeltaFactor 225 | let floatingPointSaturationMatrix: [CGFloat] = [ 226 | 0.0722 + 0.9278 * s, 0.0722 - 0.0722 * s, 0.0722 - 0.0722 * s, 0, 227 | 0.7152 - 0.7152 * s, 0.7152 + 0.2848 * s, 0.7152 - 0.7152 * s, 0, 228 | 0.2126 - 0.2126 * s, 0.2126 - 0.2126 * s, 0.2126 + 0.7873 * s, 0, 229 | 0, 0, 0, 1 230 | ] 231 | 232 | let divisor: CGFloat = 256 233 | let matrixSize = floatingPointSaturationMatrix.count 234 | var saturationMatrix = [Int16](repeating: 0, count: matrixSize) 235 | 236 | for i: Int in 0 ..< matrixSize { 237 | saturationMatrix[i] = Int16(round(floatingPointSaturationMatrix[i] * divisor)) 238 | } 239 | 240 | if hasBlur { 241 | vImageMatrixMultiply_ARGB8888(&effectOutBuffer, &effectInBuffer, saturationMatrix, Int32(divisor), nil, nil, vImage_Flags(kvImageNoFlags)) 242 | effectImageBuffersAreSwapped = true 243 | } else { 244 | vImageMatrixMultiply_ARGB8888(&effectInBuffer, &effectOutBuffer, saturationMatrix, Int32(divisor), nil, nil, vImage_Flags(kvImageNoFlags)) 245 | } 246 | } 247 | 248 | if !effectImageBuffersAreSwapped { 249 | effectImage = UIGraphicsGetImageFromCurrentImageContext()! 250 | } 251 | 252 | UIGraphicsEndImageContext() 253 | 254 | if effectImageBuffersAreSwapped { 255 | effectImage = UIGraphicsGetImageFromCurrentImageContext()! 256 | } 257 | 258 | UIGraphicsEndImageContext() 259 | } 260 | 261 | // Set up output context. 262 | UIGraphicsBeginImageContextWithOptions(size, false, screenScale) 263 | 264 | guard let outputContext = UIGraphicsGetCurrentContext() else { return nil } 265 | 266 | outputContext.scaleBy(x: 1.0, y: -1.0) 267 | outputContext.translateBy(x: 0, y: -size.height) 268 | 269 | // Draw base image. 270 | outputContext.draw(cgImage, in: imageRect) 271 | 272 | // Draw effect image. 273 | if hasBlur { 274 | outputContext.saveGState() 275 | if let maskCGImage = maskImage?.cgImage { 276 | outputContext.clip(to: imageRect, mask: maskCGImage); 277 | } 278 | outputContext.draw(effectImage.cgImage!, in: imageRect) 279 | outputContext.restoreGState() 280 | } 281 | 282 | // Add in color tint. 283 | if let color = tintColor { 284 | outputContext.saveGState() 285 | outputContext.setFillColor(color.cgColor) 286 | outputContext.fill(imageRect) 287 | outputContext.restoreGState() 288 | } 289 | 290 | // Output image is ready. 291 | let outputImage = UIGraphicsGetImageFromCurrentImageContext() 292 | UIGraphicsEndImageContext() 293 | 294 | return outputImage 295 | } 296 | } 297 | --------------------------------------------------------------------------------