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 +4 -4
- data/lib/ffi/gmagick/image.rb +11 -8
- data/lib/ffi/gmagick/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30e772427cb4e7ed886e6297ec02d1cf88676fe5
|
4
|
+
data.tar.gz: 49d2a50de80e00f8a334a209b06ccf6c7992c1ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77d85f31f95bd7475d17e42d4ce6c7947c95f36c89a006eb96f974c2d6a024b797f95779c0176526522254d84d22ce9d8624a9f90549e695cc559e104b386262
|
7
|
+
data.tar.gz: a2e6dda11c05124df49d2b7244b52e7934b09466295568a2dd5e36f17ffcdf9b2f85f964caaf83a3ec2cc1c5e35232e353f8c8058bf6da82bc616a88c9eff493
|
data/lib/ffi/gmagick/image.rb
CHANGED
@@ -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
|
-
|
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(
|
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
|
-
|
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
|
-
|
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
|
data/lib/ffi/gmagick/version.rb
CHANGED