Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added spec/images/uhdr.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions spec/meta_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local vips = require "vips"
local ffi = require "ffi"

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

assert.are.same(im2:format(), "double")
end)

it("can set gainmap", function()
if vips.version.at_least(8, 18) and vips.has("uhdrload") then
local function crop_gainmap(image)
local gainmap = image:get_gainmap()

if gainmap then
local new_gainmap = gainmap:crop(0, 0, 10, 10)
image = image:copy()
image:set_type(vips.gvalue.image_type, "gainmap", new_gainmap)
end

return image
end

local image = vips.Image.new_from_file(UHDR_FILE)
image = crop_gainmap(image)
local buf = image:write_to_buffer(".jpg")
local new_image = vips.Image.new_from_buffer(buf, "")
local new_gainmap = new_image:get_gainmap()

assert.are.same(new_gainmap:width(), 10)
end
end)
end)
7 changes: 7 additions & 0 deletions src/vips.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ function vips.concurrency_get()
return vips_lib.vips_concurrency_get()
end

function vips.type_find(basename, nickname)
return vips_lib.vips_type_find(basename, nickname)
end

function vips.has(name)
return vips.type_find("VipsOperation", name) ~= 0
end
-- for compat with 1.1-6, when these were misnamed
vips.set_max = vips.cache_set_max
vips.get_max = vips.cache_get_max
Expand Down
10 changes: 10 additions & 0 deletions src/vips/Image_methods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,16 @@ function Image_method:remove(name)
return vips_lib.vips_image_remove(self.vimage, name) ~= 0
end

function Image_method:get_gainmap()
collectgarbage("stop")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain you need to stop and restart the GC -- with the API change vips_image_get_gainmap now returns a true reference, so your pointer should be safe.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be, but there are some oddities in Lua 5.4 which cause a crash (illegal machine instruction) when running the uhdr.lua script (still seen in https://github.com/libvips/lua-vips/compare/ca7df971d6a3a34ce9a076e8c3e238812c1452f2..7e8f5c44813ee311e0acf1e3f5c4bd0bf97c175d) via lua5.4 uhdr.lua.
It works fine with lua5.3 and luajit without stopping the GC.

local vimage = vips_lib.vips_image_get_gainmap(self.vimage)
if vimage == ffi.NULL then
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to restart the gc here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for Lua 5.4, see below.

end

collectgarbage("restart")
return Image.new(vimage)
end
-- standard header fields

function Image_method:width()
Expand Down
4 changes: 4 additions & 0 deletions src/vips/cdefs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ ffi.cdef [[
GType vips_blend_mode_get_type (void);
GType vips_band_format_get_type (void);

GType vips_type_find (const char *basename, const char *nickname);

int vips_enum_from_nick (const char *domain,
GType gtype, const char *str);
const char *vips_enum_nick (GType gtype, int value);
Expand Down Expand Up @@ -166,6 +168,8 @@ ffi.cdef [[
// opaque
} VipsImage;

VipsImage *vips_image_get_gainmap(VipsImage *image);

typedef struct _VipsConnection {
VipsObject parent_instance;

Expand Down
Loading