ruby-vips 0.3.14 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +22 -0
  3. data/CHANGELOG.md +4 -0
  4. data/Gemfile +15 -0
  5. data/Gemfile.lock +46 -31
  6. data/{LICENSE → LICENSE.txt} +1 -1
  7. data/README.md +101 -145
  8. data/Rakefile +45 -0
  9. data/TODO +8 -32
  10. data/VERSION +1 -0
  11. data/example/annotate.rb +17 -0
  12. data/example/daltonize8.rb +75 -0
  13. data/example/example1.rb +84 -0
  14. data/example/example2.rb +31 -0
  15. data/example/example3.rb +19 -0
  16. data/example/example4.rb +18 -0
  17. data/example/example5.rb +31 -0
  18. data/example/trim8.rb +41 -0
  19. data/example/watermark.rb +44 -0
  20. data/example/wobble.rb +36 -0
  21. data/lib/vips.rb +151 -14
  22. data/lib/vips/access.rb +14 -0
  23. data/lib/vips/align.rb +11 -0
  24. data/lib/vips/angle.rb +12 -0
  25. data/lib/vips/angle45.rb +16 -0
  26. data/lib/vips/argument.rb +163 -0
  27. data/lib/vips/bandformat.rb +20 -0
  28. data/lib/vips/call.rb +302 -0
  29. data/lib/vips/coding.rb +14 -0
  30. data/lib/vips/demandstyle.rb +35 -0
  31. data/lib/vips/direction.rb +11 -0
  32. data/lib/vips/error.rb +30 -0
  33. data/lib/vips/extend.rb +22 -0
  34. data/lib/vips/foreignflags.rb +20 -0
  35. data/lib/vips/image.rb +1382 -0
  36. data/lib/vips/interpolate.rb +37 -0
  37. data/lib/vips/interpretation.rb +28 -0
  38. data/lib/vips/methods.rb +1807 -0
  39. data/lib/vips/operation.rb +19 -0
  40. data/ruby-vips8.gemspec +112 -0
  41. data/spec/image_spec.rb +515 -0
  42. data/spec/samples/balloon.v +0 -0
  43. data/spec/samples/ghost.ppm +405 -0
  44. data/spec/samples/huge.jpg +0 -0
  45. data/spec/samples/icc.jpg +0 -0
  46. data/spec/samples/lcd.icc +0 -0
  47. data/spec/samples/lion.svg +154 -0
  48. data/spec/samples/sample.csv +7 -0
  49. data/spec/samples/sample.exr +0 -0
  50. data/spec/samples/wagon.jpg +0 -0
  51. data/spec/samples/wagon.v +0 -0
  52. data/spec/spec_helper.rb +49 -0
  53. data/spec/vips_spec.rb +74 -0
  54. metadata +110 -70
  55. data/ext/extconf.rb +0 -31
  56. data/ext/header.c +0 -457
  57. data/ext/header.h +0 -9
  58. data/ext/image.c +0 -629
  59. data/ext/image.h +0 -72
  60. data/ext/image_arithmetic.c +0 -936
  61. data/ext/image_arithmetic.h +0 -38
  62. data/ext/image_boolean.c +0 -301
  63. data/ext/image_boolean.h +0 -8
  64. data/ext/image_colour.c +0 -590
  65. data/ext/image_colour.h +0 -36
  66. data/ext/image_conversion.c +0 -884
  67. data/ext/image_conversion.h +0 -38
  68. data/ext/image_convolution.c +0 -368
  69. data/ext/image_convolution.h +0 -13
  70. data/ext/image_freq_filt.c +0 -740
  71. data/ext/image_freq_filt.h +0 -27
  72. data/ext/image_histograms_lut.c +0 -643
  73. data/ext/image_histograms_lut.h +0 -28
  74. data/ext/image_morphology.c +0 -327
  75. data/ext/image_morphology.h +0 -13
  76. data/ext/image_mosaicing.c +0 -554
  77. data/ext/image_mosaicing.h +0 -15
  78. data/ext/image_relational.c +0 -384
  79. data/ext/image_relational.h +0 -8
  80. data/ext/image_resample.c +0 -249
  81. data/ext/image_resample.h +0 -9
  82. data/ext/interpolator.c +0 -106
  83. data/ext/interpolator.h +0 -7
  84. data/ext/mask.c +0 -347
  85. data/ext/mask.h +0 -18
  86. data/ext/reader.c +0 -261
  87. data/ext/reader.h +0 -2
  88. data/ext/ruby_vips.c +0 -188
  89. data/ext/ruby_vips.h +0 -72
  90. data/ext/tags +0 -450
  91. data/ext/writer.c +0 -371
  92. data/ext/writer.h +0 -2
  93. data/lib/vips/reader.rb +0 -272
  94. data/lib/vips/version.rb +0 -3
  95. data/lib/vips/writer.rb +0 -342
  96. data/ruby-vips.gemspec +0 -100
  97. data/ruby.supp +0 -134
@@ -1,371 +0,0 @@
1
- #include "ruby_vips.h"
2
-
3
- /* :nodoc: */
4
-
5
- static VALUE
6
- writer_initialize(int argc, VALUE *argv, VALUE obj)
7
- {
8
- VALUE image, opts;
9
- rb_scan_args(argc, argv, "11", &image, &opts);
10
- GetImg(image, data, im);
11
- GetImg(obj, data_new, im_new);
12
-
13
- img_add_dep(data_new, image);
14
- if (im_copy(im, im_new))
15
- vips_lib_error();
16
-
17
- return obj;
18
- }
19
-
20
- /*
21
- * call-seq:
22
- * writer.image -> image
23
- *
24
- * Returns the image associated with *self*.
25
- */
26
-
27
- static VALUE
28
- writer_image(VALUE obj)
29
- {
30
- GetImg(obj, data, im);
31
-
32
- if(data->deps)
33
- return data->deps[0];
34
-
35
- return Qnil;
36
- }
37
-
38
- static VALUE
39
- writer_meta_set(VALUE obj, const char* name, VALUE str)
40
- {
41
- GetImg(obj, data, im);
42
-
43
- size_t len = RSTRING_LEN(str);
44
- void *buf = malloc(len);
45
- memcpy(buf, RSTRING_PTR(str), len);
46
-
47
- if (im_meta_set_blob(im, name, (im_callback_fn)xfree, buf, len)) {
48
- xfree(buf);
49
- vips_lib_error();
50
- }
51
-
52
- return str;
53
- }
54
-
55
- static VALUE
56
- writer_meta_remove(VALUE obj, const char* name)
57
- {
58
- GetImg(obj, data, im);
59
- #if ATLEAST_VIPS( 7, 22 )
60
- if (im_meta_remove(im, name))
61
- return Qfalse;
62
- #else
63
- rb_raise(eVIPSError, "This method is not implemented in your version of VIPS");
64
- #endif
65
- return Qtrue;
66
- }
67
-
68
- /*
69
- * call-seq:
70
- * writer.exif = exif_data
71
- *
72
- * Sets the exif header of the writer to <i>exif_data</i>. This will be
73
- * written only if the file format supports embedded exif data.
74
- *
75
- */
76
-
77
- static VALUE
78
- writer_exif_set(VALUE obj, VALUE str)
79
- {
80
- return writer_meta_set(obj, IM_META_EXIF_NAME, str);
81
- }
82
-
83
- /*
84
- * call-seq:
85
- * writer.remove_exif -> true or false
86
- *
87
- * Removes exif data associated with *self*.
88
- */
89
-
90
- static VALUE
91
- writer_remove_exif(VALUE obj)
92
- {
93
- return writer_meta_remove(obj, IM_META_EXIF_NAME);
94
- }
95
-
96
- /*
97
- * call-seq:
98
- * writer.icc = icc_data
99
- *
100
- * Sets the icc header of the writer to <i>icc_data</i>. This will be written
101
- * only if the file format supports embedded icc data.
102
- *
103
- */
104
-
105
- static VALUE
106
- writer_icc_set(VALUE obj, VALUE str)
107
- {
108
- return writer_meta_set(obj, IM_META_ICC_NAME, str);
109
- }
110
-
111
- /*
112
- * call-seq:
113
- * writer.remove_icc -> true or false
114
- *
115
- * Removes icc data associated with *self*.
116
- */
117
-
118
- static VALUE
119
- writer_remove_icc(VALUE obj)
120
- {
121
- return writer_meta_remove(obj, IM_META_ICC_NAME);
122
- }
123
-
124
- /* :nodoc: */
125
-
126
- static VALUE
127
- writer_write_internal(VALUE obj, VALUE path)
128
- {
129
- VipsImage *out;
130
- GetImg(obj, data, im);
131
-
132
- if (!(out = im_open(StringValuePtr(path), "w")) || im_copy(im, out))
133
- vips_lib_error();
134
-
135
- im_close(out);
136
-
137
- return obj;
138
- }
139
-
140
- /* :nodoc: */
141
-
142
- static VALUE
143
- jpeg_buf_internal(VALUE obj, VALUE quality)
144
- {
145
- char *buf = NULL;
146
- int length;
147
-
148
- GetImg(obj, data, im);
149
-
150
- #if ATLEAST_VIPS( 7, 28 )
151
- {
152
- size_t len;
153
-
154
- if (vips_jpegsave_buffer(im, &buf, &len,
155
- "Q", NUM2INT(quality),
156
- NULL))
157
- vips_lib_error();
158
-
159
- /* Argh.
160
- */
161
- length = len;
162
- }
163
- #else
164
- if (im_vips2bufjpeg(im, NULL, NUM2INT(quality), &buf, &length))
165
- vips_lib_error();
166
- #endif
167
-
168
- return rb_tainted_str_new(buf, length);
169
- }
170
-
171
- /* :nodoc: */
172
-
173
- static VALUE
174
- jpeg_write_internal(VALUE obj, VALUE path)
175
- {
176
- GetImg(obj, data, im);
177
-
178
- if (im_vips2jpeg(im, RSTRING_PTR(path)))
179
- vips_lib_error();
180
-
181
- return obj;
182
- }
183
-
184
- /* :nodoc: */
185
-
186
- static VALUE
187
- tiff_write_internal(VALUE obj, VALUE path)
188
- {
189
- GetImg(obj, data, im);
190
-
191
- if (im_vips2tiff(im, RSTRING_PTR(path)))
192
- vips_lib_error();
193
-
194
- return obj;
195
- }
196
-
197
- /* :nodoc: */
198
-
199
- static VALUE
200
- ppm_write_internal(VALUE obj, VALUE path)
201
- {
202
- GetImg(obj, data, im);
203
-
204
- if (im_vips2ppm(im, RSTRING_PTR(path)))
205
- vips_lib_error();
206
-
207
- return obj;
208
- }
209
-
210
- /* :nodoc: */
211
-
212
- static VALUE
213
- png_buf_internal(VALUE obj, VALUE compression, VALUE interlace)
214
- {
215
- char *buf;
216
- size_t length;
217
- GetImg(obj, data, im);
218
-
219
- #if ATLEAST_VIPS( 7, 28 )
220
- if (vips_pngsave_buffer(im, &buf, &length,
221
- "compression", NUM2INT(compression),
222
- "interlace", NUM2INT(interlace),
223
- NULL))
224
- vips_lib_error();
225
- #elif ATLEAST_VIPS( 7, 23 )
226
- if (im_vips2bufpng(im, NULL, NUM2INT(compression), NUM2INT(interlace),
227
- &buf, &length))
228
- vips_lib_error();
229
- #else
230
- rb_raise(eVIPSError, "This method is not implemented in your version of VIPS");
231
- #endif
232
-
233
- return rb_tainted_str_new(buf, length);
234
- }
235
-
236
- /* :nodoc: */
237
-
238
- static VALUE
239
- png_write_internal(VALUE obj, VALUE path)
240
- {
241
- GetImg(obj, data, im);
242
-
243
- if (im_vips2png(im, RSTRING_PTR(path)))
244
- vips_lib_error();
245
-
246
- return obj;
247
- }
248
-
249
- /* :nodoc: */
250
-
251
- static VALUE
252
- webp_write_internal(VALUE obj, VALUE path)
253
- {
254
- #if ATLEAST_VIPS( 7, 42 )
255
- GetImg(obj, data, im);
256
-
257
- if (im_vips2webp(im, RSTRING_PTR(path)))
258
- vips_lib_error();
259
- #else
260
- rb_raise(eVIPSError, "This method is not implemented in your version of VIPS");
261
- #endif
262
-
263
- return obj;
264
- }
265
-
266
- /* :nodoc: */
267
-
268
- static VALUE
269
- csv_write_internal(VALUE obj, VALUE path)
270
- {
271
- GetImg(obj, data, im);
272
-
273
- if (im_vips2csv(im, RSTRING_PTR(path)))
274
- vips_lib_error();
275
-
276
- return obj;
277
- }
278
-
279
- /* :nodoc: */
280
-
281
- static VALUE
282
- vips_write_internal(VALUE obj, VALUE path)
283
- {
284
- VipsImage *im_new;
285
- GetImg(obj, data, im);
286
-
287
- if (!(im_new = (VipsImage *)im_openout(RSTRING_PTR(path))))
288
- vips_lib_error();
289
-
290
- if (im_copy(im, im_new))
291
- vips_lib_error();
292
-
293
- im_close(im_new);
294
-
295
- return obj;
296
- }
297
-
298
- /*
299
- * Base class for image format readers.
300
- */
301
-
302
- void
303
- init_Writer(void)
304
- {
305
- VALUE writer = rb_define_class_under(mVIPS, "Writer", rb_cObject);
306
-
307
- rb_include_module(writer, mVIPSHeader);
308
- rb_define_alloc_func(writer, img_init_partial_anyclass);
309
- rb_define_method(writer, "initialize", writer_initialize, -1);
310
- rb_define_method(writer, "image", writer_image, 0);
311
- rb_define_method(writer, "exif=", writer_exif_set, 1);
312
- rb_define_method(writer, "remove_exif", writer_remove_exif, 0);
313
- rb_define_method(writer, "icc=", writer_icc_set, 1);
314
- rb_define_method(writer, "remove_icc", writer_remove_icc, 0);
315
- rb_define_private_method(writer, "write_internal", writer_write_internal, 1);
316
-
317
- /*
318
- * Write JPEG images.
319
- */
320
-
321
- VALUE jpeg_writer = rb_define_class_under(mVIPS, "JPEGWriter", writer);
322
- rb_define_private_method(jpeg_writer, "buf_internal", jpeg_buf_internal, 1);
323
- rb_define_private_method(jpeg_writer, "write_internal", jpeg_write_internal, 1);
324
-
325
- /*
326
- * Write TIFF images.
327
- */
328
-
329
- VALUE tiff_writer = rb_define_class_under(mVIPS, "TIFFWriter", writer);
330
- rb_define_private_method(tiff_writer, "write_internal", tiff_write_internal, 1);
331
-
332
- /*
333
- * Write PPM images.
334
- */
335
-
336
- VALUE ppm_writer = rb_define_class_under(mVIPS, "PPMWriter", writer);
337
- rb_define_private_method(ppm_writer, "write_internal", ppm_write_internal, 1);
338
-
339
- /*
340
- * Write PNG images.
341
- */
342
-
343
- VALUE png_writer = rb_define_class_under(mVIPS, "PNGWriter", writer);
344
- rb_define_private_method(png_writer, "write_internal", png_write_internal, 1);
345
- rb_define_private_method(png_writer, "buf_internal", png_buf_internal, 2);
346
-
347
- /*
348
- * Write WebP images.
349
- */
350
-
351
- VALUE webp_writer = rb_define_class_under(mVIPS, "WEBPWriter", writer);
352
- rb_define_private_method(webp_writer, "write_internal", webp_write_internal, 1);
353
-
354
- /*
355
- * Write CSV images.
356
- */
357
-
358
- VALUE csv_writer = rb_define_class_under(mVIPS, "CSVWriter", writer);
359
- rb_define_private_method(csv_writer, "write_internal", csv_write_internal, 1);
360
-
361
- /*
362
- * Write native VIPS images.
363
- */
364
-
365
- VALUE vips_writer = rb_define_class_under(mVIPS, "VIPSWriter", writer);
366
- rb_define_private_method(vips_writer, "write_internal", vips_write_internal, 1);
367
-
368
- #if 0
369
- VALUE mVIPS = rb_define_module("VIPS");
370
- #endif
371
- }
@@ -1,2 +0,0 @@
1
- void init_Writer(void);
2
-
@@ -1,272 +0,0 @@
1
- module VIPS
2
- class Reader
3
- attr_reader :path
4
-
5
- def initialize(path, options={})
6
- @path = path
7
- @_im = nil
8
- end
9
-
10
- def read
11
- # in case the sub-class has not read it
12
- if not @_im
13
- @_im = read_retry @path, 0
14
- end
15
- @_im
16
- end
17
-
18
- # support these two for compat with older ruby-vips
19
- def x_size
20
- read.x_size
21
- end
22
-
23
- def y_size
24
- read.y_size
25
- end
26
-
27
- def exif
28
- read.exif
29
- end
30
-
31
- def exif?
32
- read.exif?
33
- end
34
-
35
- private
36
-
37
- # read can fail due to no file descriptors ... if we fail, do a GC and try
38
- # again a second time
39
- def read_retry(path, seq)
40
- im = nil
41
- begin
42
- im = read_internal path, seq
43
- rescue
44
- GC.start
45
- im = read_internal path, seq
46
- end
47
- im
48
- end
49
- end
50
-
51
- class JPEGReader < Reader
52
- attr_reader :shrink_factor
53
- attr_accessor :fail_on_warn
54
- attr_accessor :sequential
55
-
56
- SHRINK_FACTOR = [1, 2, 4, 8]
57
-
58
- # Creates a jpeg image file reader.
59
- def initialize(path, options={})
60
- @shrink_factor = options[:shrink_factor] || 1
61
- @fail_on_warn = options[:fail_on_warn] || false
62
- @sequential = options[:sequential] || false
63
-
64
- super path, options
65
- end
66
-
67
- def read
68
- str = "#{@path}:#{@shrink_factor}"
69
- str << ","
70
- str << "fail" if @fail_on_warn
71
-
72
- seq = 0
73
- if VIPS.sequential_mode_supported?
74
- str << ","
75
- str << "sequential" if @sequential
76
- seq = 1
77
- end
78
-
79
- @_im = read_retry str, seq
80
- end
81
-
82
- def b_to_i(b)
83
- if b
84
- 1
85
- else
86
- 0
87
- end
88
- end
89
-
90
- def read_buffer
91
- @_im = buf_internal @path, @shrink_factor, b_to_i(@fail_on_warn)
92
- end
93
-
94
- # Shrink the jpeg while reading from disk. This means that the entire image
95
- # never has to be loaded in memory. Shrink factor can be 1 (no shrink), 2,
96
- # 4, or 8.
97
- def shrink_factor=(shrink_factor_v)
98
- unless SHRINK_FACTOR.include?(shrink_factor_v)
99
- raise ArgumentError, "Shrink factor must be one of: #{SHRINK_FACTOR.join ', '}."
100
- end
101
-
102
- @shrink_factor = shrink_factor_v
103
- end
104
- end
105
-
106
- class CSVReader < Reader
107
- attr_reader :line_skip, :line_limit
108
- attr_accessor :whitespace, :separator
109
-
110
- # Creates a CSV reader.
111
- def initialize(path, options={})
112
- @line_skip = options[:line_skip] || 0
113
- @whitespace = options[:whitespace] || ' "'
114
- @separator = options[:separator] || ";,\t"
115
- @line_limit = options[:line_limit] || 0
116
-
117
- super path, options
118
- end
119
-
120
- def read
121
- str = "#{@path}:ski:#{@line_skip},whi:#{@whitespace}"
122
- str << ",lin:#{@line_limit == 0 ? -1 : @line_limit}"
123
-
124
- # VIPS magic open path limitation/bug -- we cannot specify the comma char
125
- str << ",sep:#{@separator}" unless @separator[/,/]
126
-
127
- @_im = read_retry str, 0
128
- end
129
-
130
- # Set the number of lines to skip at the beginning of the file.
131
- def line_skip=(line_skip_v)
132
- if line_skip_v < 0
133
- raise ArgumentError, "Line skip must be 0 or more."
134
- end
135
-
136
- @line_skip = line_skip_v
137
- end
138
-
139
- # Set a limit of how many lines to read in.
140
- def line_limit=(line_limit_v)
141
- if line_limit_v < 0
142
- raise ArgumentError, "Line limit must be 0 (read all) or more."
143
- end
144
-
145
- @line_limit = line_limit_v
146
- end
147
- end
148
-
149
- class TIFFReader < Reader
150
- attr_reader :page_number
151
- attr_accessor :sequential
152
-
153
- # Create a tiff image file reader.
154
- def initialize(path, options={})
155
- @page_number = nil
156
- @sequential = options[:sequential] || false
157
-
158
- self.page_number = options[:page_number] if options.has_key?(:page_number)
159
- super path, options
160
- end
161
-
162
- def read
163
- str = "#{@path}:"
164
- str << "#{@page_number}" if @page_number
165
-
166
- seq = 0
167
- if VIPS.sequential_mode_supported?
168
- str << ","
169
- str << "sequential" if @sequential
170
- seq = 1
171
- end
172
-
173
- @_im = read_retry str, seq
174
- end
175
-
176
- # Select which page in a multiple-page tiff to read. When set to nil, all
177
- # pages are read as a single image.
178
- def page_number=(page_number_v)
179
- unless page_number_v.nil? || page_number_v > 0
180
- raise ArgumentError, "Page number has to be nil or larger than zero."
181
- end
182
-
183
- @page_number = page_number_v
184
- end
185
- end
186
-
187
- class PNGReader < Reader
188
- attr_accessor :sequential
189
-
190
- # Create a png image file reader.
191
- def initialize(path, options={})
192
- @sequential = options[:sequential] || false
193
-
194
- super path, options
195
- end
196
-
197
- def read
198
- # some old versions of vips (eg. 7.26) have a bug in the png reader where
199
- # the ':' is not tripped from the filename in the ispng test ... only put
200
- # the ':' there if we have to
201
- str = "#{@path}"
202
-
203
- seq = 0
204
- if VIPS.sequential_mode_supported?
205
- str << ":sequential" if @sequential
206
- seq = 1
207
- end
208
-
209
- @_im = read_retry str, seq
210
- end
211
-
212
- def read_buffer
213
- @_im = buf_internal @path
214
- end
215
- end
216
-
217
- class MagickReader < Reader
218
- def read_buffer
219
- @_im = buf_internal @path
220
- end
221
- end
222
-
223
- class Image
224
-
225
- # Load a ppm file straight to a VIPS Image.
226
- def self.ppm(*args)
227
- PPMReader.new(*args).read
228
- end
229
-
230
- # Load an exr file straight to a VIPS Image.
231
- def self.exr(*args)
232
- EXRReader.new(*args).read
233
- end
234
-
235
- # Load a csv file straight to a VIPS Image.
236
- def self.csv(*args)
237
- CSVReader.new(*args).read
238
- end
239
-
240
- # Load a jpeg file straight to a VIPS Image.
241
- def self.jpeg(*args)
242
- JPEGReader.new(*args).read
243
- end
244
-
245
- # Load a file straight to a VIPS Image using the magick library.
246
- def self.magick(*args)
247
- MagickReader.new(*args).read
248
- end
249
-
250
- # Load a png file straight to a VIPS Image.
251
- def self.png(*args)
252
- PNGReader.new(*args).read
253
- end
254
-
255
- # Load a tiff file straight to a VIPS Image.
256
- def self.tiff(*args)
257
- TIFFReader.new(*args).read
258
- end
259
-
260
- # Load a native vips file straight to a VIPS Image.
261
- def self.vips(*args)
262
- VIPSReader.new(*args).read
263
- end
264
-
265
- # Load any file straight to a VIPS Image. VIPS will determine the format
266
- # based on the file extension. If the extension is not recognized, VIPS
267
- # will look at the file signature.
268
- def self.new(*args)
269
- Reader.new(*args).read
270
- end
271
- end
272
- end