Skip to content

Commit 7e8f5c4

Browse files
committed
Add test for gainmap
1 parent 813a92b commit 7e8f5c4

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

spec/images/uhdr.jpg

1.14 MB
Loading

spec/meta_spec.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local vips = require "vips"
22
local ffi = require "ffi"
33

4+
local UHDR_FILE = "./spec/images/uhdr.jpg"
45
-- test metadata read/write
56
describe("metadata", function()
67
local array, im
@@ -59,4 +60,28 @@ describe("metadata", function()
5960

6061
assert.are.same(im2:format(), "double")
6162
end)
63+
64+
it("can set gainmap", function()
65+
if vips.version.at_least(8, 18) and vips.has("uhdrload") then
66+
local function crop_gainmap(image)
67+
local gainmap = image:get_gainmap()
68+
69+
if gainmap then
70+
local new_gainmap = gainmap:crop(0, 0, 10, 10)
71+
image = image:copy()
72+
image:set_type(vips.gvalue.image_type, "gainmap", new_gainmap)
73+
end
74+
75+
return image
76+
end
77+
78+
local image = vips.Image.new_from_file(UHDR_FILE)
79+
image = crop_gainmap(image)
80+
local buf = image:write_to_buffer(".jpg")
81+
local new_image = vips.Image.new_from_buffer(buf, "")
82+
local new_gainmap = new_image:get_gainmap()
83+
84+
assert.are.same(new_gainmap:width(), 10)
85+
end
86+
end)
6287
end)

src/vips.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ function vips.concurrency_get()
6464
return vips_lib.vips_concurrency_get()
6565
end
6666

67+
function vips.type_find(basename, nickname)
68+
return vips_lib.vips_type_find(basename, nickname)
69+
end
70+
71+
function vips.has(name)
72+
return vips.type_find("VipsOperation", name) ~= 0
73+
end
6774
-- for compat with 1.1-6, when these were misnamed
6875
vips.set_max = vips.cache_set_max
6976
vips.get_max = vips.cache_get_max

src/vips/cdefs.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ ffi.cdef [[
3535
GType vips_blend_mode_get_type (void);
3636
GType vips_band_format_get_type (void);
3737

38+
GType vips_type_find (const char *basename, const char *nickname);
39+
3840
int vips_enum_from_nick (const char *domain,
3941
GType gtype, const char *str);
4042
const char *vips_enum_nick (GType gtype, int value);

0 commit comments

Comments
 (0)