colorfulness 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/colorfulness.gemspec +1 -1
- data/lib/colorfulness/calculator.rb +11 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2417ae2a64e9c33b18e606fca5ae0f5904e70a6
|
4
|
+
data.tar.gz: 9dbf0801a1899e7455af35ab0c69378c4e9b3b1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c5fcef63c62b055f865d641e63c3b00f82503a7da6c51bd8a3218609352d75df0b3a42b6875d516c54015da68e3cd9f02616a4ed204f0b2c9c602b23d77a6fb
|
7
|
+
data.tar.gz: ea1baaf6de2468a380f80013c638c16e18653f21417d6759d7fa46dbeafe1547478ba1951aad6a31a3009976af81d95d55197c82735a4e01c4a481a54ebb4d85
|
data/colorfulness.gemspec
CHANGED
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "colorfulness"
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.2"
|
6
6
|
s.authors = ["Tom Taylor"]
|
7
7
|
s.email = ["tom@tomtaylor.co.uk"]
|
8
8
|
s.homepage = "https://github.com/tomtaylor/colorfulness"
|
@@ -4,8 +4,12 @@ require 'oily_png'
|
|
4
4
|
module Colorfulness
|
5
5
|
class Calculator
|
6
6
|
|
7
|
-
|
7
|
+
# Initialize the Calculator with a ChunkyPNG::Image, and an optional
|
8
|
+
# background color to composite against, to remove the alpha component, if
|
9
|
+
# any.
|
10
|
+
def initialize(image, background_color = ChunkyPNG::Color::WHITE)
|
8
11
|
@image = image
|
12
|
+
@background_color = background_color
|
9
13
|
end
|
10
14
|
|
11
15
|
# Technique from https://gist.github.com/zabela/8539116, a MATLAB
|
@@ -17,8 +21,13 @@ module Colorfulness
|
|
17
21
|
|
18
22
|
(0...@image.width).each do |x|
|
19
23
|
(0...@image.height).each do |y|
|
24
|
+
# Gets the integer RGB value
|
20
25
|
pixel = @image.get_pixel(x, y)
|
21
|
-
|
26
|
+
# Compose the pixel against a background color to remove the alpha
|
27
|
+
# component.
|
28
|
+
flat_pixel = ChunkyPNG::Color.compose(pixel, @background_color)
|
29
|
+
rgb = ChunkyPNG::Color.to_truecolor_bytes(flat_pixel)
|
30
|
+
# Convert each component to float values between 0 and 1
|
22
31
|
r, g, b = rgb.map { |c| c.to_f / ChunkyPNG::Color::MAX }
|
23
32
|
|
24
33
|
rg << (r - g).abs
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colorfulness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chunky_png
|