ffi-gmagick 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30e772427cb4e7ed886e6297ec02d1cf88676fe5
4
- data.tar.gz: 49d2a50de80e00f8a334a209b06ccf6c7992c1ea
3
+ metadata.gz: b4d35771f4f73c964d3d41cf48d411c6b87556e6
4
+ data.tar.gz: adf9c47547359d756b9bd142cf94b4bd7e700a53
5
5
  SHA512:
6
- metadata.gz: 77d85f31f95bd7475d17e42d4ce6c7947c95f36c89a006eb96f974c2d6a024b797f95779c0176526522254d84d22ce9d8624a9f90549e695cc559e104b386262
7
- data.tar.gz: a2e6dda11c05124df49d2b7244b52e7934b09466295568a2dd5e36f17ffcdf9b2f85f964caaf83a3ec2cc1c5e35232e353f8c8058bf6da82bc616a88c9eff493
6
+ metadata.gz: 0d67b0825501d5e4666dc99f776d3ad8fda8d2ccb99e98ccc200fbf9191289c207a47ca5cca2d268d94850226403023461b2d0341fcb876baaf463c23fa5011f
7
+ data.tar.gz: 3e21e5130fcff8af7ff7ae576f6e6c340999ba0cdc672d9c95c0108490c0ed3d48878da9e66a0ad5ace2b521c84598873a81b31b9a8f7e9877f73ca92b14a9db
@@ -4,6 +4,7 @@ module FFI
4
4
  typedef :pointer, :composite_wand
5
5
  typedef :pointer, :blob
6
6
  typedef :pointer, :profile
7
+ typedef :pointer, :gravity
7
8
  typedef :string, :name
8
9
  typedef :string, :filename
9
10
  typedef :string, :format
@@ -58,6 +59,11 @@ module FFI
58
59
  attach_function :MagickSetImageDepth, [ :wand, :depth ], :magick_pass_fail
59
60
  attach_function :MagickGetImageSize, [ :wand ], :ulong
60
61
 
62
+ attach_function :MagickGetNumberImages, [ :wand ], :ulong
63
+ attach_function :MagickNextImage, [ :wand ], :magick_pass_fail
64
+ attach_function :MagickPreviousImage, [ :wand ], :magick_pass_fail
65
+ attach_function :MagickRemoveImage, [ :wand ], :magick_pass_fail
66
+
61
67
  attach_function :MagickSetCompressionQuality, [ :wand, :quality ], :magick_pass_fail
62
68
  attach_function :MagickStripImage, [ :wand ], :magick_pass_fail
63
69
  attach_function :MagickUnsharpMaskImage, [ :wand, :radius, :sigma, :amount, :threshold ], :magick_pass_fail
@@ -71,6 +77,7 @@ module FFI
71
77
  attach_function :MagickSetImageInterlaceScheme, [ :wand, :interlace_type ], :magick_pass_fail
72
78
  attach_function :MagickSetInterlaceScheme, [ :wand, :interlace_type ], :magick_pass_fail
73
79
  attach_function :MagickFlattenImages, [ :wand ], :wand
80
+ # attach_function :MagickSetImageGravity, [ :wand, :gravity ], :magick_pass_fail
74
81
  attach_function :MagickMapImage, [ :wand, :wand, :dither ], :magick_pass_fail
75
82
  attach_function :MagickGetImageHistogram, [ :wand, :pointer ], :pointer
76
83
  attach_function :MagickGetImageColors, [ :wand ], :ulong
@@ -172,6 +179,36 @@ module FFI
172
179
  end
173
180
  alias_method :length, :size
174
181
 
182
+ # Get the number of bits used to represent a single component of a pixel
183
+ def depth
184
+ return FFI::GMagick.MagickGetImageDepth( @wand )
185
+ end
186
+
187
+ # Set the number of bits used to represent a single component of a pixel
188
+ def depth=(depth=8)
189
+ @status = FFI::GMagick.MagickSetImageDepth( @wand, depth )
190
+ end
191
+
192
+ # Return the number of images in this wand (sequence)
193
+ def count
194
+ return FFI::GMagick.MagickGetNumberImages( @wand )
195
+ end
196
+
197
+ # Go to the next image in the sequence
198
+ def next
199
+ @status = FFI::GMagick.MagickNextImage( @wand )
200
+ end
201
+
202
+ # Go to the previous image in the sequence
203
+ def previous
204
+ @status = FFI::GMagick.MagickPreviousImage( @wand )
205
+ end
206
+
207
+ # Remove the current image in the sequence
208
+ def remove
209
+ @status = FFI::GMagick.MagickRemoveImage( @wand )
210
+ end
211
+
175
212
  # Return the image format
176
213
  def format
177
214
  FFI::GMagick.MagickGetImageFormat( @wand )
@@ -216,14 +253,12 @@ module FFI
216
253
  def colorspace
217
254
  FFI::GMagick.MagickGetImageColorspace( @wand )
218
255
  end
219
- alias_method :colormodel, :colorspace
220
256
 
221
257
  # Set the image colorspace to one of the valid
222
258
  # <a href="http://www.graphicsmagick.org/api/types.html#colorspacetype">colorspace types</a>.
223
259
  def colorspace=(colorspace)
224
260
  FFI::GMagick.MagickSetImageColorspace( @wand, colorspace )
225
261
  end
226
- alias_method :colormodel=, :colorspace=
227
262
 
228
263
  # Return the information for a specific profile in the image
229
264
  def profile(name="ICC")
@@ -269,12 +304,17 @@ module FFI
269
304
  end
270
305
 
271
306
  # Returns the number of unique colors in the image
272
- def get_color_count
307
+ def colorcount
273
308
  return FFI::GMagick.MagickGetImageColors( @wand )
274
309
  end
275
310
 
311
+ # Replace the colors of an image with the closest color from a reference image.
312
+ def map(reference_image, dither=0)
313
+ FFI::GMagick.MagickMapImage( @wand, reference_image.wand, dither )
314
+ end
315
+
276
316
  # Get a simplified histogram for this image.
277
- def get_histogram(web_safe=true)
317
+ def histogram(web_safe=false)
278
318
  new_wand = FFI::GMagick.CloneMagickWand( @wand )
279
319
 
280
320
  # "WebSafe" colors are built around the original 216 colors defined by Netscape
@@ -285,22 +325,30 @@ module FFI
285
325
  FFI::GMagick.DestroyMagickWand( netscape )
286
326
  end
287
327
 
328
+ total_color_count = 0.0
288
329
  histogram = {}
289
- number_of_colors = FFI::GMagick.MagickGetImageColors(new_wand).to_f
290
-
291
330
  FFI::MemoryPointer.new(:ulong, 1) do |max_colors|
292
331
  pointer = FFI::GMagick.MagickGetImageHistogram( new_wand, max_colors )
332
+ number_of_colors = max_colors.read_int
293
333
 
294
- pixel_wands = pointer.read_array_of_pointer(max_colors.read_int)
334
+ pixel_wands = pointer.read_array_of_pointer(number_of_colors)
295
335
  pixel_wands.each do |wand|
296
336
  pixel = FFI::GMagick::Pixel.new(wand)
297
337
  hex_color = "#%02X%02X%02X" % pixel.get_color.split(",").map(&:to_i)
298
- histogram[hex_color] = (pixel.get_color_count / number_of_colors)
338
+ color_count = pixel.get_color_count
339
+ total_color_count += color_count
340
+ histogram[hex_color] = color_count
299
341
  end
300
342
  end
301
343
  FFI::GMagick.DestroyMagickWand( new_wand )
302
344
 
303
- return histogram
345
+ # Convert values to percentage of colors and remove infinitesimal numbers
346
+ final = {}
347
+ histogram.map do |k,v|
348
+ final[k] = (v / total_color_count).round(3) if (v/total_color_count) >= 0.001
349
+ end
350
+
351
+ return final
304
352
  end
305
353
 
306
354
  # Change the quality (compression) of the image
@@ -1,5 +1,5 @@
1
1
  module FFI
2
2
  module GMagick
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.10"
4
4
  end
5
5
  end
data/test/image_test.rb CHANGED
@@ -60,7 +60,6 @@ class ImageTest < MiniTest::Unit::TestCase
60
60
 
61
61
  def test_colorspace
62
62
  assert_equal :RGBColorspace, @image.colorspace, "invalid color space"
63
- assert_equal :RGBColorspace, @image.colormodel, "invalid color model"
64
63
  end
65
64
 
66
65
  def test_get_type
@@ -72,6 +71,15 @@ class ImageTest < MiniTest::Unit::TestCase
72
71
  assert_equal :PlaneInterlace, @image.interlace, "invalid interlace"
73
72
  end
74
73
 
74
+ def test_get_depth
75
+ assert_equal 8, @image.depth
76
+ end
77
+
78
+ def test_set_depth
79
+ @image.depth = 2
80
+ assert_equal 2, @image.depth
81
+ end
82
+
75
83
  def test_set_type
76
84
  skip
77
85
  @image.type = :TrueColorType
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-gmagick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Hurt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-27 00:00:00.000000000 Z
11
+ date: 2014-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi