ffi-gmagick 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cd0e82c18ae40fdac196a30427d057c0d7ef6c4
4
- data.tar.gz: 8c5ecdd6bb78c1e3bb5186b9a69370d1036fe8ba
3
+ metadata.gz: 30e772427cb4e7ed886e6297ec02d1cf88676fe5
4
+ data.tar.gz: 49d2a50de80e00f8a334a209b06ccf6c7992c1ea
5
5
  SHA512:
6
- metadata.gz: fadf91e22cac1576821a48d0f5b3b71984a2c5f7e81f2f247cde323f87896db0add2eba15e2177b8d94b6058051860a0313a6011136ae79252f18094d2bb5af3
7
- data.tar.gz: 69ec4bc5171084bdca4856083e5057e679bc8626c7842cf7af3a8ebbfc3f5c1457b1a691ee112402136e17d253f005e2e82335c2625d11819c08b59ebd5ad462
6
+ metadata.gz: 77d85f31f95bd7475d17e42d4ce6c7947c95f36c89a006eb96f974c2d6a024b797f95779c0176526522254d84d22ce9d8624a9f90549e695cc559e104b386262
7
+ data.tar.gz: a2e6dda11c05124df49d2b7244b52e7934b09466295568a2dd5e36f17ffcdf9b2f85f964caaf83a3ec2cc1c5e35232e353f8c8058bf6da82bc616a88c9eff493
@@ -73,6 +73,7 @@ module FFI
73
73
  attach_function :MagickFlattenImages, [ :wand ], :wand
74
74
  attach_function :MagickMapImage, [ :wand, :wand, :dither ], :magick_pass_fail
75
75
  attach_function :MagickGetImageHistogram, [ :wand, :pointer ], :pointer
76
+ attach_function :MagickGetImageColors, [ :wand ], :ulong
76
77
 
77
78
  attach_function :MagickResizeImage, [ :wand, :columns, :rows, :filter_type, :blur ], :magick_pass_fail
78
79
  attach_function :MagickResampleImage, [ :wand, :x_resolution, :y_resolution, :filter_type, :blur ], :magick_pass_fail
@@ -267,6 +268,11 @@ module FFI
267
268
  return FFI::GMagick::Image.new(local_wand)
268
269
  end
269
270
 
271
+ # Returns the number of unique colors in the image
272
+ def get_color_count
273
+ return FFI::GMagick.MagickGetImageColors( @wand )
274
+ end
275
+
270
276
  # Get a simplified histogram for this image.
271
277
  def get_histogram(web_safe=true)
272
278
  new_wand = FFI::GMagick.CloneMagickWand( @wand )
@@ -280,24 +286,21 @@ module FFI
280
286
  end
281
287
 
282
288
  histogram = {}
283
- total_color_count = 0.0
289
+ number_of_colors = FFI::GMagick.MagickGetImageColors(new_wand).to_f
290
+
284
291
  FFI::MemoryPointer.new(:ulong, 1) do |max_colors|
285
292
  pointer = FFI::GMagick.MagickGetImageHistogram( new_wand, max_colors )
286
- number_of_colors = max_colors.read_int
287
293
 
288
- pixel_wands = pointer.read_array_of_pointer(number_of_colors)
294
+ pixel_wands = pointer.read_array_of_pointer(max_colors.read_int)
289
295
  pixel_wands.each do |wand|
290
296
  pixel = FFI::GMagick::Pixel.new(wand)
291
297
  hex_color = "#%02X%02X%02X" % pixel.get_color.split(",").map(&:to_i)
292
- color_count = pixel.get_color_count
293
- total_color_count += color_count
294
- histogram[hex_color] = color_count
298
+ histogram[hex_color] = (pixel.get_color_count / number_of_colors)
295
299
  end
296
300
  end
297
301
  FFI::GMagick.DestroyMagickWand( new_wand )
298
302
 
299
- # Convert distribution to %
300
- return histogram.map{|k,v| {k => v / total_color_count}}
303
+ return histogram
301
304
  end
302
305
 
303
306
  # Change the quality (compression) of the image
@@ -1,5 +1,5 @@
1
1
  module FFI
2
2
  module GMagick
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-gmagick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Hurt