pxlsrt 1.8.1-java

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 783ea861f583a0150d359b36f3567c3c09e7e5cd
4
+ data.tar.gz: 5778f9ed8f18a200aea7693006bc05a7f67246b1
5
+ SHA512:
6
+ metadata.gz: 44bc8625845141409354ce8ad2ca2e3a218c058538bcc9c24efeb891d9be48eae9ca814da637aca1dee134fb96cdb8323227126a3e91e61e41812e6622964cd7
7
+ data.tar.gz: 60c28303d6f558b5db763578f56fc777aa67902a3a3fe5ac780e9389ababdc77e8d04ca9d210d724b9f58f883e0568a439129c3921257a6e5f0983704d6ba1dd
data/bin/pxlsrt ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ require 'pxlsrt'
4
+ require 'thor'
5
+
6
+ class CLI < Thor
7
+ #class_option :verbose, :type => :boolean, :default => false, :aliases => "-V"
8
+
9
+ option :reverse, :default => false, :aliases => "-r"
10
+ option :vertical, :type => :boolean, :default => false, :aliases => "-v"
11
+ option :diagonal, :type => :boolean, :default => false, :aliases => "-d"
12
+ option :method, :type => :string, :default => "sum-rgb", :banner => "[#{PxlsrtJ::Colors::METHODS.join(" | ")}]", :aliases => "-m", :enum => PxlsrtJ::Colors::METHODS
13
+ option :middle, :default => false, :aliases => "-M"
14
+ option :min, :type => :numeric, :default => Float::INFINITY, :banner => "MINIMUM BANDWIDTH"
15
+ option :max, :type => :numeric, :default => Float::INFINITY, :banner => "MAXIMUM BANDWIDTH"
16
+ desc "brute INPUT OUTPUT [options]", "Brute pixel sorting"
17
+ ##
18
+ # Specific options:
19
+ # * min - Minimum bandwidth.
20
+ # * max - Maximum bandwidth.
21
+ def brute(input, output)
22
+ k={:trusted=>true}
23
+ for o in options.keys
24
+ k[o.to_sym]=options[o]
25
+ end
26
+ PxlsrtJ::Brute.suite(input, output, k)
27
+ end
28
+
29
+ option :reverse, :default => false, :aliases => "-r"
30
+ option :vertical, :type => :boolean, :default => false, :aliases => "-v"
31
+ option :diagonal, :type => :boolean, :default => false, :aliases => "-d"
32
+ option :method, :type => :string, :default => "sum-rgb", :banner => "[#{PxlsrtJ::Colors::METHODS.join(" | ")}]", :aliases => "-m", :enum => PxlsrtJ::Colors::METHODS
33
+ option :middle, :default => false, :aliases => "-M"
34
+ option :absolute, :type => :boolean, :default => false, :aliases => "-a", :banner => "ABSOLUTE EDGE FINDING"
35
+ option :threshold, :type => :numeric, :default => 20, :aliases => "-t"
36
+ desc "smart INPUT OUTPUT [options]", "Smart pixel sorting"
37
+ ##
38
+ # Specific options:
39
+ # * threshold - Number used in edge finding. Specifics explained under "absolute".
40
+ # * absolute - Make edge finding absolute over relative. For example, define a range as a collection of values under the threshold. Relative edge finding is when the contrast of the next pixel is larger than the threshold.
41
+ def smart(input, output)
42
+ k={:trusted=>true}
43
+ for o in options.keys
44
+ k[o.to_sym]=options[o]
45
+ end
46
+ PxlsrtJ::Smart.suite(input, output, k)
47
+ end
48
+
49
+ option :method, :type => :string, :default => "brightness", :aliases => "-m", :enum => ["brightness", "white", "black"]
50
+ option :value, :type => :numeric, :aliases => "-v"
51
+ desc "kim INPUT OUTPUT [options]", "Uses Kim Asendorf's algorithm"
52
+ def kim(input, output)
53
+ k= {:trusted => true}
54
+ for o in options.keys
55
+ k[o.to_sym] = options[o]
56
+ end
57
+ PxlsrtJ::Kim.suite(input, output, k)
58
+ end
59
+ end
60
+
61
+ CLI.start(ARGV)
@@ -0,0 +1,215 @@
1
+ require 'java'
2
+ require_relative 'pxlsrt.jar'
3
+ import 'pxlsrt.Pxlsrt'
4
+ # import 'java.io.File'
5
+ import 'javax.imageio.ImageIO'
6
+
7
+ module PxlsrtJ
8
+ class Colors
9
+ METHODS = ["sum-rgb", "red", "green", "blue", "sum-hsb", "hue", "saturation", "brightness", "uniqueness", "luma", "random", "cyan", "magenta", "yellow", "none"]
10
+ end
11
+ class Helpers
12
+ def self.isNumeric?(s)
13
+ true if Float(s) rescue false
14
+ end
15
+ def self.checkOptions(options, rules)
16
+ match=true
17
+ for o in options.keys
18
+ o_match=false
19
+ if rules[o].class==Array
20
+ if rules[o].include?(options[o])
21
+ o_match=true
22
+ else
23
+ for r in 0...rules[o].length
24
+ if rules[o][r].class==Hash
25
+ for n in rules[o][r][:class]
26
+ if n==options[o].class
27
+ o_match=match
28
+ break
29
+ end
30
+ end
31
+ end
32
+ if o_match==true
33
+ break
34
+ end
35
+ end
36
+ end
37
+ elsif rules[o] == :anything
38
+ o_match = true
39
+ end
40
+ match=(match and o_match)
41
+ if match==false
42
+ break
43
+ end
44
+ end
45
+ return match
46
+ end
47
+ def self.prepareOptions(options, image, type)
48
+ if type == :brute or type == :smart
49
+ if PxlsrtJ::Helpers.isNumeric?(options[:middle])
50
+ options[:middle] = options[:middle].to_i
51
+ elsif options[:middle] == "" or options[:middle] == "middle"
52
+ options[:middle] = 1
53
+ else
54
+ options[:middle] = 0
55
+ end
56
+ if not options[:vertical] and not options[:diagonal]
57
+ options[:direction] = "horizontal"
58
+ elsif not options[:vertical] and options[:diagonal]
59
+ options[:direction] = "diagonal"
60
+ elsif options[:vertical] and not options[:diagonal]
61
+ options[:direction] = "vertical"
62
+ elsif options[:vertical] and options[:diagonal]
63
+ options[:direction] = "r-diagonal"
64
+ end
65
+ end
66
+ case type
67
+ when :brute
68
+ if options[:min] == Float::INFINITY
69
+ options[:min] = ((image.width ** 2 + image.height ** 2) ** 0.5).ceil.to_i
70
+ else
71
+ options[:min] = options[:min].to_i
72
+ end
73
+ if options[:max] == Float::INFINITY
74
+ options[:max] = ((image.width ** 2 + image.height ** 2) ** 0.5).ceil.to_i
75
+ else
76
+ options[:max] = options[:max].to_i
77
+ end
78
+ when :smart
79
+ options[:threshold] = options[:threshold].to_i
80
+ when :kim
81
+ unless options[:value] == false
82
+ options[:value] = options[:value].to_i
83
+ end
84
+ end
85
+ end
86
+ end
87
+ class Brute
88
+ def self.suite(inputFileName, outputFileName, o = {})
89
+ kml = PxlsrtJ::Brute.brute(inputFileName, o)
90
+ if kml != nil
91
+ f = Java::JavaIo::File.new outputFileName
92
+ Java::JavaxImageio::ImageIO.write kml.modified, outputFileName.split('.').last, f
93
+ end
94
+ end
95
+ def self.brute(input, o = {})
96
+ defOptions = {
97
+ :reverse => false,
98
+ :vertical => false,
99
+ :diagonal => false,
100
+ :method => "sum-rgb",
101
+ :min => Float::INFINITY,
102
+ :max => Float::INFINITY,
103
+ :trusted => false,
104
+ :middle => false
105
+ }
106
+ defRules = {
107
+ :reverse => [false, true],
108
+ :vertical => [false, true],
109
+ :diagonal => [false, true],
110
+ :method => PxlsrtJ::Colors::METHODS,
111
+ :min => [Float::INFINITY, {:class => [Fixnum]}],
112
+ :max => [Float::INFINITY, {:class => [Fixnum]}],
113
+ :trusted => [false, true],
114
+ :middle => :anything
115
+ }
116
+ options = defOptions.merge(o)
117
+ image = nil
118
+ if o.length==0 or options[:trusted]==true or (options[:trusted]==false and o.length!=0 and PxlsrtJ::Helpers.checkOptions(options, defRules)!=false) and input.class == String
119
+ image = Java::Pxlsrt::Pxlsrt.new input
120
+ PxlsrtJ::Helpers.prepareOptions options, image, :brute
121
+ image.brute(
122
+ options[:min],
123
+ options[:max],
124
+ options[:direction],
125
+ options[:method],
126
+ options[:reverse],
127
+ options[:middle]
128
+ )
129
+ end
130
+ return image
131
+ end
132
+ end
133
+ class Smart
134
+ def self.suite(inputFileName, outputFileName, o = {})
135
+ kml = PxlsrtJ::Smart.smart(inputFileName, o)
136
+ if kml != nil
137
+ f = Java::JavaIo::File.new outputFileName
138
+ Java::JavaxImageio::ImageIO.write kml.modified, outputFileName.split('.').last, f
139
+ end
140
+ end
141
+ def self.smart(input, o = {})
142
+ defOptions = {
143
+ :reverse => false,
144
+ :vertical => false,
145
+ :diagonal => false,
146
+ :method => "sum-rgb",
147
+ :absolute => false,
148
+ :threshold => 20,
149
+ :trusted => false,
150
+ :middle => false
151
+ }
152
+ defRules = {
153
+ :reverse => [false, true],
154
+ :vertical => [false, true],
155
+ :diagonal => [false, true],
156
+ :method => PxlsrtJ::Colors::METHODS,
157
+ :absolute => [false, true],
158
+ :threshold => [{:class => [Float, Fixnum]}],
159
+ :trusted => [false, true],
160
+ :middle => :anything
161
+ }
162
+ options = defOptions.merge(o)
163
+ image = nil
164
+ if o.length==0 or options[:trusted]==true or (options[:trusted]==false and o.length!=0 and PxlsrtJ::Helpers.checkOptions(options, defRules)!=false) and input.class == String
165
+ image = Java::Pxlsrt::Pxlsrt.new input
166
+ PxlsrtJ::Helpers.prepareOptions options, image, :smart
167
+ image.smart(
168
+ options[:threshold],
169
+ options[:absolute],
170
+ options[:direction],
171
+ options[:method],
172
+ options[:reverse],
173
+ options[:middle]
174
+ )
175
+ end
176
+ return image
177
+ end
178
+ end
179
+ class Kim
180
+ def self.suite(inputFileName, outputFileName, o = {})
181
+ kml = PxlsrtJ::Kim.kim(inputFileName, o)
182
+ if kml != nil
183
+ f = Java::JavaIo::File.new outputFileName
184
+ Java::JavaxImageio::ImageIO.write kml.modified, outputFileName.split('.').last, f
185
+ end
186
+ end
187
+ def self.kim(input, o = {})
188
+ defOptions = {
189
+ :method => "brightness",
190
+ :value => false,
191
+ :trusted => false
192
+ }
193
+ defRules = {
194
+ :method => ["brightness", "black", "white"],
195
+ :value => [false, {:class => [Fixnum]}],
196
+ :trusted => [false, true]
197
+ }
198
+ options=defOptions.merge(o)
199
+ image = nil
200
+ if o.length==0 or options[:trusted]==true or (options[:trusted]==false and o.length!=0 and PxlsrtJ::Helpers.checkOptions(options, defRules)!=false) and input.class == String
201
+ image = Java::Pxlsrt::Pxlsrt.new input
202
+ PxlsrtJ::Helpers.prepareOptions options, image, :kim
203
+ if options[:value] == false
204
+ image.kim(options[:method])
205
+ else
206
+ image.kim(
207
+ options[:method],
208
+ options[:value]
209
+ )
210
+ end
211
+ end
212
+ return image
213
+ end
214
+ end
215
+ end
Binary file
@@ -0,0 +1,3 @@
1
+ module PxlsrtJ
2
+ VERSION = "1.8.1"
3
+ end
data/lib/pxlsrt.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "pxlsrt/version"
2
+ require "pxlsrt/java"
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pxlsrt
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.8.1
5
+ platform: java
6
+ authors:
7
+ - EVA-01
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.18'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.18'
55
+ description: Pixel sort PNG files with ease!
56
+ email:
57
+ - j.bruno.che@gmail.com
58
+ executables:
59
+ - pxlsrt
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - bin/pxlsrt
64
+ - lib/pxlsrt.rb
65
+ - lib/pxlsrt/java.rb
66
+ - lib/pxlsrt/pxlsrt.jar
67
+ - lib/pxlsrt/version.rb
68
+ homepage: https://github.com/EVA-01/pxlsrt
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.4.8
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Pixel sort PNG files.
92
+ test_files: []