├── .gitignore ├── DDBlackWhite.podspec ├── DDBlackWhite.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ └── DDBlackWhite.xcscheme ├── DDBlackWhite ├── DDBlackWhite.h ├── DDBlackWhite.swift └── Info.plist ├── DDBlackWhiteExample ├── DDBlackWhiteExample.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── DDBlackWhiteExample │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── DDBlackWhiteViewController.swift │ ├── Info.plist │ └── ViewController.swift ├── Info └── DDBlackWhite.gif ├── LICENSE └── README.md /.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 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | Pods/ 27 | Podfile.lock 28 | 29 | # Carthage 30 | # 31 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 32 | # Carthage/Checkouts 33 | 34 | Carthage/Build 35 | -------------------------------------------------------------------------------- /DDBlackWhite.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |spec| 2 | 3 | spec.name = "DDBlackWhite" 4 | spec.platform = :ios 5 | spec.summary = "DDBlackWhite allows a user to make his image black and white" 6 | spec.requires_arc = true 7 | spec.version = "0.0.2" 8 | spec.license = { :type => "MIT", :file => "LICENSE" } 9 | spec.author = { "Dmitriy Dotsenko" => "d.dotsenko@icloud.com" } 10 | spec.homepage = "https://github.com/d-dotsenko/DDBlackWhite" 11 | spec.source = { :git => "https://github.com/d-dotsenko/DDBlackWhite.git", :tag => "#{spec.version}" } 12 | spec.frameworks = "UIKit" 13 | spec.source_files = "DDBlackWhite/**/*.{h,swift}" 14 | spec.swift_version = "4.2" 15 | spec.ios.deployment_target = "9.0" 16 | end 17 | -------------------------------------------------------------------------------- /DDBlackWhite.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F24E06F52235186800906B54 /* DDBlackWhite.h in Headers */ = {isa = PBXBuildFile; fileRef = F24E06F32235186800906B54 /* DDBlackWhite.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | F24E074B223519F500906B54 /* DDBlackWhite.swift in Sources */ = {isa = PBXBuildFile; fileRef = F24E074A223519F500906B54 /* DDBlackWhite.swift */; }; 12 | /* End PBXBuildFile section */ 13 | 14 | /* Begin PBXFileReference section */ 15 | F24E06F02235186800906B54 /* DDBlackWhite.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DDBlackWhite.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 16 | F24E06F32235186800906B54 /* DDBlackWhite.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DDBlackWhite.h; sourceTree = ""; }; 17 | F24E06F42235186800906B54 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 18 | F24E074A223519F500906B54 /* DDBlackWhite.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DDBlackWhite.swift; sourceTree = ""; }; 19 | /* End PBXFileReference section */ 20 | 21 | /* Begin PBXFrameworksBuildPhase section */ 22 | F24E06ED2235186800906B54 /* Frameworks */ = { 23 | isa = PBXFrameworksBuildPhase; 24 | buildActionMask = 2147483647; 25 | files = ( 26 | ); 27 | runOnlyForDeploymentPostprocessing = 0; 28 | }; 29 | /* End PBXFrameworksBuildPhase section */ 30 | 31 | /* Begin PBXGroup section */ 32 | F24E06E62235186800906B54 = { 33 | isa = PBXGroup; 34 | children = ( 35 | F24E06F22235186800906B54 /* DDBlackWhite */, 36 | F24E06F12235186800906B54 /* Products */, 37 | ); 38 | sourceTree = ""; 39 | }; 40 | F24E06F12235186800906B54 /* Products */ = { 41 | isa = PBXGroup; 42 | children = ( 43 | F24E06F02235186800906B54 /* DDBlackWhite.framework */, 44 | ); 45 | name = Products; 46 | sourceTree = ""; 47 | }; 48 | F24E06F22235186800906B54 /* DDBlackWhite */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | F24E06F32235186800906B54 /* DDBlackWhite.h */, 52 | F24E06F42235186800906B54 /* Info.plist */, 53 | F24E074A223519F500906B54 /* DDBlackWhite.swift */, 54 | ); 55 | path = DDBlackWhite; 56 | sourceTree = ""; 57 | }; 58 | /* End PBXGroup section */ 59 | 60 | /* Begin PBXHeadersBuildPhase section */ 61 | F24E06EB2235186800906B54 /* Headers */ = { 62 | isa = PBXHeadersBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | F24E06F52235186800906B54 /* DDBlackWhite.h in Headers */, 66 | ); 67 | runOnlyForDeploymentPostprocessing = 0; 68 | }; 69 | /* End PBXHeadersBuildPhase section */ 70 | 71 | /* Begin PBXNativeTarget section */ 72 | F24E06EF2235186800906B54 /* DDBlackWhite */ = { 73 | isa = PBXNativeTarget; 74 | buildConfigurationList = F24E06F82235186800906B54 /* Build configuration list for PBXNativeTarget "DDBlackWhite" */; 75 | buildPhases = ( 76 | F24E06EB2235186800906B54 /* Headers */, 77 | F24E06EC2235186800906B54 /* Sources */, 78 | F24E06ED2235186800906B54 /* Frameworks */, 79 | F24E06EE2235186800906B54 /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = DDBlackWhite; 86 | productName = DDBlackWhite; 87 | productReference = F24E06F02235186800906B54 /* DDBlackWhite.framework */; 88 | productType = "com.apple.product-type.framework"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | F24E06E72235186800906B54 /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastUpgradeCheck = 1010; 97 | ORGANIZATIONNAME = DD; 98 | TargetAttributes = { 99 | F24E06EF2235186800906B54 = { 100 | CreatedOnToolsVersion = 10.1; 101 | LastSwiftMigration = 1010; 102 | }; 103 | }; 104 | }; 105 | buildConfigurationList = F24E06EA2235186800906B54 /* Build configuration list for PBXProject "DDBlackWhite" */; 106 | compatibilityVersion = "Xcode 9.3"; 107 | developmentRegion = en; 108 | hasScannedForEncodings = 0; 109 | knownRegions = ( 110 | en, 111 | ); 112 | mainGroup = F24E06E62235186800906B54; 113 | productRefGroup = F24E06F12235186800906B54 /* Products */; 114 | projectDirPath = ""; 115 | projectRoot = ""; 116 | targets = ( 117 | F24E06EF2235186800906B54 /* DDBlackWhite */, 118 | ); 119 | }; 120 | /* End PBXProject section */ 121 | 122 | /* Begin PBXResourcesBuildPhase section */ 123 | F24E06EE2235186800906B54 /* Resources */ = { 124 | isa = PBXResourcesBuildPhase; 125 | buildActionMask = 2147483647; 126 | files = ( 127 | ); 128 | runOnlyForDeploymentPostprocessing = 0; 129 | }; 130 | /* End PBXResourcesBuildPhase section */ 131 | 132 | /* Begin PBXSourcesBuildPhase section */ 133 | F24E06EC2235186800906B54 /* Sources */ = { 134 | isa = PBXSourcesBuildPhase; 135 | buildActionMask = 2147483647; 136 | files = ( 137 | F24E074B223519F500906B54 /* DDBlackWhite.swift in Sources */, 138 | ); 139 | runOnlyForDeploymentPostprocessing = 0; 140 | }; 141 | /* End PBXSourcesBuildPhase section */ 142 | 143 | /* Begin XCBuildConfiguration section */ 144 | F24E06F62235186800906B54 /* Debug */ = { 145 | isa = XCBuildConfiguration; 146 | buildSettings = { 147 | ALWAYS_SEARCH_USER_PATHS = NO; 148 | CLANG_ANALYZER_NONNULL = YES; 149 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 150 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 151 | CLANG_CXX_LIBRARY = "libc++"; 152 | CLANG_ENABLE_MODULES = YES; 153 | CLANG_ENABLE_OBJC_ARC = YES; 154 | CLANG_ENABLE_OBJC_WEAK = YES; 155 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 156 | CLANG_WARN_BOOL_CONVERSION = YES; 157 | CLANG_WARN_COMMA = YES; 158 | CLANG_WARN_CONSTANT_CONVERSION = YES; 159 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 160 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 161 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 162 | CLANG_WARN_EMPTY_BODY = YES; 163 | CLANG_WARN_ENUM_CONVERSION = YES; 164 | CLANG_WARN_INFINITE_RECURSION = YES; 165 | CLANG_WARN_INT_CONVERSION = YES; 166 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 167 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 168 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 169 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 170 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 171 | CLANG_WARN_STRICT_PROTOTYPES = YES; 172 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 173 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 174 | CLANG_WARN_UNREACHABLE_CODE = YES; 175 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 176 | CODE_SIGN_IDENTITY = "iPhone Developer"; 177 | COPY_PHASE_STRIP = NO; 178 | CURRENT_PROJECT_VERSION = 1; 179 | DEBUG_INFORMATION_FORMAT = dwarf; 180 | ENABLE_STRICT_OBJC_MSGSEND = YES; 181 | ENABLE_TESTABILITY = YES; 182 | GCC_C_LANGUAGE_STANDARD = gnu11; 183 | GCC_DYNAMIC_NO_PIC = NO; 184 | GCC_NO_COMMON_BLOCKS = YES; 185 | GCC_OPTIMIZATION_LEVEL = 0; 186 | GCC_PREPROCESSOR_DEFINITIONS = ( 187 | "DEBUG=1", 188 | "$(inherited)", 189 | ); 190 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 191 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 192 | GCC_WARN_UNDECLARED_SELECTOR = YES; 193 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 194 | GCC_WARN_UNUSED_FUNCTION = YES; 195 | GCC_WARN_UNUSED_VARIABLE = YES; 196 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 197 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 198 | MTL_FAST_MATH = YES; 199 | ONLY_ACTIVE_ARCH = YES; 200 | SDKROOT = iphoneos; 201 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 202 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 203 | VERSIONING_SYSTEM = "apple-generic"; 204 | VERSION_INFO_PREFIX = ""; 205 | }; 206 | name = Debug; 207 | }; 208 | F24E06F72235186800906B54 /* Release */ = { 209 | isa = XCBuildConfiguration; 210 | buildSettings = { 211 | ALWAYS_SEARCH_USER_PATHS = NO; 212 | CLANG_ANALYZER_NONNULL = YES; 213 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 214 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 215 | CLANG_CXX_LIBRARY = "libc++"; 216 | CLANG_ENABLE_MODULES = YES; 217 | CLANG_ENABLE_OBJC_ARC = YES; 218 | CLANG_ENABLE_OBJC_WEAK = YES; 219 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 220 | CLANG_WARN_BOOL_CONVERSION = YES; 221 | CLANG_WARN_COMMA = YES; 222 | CLANG_WARN_CONSTANT_CONVERSION = YES; 223 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 224 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 225 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 226 | CLANG_WARN_EMPTY_BODY = YES; 227 | CLANG_WARN_ENUM_CONVERSION = YES; 228 | CLANG_WARN_INFINITE_RECURSION = YES; 229 | CLANG_WARN_INT_CONVERSION = YES; 230 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 231 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 232 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 233 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 234 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 235 | CLANG_WARN_STRICT_PROTOTYPES = YES; 236 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 237 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 238 | CLANG_WARN_UNREACHABLE_CODE = YES; 239 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 240 | CODE_SIGN_IDENTITY = "iPhone Developer"; 241 | COPY_PHASE_STRIP = NO; 242 | CURRENT_PROJECT_VERSION = 1; 243 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 244 | ENABLE_NS_ASSERTIONS = NO; 245 | ENABLE_STRICT_OBJC_MSGSEND = YES; 246 | GCC_C_LANGUAGE_STANDARD = gnu11; 247 | GCC_NO_COMMON_BLOCKS = YES; 248 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 249 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 250 | GCC_WARN_UNDECLARED_SELECTOR = YES; 251 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 252 | GCC_WARN_UNUSED_FUNCTION = YES; 253 | GCC_WARN_UNUSED_VARIABLE = YES; 254 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 255 | MTL_ENABLE_DEBUG_INFO = NO; 256 | MTL_FAST_MATH = YES; 257 | SDKROOT = iphoneos; 258 | SWIFT_COMPILATION_MODE = wholemodule; 259 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 260 | VALIDATE_PRODUCT = YES; 261 | VERSIONING_SYSTEM = "apple-generic"; 262 | VERSION_INFO_PREFIX = ""; 263 | }; 264 | name = Release; 265 | }; 266 | F24E06F92235186800906B54 /* Debug */ = { 267 | isa = XCBuildConfiguration; 268 | buildSettings = { 269 | CLANG_ENABLE_MODULES = YES; 270 | CODE_SIGN_IDENTITY = ""; 271 | CODE_SIGN_STYLE = Automatic; 272 | DEFINES_MODULE = YES; 273 | DYLIB_COMPATIBILITY_VERSION = 1; 274 | DYLIB_CURRENT_VERSION = 1; 275 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 276 | INFOPLIST_FILE = DDBlackWhite/Info.plist; 277 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 278 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 279 | LD_RUNPATH_SEARCH_PATHS = ( 280 | "$(inherited)", 281 | "@executable_path/Frameworks", 282 | "@loader_path/Frameworks", 283 | ); 284 | PRODUCT_BUNDLE_IDENTIFIER = DD.DDBlackWhite; 285 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 286 | SKIP_INSTALL = YES; 287 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 288 | SWIFT_VERSION = 4.2; 289 | TARGETED_DEVICE_FAMILY = "1,2"; 290 | }; 291 | name = Debug; 292 | }; 293 | F24E06FA2235186800906B54 /* Release */ = { 294 | isa = XCBuildConfiguration; 295 | buildSettings = { 296 | CLANG_ENABLE_MODULES = YES; 297 | CODE_SIGN_IDENTITY = ""; 298 | CODE_SIGN_STYLE = Automatic; 299 | DEFINES_MODULE = YES; 300 | DYLIB_COMPATIBILITY_VERSION = 1; 301 | DYLIB_CURRENT_VERSION = 1; 302 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 303 | INFOPLIST_FILE = DDBlackWhite/Info.plist; 304 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 305 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 306 | LD_RUNPATH_SEARCH_PATHS = ( 307 | "$(inherited)", 308 | "@executable_path/Frameworks", 309 | "@loader_path/Frameworks", 310 | ); 311 | PRODUCT_BUNDLE_IDENTIFIER = DD.DDBlackWhite; 312 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 313 | SKIP_INSTALL = YES; 314 | SWIFT_VERSION = 4.2; 315 | TARGETED_DEVICE_FAMILY = "1,2"; 316 | }; 317 | name = Release; 318 | }; 319 | /* End XCBuildConfiguration section */ 320 | 321 | /* Begin XCConfigurationList section */ 322 | F24E06EA2235186800906B54 /* Build configuration list for PBXProject "DDBlackWhite" */ = { 323 | isa = XCConfigurationList; 324 | buildConfigurations = ( 325 | F24E06F62235186800906B54 /* Debug */, 326 | F24E06F72235186800906B54 /* Release */, 327 | ); 328 | defaultConfigurationIsVisible = 0; 329 | defaultConfigurationName = Release; 330 | }; 331 | F24E06F82235186800906B54 /* Build configuration list for PBXNativeTarget "DDBlackWhite" */ = { 332 | isa = XCConfigurationList; 333 | buildConfigurations = ( 334 | F24E06F92235186800906B54 /* Debug */, 335 | F24E06FA2235186800906B54 /* Release */, 336 | ); 337 | defaultConfigurationIsVisible = 0; 338 | defaultConfigurationName = Release; 339 | }; 340 | /* End XCConfigurationList section */ 341 | }; 342 | rootObject = F24E06E72235186800906B54 /* Project object */; 343 | } 344 | -------------------------------------------------------------------------------- /DDBlackWhite.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DDBlackWhite.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /DDBlackWhite.xcodeproj/xcshareddata/xcschemes/DDBlackWhite.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /DDBlackWhite/DDBlackWhite.h: -------------------------------------------------------------------------------- 1 | // 2 | // DDBlackWhite.h 3 | // DDBlackWhite 4 | // 5 | // Created by Dmitriy Dotsenko on 10/03/2019. 6 | // Copyright © 2019 Dmitriy Dotsenko. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for DDBlackWhite. 12 | FOUNDATION_EXPORT double DDBlackWhiteVersionNumber; 13 | 14 | //! Project version string for DDBlackWhite. 15 | FOUNDATION_EXPORT const unsigned char DDBlackWhiteVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /DDBlackWhite/DDBlackWhite.swift: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2019 Dmitriy Dotsenko 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | */ 23 | 24 | import UIKit 25 | 26 | open class DDBlackWhite: NSObject { 27 | 28 | /// MARK: - Public VARs 29 | 30 | /* 31 | The filter image 32 | */ 33 | open var inputImage: UIImage? { 34 | didSet { 35 | guard let image = inputImage else { 36 | return 37 | } 38 | ciImage = CIImage(image: image) 39 | setupFilter() 40 | reset() 41 | } 42 | } 43 | 44 | /* 45 | The filtered image 46 | */ 47 | open private(set) var outputImage: UIImage? 48 | 49 | /* 50 | The filter brightness value (0.0 ... 1.0) 51 | Default is 0.5 52 | */ 53 | open var brightness: CGFloat = 0.5 { 54 | didSet { 55 | reset() 56 | } 57 | } 58 | 59 | /// MARK: - Private VARs 60 | 61 | private var filter: CIFilter? 62 | private var ciImage: CIImage? 63 | 64 | /// MARK: - Public 65 | 66 | open func getFilteredImage(closure: @escaping (UIImage?)->Void) { 67 | DispatchQueue.global(qos: .background).async { [weak weakSelf = self] in 68 | guard let strongSelf = weakSelf else { 69 | return 70 | } 71 | if let outputImageCI = strongSelf.filter?.outputImage { 72 | if let outputImageCG = CIContext(options: nil).createCGImage(outputImageCI, from: outputImageCI.extent) { 73 | strongSelf.outputImage = UIImage(cgImage: outputImageCG) 74 | guard let image = strongSelf.outputImage else { 75 | closure(nil) 76 | return 77 | } 78 | closure(image) 79 | } 80 | } 81 | } 82 | } 83 | 84 | /// MARK: - Private 85 | 86 | private func setupFilter() { 87 | filter = CIFilter(name: "CIColorMonochrome") 88 | filter?.setValue(ciImage, forKey: "inputImage") 89 | filter?.setValue(1.0, forKey: "inputIntensity") 90 | } 91 | 92 | private func reset() { 93 | filter?.setValue(CIColor(red: brightness, green: brightness, blue: brightness), forKey: "inputColor") 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /DDBlackWhite/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 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /DDBlackWhiteExample/DDBlackWhiteExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F24E07272235195600906B54 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F24E07262235195600906B54 /* AppDelegate.swift */; }; 11 | F24E07292235195600906B54 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F24E07282235195600906B54 /* ViewController.swift */; }; 12 | F24E072C2235195600906B54 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F24E072A2235195600906B54 /* Main.storyboard */; }; 13 | F24E072E2235195700906B54 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F24E072D2235195700906B54 /* Assets.xcassets */; }; 14 | F24E07312235195700906B54 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F24E072F2235195700906B54 /* LaunchScreen.storyboard */; }; 15 | F24E074D2235220D00906B54 /* DDBlackWhiteViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F24E074C2235220D00906B54 /* DDBlackWhiteViewController.swift */; }; 16 | F24E074E2235261C00906B54 /* DDBlackWhite.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F24E0749223519AB00906B54 /* DDBlackWhite.framework */; }; 17 | F24E074F2235261C00906B54 /* DDBlackWhite.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F24E0749223519AB00906B54 /* DDBlackWhite.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | F24E0748223519AB00906B54 /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = F24E0744223519AB00906B54 /* DDBlackWhite.xcodeproj */; 24 | proxyType = 2; 25 | remoteGlobalIDString = F24E06F02235186800906B54; 26 | remoteInfo = DDBlackWhite; 27 | }; 28 | /* End PBXContainerItemProxy section */ 29 | 30 | /* Begin PBXCopyFilesBuildPhase section */ 31 | F24E07522235261C00906B54 /* Embed Frameworks */ = { 32 | isa = PBXCopyFilesBuildPhase; 33 | buildActionMask = 2147483647; 34 | dstPath = ""; 35 | dstSubfolderSpec = 10; 36 | files = ( 37 | F24E074F2235261C00906B54 /* DDBlackWhite.framework in Embed Frameworks */, 38 | ); 39 | name = "Embed Frameworks"; 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXCopyFilesBuildPhase section */ 43 | 44 | /* Begin PBXFileReference section */ 45 | F24E07232235195600906B54 /* DDBlackWhiteExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DDBlackWhiteExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 46 | F24E07262235195600906B54 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 47 | F24E07282235195600906B54 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 48 | F24E072B2235195600906B54 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 49 | F24E072D2235195700906B54 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 50 | F24E07302235195700906B54 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 51 | F24E07322235195700906B54 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 52 | F24E0744223519AB00906B54 /* DDBlackWhite.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = DDBlackWhite.xcodeproj; path = ../DDBlackWhite.xcodeproj; sourceTree = ""; }; 53 | F24E074C2235220D00906B54 /* DDBlackWhiteViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DDBlackWhiteViewController.swift; sourceTree = ""; }; 54 | /* End PBXFileReference section */ 55 | 56 | /* Begin PBXFrameworksBuildPhase section */ 57 | F24E07202235195600906B54 /* Frameworks */ = { 58 | isa = PBXFrameworksBuildPhase; 59 | buildActionMask = 2147483647; 60 | files = ( 61 | F24E074E2235261C00906B54 /* DDBlackWhite.framework in Frameworks */, 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | /* End PBXFrameworksBuildPhase section */ 66 | 67 | /* Begin PBXGroup section */ 68 | F24E071A2235195600906B54 = { 69 | isa = PBXGroup; 70 | children = ( 71 | F24E0744223519AB00906B54 /* DDBlackWhite.xcodeproj */, 72 | F24E07252235195600906B54 /* DDBlackWhiteExample */, 73 | F24E07242235195600906B54 /* Products */, 74 | ); 75 | sourceTree = ""; 76 | }; 77 | F24E07242235195600906B54 /* Products */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | F24E07232235195600906B54 /* DDBlackWhiteExample.app */, 81 | ); 82 | name = Products; 83 | sourceTree = ""; 84 | }; 85 | F24E07252235195600906B54 /* DDBlackWhiteExample */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | F24E07262235195600906B54 /* AppDelegate.swift */, 89 | F24E07282235195600906B54 /* ViewController.swift */, 90 | F24E074C2235220D00906B54 /* DDBlackWhiteViewController.swift */, 91 | F24E072A2235195600906B54 /* Main.storyboard */, 92 | F24E072D2235195700906B54 /* Assets.xcassets */, 93 | F24E072F2235195700906B54 /* LaunchScreen.storyboard */, 94 | F24E07322235195700906B54 /* Info.plist */, 95 | ); 96 | path = DDBlackWhiteExample; 97 | sourceTree = ""; 98 | }; 99 | F24E0745223519AB00906B54 /* Products */ = { 100 | isa = PBXGroup; 101 | children = ( 102 | F24E0749223519AB00906B54 /* DDBlackWhite.framework */, 103 | ); 104 | name = Products; 105 | sourceTree = ""; 106 | }; 107 | /* End PBXGroup section */ 108 | 109 | /* Begin PBXNativeTarget section */ 110 | F24E07222235195600906B54 /* DDBlackWhiteExample */ = { 111 | isa = PBXNativeTarget; 112 | buildConfigurationList = F24E07352235195700906B54 /* Build configuration list for PBXNativeTarget "DDBlackWhiteExample" */; 113 | buildPhases = ( 114 | F24E071F2235195600906B54 /* Sources */, 115 | F24E07202235195600906B54 /* Frameworks */, 116 | F24E07212235195600906B54 /* Resources */, 117 | F24E07522235261C00906B54 /* Embed Frameworks */, 118 | ); 119 | buildRules = ( 120 | ); 121 | dependencies = ( 122 | ); 123 | name = DDBlackWhiteExample; 124 | productName = DDBlackWhiteExample; 125 | productReference = F24E07232235195600906B54 /* DDBlackWhiteExample.app */; 126 | productType = "com.apple.product-type.application"; 127 | }; 128 | /* End PBXNativeTarget section */ 129 | 130 | /* Begin PBXProject section */ 131 | F24E071B2235195600906B54 /* Project object */ = { 132 | isa = PBXProject; 133 | attributes = { 134 | LastSwiftUpdateCheck = 1010; 135 | LastUpgradeCheck = 1010; 136 | ORGANIZATIONNAME = DD; 137 | TargetAttributes = { 138 | F24E07222235195600906B54 = { 139 | CreatedOnToolsVersion = 10.1; 140 | }; 141 | }; 142 | }; 143 | buildConfigurationList = F24E071E2235195600906B54 /* Build configuration list for PBXProject "DDBlackWhiteExample" */; 144 | compatibilityVersion = "Xcode 9.3"; 145 | developmentRegion = en; 146 | hasScannedForEncodings = 0; 147 | knownRegions = ( 148 | en, 149 | Base, 150 | ); 151 | mainGroup = F24E071A2235195600906B54; 152 | productRefGroup = F24E07242235195600906B54 /* Products */; 153 | projectDirPath = ""; 154 | projectReferences = ( 155 | { 156 | ProductGroup = F24E0745223519AB00906B54 /* Products */; 157 | ProjectRef = F24E0744223519AB00906B54 /* DDBlackWhite.xcodeproj */; 158 | }, 159 | ); 160 | projectRoot = ""; 161 | targets = ( 162 | F24E07222235195600906B54 /* DDBlackWhiteExample */, 163 | ); 164 | }; 165 | /* End PBXProject section */ 166 | 167 | /* Begin PBXReferenceProxy section */ 168 | F24E0749223519AB00906B54 /* DDBlackWhite.framework */ = { 169 | isa = PBXReferenceProxy; 170 | fileType = wrapper.framework; 171 | path = DDBlackWhite.framework; 172 | remoteRef = F24E0748223519AB00906B54 /* PBXContainerItemProxy */; 173 | sourceTree = BUILT_PRODUCTS_DIR; 174 | }; 175 | /* End PBXReferenceProxy section */ 176 | 177 | /* Begin PBXResourcesBuildPhase section */ 178 | F24E07212235195600906B54 /* Resources */ = { 179 | isa = PBXResourcesBuildPhase; 180 | buildActionMask = 2147483647; 181 | files = ( 182 | F24E07312235195700906B54 /* LaunchScreen.storyboard in Resources */, 183 | F24E072E2235195700906B54 /* Assets.xcassets in Resources */, 184 | F24E072C2235195600906B54 /* Main.storyboard in Resources */, 185 | ); 186 | runOnlyForDeploymentPostprocessing = 0; 187 | }; 188 | /* End PBXResourcesBuildPhase section */ 189 | 190 | /* Begin PBXSourcesBuildPhase section */ 191 | F24E071F2235195600906B54 /* Sources */ = { 192 | isa = PBXSourcesBuildPhase; 193 | buildActionMask = 2147483647; 194 | files = ( 195 | F24E074D2235220D00906B54 /* DDBlackWhiteViewController.swift in Sources */, 196 | F24E07292235195600906B54 /* ViewController.swift in Sources */, 197 | F24E07272235195600906B54 /* AppDelegate.swift in Sources */, 198 | ); 199 | runOnlyForDeploymentPostprocessing = 0; 200 | }; 201 | /* End PBXSourcesBuildPhase section */ 202 | 203 | /* Begin PBXVariantGroup section */ 204 | F24E072A2235195600906B54 /* Main.storyboard */ = { 205 | isa = PBXVariantGroup; 206 | children = ( 207 | F24E072B2235195600906B54 /* Base */, 208 | ); 209 | name = Main.storyboard; 210 | sourceTree = ""; 211 | }; 212 | F24E072F2235195700906B54 /* LaunchScreen.storyboard */ = { 213 | isa = PBXVariantGroup; 214 | children = ( 215 | F24E07302235195700906B54 /* Base */, 216 | ); 217 | name = LaunchScreen.storyboard; 218 | sourceTree = ""; 219 | }; 220 | /* End PBXVariantGroup section */ 221 | 222 | /* Begin XCBuildConfiguration section */ 223 | F24E07332235195700906B54 /* Debug */ = { 224 | isa = XCBuildConfiguration; 225 | buildSettings = { 226 | ALWAYS_SEARCH_USER_PATHS = NO; 227 | CLANG_ANALYZER_NONNULL = YES; 228 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 229 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 230 | CLANG_CXX_LIBRARY = "libc++"; 231 | CLANG_ENABLE_MODULES = YES; 232 | CLANG_ENABLE_OBJC_ARC = YES; 233 | CLANG_ENABLE_OBJC_WEAK = YES; 234 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 235 | CLANG_WARN_BOOL_CONVERSION = YES; 236 | CLANG_WARN_COMMA = YES; 237 | CLANG_WARN_CONSTANT_CONVERSION = YES; 238 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 239 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 240 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 241 | CLANG_WARN_EMPTY_BODY = YES; 242 | CLANG_WARN_ENUM_CONVERSION = YES; 243 | CLANG_WARN_INFINITE_RECURSION = YES; 244 | CLANG_WARN_INT_CONVERSION = YES; 245 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 246 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 247 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 248 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 249 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 250 | CLANG_WARN_STRICT_PROTOTYPES = YES; 251 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 252 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 253 | CLANG_WARN_UNREACHABLE_CODE = YES; 254 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 255 | CODE_SIGN_IDENTITY = "iPhone Developer"; 256 | COPY_PHASE_STRIP = NO; 257 | DEBUG_INFORMATION_FORMAT = dwarf; 258 | ENABLE_STRICT_OBJC_MSGSEND = YES; 259 | ENABLE_TESTABILITY = YES; 260 | GCC_C_LANGUAGE_STANDARD = gnu11; 261 | GCC_DYNAMIC_NO_PIC = NO; 262 | GCC_NO_COMMON_BLOCKS = YES; 263 | GCC_OPTIMIZATION_LEVEL = 0; 264 | GCC_PREPROCESSOR_DEFINITIONS = ( 265 | "DEBUG=1", 266 | "$(inherited)", 267 | ); 268 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 269 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 270 | GCC_WARN_UNDECLARED_SELECTOR = YES; 271 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 272 | GCC_WARN_UNUSED_FUNCTION = YES; 273 | GCC_WARN_UNUSED_VARIABLE = YES; 274 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 275 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 276 | MTL_FAST_MATH = YES; 277 | ONLY_ACTIVE_ARCH = YES; 278 | SDKROOT = iphoneos; 279 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 280 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 281 | }; 282 | name = Debug; 283 | }; 284 | F24E07342235195700906B54 /* Release */ = { 285 | isa = XCBuildConfiguration; 286 | buildSettings = { 287 | ALWAYS_SEARCH_USER_PATHS = NO; 288 | CLANG_ANALYZER_NONNULL = YES; 289 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 290 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 291 | CLANG_CXX_LIBRARY = "libc++"; 292 | CLANG_ENABLE_MODULES = YES; 293 | CLANG_ENABLE_OBJC_ARC = YES; 294 | CLANG_ENABLE_OBJC_WEAK = YES; 295 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 296 | CLANG_WARN_BOOL_CONVERSION = YES; 297 | CLANG_WARN_COMMA = YES; 298 | CLANG_WARN_CONSTANT_CONVERSION = YES; 299 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 300 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 301 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 302 | CLANG_WARN_EMPTY_BODY = YES; 303 | CLANG_WARN_ENUM_CONVERSION = YES; 304 | CLANG_WARN_INFINITE_RECURSION = YES; 305 | CLANG_WARN_INT_CONVERSION = YES; 306 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 307 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 308 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 309 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 310 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 311 | CLANG_WARN_STRICT_PROTOTYPES = YES; 312 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 313 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 314 | CLANG_WARN_UNREACHABLE_CODE = YES; 315 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 316 | CODE_SIGN_IDENTITY = "iPhone Developer"; 317 | COPY_PHASE_STRIP = NO; 318 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 319 | ENABLE_NS_ASSERTIONS = NO; 320 | ENABLE_STRICT_OBJC_MSGSEND = YES; 321 | GCC_C_LANGUAGE_STANDARD = gnu11; 322 | GCC_NO_COMMON_BLOCKS = YES; 323 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 324 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 325 | GCC_WARN_UNDECLARED_SELECTOR = YES; 326 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 327 | GCC_WARN_UNUSED_FUNCTION = YES; 328 | GCC_WARN_UNUSED_VARIABLE = YES; 329 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 330 | MTL_ENABLE_DEBUG_INFO = NO; 331 | MTL_FAST_MATH = YES; 332 | SDKROOT = iphoneos; 333 | SWIFT_COMPILATION_MODE = wholemodule; 334 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 335 | VALIDATE_PRODUCT = YES; 336 | }; 337 | name = Release; 338 | }; 339 | F24E07362235195700906B54 /* Debug */ = { 340 | isa = XCBuildConfiguration; 341 | buildSettings = { 342 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 343 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 344 | CODE_SIGN_STYLE = Automatic; 345 | INFOPLIST_FILE = DDBlackWhiteExample/Info.plist; 346 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 347 | LD_RUNPATH_SEARCH_PATHS = ( 348 | "$(inherited)", 349 | "@executable_path/Frameworks", 350 | ); 351 | PRODUCT_BUNDLE_IDENTIFIER = DD.DDBlackWhiteExample; 352 | PRODUCT_NAME = "$(TARGET_NAME)"; 353 | SWIFT_VERSION = 4.2; 354 | TARGETED_DEVICE_FAMILY = "1,2"; 355 | }; 356 | name = Debug; 357 | }; 358 | F24E07372235195700906B54 /* Release */ = { 359 | isa = XCBuildConfiguration; 360 | buildSettings = { 361 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 362 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 363 | CODE_SIGN_STYLE = Automatic; 364 | INFOPLIST_FILE = DDBlackWhiteExample/Info.plist; 365 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 366 | LD_RUNPATH_SEARCH_PATHS = ( 367 | "$(inherited)", 368 | "@executable_path/Frameworks", 369 | ); 370 | PRODUCT_BUNDLE_IDENTIFIER = DD.DDBlackWhiteExample; 371 | PRODUCT_NAME = "$(TARGET_NAME)"; 372 | SWIFT_VERSION = 4.2; 373 | TARGETED_DEVICE_FAMILY = "1,2"; 374 | }; 375 | name = Release; 376 | }; 377 | /* End XCBuildConfiguration section */ 378 | 379 | /* Begin XCConfigurationList section */ 380 | F24E071E2235195600906B54 /* Build configuration list for PBXProject "DDBlackWhiteExample" */ = { 381 | isa = XCConfigurationList; 382 | buildConfigurations = ( 383 | F24E07332235195700906B54 /* Debug */, 384 | F24E07342235195700906B54 /* Release */, 385 | ); 386 | defaultConfigurationIsVisible = 0; 387 | defaultConfigurationName = Release; 388 | }; 389 | F24E07352235195700906B54 /* Build configuration list for PBXNativeTarget "DDBlackWhiteExample" */ = { 390 | isa = XCConfigurationList; 391 | buildConfigurations = ( 392 | F24E07362235195700906B54 /* Debug */, 393 | F24E07372235195700906B54 /* Release */, 394 | ); 395 | defaultConfigurationIsVisible = 0; 396 | defaultConfigurationName = Release; 397 | }; 398 | /* End XCConfigurationList section */ 399 | }; 400 | rootObject = F24E071B2235195600906B54 /* Project object */; 401 | } 402 | -------------------------------------------------------------------------------- /DDBlackWhiteExample/DDBlackWhiteExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DDBlackWhiteExample/DDBlackWhiteExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /DDBlackWhiteExample/DDBlackWhiteExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // DDBlackWhiteExample 4 | // 5 | // Created by Dmitriy Dotsenko on 10/03/2019. 6 | // Copyright © 2019 Dmitriy Dotsenko. 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: [UIApplication.LaunchOptionsKey: 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 invalidate graphics rendering callbacks. 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 active 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 | -------------------------------------------------------------------------------- /DDBlackWhiteExample/DDBlackWhiteExample/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 | } -------------------------------------------------------------------------------- /DDBlackWhiteExample/DDBlackWhiteExample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /DDBlackWhiteExample/DDBlackWhiteExample/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 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /DDBlackWhiteExample/DDBlackWhiteExample/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 | 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 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /DDBlackWhiteExample/DDBlackWhiteExample/DDBlackWhiteViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DDBlackWhiteViewController.swift 3 | // DDBlackWhiteExample 4 | // 5 | // Created by Dmitriy Dotsenko on 10/03/2019. 6 | // Copyright © 2019 Dmitriy Dotsenko. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import DDBlackWhite 11 | 12 | class DDBlackWhiteViewController: UIViewController { 13 | 14 | @IBOutlet weak var imageView: UIImageView! 15 | @IBOutlet weak var slider: UISlider! 16 | @IBOutlet weak var valueLabel: UILabel! 17 | 18 | public var inputImage:UIImage? 19 | public var completionClosure: ((UIImage?)->Void)? 20 | 21 | private let blackWhite = DDBlackWhite() 22 | private var previousSliderValue:Float = 0.5 23 | 24 | override func viewDidLoad() { 25 | super.viewDidLoad() 26 | view.backgroundColor = UIColor.white 27 | slider.minimumValue = 0 28 | slider.maximumValue = 1 29 | slider.value = 0.5 30 | slider.addTarget(self, action: #selector(sliderValueChanged), for: .valueChanged) 31 | 32 | blackWhite.inputImage = inputImage?.fixOrientation() 33 | blackWhite.brightness = CGFloat(slider.value) 34 | blackWhite.getFilteredImage { [weak weakSelf = self] (image) in 35 | weakSelf?.updateImage(image: image) 36 | } 37 | } 38 | 39 | @objc private func sliderValueChanged() { 40 | let newValue = roundf(slider.value*10) / 10.0 41 | slider.value = newValue 42 | valueLabel.text = String(format: "%.1f", newValue) 43 | if abs(newValue - previousSliderValue) < 0.1 { 44 | return 45 | } 46 | previousSliderValue = newValue 47 | blackWhite.brightness = CGFloat(newValue) 48 | blackWhite.getFilteredImage { [weak weakSelf = self] (image) in 49 | weakSelf?.updateImage(image: image) 50 | } 51 | } 52 | 53 | private func updateImage(image: UIImage?) { 54 | DispatchQueue.main.async { [weak weakSelf = self] in 55 | weakSelf?.imageView.image = image 56 | if let closure = weakSelf?.completionClosure { 57 | closure(image) 58 | } 59 | } 60 | } 61 | } 62 | 63 | extension UIImage { 64 | func fixOrientation() -> UIImage { 65 | if imageOrientation == .up { 66 | return self 67 | } 68 | UIGraphicsBeginImageContextWithOptions(size, false, scale) 69 | draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height)) 70 | if let normalizedImage: UIImage = UIGraphicsGetImageFromCurrentImageContext() { 71 | UIGraphicsEndImageContext() 72 | return normalizedImage 73 | } 74 | return self 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /DDBlackWhiteExample/DDBlackWhiteExample/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 | -------------------------------------------------------------------------------- /DDBlackWhiteExample/DDBlackWhiteExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // DDBlackWhiteExample 4 | // 5 | // Created by Dmitriy Dotsenko on 10/03/2019. 6 | // Copyright © 2019 Dmitriy Dotsenko. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | @IBOutlet weak var imageView: UIImageView! 14 | @IBOutlet weak var filteredImageView: UIImageView! 15 | 16 | var image: UIImage? 17 | 18 | override func viewDidAppear(_ animated: Bool) { 19 | super.viewDidAppear(animated) 20 | 21 | let editItem = UIBarButtonItem(barButtonSystemItem: .edit, 22 | target: self, 23 | action: #selector(openEdit)) 24 | 25 | let libraryItem = UIBarButtonItem(barButtonSystemItem: .camera, 26 | target: self, 27 | action: #selector(openLibrary)) 28 | 29 | self.navigationItem.leftBarButtonItem = libraryItem 30 | self.navigationItem.rightBarButtonItem = editItem 31 | 32 | if (self.image == nil) { 33 | openLibrary() 34 | } 35 | } 36 | 37 | @objc func openLibrary() { 38 | let pickerView = UIImagePickerController.init() 39 | pickerView.delegate = self 40 | pickerView.sourceType = UIImagePickerController.SourceType.photoLibrary 41 | 42 | present(pickerView, animated: true, completion: nil) 43 | } 44 | 45 | @objc func openEdit() { 46 | guard let image = image else { 47 | return 48 | } 49 | self.edit(image: image) 50 | } 51 | 52 | func edit(image: UIImage) { 53 | performSegue(withIdentifier: "ShowBlackWhite", sender: nil) 54 | } 55 | 56 | override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 57 | if let vc = segue.destination as? DDBlackWhiteViewController { 58 | vc.inputImage = image 59 | vc.completionClosure = { [weak weakSelf = self] (image) in 60 | weakSelf?.imageView.image = weakSelf?.image 61 | weakSelf?.filteredImageView.image = image 62 | } 63 | } 64 | } 65 | } 66 | 67 | extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { 68 | public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { 69 | guard let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else { 70 | return 71 | } 72 | self.image = image 73 | picker.dismiss(animated: true) { 74 | self.edit(image: image) 75 | } 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /Info/DDBlackWhite.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d-dotsenko/DDBlackWhite/8deb0b69c4b3db8606afeba35ca502f7fee72bd5/Info/DDBlackWhite.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Dmitriy Dotsenko 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DDBlackWhite 2 | 3 | [![Language](http://img.shields.io/badge/language-swift-brightgreen.svg?style=flat)](https://developer.apple.com/swift) 4 | [![Platform](https://img.shields.io/cocoapods/p/DDBlackWhite.svg?style=flat)](http://cocoapods.org/pods/DDBlackWhite) 5 | [![License](https://img.shields.io/cocoapods/l/DDBlackWhite.svg?style=flat)](http://cocoapods.org/pods/DDBlackWhite) 6 | [![Version](https://img.shields.io/cocoapods/v/DDBlackWhite.svg?style=flat)](http://cocoapods.org/pods/DDBlackWhite) 7 | 8 | 9 | Make your image black and white 10 | 11 | DDBlackWhite 12 | 13 | ## Installation 14 | 15 | ### CocoaPods 16 | 17 | To install `DDBlackWhite` via [CocoaPods](http://cocoapods.org), add the following line to your Podfile: 18 | 19 | ``` 20 | pod 'DDBlackWhite' 21 | ``` 22 | 23 | After installing the cocoapod into your project import `DDBlackWhite` with: 24 | 25 | ``` 26 | import DDBlackWhite 27 | ``` 28 | 29 | ### Carthage 30 | 31 | To install `DDBlackWhite` via [Carthage](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos), add the following line to your Cartfile: 32 | 33 | ``` 34 | github "d-dotsenko/DDBlackWhite" 35 | ``` 36 | 37 | And then run: 38 | 39 | ``` 40 | carthage update 41 | ``` 42 | 43 | ### Manually 44 | 45 | Add `DDBlackWhite` folder to your Xcode project. 46 | 47 | ## Usage 48 | 49 | See the example Xcode project. 50 | 51 | ### Basic setup 52 | 53 | Create the `DDBlackWhite` instance, set the `inputImage` and `brightness` variables. 54 | Call `getFilteredImage` method and its closure will return the filtered image. 55 | 56 | ```swift 57 | let blackWhite = DDBlackWhite() 58 | blackWhite.inputImage = image 59 | blackWhite.brightness = 0.8 60 | blackWhite.getFilteredImage { (image) in 61 | // filtered image received 62 | } 63 | ``` 64 | 65 | ### Populating the data 66 | 67 | ```swift 68 | var inputImage: UIImage? 69 | private(set) var outputImage: UIImage? 70 | var brightness: CGFloat // The filter brightness value (0.0 ... 1.0), Default is 0.5 71 | 72 | func getFilteredImage(closure: @escaping (UIImage?)->Void) 73 | ``` 74 | 75 | ## Requirements 76 | 77 | - iOS 9.0 78 | - Xcode 10, Swift 4.2 79 | 80 | ## License 81 | 82 | `DDBlackWhite` is available under the MIT license. See the [LICENSE](./LICENSE) file for more info. 83 | --------------------------------------------------------------------------------