pxlsrt 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pxlsrt/brute.rb +7 -7
- data/lib/pxlsrt/colors.rb +1 -103
- data/lib/pxlsrt/lines.rb +103 -0
- data/lib/pxlsrt/smart.rb +17 -7
- data/lib/pxlsrt/version.rb +1 -1
- data/lib/pxlsrt.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9904ad442d8b272d6aa9e196085efc13e9e6c0e
|
4
|
+
data.tar.gz: 145c0cae2d397312d85a4c3627581eb2076a95a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fc1fd26d049302824076066ec5a495ba27f76402263e20aba2a02dd673357a6b46d4b5685bea5a1c6935ad51512ba566ded3ee43b0f786f0e1baf1dd80aa25d
|
7
|
+
data.tar.gz: 204629fbe1687469b21fea3f1bf2a94350fa2ad1b657625cbd753cf11a9ddba06a683542bc470678cab1116720263ba491ca3190368b6d058ce8d4ed7e3e3dd9
|
data/lib/pxlsrt/brute.rb
CHANGED
@@ -80,14 +80,14 @@ module Pxlsrt
|
|
80
80
|
end
|
81
81
|
if options[:vertical]==true
|
82
82
|
Pxlsrt::Helpers.verbose("Rotating image for vertical mode...") if options[:verbose]
|
83
|
-
kml=Pxlsrt::
|
83
|
+
kml=Pxlsrt::Lines.rotateImage(kml, w, h, 3)
|
84
84
|
w,h=h,w
|
85
85
|
end
|
86
86
|
toImage=[]
|
87
87
|
if !options[:diagonal]
|
88
88
|
Pxlsrt::Helpers.verbose("Pixel sorting using method '#{options[:method]}'...") if options[:verbose]
|
89
|
-
for m in Pxlsrt::
|
90
|
-
sliceRanges=Pxlsrt::
|
89
|
+
for m in Pxlsrt::Lines.imageRGBLines(kml, w)
|
90
|
+
sliceRanges=Pxlsrt::Lines.randomSlices(m, options[:min], options[:max])
|
91
91
|
newInTown=[]
|
92
92
|
if options[:smooth]!=true
|
93
93
|
for ranger in sliceRanges
|
@@ -105,10 +105,10 @@ module Pxlsrt
|
|
105
105
|
end
|
106
106
|
else
|
107
107
|
Pxlsrt::Helpers.verbose("Determining diagonals...") if options[:verbose]
|
108
|
-
dia=Pxlsrt::
|
108
|
+
dia=Pxlsrt::Lines.getDiagonals(kml,w,h)
|
109
109
|
Pxlsrt::Helpers.verbose("Pixel sorting using method '#{options[:method]}'...") if options[:verbose]
|
110
110
|
for m in dia.keys
|
111
|
-
sliceRanges=Pxlsrt::
|
111
|
+
sliceRanges=Pxlsrt::Lines.randomSlices(dia[m], options[:min], options[:max])
|
112
112
|
newInTown=[]
|
113
113
|
if options[:smooth]!=true
|
114
114
|
for ranger in sliceRanges
|
@@ -125,11 +125,11 @@ module Pxlsrt
|
|
125
125
|
dia[m]=newInTown
|
126
126
|
end
|
127
127
|
Pxlsrt::Helpers.verbose("Setting diagonals back to standard lines...") if options[:verbose]
|
128
|
-
toImage=Pxlsrt::
|
128
|
+
toImage=Pxlsrt::Lines.fromDiagonals(dia,w)
|
129
129
|
end
|
130
130
|
if options[:vertical]==true
|
131
131
|
Pxlsrt::Helpers.verbose("Rotating back (because of vertical mode).") if options[:verbose]
|
132
|
-
toImage=Pxlsrt::
|
132
|
+
toImage=Pxlsrt::Lines.rotateImage(toImage, w,h,1)
|
133
133
|
w,h=h,w
|
134
134
|
end
|
135
135
|
Pxlsrt::Helpers.verbose("Giving pixels new RGB values...") if options[:verbose]
|
data/lib/pxlsrt/colors.rb
CHANGED
@@ -2,7 +2,7 @@ require "oily_png"
|
|
2
2
|
|
3
3
|
module Pxlsrt
|
4
4
|
##
|
5
|
-
# Includes color
|
5
|
+
# Includes color operations.
|
6
6
|
class Colors
|
7
7
|
##
|
8
8
|
# Converts a ChunkyPNG pixel into an array of the red, green, blue, and alpha values
|
@@ -15,65 +15,6 @@ module Pxlsrt
|
|
15
15
|
return File.read(path).bytes==[137, 80, 78, 71, 10]
|
16
16
|
end
|
17
17
|
##
|
18
|
-
# ChunkyPNG's rotation was a little slow and doubled runtime.
|
19
|
-
# This "rotates" an array, based on the width and height.
|
20
|
-
# It uses math and it's really cool, trust me.
|
21
|
-
def self.rotateImage(what, width, height, a)
|
22
|
-
nu=[]
|
23
|
-
case a
|
24
|
-
when 0, 360, 4
|
25
|
-
nu=what
|
26
|
-
when 1, 90
|
27
|
-
for xy in 0..(what.length-1)
|
28
|
-
nu[((height-1)-(xy/width).floor)+(xy % width)*height]=what[xy]
|
29
|
-
end
|
30
|
-
when 2, 180
|
31
|
-
nu=what.reverse
|
32
|
-
when 3, 270
|
33
|
-
for xy in 0..(what.length-1)
|
34
|
-
nu[(xy/width).floor+((width-1)-(xy % width))*height]=what[xy]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
return nu
|
38
|
-
end
|
39
|
-
##
|
40
|
-
# Gets "rows" of an array based on a width
|
41
|
-
def self.imageRGBLines(image, width)
|
42
|
-
return image.each_slice(width).to_a
|
43
|
-
end
|
44
|
-
##
|
45
|
-
# Outputs random slices of an array.
|
46
|
-
# Because of the requirements of pxlsrt, it doesn't actually slice the array, bute returns a range-like array. Example:
|
47
|
-
# [[0, 5], [6, 7], [8, 10]]
|
48
|
-
def self.randomSlices(arr, minLength, maxLength)
|
49
|
-
len=arr.length-1
|
50
|
-
if len!=0
|
51
|
-
min=[minLength, maxLength].min
|
52
|
-
max=[maxLength, minLength].max
|
53
|
-
if min > len
|
54
|
-
min=len
|
55
|
-
end
|
56
|
-
if max > len
|
57
|
-
max=len
|
58
|
-
end
|
59
|
-
nu=[[0, rand(min..max)]]
|
60
|
-
last=nu.first[1]
|
61
|
-
sorting=true
|
62
|
-
while sorting do
|
63
|
-
if (len-last) <= max
|
64
|
-
nu.push([last+1, len])
|
65
|
-
sorting=false
|
66
|
-
else
|
67
|
-
nu.push([last+1, last+1+rand(min..max)])
|
68
|
-
last=nu.last[1]
|
69
|
-
end
|
70
|
-
end
|
71
|
-
else
|
72
|
-
nu=[[0,0]]
|
73
|
-
end
|
74
|
-
return nu
|
75
|
-
end
|
76
|
-
##
|
77
18
|
# This is really lame. Adds first three values of an array together.
|
78
19
|
def self.pxldex(pxl)
|
79
20
|
return pxl[0]+pxl[1]+pxl[2]
|
@@ -202,52 +143,9 @@ module Pxlsrt
|
|
202
143
|
end
|
203
144
|
end
|
204
145
|
##
|
205
|
-
# Uses math to turn an array into an array of diagonals.
|
206
|
-
def self.getDiagonals(array, width, height)
|
207
|
-
dias={}
|
208
|
-
for x in (1-height)..(width-1)
|
209
|
-
z=[]
|
210
|
-
for y in 0..(height-1)
|
211
|
-
if (x+(width+1)*y).between?(width*y, (width*(y+1)-1))
|
212
|
-
z.push(array[(x+(width+1)*y)])
|
213
|
-
end
|
214
|
-
end
|
215
|
-
dias[x.to_s]=z
|
216
|
-
end
|
217
|
-
return dias
|
218
|
-
end
|
219
|
-
##
|
220
|
-
# Uses math to turn an array of diagonals into a linear array.
|
221
|
-
def self.fromDiagonals(obj, width)
|
222
|
-
ell=[]
|
223
|
-
for k in obj.keys
|
224
|
-
r=k.to_i
|
225
|
-
n=r < 0
|
226
|
-
if n
|
227
|
-
x=0
|
228
|
-
y=r.abs
|
229
|
-
else
|
230
|
-
x=r
|
231
|
-
y=0
|
232
|
-
end
|
233
|
-
ell[x+y*width]=obj[k].first
|
234
|
-
for v in 1..(obj[k].length-1)
|
235
|
-
x+=1
|
236
|
-
y+=1
|
237
|
-
ell[x+y*width]=obj[k][v]
|
238
|
-
end
|
239
|
-
end
|
240
|
-
return ell
|
241
|
-
end
|
242
|
-
##
|
243
146
|
# Turns an RGB-like array into ChunkyPNG's color
|
244
147
|
def self.arrayToRGBA(a)
|
245
148
|
return ChunkyPNG::Color.rgba(a[0], a[1], a[2], a[3])
|
246
149
|
end
|
247
|
-
##
|
248
|
-
# Used in determining Sobel values.
|
249
|
-
def self.sobelate(i, x,y)
|
250
|
-
return ChunkyPNG::Color.to_grayscale_bytes(i[x,y]).first
|
251
|
-
end
|
252
150
|
end
|
253
151
|
end
|
data/lib/pxlsrt/lines.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
module Pxlsrt
|
2
|
+
##
|
3
|
+
# "Line" operations used on arrays f colors.
|
4
|
+
class Lines
|
5
|
+
##
|
6
|
+
# ChunkyPNG's rotation was a little slow and doubled runtime.
|
7
|
+
# This "rotates" an array, based on the width and height.
|
8
|
+
# It uses math and it's really cool, trust me.
|
9
|
+
def self.rotateImage(what, width, height, a)
|
10
|
+
nu=[]
|
11
|
+
case a
|
12
|
+
when 0, 360, 4
|
13
|
+
nu=what
|
14
|
+
when 1, 90
|
15
|
+
for xy in 0..(what.length-1)
|
16
|
+
nu[((height-1)-(xy/width).floor)+(xy % width)*height]=what[xy]
|
17
|
+
end
|
18
|
+
when 2, 180
|
19
|
+
nu=what.reverse
|
20
|
+
when 3, 270
|
21
|
+
for xy in 0..(what.length-1)
|
22
|
+
nu[(xy/width).floor+((width-1)-(xy % width))*height]=what[xy]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
return nu
|
26
|
+
end
|
27
|
+
##
|
28
|
+
# Gets "rows" of an array based on a width
|
29
|
+
def self.imageRGBLines(image, width)
|
30
|
+
return image.each_slice(width).to_a
|
31
|
+
end
|
32
|
+
##
|
33
|
+
# Outputs random slices of an array.
|
34
|
+
# Because of the requirements of pxlsrt, it doesn't actually slice the array, bute returns a range-like array. Example:
|
35
|
+
# [[0, 5], [6, 7], [8, 10]]
|
36
|
+
def self.randomSlices(arr, minLength, maxLength)
|
37
|
+
len=arr.length-1
|
38
|
+
if len!=0
|
39
|
+
min=[minLength, maxLength].min
|
40
|
+
max=[maxLength, minLength].max
|
41
|
+
if min > len
|
42
|
+
min=len
|
43
|
+
end
|
44
|
+
if max > len
|
45
|
+
max=len
|
46
|
+
end
|
47
|
+
nu=[[0, rand(min..max)]]
|
48
|
+
last=nu.first[1]
|
49
|
+
sorting=true
|
50
|
+
while sorting do
|
51
|
+
if (len-last) <= max
|
52
|
+
nu.push([last+1, len])
|
53
|
+
sorting=false
|
54
|
+
else
|
55
|
+
nu.push([last+1, last+1+rand(min..max)])
|
56
|
+
last=nu.last[1]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
else
|
60
|
+
nu=[[0,0]]
|
61
|
+
end
|
62
|
+
return nu
|
63
|
+
end
|
64
|
+
##
|
65
|
+
# Uses math to turn an array into an array of diagonals.
|
66
|
+
def self.getDiagonals(array, width, height)
|
67
|
+
dias={}
|
68
|
+
for x in (1-height)..(width-1)
|
69
|
+
z=[]
|
70
|
+
for y in 0..(height-1)
|
71
|
+
if (x+(width+1)*y).between?(width*y, (width*(y+1)-1))
|
72
|
+
z.push(array[(x+(width+1)*y)])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
dias[x.to_s]=z
|
76
|
+
end
|
77
|
+
return dias
|
78
|
+
end
|
79
|
+
##
|
80
|
+
# Uses math to turn an array of diagonals into a linear array.
|
81
|
+
def self.fromDiagonals(obj, width)
|
82
|
+
ell=[]
|
83
|
+
for k in obj.keys
|
84
|
+
r=k.to_i
|
85
|
+
n=r < 0
|
86
|
+
if n
|
87
|
+
x=0
|
88
|
+
y=r.abs
|
89
|
+
else
|
90
|
+
x=r
|
91
|
+
y=0
|
92
|
+
end
|
93
|
+
ell[x+y*width]=obj[k].first
|
94
|
+
for v in 1..(obj[k].length-1)
|
95
|
+
x+=1
|
96
|
+
y+=1
|
97
|
+
ell[x+y*width]=obj[k][v]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
return ell
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/pxlsrt/smart.rb
CHANGED
@@ -80,12 +80,22 @@ module Pxlsrt
|
|
80
80
|
valued="start"
|
81
81
|
k=[]
|
82
82
|
Pxlsrt::Helpers.verbose("Getting Sobel values and colors for pixels...") if options[:verbose]
|
83
|
+
grey=img.grayscale
|
83
84
|
for xy in 0..(w*h-1)
|
84
85
|
x=xy % w
|
85
86
|
y=(xy/w).floor
|
86
87
|
if x!=0 and x!=(w-1) and y!=0 and y!=(h-1)
|
87
|
-
|
88
|
-
|
88
|
+
t1=ChunkyPNG::Color.r(grey[x-1,y-1])
|
89
|
+
t2=ChunkyPNG::Color.r(grey[x,y-1])
|
90
|
+
t3=ChunkyPNG::Color.r(grey[x+1,y-1])
|
91
|
+
t4=ChunkyPNG::Color.r(grey[x-1,y])
|
92
|
+
t5=ChunkyPNG::Color.r(grey[x,y])
|
93
|
+
t6=ChunkyPNG::Color.r(grey[x+1,y])
|
94
|
+
t7=ChunkyPNG::Color.r(grey[x-1,y+1])
|
95
|
+
t8=ChunkyPNG::Color.r(grey[x,y+1])
|
96
|
+
t9=ChunkyPNG::Color.r(grey[x+1,y+1])
|
97
|
+
pixel_x=(sobel_x[0][0]*t1)+(sobel_x[0][1]*t2)+(sobel_x[0][2]*t3)+(sobel_x[1][0]*t4)+(sobel_x[1][1]*t5)+(sobel_x[1][2]*t6)+(sobel_x[2][0]*t7)+(sobel_x[2][1]*t8)+(sobel_x[2][2]*t9)
|
98
|
+
pixel_y=(sobel_y[0][0]*t1)+(sobel_y[0][1]*t2)+(sobel_y[0][2]*t3)+(sobel_y[1][0]*t4)+(sobel_y[1][1]*t5)+(sobel_y[1][2]*t6)+(sobel_y[2][0]*t7)+(sobel_y[2][1]*t8)+(sobel_y[2][2]*t9)
|
89
99
|
val = Math.sqrt(pixel_x * pixel_x + pixel_y * pixel_y).ceil
|
90
100
|
else
|
91
101
|
val = 2000000000
|
@@ -94,11 +104,11 @@ module Pxlsrt
|
|
94
104
|
end
|
95
105
|
if options[:vertical]==true
|
96
106
|
Pxlsrt::Helpers.verbose("Rotating image for vertical mode...") if options[:verbose]
|
97
|
-
k=Pxlsrt::
|
107
|
+
k=Pxlsrt::Lines.rotateImage(k,w,h,3)
|
98
108
|
w,h=h,w
|
99
109
|
end
|
100
110
|
if !options[:diagonal]
|
101
|
-
lines=Pxlsrt::
|
111
|
+
lines=Pxlsrt::Lines.imageRGBLines(k, w)
|
102
112
|
Pxlsrt::Helpers.verbose("Determining bands with a#{options[:absolute] ? "n absolute" : " relative"} threshold of #{options[:threshold]}...") if options[:verbose]
|
103
113
|
bands=Array.new()
|
104
114
|
for j in lines
|
@@ -148,7 +158,7 @@ module Pxlsrt
|
|
148
158
|
end
|
149
159
|
else
|
150
160
|
Pxlsrt::Helpers.verbose("Determining diagonals...") if options[:verbose]
|
151
|
-
dia=Pxlsrt::
|
161
|
+
dia=Pxlsrt::Lines.getDiagonals(k,w,h)
|
152
162
|
Pxlsrt::Helpers.verbose("Determining bands with a#{options[:absolute] ? "n absolute" : " relative"} threshold of #{options[:threshold]}...") if options[:verbose]
|
153
163
|
for j in dia.keys
|
154
164
|
bands=[]
|
@@ -204,11 +214,11 @@ module Pxlsrt
|
|
204
214
|
dia[j]=ell
|
205
215
|
end
|
206
216
|
Pxlsrt::Helpers.verbose("Setting diagonals back to standard lines...") if options[:verbose]
|
207
|
-
image=Pxlsrt::
|
217
|
+
image=Pxlsrt::Lines.fromDiagonals(dia,w)
|
208
218
|
end
|
209
219
|
if options[:vertical]==true
|
210
220
|
Pxlsrt::Helpers.verbose("Rotating back (because of vertical mode).") if options[:verbose]
|
211
|
-
image=Pxlsrt::
|
221
|
+
image=Pxlsrt::Lines.rotateImage(image,w,h,1)
|
212
222
|
w,h=h,w
|
213
223
|
end
|
214
224
|
Pxlsrt::Helpers.verbose("Giving pixels new RGB values...") if options[:verbose]
|
data/lib/pxlsrt/version.rb
CHANGED
data/lib/pxlsrt.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.4.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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/pxlsrt/brute.rb
|
80
80
|
- lib/pxlsrt/colors.rb
|
81
81
|
- lib/pxlsrt/helpers.rb
|
82
|
+
- lib/pxlsrt/lines.rb
|
82
83
|
- lib/pxlsrt/smart.rb
|
83
84
|
- lib/pxlsrt/version.rb
|
84
85
|
homepage: https://github.com/EVA-01/pxlsrt
|