Skip to content

Commit

Permalink
Merge pull request BradLarson#1880 from tbveralrud/master
Browse files Browse the repository at this point in the history
Implement shouldResizeBlurRadiusWithImageSize feature for blurs.
  • Loading branch information
BradLarson committed Jan 24, 2015
2 parents eecb459 + 7172fc4 commit 5186c19
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion framework/Source/GPUImageGaussianBlurFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
@property (readwrite, nonatomic) CGFloat blurRadiusInPixels;

/** Setting these properties will allow the blur radius to scale with the size of the image
/** Setting these properties will allow the blur radius to scale with the size of the image. These properties are mutually exclusive; setting either will set the other to 0.
*/
@property (readwrite, nonatomic) CGFloat blurRadiusAsFractionOfImageWidth;
@property (readwrite, nonatomic) CGFloat blurRadiusAsFractionOfImageHeight;
Expand Down
29 changes: 27 additions & 2 deletions framework/Source/GPUImageGaussianBlurFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,16 @@ - (void)setupFilterForSize:(CGSize)filterFrameSize;
{
[super setupFilterForSize:filterFrameSize];

if (shouldResizeBlurRadiusWithImageSize == YES)
if (shouldResizeBlurRadiusWithImageSize)
{

if (self.blurRadiusAsFractionOfImageWidth > 0)
{
self.blurRadiusInPixels = filterFrameSize.width * self.blurRadiusAsFractionOfImageWidth;
}
else
{
self.blurRadiusInPixels = filterFrameSize.height * self.blurRadiusAsFractionOfImageHeight;
}
}
}

Expand Down Expand Up @@ -485,4 +492,22 @@ - (void)setBlurRadiusInPixels:(CGFloat)newValue;
shouldResizeBlurRadiusWithImageSize = NO;
}

- (void)setBlurRadiusAsFractionOfImageWidth:(CGFloat)blurRadiusAsFractionOfImageWidth
{
if (blurRadiusAsFractionOfImageWidth < 0) return;

shouldResizeBlurRadiusWithImageSize = _blurRadiusAsFractionOfImageWidth != blurRadiusAsFractionOfImageWidth && blurRadiusAsFractionOfImageWidth > 0;
_blurRadiusAsFractionOfImageWidth = blurRadiusAsFractionOfImageWidth;
_blurRadiusAsFractionOfImageHeight = 0;
}

- (void)setBlurRadiusAsFractionOfImageHeight:(CGFloat)blurRadiusAsFractionOfImageHeight
{
if (blurRadiusAsFractionOfImageHeight < 0) return;

shouldResizeBlurRadiusWithImageSize = _blurRadiusAsFractionOfImageHeight != blurRadiusAsFractionOfImageHeight && blurRadiusAsFractionOfImageHeight > 0;
_blurRadiusAsFractionOfImageHeight = blurRadiusAsFractionOfImageHeight;
_blurRadiusAsFractionOfImageWidth = 0;
}

@end

0 comments on commit 5186c19

Please sign in to comment.