ruby-vips 0.3.14 → 1.0.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.
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,72 +0,0 @@
1
- #ifndef RUBY_VIPS_IMAGE_H
2
- #define RUBY_VIPS_IMAGE_H
3
-
4
- #include "ruby_vips.h"
5
-
6
- extern VALUE cVIPSImage;
7
-
8
- struct _vipsImg {
9
- VipsImage *in;
10
- VALUE *deps;
11
- int deps_len;
12
- };
13
- typedef struct _vipsImg vipsImg;
14
-
15
- void img_add_dep(vipsImg*, VALUE);
16
- VALUE img_spawn(VALUE);
17
- VALUE img_spawn2(VALUE, VALUE);
18
- VALUE img_spawn3(VALUE, VALUE, VALUE);
19
- VALUE img_alloc(VALUE);
20
- VALUE img_init(VALUE, VipsImage*);
21
- VALUE img_init_partial();
22
- VALUE img_init_partial_anyclass(VALUE);
23
- VipsBandFmt img_id_to_band_fmt(VALUE);
24
- void init_Image(void);
25
-
26
- #define GetImg(obj, data, im) \
27
- vipsImg *data; \
28
- VipsImage *im __attribute__ ((unused)); \
29
- Data_Get_Struct(obj, vipsImg, data); \
30
- im = data->in;
31
-
32
- #define OutImg(obj, new, data_new, im_new) \
33
- VALUE new = img_spawn(obj); \
34
- GetImg(new, data_new, im_new);
35
-
36
- #define OutImg2(obj, obj2, new, data_new, im_new) \
37
- VALUE new = img_spawn2(obj, obj2); \
38
- GetImg(new, data_new, im_new);
39
-
40
- #define OutImg3(obj, obj2, obj3, new, data_new, im_new) \
41
- VALUE new = img_spawn3(obj, obj2, obj3); \
42
- GetImg(new, data_new, im_new);
43
-
44
- #define OutPartial(new, data_new, im_new) \
45
- VALUE new = img_init_partial(); \
46
- GetImg(new, data_new, im_new);
47
-
48
- #define RUBY_VIPS_UNARY(VIPS_METHOD) \
49
- do { \
50
- GetImg(obj, data, im); \
51
- OutImg(obj, new, data_new, im_new); \
52
- \
53
- if (VIPS_METHOD(im, im_new)) \
54
- vips_lib_error(); \
55
- \
56
- return new; \
57
- } while(0)
58
-
59
- #define RUBY_VIPS_BINARY(VIPS_METHOD) \
60
- do { \
61
- GetImg(obj, data, im); \
62
- GetImg(obj2, data2, im2); \
63
- OutImg2(obj, obj2, new, data_new, im_new); \
64
- \
65
- if (VIPS_METHOD(im, im2, im_new)) \
66
- vips_lib_error(); \
67
- \
68
- return new; \
69
- } while(0)
70
-
71
- #endif
72
-
@@ -1,936 +0,0 @@
1
- #include "ruby_vips.h"
2
-
3
- /*
4
- * call-seq:
5
- * im.measure_area(left, top, width, height, h, v, sel) -> array
6
- *
7
- * Analyse a grid of colour patches, producing an array of averages.
8
- * Pass a box defined by <i>left</i>, <i>top</i>, <i>width</i>, and
9
- * <i>height</i>, the number of horizontal and vertical patches <i>h</i> and
10
- * <i>v</i>, an array giving the numbers of the patches to measure <i>sel</i>
11
- * (patches are numbered left-to-right, top-to-bottom, starting with 1). Return
12
- * an array in which rows are patches and columns are bands. Only the central
13
- * 50% of each patch is averaged.
14
- */
15
-
16
- VALUE
17
- img_measure_area(VALUE obj, VALUE left, VALUE top, VALUE width, VALUE height,
18
- VALUE h, VALUE v, VALUE sel)
19
- {
20
- DOUBLEMASK *ret;
21
- int *a, i, len = RARRAY_LENINT(sel);
22
- GetImg(obj, data, im);
23
-
24
- a = ALLOC_N(int, len);
25
- for (i = 0; i < len; i++)
26
- a[i] = NUM2INT(RARRAY_PTR(sel)[i]);
27
-
28
- ret = im_measure_area(im, NUM2INT(left), NUM2INT(top), NUM2INT(width),
29
- NUM2INT(height), NUM2INT(h), NUM2INT(v), a, len, "img_measure_area");
30
-
31
- xfree(a);
32
-
33
- return dmask2rb(ret);
34
- }
35
-
36
- /*
37
- * call-seq:
38
- * im.stats -> array
39
- *
40
- * Find many image statistics in a single pass through the pixels. Returns an
41
- * array of 6 columns by n+1 (where n is number of bands in the image) rows.
42
- * Columns are statistics, and are, in order: minimum, maximum, sum, sum of
43
- * squares, mean, standard deviation. Row 0 has statistics for all bands
44
- * together, row 1 has stats for band 1, and so on.
45
- */
46
-
47
- VALUE
48
- img_stats(VALUE obj)
49
- {
50
- DOUBLEMASK *ret;
51
- GetImg(obj, data, im);
52
-
53
- if (!(ret = im_stats(im)))
54
- vips_lib_error();
55
-
56
- return dmask2rb(ret);
57
- }
58
-
59
- /*
60
- * call-seq:
61
- * im.max -> number
62
- *
63
- * Finds the the maximum value of *self*. If input is complex, the max modulus
64
- * is returned. Finds the maximum of all bands: if you want to find the maximum
65
- * of each band separately, use Image#stats.
66
- */
67
-
68
- VALUE
69
- img_max(VALUE obj) {
70
- double out;
71
- GetImg(obj, data, im);
72
-
73
- if (im_max(im, &out))
74
- vips_lib_error();
75
-
76
- return DBL2NUM(out);
77
- }
78
-
79
- /*
80
- * call-seq:
81
- * im.min -> number
82
- *
83
- * Finds the the minimum value of the image. If input is complex, the min
84
- * modulus is returned. Finds the minimum of all bands: if you want to find the
85
- * minimum of each band separately, use Image#stats.
86
- */
87
-
88
- VALUE
89
- img_min(VALUE obj) {
90
- double out;
91
- GetImg(obj, data, im);
92
-
93
- if (im_min(im, &out))
94
- vips_lib_error();
95
-
96
- return DBL2NUM(out);
97
- }
98
-
99
- /*
100
- * call-seq:
101
- * im.avg -> number
102
- *
103
- * Finds the average of an image. Works on any non-complex image format.
104
- */
105
-
106
- VALUE
107
- img_avg(VALUE obj) {
108
- double out;
109
- GetImg(obj, data, im);
110
-
111
- if (im_avg(im, &out))
112
- vips_lib_error();
113
-
114
- return DBL2NUM(out);
115
- }
116
-
117
- /*
118
- * call-seq:
119
- * im.deviate -> number
120
- *
121
- * This operation finds the standard deviation of all pixels in the image. It
122
- * operates on all bands of the input image: use Image#stats if you need to
123
- * calculate an average for each band.
124
- *
125
- * Non-complex images only.
126
- */
127
-
128
- VALUE
129
- img_deviate(VALUE obj) {
130
- double out;
131
- GetImg(obj, data, im);
132
-
133
- if (im_deviate(im, &out))
134
- vips_lib_error();
135
-
136
- return DBL2NUM(out);
137
- }
138
-
139
- /*
140
- * call-seq:
141
- * im.maxpos_avg -> [ x, y, value ]
142
- *
143
- * Function to find the maximum of an image. In the event of a draw, returns
144
- * average of all drawing coords.
145
- */
146
-
147
- VALUE
148
- img_maxpos_avg(VALUE obj) {
149
- double x, y, out;
150
- GetImg(obj, data, im);
151
-
152
- if (im_maxpos_avg(im, &x, &y, &out))
153
- vips_lib_error();
154
-
155
- return rb_ary_new3(3, DBL2NUM(x), DBL2NUM(y), DBL2NUM(out));
156
- }
157
-
158
- static VALUE
159
- img_maxpos_single(VALUE obj) {
160
- double out;
161
- int x, y;
162
- GetImg(obj, data, im);
163
-
164
- if (im_maxpos(im, &x, &y, &out))
165
- vips_lib_error();
166
-
167
- return rb_ary_new3(3, INT2NUM(x), INT2NUM(y), DBL2NUM(out));
168
- }
169
-
170
- static VALUE
171
- img_maxpos_n(VALUE obj, int len) {
172
- double *out;
173
- int im_return, i, *x, *y;
174
- VALUE t, ary;
175
- GetImg(obj, data, im);
176
-
177
- ary = rb_ary_new2(len);
178
-
179
- x = ALLOC_N(int, len);
180
- y = ALLOC_N(int, len);
181
- out = ALLOC_N(double, len);
182
-
183
- if (!(im_return = im_maxpos_vec(im, x, y, out, len))) {
184
- for (i = 0; i < len; i++) {
185
- t = rb_ary_new3(3, INT2NUM(x[i]), INT2NUM(y[i]), DBL2NUM(out[i]));
186
- rb_ary_push(ary, t);
187
- }
188
- }
189
-
190
- xfree(x);
191
- xfree(y);
192
- xfree(out);
193
-
194
- if(im_return)
195
- vips_lib_error();
196
-
197
- return ary;
198
- }
199
-
200
- /*
201
- * call-seq:
202
- * im.maxpos -> x, y, value
203
- * im.maxpos(n, ...) -> [ x, y, value ], ...
204
- *
205
- * Function to find the maximum of an image. Works for any image type. Returns
206
- * an array with the x and y coordinates of the maximum value and the
207
- * corresponding value. If <i>n</i> is given, returns the <i>n</i> largest
208
- * values. For complex images, finds the pixel with the highest modulus.
209
- */
210
-
211
- VALUE
212
- img_maxpos(int argc, VALUE *argv, VALUE obj) {
213
- VALUE v_num;
214
-
215
- rb_scan_args(argc, argv, "01", &v_num);
216
- if (NIL_P(v_num))
217
- return img_maxpos_single(obj);
218
- else
219
- return img_maxpos_n(obj, NUM2INT(v_num));
220
- }
221
-
222
- static VALUE
223
- img_minpos_single(VALUE obj) {
224
- double out;
225
- int x, y;
226
- GetImg(obj, data, im);
227
-
228
- if (im_minpos(im, &x, &y, &out))
229
- vips_lib_error();
230
-
231
- return rb_ary_new3(3, INT2NUM(x), INT2NUM(y), DBL2NUM(out));
232
- }
233
-
234
- static VALUE
235
- img_minpos_n(VALUE obj, int len) {
236
- double *out;
237
- int im_return, i, *x, *y;
238
- VALUE t, ary;
239
- GetImg(obj, data, im);
240
-
241
- ary = rb_ary_new2(len);
242
-
243
- x = ALLOC_N(int, len);
244
- y = ALLOC_N(int, len);
245
- out = ALLOC_N(double, len);
246
-
247
- if (!(im_return = im_minpos_vec(im, x, y, out, len))) {
248
- for (i = 0; i < len; i++) {
249
- t = rb_ary_new3(3, INT2NUM(x[i]), INT2NUM(y[i]), DBL2NUM(out[i]));
250
- rb_ary_push(ary, t);
251
- }
252
- }
253
-
254
- xfree(x);
255
- xfree(y);
256
- xfree(out);
257
-
258
- if(im_return)
259
- vips_lib_error();
260
-
261
- return ary;
262
- }
263
-
264
- /*
265
- * call-seq:
266
- * im.minpos -> x, y, value
267
- * im.minpos(n) -> [ x, y, value ], ...
268
- *
269
- * Function to find the minimum of an image. Works for any image type. Returns
270
- * an array with the x and y coordinates of the minimum value and the
271
- * corresponding value. If <i>n</i> is given, returns the <i>n</i> lowest
272
- * values. For complex images, finds the pixel with the lowest modulus.
273
- */
274
-
275
- VALUE
276
- img_minpos(int argc, VALUE *argv, VALUE obj) {
277
- VALUE v_num;
278
-
279
- rb_scan_args(argc, argv, "01", &v_num);
280
- if (NIL_P(v_num))
281
- return img_minpos_single(obj);
282
- else
283
- return img_minpos_n(obj, NUM2INT(v_num));
284
- }
285
-
286
- /*
287
- * call-seq:
288
- * im.bandmean -> image
289
- *
290
- * Creates a one-band image where each pixel is the average of the bands for
291
- * that pixel in the input image. The output band format is the same as the
292
- * input band format. Integer types use round-to-nearest averaging.
293
- *
294
- */
295
-
296
- VALUE
297
- img_bandmean(VALUE obj)
298
- {
299
- RUBY_VIPS_UNARY(im_bandmean);
300
- }
301
-
302
- /*
303
- * call-seq:
304
- * im.add(other_image) -> image
305
- * im + other_image -> image
306
- *
307
- * This operation calculates im + <i>other_image</i> and writes the result to
308
- * a new image. The images must be the same size. They may have any format.
309
- *
310
- * If the number of bands differs, one of the images must have one band. In
311
- * this case, an n-band image is formed from the one-band image by joining n
312
- * copies of the one-band image together, and then the two n-band images are
313
- * operated upon.
314
- *
315
- * The two input images are cast up to the smallest common type.
316
- */
317
-
318
- VALUE
319
- img_add(VALUE obj, VALUE obj2)
320
- {
321
- RUBY_VIPS_BINARY(im_add);
322
- }
323
-
324
- /*
325
- * call-seq:
326
- * im.subtract(other_image) -> image
327
- * im - other_image -> image
328
- *
329
- * This operation calculates im - <i>image</i> and writes the result to a new
330
- * image. The images must be the same size. They may have any format.
331
- *
332
- * If the number of bands differs, one of the images must have one band. In this
333
- * case, an n-band image is formed from the one-band image by joining n copies
334
- * of the one-band image together, and then the two n-band images are operated
335
- * upon.
336
- *
337
- * The two input images are cast up to the smallest common type.
338
- */
339
-
340
- VALUE
341
- img_subtract(VALUE obj, VALUE obj2)
342
- {
343
- RUBY_VIPS_BINARY(im_subtract);
344
- }
345
-
346
- /*
347
- * call-seq:
348
- * im.invert -> image
349
- *
350
- * This operation calculates (255 - im). The operation works on uchar images
351
- * only. The input can have any no of channels.
352
- *
353
- * See Image#exptra for a function which can process any input image type.
354
- */
355
-
356
- VALUE
357
- img_invert(VALUE obj)
358
- {
359
- RUBY_VIPS_UNARY(im_invert);
360
- }
361
-
362
- static VALUE
363
- img_lin_mult(int argc, VALUE *argv_a, VALUE *argv_b, VALUE obj)
364
- {
365
- double *a, *b;
366
- int i;
367
-
368
- GetImg(obj, data, im);
369
- OutImg(obj, new, data_new, im_new);
370
-
371
- a = IM_ARRAY(im_new, argc, double);
372
- b = IM_ARRAY(im_new, argc, double);
373
-
374
- for (i = 0; i < argc; i++) {
375
- a[i] = NUM2DBL(argv_a[i]);
376
- b[i] = NUM2DBL(argv_b[i]);
377
- }
378
-
379
- if (im_lintra_vec(argc, a, im, b, im_new))
380
- vips_lib_error();
381
-
382
- return new;
383
- }
384
-
385
- /*
386
- * call-seq:
387
- * im.lin(a, b) -> image
388
- * im.lin([a1, a2, a3], [b1, b2, b3]) -> image
389
- *
390
- * Pass an image through a linear transform - ie. im * <i>a</i> + <i>b</i>.
391
- * Output is always float for integer input, double for double input, complex
392
- * for complex input and double complex for double complex input.
393
- *
394
- * If the arrays are passed in and they have the same number of elements as
395
- * there are bands in the image, then one array element is used for each band.
396
- * If the arrays have more than one element and the image only has a single
397
- * band, the result is a many-band image where each band corresponds to one
398
- * array element.
399
- */
400
-
401
- VALUE
402
- img_lin(VALUE obj, VALUE a, VALUE b)
403
- {
404
- int len = 1;
405
- VALUE *a_v = &a;
406
- VALUE *b_v = &b;
407
-
408
- if (TYPE(a) == T_ARRAY) {
409
- len = RARRAY_LEN(a);
410
-
411
- if (len < 1 || len != RARRAY_LEN(b))
412
- rb_raise(rb_eArgError, "argument arrays must be of equal length with at least one element");
413
-
414
- a_v = RARRAY_PTR(a);
415
- b_v = RARRAY_PTR(b);
416
- }
417
-
418
- return img_lin_mult(len, a_v, b_v, obj);
419
- }
420
-
421
- /*
422
- * call-seq:
423
- * im.multiply(other_image) -> image
424
- * im * other_image -> image
425
- *
426
- * This operation calculates im * <i>other_image</i>. The images must be the
427
- * same size. They may have any format.
428
- *
429
- * If the number of bands differs, one of the images must have one band. In
430
- * this case, an n-band image is formed from the one-band image by joining n
431
- * copies of the one-band image together, and then the two n-band images are
432
- * operated upon.
433
- *
434
- * The two input images are cast up to the smallest common type.
435
- */
436
-
437
- VALUE
438
- img_multiply(VALUE obj, VALUE obj2)
439
- {
440
- RUBY_VIPS_BINARY(im_multiply);
441
- }
442
-
443
- static VALUE
444
- img_remainder_img(VALUE obj, VALUE obj2)
445
- {
446
- RUBY_VIPS_BINARY(im_remainder);
447
- }
448
-
449
- static VALUE
450
- img_remainder_const(int argc, VALUE *argv, VALUE obj)
451
- {
452
- int i;
453
- double *c;
454
-
455
- GetImg(obj, data, im);
456
- OutImg(obj, new, data_new, im_new);
457
-
458
- c = IM_ARRAY(im_new, argc, double);
459
- for (i = 0; i < argc; i++)
460
- c[i] = NUM2DBL(argv[i]);
461
-
462
- if (im_remainder_vec(im, im_new, argc, c))
463
- vips_lib_error();
464
-
465
- return new;
466
- }
467
-
468
- /*
469
- * call-seq:
470
- * im % other_image -> image
471
- * im % c -> image
472
- * im % [c, ...] -> image
473
- *
474
- * im.remainder(other_image) -> image
475
- * im.remainder(c) -> image
476
- * im.remainder(c, ...) -> image
477
- *
478
- * The first form calculates im % <i>other_image</i> (remainder after
479
- * division). The images must be the same size. They may have any non-complex
480
- * format. For float formats, it calculates im - <i>other_image</i> * floor (im
481
- * / <i>other_image</i>).
482
- *
483
- * If the number of bands differs, one of the images must have one band. In
484
- * this case, an n-band image is formed from the one-band image by joining n
485
- * copies of the one-band image together, and then the two n-band images are
486
- * operated upon.
487
- *
488
- * The two input images are cast up to the smallest common type.
489
- *
490
- * The second and third form calculates im % <i>c</i> (remainder after division
491
- * by constant). The image may have any non-complex format. For float formats,
492
- * calculates im - <i>c</i> * floor (im / <i>c</i>).
493
- *
494
- * If the number of image bands and constants differs, then the image must have
495
- * one band or there must only one constant. Either the image is up-banded by
496
- * joining n copies of the one-band image together, or the same constant is
497
- * used for all image bands.
498
- */
499
-
500
- VALUE
501
- img_remainder(int argc, VALUE *argv, VALUE obj)
502
- {
503
- if (argc < 1)
504
- rb_raise(rb_eArgError, "Expected at least one constant");
505
- else if (argc == 1 && CLASS_OF(argv[0]) == cVIPSImage)
506
- return img_remainder_img(obj, argv[0]);
507
- else
508
- return img_remainder_const(argc, argv, obj);
509
- }
510
-
511
- VALUE
512
- img_remainder_binop(VALUE obj, VALUE arg)
513
- {
514
- int argc = 1;
515
- VALUE *argv = &arg;
516
-
517
- if (TYPE(arg) == T_ARRAY) {
518
- argc = RARRAY_LEN(arg);
519
- argv = RARRAY_PTR(arg);
520
- }
521
-
522
- return img_remainder(argc, argv, obj);
523
- }
524
-
525
- /*
526
- * call-seq:
527
- * im.divide(other_image) -> image
528
- * im / other_image -> image
529
- *
530
- * This operation calculates im / <i>other_image</i>. The images must be the
531
- * same size. They may have any format.
532
- *
533
- * If the number of bands differs, one of the images must have one band. In
534
- * this case, an n-band image is formed from the one-band image by joining n
535
- * copies of the one-band image together, and then the two n-band images are
536
- * operated upon.
537
- *
538
- * The two input images are cast up to the smallest common type.
539
- */
540
-
541
- VALUE
542
- img_divide(VALUE obj, VALUE obj2)
543
- {
544
- RUBY_VIPS_BINARY(im_divide);
545
- }
546
-
547
- /*
548
- * call-seq:
549
- * im.recomb(array) -> image
550
- *
551
- * This operation recombines an image's bands. Each pixel in im is treated as
552
- * an n-element vector, where n is the number of bands in im, and multipled by
553
- * the n x m matrix <i>array</i> to produce the m-band output image.
554
- *
555
- * The output image is always float, unless im is double, in which case it is
556
- * double too. No complex images allowed.
557
- *
558
- * It's useful for various sorts of colour space conversions.
559
- */
560
-
561
- VALUE
562
- img_recomb(VALUE obj, VALUE recomb)
563
- {
564
- DOUBLEMASK *dmask;
565
-
566
- GetImg(obj, data, im);
567
- OutImg(obj, new, data_new, im_new);
568
-
569
- mask_arg2mask(recomb, NULL, &dmask);
570
-
571
- if (im_recomb(im, im_new, dmask))
572
- vips_lib_error();
573
-
574
- return new;
575
- }
576
-
577
- /*
578
- * call-seq:
579
- * im.sign -> image
580
- *
581
- * Finds the unit vector in the direction of the pixel value. For non-complex
582
- * images, it returns a signed char image with values -1, 0, and 1 for
583
- * negative, zero and positive pixels. For complex images, it returns a complex
584
- * normalised to length 1.
585
- */
586
-
587
- VALUE
588
- img_sign(VALUE obj)
589
- {
590
- RUBY_VIPS_UNARY(im_sign);
591
- }
592
-
593
- /*
594
- * call-seq:
595
- * im.abs -> image
596
- *
597
- * This operation finds the absolute value of an image. It does a copy for
598
- * unsigned integer types, negate for negative values in signed integer types,
599
- * fabs(3) for float types, and calculate modulus for complex types.
600
- */
601
-
602
- VALUE
603
- img_abs(VALUE obj)
604
- {
605
- RUBY_VIPS_UNARY(im_abs);
606
- }
607
-
608
- /*
609
- * call-seq:
610
- * im.floor -> image
611
- *
612
- * For each pixel, find the largest integral value not less than. Copy for
613
- * integer types. Output type == input type.
614
- */
615
-
616
- VALUE
617
- img_floor(VALUE obj)
618
- {
619
- RUBY_VIPS_UNARY(im_floor);
620
- }
621
-
622
- /*
623
- * call-seq:
624
- * im.rint -> image
625
- *
626
- * Finds the nearest integral value. Copy for integer types. Output type ==
627
- * input type.
628
- */
629
-
630
- VALUE
631
- img_rint(VALUE obj)
632
- {
633
- RUBY_VIPS_UNARY(im_rint);
634
- }
635
-
636
- /*
637
- * call-seq:
638
- * im.ceil -> image
639
- *
640
- * For each pixel, find the smallest integral value not less than. Copy for
641
- * integer types. Output type == input type.
642
- */
643
-
644
- VALUE
645
- img_ceil(VALUE obj)
646
- {
647
- RUBY_VIPS_UNARY(im_ceil);
648
- }
649
-
650
- /*
651
- * call-seq:
652
- * linreg(x) -> image
653
- * linreg(*args) -> image
654
- *
655
- * Function to find perform pixelwise linear regression on an array of
656
- * single band images. The output is a seven-band double image.
657
- *
658
- * <i>x</i> is the position of each image (pixel value is Y).
659
- */
660
-
661
- VALUE
662
- img_s_linreg(int argc, VALUE *argv, VALUE obj)
663
- {
664
- vipsImg *in;
665
- IMAGE **ins;
666
- double *vips_xs;
667
- VALUE cur_img;
668
- int i;
669
- OutPartial(new, data_new, im_new);
670
-
671
- vips_xs = IM_ARRAY(im_new, argc, double);
672
- ins = IM_ARRAY(im_new, argc + 1, IMAGE*);
673
-
674
- ins[argc] = NULL; /* takes a NULL terminated array of IMAGE pointers */
675
-
676
- for (i = 0; i < argc; i++) {
677
- cur_img = RARRAY_PTR(argv[i])[0];
678
- img_add_dep(data_new, cur_img);
679
-
680
- Data_Get_Struct(cur_img, vipsImg, in);
681
- ins[i] = in->in;
682
-
683
- vips_xs[i] = NUM2DBL(RARRAY_PTR(argv[i])[1]);
684
- }
685
-
686
- if (im_linreg(ins, im_new, vips_xs))
687
- vips_lib_error();
688
-
689
- return new;
690
- }
691
-
692
- /*
693
- * call-seq:
694
- * im.point(interpolator_sym, x, y, band) -> number
695
- *
696
- * Find the value at (@x, @y) in given band of image.
697
- * Non-integral values are calculated using the supplied interpolator, e.g.
698
- * :bilinear.
699
- *
700
- * To get a list of available interpolators, look at
701
- * VIPS::Interpolator::INTERPOLATORS.keys
702
- */
703
-
704
- VALUE
705
- img_point(VALUE obj, VALUE itrp_sym, VALUE x, VALUE y, VALUE band)
706
- {
707
- double out;
708
- VipsInterpolate *itrp_vips = interp_lookup(itrp_sym);
709
- GetImg(obj, data, im);
710
-
711
- if (im_point(im, itrp_vips, NUM2DBL(x), NUM2DBL(y), NUM2INT(band), &out))
712
- vips_lib_error();
713
-
714
- return DBL2NUM(out);
715
- }
716
-
717
- /*
718
- * call-seq:
719
- * im.pow(c, ...) -> image
720
- *
721
- * im ** c -> image
722
- * im ** [c, ...] -> image
723
- *
724
- * Tansforms each pixel value in the input image to value ** <i>c</i> in the
725
- * output image. It detects division by zero, setting those pixels to zero in
726
- * the output. Beware: it does this silently!
727
- *
728
- * If one constant <i>c</i> is given, that constant is used for each image
729
- * band. If more than one value is given, it must have the same number of
730
- * elements as there are bands in the image, and one element is used for each
731
- * band.
732
- */
733
-
734
- VALUE
735
- img_pow(int argc, VALUE *argv, VALUE obj)
736
- {
737
- double *c;
738
- int i;
739
-
740
- if (argc < 1)
741
- rb_raise(rb_eArgError, "Expected at least one constant");
742
-
743
- GetImg(obj, data, im);
744
- OutImg(obj, new, data_new, im_new);
745
-
746
- c = IM_ARRAY(im_new, argc, double);
747
-
748
- for (i = 0; i < argc; i++)
749
- c[i] = NUM2DBL(argv[i]);
750
-
751
- if (im_powtra_vec(im, im_new, argc, c))
752
- vips_lib_error();
753
-
754
- return new;
755
- }
756
-
757
- VALUE
758
- img_pow_binop(VALUE obj, VALUE arg)
759
- {
760
- int argc = 1;
761
- VALUE *argv = &arg;
762
-
763
- if (TYPE(arg) == T_ARRAY) {
764
- argc = RARRAY_LEN(arg);
765
- argv = RARRAY_PTR(arg);
766
- }
767
-
768
- return img_pow(argc, argv, obj);
769
- }
770
-
771
- /*
772
- * call-seq:
773
- * im.expn(c, ...) -> image
774
- *
775
- * Transforms each pixel value of the input image to <i>c</i> ** value in the
776
- * output image. It detects division by zero, setting those pixels to zero in
777
- * the output. Beware: it does this silently!
778
- *
779
- * If one constant <i>c</i> is given, that constant is used for each image
780
- * band. If more than one value is given, it must have the same number of
781
- * elements as there are bands in the image, and one element is used for each
782
- * band.
783
- */
784
-
785
- VALUE
786
- img_expn(int argc, VALUE *argv, VALUE obj)
787
- {
788
- double *c;
789
- int i;
790
- GetImg(obj, data, im);
791
- OutImg(obj, new, data_new, im_new);
792
-
793
- c = IM_ARRAY(im_new, argc, double);
794
-
795
- for (i = 0; i < argc; i++)
796
- c[i] = NUM2DBL(argv[i]);
797
-
798
- if (im_expntra_vec(im, im_new, argc, c))
799
- vips_lib_error();
800
-
801
- return new;
802
- }
803
-
804
- /*
805
- * call-seq:
806
- * im.log -> image
807
- *
808
- * For each pixel, calculate the natural logarithm. The output type is float,
809
- * unless the input is double, in which case the output is double. Non-complex
810
- * images only.
811
- */
812
-
813
- VALUE
814
- img_log(VALUE obj)
815
- {
816
- RUBY_VIPS_UNARY(im_logtra);
817
- }
818
-
819
- /*
820
- * call-seq:
821
- * im.log10 -> image
822
- *
823
- * For each pixel, calculate the base 10 logarithm. The output type is float,
824
- * unless the input is double, in which case the output is double. Non-complex
825
- * images only.
826
- */
827
-
828
- VALUE
829
- img_log10(VALUE obj)
830
- {
831
- RUBY_VIPS_UNARY(im_log10tra);
832
- }
833
-
834
- /*
835
- * call-seq:
836
- * im.sin -> image
837
- *
838
- * For each pixel, calculate the sine. Angles are expressed in degrees. The
839
- * output type is float, unless the input is double, in which case the output
840
- * is double. Non-complex images only.
841
- */
842
-
843
- VALUE
844
- img_sin(VALUE obj)
845
- {
846
- RUBY_VIPS_UNARY(im_sintra);
847
- }
848
-
849
- /*
850
- * call-seq:
851
- * im.cos -> image
852
- *
853
- * For each pixel, calculate the cosine. Angles are expressed in degrees. The
854
- * output type is float, unless the input is double, in which case the output
855
- * is double. Non-complex images only.
856
- */
857
-
858
- VALUE
859
- img_cos(VALUE obj)
860
- {
861
- RUBY_VIPS_UNARY(im_costra);
862
- }
863
-
864
- /*
865
- * call-seq:
866
- * im.tan -> image
867
- *
868
- * For each pixel, calculate the tangent. Angles are expressed in degrees. The
869
- * output type is float, unless the input is double, in which case the output
870
- * is double. Non-complex images only.
871
- */
872
-
873
- VALUE
874
- img_tan(VALUE obj)
875
- {
876
- RUBY_VIPS_UNARY(im_tantra);
877
- }
878
-
879
- /*
880
- * call-seq:
881
- * im.asin -> image
882
- *
883
- * For each pixel, calculate the arc or inverse sine. Angles are expressed in
884
- * degrees. The output type is float, unless the input is double, in which case
885
- * the output is double. Non-complex images only.
886
- */
887
-
888
- VALUE
889
- img_asin(VALUE obj)
890
- {
891
- RUBY_VIPS_UNARY(im_asintra);
892
- }
893
-
894
- /*
895
- * call-seq:
896
- * im.acos -> image
897
- *
898
- * For each pixel, calculate the arc or inverse cosine. Angles are expressed in
899
- * degrees. The output type is float, unless the input is double, in which case
900
- * the output is double. Non-complex images only.
901
- */
902
-
903
- VALUE
904
- img_acos(VALUE obj)
905
- {
906
- RUBY_VIPS_UNARY(im_acostra);
907
- }
908
-
909
- /*
910
- * call-seq:
911
- * im.atan -> image
912
- *
913
- * For each pixel, calculate the arc or inverse tangent. Angles are expressed
914
- * in degrees. The output type is float, unless the input is double, in which
915
- * case the output is double. Non-complex images only.
916
- */
917
-
918
- VALUE
919
- img_atan(VALUE obj)
920
- {
921
- RUBY_VIPS_UNARY(im_atantra);
922
- }
923
-
924
- /*
925
- * call-seq:
926
- * im.cross_phase(other_image) -> image
927
- *
928
- * Find the phase of the cross power spectrum of two complex images, expressed
929
- * as a complex image where the modulus of each pixel is one.
930
- */
931
-
932
- VALUE
933
- img_cross_phase(VALUE obj, VALUE obj2)
934
- {
935
- RUBY_VIPS_BINARY(im_cross_phase);
936
- }