pxlsrt 1.6 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eddc063a560a8420871b095ee6e56c96d1b3b66b
4
- data.tar.gz: dcfb8606b9c47d43402e6030a80d274b83d3a4e0
3
+ metadata.gz: 6ef9f339272ae1b0a3e64f18977fbff964134b27
4
+ data.tar.gz: 7b2b1da4aed79741292035875de61a5021e914be
5
5
  SHA512:
6
- metadata.gz: e4b768476d0bda214468c888b1357396d4c62bc5d60aa45546c8d283f73b1957a3e11112589ae689c6a67a2ec0ca37609b94c55b77d70f118949894fb976655c
7
- data.tar.gz: 9afbf4b2e3515a51d95143d7d30e031788f7de39ade4870e98f17938b4026b5c9a687a840c493c58641669db04b7ff6dad3b0f045ed5f07fbe3baf513b593111
6
+ metadata.gz: 806ffa517135b62506f57c4f25f000c6850318474241090da870e9778ac112da2216ec31f131bcc2b766a9313f73add3523c409889f04903cbaac58382945a6c
7
+ data.tar.gz: e50c87887ec75c396874dedb234521b6eeff6e3440ffb44f4a243ebbbaddd116e7eb0e58f6f4f61c8dd55d16c99c9d9bf5284b582d028c7375af65b8e7f974ad
data/bin/pxlsrt CHANGED
@@ -14,7 +14,7 @@ require 'thor'
14
14
  # * verbose - Have pxlsrt tell you what it's working on.
15
15
  # * help - More in depth commands.
16
16
  class CLI < Thor
17
- class_option :reverse, :type => :string, :default => "no", :banner => "[no | reverse | either]", :aliases => "-r", :enum => ["no", "reverse", "either"]
17
+ class_option :reverse, :default => false, :aliases => "-r"
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"
@@ -19,7 +19,7 @@ module Pxlsrt
19
19
  def self.brute(input, o={})
20
20
  startTime=Time.now
21
21
  defOptions={
22
- :reverse => "no",
22
+ :reverse => false,
23
23
  :vertical => false,
24
24
  :diagonal => false,
25
25
  :smooth => false,
@@ -31,7 +31,7 @@ module Pxlsrt
31
31
  :middle => false
32
32
  }
33
33
  defRules={
34
- :reverse => ["no", "reverse", "either"],
34
+ :reverse => :anything,
35
35
  :vertical => [false, true],
36
36
  :diagonal => [false, true],
37
37
  :smooth => [false, true],
@@ -52,18 +52,19 @@ module Pxlsrt
52
52
  if ca.length==1
53
53
  return ca.first
54
54
  end
55
+ Pxlsrt::Helpers.verbose(ca) if ca.length == 0
55
56
  if !chunky
56
57
  r=((ca.collect { |c| c[0] }).inject{ |sum, el| sum+el }).to_f / ca.size
57
58
  g=((ca.collect { |c| c[1] }).inject{ |sum, el| sum+el }).to_f / ca.size
58
59
  b=((ca.collect { |c| c[2] }).inject{ |sum, el| sum+el }).to_f / ca.size
59
60
  a=((ca.collect { |c| c[3] }).inject{ |sum, el| sum+el }).to_f / ca.size
60
- return [r,g,b,a]
61
+ return [r.to_i, g.to_i, b.to_i, a.to_i]
61
62
  else
62
63
  r=((ca.collect { |c| ChunkyPNG::Color.r(c) }).inject{ |sum, el| sum+el }).to_f / ca.size
63
64
  g=((ca.collect { |c| ChunkyPNG::Color.g(c) }).inject{ |sum, el| sum+el }).to_f / ca.size
64
65
  b=((ca.collect { |c| ChunkyPNG::Color.b(c) }).inject{ |sum, el| sum+el }).to_f / ca.size
65
66
  a=((ca.collect { |c| ChunkyPNG::Color.a(c) }).inject{ |sum, el| sum+el }).to_f / ca.size
66
- return ChunkyPNG::Color.rgba(r,g,b,a)
67
+ return ChunkyPNG::Color.rgba(r.to_i, g.to_i, b.to_i, a.to_i)
67
68
  end
68
69
  end
69
70
  ##
@@ -102,6 +103,7 @@ module Pxlsrt
102
103
  # * alpha
103
104
  def self.pixelSort(list, how, reverse)
104
105
  mhm=[]
106
+ Pxlsrt::Helpers.error(list) if list.length == 0
105
107
  case how.downcase
106
108
  when "sum-rgb"
107
109
  mhm= list.sort_by { |c| ChunkyPNG::Color.r(c)+ChunkyPNG::Color.g(c)+ChunkyPNG::Color.b(c) }
@@ -59,9 +59,9 @@ module Pxlsrt
59
59
  ##
60
60
  # Pixel sorting helper to eliminate repetition.
61
61
  def self.handlePixelSort(band, o)
62
- if o[:reverse].downcase == "reverse"
62
+ if (o[:reverse].class == String and (o[:reverse].downcase == "reverse" or o[:reverse] == "")) or o[:reverse] == true
63
63
  reverse = 1
64
- elsif o[:reverse].downcase == "either"
64
+ elsif o[:reverse].class == String and o[:reverse].downcase == "either"
65
65
  reverse = -1
66
66
  else
67
67
  reverse = 0
@@ -88,32 +88,32 @@ module Pxlsrt
88
88
  # Because of the requirements of pxlsrt, it doesn't actually slice the array, but returns a range-like array. Example:
89
89
  # [[0, 5], [6, 7], [8, 10]]
90
90
  def self.randomSlices(mainLength, minLength, maxLength)
91
- len=mainLength-1
92
- if len!=0
93
- min=[minLength, maxLength].min
94
- max=[maxLength, minLength].max
95
- if min > len
96
- min=len
97
- end
98
- if max > len
99
- max=len
100
- end
101
- nu=[[0, rand(min..max)]]
102
- last=nu.first[1]
103
- sorting=true
91
+ if mainLength <= 1
92
+ return [[0, 0]]
93
+ else
94
+ min = [minLength, maxLength].min
95
+ max = [minLength, maxLength].max
96
+ min = mainLength if min > mainLength
97
+ max = mainLength if max > mainLength
98
+ min = 1 if min < 1
99
+ max = 1 if max < 1
100
+ nu = [[0, rand(min..max) - 1]]
101
+ last = nu.last.last
102
+ sorting = true
103
+ i = 0
104
104
  while sorting do
105
- if (len-last) <= max
106
- nu.push([last+1, len])
107
- sorting=false
105
+ if (mainLength - last) <= max
106
+ if last + 1 <= mainLength - 1
107
+ nu.push([last + 1, mainLength - 1])
108
+ end
109
+ sorting = false
108
110
  else
109
- nu.push([last+1, last+1+rand(min..max)])
110
- last=nu.last[1]
111
+ nu.push([last+1, last + rand(min..max)])
111
112
  end
113
+ last = nu.last.last
112
114
  end
113
- else
114
- nu=[[0,0]]
115
+ return nu
115
116
  end
116
- return nu
117
117
  end
118
118
  ##
119
119
  # Uses math to turn an array into an array of diagonals.
@@ -20,7 +20,7 @@ module Pxlsrt
20
20
  def self.smart(input, o={})
21
21
  startTime=Time.now
22
22
  defOptions={
23
- :reverse => "no",
23
+ :reverse => false,
24
24
  :vertical => false,
25
25
  :diagonal => false,
26
26
  :smooth => false,
@@ -32,7 +32,7 @@ module Pxlsrt
32
32
  :middle => false
33
33
  }
34
34
  defRules={
35
- :reverse => ["no", "reverse", "either"],
35
+ :reverse => :anything,
36
36
  :vertical => [false, true],
37
37
  :diagonal => [false, true],
38
38
  :smooth => [false, true],
@@ -1,5 +1,5 @@
1
1
  ##
2
2
  # The main module, your best friend.
3
3
  module Pxlsrt
4
- VERSION = "1.6"
4
+ VERSION = "1.6.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.6'
4
+ version: 1.6.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-08-11 00:00:00.000000000 Z
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.3.0
106
+ rubygems_version: 2.4.1
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Pixel sort PNG files.