@@ -50,6 +50,10 @@ module Vips
5050 attach_function :vips_addalpha , [ :pointer , :pointer , :varargs ] , :int
5151 end
5252
53+ if Vips . at_least_libvips? ( 8 , 18 )
54+ attach_function :vips_image_get_gainmap , [ :pointer ] , :pointer
55+ end
56+
5357 # move these three lines to mutableimage when we finally remove set and
5458 # remove in this class
5559 attach_function :vips_image_set ,
@@ -797,8 +801,36 @@ def get_fields
797801 names
798802 end
799803
804+ # Get the gainmap (if any) from an image.
805+ #
806+ # After modifying the gainmap, you should write it back to the image in a
807+ # mutable block, see [#mutate], in the field "gainmap".
808+ #
809+ # For example:
810+ #
811+ # ```ruby
812+ # gainmap = image.get_gainmap
813+ # unless gainmap.nil?
814+ # new_gainmap = gainmap.crop left, top, width, height
815+ # image = image.mutate do |x|
816+ # x.set_type! Vips::IMAGE_TYPE, "gainmap", new_gainmap
817+ # end
818+ # end
819+ # ```
820+ #
821+ # @return [Image] the gainmap image, or nil
822+ def get_gainmap
823+ if Vips . at_least_libvips? ( 8 , 18 )
824+ vi = Vips . vips_image_get_gainmap self
825+ return nil if vi . null?
826+ Image . new ( vi )
827+ else
828+ nil
829+ end
830+ end
831+
800832 # Mutate an image with a block. Inside the block, you can call methods
801- # which modify the image, such as setting or removing metadata, or
833+ # which modify the image, such as setting or removing metadata or
802834 # modifying pixels.
803835 #
804836 # For example:
0 commit comments