Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More options for customizing the blurring effect #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions FXBlurView/FXBlurView.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
@interface UIImage (FXBlurView)

- (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor;
- (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor isMonochrome:(BOOL)isMonochrome minBrightness:(CGFloat)minBrightness maxBrightness:(CGFloat)maxBrightness overrideAlpha:(BOOL)overrideAlpha;

@end

Expand All @@ -63,6 +64,10 @@

@property (nonatomic, getter = isBlurEnabled) BOOL blurEnabled;
@property (nonatomic, getter = isDynamic) BOOL dynamic;
@property (nonatomic, getter = isMonochrome) BOOL monochrome;
@property (nonatomic, getter = isOverridingAlpha) BOOL overrideAlpha;
@property (nonatomic, assign) CGFloat minBrightness;
@property (nonatomic, assign) CGFloat maxBrightness;
@property (nonatomic, assign) NSUInteger iterations;
@property (nonatomic, assign) NSTimeInterval updateInterval;
@property (nonatomic, assign) CGFloat blurRadius;
Expand Down
38 changes: 33 additions & 5 deletions FXBlurView/FXBlurView.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@


@implementation UIImage (FXBlurView)

- (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor
- (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor {
return [self blurredImageWithRadius:radius iterations:iterations tintColor:tintColor isMonochrome:NO minBrightness:0 maxBrightness:1 overrideAlpha:YES];
}
- (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)iterations tintColor:(UIColor *)tintColor isMonochrome:(BOOL)isMonochrome minBrightness:(CGFloat)minBrightness maxBrightness:(CGFloat)maxBrightness overrideAlpha:(BOOL)overrideAlpha
{
//image must be nonzero size
if (floorf(self.size.width) * floorf(self.size.height) <= 0.0f) return self;
Expand Down Expand Up @@ -101,9 +103,26 @@ - (UIImage *)blurredImageWithRadius:(CGFloat)radius iterations:(NSUInteger)itera
//apply tint
if (tintColor && CGColorGetAlpha(tintColor.CGColor) > 0.0f)
{
CGContextSetFillColorWithColor(ctx, [tintColor colorWithAlphaComponent:0.25].CGColor);
CGContextSetBlendMode(ctx, kCGBlendModePlusLighter);
if (isMonochrome) {
CGContextSetBlendMode(ctx, kCGBlendModeColor);
} else {
CGContextSetBlendMode(ctx, kCGBlendModePlusLighter);
}
if (overrideAlpha) {
tintColor = [tintColor colorWithAlphaComponent:0.25];
}
CGContextSetFillColorWithColor(ctx, tintColor.CGColor);
CGContextFillRect(ctx, CGRectMake(0, 0, buffer1.width, buffer1.height));

if (maxBrightness - minBrightness < 1) {
CGContextSetFillColorWithColor(ctx, [UIColor colorWithWhite:maxBrightness - minBrightness alpha:1].CGColor);
CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
CGContextFillRect(ctx, CGRectMake(0, 0, buffer1.width, buffer1.height));

CGContextSetFillColorWithColor(ctx, [UIColor colorWithWhite:minBrightness alpha:1].CGColor);
CGContextSetBlendMode(ctx, kCGBlendModePlusLighter);
CGContextFillRect(ctx, CGRectMake(0, 0, buffer1.width, buffer1.height));
}
}

//create image from context
Expand Down Expand Up @@ -309,6 +328,11 @@ - (void)setUp
if (!_dynamicSet) _dynamic = YES;
if (!_blurEnabledSet) _blurEnabled = YES;
self.updateInterval = _updateInterval;
self.minBrightness = 0;
self.maxBrightness = 1;
self.monochrome = NO;
self.overrideAlpha = YES;

self.layer.magnificationFilter = @"linear"; // kCAFilterLinear

unsigned int numberOfMethods;
Expand Down Expand Up @@ -571,7 +595,11 @@ - (UIImage *)blurredSnapshot:(UIImage *)snapshot radius:(CGFloat)blurRadius
{
return [snapshot blurredImageWithRadius:blurRadius
iterations:self.iterations
tintColor:self.tintColor];
tintColor:self.tintColor
isMonochrome:self.isMonochrome
minBrightness:self.minBrightness
maxBrightness:self.maxBrightness
overrideAlpha:self.isOverridingAlpha];
}

- (void)setLayerContents:(UIImage *)image
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>7BE4F9F8-B4ED-4816-BDC6-1EA1E98D500A</string>
<key>IDESourceControlProjectName</key>
<string>FXBlurViewExample</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>E69A25C4-E035-43D9-8819-6E7D488663E1</key>
<string>https://github.com/three-tall-guys/FXBlurView.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>Tests/AnimationTest/FXBlurViewExample.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>E69A25C4-E035-43D9-8819-6E7D488663E1</key>
<string>../../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/three-tall-guys/FXBlurView.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>E69A25C4-E035-43D9-8819-6E7D488663E1</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>E69A25C4-E035-43D9-8819-6E7D488663E1</string>
<key>IDESourceControlWCCName</key>
<string>FXBlurView</string>
</dict>
</array>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "01F3118F17CA5C4600C54664"
BuildableName = "FXBlurViewExample.app"
BlueprintName = "FXBlurViewExample"
ReferencedContainer = "container:FXBlurViewExample.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "01F3118F17CA5C4600C54664"
BuildableName = "FXBlurViewExample.app"
BlueprintName = "FXBlurViewExample"
ReferencedContainer = "container:FXBlurViewExample.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "01F3118F17CA5C4600C54664"
BuildableName = "FXBlurViewExample.app"
BlueprintName = "FXBlurViewExample"
ReferencedContainer = "container:FXBlurViewExample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "01F3118F17CA5C4600C54664"
BuildableName = "FXBlurViewExample.app"
BlueprintName = "FXBlurViewExample"
ReferencedContainer = "container:FXBlurViewExample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>FXBlurViewExample.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>01F3118F17CA5C4600C54664</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
4 changes: 4 additions & 0 deletions Tests/EdgeTest/FXBlurViewExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
01F311B017CA5C4600C54664 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 01F311AE17CA5C4600C54664 /* ViewController.xib */; };
01F311BF17CA5E5600C54664 /* FXBlurView.m in Sources */ = {isa = PBXBuildFile; fileRef = 01F311BE17CA5E5600C54664 /* FXBlurView.m */; };
01F311C117CA5ECA00C54664 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01F311C017CA5ECA00C54664 /* Accelerate.framework */; };
2C955D22190CEC7D0011A979 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C955D21190CEC7D0011A979 /* QuartzCore.framework */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -39,13 +40,15 @@
01F311BD17CA5E5600C54664 /* FXBlurView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FXBlurView.h; sourceTree = "<group>"; };
01F311BE17CA5E5600C54664 /* FXBlurView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FXBlurView.m; sourceTree = "<group>"; };
01F311C017CA5ECA00C54664 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
2C955D21190CEC7D0011A979 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
01F3118D17CA5C4600C54664 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2C955D22190CEC7D0011A979 /* QuartzCore.framework in Frameworks */,
01F311C117CA5ECA00C54664 /* Accelerate.framework in Frameworks */,
01F3119417CA5C4600C54664 /* UIKit.framework in Frameworks */,
01F3119617CA5C4600C54664 /* Foundation.framework in Frameworks */,
Expand Down Expand Up @@ -77,6 +80,7 @@
01F3119217CA5C4600C54664 /* Frameworks */ = {
isa = PBXGroup;
children = (
2C955D21190CEC7D0011A979 /* QuartzCore.framework */,
01F311C017CA5ECA00C54664 /* Accelerate.framework */,
01F3119317CA5C4600C54664 /* UIKit.framework */,
01F3119517CA5C4600C54664 /* Foundation.framework */,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>AA66B166-188D-4795-88D4-ECC87DEE3772</string>
<key>IDESourceControlProjectName</key>
<string>FXBlurViewExample</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>E69A25C4-E035-43D9-8819-6E7D488663E1</key>
<string>https://github.com/three-tall-guys/FXBlurView.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>Tests/EdgeTest/FXBlurViewExample.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>E69A25C4-E035-43D9-8819-6E7D488663E1</key>
<string>../../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/three-tall-guys/FXBlurView.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>E69A25C4-E035-43D9-8819-6E7D488663E1</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>E69A25C4-E035-43D9-8819-6E7D488663E1</string>
<key>IDESourceControlWCCName</key>
<string>FXBlurView</string>
</dict>
</array>
</dict>
</plist>
Binary file not shown.
Loading