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,36 +0,0 @@
1
- VALUE img_lab_to_lch(VALUE);
2
- VALUE img_lch_to_lab(VALUE);
3
- VALUE img_labq_to_xyz(VALUE);
4
- VALUE img_rad_to_float(VALUE);
5
- VALUE img_float_to_rad(VALUE);
6
- VALUE img_lch_to_ucs(VALUE);
7
- VALUE img_lab_to_labq(VALUE);
8
- VALUE img_lab_to_labs(VALUE);
9
- VALUE img_lab_to_xyz(VALUE);
10
- VALUE img_lab_to_xyz_temp(VALUE, VALUE, VALUE, VALUE);
11
- VALUE img_lab_to_ucs(VALUE);
12
- VALUE img_labq_to_lab(VALUE);
13
- VALUE img_labq_to_labs(VALUE);
14
- VALUE img_labs_to_labq(VALUE);
15
- VALUE img_labs_to_lab(VALUE);
16
- VALUE img_ucs_to_xyz(VALUE);
17
- VALUE img_ucs_to_lch(VALUE);
18
- VALUE img_ucs_to_lab(VALUE);
19
- VALUE img_xyz_to_lab(VALUE);
20
- VALUE img_xyz_to_lab_temp(VALUE, VALUE, VALUE, VALUE);
21
- VALUE img_xyz_to_ucs(VALUE);
22
- VALUE img_srgb_to_xyz(VALUE);
23
- VALUE img_xyz_to_srgb(VALUE);
24
- VALUE img_yxy_to_xyz(VALUE);
25
- VALUE img_xyz_to_yxy(VALUE);
26
- VALUE img_decmc_from_lab(VALUE, VALUE);
27
- VALUE img_de00_from_lab(VALUE, VALUE);
28
- VALUE img_de_from_xyz(VALUE, VALUE);
29
- VALUE img_de_from_lab(VALUE, VALUE);
30
- VALUE img_lab_morph(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
31
- VALUE img_icc_transform(VALUE, VALUE, VALUE, VALUE);
32
- VALUE img_icc_import(VALUE, VALUE, VALUE);
33
- VALUE img_icc_import_embedded(VALUE, VALUE);
34
- VALUE img_icc_export_depth(VALUE, VALUE, VALUE, VALUE);
35
- VALUE img_icc_ac2rc(VALUE, VALUE, VALUE);
36
- void init_Image_colour();
@@ -1,884 +0,0 @@
1
- #include "ruby_vips.h"
2
-
3
- static ID id_black, id_extend, id_repeat, id_mirror, id_white;
4
-
5
- /*
6
- * call-seq:
7
- * im.to_mask -> mask
8
- *
9
- * Make a mask from an image. All images are cast to band format :DOUBLE
10
- * before processing. There are two cases for handling bands:
11
- *
12
- * If the image has a single band, Image#to_mask will write a mask the same
13
- * size as the image.
14
- *
15
- * If the image has more than one band, it must be one pixel high or wide. In
16
- * this case the output mask uses that axis to represent band values.
17
- */
18
-
19
- VALUE
20
- img_to_mask(VALUE obj)
21
- {
22
- vipsMask *msk;
23
- VALUE mask = mask_alloc(cVIPSMask);
24
- GetImg(obj, data, im);
25
-
26
- Data_Get_Struct(mask, vipsMask, msk);
27
-
28
- if (!(msk->dmask = im_vips2mask(im, "img_vips2mask")))
29
- vips_lib_error();
30
-
31
- return mask;
32
- }
33
-
34
- /*
35
- * call-seq:
36
- * im.dup -> image
37
- *
38
- * Create a copy of an image.
39
- */
40
-
41
- VALUE
42
- img_dup(VALUE obj)
43
- {
44
- RUBY_VIPS_UNARY(im_copy);
45
- }
46
-
47
- /*
48
- * call-seq:
49
- * im.copy_swap -> image
50
- *
51
- * Copy an image, swapping byte order between little and big endian. This
52
- * really does change image pixels and does not just alter the header.
53
- */
54
-
55
- VALUE
56
- img_copy_swap(VALUE obj)
57
- {
58
- RUBY_VIPS_UNARY(im_copy_swap);
59
- }
60
-
61
- /*
62
- * call-seq:
63
- * im.copy_native -> image
64
- *
65
- * Copy an image to native order, that is, the order for the executing program.
66
- */
67
-
68
- VALUE
69
- img_copy_native(VALUE obj, VALUE input_msb_first)
70
- {
71
- #if ATLEAST_VIPS( 7, 22 )
72
- vipsImg *in, *out;
73
- int msb_first;
74
-
75
- VALUE new = img_spawn(obj);
76
-
77
- Data_Get_Struct(obj, vipsImg, in);
78
- Data_Get_Struct(new, vipsImg, out);
79
-
80
- msb_first = input_msb_first == Qtrue ? TRUE : FALSE;
81
- if( im_copy_native(in->in, out->in, msb_first) )
82
- vips_lib_error();
83
-
84
- return new;
85
- #else
86
- rb_raise(eVIPSError, "Your version of vips doesn't support this operation");
87
- #endif
88
- }
89
-
90
- /*
91
- * call-seq:
92
- * im.copy_file -> image
93
- *
94
- * Copy an image to a disc file, then copy again to output. If the image is
95
- * already a disc file, just copy straight through.
96
- *
97
- * The file is automatically deleted when <i>image</i> is closed.
98
- */
99
-
100
- VALUE
101
- img_copy_file(VALUE obj)
102
- {
103
- vipsImg *in, *out;
104
-
105
- VALUE new = img_spawn(obj);
106
-
107
- Data_Get_Struct(obj, vipsImg, in);
108
- Data_Get_Struct(new, vipsImg, out);
109
-
110
- if( im_copy_file(in->in, out->in) )
111
- vips_lib_error();
112
-
113
- return new;
114
- }
115
-
116
- /*
117
- * call-seq:
118
- * im.clip2fmt(fmt_symbol) -> image
119
- *
120
- * Convert the image to <i>fmt_symbol</i> format. You can convert between any
121
- * pair of formats. Floats are truncated (not rounded). Out of range values are
122
- * clipped.
123
- *
124
- * <i>fmt_symbol</i> can be any of: :NOTSET, :UCHAR, :CHAR, :USHORT, :SHORT,
125
- * :UINT, :INT, :FLOAT, :COMPLEX, :DOUBLE, :DPCOMPLEX.
126
- */
127
-
128
- VALUE
129
- img_clip2fmt(VALUE obj, VALUE fmt)
130
- {
131
- GetImg(obj, data, im);
132
- OutImg(obj, new, data_new, im_new);
133
-
134
- if (im_clip2fmt(im, im_new, header_id_to_band_fmt(SYM2ID(fmt))))
135
- vips_lib_error();
136
-
137
- return new;
138
- }
139
-
140
- /*
141
- * call-seq:
142
- * im.scale -> image
143
- *
144
- * Search the image for the maximum and minimum value, then return the image
145
- * as unsigned 8-bit, scaled so that the maximum value is 255 and the
146
- * minimum is zero.
147
- */
148
-
149
- VALUE
150
- img_scale(VALUE obj)
151
- {
152
- RUBY_VIPS_UNARY(im_scale);
153
- }
154
-
155
- /*
156
- * call-seq:
157
- * im.msb([band]) -> image
158
- *
159
- * Turn any integer image to 8-bit unsigned char by discarding all but the most
160
- * significant byte. Signed values are converted to unsigned by adding 128.
161
- *
162
- * This operator also works for LABQ coding.
163
- *
164
- * If <i>band</i> is given, this will turn any integer image to a single-band'
165
- * 8-bit unsigned char by discarding all but the most significant byte from the
166
- * selected band.
167
- */
168
-
169
- VALUE
170
- img_msb(int argc, VALUE *argv, VALUE obj)
171
- {
172
- VALUE v_num;
173
- GetImg(obj, data, im);
174
- OutImg(obj, new, data_new, im_new);
175
-
176
- rb_scan_args(argc, argv, "01", &v_num);
177
-
178
- if (NIL_P(v_num)) {
179
- if (im_msb(im, im_new))
180
- vips_lib_error();
181
- } else if (im_msb_band(im, im_new, NUM2INT(v_num)))
182
- vips_lib_error();
183
-
184
- return new;
185
- }
186
-
187
- /*
188
- * call-seq:
189
- * im.c2amph -> image
190
- *
191
- * Convert a complex image from rectangular to polar coordinates. Angles are
192
- * expressed in degrees.
193
- */
194
-
195
- VALUE
196
- img_c2amph(VALUE obj)
197
- {
198
- RUBY_VIPS_UNARY(im_c2amph);
199
- }
200
-
201
- /*
202
- * call-seq:
203
- * im.c2rect -> image
204
- *
205
- * Convert a complex image from polar to rectangular coordinates. Angles are
206
- * expressed in degrees.
207
- */
208
-
209
- VALUE
210
- img_c2rect(VALUE obj)
211
- {
212
- RUBY_VIPS_UNARY(im_c2rect);
213
- }
214
-
215
- /*
216
- * call-seq:
217
- * im.ri2c(other_image) -> image
218
- *
219
- * Compose two real images to make a complex image. If either image has band
220
- * format :DOUBLE, the output image is band format :DPCOMPLEX. Otherwise the
221
- * output image is :COMPLEX.
222
- *
223
- * If the number of bands differs, one of the images must have one band. In
224
- * this case, an n-band image is formed from the one-band image by joining n
225
- * copies of the one-band image together, and then the two n-band images are
226
- * operated upon.
227
- *
228
- * The two input images are cast up to the smallest common type.
229
- */
230
-
231
- VALUE
232
- img_ri2c(VALUE obj, VALUE obj2)
233
- {
234
- RUBY_VIPS_BINARY(im_ri2c);
235
- }
236
-
237
- /*
238
- * call-seq:
239
- * im.c2imag -> image
240
- *
241
- * Extract the imaginary part of a complex image.
242
- */
243
-
244
- VALUE
245
- img_c2imag(VALUE obj)
246
- {
247
- RUBY_VIPS_UNARY(im_c2imag);
248
- }
249
-
250
- /*
251
- * call-seq:
252
- * im.c2real -> image
253
- *
254
- * Extract the real part of a complex image.
255
- */
256
-
257
- VALUE
258
- img_c2real(VALUE obj)
259
- {
260
- RUBY_VIPS_UNARY(im_c2real);
261
- }
262
-
263
- /*
264
- * call-seq:
265
- * im.scaleps -> image
266
- *
267
- * Scale a power spectrum. Transform with log10(1.0 + x ** 0.25)) + 0.5,
268
- * then scale so max == 255.
269
- */
270
-
271
- VALUE
272
- img_scaleps(VALUE obj)
273
- {
274
- RUBY_VIPS_UNARY(im_scaleps);
275
- }
276
-
277
- /*
278
- * call-seq:
279
- * im.falsecolour -> image
280
- *
281
- * Turn a 1-band 8-bit image into a 3-band 8-bit image with a false colour
282
- * map. The map is supposed to make small differences in brightness more
283
- * obvious.
284
- */
285
-
286
- VALUE
287
- img_falsecolour(VALUE obj)
288
- {
289
- RUBY_VIPS_UNARY(im_falsecolour);
290
- }
291
-
292
- /*
293
- * call-seq:
294
- * Image.gaussnoise(width, height, mean, sigma) -> image
295
- *
296
- * Make a one band float image of gaussian noise with the specified
297
- * distribution. The noise distribution is created by averaging 12 random
298
- * numbers with the appropriate weights.
299
- */
300
-
301
- VALUE
302
- img_s_gaussnoise(VALUE obj, VALUE x, VALUE y, VALUE mean, VALUE sigma)
303
- {
304
- OutPartial(new, data, im_new);
305
-
306
- if (im_gaussnoise(im_new, NUM2INT(x), NUM2INT(y), NUM2DBL(mean),
307
- NUM2DBL(sigma)))
308
- vips_lib_error();
309
-
310
- return new;
311
- }
312
-
313
- /*
314
- * call-seq:
315
- * Image.black(width, height, bands) -> image
316
- *
317
- * Make a black unsigned char image of a specified size.
318
- */
319
-
320
- VALUE
321
- img_s_black(VALUE obj, VALUE width, VALUE height, VALUE bands)
322
- {
323
- OutPartial(new, data, im_new);
324
-
325
- if (im_black(im_new, NUM2INT(width), NUM2INT(height), NUM2DBL(bands)))
326
- vips_lib_error();
327
-
328
- return new;
329
- }
330
-
331
- /*
332
- * call-seq:
333
- * Image.text(text, font, width, alignment, dpi) -> image
334
- *
335
- * Draw the string <i>text</i> to an image. @out is a one-band 8-bit
336
- * unsigned char image, with 0 for no text and 255 for text. Values inbetween
337
- * are used for anti-aliasing.
338
- *
339
- * <i>text</i> is the text to render as a UTF-8 string. It can contain Pango
340
- * markup, for example "&lt;i&gt;The&lt;/i&gt;Guardian".
341
- *
342
- * <i>font</i> is the font to render with, selected by fontconfig. Examples
343
- * might be "sans 12" or perhaps "bitstream charter bold 10".
344
- *
345
- * <i>width</i> is the maximum number of pixels across to draw within. If the
346
- * generated text is wider than this, it will wrap to a new line. In this
347
- * case, <i>alignment</i> can be used to set the alignment style for multi-line
348
- * text. 0 means left-align, 1 centre, 2 right-align.
349
- *
350
- * <i>dpi</i> sets the resolution to render at. "sans 12" at 72 dpi draws
351
- * characters approximately 12 pixels high.
352
- */
353
-
354
- VALUE
355
- img_s_text(VALUE obj, VALUE text, VALUE font, VALUE width,
356
- VALUE alignment, VALUE dpi)
357
- {
358
- OutPartial(new, data, im_new);
359
-
360
- if (im_text(im_new, StringValuePtr(text), StringValuePtr(font),
361
- NUM2INT(width), NUM2INT(alignment), NUM2INT(dpi)))
362
- vips_lib_error();
363
-
364
- return new;
365
- }
366
-
367
- /*
368
- * call-seq:
369
- * im.extract_band(band [,num_bands]) -> image
370
- *
371
- * Extract the band given by <i>band</i> from the image. If <i>num_bands</i> is
372
- * given, extract that many bands. Bands number from zero.
373
- *
374
- * im.extract_band(0, 2) # => new image with bands 0 & 1 from original.
375
- *
376
- * Extracting bands outside the input image will trigger an error.
377
- */
378
-
379
- VALUE
380
- img_extract_band(int argc, VALUE *argv, VALUE obj)
381
- {
382
- VALUE v_start_band, v_num_bands;
383
- int num_bands;
384
- GetImg(obj, data, im);
385
- OutImg(obj, new, data_new, im_new);
386
-
387
- rb_scan_args(argc, argv, "11", &v_start_band, &v_num_bands);
388
- num_bands = NIL_P(v_num_bands) ? 1 : NUM2INT(v_num_bands);
389
-
390
- if (im_extract_bands(im, im_new, NUM2INT(v_start_band), num_bands))
391
- vips_lib_error();
392
-
393
- return new;
394
- }
395
-
396
- /*
397
- * call-seq:
398
- * im.extract_area(left, top, width, height) -> image
399
- * im.extract_area(left, top, width, height, band [,num_bands]) -> image
400
- *
401
- * The first form will extract an area from an image.
402
- *
403
- * The second form will extract an area and a number of bands from an image.
404
- * Bands number from zero. Extracting outside the input image will trigger an
405
- * error.
406
- */
407
-
408
- VALUE
409
- img_extract_area(int argc, VALUE *argv, VALUE obj)
410
- {
411
- VALUE v_left, v_top, v_width, v_height, v_start_band, v_num_bands;
412
- int start_band, num_bands;
413
- GetImg(obj, data, im);
414
- OutImg(obj, new, data_new, im_new);
415
-
416
- rb_scan_args(argc, argv, "42", &v_left, &v_top, &v_width, &v_height,
417
- &v_start_band, &v_num_bands);
418
-
419
- /* Start band defaults to the first band */
420
- start_band = NIL_P(v_start_band) ? 0 : NUM2INT(v_start_band);
421
-
422
- /* Number of bands defaults to all bands or the selected band.
423
- */
424
- if (NIL_P(v_num_bands))
425
- num_bands = NIL_P(v_start_band) ? im->Bands : 1;
426
- else
427
- num_bands = NUM2INT(v_num_bands);
428
-
429
- if (im_extract_areabands(im, im_new, NUM2INT(v_left), NUM2INT(v_top),
430
- NUM2INT(v_width), NUM2INT(v_height), start_band, num_bands))
431
- vips_lib_error();
432
-
433
- return new;
434
- }
435
-
436
- /*
437
- * call-seq:
438
- * im.embed(type_sym, x, y, width, height) -> image
439
- *
440
- * The opposite of Image#extract: embed an image within a larger image.
441
- * <i>type_sym</i> controls what appears in the new pixels:
442
- *
443
- * * :black - black pels (all bytes == 0)
444
- * * :extend - extend pels from image edge
445
- * * :repeat - repeat image
446
- * * :mirror - mirror image
447
- * * :white - white pixels (all bytes == 255)
448
- */
449
-
450
- VALUE
451
- img_embed(VALUE obj, VALUE type_v, VALUE x, VALUE y, VALUE width, VALUE height)
452
- {
453
- ID type_id = SYM2ID(type_v);
454
- int type;
455
- GetImg(obj, data, im);
456
- OutImg(obj, new, data_new, im_new);
457
-
458
- if (type_id == id_black) type = 0;
459
- else if (type_id == id_extend) type = 1;
460
- else if (type_id == id_repeat) type = 2;
461
- else if (type_id == id_mirror) type = 3;
462
- else if (type_id == id_white) type = 4;
463
- else
464
- rb_raise(rb_eArgError, "Extend type must be :black, :extend, :repeat, :mirror, :white");
465
-
466
- if (im_embed(im, im_new, type, NUM2INT(x), NUM2INT(y), NUM2INT(width),
467
- NUM2INT(height)))
468
- vips_lib_error();
469
-
470
- return new;
471
- }
472
-
473
- /*
474
- * call-seq:
475
- * im.tile_cache(tile_width, tile_height, max_tiles) -> image
476
- *
477
- * This operation behaves rather like copy between images,
478
- * except that it keeps a cache of computed pixels.
479
- * This cache is made of up to max_tiles tiles (a value of -1 for
480
- * means any number of tiles), and each tile is of size tile_width
481
- * by tile_height pixels.
482
- */
483
-
484
- VALUE
485
- img_tile_cache(VALUE obj, VALUE tile_width, VALUE tile_height, VALUE max_tiles)
486
- {
487
- GetImg(obj, data, im);
488
- OutImg(obj, new, data_new, im_new);
489
-
490
- if (im_tile_cache(im, im_new,
491
- NUM2INT(tile_width), NUM2INT(tile_height), NUM2INT(max_tiles)))
492
- vips_lib_error();
493
-
494
- return new;
495
- }
496
-
497
- /*
498
- * call-seq:
499
- * im.bandjoin(other_image, ...) -> image
500
- *
501
- * Join a set of images together, bandwise. If the images have n and m bands,
502
- * then the output image will have n + m bands, with the first n coming from
503
- * the first image and the last m from the second.
504
- *
505
- * The images must be the same size. The input images are cast up to the
506
- * smallest common type.
507
- */
508
-
509
- VALUE
510
- img_bandjoin(int argc, VALUE *argv, VALUE obj)
511
- {
512
- vipsImg *im_t;
513
- IMAGE **ins;
514
- int i;
515
- GetImg(obj, data, im);
516
- OutImg(obj, new, data_new, im_new);
517
-
518
- if(argc == 0)
519
- rb_raise(rb_eArgError, "Need at least one argument");
520
-
521
- ins = IM_ARRAY(im_new, argc + 1, IMAGE*);
522
- ins[0] = im;
523
-
524
- for (i = 0; i < argc; i++) {
525
- img_add_dep(data_new, argv[i]);
526
- Data_Get_Struct(argv[i], vipsImg, im_t);
527
- ins[i + 1] = im_t->in;
528
- }
529
-
530
- if (im_gbandjoin(ins, im_new, argc + 1))
531
- vips_lib_error();
532
-
533
- return new;
534
- }
535
-
536
- /*
537
- * call-seq:
538
- * im.insert_noexpand(other_image, x, y) -> image
539
- *
540
- * Insert one image into another. <i>other_image</i> is inserted into *self* at
541
- * position <i>x</i>, <i>y</i> relative to the top LH corner of *self*. The
542
- * output image is the same size as *self*. <i>other_image</i> is clipped
543
- * against the edges of *self*.
544
- *
545
- * If the number of bands differs, one of the images must have one band. In
546
- * this case, an n-band image is formed from the one-band image by joining n
547
- * copies of the one-band image together, and then the two n-band images are
548
- * operated upon.
549
- *
550
- * The two input images are cast up to the smallest common type.
551
- */
552
-
553
- VALUE
554
- img_insert_noexpand(VALUE obj, VALUE obj2, VALUE x, VALUE y)
555
- {
556
- GetImg(obj, data, im);
557
- GetImg(obj2, data2, im2);
558
- OutImg2(obj, obj2, new, data_new, im_new);
559
-
560
- if (im_insert_noexpand(im, im2, im_new, NUM2INT(x), NUM2INT(y)))
561
- vips_lib_error();
562
-
563
- return new;
564
- }
565
-
566
- static VALUE
567
- img_insert_one(VALUE obj, VALUE obj2, VALUE x, VALUE y)
568
- {
569
- GetImg(obj, data, im);
570
- GetImg(obj2, data2, im2);
571
- OutImg2(obj, obj2, new, data_new, im_new);
572
-
573
- if (im_insert(im, im2, im_new, NUM2INT(x), NUM2INT(y)))
574
- vips_lib_error();
575
-
576
- return new;
577
- }
578
-
579
- static VALUE
580
- img_insertset(int argc, VALUE *argv, VALUE obj, VALUE obj2)
581
- {
582
- int i, *x, *y;
583
- GetImg(obj, data, im);
584
- GetImg(obj2, data2, im2);
585
- OutImg2(obj, obj2, new, data_new, im_new);
586
-
587
- x = IM_ARRAY(im_new, argc - 1, int);
588
- y = IM_ARRAY(im_new, argc - 1, int);
589
-
590
- for(i = 1; i < argc; i++) {
591
- x[i - 1] = NUM2INT(RARRAY_PTR(argv[i])[0]);
592
- y[i - 1] = NUM2INT(RARRAY_PTR(argv[i])[1]);
593
- }
594
-
595
- if( im_insertset(im, im2, im_new, argc - 1, x, y) )
596
- vips_lib_error();
597
-
598
- return new;
599
- }
600
-
601
- /*
602
- * call-seq:
603
- * im.insert(other_image, x, y) -> image
604
- * im.insert(other_image, coordinates, ...) -> image
605
- *
606
- * Insert <i>other_image</i> repeatedly into *self* at the positions listed in
607
- * the <i>coordinates</i> arrays. These arrays should contain x and y
608
- * coordinates:
609
- *
610
- * im.insert(other_image, 100, 100) # => other_image inserted once at 100, 100
611
- * im.insert(other_image, [12, 20], [32, 22]) # => inserted twice at given coordinates
612
- * The output image is the same size as *self*. <i>other_image</i> is clipped
613
- * against the edges of *self*.
614
- *
615
- * This operation is fast for large @n, but will use a memory buffer the size
616
- * of the output image. It's useful for things like making scatter plots.
617
- *
618
- * If the number of bands differs, one of the images must have one band. In
619
- * this case, an n-band image is formed from the one-band image by joining n
620
- * copies of the one-band image together, and then the two n-band images are
621
- * operated upon.
622
- *
623
- * The two input images are cast up to the smallest common type.
624
- */
625
-
626
- VALUE
627
- img_insert(int argc, VALUE *argv, VALUE obj)
628
- {
629
- VALUE obj2, x_or_ary, y_or_arys;
630
-
631
- rb_scan_args(argc, argv, "2*", &obj2, &x_or_ary, &y_or_arys);
632
-
633
- if (TYPE(x_or_ary) == T_ARRAY) {
634
- if (!NIL_P(y_or_arys))
635
- rb_ary_unshift(y_or_arys, x_or_ary);
636
-
637
- return img_insertset(RARRAY_LEN(y_or_arys), RARRAY_PTR(y_or_arys), obj,
638
- obj2);
639
- }
640
-
641
- if (RARRAY_LEN(y_or_arys) != 1)
642
- rb_raise(rb_eArgError,
643
- "Need two coordinates or an array of coordinates");
644
-
645
- return img_insert_one(obj, obj2, x_or_ary, RARRAY_PTR(y_or_arys)[0]);
646
- }
647
-
648
- /*
649
- * call-seq:
650
- * im.lrjoin(other_image) -> image
651
- *
652
- * Join *self* and <i>other_image</i> together, left-right. If one is taller
653
- * than the other, the output image will be as high as the smaller image.
654
- *
655
- * If the number of bands differs, one of the images must have one band. In
656
- * this case, an n-band image is formed from the one-band image by joining n
657
- * copies of the one-band image together, and then the two n-band images are
658
- * operated upon.
659
- *
660
- * The two input images are cast up to the smallest common type.
661
- */
662
-
663
- VALUE
664
- img_lrjoin(VALUE obj, VALUE obj2)
665
- {
666
- RUBY_VIPS_BINARY(im_lrjoin);
667
- }
668
-
669
- /*
670
- * call-seq:
671
- * im.tbjoin(other_image) -> image
672
- *
673
- * Join *self* and <i>other_image</i> together, top-bottom. If one is taller
674
- * than the other, the output image will be as high as the smaller image.
675
- *
676
- * If the number of bands differs, one of the images must have one band. In
677
- * this case, an n-band image is formed from the one-band image by joining n
678
- * copies of the one-band image together, and then the two n-band images are
679
- * operated upon.
680
- *
681
- * The two input images are cast up to the smallest common type.
682
- */
683
-
684
- VALUE
685
- img_tbjoin(VALUE obj, VALUE obj2)
686
- {
687
- RUBY_VIPS_BINARY(im_tbjoin);
688
- }
689
-
690
- /*
691
- * call-seq:
692
- * im.replicate(across, down) -> image
693
- *
694
- * Replicate an image <i>across</i> times horizontally <i>down</i> times
695
- * vertically.
696
- */
697
-
698
- VALUE
699
- img_replicate(VALUE obj, VALUE across, VALUE down)
700
- {
701
- GetImg(obj, data, im);
702
- OutImg(obj, new, data_new, im_new);
703
-
704
- if (im_replicate(im, im_new, NUM2INT(across), NUM2INT(down)))
705
- vips_lib_error();
706
-
707
- return new;
708
- }
709
-
710
- /*
711
- * call-seq:
712
- * im.grid(tile_height, across, down) -> image
713
- *
714
- * Chop a tall thin image up into a set of tiles, lay the tiles out in a grid.
715
- *
716
- * *self* should be a very tall, thin image containing a list of smaller
717
- * images. Volumetric or time-sequence images are often laid out like this.
718
- * This image is chopped into a series of tiles, each <i>tile_height</i> pixels'
719
- * high and the width of *self*. The tiles are then rearranged into a grid
720
- * <i>across</i> tiles across and <i>down</i> tiles down in row-major order.
721
- */
722
-
723
- VALUE
724
- img_grid(VALUE obj, VALUE tile_height, VALUE across, VALUE down)
725
- {
726
- GetImg(obj, data, im);
727
- OutImg(obj, new, data_new, im_new);
728
-
729
- if (im_grid(im, im_new, NUM2INT(tile_height), NUM2INT(across),
730
- NUM2INT(down)))
731
- vips_lib_error();
732
-
733
- return new;
734
- }
735
-
736
- /*
737
- * call-seq:
738
- * im.wrap(x, y) -> image
739
- *
740
- * Slice an image up and move the segments about so that the pixel that was
741
- * at 0, 0 is now at <i>x</i>, <i>y</i>.
742
- */
743
-
744
- VALUE
745
- img_wrap(VALUE obj, VALUE x, VALUE y)
746
- {
747
- GetImg(obj, data, im);
748
- OutImg(obj, new, data_new, im_new);
749
-
750
- if (im_wrap(im, im_new, NUM2INT(x), NUM2INT(y)))
751
- vips_lib_error();
752
-
753
- return new;
754
- }
755
-
756
- /*
757
- * call-seq:
758
- * im.fliphor -> image
759
- *
760
- * Flips an image left-right.
761
- */
762
-
763
- VALUE
764
- img_fliphor(VALUE obj)
765
- {
766
- RUBY_VIPS_UNARY(im_fliphor);
767
- }
768
-
769
- /*
770
- * call-seq:
771
- * im.flipver -> image
772
- *
773
- * Flips an image top-bottom.
774
- */
775
-
776
- VALUE
777
- img_flipver(VALUE obj)
778
- {
779
- RUBY_VIPS_UNARY(im_flipver);
780
- }
781
-
782
- /*
783
- * call-seq:
784
- * im.rot90 -> image
785
- *
786
- * Rotate an image 90 degrees.
787
- */
788
-
789
- VALUE
790
- img_rot90(VALUE obj)
791
- {
792
- RUBY_VIPS_UNARY(im_rot90);
793
- }
794
-
795
- /*
796
- * call-seq:
797
- * im.rot180 -> image
798
- *
799
- * Rotate an image 180 degrees.
800
- */
801
-
802
- VALUE
803
- img_rot180(VALUE obj)
804
- {
805
- RUBY_VIPS_UNARY(im_rot180);
806
- }
807
-
808
- /*
809
- * call-seq:
810
- * im.rot270 -> image
811
- *
812
- * Rotate an image 270 degrees.
813
- */
814
-
815
- VALUE
816
- img_rot270(VALUE obj)
817
- {
818
- RUBY_VIPS_UNARY(im_rot270);
819
- }
820
-
821
- /*
822
- * call-seq:
823
- * im.subsample(x [,y]) -> image
824
- *
825
- * Subsample an image by an integer fraction. This is fast nearest-neighbour
826
- * shrink.
827
- *
828
- * If only one integer is given the width and height are subsampled equally.
829
- */
830
-
831
- VALUE
832
- img_subsample(int argc, VALUE *argv, VALUE obj)
833
- {
834
- VALUE x, y;
835
- GetImg(obj, data, im);
836
- OutImg(obj, new, data_new, im_new);
837
-
838
- rb_scan_args(argc, argv, "11", &x, &y);
839
- if (NIL_P(y))
840
- y = x;
841
-
842
- if (im_subsample(im, im_new, NUM2INT(x), NUM2INT(y)))
843
- vips_lib_error();
844
-
845
- return new;
846
- }
847
-
848
- /*
849
- * call-seq:
850
- * im.zoom(x [,y]) -> image
851
- *
852
- * Zoom an image by repeating pixels. This is fast nearest-neighbour
853
- * zoom.
854
- *
855
- * If only one integer is given the width and height are zoomed equally.
856
- */
857
-
858
- VALUE
859
- img_zoom(int argc, VALUE *argv, VALUE obj)
860
- {
861
- VALUE x, y;
862
- GetImg(obj, data, im);
863
- OutImg(obj, new, data_new, im_new);
864
-
865
- rb_scan_args(argc, argv, "11", &x, &y);
866
- if (NIL_P(y))
867
- y = x;
868
-
869
- if (im_zoom(im, im_new, NUM2INT(x), NUM2INT(y)))
870
- vips_lib_error();
871
-
872
- return new;
873
- }
874
-
875
- void
876
- init_Image_conversion()
877
- {
878
- id_black = rb_intern("black");
879
- id_extend = rb_intern("extend");
880
- id_repeat = rb_intern("repeat");
881
- id_mirror = rb_intern("mirror");
882
- id_white = rb_intern("white");
883
- }
884
-