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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## master

* raise Vips::Error if `copy_memory` fails [VitaliiLazebnyi]
* `Source.new_from_memory` keeps a reference to the memory area [jeremy]

## Version 2.3.0 (2025-12-10)

Expand Down
15 changes: 6 additions & 9 deletions lib/vips/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,10 @@ def add_alpha
#
# @return [Image] new memory image
def copy_memory
new_image = Vips.vips_image_copy_memory self
raise Vips::Error if new_image.null?
ptr = Vips.vips_image_copy_memory self
raise Vips::Error if ptr.null?

Vips::Image.new new_image
Vips::Image.new ptr
end

# Draw a point on an image.
Expand All @@ -1037,8 +1037,7 @@ def draw_point ink, left, top, **opts
# @param other [Image, Real, Array<Real>] Thing to add to self
# @return [Image] result of addition
def + other
other.is_a?(Vips::Image) ?
add(other) : linear(1, other)
other.is_a?(Vips::Image) ? add(other) : linear(1, other)
end

# Subtract an image, constant or array.
Expand All @@ -1055,8 +1054,7 @@ def - other
# @param other [Image, Real, Array<Real>] Thing to multiply by self
# @return [Image] result of multiplication
def * other
other.is_a?(Vips::Image) ?
multiply(other) : linear(other, 0)
other.is_a?(Vips::Image) ? multiply(other) : linear(other, 0)
end

# Divide an image, constant or array.
Expand All @@ -1073,8 +1071,7 @@ def / other
# @param other [Image, Real, Array<Real>] self modulo this
# @return [Image] result of modulo
def % other
other.is_a?(Vips::Image) ?
remainder(other) : remainder_const(other)
other.is_a?(Vips::Image) ? remainder(other) : remainder_const(other)
end

# Raise to power of an image, constant or array.
Expand Down
9 changes: 6 additions & 3 deletions lib/vips/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ def self.new_from_file(filename)
def self.new_from_memory(data)
ptr = Vips.vips_source_new_from_memory data, data.bytesize
raise Vips::Error if ptr.null?
source = Vips::Source.new ptr

# FIXME do we need to keep a ref to the underlying memory area? what
# about Image.new_from_buffer? Does that need a secret ref too?
# keep a secret ref to the underlying object .. this reference will be
# inherited by things that in turn depend on us, so the memory we are
# using will not be freed
source.references << data

Vips::Source.new ptr
source
end
end
end
Loading