@@ -278,8 +278,8 @@ def self.new_from_file name, **opts
278
278
Operation . call loader , [ filename ] , opts , option_string
279
279
end
280
280
281
- # Create a new {Image} for an image encoded, in a format such as
282
- # JPEG, in a binary string. Load options may be passed as
281
+ # Create a new {Image} for an image encoded in a format such as
282
+ # JPEG in a binary string. Load options may be passed as
283
283
# strings or appended as a hash. For example:
284
284
#
285
285
# ```
@@ -316,7 +316,22 @@ def self.new_from_buffer data, option_string, **opts
316
316
Vips ::Operation . call loader , [ data ] , opts , option_string
317
317
end
318
318
319
- # Create a new {Image} from memory
319
+ # Create a new {Image} from a C-style array held in memory. For example:
320
+ #
321
+ # ```
322
+ # image = Vips::Image.black(16, 16) + 128
323
+ # data = image.write_to_memory
324
+ #
325
+ # x = Vips::Image.new_from_memory data,
326
+ # image.width, image.height, image.bands, image.format
327
+ # ```
328
+ #
329
+ # {new_from_memory} keeps a reference to the array of pixels you pass in
330
+ # to try to prevent that memory from being freed by the Ruby GC while it
331
+ # is being used.
332
+ #
333
+ # See {new_from_memory_copy} for a version of this method which does not
334
+ # keep a reference.
320
335
#
321
336
# @param data [String, FFI::Pointer] the data to load from
322
337
# @param width [Integer] width in pixels
@@ -333,7 +348,8 @@ def self.new_from_memory data, width, height, bands, format
333
348
end
334
349
335
350
format_number = GObject ::GValue . from_nick BAND_FORMAT_TYPE , format
336
- vi = Vips ::vips_image_new_from_memory data , size , width , height , bands , format_number
351
+ vi = Vips ::vips_image_new_from_memory data , size ,
352
+ width , height , bands , format_number
337
353
raise Vips ::Error if vi . null?
338
354
image = new ( vi )
339
355
@@ -345,7 +361,9 @@ def self.new_from_memory data, width, height, bands, format
345
361
image
346
362
end
347
363
348
- # Create a new {Image} from memory and copies the memory area
364
+ # Create a new {Image} from memory and copies the memory area. See
365
+ # {new_from_memory} for a version of this method which does not copy the
366
+ # memory area.
349
367
#
350
368
# @param data [String, FFI::Pointer] the data to load from
351
369
# @param width [Integer] width in pixels
@@ -355,7 +373,8 @@ def self.new_from_memory data, width, height, bands, format
355
373
# @return [Image] the loaded image
356
374
def self . new_from_memory_copy data , width , height , bands , format
357
375
format_number = GObject ::GValue . from_nick BAND_FORMAT_TYPE , format
358
- vi = Vips ::vips_image_new_from_memory_copy data , data . bytesize , width , height , bands , format_number
376
+ vi = Vips ::vips_image_new_from_memory_copy data , data . bytesize ,
377
+ width , height , bands , format_number
359
378
raise Vips ::Error if vi . null?
360
379
new ( vi )
361
380
end
0 commit comments