image_svd 0.1.6 → 0.1.7

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: 7ba755a5c928c69d8bf6b2e84e51cb1a2493d641
4
- data.tar.gz: ed5574e929155f21d39e95cf1b9d7026babb6fba
3
+ metadata.gz: ce7398aabec67a2fcb7e6ec057a0f09e9f86b693
4
+ data.tar.gz: aae65d572ac588b0e263dc58aadeeb8ce44a4080
5
5
  SHA512:
6
- metadata.gz: 7653dc6421ad11f66c938b34a653ad5ed74372c803984d38d904c8017021d994abaa278fde9e93ae2598efd9fc40927fac904846ed477f49db1432b54c12c5a9
7
- data.tar.gz: de64f94042ef0e17949ae4bd4b7772f4f60c9ed210bc3b10ceb9d781d93a36b36b77d0584dcbf99f48482ff08583e1e50eeb4e8e09deea5f70cdcd68ffc91d6d
6
+ metadata.gz: 37024e30240eab7642cc0996f156f398cce71d867da33f071d211bfe5c4ede0cc3a740c1dcca441050763b7cd018f0923eca069f4436715b7bcabd81f4131da5
7
+ data.tar.gz: 6b395393e0d37728026f450a32e7e377632e097442dddd2f21441a33643918fa1149b9d97867ab5a32929086765fae25452a2e0547ce045bcfa297ab69257d6a
@@ -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.iterate_on_input(options) do |o|
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.merge(singular_values: vs)
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.iterate_on_input(opts)
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
- o = process(opts).merge(new_options)
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
- %x(echo '#{Util::IMAGE_CREDIT}' > iptcData.pro)
157
- %x(convert #{path} +profile 8BIM -profile 8BIMTEXT:iptcData.pro #{path})
158
- %x(rm iptcData.pro)
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)
@@ -15,7 +15,7 @@ module ImageSvd
15
15
 
16
16
  IMAGE_CREDIT = <<-EOS
17
17
  2#0="&#0;&#2;"
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"
@@ -1,4 +1,4 @@
1
1
  # This module holds the gem's code
2
2
  module ImageSvd
3
- VERSION = '0.1.6'
3
+ VERSION = '0.1.7'
4
4
  end
@@ -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.6
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-12 00:00:00.000000000 Z
11
+ date: 2014-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pnm