image_svd 0.1.6 → 0.1.7
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 +4 -4
- data/lib/image_svd/cli.rb +27 -5
- data/lib/image_svd/image_matrix.rb +4 -3
- data/lib/image_svd/util.rb +1 -1
- data/lib/image_svd/version.rb +1 -1
- data/spec/cli_spec.rb +4 -2
- 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: ce7398aabec67a2fcb7e6ec057a0f09e9f86b693
|
4
|
+
data.tar.gz: aae65d572ac588b0e263dc58aadeeb8ce44a4080
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37024e30240eab7642cc0996f156f398cce71d867da33f071d211bfe5c4ede0cc3a740c1dcca441050763b7cd018f0923eca069f4436715b7bcabd81f4131da5
|
7
|
+
data.tar.gz: 6b395393e0d37728026f450a32e7e377632e097442dddd2f21441a33643918fa1149b9d97867ab5a32929086765fae25452a2e0547ce045bcfa297ab69257d6a
|
data/lib/image_svd/cli.rb
CHANGED
@@ -5,7 +5,14 @@ module ImageSvd
|
|
5
5
|
class CLI
|
6
6
|
# The entry point for the application logic
|
7
7
|
def run(options)
|
8
|
-
Options.
|
8
|
+
pool = Options.collect_input(options)
|
9
|
+
until pool.empty?
|
10
|
+
async_batch(pool.slice!(0..(options[:thread_count] - 1)))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def async_batch(arr_options)
|
15
|
+
arr_options.each do |o|
|
9
16
|
if o[:directory]
|
10
17
|
fork { run_single_image(o) }
|
11
18
|
else
|
@@ -108,6 +115,14 @@ module ImageSvd
|
|
108
115
|
' it contains.',
|
109
116
|
default: false,
|
110
117
|
short: '-r'
|
118
|
+
opt :thread_count,
|
119
|
+
'Advanced feature. The amount of separate threads to use when'\
|
120
|
+
' processing images. Relevant when processing many images in'\
|
121
|
+
' a directory. Should not exceed (n - 1) where n is the'\
|
122
|
+
' logical core count on the end user\'s computer. Otherwise,'\
|
123
|
+
' a higher number means less total time spent processing.',
|
124
|
+
default: 3,
|
125
|
+
short: '-t'
|
111
126
|
end
|
112
127
|
end
|
113
128
|
# rubocop:enable MethodLength
|
@@ -121,7 +136,8 @@ module ImageSvd
|
|
121
136
|
|
122
137
|
def self.process(opts)
|
123
138
|
vs = format_num_sing_vals(opts[:num_singular_values].to_s)
|
124
|
-
opts
|
139
|
+
n = validate_thread_count(opts[:thread_count])
|
140
|
+
opts.merge(singular_values: vs, thread_count: n)
|
125
141
|
end
|
126
142
|
|
127
143
|
# reformats the string cmd line option to an array
|
@@ -132,6 +148,11 @@ module ImageSvd
|
|
132
148
|
vs.length == 1 ? vs : ((vs.first)..(vs.last)).to_a
|
133
149
|
end
|
134
150
|
|
151
|
+
# prevent non positive requested thread_counts
|
152
|
+
def self.validate_thread_count(n)
|
153
|
+
n > 1 ? n : 1
|
154
|
+
end
|
155
|
+
|
135
156
|
# reformats directory inputs into an array of files, or repackages file
|
136
157
|
# inputs to be contained inside an array
|
137
158
|
def self.expand_input_files(opts)
|
@@ -152,16 +173,17 @@ module ImageSvd
|
|
152
173
|
(path_components << 'out' << filename).join('/')
|
153
174
|
end
|
154
175
|
|
155
|
-
def self.
|
176
|
+
def self.collect_input(opts)
|
156
177
|
%x(mkdir #{opts[:input_file].path + 'out'}) if opts[:directory]
|
178
|
+
collection = []
|
157
179
|
expand_input_files(opts).each do |file|
|
158
180
|
new_options = { input_file: file }
|
159
181
|
if opts[:directory]
|
160
182
|
new_options.merge!(output_name: output_dir_path_for_input_file(file))
|
161
183
|
end
|
162
|
-
|
163
|
-
yield o
|
184
|
+
collection << process(opts).merge(new_options)
|
164
185
|
end
|
186
|
+
collection
|
165
187
|
end
|
166
188
|
end
|
167
189
|
end
|
@@ -153,9 +153,10 @@ module ImageSvd
|
|
153
153
|
|
154
154
|
# more info: http://www.imagemagick.org/Usage/formats/#profile_iptc
|
155
155
|
def add_image_svd_credit!(path)
|
156
|
-
|
157
|
-
%x(
|
158
|
-
%x(
|
156
|
+
r = rand(99999)
|
157
|
+
%x(echo '#{Util::IMAGE_CREDIT}' > iptcData#{r}.pro)
|
158
|
+
%x(convert #{path} +profile 8BIM -profile 8BIMTEXT:iptcData#{r}.pro #{path})
|
159
|
+
%x(rm iptcData#{r}.pro)
|
159
160
|
end
|
160
161
|
|
161
162
|
def save_svd(path)
|
data/lib/image_svd/util.rb
CHANGED
@@ -15,7 +15,7 @@ module ImageSvd
|
|
15
15
|
|
16
16
|
IMAGE_CREDIT = <<-EOS
|
17
17
|
2#0="�"
|
18
|
-
2#120#Caption="Created with image_svd"
|
18
|
+
2#120#Caption="Created with image_svd v #{ImageSvd::VERSION}"
|
19
19
|
2#40#Special Instructions="http://www.rubygems.org/gems/image_svd"
|
20
20
|
2#80#Byline="http://www.ilyakavalerov.com"
|
21
21
|
2#110#Credit="Image manipulation by Ilya Kavalerov"
|
data/lib/image_svd/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -11,7 +11,8 @@ describe 'CLI' do
|
|
11
11
|
input_file: orig,
|
12
12
|
convert: true,
|
13
13
|
num_singular_values: '2',
|
14
|
-
grayscale: true
|
14
|
+
grayscale: true,
|
15
|
+
thread_count: 3
|
15
16
|
}
|
16
17
|
end
|
17
18
|
|
@@ -69,7 +70,8 @@ describe 'CLI' do
|
|
69
70
|
input_file: orig,
|
70
71
|
convert: true,
|
71
72
|
num_singular_values: '2',
|
72
|
-
grayscale: false
|
73
|
+
grayscale: false,
|
74
|
+
thread_count: 3
|
73
75
|
}
|
74
76
|
end
|
75
77
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_svd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Kavalerov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pnm
|