Skip to content

Commit

Permalink
Add spec file for interpolate
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandlo committed Mar 13, 2024
1 parent 730a737 commit caa1183
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions spec/interpolate_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
local vips = require "vips"

-- test image interpolation
describe("image interpolation", function()
setup(function()
-- vips.log.enable(true)
end)

it("can rotate an image using nearest interpolator", function()
local interpolate = vips.Interpolate.new_from_name("nearest")
local original = {
{ 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 },
}
local rotated = {
{ 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 15.0, 9.0, 3.0, 3.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 22.0, 16.0, 17.0, 10.0, 4.0, 5.0, 0.0 },
{ 0.0, 0.0, 29.0, 30.0, 24.0, 17.0, 18.0, 12.0, 5.0, 6.0 },
{ 0.0, 43.0, 37.0, 31.0, 31.0, 25.0, 19.0, 19.0, 13.0, 7.0 },
{ 0.0, 0.0, 45.0, 38.0, 32.0, 33.0, 26.0, 20.0, 21.0, 0.0 },
{ 0.0, 0.0, 0.0, 46.0, 40.0, 33.0, 34.0, 28.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 47.0, 41.0, 35.0, 0.0, 0.0, 0.0 },
{ 0.0, 0.0, 0.0, 0.0, 0.0, 49.0, 0.0, 0.0, 0.0, 0.0 },
}
local im = vips.Image.new_from_array(original)
local rot = im:rotate(45, { interpolate = interpolate })
local rotcheck = vips.Image.new_from_array(rotated)
assert.are.equal(rot:width(), 10)
assert.are.equal(rot:height(), 10)
assert.are.equal(rot:bands(), 1)
for x = 1, 10 do
for y = 1, 10 do
assert.are_equal(rot(x - 1, y - 1), rotcheck(x - 1, y - 1))
end
end
end)
end)

0 comments on commit caa1183

Please sign in to comment.