pxlsrt 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 656493d31b58b436d501a9211402394cb3527753
4
- data.tar.gz: ab1f3e92f84610d992a7bf1295db33e556309ec6
3
+ metadata.gz: b67067a23830e901ce06d35571c5e5435ce6cb3b
4
+ data.tar.gz: 93809cf7e8cd9fc620008f1c28bab5b381e70079
5
5
  SHA512:
6
- metadata.gz: 8acafe9a33025af289c5753f8abb320f87cb16633fefa9b43b2008dfec9193917bc8386d9fec9896901c5229b301a3c5de59222622ef2767050ffec70b2cbb64
7
- data.tar.gz: 952ada3617bb2514ff162c466b9f7935aab2e6ff396201a2b1e614739c431652a4dfd36934597da519f6ed1bbb237d2008a27d11f9136050ae3f17e4b041c842
6
+ metadata.gz: 4b3fa27fd1981baeba1d480b1b6ecea8e8a8f58c75d218310e560e62f03efd4c83764bf1f8bc012f660f3c7ed885df06b6c39daef81ab3923f141691507fb281
7
+ data.tar.gz: 0c26e6b7c66683d371dd4cb7a1c650c1a46a9050e2bbc90c09cafe6c28278c09a72d3ef0e3dc146680c7d1251b59cf10d4e0e4cd3ec8cf0d7d2caaa060f75b5f
data/bin/pxlsrt CHANGED
@@ -20,7 +20,7 @@ class CLI < Thor
20
20
  class_option :smooth, :type => :boolean, :default => false, :aliases => "-s"
21
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
- class_option :middle, :type => :boolean, :default => false, :aliases => "-M"
23
+ class_option :middle, :default => false, :aliases => "-M"
24
24
 
25
25
  option :min, :type => :numeric, :default => Float::INFINITY, :banner => "MINIMUM BANDWIDTH"
26
26
  option :max, :type => :numeric, :default => Float::INFINITY, :banner => "MAXIMUM BANDWIDTH"
@@ -40,7 +40,7 @@ module Pxlsrt
40
40
  :min => [Float::INFINITY, {:class => [Fixnum]}],
41
41
  :max => [Float::INFINITY, {:class => [Fixnum]}],
42
42
  :trusted => [false, true],
43
- :middle => [false, true]
43
+ :middle => :anything
44
44
  }
45
45
  options=defOptions.merge(o)
46
46
  if o.length==0 or options[:trusted]==true or (options[:trusted]==false and o.length!=0 and Pxlsrt::Helpers.checkOptions(options, defRules)!=false)
@@ -93,14 +93,12 @@ module Pxlsrt
93
93
  newInTown=[]
94
94
  if options[:smooth]!=true
95
95
  for ranger in sliceRanges
96
- newInTown.concat(Pxlsrt::Lines.middlate(Pxlsrt::Colors.pixelSort(m[ranger[0]..ranger[1]], options[:method].downcase, nre))) if options[:middle]
97
- newInTown.concat(Pxlsrt::Colors.pixelSort(m[ranger[0]..ranger[1]], options[:method].downcase, nre)) if !options[:middle]
96
+ newInTown.concat(Pxlsrt::Lines.handleMiddlate(Pxlsrt::Colors.pixelSort(m[ranger[0]..ranger[1]], options[:method].downcase, nre), options[:middle]))
98
97
  end
99
98
  else
100
99
  for ranger in sliceRanges
101
100
  k=(m[ranger[0]..ranger[1]]).group_by { |x| x }
102
- g=Pxlsrt::Colors.pixelSort(k.keys, options[:method].downcase, nre)
103
- g=Pxlsrt::Lines.middlate(g) if options[:middle]
101
+ g=Pxlsrt::Lines.handleMiddlate(Pxlsrt::Colors.pixelSort(k.keys, options[:method].downcase, nre), options[:middle])
104
102
  j=g.map { |x| k[x] }.flatten(1)
105
103
  newInTown.concat(j)
106
104
  end
@@ -116,14 +114,12 @@ module Pxlsrt
116
114
  newInTown=[]
117
115
  if options[:smooth]!=true
118
116
  for ranger in sliceRanges
119
- newInTown.concat(Pxlsrt::Lines.middlate(Pxlsrt::Colors.pixelSort(dia[m][ranger[0]..ranger[1]], options[:method].downcase, nre))) if options[:middle]
120
- newInTown.concat(Pxlsrt::Colors.pixelSort(dia[m][ranger[0]..ranger[1]], options[:method].downcase, nre)) if !options[:middle]
117
+ newInTown.concat(Pxlsrt::Lines.handleMiddlate(Pxlsrt::Colors.pixelSort(dia[m][ranger[0]..ranger[1]], options[:method].downcase, nre), options[:middle]))
121
118
  end
122
119
  else
123
120
  for ranger in sliceRanges
124
121
  k=(dia[m][ranger[0]..ranger[1]]).group_by { |x| x }
125
- g=Pxlsrt::Colors.pixelSort(k.keys, options[:method].downcase, nre)
126
- g=Pxlsrt::Lines.middlate(g) if options[:middle]
122
+ g=Pxlsrt::Lines.handleMiddlate(Pxlsrt::Colors.pixelSort(k.keys, options[:method].downcase, nre), options[:middle])
127
123
  j=g.map { |x| k[x] }.flatten(1)
128
124
  newInTown.concat(j)
129
125
  end
@@ -15,11 +15,6 @@ module Pxlsrt
15
15
  return File.read(path).bytes==[137, 80, 78, 71, 10]
16
16
  end
17
17
  ##
18
- # This is really lame. Adds first three values of an array together.
19
- def self.pxldex(pxl)
20
- return pxl[0]+pxl[1]+pxl[2]
21
- end
22
- ##
23
18
  # Converts an RGB-like array ([red, green, blue]) into an HSB-like array ([hue, saturation, brightness]).
24
19
  def self.rgb2hsb(rgb)
25
20
  r = rgb[0] / 255.0
@@ -97,9 +92,9 @@ module Pxlsrt
97
92
  mhm=[]
98
93
  case how.downcase
99
94
  when "sum-rgb"
100
- mhm= list.sort_by { |c| Pxlsrt::Colors.pxldex(c) }
95
+ mhm= list.sort_by { |c| c[0]+c[1]+c[2] }
101
96
  when "sum-rgba"
102
- mhm=list.sort_by { |c| Pxlsrt::Colors.pxldex(c)+c[3] }
97
+ mhm=list.sort_by { |c| c[0]+c[1]+c[2]+c[3] }
103
98
  when "red"
104
99
  mhm= list.sort_by { |c| c[0] }
105
100
  when "yellow"
@@ -126,13 +121,13 @@ module Pxlsrt
126
121
  avg=Pxlsrt::Colors.colorAverage(list)
127
122
  mhm=list.sort_by { |c| Pxlsrt::Colors.colorUniqueness(c, [avg]) }
128
123
  when "luma"
129
- mhm=list.sort_by { |c| Pxlsrt::Colors.pxldex([c[0]*0.2126, c[1]*0.7152, c[2]*0.0722]) }
124
+ mhm=list.sort_by { |c| c[0]*0.2126+c[1]*0.7152+c[2]*0.0722 }
130
125
  when "random"
131
126
  mhm=list.shuffle
132
127
  when "alpha"
133
128
  mhm=list.sort_by{ |c| c[3] }
134
129
  else
135
- mhm= list.sort_by { |c| Pxlsrt::Colors.pxldex(c) }
130
+ mhm= list.sort_by { |c| c[0]+c[1]+c[2] }
136
131
  end
137
132
  if reverse == 0
138
133
  return mhm
@@ -18,6 +18,11 @@ module Pxlsrt
18
18
  return "\e[36m#{what}\e[0m"
19
19
  end
20
20
  ##
21
+ # Determines if a string can be a float or integer.
22
+ def self.isNumeric?(s)
23
+ true if Float(s) rescue false
24
+ end
25
+ ##
21
26
  # Checks if supplied options follow the rules.
22
27
  def self.checkOptions(options, rules)
23
28
  match=true
@@ -41,6 +46,8 @@ module Pxlsrt
41
46
  end
42
47
  end
43
48
  end
49
+ elsif rules[o] == :anything
50
+ o_match = true
44
51
  end
45
52
  match=(match and o_match)
46
53
  if match==false
@@ -27,26 +27,65 @@ module Pxlsrt
27
27
  ##
28
28
  # Some fancy rearranging.
29
29
  # [a, b, c, d, e] -> [d, b, a, c, e]
30
+ # [a, b, c, d] -> [c, a, b, d]
30
31
  def self.middlate(arr)
31
32
  a=[]
32
- f=(arr.length/2.0).ceil-1
33
- for e in 1..arr.length
34
- if (arr.length+e)%2==0
35
- a[f+(e/2.0).floor]=arr[e-1]
36
- elsif (arr.length+e)%2==1
37
- a[f-(e/2.0).floor]=arr[e-1]
33
+ for e in 0...arr.length
34
+ if (arr.length+e) % 2 == 1
35
+ a[0.5*(arr.length+e-1)]=arr[e]
36
+ elsif (arr.length+e) % 2 == 0
37
+ a[0.5*(arr.length-e)-1]=arr[e]
38
38
  end
39
39
  end
40
40
  return a
41
41
  end
42
42
  ##
43
+ # Some fancy unrearranging.
44
+ # [d, b, a, c, e] -> [a, b, c, d, e]
45
+ # [c, a, b, d] -> [a, b, c, d]
46
+ def self.reverseMiddlate(arr)
47
+ a=[]
48
+ for e in 0...arr.length
49
+ if e == ((arr.length/2.0).ceil - 1)
50
+ a[0] = arr[e]
51
+ elsif e < ((arr.length/2.0).ceil - 1)
52
+ a[arr.length - 2*e - 2] = arr[e]
53
+ elsif e > ((arr.length/2.0).ceil - 1)
54
+ a[2*e - arr.length + 1] = arr[e]
55
+ end
56
+ end
57
+ return a
58
+ end
59
+ ##
60
+ # Handle middlate requests
61
+ def self.handleMiddlate(arr, d)
62
+ n = Pxlsrt::Helpers.isNumeric?(d)
63
+ if n and d.to_i > 0
64
+ k = arr
65
+ for l in 0...(d.to_i)
66
+ k = Pxlsrt::Lines.middlate(k)
67
+ end
68
+ return k
69
+ elsif n and d.to_i < 0
70
+ k = arr
71
+ for l in 0...(d.to_i.abs)
72
+ k = Pxlsrt::Lines.reverseMiddlate(k)
73
+ end
74
+ return k
75
+ elsif d == "" or d == "middle"
76
+ return Pxlsrt::Lines.middlate(arr)
77
+ else
78
+ return arr
79
+ end
80
+ end
81
+ ##
43
82
  # Gets "rows" of an array based on a width
44
83
  def self.imageRGBLines(image, width)
45
84
  return image.each_slice(width).to_a
46
85
  end
47
86
  ##
48
87
  # Outputs random slices of an array.
49
- # Because of the requirements of pxlsrt, it doesn't actually slice the array, bute returns a range-like array. Example:
88
+ # Because of the requirements of pxlsrt, it doesn't actually slice the array, but returns a range-like array. Example:
50
89
  # [[0, 5], [6, 7], [8, 10]]
51
90
  def self.randomSlices(arr, minLength, maxLength)
52
91
  len=arr.length-1
@@ -3,9 +3,9 @@ require 'oily_png'
3
3
 
4
4
  module Pxlsrt
5
5
  ##
6
- # Smart sorting uses edge-finding algorithms to create bands to sort,
6
+ # Smart sorting uses sorted-finding algorithms to create bands to sort,
7
7
  # as opposed to brute sorting which doesn't care for the content or
8
- # edges, just a specified range to create bands.
8
+ # sorteds, just a specified range to create bands.
9
9
  class Smart
10
10
  ##
11
11
  # Uses Pxlsrt::Smart.smart to input and output from pne method.
@@ -28,7 +28,7 @@ module Pxlsrt
28
28
  :verbose => false,
29
29
  :absolute => false,
30
30
  :threshold => 20,
31
- :edge => 2,
31
+ :sorted => 2,
32
32
  :trusted => false,
33
33
  :middle => false
34
34
  }
@@ -41,9 +41,9 @@ module Pxlsrt
41
41
  :verbose => [false, true],
42
42
  :absolute => [false, true],
43
43
  :threshold => [{:class => [Float, Fixnum]}],
44
- :edge => [{:class => [Fixnum]}],
44
+ :sorted => [{:class => [Fixnum]}],
45
45
  :trusted => [false, true],
46
- :middle => [false, true]
46
+ :middle => :anything
47
47
  }
48
48
  options=defOptions.merge(o)
49
49
  if o.length==0 or options[:trusted]==true or (options[:trusted]==false and o.length!=0 and Pxlsrt::Helpers.checkOptions(options, defRules)!=false)
@@ -151,13 +151,11 @@ module Pxlsrt
151
151
  if options[:smooth]
152
152
  for band in bands
153
153
  u=band.group_by {|x| x}
154
- image.concat(Pxlsrt::Colors.pixelSort(u.keys, options[:method], nre).map { |x| u[x] }.flatten(1)) if !options[:middle]
155
- image.concat(Pxlsrt::Lines(Pxlsrt::Colors.pixelSort(u.keys, options[:method], nre).map { |x| u[x] }.flatten(1))) if options[:middle]
154
+ image.concat(Pxlsrt::Lines.handleMiddlate(Pxlsrt::Colors.pixelSort(u.keys, options[:method], nre).map { |x| u[x] }.flatten(1), options[:middle]))
156
155
  end
157
156
  else
158
157
  for band in bands
159
- image.concat(Pxlsrt::Colors.pixelSort(band, options[:method], nre)) if !options[:middle]
160
- image.concat(Pxlsrt::Lines.middlate(Pxlsrt::Colors.pixelSort(band, options[:method], nre))) if options[:middle]
158
+ image.concat(Pxlsrt::Lines.handleMiddlate(Pxlsrt::Colors.pixelSort(band, options[:method], nre), options[:middle]))
161
159
  end
162
160
  end
163
161
  else
@@ -208,13 +206,11 @@ module Pxlsrt
208
206
  if options[:smooth]
209
207
  for band in dia[j]
210
208
  u=band.group_by {|x| x}
211
- ell.concat(Pxlsrt::Colors.pixelSort(u.keys, options[:method], nre).map { |x| u[x] }.flatten(1)) if !options[:middle]
212
- ell.concat(Pxlsrt::Lines.middlate(Pxlsrt::Colors.pixelSort(u.keys, options[:method], nre).map { |x| u[x] }.flatten(1))) if options[:middle]
209
+ ell.concat(Pxlsrt::Lines.handleMiddlate(Pxlsrt::Colors.pixelSort(u.keys, options[:method], nre).map { |x| u[x] }.flatten(1), options[:middle]))
213
210
  end
214
211
  else
215
212
  for band in dia[j]
216
- ell.concat(Pxlsrt::Colors.pixelSort(band, options[:method], nre)) if !options[:middle]
217
- ell.concat(Pxlsrt::Lines.middlate(Pxlsrt::Colors.pixelSort(band, options[:method], nre))) if options[:middle]
213
+ ell.concat(Pxlsrt::Lines.handleMiddlate(Pxlsrt::Colors.pixelSort(band, options[:method], nre), options[:middle]))
218
214
  end
219
215
  end
220
216
  dia[j]=ell
@@ -1,5 +1,5 @@
1
1
  ##
2
2
  # The main module, your best friend.
3
3
  module Pxlsrt
4
- VERSION = "1.5.0"
4
+ VERSION = "1.5.1"
5
5
  end
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.5.0
4
+ version: 1.5.1
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-09 00:00:00.000000000 Z
11
+ date: 2014-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler