Skip to content

Commit

Permalink
Merge pull request #3 from Eskils/develop
Browse files Browse the repository at this point in the history
Fix applying gradientBlur causes unintended blurring
  • Loading branch information
Eskils authored Feb 16, 2024
2 parents bd34a6c + 343e9ec commit 74d9fcb
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let package = Package(
dependencies: [
.package(
url: "https://github.com/Eskils/VariableBlurImageView",
.upToNextMinor(from: "1.1.1") // or `.upToNextMajor
.upToNextMinor(from: "1.1.2") // or `.upToNextMajor
)
],
targets: [
Expand Down
11 changes: 9 additions & 2 deletions Sources/VariableBlurImageView/VariableBlur.metal
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,16 @@ kernel void gradientVariableBlur(
const float4 gradientValue = gradient.read(gradientGid);
const half luma = ((half)gradientValue.x + (half)gradientValue.y + (half)gradientValue.z) / 3;

half radius = max(luma * (half)maxRadius, 1.0h);
half radius = luma * (half)maxRadius;

float4 colorOut;

if (radius >= 1.0h) {
colorOut = (float4)colorForBlurAtPixel(hGid, textureIn, radius);
} else {
colorOut = textureIn.read(gid);
}

float4 colorOut = (float4)colorForBlurAtPixel(hGid, textureIn, radius);

textureOut.write(colorOut, gid);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class VariableBlurImageViewTests: XCTestCase {

let testsDirectory = URL(fileURLWithPath: #filePath + "/..").standardizedFileURL.path

let inputImageName = "GreenerOnTheOtherSide"
let inputImageName = "VariableBlurTestImage"

func testVerticalVariableBlur() throws {
XCTAssertTrue(
Expand Down Expand Up @@ -159,6 +159,25 @@ final class VariableBlurImageViewTests: XCTestCase {
)
}

func testGradientBlurSmallImageForUnintendedBlur() throws {
let inputImageName = "VariableBlurTestImageSmall"
let gradientImage = try provideInputImage(inputImageName: "TestAlpha")

XCTAssertTrue(
try isEqual(
inputImageName: inputImageName,
expectedImageName: "\(inputImageName)-GradientBlur-20",
afterPerformingImageOperations: { input in
try variableBlurEngine.applyGradientVariableBlur(
toImage: input,
withGradient: gradientImage,
maxRadius: 20
)
}
)
)
}

func testPerformanceOfGradientBlur() throws {
let inputImage = try provideInputImage(inputImageName: inputImageName)
let gradientImage = try provideInputImage(inputImageName: "TestAlpha")
Expand Down

0 comments on commit 74d9fcb

Please sign in to comment.