pxlsrt 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pxlsrt +1 -1
- data/lib/pxlsrt/brute.rb +3 -3
- data/lib/pxlsrt/colors.rb +38 -7
- data/lib/pxlsrt/smart.rb +3 -3
- data/lib/pxlsrt/version.rb +1 -1
- 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: 261def653de6b5100adf27ef5e0322d097d16563
|
4
|
+
data.tar.gz: 2e5e58532b22930c4b91d00b4beb62eca0b2077c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 320adc9d126207b337658fdaa7797a54de176db706232ddf30988ff4033dcd3e5cf51765a3f97130e0d49088187a8e15a41aae836ec402c42f919fe30d7b43a6
|
7
|
+
data.tar.gz: b0d6a304921ea9dabbc4ac2d9147a54d81667767f70922b0d673902c9f073b9769bee49d398b4cffe970275149d3b317afeb08d997963917886802577fa223fe
|
data/bin/pxlsrt
CHANGED
@@ -18,7 +18,7 @@ class CLI < Thor
|
|
18
18
|
class_option :vertical, :type => :boolean, :default => false, :aliases => "-v"
|
19
19
|
class_option :diagonal, :type => :boolean, :default => false, :aliases => "-d"
|
20
20
|
class_option :smooth, :type => :boolean, :default => false, :aliases => "-s"
|
21
|
-
class_option :method, :type => :string, :default => "sum-rgb", :banner => "[sum-rgb | red | green | blue | sum-hsb | hue | saturation | brightness | uniqueness | luma | random]", :aliases => "-m", :enum => ["sum-rgb", "red", "green", "blue", "sum-hsb", "hue", "saturation", "brightness", "uniqueness", "luma", "random"]
|
21
|
+
class_option :method, :type => :string, :default => "sum-rgb", :banner => "[sum-rgb | red | green | blue | sum-hsb | hue | saturation | brightness | uniqueness | luma | random | cyan | magenta | yellow | alpha | sum-rgba | sum-hsba]", :aliases => "-m", :enum => ["sum-rgb", "red", "green", "blue", "sum-hsb", "hue", "saturation", "brightness", "uniqueness", "luma", "random", "cyan", "magenta", "yellow", "alpha", "sum-rgba", "sum-hsba"]
|
22
22
|
class_option :verbose, :type => :boolean, :default => false, :aliases => "-V"
|
23
23
|
|
24
24
|
option :min, :type => :numeric, :default => Float::INFINITY, :banner => "MINIMUM BANDWIDTH"
|
data/lib/pxlsrt/brute.rb
CHANGED
@@ -34,7 +34,7 @@ module Pxlsrt
|
|
34
34
|
:vertical => [false, true],
|
35
35
|
:diagonal => [false, true],
|
36
36
|
:smooth => [false, true],
|
37
|
-
:method => ["sum-rgb", "red", "green", "blue", "sum-hsb", "hue", "saturation", "brightness", "uniqueness", "luma", "random"],
|
37
|
+
:method => ["sum-rgb", "red", "green", "blue", "sum-hsb", "hue", "saturation", "brightness", "uniqueness", "luma", "random", "cyan", "magenta", "yellow", "alpha", "sum-rgba", "sum-hsba"],
|
38
38
|
:verbose => [false, true],
|
39
39
|
:min => [Float::INFINITY, {:class => [Fixnum]}],
|
40
40
|
:max => [Float::INFINITY, {:class => [Fixnum]}],
|
@@ -76,7 +76,7 @@ module Pxlsrt
|
|
76
76
|
Pxlsrt::Helpers.verbose("Retrieving RGB values of pixels...") if options[:verbose]
|
77
77
|
kml=[]
|
78
78
|
for xy in 0..(w*h-1)
|
79
|
-
kml.push(Pxlsrt::Colors.
|
79
|
+
kml.push(Pxlsrt::Colors.getRGBA(png[xy % w,(xy/w).floor]))
|
80
80
|
end
|
81
81
|
if options[:vertical]==true
|
82
82
|
Pxlsrt::Helpers.verbose("Rotating image for vertical mode...") if options[:verbose]
|
@@ -134,7 +134,7 @@ module Pxlsrt
|
|
134
134
|
end
|
135
135
|
Pxlsrt::Helpers.verbose("Giving pixels new RGB values...") if options[:verbose]
|
136
136
|
for xy in 0..(w*h-1)
|
137
|
-
sorted[xy % w, (xy/w).floor]=Pxlsrt::Colors.
|
137
|
+
sorted[xy % w, (xy/w).floor]=Pxlsrt::Colors.arrayToRGBA(toImage[xy])
|
138
138
|
end
|
139
139
|
endTime=Time.now
|
140
140
|
timeElapsed=endTime-startTime
|
data/lib/pxlsrt/colors.rb
CHANGED
@@ -5,9 +5,9 @@ module Pxlsrt
|
|
5
5
|
# Includes color and image operations.
|
6
6
|
class Colors
|
7
7
|
##
|
8
|
-
# Converts a ChunkyPNG pixel into an array of the
|
9
|
-
def self.
|
10
|
-
return [ChunkyPNG::Color.r(pxl), ChunkyPNG::Color.g(pxl), ChunkyPNG::Color.b(pxl)]
|
8
|
+
# Converts a ChunkyPNG pixel into an array of the red, green, blue, and alpha values
|
9
|
+
def self.getRGBA(pxl)
|
10
|
+
return [ChunkyPNG::Color.r(pxl), ChunkyPNG::Color.g(pxl), ChunkyPNG::Color.b(pxl), ChunkyPNG::Color.a(pxl)]
|
11
11
|
end
|
12
12
|
##
|
13
13
|
# Check if file is a PNG image. ChunkyPNG only works with PNG images. Eventually, I might use conversion tools to add support, but not right now.
|
@@ -119,12 +119,13 @@ module Pxlsrt
|
|
119
119
|
r=((ca.collect { |c| c[0] }).inject{ |sum, el| sum+el }).to_f / ca.size
|
120
120
|
g=((ca.collect { |c| c[1] }).inject{ |sum, el| sum+el }).to_f / ca.size
|
121
121
|
b=((ca.collect { |c| c[2] }).inject{ |sum, el| sum+el }).to_f / ca.size
|
122
|
-
|
122
|
+
a=((ca.collect { |c| c[3] }).inject{ |sum, el| sum+el }).to_f / ca.size
|
123
|
+
return [r,g,b,a]
|
123
124
|
end
|
124
125
|
##
|
125
126
|
# Determines color distance from each other using the Pythagorean theorem.
|
126
127
|
def self.colorDistance(c1,c2)
|
127
|
-
return Math.sqrt((c1[0]-c2[0])**2+(c1[1]-c2[1])**2+(c1[2]-c2[2])**2)
|
128
|
+
return Math.sqrt((c1[0]-c2[0])**2+(c1[1]-c2[1])**2+(c1[2]-c2[2])**2+(c1[3]-c2[3])**2)
|
128
129
|
end
|
129
130
|
##
|
130
131
|
# Uses a combination of color averaging and color distance to find how "unique" a color is.
|
@@ -133,17 +134,43 @@ module Pxlsrt
|
|
133
134
|
end
|
134
135
|
##
|
135
136
|
# Sorts an array of colors based on a method.
|
137
|
+
# Available methods:
|
138
|
+
# * sum-rgb (default)
|
139
|
+
# * sum-rgba
|
140
|
+
# * red
|
141
|
+
# * yellow
|
142
|
+
# * green
|
143
|
+
# * cyan
|
144
|
+
# * blue
|
145
|
+
# * magenta
|
146
|
+
# * hue
|
147
|
+
# * saturation
|
148
|
+
# * brightness
|
149
|
+
# * sum-hsb
|
150
|
+
# * sum-hsba
|
151
|
+
# * uniqueness
|
152
|
+
# * luma
|
153
|
+
# * random
|
154
|
+
# * alpha
|
136
155
|
def self.pixelSort(list, how, reverse)
|
137
156
|
mhm=[]
|
138
157
|
case how.downcase
|
139
158
|
when "sum-rgb"
|
140
159
|
mhm= list.sort_by { |c| Pxlsrt::Colors.pxldex(c) }
|
160
|
+
when "sum-rgba"
|
161
|
+
mhm=list.sort_by { |c| Pxlsrt::Colors.pxldex(c)+c[3] }
|
141
162
|
when "red"
|
142
163
|
mhm= list.sort_by { |c| c[0] }
|
164
|
+
when "yellow"
|
165
|
+
mhm=list.sort_by { |c| c[0]+c[1] }
|
143
166
|
when "green"
|
144
167
|
mhm= list.sort_by { |c| c[1] }
|
168
|
+
when "cyan"
|
169
|
+
mhm=list.sort_by { |c| c[1]+c[2] }
|
145
170
|
when "blue"
|
146
171
|
mhm= list.sort_by { |c| c[2] }
|
172
|
+
when "magenta"
|
173
|
+
mhm=list.sort_by { |c| c[0]+c[2] }
|
147
174
|
when "hue"
|
148
175
|
mhm= list.sort_by { |c| Pxlsrt::Colors.rgb2hsb(c)[0] }
|
149
176
|
when "saturation"
|
@@ -152,6 +179,8 @@ module Pxlsrt
|
|
152
179
|
mhm= list.sort_by { |c| Pxlsrt::Colors.rgb2hsb(c)[2] }
|
153
180
|
when "sum-hsb"
|
154
181
|
mhm= list.sort_by { |c| k=Pxlsrt::Colors.rgb2hsb(c); k[0]*100/360+k[1]+k[2] }
|
182
|
+
when "sum-hsb"
|
183
|
+
mhm= list.sort_by { |c| k=Pxlsrt::Colors.rgb2hsb(c); k[0]*100/360+k[1]+k[2]+k[3]*100/255 }
|
155
184
|
when "uniqueness"
|
156
185
|
avg=Pxlsrt::Colors.colorAverage(list)
|
157
186
|
mhm=list.sort_by { |c| Pxlsrt::Colors.colorUniqueness(c, [avg]) }
|
@@ -159,6 +188,8 @@ module Pxlsrt
|
|
159
188
|
mhm=list.sort_by { |c| Pxlsrt::Colors.pxldex([c[0]*0.2126, c[1]*0.7152, c[2]*0.0722]) }
|
160
189
|
when "random"
|
161
190
|
mhm=list.shuffle
|
191
|
+
when "alpha"
|
192
|
+
mhm=list.sort_by{ |c| c[3] }
|
162
193
|
else
|
163
194
|
mhm= list.sort_by { |c| Pxlsrt::Colors.pxldex(c) }
|
164
195
|
end
|
@@ -210,8 +241,8 @@ module Pxlsrt
|
|
210
241
|
end
|
211
242
|
##
|
212
243
|
# Turns an RGB-like array into ChunkyPNG's color
|
213
|
-
def self.
|
214
|
-
return ChunkyPNG::Color.
|
244
|
+
def self.arrayToRGBA(a)
|
245
|
+
return ChunkyPNG::Color.rgba(a[0], a[1], a[2], a[3])
|
215
246
|
end
|
216
247
|
##
|
217
248
|
# Used in determining Sobel values.
|
data/lib/pxlsrt/smart.rb
CHANGED
@@ -36,7 +36,7 @@ module Pxlsrt
|
|
36
36
|
:vertical => [false, true],
|
37
37
|
:diagonal => [false, true],
|
38
38
|
:smooth => [false, true],
|
39
|
-
:method => ["sum-rgb", "red", "green", "blue", "sum-hsb", "hue", "saturation", "brightness", "uniqueness", "luma", "random"],
|
39
|
+
:method => ["sum-rgb", "red", "green", "blue", "sum-hsb", "hue", "saturation", "brightness", "uniqueness", "luma", "random", "cyan", "magenta", "yellow", "alpha", "sum-rgba", "sum-hsba"],
|
40
40
|
:verbose => [false, true],
|
41
41
|
:absolute => [false, true],
|
42
42
|
:threshold => [{:class => [Float, Fixnum]}],
|
@@ -90,7 +90,7 @@ module Pxlsrt
|
|
90
90
|
else
|
91
91
|
val = 2000000000
|
92
92
|
end
|
93
|
-
k.push({ "sobel" => val, "pixel" => [x, y], "color" => Pxlsrt::Colors.
|
93
|
+
k.push({ "sobel" => val, "pixel" => [x, y], "color" => Pxlsrt::Colors.getRGBA(img[x, y]) })
|
94
94
|
end
|
95
95
|
if options[:vertical]==true
|
96
96
|
Pxlsrt::Helpers.verbose("Rotating image for vertical mode...") if options[:verbose]
|
@@ -213,7 +213,7 @@ module Pxlsrt
|
|
213
213
|
end
|
214
214
|
Pxlsrt::Helpers.verbose("Giving pixels new RGB values...") if options[:verbose]
|
215
215
|
for px in 0..(w*h-1)
|
216
|
-
edge[px % w, (px/w).floor]=Pxlsrt::Colors.
|
216
|
+
edge[px % w, (px/w).floor]=Pxlsrt::Colors.arrayToRGBA(image[px])
|
217
217
|
end
|
218
218
|
endTime=Time.now
|
219
219
|
timeElapsed=endTime-startTime
|
data/lib/pxlsrt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pxlsrt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- EVA-01
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|