ruby-vips 0.2.1 → 0.3.0

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,2 @@
1
+ void init_Writer(void);
2
+
@@ -4,60 +4,24 @@ module VIPS
4
4
 
5
5
  def initialize(path, options={})
6
6
  @path = path
7
- read_header path unless options[:skip_header]
8
- end
9
-
10
- def self.read(path, options={})
11
- options[:skip_header] = true
12
- reader = new path, options
13
- reader.read
7
+ @_im = nil
14
8
  end
15
9
 
16
10
  def read
17
- read_internal @path
18
- end
19
- end
20
-
21
- class CSVReader < Reader
22
- attr_reader :line_skip, :line_limit
23
- attr_accessor :whitespace, :separator
24
-
25
- # Creates a CSV reader.
26
- def initialize(path, options={})
27
- @line_skip = options[:line_skip] || 0
28
- @whitespace = options[:whitespace] || ' "'
29
- @separator = options[:separator] || ";,\t"
30
- @line_limit = options[:line_limit] || 0
31
-
32
- super path, options
33
- end
34
-
35
- # Read the CSV file and return a VIPS Image object.
36
- def read
37
- str = "#{@path}:ski:#{@line_skip},whi:#{@whitespace}"
38
- str << ",lin:#{@line_limit == 0 ? -1 : @line_limit}"
39
-
40
- # VIPS magic open path limitation/bug -- we cannot specify the comma char
41
- str << ",sep:#{@separator}" unless @separator[/,/]
42
- read_internal str
43
- end
44
-
45
- # Set the number of lines to skip at the beginning of the file.
46
- def line_skip=(line_skip_v)
47
- if line_skip_v < 0
48
- raise ArgumentError, "Line skip must be 0 or more."
11
+ # in case the sub-class has not read it
12
+ if not @_im
13
+ @_im = read_internal @path, 0
49
14
  end
50
-
51
- @line_skip = line_skip_v
15
+ @_im
52
16
  end
53
17
 
54
- # Set a limit of how many lines to read in.
55
- def line_limit=(line_limit_v)
56
- if line_limit_v < 0
57
- raise ArgumentError, "Line limit must be 0 (read all) or more."
58
- end
18
+ # support these two for compat with older ruby-vips
19
+ def x_size
20
+ @_im.x_size
21
+ end
59
22
 
60
- @line_limit = line_limit_v
23
+ def y_size
24
+ @_im.y_size
61
25
  end
62
26
  end
63
27
 
@@ -77,18 +41,19 @@ module VIPS
77
41
  super path, options
78
42
  end
79
43
 
80
- # Read the jpeg file from disk and return a VIPS Image object.
81
44
  def read
82
45
  str = "#{@path}:#{shrink_factor}"
83
46
  str << ","
84
47
  str << "fail" if @fail_on_warn
85
48
 
49
+ seq = 0
86
50
  if Vips.sequential_mode_supported?
87
51
  str << ","
88
52
  str << "sequential" if @sequential
53
+ seq = 1
89
54
  end
90
55
 
91
- read_internal str
56
+ @_im = read_internal str, seq
92
57
  end
93
58
 
94
59
  # Shrink the jpeg while reading from disk. This means that the entire image
@@ -103,6 +68,49 @@ module VIPS
103
68
  end
104
69
  end
105
70
 
71
+ class CSVReader < Reader
72
+ attr_reader :line_skip, :line_limit
73
+ attr_accessor :whitespace, :separator
74
+
75
+ # Creates a CSV reader.
76
+ def initialize(path, options={})
77
+ @line_skip = options[:line_skip] || 0
78
+ @whitespace = options[:whitespace] || ' "'
79
+ @separator = options[:separator] || ";,\t"
80
+ @line_limit = options[:line_limit] || 0
81
+
82
+ super path, options
83
+ end
84
+
85
+ def read
86
+ str = "#{@path}:ski:#{@line_skip},whi:#{@whitespace}"
87
+ str << ",lin:#{@line_limit == 0 ? -1 : @line_limit}"
88
+
89
+ # VIPS magic open path limitation/bug -- we cannot specify the comma char
90
+ str << ",sep:#{@separator}" unless @separator[/,/]
91
+
92
+ @_im = read_internal str, 0
93
+ end
94
+
95
+ # Set the number of lines to skip at the beginning of the file.
96
+ def line_skip=(line_skip_v)
97
+ if line_skip_v < 0
98
+ raise ArgumentError, "Line skip must be 0 or more."
99
+ end
100
+
101
+ @line_skip = line_skip_v
102
+ end
103
+
104
+ # Set a limit of how many lines to read in.
105
+ def line_limit=(line_limit_v)
106
+ if line_limit_v < 0
107
+ raise ArgumentError, "Line limit must be 0 (read all) or more."
108
+ end
109
+
110
+ @line_limit = line_limit_v
111
+ end
112
+ end
113
+
106
114
  class TIFFReader < Reader
107
115
  attr_reader :page_number
108
116
  attr_accessor :sequential
@@ -116,17 +124,18 @@ module VIPS
116
124
  super path, options
117
125
  end
118
126
 
119
- # Read the tiff file from disk and return a VIPS Image object.
120
127
  def read
121
128
  str = "#{@path}:"
122
129
  str << "#{@page_number}" if @page_number
123
130
 
131
+ seq = 0
124
132
  if Vips.sequential_mode_supported?
125
133
  str << ","
126
134
  str << "sequential" if @sequential
135
+ seq = 1
127
136
  end
128
137
 
129
- read_internal str
138
+ @_im = read_internal str, seq
130
139
  end
131
140
 
132
141
  # Select which page in a multiple-page tiff to read. When set to nil, all
@@ -150,16 +159,17 @@ module VIPS
150
159
  super path, options
151
160
  end
152
161
 
153
- # Read the png file from disk and return a VIPS Image object.
154
162
  def read
155
163
  str = @path
156
164
 
165
+ seq = 0
157
166
  if Vips.sequential_mode_supported?
158
167
  str << ":"
159
168
  str << "sequential" if @sequential
169
+ seq = 1
160
170
  end
161
171
 
162
- read_internal str
172
+ @_im = read_internal str, seq
163
173
  end
164
174
  end
165
175
 
@@ -167,49 +177,49 @@ module VIPS
167
177
 
168
178
  # Load a ppm file straight to a VIPS Image.
169
179
  def self.ppm(*args)
170
- PPMReader.read *args
180
+ PPMReader.new(*args).read
171
181
  end
172
182
 
173
183
  # Load an exr file straight to a VIPS Image.
174
184
  def self.exr(*args)
175
- EXRReader.read *args
185
+ EXRReader.new(*args).read
176
186
  end
177
187
 
178
188
  # Load a csv file straight to a VIPS Image.
179
189
  def self.csv(*args)
180
- CSVReader.read *args
190
+ CSVReader.new(*args).read
181
191
  end
182
192
 
183
193
  # Load a jpeg file straight to a VIPS Image.
184
194
  def self.jpeg(*args)
185
- JPEGReader.read *args
195
+ JPEGReader.new(*args).read
186
196
  end
187
197
 
188
198
  # Load a file straight to a VIPS Image using the magick library.
189
199
  def self.magick(*args)
190
- MagickReader.read *args
200
+ MagickReader.new(*args).read
191
201
  end
192
202
 
193
203
  # Load a png file straight to a VIPS Image.
194
204
  def self.png(*args)
195
- PNGReader.read *args
205
+ PNGReader.new(*args).read
196
206
  end
197
207
 
198
208
  # Load a tiff file straight to a VIPS Image.
199
209
  def self.tiff(*args)
200
- TIFFReader.read *args
210
+ TIFFReader.new(*args).read
201
211
  end
202
212
 
203
213
  # Load a native vips file straight to a VIPS Image.
204
214
  def self.vips(*args)
205
- VIPSReader.read *args
215
+ VIPSReader.new(*args).read
206
216
  end
207
217
 
208
218
  # Load any file straight to a VIPS Image. VIPS will determine the format
209
219
  # based on the file extension. If the extension is not recognized, VIPS
210
220
  # will look at the file signature.
211
221
  def self.new(*args)
212
- Reader.read *args
222
+ Reader.new(*args).read
213
223
  end
214
224
  end
215
225
  end
@@ -1,3 +1,3 @@
1
1
  module VIPS
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ruby-vips"
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Timothy Elliott", "John Cupitt"]
12
- s.date = "2012-07-16"
12
+ s.date = "2012-07-24"
13
13
  s.description = "Ruby extension for the vips image processing library."
14
14
  s.email = "jcupitt@gmail.com"
15
15
  s.extensions = ["ext/extconf.rb"]
@@ -54,14 +54,17 @@ Gem::Specification.new do |s|
54
54
  "ext/mask.c",
55
55
  "ext/mask.h",
56
56
  "ext/reader.c",
57
+ "ext/reader.h",
57
58
  "ext/ruby_vips.c",
58
59
  "ext/ruby_vips.h",
59
60
  "ext/writer.c",
61
+ "ext/writer.h",
60
62
  "lib/vips.rb",
61
63
  "lib/vips/reader.rb",
62
64
  "lib/vips/version.rb",
63
65
  "lib/vips/writer.rb",
64
- "ruby-vips.gemspec"
66
+ "ruby-vips.gemspec",
67
+ "ruby.supp"
65
68
  ]
66
69
  s.homepage = "http://github.com/jcupitt/ruby-vips"
67
70
  s.licenses = ["MIT"]
@@ -0,0 +1,194 @@
1
+ # valgrind suppressions file for ubuntu 12.04
2
+ # with this set of suppressions I can run
3
+ # valgrind --db-attach=yes ruby -S rspec spec/vips/vips_reader_spec.rb ..
4
+ # successfully
5
+
6
+ {
7
+ cond1
8
+ Memcheck:Cond
9
+ ...
10
+ fun:rb_newobj
11
+ obj:/usr/lib/libruby1.8.so.1.8.7
12
+ fun:rb_str_buf_new
13
+ obj:/usr/lib/libruby1.8.so.1.8.7
14
+ obj:/usr/lib/libruby1.8.so.1.8.7
15
+ fun:ruby_yyparse
16
+ }
17
+
18
+ {
19
+ val1
20
+ Memcheck:Value8
21
+ ...
22
+ fun:rb_newobj
23
+ obj:/usr/lib/libruby1.8.so.1.8.7
24
+ fun:rb_str_buf_new
25
+ obj:/usr/lib/libruby1.8.so.1.8.7
26
+ obj:/usr/lib/libruby1.8.so.1.8.7
27
+ fun:ruby_yyparse
28
+ }
29
+
30
+ {
31
+ cond2
32
+ Memcheck:Cond
33
+ ...
34
+ obj:/usr/lib/libruby1.8.so.1.8.7
35
+ obj:/usr/lib/libruby1.8.so.1.8.7
36
+ fun:rb_newobj
37
+ obj:/usr/lib/libruby1.8.so.1.8.7
38
+ obj:/usr/lib/libruby1.8.so.1.8.7
39
+ fun:rb_str_new3
40
+ }
41
+
42
+ {
43
+ val2
44
+ Memcheck:Value8
45
+ ...
46
+ obj:/usr/lib/libruby1.8.so.1.8.7
47
+ obj:/usr/lib/libruby1.8.so.1.8.7
48
+ fun:rb_newobj
49
+ obj:/usr/lib/libruby1.8.so.1.8.7
50
+ obj:/usr/lib/libruby1.8.so.1.8.7
51
+ fun:rb_str_new3
52
+ }
53
+
54
+ {
55
+ cond3
56
+ Memcheck:Cond
57
+ ...
58
+ obj:/usr/lib/libruby1.8.so.1.8.7
59
+ fun:rb_newobj
60
+ fun:rb_node_newnode
61
+ obj:/usr/lib/libruby1.8.so.1.8.7
62
+ fun:ruby_yyparse
63
+ }
64
+
65
+ {
66
+ val3
67
+ Memcheck:Value8
68
+ ...
69
+ obj:/usr/lib/libruby1.8.so.1.8.7
70
+ obj:/usr/lib/libruby1.8.so.1.8.7
71
+ fun:rb_newobj
72
+ fun:rb_node_newnode
73
+ obj:/usr/lib/libruby1.8.so.1.8.7
74
+ fun:ruby_yyparse
75
+ }
76
+
77
+ {
78
+ val4
79
+ Memcheck:Value8
80
+ ...
81
+ obj:/usr/lib/libruby1.8.so.1.8.7
82
+ fun:rb_newobj
83
+ fun:rb_node_newnode
84
+ fun:ruby_yyparse
85
+ }
86
+
87
+ {
88
+ cond4
89
+ Memcheck:Cond
90
+ ...
91
+ obj:/usr/lib/libruby1.8.so.1.8.7
92
+ fun:rb_newobj
93
+ }
94
+
95
+ {
96
+ val5
97
+ Memcheck:Value8
98
+ fun:st_lookup
99
+ fun:rb_mark_generic_ivar
100
+ ...
101
+ obj:/usr/lib/libruby1.8.so.1.8.7
102
+ obj:/usr/lib/libruby1.8.so.1.8.7
103
+ fun:rb_newobj
104
+ }
105
+
106
+ {
107
+ val6
108
+ Memcheck:Value8
109
+ ...
110
+ obj:/usr/lib/libruby1.8.so.1.8.7
111
+ fun:rb_newobj
112
+ ...
113
+ obj:/usr/lib/libruby1.8.so.1.8.7
114
+ fun:img_each_pixel
115
+ }
116
+
117
+ {
118
+ val6a
119
+ Memcheck:Value8
120
+ ...
121
+ obj:/usr/lib/libruby1.8.so.1.8.7
122
+ fun:rb_newobj
123
+ fun:rb_float_new
124
+ ...
125
+ obj:/usr/lib/libruby1.8.so.1.8.7
126
+ }
127
+
128
+ {
129
+ val7
130
+ Memcheck:Value8
131
+ ...
132
+ obj:/usr/lib/libruby1.8.so.1.8.7
133
+ fun:rb_newobj
134
+ ...
135
+ obj:/usr/lib/libruby1.8.so.1.8.7
136
+ fun:rb_ary_each
137
+ }
138
+
139
+ {
140
+ val7a
141
+ Memcheck:Value8
142
+ ...
143
+ obj:/usr/lib/libruby1.8.so.1.8.7
144
+ fun:rb_newobj
145
+ fun:rb_node_newnode
146
+ fun:rb_iterate
147
+ ...
148
+ }
149
+
150
+ {
151
+ cond5
152
+ Memcheck:Cond
153
+ ...
154
+ obj:/usr/lib/libruby1.8.so.1.8.7
155
+ fun:ruby_xmalloc
156
+ obj:/usr/lib/libruby1.8.so.1.8.7
157
+ fun:rb_reg_new
158
+ }
159
+
160
+ {
161
+ val8
162
+ Memcheck:Value8
163
+ ...
164
+ obj:/usr/lib/libruby1.8.so.1.8.7
165
+ fun:ruby_xmalloc
166
+ obj:/usr/lib/libruby1.8.so.1.8.7
167
+ fun:rb_reg_new
168
+ }
169
+
170
+ {
171
+ cond6
172
+ Memcheck:Cond
173
+ ...
174
+ obj:/usr/lib/libruby1.8.so.1.8.7
175
+ fun:ruby_xmalloc
176
+ fun:st_add_direct
177
+ obj:/usr/lib/libruby1.8.so.1.8.7
178
+ fun:st_foreach
179
+ }
180
+
181
+ {
182
+ val9
183
+ Memcheck:Value8
184
+ ...
185
+ obj:/usr/lib/libruby1.8.so.1.8.7
186
+ obj:/usr/lib/libruby1.8.so.1.8.7
187
+ fun:ruby_xmalloc
188
+ fun:st_add_direct
189
+ obj:/usr/lib/libruby1.8.so.1.8.7
190
+ fun:st_foreach
191
+ }
192
+
193
+
194
+