ruby-vips 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +14 -0
- data/README.md +30 -17
- data/ext/extconf.rb +22 -2
- data/ext/header.c +2 -4
- data/ext/header.h +1 -0
- data/ext/image.c +7 -18
- data/ext/image.h +2 -1
- data/ext/image_arithmetic.c +0 -4
- data/ext/image_arithmetic.h +1 -1
- data/ext/image_boolean.c +0 -1
- data/ext/image_boolean.h +2 -2
- data/ext/image_colour.c +0 -3
- data/ext/image_conversion.c +2 -5
- data/ext/image_convolution.c +0 -3
- data/ext/image_freq_filt.c +0 -2
- data/ext/image_histograms_lut.c +3 -6
- data/ext/image_histograms_lut.h +1 -1
- data/ext/image_morphology.c +1 -4
- data/ext/image_mosaicing.c +0 -2
- data/ext/image_mosaicing.h +1 -0
- data/ext/image_relational.c +0 -2
- data/ext/image_resample.c +0 -4
- data/ext/interpolator.c +1 -1
- data/ext/interpolator.h +1 -0
- data/ext/mask.c +1 -3
- data/ext/mask.h +1 -0
- data/ext/reader.c +17 -163
- data/ext/reader.h +2 -0
- data/ext/ruby_vips.c +0 -13
- data/ext/ruby_vips.h +25 -2
- data/ext/writer.c +5 -25
- data/ext/writer.h +2 -0
- data/lib/vips/reader.rb +72 -62
- data/lib/vips/version.rb +1 -1
- data/ruby-vips.gemspec +6 -3
- data/ruby.supp +194 -0
- metadata +6 -3
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
# master
|
2
2
|
|
3
|
+
# Version 0.3.0
|
4
|
+
|
5
|
+
Release date: 2012-07-20
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
* More rspec tests [John Cupitt]
|
10
|
+
* Updated to libvips-7.30 [John Cupitt]
|
11
|
+
|
3
12
|
### Changed
|
4
13
|
|
14
|
+
* Reworked Reader class offers better performance and compatibility [John
|
15
|
+
Cupitt]
|
5
16
|
* Don't use :sequential option for older libvipses [John Cupitt]
|
17
|
+
* Rename "tone_analyze" as "tone_analyse" for consistency with the rest of
|
18
|
+
vips [John CUpitt]
|
6
19
|
|
7
20
|
### Fixed
|
8
21
|
|
22
|
+
* Now passes rspec test suite cleanly in valgrind [John Cupitt]
|
9
23
|
* Fixed check of sequential mode support [Stanislaw Pankevich]
|
10
24
|
|
11
25
|
# Version 0.2.0
|
data/README.md
CHANGED
@@ -1,24 +1,20 @@
|
|
1
1
|
# ruby-vips : A fast image processing extension for Ruby.
|
2
2
|
|
3
|
-
*Note*: ruby-vips git master is the development version and uses features
|
4
|
-
from git master of libvips (the unreleased 7.29) as well. You may prefer
|
5
|
-
the stable 0.2 branch of ruby-vips.
|
6
|
-
|
7
3
|
[![Build Status](https://secure.travis-ci.org/jcupitt/ruby-vips.png)](http://travis-ci.org/jcupitt/ruby-vips)
|
8
4
|
|
9
5
|
ruby-vips is a ruby extension for [vips](http://www.vips.ecs.soton.ac.uk).
|
10
|
-
It is
|
6
|
+
It is fast and it can process images without requiring the
|
11
7
|
entire image to be loaded into memory. For example, the benchmark at
|
12
8
|
[vips-benchmarks](https://github.com/stanislaw/vips-benchmarks) loads a large
|
13
9
|
image, crops, shrinks, sharpens and saves again:
|
14
10
|
|
15
|
-
|
11
|
+
```text
|
16
12
|
real time in seconds, fastest of three runs
|
17
13
|
benchmark tiff jpeg
|
18
14
|
ruby-vips.rb 0.45 0.56
|
19
15
|
rmagick.rb 1.69 1.90
|
20
16
|
netpbm.sh 1.74 1.63
|
21
|
-
image-magick
|
17
|
+
image-magick.sh 2.87 3.02
|
22
18
|
image_sci.rb 3.19 2.90
|
23
19
|
|
24
20
|
peak memory use in kilobytes
|
@@ -26,7 +22,7 @@ benchmark peak RSS
|
|
26
22
|
ruby-vips.rb 160400
|
27
23
|
image_sci.rb 546992
|
28
24
|
rmagick.rb 1370064
|
29
|
-
|
25
|
+
```
|
30
26
|
|
31
27
|
See also [benchmarks at the official libvips
|
32
28
|
website](http://www.vips.ecs.soton.ac.uk/index.php?title=Speed_and_Memory_Use).
|
@@ -45,7 +41,7 @@ or to disk.
|
|
45
41
|
* OS X or Linux
|
46
42
|
* MRI 1.8.7, 1.9.2
|
47
43
|
* libvips 7.29 and later (it will work with earlier libvips, but some
|
48
|
-
features may not be functional
|
44
|
+
features may not be functional)
|
49
45
|
|
50
46
|
## Installation.
|
51
47
|
|
@@ -65,7 +61,8 @@ TODO: Describe & test with macports.
|
|
65
61
|
|
66
62
|
### Other platforms
|
67
63
|
|
68
|
-
See [
|
64
|
+
See [Installation on various
|
65
|
+
platforms](https://github.com/jcupitt/ruby-vips/wiki/installation-on-various-platforms).
|
69
66
|
|
70
67
|
### Installing the gem.
|
71
68
|
|
@@ -73,6 +70,16 @@ See [Installiation on various platforms](https://github.com/jcupitt/ruby-vips/wi
|
|
73
70
|
$ gem install ruby-vips
|
74
71
|
```
|
75
72
|
|
73
|
+
Alternatively, for a debug build:
|
74
|
+
|
75
|
+
```bash
|
76
|
+
$ gem install ruby-vips -- --enable-debug
|
77
|
+
```
|
78
|
+
|
79
|
+
```bash
|
80
|
+
$ gem install ruby-vips
|
81
|
+
```
|
82
|
+
|
76
83
|
or include it in Gemfile:
|
77
84
|
|
78
85
|
```ruby
|
@@ -82,7 +89,7 @@ gem 'ruby-vips'
|
|
82
89
|
## Documentation.
|
83
90
|
|
84
91
|
ruby-vips has [rdoc
|
85
|
-
documentation](http://rubydoc.info/gems/ruby-vips/0.
|
92
|
+
documentation](http://rubydoc.info/gems/ruby-vips/0.2.0/frames). Also
|
86
93
|
see [Wiki page](https://github.com/jcupitt/ruby-vips/wiki)
|
87
94
|
|
88
95
|
## Small example
|
@@ -97,12 +104,17 @@ require 'vips'
|
|
97
104
|
|
98
105
|
include VIPS
|
99
106
|
|
100
|
-
# Create an image object. It will not actually load the
|
107
|
+
# Create an image object. It will not actually load the pixel data until
|
108
|
+
# needed.
|
101
109
|
im = Image.jpeg('mypic.jpg')
|
102
110
|
|
111
|
+
# You can read all the header fields without triggering a pixel load.
|
112
|
+
puts "it's #{im.x_size} pixels across!"
|
113
|
+
|
103
114
|
# Shrink the jpeg by a factor of four when loading -- huge speed and CPU
|
104
115
|
# improvements on large images.
|
105
116
|
im = Image.jpeg('mypic.jpg', :shrink_factor => 4)
|
117
|
+
puts "but only #{im.x_size} pixels when we shrink on load"
|
106
118
|
|
107
119
|
# Add a shrink by a factor of two to the pipeline. This will not actually be
|
108
120
|
# executed yet.
|
@@ -112,6 +124,9 @@ im_shrink_by_two = im.shrink(2)
|
|
112
124
|
# actually loaded and resized. With images that allow for random access from
|
113
125
|
# the hard drive (VIPS native format, tiled OpenEXR, ppm/pbm/pgm/pfm, tiled
|
114
126
|
# tiff, and RAW images), the entire image is never read into memory.
|
127
|
+
# For other formats, the image is either decompressed to a temporary disc
|
128
|
+
# file and then processed from there, or, if you give the :sequential hint,
|
129
|
+
# streamed directly from the file.
|
115
130
|
im_shrink_by_two.png('out.png', :interlace => true)
|
116
131
|
|
117
132
|
# All ruby-vips image commands can be chained, so the above sequence could
|
@@ -126,18 +141,16 @@ Image.jpeg('mypic.jpg', :shrink_factor => 4).shrink(2).png('out.png')
|
|
126
141
|
Image.new('mypic.jpg').shrink(2).write('out.png')
|
127
142
|
```
|
128
143
|
|
129
|
-
##
|
130
|
-
|
131
|
-
### Contain memuse
|
144
|
+
## Garbage collection
|
132
145
|
|
133
|
-
ruby-vips only
|
146
|
+
ruby-vips only frees images on GC. In other words:
|
134
147
|
|
135
148
|
```ruby
|
136
149
|
a = Image.new(filename)
|
137
150
|
a = nil
|
138
151
|
```
|
139
152
|
|
140
|
-
will not release the resources associated with a
|
153
|
+
will not release the resources associated with `a`, you have to
|
141
154
|
either request a GC explicitly or wait for Ruby to GC for you. This can
|
142
155
|
be a problem if you're processing many images.
|
143
156
|
|
data/ext/extconf.rb
CHANGED
@@ -4,8 +4,28 @@ require "mkmf"
|
|
4
4
|
|
5
5
|
File::unlink("Makefile") if (File::exist?("Makefile"))
|
6
6
|
|
7
|
-
|
7
|
+
# override normal build configuration to build debug friendly library
|
8
|
+
# if installed via 'gem install ruby-vips -- --enable-debug'
|
9
|
+
# see: http://jonforums.github.com/ruby/2011/01/27/debugging-native-gems-1.html
|
10
|
+
if enable_config('debug')
|
11
|
+
puts '[INFO] enabling debug library build configuration.'
|
12
|
+
if RUBY_VERSION < '1.9'
|
13
|
+
$CFLAGS = CONFIG['CFLAGS'].gsub(/\s\-O\d?\s/, ' -O0 ')
|
14
|
+
$CFLAGS.gsub!(/\s?\-g\w*\s/, ' -ggdb3 ')
|
15
|
+
CONFIG['LDSHARED'] = CONFIG['LDSHARED'].gsub(/\s\-s(\s|\z)/, ' ')
|
16
|
+
else
|
17
|
+
CONFIG['debugflags'] << ' -ggdb3 -O0'
|
18
|
+
end
|
19
|
+
end
|
8
20
|
|
9
|
-
|
21
|
+
# vips-7.30 and later use plain "vips" for the pkg-config name: look for that
|
22
|
+
# first
|
23
|
+
if not pkg_config("vips")
|
24
|
+
VIPS_VERSIONS = %w[7.29 7.28 7.27 7.26 7.24 7.23 7.22 7.20]
|
25
|
+
|
26
|
+
if not VIPS_VERSIONS.detect {|x| pkg_config("vips-#{x}") }
|
27
|
+
raise("no pkg_config for any of following libvips versions: #{VIPS_VERSIONS.join(', ')}")
|
28
|
+
end
|
29
|
+
end
|
10
30
|
|
11
31
|
create_makefile('vips_ext')
|
data/ext/header.c
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
#include "ruby_vips.h"
|
2
|
-
#include "image.h"
|
3
|
-
#include "header.h"
|
4
2
|
|
5
3
|
VALUE mVIPSHeader;
|
6
4
|
|
@@ -22,8 +20,8 @@ header_band_fmt_to_id(VipsBandFmt band_fmt)
|
|
22
20
|
case IM_BANDFMT_COMPLEX: return id_complex; // two floats
|
23
21
|
case IM_BANDFMT_DOUBLE: return id_double;
|
24
22
|
case IM_BANDFMT_DPCOMPLEX: return id_dbcomplex; // two doubles
|
23
|
+
default: return id_notset;
|
25
24
|
}
|
26
|
-
return id_notset;
|
27
25
|
}
|
28
26
|
|
29
27
|
VipsBandFmt
|
@@ -399,7 +397,7 @@ header_set(VALUE obj, VALUE name, VALUE value)
|
|
399
397
|
*/
|
400
398
|
|
401
399
|
void
|
402
|
-
init_Header()
|
400
|
+
init_Header( void )
|
403
401
|
{
|
404
402
|
mVIPSHeader = rb_define_module_under(mVIPS, "Header");
|
405
403
|
|
data/ext/header.h
CHANGED
data/ext/image.c
CHANGED
@@ -1,18 +1,4 @@
|
|
1
1
|
#include "ruby_vips.h"
|
2
|
-
#include "header.h"
|
3
|
-
|
4
|
-
#include "image.h"
|
5
|
-
#include "image_arithmetic.h"
|
6
|
-
#include "image_boolean.h"
|
7
|
-
#include "image_colour.h"
|
8
|
-
#include "image_conversion.h"
|
9
|
-
#include "image_convolution.h"
|
10
|
-
#include "image_freq_filt.h"
|
11
|
-
#include "image_histograms_lut.h"
|
12
|
-
#include "image_morphology.h"
|
13
|
-
#include "image_mosaicing.h"
|
14
|
-
#include "image_relational.h"
|
15
|
-
#include "image_resample.h"
|
16
2
|
|
17
3
|
VALUE cVIPSImage;
|
18
4
|
|
@@ -150,8 +136,8 @@ img_vtype_to_id(VipsType vtype)
|
|
150
136
|
case IM_TYPE_YXY: return id_yxy;
|
151
137
|
case IM_TYPE_RGB16: return id_rgb16;
|
152
138
|
case IM_TYPE_GREY16: return id_grey16;
|
139
|
+
default: return id_b_w;
|
153
140
|
}
|
154
|
-
return id_b_w;
|
155
141
|
}
|
156
142
|
|
157
143
|
ID
|
@@ -161,8 +147,8 @@ img_coding_to_id(VipsCoding coding)
|
|
161
147
|
case IM_CODING_NONE: return id_none;
|
162
148
|
case IM_CODING_LABQ: return id_labq;
|
163
149
|
case IM_CODING_RAD: return id_rad;
|
150
|
+
default: return id_none;
|
164
151
|
}
|
165
|
-
return id_none;
|
166
152
|
}
|
167
153
|
|
168
154
|
/*
|
@@ -283,6 +269,8 @@ img_pixel_to_rb(VipsImage *im, int x, int y)
|
|
283
269
|
case IM_BANDFMT_DOUBLE: GETPIX( double, rb_float_new ); break;
|
284
270
|
case IM_BANDFMT_COMPLEX: CGETPIX( float, rb_float_new ); break;
|
285
271
|
case IM_BANDFMT_DPCOMPLEX: CGETPIX( double, rb_float_new ); break;
|
272
|
+
|
273
|
+
default: GETPIX( unsigned char, UINT2NUM ); break;
|
286
274
|
}
|
287
275
|
}
|
288
276
|
|
@@ -356,7 +344,8 @@ img_data(VALUE obj)
|
|
356
344
|
if (im_incheck(im) || im_check_uncoded("img_aref", im))
|
357
345
|
return( Qnil );
|
358
346
|
|
359
|
-
return rb_tainted_str_new(
|
347
|
+
return rb_tainted_str_new((const char *) im->data,
|
348
|
+
IM_IMAGE_SIZEOF_LINE(im) * im->Ysize);
|
360
349
|
}
|
361
350
|
|
362
351
|
/*
|
@@ -565,7 +554,7 @@ init_Image(void)
|
|
565
554
|
rb_define_method(cVIPSImage, "heq", img_heq, -1); // in image_histograms_lut.c
|
566
555
|
rb_define_method(cVIPSImage, "lhisteq", img_lhisteq, 2); // in image_histograms_lut.c
|
567
556
|
rb_define_method(cVIPSImage, "stdif", img_stdif, 6); // in image_histograms_lut.c
|
568
|
-
rb_define_method(cVIPSImage, "
|
557
|
+
rb_define_method(cVIPSImage, "tone_analyse", img_tone_analyse, 6); // in image_histograms_lut.c
|
569
558
|
rb_define_method(cVIPSImage, "maplut", img_maplut, 1); // in image_histograms_lut.c
|
570
559
|
rb_define_method(cVIPSImage, "histplot", img_histplot, 0); // in image_histograms_lut.c
|
571
560
|
rb_define_method(cVIPSImage, "dilate", img_dilate, 1); // in image_morphology.c
|
data/ext/image.h
CHANGED
@@ -21,10 +21,11 @@ VALUE img_init(VALUE, VipsImage*);
|
|
21
21
|
VALUE img_init_partial();
|
22
22
|
VALUE img_init_partial_anyclass(VALUE);
|
23
23
|
VipsBandFmt img_id_to_band_fmt(VALUE);
|
24
|
+
void init_Image(void);
|
24
25
|
|
25
26
|
#define GetImg(obj, data, im) \
|
26
27
|
vipsImg *data; \
|
27
|
-
VipsImage *im; \
|
28
|
+
VipsImage *im __attribute__ ((unused)); \
|
28
29
|
Data_Get_Struct(obj, vipsImg, data); \
|
29
30
|
im = data->in;
|
30
31
|
|
data/ext/image_arithmetic.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
#include "ruby_vips.h"
|
2
|
-
#include "image.h"
|
3
|
-
#include "mask.h"
|
4
|
-
#include "interpolator.h"
|
5
2
|
|
6
3
|
/*
|
7
4
|
* call-seq:
|
@@ -21,7 +18,6 @@ img_measure_area(VALUE obj, VALUE left, VALUE top, VALUE width, VALUE height,
|
|
21
18
|
VALUE h, VALUE v, VALUE sel)
|
22
19
|
{
|
23
20
|
DOUBLEMASK *ret;
|
24
|
-
VALUE results;
|
25
21
|
int *a, i, len = RARRAY_LENINT(sel);
|
26
22
|
GetImg(obj, data, im);
|
27
23
|
|
data/ext/image_arithmetic.h
CHANGED
@@ -25,7 +25,7 @@ VALUE img_ceil(VALUE);
|
|
25
25
|
VALUE img_s_linreg(int, VALUE*, VALUE);
|
26
26
|
VALUE img_point(VALUE, VALUE, VALUE, VALUE, VALUE);
|
27
27
|
VALUE img_pow(int, VALUE*, VALUE);
|
28
|
-
VALUE img_pow_binop(
|
28
|
+
VALUE img_pow_binop(VALUE obj, VALUE arg);
|
29
29
|
VALUE img_expn(int, VALUE*, VALUE);
|
30
30
|
VALUE img_log(VALUE);
|
31
31
|
VALUE img_log10(VALUE);
|
data/ext/image_boolean.c
CHANGED
data/ext/image_boolean.h
CHANGED
@@ -4,5 +4,5 @@ VALUE img_or(int, VALUE*, VALUE);
|
|
4
4
|
VALUE img_or_binop(VALUE, VALUE arg);
|
5
5
|
VALUE img_xor(int, VALUE*, VALUE);
|
6
6
|
VALUE img_xor_binop(VALUE, VALUE arg);
|
7
|
-
VALUE img_shiftleft(
|
8
|
-
VALUE img_shiftright(
|
7
|
+
VALUE img_shiftleft(VALUE obj, VALUE arg);
|
8
|
+
VALUE img_shiftright(VALUE obj, VALUE arg);
|
data/ext/image_colour.c
CHANGED
data/ext/image_conversion.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
#include "ruby_vips.h"
|
2
|
-
#include "image.h"
|
3
|
-
#include "mask.h"
|
4
|
-
#include "header.h"
|
5
2
|
|
6
3
|
static ID id_black, id_extend, id_repeat, id_mirror, id_white;
|
7
4
|
|
@@ -591,8 +588,8 @@ img_insertset(int argc, VALUE *argv, VALUE obj, VALUE obj2)
|
|
591
588
|
y = IM_ARRAY(im_new, argc - 1, int);
|
592
589
|
|
593
590
|
for(i = 1; i < argc; i++) {
|
594
|
-
x[i] = NUM2INT(RARRAY_PTR(argv[i])[0]);
|
595
|
-
y[i] = NUM2INT(RARRAY_PTR(argv[i])[1]);
|
591
|
+
x[i - 1] = NUM2INT(RARRAY_PTR(argv[i])[0]);
|
592
|
+
y[i - 1] = NUM2INT(RARRAY_PTR(argv[i])[1]);
|
596
593
|
}
|
597
594
|
|
598
595
|
if( im_insertset(im, im2, im_new, argc - 1, x, y) )
|
data/ext/image_convolution.c
CHANGED
data/ext/image_freq_filt.c
CHANGED
data/ext/image_histograms_lut.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
#include "ruby_vips.h"
|
2
|
-
#include "image.h"
|
3
|
-
#include "mask.h"
|
4
|
-
#include "image_histograms_lut.h"
|
5
2
|
|
6
3
|
/*
|
7
4
|
* call-seq:
|
@@ -620,21 +617,21 @@ img_s_tone_build(VALUE obj,
|
|
620
617
|
|
621
618
|
/*
|
622
619
|
* call-seq:
|
623
|
-
* im.
|
620
|
+
* im.tone_analyse(ps, pm, ph, s, m, h) -> image
|
624
621
|
*
|
625
622
|
* As Image#tone_build, but analyse the histogram of *self* and use it to pick
|
626
623
|
* the 0.1% and 99.9% points for <i>lb</i> and <i>lw</i>.
|
627
624
|
*/
|
628
625
|
|
629
626
|
VALUE
|
630
|
-
|
627
|
+
img_tone_analyse(VALUE obj,
|
631
628
|
VALUE ps, VALUE pm, VALUE ph, VALUE s, VALUE m, VALUE h)
|
632
629
|
{
|
633
630
|
#if IM_MAJOR_VERSION > 7 || IM_MINOR_VERSION >= 23
|
634
631
|
GetImg(obj, data, im);
|
635
632
|
OutImg(obj, new, data_new, im_new);
|
636
633
|
|
637
|
-
if (
|
634
|
+
if (im_tone_analyse(im, im_new,
|
638
635
|
NUM2DBL(ps), NUM2DBL(pm), NUM2DBL(ph),
|
639
636
|
NUM2DBL(s), NUM2DBL(m), NUM2DBL(h)) )
|
640
637
|
vips_lib_error();
|
data/ext/image_histograms_lut.h
CHANGED
@@ -25,4 +25,4 @@ VALUE img_s_tone_build_range(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE,
|
|
25
25
|
VALUE, VALUE, VALUE, VALUE);
|
26
26
|
VALUE img_s_tone_build(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE,
|
27
27
|
VALUE);
|
28
|
-
VALUE
|
28
|
+
VALUE img_tone_analyse(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
data/ext/image_morphology.c
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
#include "ruby_vips.h"
|
2
|
-
#include "image.h"
|
3
|
-
#include "mask.h"
|
4
|
-
#include "image_morphology.h"
|
5
2
|
|
6
3
|
/*
|
7
4
|
* call-seq:
|
@@ -170,7 +167,7 @@ img_rank_image(int argc, VALUE *argv, VALUE obj)
|
|
170
167
|
VALUE
|
171
168
|
img_maxvalue(int argc, VALUE *argv, VALUE obj)
|
172
169
|
{
|
173
|
-
img_rank_image_internal(argc, argv, obj, argc - 1);
|
170
|
+
return img_rank_image_internal(argc, argv, obj, argc - 1);
|
174
171
|
}
|
175
172
|
|
176
173
|
static VALUE
|