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
@@ -0,0 +1,7 @@
1
+ 0,0,0,255,0,0,0
2
+ 0,0,0,255,0,0,0
3
+ 0,0,0,255,0,0,0
4
+ 0,0,0,255,0,0,0
5
+ 0,255,0,255,0,0,0
6
+ 0,255,0,255,0,0,0
7
+ 0,0,255,255,0,0,0
Binary file
Binary file
Binary file
@@ -0,0 +1,49 @@
1
+ require 'vips'
2
+
3
+ require 'tempfile'
4
+
5
+ module Spec
6
+
7
+ module Path
8
+ def root
9
+ @root ||= Pathname.new(File.expand_path('..', __FILE__))
10
+ end
11
+
12
+ def sample(*path)
13
+ root.join 'samples', *path
14
+ end
15
+
16
+ def tmp(*path)
17
+ root.join 'tmp', 'working', *path
18
+ end
19
+
20
+ extend self
21
+
22
+ end
23
+
24
+ module Helpers
25
+ def reset_working!
26
+ FileUtils.rm Dir[tmp.join('*.*')]
27
+ FileUtils.mkdir_p(tmp)
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ def simg(name)
34
+ Spec::Path::sample(name).to_s
35
+ end
36
+
37
+ def timg(name)
38
+ Spec::Path::tmp(name).to_s
39
+ end
40
+
41
+ RSpec.configure do |config|
42
+ config.include Spec::Path
43
+ config.include Spec::Helpers
44
+
45
+ config.before :each do
46
+ reset_working!
47
+ end
48
+
49
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper.rb'
2
+
3
+ RSpec.describe Vips do
4
+ describe '#call' do
5
+ it 'can make a black image' do
6
+ image = Vips::call "black", 200, 200
7
+
8
+ expect(image.width).to eq(200)
9
+ expect(image.height).to eq(200)
10
+ expect(image.bands).to eq(1)
11
+ end
12
+
13
+ it 'can take an optional argument' do
14
+ image = Vips::call "black", 200, 200, :bands => 12
15
+
16
+ expect(image.width).to eq(200)
17
+ expect(image.height).to eq(200)
18
+ expect(image.bands).to eq(12)
19
+ end
20
+
21
+ it 'can take an optional argument' do
22
+ image = Vips::call "black", 200, 200, :bands => 12
23
+
24
+ expect(image.width).to eq(200)
25
+ expect(image.height).to eq(200)
26
+ expect(image.bands).to eq(12)
27
+ end
28
+
29
+ it 'can handle enum arguments' do
30
+ black = Vips::call "black", 200, 200
31
+ embed = Vips::call "embed", black, 10, 10, 500, 500,
32
+ :extend => :mirror
33
+
34
+ expect(embed.width).to eq(500)
35
+ expect(embed.height).to eq(500)
36
+ expect(embed.bands).to eq(1)
37
+ end
38
+
39
+ it 'enum arguments can be strings' do
40
+ black = Vips::call "black", 200, 200
41
+ embed = Vips::call "embed", black, 10, 10, 500, 500,
42
+ :extend => "mirror"
43
+
44
+ expect(embed.width).to eq(500)
45
+ expect(embed.height).to eq(500)
46
+ expect(embed.bands).to eq(1)
47
+ end
48
+
49
+ it 'can return optional output args' do
50
+ point = Vips::call "black", 1, 1
51
+ test = Vips::call "embed", point, 20, 10, 100, 100,
52
+ :extend => :white
53
+ value, opts = Vips::call "min", test, :x => true, :y => true
54
+
55
+ expect(value).to eq(0)
56
+ expect(opts['x']).to eq(20)
57
+ expect(opts['y']).to eq(10)
58
+ end
59
+
60
+ it 'can call draw operations' do
61
+ black = Vips::call "black", 100, 100
62
+ test = Vips::call "draw_rect", black, 255, 10, 10, 1, 1
63
+
64
+ max_black = Vips::call "max", black
65
+ max_test = Vips::call "max", test
66
+
67
+ expect(max_black).to eq(0)
68
+ expect(max_test).to eq(255)
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
metadata CHANGED
@@ -1,140 +1,181 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-vips
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Timothy Elliott
8
7
  - John Cupitt
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2016-01-25 00:00:00.000000000 Z
11
+ date: 2016-06-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: rdoc
14
+ name: gobject-introspection
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
17
  - - "~>"
19
18
  - !ruby/object:Gem::Version
20
- version: '3.12'
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.3'
21
34
  type: :development
22
35
  prerelease: false
23
36
  version_requirements: !ruby/object:Gem::Requirement
24
37
  requirements:
25
38
  - - "~>"
26
39
  - !ruby/object:Gem::Version
27
- version: '3.12'
40
+ version: '3.3'
28
41
  - !ruby/object:Gem::Dependency
29
- name: bundler
42
+ name: yard
30
43
  requirement: !ruby/object:Gem::Requirement
31
44
  requirements:
32
45
  - - "~>"
33
46
  - !ruby/object:Gem::Version
34
- version: '1.0'
47
+ version: '0.8'
35
48
  type: :development
36
49
  prerelease: false
37
50
  version_requirements: !ruby/object:Gem::Requirement
38
51
  requirements:
39
52
  - - "~>"
40
53
  - !ruby/object:Gem::Version
41
- version: '1.0'
54
+ version: '0.8'
42
55
  - !ruby/object:Gem::Dependency
43
- name: jeweler
56
+ name: redcarpet
44
57
  requirement: !ruby/object:Gem::Requirement
45
58
  requirements:
46
59
  - - "~>"
47
60
  - !ruby/object:Gem::Version
48
- version: '1.8'
61
+ version: '3.3'
49
62
  type: :development
50
63
  prerelease: false
51
64
  version_requirements: !ruby/object:Gem::Requirement
52
65
  requirements:
53
66
  - - "~>"
54
67
  - !ruby/object:Gem::Version
55
- version: '1.8'
68
+ version: '3.3'
56
69
  - !ruby/object:Gem::Dependency
57
- name: rspec
70
+ name: github-markup
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jeweler
58
99
  requirement: !ruby/object:Gem::Requirement
59
100
  requirements:
60
101
  - - "~>"
61
102
  - !ruby/object:Gem::Version
62
- version: '3.4'
103
+ version: '2.0'
63
104
  type: :development
64
105
  prerelease: false
65
106
  version_requirements: !ruby/object:Gem::Requirement
66
107
  requirements:
67
108
  - - "~>"
68
109
  - !ruby/object:Gem::Version
69
- version: '3.4'
70
- description: Ruby extension for the vips image processing library.
110
+ version: '2.0'
111
+ description: ruby-vips is a ruby extension for vips. It is extremely fast and it can
112
+ process huge images without requiring the entire image to be loaded into memory.
71
113
  email: jcupitt@gmail.com
72
114
  executables: []
73
- extensions:
74
- - ext/extconf.rb
115
+ extensions: []
75
116
  extra_rdoc_files:
76
- - LICENSE
117
+ - LICENSE.txt
77
118
  - README.md
78
119
  - TODO
79
120
  files:
121
+ - ".travis.yml"
80
122
  - CHANGELOG.md
123
+ - Gemfile
81
124
  - Gemfile.lock
82
- - LICENSE
125
+ - LICENSE.txt
83
126
  - README.md
127
+ - Rakefile
84
128
  - TODO
85
- - ext/extconf.rb
86
- - ext/header.c
87
- - ext/header.h
88
- - ext/image.c
89
- - ext/image.h
90
- - ext/image_arithmetic.c
91
- - ext/image_arithmetic.h
92
- - ext/image_boolean.c
93
- - ext/image_boolean.h
94
- - ext/image_colour.c
95
- - ext/image_colour.h
96
- - ext/image_conversion.c
97
- - ext/image_conversion.h
98
- - ext/image_convolution.c
99
- - ext/image_convolution.h
100
- - ext/image_freq_filt.c
101
- - ext/image_freq_filt.h
102
- - ext/image_histograms_lut.c
103
- - ext/image_histograms_lut.h
104
- - ext/image_morphology.c
105
- - ext/image_morphology.h
106
- - ext/image_mosaicing.c
107
- - ext/image_mosaicing.h
108
- - ext/image_relational.c
109
- - ext/image_relational.h
110
- - ext/image_resample.c
111
- - ext/image_resample.h
112
- - ext/interpolator.c
113
- - ext/interpolator.h
114
- - ext/mask.c
115
- - ext/mask.h
116
- - ext/reader.c
117
- - ext/reader.h
118
- - ext/ruby_vips.c
119
- - ext/ruby_vips.h
120
- - ext/tags
121
- - ext/writer.c
122
- - ext/writer.h
129
+ - VERSION
130
+ - example/annotate.rb
131
+ - example/daltonize8.rb
132
+ - example/example1.rb
133
+ - example/example2.rb
134
+ - example/example3.rb
135
+ - example/example4.rb
136
+ - example/example5.rb
137
+ - example/trim8.rb
138
+ - example/watermark.rb
139
+ - example/wobble.rb
123
140
  - lib/vips.rb
124
- - lib/vips/reader.rb
125
- - lib/vips/version.rb
126
- - lib/vips/writer.rb
127
- - ruby-vips.gemspec
128
- - ruby.supp
141
+ - lib/vips/access.rb
142
+ - lib/vips/align.rb
143
+ - lib/vips/angle.rb
144
+ - lib/vips/angle45.rb
145
+ - lib/vips/argument.rb
146
+ - lib/vips/bandformat.rb
147
+ - lib/vips/call.rb
148
+ - lib/vips/coding.rb
149
+ - lib/vips/demandstyle.rb
150
+ - lib/vips/direction.rb
151
+ - lib/vips/error.rb
152
+ - lib/vips/extend.rb
153
+ - lib/vips/foreignflags.rb
154
+ - lib/vips/image.rb
155
+ - lib/vips/interpolate.rb
156
+ - lib/vips/interpretation.rb
157
+ - lib/vips/methods.rb
158
+ - lib/vips/operation.rb
159
+ - ruby-vips8.gemspec
160
+ - spec/image_spec.rb
161
+ - spec/samples/balloon.v
162
+ - spec/samples/ghost.ppm
163
+ - spec/samples/huge.jpg
164
+ - spec/samples/icc.jpg
165
+ - spec/samples/lcd.icc
166
+ - spec/samples/lion.svg
167
+ - spec/samples/sample.csv
168
+ - spec/samples/sample.exr
169
+ - spec/samples/wagon.jpg
170
+ - spec/samples/wagon.v
171
+ - spec/spec_helper.rb
172
+ - spec/vips_spec.rb
129
173
  homepage: http://github.com/jcupitt/ruby-vips
130
174
  licenses:
131
175
  - MIT
132
176
  metadata: {}
133
177
  post_install_message:
134
- rdoc_options:
135
- - "--title"
136
- - 'ruby-vips #{version}'
137
- - ext
178
+ rdoc_options: []
138
179
  require_paths:
139
180
  - lib
140
181
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -149,9 +190,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
190
  version: '0'
150
191
  requirements: []
151
192
  rubyforge_project:
152
- rubygems_version: 2.2.2
193
+ rubygems_version: 2.5.1
153
194
  signing_key:
154
195
  specification_version: 4
155
- summary: ruby-vips is a ruby extension for vips. It is extremely fast and it can process
156
- huge images without requiring the entire image to be loaded into memory.
196
+ summary: Ruby extension for the vips image processing library.
157
197
  test_files: []
@@ -1,31 +0,0 @@
1
- ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
2
-
3
- require "mkmf"
4
-
5
- File::unlink("Makefile") if (File::exist?("Makefile"))
6
-
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
20
-
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
30
-
31
- create_makefile('vips_ext')
@@ -1,457 +0,0 @@
1
- #include "ruby_vips.h"
2
-
3
- VALUE mVIPSHeader;
4
-
5
- static ID id_notset, id_uchar, id_char, id_ushort, id_short, id_uint, id_int,
6
- id_float, id_complex, id_double, id_dbcomplex;
7
-
8
- ID
9
- header_band_fmt_to_id(VipsBandFmt band_fmt)
10
- {
11
- switch(band_fmt) {
12
- case IM_BANDFMT_NOTSET: return id_notset;
13
- case IM_BANDFMT_UCHAR: return id_uchar;
14
- case IM_BANDFMT_CHAR: return id_char;
15
- case IM_BANDFMT_USHORT: return id_ushort;
16
- case IM_BANDFMT_SHORT: return id_short;
17
- case IM_BANDFMT_UINT: return id_uint;
18
- case IM_BANDFMT_INT: return id_int;
19
- case IM_BANDFMT_FLOAT: return id_float;
20
- case IM_BANDFMT_COMPLEX: return id_complex; // two floats
21
- case IM_BANDFMT_DOUBLE: return id_double;
22
- case IM_BANDFMT_DPCOMPLEX: return id_dbcomplex; // two doubles
23
- default: return id_notset;
24
- }
25
- }
26
-
27
- VipsBandFmt
28
- header_id_to_band_fmt(ID rb)
29
- {
30
- if(rb == id_notset) return IM_BANDFMT_NOTSET;
31
- else if(rb == id_uchar) return IM_BANDFMT_UCHAR;
32
- else if(rb == id_char) return IM_BANDFMT_CHAR;
33
- else if(rb == id_ushort) return IM_BANDFMT_USHORT;
34
- else if(rb == id_short) return IM_BANDFMT_SHORT;
35
- else if(rb == id_uint) return IM_BANDFMT_UINT;
36
- else if(rb == id_int) return IM_BANDFMT_INT;
37
- else if(rb == id_float) return IM_BANDFMT_FLOAT;
38
- else if(rb == id_complex) return IM_BANDFMT_COMPLEX;
39
- else if(rb == id_double) return IM_BANDFMT_DOUBLE;
40
- else if(rb == id_dbcomplex) return IM_BANDFMT_DPCOMPLEX;
41
-
42
- return (VipsBandFmt)NULL;
43
- }
44
-
45
- /*
46
- * call-seq:
47
- * im.x_size -> number
48
- *
49
- * Get the width in pixels of the image.
50
- */
51
-
52
- static VALUE
53
- header_x_size(VALUE obj)
54
- {
55
- GetImg(obj, data, im);
56
-
57
- if (im)
58
- return INT2FIX(im->Xsize);
59
-
60
- return Qnil;
61
- }
62
-
63
- /*
64
- * call-seq:
65
- * im.y_size -> number
66
- *
67
- * Get the height in pixels of the image.
68
- */
69
-
70
- static VALUE
71
- header_y_size(VALUE obj)
72
- {
73
- GetImg(obj, data, im);
74
-
75
- if (im)
76
- return INT2FIX(im->Ysize);
77
-
78
- return Qnil;
79
- }
80
-
81
- /*
82
- * call-seq:
83
- * im.size -> [width, height]
84
- *
85
- * Get the size of the image in pixels.
86
- */
87
-
88
- static VALUE
89
- header_size(VALUE obj)
90
- {
91
- GetImg(obj, data, im);
92
-
93
- if (im)
94
- return rb_ary_new3(2, INT2FIX(im->Xsize), INT2FIX(im->Ysize));
95
-
96
- return Qnil;
97
- }
98
-
99
- /*
100
- * call-seq:
101
- * im.bands -> number
102
- *
103
- * Get the number of bands in the image.
104
- */
105
-
106
- static VALUE
107
- header_bands(VALUE obj)
108
- {
109
- GetImg(obj, data, im);
110
-
111
- if (im)
112
- return INT2FIX(im->Bands);
113
-
114
- return Qnil;
115
- }
116
-
117
- /*
118
- * call-seq:
119
- * im.band_fmt -> band_format_sym
120
- *
121
- * Get the band format of the image.
122
- */
123
-
124
- static VALUE
125
- header_band_fmt(VALUE obj)
126
- {
127
- GetImg(obj, data, im);
128
-
129
- if (im)
130
- return ID2SYM(header_band_fmt_to_id(im->BandFmt));
131
-
132
- return Qnil;
133
- }
134
-
135
- /*
136
- * call-seq:
137
- * im.x_res -> number
138
- *
139
- * Get the x-resolution of the image.
140
- */
141
-
142
- static VALUE
143
- header_x_res(VALUE obj)
144
- {
145
- GetImg(obj, data, im);
146
-
147
- if (im)
148
- return rb_float_new(im->Xres);
149
-
150
- return Qnil;
151
- }
152
-
153
- /*
154
- * call-seq:
155
- * im.y_res -> number
156
- *
157
- * Get the y-resolution of the image.
158
- */
159
-
160
- static VALUE
161
- header_y_res(VALUE obj)
162
- {
163
- GetImg(obj, data, im);
164
-
165
- if (im)
166
- return rb_float_new(im->Yres);
167
-
168
- return Qnil;
169
- }
170
-
171
- /*
172
- * call-seq:
173
- * im.x_offset -> number
174
- *
175
- * Get the x-offset of the image.
176
- */
177
-
178
- static VALUE
179
- header_x_offset(VALUE obj)
180
- {
181
- GetImg(obj, data, im);
182
-
183
- if (im)
184
- return INT2FIX(im->Xoffset);
185
-
186
- return Qnil;
187
- }
188
-
189
- /*
190
- * call-seq:
191
- * im.y_offset -> number
192
- *
193
- * Get the y-offset of the image.
194
- */
195
-
196
- static VALUE
197
- header_y_offset(VALUE obj)
198
- {
199
- GetImg(obj, data, im);
200
-
201
- if (im)
202
- return INT2FIX(im->Yoffset);
203
-
204
- return Qnil;
205
- }
206
-
207
- /* VipsImage macros with useful information */
208
-
209
- /*
210
- * call-seq:
211
- * im.sizeof_element -> number
212
- *
213
- * Returns the size of a single image band item, in bytes.
214
- */
215
-
216
- static VALUE
217
- header_sizeof_element(VALUE obj)
218
- {
219
- GetImg(obj, data, im);
220
-
221
- if (im)
222
- return INT2FIX(IM_IMAGE_SIZEOF_ELEMENT(im));
223
-
224
- return Qnil;
225
- }
226
-
227
- /*
228
- * call-seq:
229
- * im.sizeof_pel -> number
230
- *
231
- * Returns the size of a pixel in the image, in bytes.
232
- */
233
-
234
- static VALUE
235
- header_sizeof_pel(VALUE obj)
236
- {
237
- GetImg(obj, data, im);
238
-
239
- if (im)
240
- return INT2FIX(IM_IMAGE_SIZEOF_PEL(im));
241
-
242
- return Qnil;
243
- }
244
-
245
- /*
246
- * call-seq:
247
- * im.sizeof_line -> number
248
- *
249
- * Returns the size of all pixels in the row of the image, uncompressed, in
250
- * bytes.
251
- */
252
-
253
- static VALUE
254
- header_sizeof_line(VALUE obj)
255
- {
256
- GetImg(obj, data, im);
257
-
258
- if (im)
259
- return INT2FIX(IM_IMAGE_SIZEOF_LINE(im));
260
-
261
- return Qnil;
262
- }
263
-
264
- /*
265
- * call-seq:
266
- * im.n_elements -> number
267
- *
268
- * Returns the number of elements in an image row, i.e. bands * x_size.
269
- */
270
-
271
- static VALUE
272
- header_n_elements(VALUE obj)
273
- {
274
- GetImg(obj, data, im);
275
-
276
- if (im)
277
- return INT2FIX(IM_IMAGE_N_ELEMENTS(im));
278
-
279
- return Qnil;
280
- }
281
-
282
- static VALUE
283
- header_meta_get(VALUE obj, const char* name)
284
- {
285
- GetImg(obj, data, im);
286
-
287
- void *buf;
288
- size_t len;
289
-
290
- if (im_meta_get_blob(im, name, &buf, &len))
291
- return Qnil;
292
-
293
- return rb_tainted_str_new((char *)buf, len);
294
- }
295
-
296
- static VALUE
297
- header_meta_get_string(VALUE obj, const char* name)
298
- {
299
- GetImg(obj, data, im);
300
-
301
- char *str;
302
- VALUE result;
303
-
304
- if (vips_image_get_as_string(im, name, &str))
305
- vips_lib_error();
306
- result = rb_tainted_str_new(str, strlen(str));
307
- g_free(str);
308
-
309
- return result;
310
- }
311
-
312
- static void
313
- header_meta_set_string(VALUE obj, const char* name, const char* value)
314
- {
315
- GetImg(obj, data, im);
316
-
317
- vips_image_set_string(im, name, value);
318
- }
319
-
320
- static VALUE
321
- header_meta_p(VALUE obj, const char* name)
322
- {
323
- GetImg(obj, data, im);
324
-
325
- if (im_header_get_typeof(im, name))
326
- return Qtrue;
327
-
328
- return Qfalse;
329
- }
330
-
331
- /*
332
- * call-seq:
333
- * im.exif -> string
334
- *
335
- * Returns a binary string containing the raw exif header data.
336
- */
337
-
338
- static VALUE
339
- header_exif(VALUE obj)
340
- {
341
- return header_meta_get(obj, IM_META_EXIF_NAME);
342
- }
343
-
344
- /*
345
- * call-seq:
346
- * im.exif? -> true or false
347
- *
348
- * Indicates whether the image has an exif header attached to it.
349
- */
350
-
351
- static VALUE
352
- header_exif_p(VALUE obj)
353
- {
354
- return header_meta_p(obj, IM_META_EXIF_NAME);
355
- }
356
-
357
- /*
358
- * call-seq:
359
- * im.icc -> string
360
- *
361
- * Returns a binary string containing the raw icc header data.
362
- */
363
-
364
- static VALUE
365
- header_icc(VALUE obj)
366
- {
367
- return header_meta_get(obj, IM_META_ICC_NAME);
368
- }
369
-
370
- /*
371
- * call-seq:
372
- * im.icc? -> true or false
373
- *
374
- * Indicates whether the image has an icc header attached to it.
375
- */
376
-
377
- static VALUE
378
- header_icc_p(VALUE obj)
379
- {
380
- return header_meta_p(obj, IM_META_ICC_NAME);
381
- }
382
-
383
- /*
384
- * call-seq:
385
- * im.get(name) -> string
386
- *
387
- * Return metadata item 'name' as a string.
388
- */
389
-
390
- static VALUE
391
- header_get(VALUE obj, VALUE name)
392
- {
393
- return header_meta_get_string(obj, StringValuePtr(name));
394
- }
395
-
396
- /*
397
- * call-seq:
398
- * im.set(name, value)
399
- *
400
- * Set metadata item 'name' to value.
401
- */
402
-
403
- static VALUE
404
- header_set(VALUE obj, VALUE name, VALUE value)
405
- {
406
- header_meta_set_string(obj,
407
- StringValuePtr(name), StringValuePtr(value));
408
-
409
- return Qnil;
410
- }
411
-
412
- /*
413
- * The header module holds image header operations that are common to readers,
414
- * writers and image objects.
415
- */
416
-
417
- void
418
- init_Header( void )
419
- {
420
- mVIPSHeader = rb_define_module_under(mVIPS, "Header");
421
-
422
- rb_define_method(mVIPSHeader, "x_size", header_x_size, 0);
423
- rb_define_method(mVIPSHeader, "y_size", header_y_size, 0);
424
- rb_define_method(mVIPSHeader, "size", header_size, 0);
425
- rb_define_method(mVIPSHeader, "bands", header_bands, 0);
426
- rb_define_method(mVIPSHeader, "band_fmt", header_band_fmt, 0);
427
- rb_define_method(mVIPSHeader, "x_res", header_x_res, 0);
428
- rb_define_method(mVIPSHeader, "y_res", header_y_res, 0);
429
- rb_define_method(mVIPSHeader, "x_offset", header_x_offset, 0);
430
- rb_define_method(mVIPSHeader, "y_offset", header_y_offset, 0);
431
- rb_define_method(mVIPSHeader, "sizeof_element", header_sizeof_element, 0);
432
- rb_define_method(mVIPSHeader, "sizeof_pel", header_sizeof_pel, 0);
433
- rb_define_method(mVIPSHeader, "sizeof_line", header_sizeof_line, 0);
434
- rb_define_method(mVIPSHeader, "n_elements", header_n_elements, 0);
435
- rb_define_method(mVIPSHeader, "exif", header_exif, 0);
436
- rb_define_method(mVIPSHeader, "exif?", header_exif_p, 0);
437
- rb_define_method(mVIPSHeader, "icc", header_icc, 0);
438
- rb_define_method(mVIPSHeader, "icc?", header_icc_p, 0);
439
- rb_define_method(mVIPSHeader, "get", header_get, 1);
440
- rb_define_method(mVIPSHeader, "set", header_set, 2);
441
-
442
- id_notset = rb_intern("NOTSET");
443
- id_uchar = rb_intern("UCHAR");
444
- id_char = rb_intern("CHAR");
445
- id_ushort = rb_intern("USHORT");
446
- id_short = rb_intern("SHORT");
447
- id_uint = rb_intern("UINT");
448
- id_int = rb_intern("INT");
449
- id_float = rb_intern("FLOAT");
450
- id_complex = rb_intern("COMPLEX");
451
- id_double = rb_intern("DOUBLE");
452
- id_dbcomplex = rb_intern("DBCOMPLEX");
453
-
454
- #if 0
455
- VALUE mVIPS = rb_define_module("VIPS");
456
- #endif
457
- }