Skip to content

Commit

Permalink
Use Int Precision w/Vips During Sharpen (#56)
Browse files Browse the repository at this point in the history
Work in #22 added automatic image sharpening for Vips. However, discovered in #55 `conv()` defaults to float precision and can leave to visual artifacts in some scenarios. Per @jcupitt recommendation, we can add `precision: :integer` to conv and this should also give us a speed-up, since int convolutions will use SIMD. #55

Fixes #55
  • Loading branch information
metaskills authored and janko committed Aug 11, 2019
1 parent 62ce311 commit 94cb723
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/image_processing/vips.rb
Expand Up @@ -140,7 +140,7 @@ def thumbnail(width, height, sharpen: SHARPEN_MASK, **options)
else
image = self.image.thumbnail_image(width, height: height, **options)
end
image = image.conv(sharpen) if sharpen
image = image.conv(sharpen, precision: :integer) if sharpen
image
end

Expand Down
20 changes: 20 additions & 0 deletions test/vips_test.rb
Expand Up @@ -174,6 +174,11 @@
normal = @pipeline.resize_to_limit!(400, 400, sharpen: false)
assert sharpened.size > normal.size, "Expected sharpened thumbnail to have bigger filesize than not sharpened thumbnail"
end

it "sharpening uses integer precision" do
sharpened = @pipeline.resize_to_limit(400, 400).call(save: false)
assert_equal :uchar, sharpened.format
end
end

describe "#resize_to_fit" do
Expand Down Expand Up @@ -217,6 +222,11 @@
normal = @pipeline.resize_to_fit!(400, 400, sharpen: false)
assert sharpened.size > normal.size, "Expected sharpened thumbnail to have bigger filesize than not sharpened thumbnail"
end

it "sharpening uses integer precision" do
sharpened = @pipeline.resize_to_limit(400, 400).call(save: false)
assert_equal :uchar, sharpened.format
end
end

describe "#resize_to_fill" do
Expand Down Expand Up @@ -248,6 +258,11 @@
normal = @pipeline.resize_to_fill!(400, 400, sharpen: false)
assert sharpened.size > normal.size, "Expected sharpened thumbnail to have bigger filesize than not sharpened thumbnail"
end

it "sharpening uses integer precision" do
sharpened = @pipeline.resize_to_limit(400, 400).call(save: false)
assert_equal :uchar, sharpened.format
end
end

describe "#resize_and_pad" do
Expand Down Expand Up @@ -297,6 +312,11 @@
normal = @pipeline.resize_and_pad!(400, 400, sharpen: false)
assert sharpened.size > normal.size, "Expected sharpened thumbnail to have bigger filesize than not sharpened thumbnail"
end

it "sharpening uses integer precision" do
sharpened = @pipeline.resize_to_limit(400, 400).call(save: false)
assert_equal :uchar, sharpened.format
end
end

describe "#rotate" do
Expand Down

0 comments on commit 94cb723

Please sign in to comment.