ruby-vips 0.1.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.
@@ -0,0 +1,3 @@
1
+ module VIPS
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,275 @@
1
+ module VIPS
2
+ class Writer
3
+ def write(path)
4
+ write_internal path
5
+ end
6
+ end
7
+
8
+ class CSVWriter < Writer
9
+ attr_accessor :separator
10
+
11
+ def initialize(image, options={})
12
+ super image
13
+ @separator = "\t"
14
+
15
+ self.separator = options[:separator] if options.has_key?(:separator)
16
+ end
17
+
18
+ def write(path)
19
+ write_internal "#{path}:sep:#{@separator}"
20
+ end
21
+ end
22
+
23
+ class JPEGWriter < Writer
24
+ attr_reader :quality
25
+
26
+ def initialize(image, options={})
27
+ super image
28
+
29
+ @quality = 75
30
+
31
+ self.quality = options[:quality] if options.has_key?(:quality)
32
+ end
33
+
34
+ def write(path)
35
+ write_internal "#{path}:#{@quality}"
36
+ end
37
+
38
+ def to_memory
39
+ buf_internal @quality
40
+ end
41
+
42
+ def quality=(quality_v)
43
+ unless (0..100).include?(quality_v)
44
+ raise ArgumentError, 'quality must be a numeric value between 0 and 100'
45
+ end
46
+
47
+ @quality = quality_v
48
+ end
49
+ end
50
+
51
+ class PNGWriter < Writer
52
+ attr_reader :compression
53
+ attr_accessor :interlace
54
+
55
+ def initialize(image, options={})
56
+ super image
57
+
58
+ @compression = 6
59
+ @interlace = false
60
+
61
+ self.compression = options[:compression] if options.has_key?(:compression)
62
+ self.interlace = options[:interlace] if options.has_key?(:interlace)
63
+ end
64
+
65
+ def write(path)
66
+ write_internal "#{path}:#{@compression},#{@interlace ? 1 : 0}"
67
+ end
68
+
69
+ def to_memory
70
+ buf_internal @compression, (@interlace ? 1 : 0)
71
+ end
72
+
73
+ def compression=(compression_v)
74
+ unless (0..9).include?(compression_v)
75
+ raise ArgumentError, 'compression must be a numeric value between 0 and 9'
76
+ end
77
+
78
+ @compression = compression_v
79
+ end
80
+ end
81
+
82
+ class PPMWriter < Writer
83
+ attr_reader :format
84
+
85
+ FORMAT = [:binary, :ascii]
86
+
87
+ def initialize(image, options={})
88
+ super image
89
+
90
+ @format = :binary
91
+
92
+ self.format = options[:format] if options.has_key?(:format)
93
+ end
94
+
95
+ def write(path)
96
+ write_internal "#{path}:#{@format}"
97
+ end
98
+
99
+ def format=(format_v)
100
+ unless FORMAT.include?(format_v)
101
+ raise ArgumentError, "format must be one of #{FORMAT.join(', ')}"
102
+ end
103
+
104
+ @format = format_v
105
+ end
106
+ end
107
+
108
+ class TIFFWriter < Writer
109
+ attr_reader :compression, :layout, :multi_res, :format, :resolution_units,
110
+ :resolution, :predictor, :quality, :tile_size
111
+
112
+ COMPRESSION = [:none, :jpeg, :deflate, :packbits, :ccittfax4, :lzw]
113
+ PREDICTOR = [:none, :horizontal_differencing, :floating_point]
114
+ LAYOUT = [:strip, :tile]
115
+ MULTI_RES = [:flat, :pyramid]
116
+ FORMAT = [:manybit, :onebit]
117
+ RESOLUTION_UNITS = [:cm, :inch]
118
+
119
+ def initialize(image, options={})
120
+ super image
121
+
122
+ @compression = :none
123
+ @quality = 75
124
+ @predictor = :none
125
+ @layout = :strip
126
+ @tile_size = [128, 128]
127
+ @multi_res = :flat
128
+ @format = :manybit
129
+ @resolution_units = :cm
130
+
131
+ [ :compression, :layout, :multi_res, :format, :resolution_units,
132
+ :resolution, :predictor, :quality, :tile_size ].each do |att|
133
+ self.send "#{att}=".to_sym, options[att] if options.has_key?(att)
134
+ end
135
+ end
136
+
137
+ def write(path)
138
+ opts = [compression_str, layout_str, @multi_res, @format, resolution_str].join ','
139
+ write_internal "#{path}:#{opts}"
140
+ end
141
+
142
+ def compression_str
143
+ case @compression
144
+ when :jpeg then "#{@compression}:#{@quality}"
145
+ when :lzw, :deflate then "#{@compression}:#{@predictor}"
146
+ else @compression
147
+ end
148
+ end
149
+
150
+ def layout_str
151
+ s = @layout
152
+ s << ":#{@tile_size.join 'x'}" if @layout == :tile
153
+ s
154
+ end
155
+
156
+ def resolution_str
157
+ s = "res_#{@resolution_units}"
158
+ s << ":#{@resolution.join 'x'}" if @resolution
159
+ s
160
+ end
161
+
162
+ def compression=(compression_v)
163
+ unless COMPRESSION.include?(compression_v)
164
+ raise ArgumentError, "compression must be one of #{COMPRESSION.join(', ')}"
165
+ end
166
+
167
+ @compression = compression_v
168
+ end
169
+
170
+ def quality=(quality_v)
171
+ unless (0..100).include?(quality_v)
172
+ raise ArgumentError, 'quality must be a numeric value between 0 and 100'
173
+ end
174
+
175
+ @quality = quality_v
176
+ end
177
+
178
+ def predictor=(predictor_v)
179
+ unless PREDICTOR.include?(predictor_v)
180
+ raise ArgumentError, "predictor must be one of #{PREDICTOR.join(', ')}"
181
+ end
182
+
183
+ @predictor = predictor_v
184
+ end
185
+
186
+ def layout=(layout_v)
187
+ unless LAYOUT.include?(layout_v)
188
+ raise ArgumentError, "layout must be one of #{LAYOUT.join(', ')}"
189
+ end
190
+
191
+ @layout = layout_v
192
+ end
193
+
194
+ def tile_size=(tile_size_v)
195
+ unless tile_size_v[0] > 1 && tile_size_v[1] > 1
196
+ raise ArgumentError, "tile sizes must be larger than 1"
197
+ end
198
+
199
+ @tile_size = tile_size_v
200
+ end
201
+
202
+ def multi_res=(multi_res_v)
203
+ unless MULTI_RES.include?(multi_res_v)
204
+ raise ArgumentError, "multi res must be one of #{MULTI_RES.join(', ')}"
205
+ end
206
+
207
+ @multi_res = multi_res_v
208
+ end
209
+
210
+ def format=(format_v)
211
+ unless FORMAT.include?(format_v)
212
+ raise ArgumentError, "format must be one of #{FORMAT.join(', ')}"
213
+ end
214
+
215
+ @format = format_v
216
+ end
217
+
218
+ def resolution_units=(resolution_units_v)
219
+ unless RESOLUTION_UNITS.include?(resolution_units_v)
220
+ raise ArgumentError, "Resolution units must be one of #{RESOLUTION_UNITS.join(', ')}"
221
+ end
222
+
223
+ @resolution_units = resolution_units_v
224
+ end
225
+
226
+ def resolution=(resolution_v)
227
+ unless resolution_v[0] > 0 && resolution_v[1] > 0
228
+ raise ArgumentError, "Resolution must have a height and width larger than 0"
229
+ end
230
+
231
+ @resolution = resolution_v
232
+ end
233
+ end
234
+
235
+ class Image
236
+ def csv(*args)
237
+ invoke_writer CSVWriter, *args
238
+ end
239
+
240
+ def jpeg(*args)
241
+ invoke_writer JPEGWriter, *args
242
+ end
243
+
244
+ def png(*args)
245
+ invoke_writer PNGWriter, *args
246
+ end
247
+
248
+ def ppm(*args)
249
+ invoke_writer PPMWriter, *args
250
+ end
251
+
252
+ def tiff(*args)
253
+ invoke_writer TIFFWriter, *args
254
+ end
255
+
256
+ def vips(*args)
257
+ invoke_writer VIPSWriter, *args
258
+ end
259
+
260
+ def write(*args)
261
+ invoke_writer Writer, *args
262
+ end
263
+
264
+ private
265
+
266
+ def invoke_writer(writer_class, path=nil, options={})
267
+ w = writer_class.new self, options
268
+ if path
269
+ w.write path
270
+ else
271
+ w
272
+ end
273
+ end
274
+ end
275
+ end
data/ruby-vips.gemspec ADDED
@@ -0,0 +1,93 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "ruby-vips"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Timothy Elliott", "John Cupitt"]
12
+ s.date = "2012-06-21"
13
+ s.description = "Ruby extension for the vips image processing library."
14
+ s.email = "jcupitt@gmail.com"
15
+ s.extensions = ["ext/extconf.rb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.md",
19
+ "TODO"
20
+ ]
21
+ s.files = [
22
+ "CHANGELOG.md",
23
+ "Gemfile.lock",
24
+ "README.md",
25
+ "ext/extconf.rb",
26
+ "ext/header.c",
27
+ "ext/header.h",
28
+ "ext/image.c",
29
+ "ext/image.h",
30
+ "ext/image_arithmetic.c",
31
+ "ext/image_arithmetic.h",
32
+ "ext/image_boolean.c",
33
+ "ext/image_boolean.h",
34
+ "ext/image_colour.c",
35
+ "ext/image_colour.h",
36
+ "ext/image_conversion.c",
37
+ "ext/image_conversion.h",
38
+ "ext/image_convolution.c",
39
+ "ext/image_convolution.h",
40
+ "ext/image_freq_filt.c",
41
+ "ext/image_freq_filt.h",
42
+ "ext/image_histograms_lut.c",
43
+ "ext/image_histograms_lut.h",
44
+ "ext/image_morphology.c",
45
+ "ext/image_morphology.h",
46
+ "ext/image_mosaicing.c",
47
+ "ext/image_mosaicing.h",
48
+ "ext/image_relational.c",
49
+ "ext/image_relational.h",
50
+ "ext/image_resample.c",
51
+ "ext/image_resample.h",
52
+ "ext/interpolator.c",
53
+ "ext/interpolator.h",
54
+ "ext/mask.c",
55
+ "ext/mask.h",
56
+ "ext/reader.c",
57
+ "ext/ruby_vips.c",
58
+ "ext/ruby_vips.h",
59
+ "ext/writer.c",
60
+ "lib/vips.rb",
61
+ "lib/vips/reader.rb",
62
+ "lib/vips/version.rb",
63
+ "lib/vips/writer.rb",
64
+ "ruby-vips.gemspec"
65
+ ]
66
+ s.homepage = "http://github.com/jcupitt/ruby-vips"
67
+ s.licenses = ["MIT"]
68
+ s.require_paths = ["lib"]
69
+ s.rubygems_version = "1.8.19"
70
+ s.summary = "ruby-vips is a ruby extension for vips. It is extremely fast and it can process huge images without requiring the entire image to be loaded into memory."
71
+
72
+ if s.respond_to? :specification_version then
73
+ s.specification_version = 3
74
+
75
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
76
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
77
+ s.add_development_dependency(%q<bundler>, [">= 0"])
78
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
79
+ s.add_development_dependency(%q<rspec>, [">= 0"])
80
+ else
81
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
82
+ s.add_dependency(%q<bundler>, [">= 0"])
83
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
84
+ s.add_dependency(%q<rspec>, [">= 0"])
85
+ end
86
+ else
87
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
88
+ s.add_dependency(%q<bundler>, [">= 0"])
89
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
90
+ s.add_dependency(%q<rspec>, [">= 0"])
91
+ end
92
+ end
93
+
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-vips
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Timothy Elliott
9
+ - John Cupitt
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-06-21 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rdoc
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '3.12'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '3.12'
31
+ - !ruby/object:Gem::Dependency
32
+ name: bundler
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.3
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 1.8.3
63
+ - !ruby/object:Gem::Dependency
64
+ name: rspec
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ description: Ruby extension for the vips image processing library.
80
+ email: jcupitt@gmail.com
81
+ executables: []
82
+ extensions:
83
+ - ext/extconf.rb
84
+ extra_rdoc_files:
85
+ - LICENSE
86
+ - README.md
87
+ - TODO
88
+ files:
89
+ - CHANGELOG.md
90
+ - Gemfile.lock
91
+ - README.md
92
+ - ext/extconf.rb
93
+ - ext/header.c
94
+ - ext/header.h
95
+ - ext/image.c
96
+ - ext/image.h
97
+ - ext/image_arithmetic.c
98
+ - ext/image_arithmetic.h
99
+ - ext/image_boolean.c
100
+ - ext/image_boolean.h
101
+ - ext/image_colour.c
102
+ - ext/image_colour.h
103
+ - ext/image_conversion.c
104
+ - ext/image_conversion.h
105
+ - ext/image_convolution.c
106
+ - ext/image_convolution.h
107
+ - ext/image_freq_filt.c
108
+ - ext/image_freq_filt.h
109
+ - ext/image_histograms_lut.c
110
+ - ext/image_histograms_lut.h
111
+ - ext/image_morphology.c
112
+ - ext/image_morphology.h
113
+ - ext/image_mosaicing.c
114
+ - ext/image_mosaicing.h
115
+ - ext/image_relational.c
116
+ - ext/image_relational.h
117
+ - ext/image_resample.c
118
+ - ext/image_resample.h
119
+ - ext/interpolator.c
120
+ - ext/interpolator.h
121
+ - ext/mask.c
122
+ - ext/mask.h
123
+ - ext/reader.c
124
+ - ext/ruby_vips.c
125
+ - ext/ruby_vips.h
126
+ - ext/writer.c
127
+ - lib/vips.rb
128
+ - lib/vips/reader.rb
129
+ - lib/vips/version.rb
130
+ - lib/vips/writer.rb
131
+ - ruby-vips.gemspec
132
+ - LICENSE
133
+ - TODO
134
+ homepage: http://github.com/jcupitt/ruby-vips
135
+ licenses:
136
+ - MIT
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ segments:
148
+ - 0
149
+ hash: -88150975
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 1.8.19
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: ruby-vips is a ruby extension for vips. It is extremely fast and it can process
162
+ huge images without requiring the entire image to be loaded into memory.
163
+ test_files: []