devil 0.1.7-x86-mswin32-60 → 0.1.8-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
data/ext/devil/ruby_ilu.c CHANGED
@@ -103,17 +103,66 @@ static VALUE ilu_Rotate(VALUE obj, VALUE rb_angle) {
103
103
  return flag ? Qtrue : Qfalse;
104
104
  }
105
105
 
106
- static VALUE ilu_Crop(VALUE obj, VALUE rb_XOff, VALUE rb_YOff, VALUE rb_width, VALUE rb_height)
106
+ static VALUE ilu_Crop(VALUE obj, VALUE rb_XOff, VALUE rb_YOff, VALUE rb_ZOff, VALUE rb_width, VALUE rb_height, VALUE rb_depth)
107
107
  {
108
108
  ILuint XOff = NUM2INT(rb_XOff);
109
109
  ILuint YOff = NUM2INT(rb_YOff);
110
+ ILuint ZOff = NUM2INT(rb_ZOff);
110
111
  ILuint width = NUM2INT(rb_width);
111
112
  ILuint height = NUM2INT(rb_height);
113
+ ILuint depth = NUM2INT(rb_depth);
112
114
 
113
- ILboolean flag = iluCrop(XOff, YOff, 1, width, height, 1);
115
+ ILboolean flag = iluCrop(XOff, YOff, ZOff, width, height, depth);
114
116
 
115
117
  return flag ? Qtrue : Qfalse;
116
118
  }
119
+
120
+ static VALUE ilu_EnlargeCanvas(VALUE obj, VALUE rb_width, VALUE rb_height, VALUE rb_depth)
121
+ {
122
+ ILuint width = NUM2INT(rb_width);
123
+ ILuint height = NUM2INT(rb_height);
124
+ ILuint depth = NUM2INT(rb_depth);
125
+
126
+ ILboolean flag = iluEnlargeCanvas(width, height, depth);
127
+
128
+ return flag ? Qtrue : Qfalse;
129
+ }
130
+
131
+ static VALUE ilu_EdgeDetectP(VALUE obj)
132
+ {
133
+ ILboolean flag = iluEdgeDetectP();
134
+
135
+ return flag ? Qtrue : Qfalse;
136
+ }
137
+
138
+ static VALUE ilu_EdgeDetectS(VALUE obj)
139
+ {
140
+ ILboolean flag = iluEdgeDetectS();
141
+
142
+ return flag ? Qtrue : Qfalse;
143
+ }
144
+
145
+ static VALUE ilu_Emboss(VALUE obj)
146
+ {
147
+ ILboolean flag = iluEmboss();
148
+
149
+ return flag ? Qtrue : Qfalse;
150
+ }
151
+
152
+ static VALUE ilu_Mirror(VALUE obj)
153
+ {
154
+ ILboolean flag = iluMirror();
155
+
156
+ return flag ? Qtrue : Qfalse;
157
+ }
158
+
159
+ static VALUE ilu_SwapColours(VALUE obj)
160
+ {
161
+ ILboolean flag = iluSwapColours();
162
+
163
+ return flag ? Qtrue : Qfalse;
164
+ }
165
+
117
166
  /* end of functions added by banisterfiend */
118
167
 
119
168
  void
@@ -138,9 +187,16 @@ InitializeILU() {
138
187
  /* methods added by banisterfiend */
139
188
  rb_define_module_function(mILU, "FlipImage", ilu_FlipImage, 0);
140
189
  rb_define_module_function(mILU, "Rotate", ilu_Rotate, 1);
141
- rb_define_module_function(mILU, "Crop", ilu_Crop, 4);
190
+ rb_define_module_function(mILU, "Crop", ilu_Crop, 6);
191
+ rb_define_module_function(mILU, "EnlargeCanvas", ilu_EnlargeCanvas, 3);
192
+ rb_define_module_function(mILU, "EdgeDetectP", ilu_EdgeDetectP, 0);
193
+ rb_define_module_function(mILU, "EdgeDetectS", ilu_EdgeDetectS, 0);
194
+ rb_define_module_function(mILU, "Emboss", ilu_Emboss, 0);
195
+ rb_define_module_function(mILU, "Mirror", ilu_Mirror, 0);
196
+ rb_define_module_function(mILU, "SwapColours", ilu_SwapColours, 0);
142
197
  /* end of functions added by banisterfiend */
143
198
 
199
+ /* constants added by banisterfiend */
144
200
  rb_define_const(mILU, "FILTER", INT2NUM(ILU_FILTER));
145
201
  rb_define_const(mILU, "NEAREST", INT2NUM(ILU_NEAREST));
146
202
  rb_define_const(mILU, "LINEAR", INT2NUM(ILU_LINEAR));
@@ -151,4 +207,13 @@ InitializeILU() {
151
207
  rb_define_const(mILU, "SCALE_BSPLINE", INT2NUM(ILU_SCALE_BSPLINE));
152
208
  rb_define_const(mILU, "SCALE_LANCZOS3", INT2NUM(ILU_SCALE_LANCZOS3));
153
209
  rb_define_const(mILU, "SCALE_MITCHELL", INT2NUM(ILU_SCALE_MITCHELL));
210
+
211
+ rb_define_const(mILU, "PLACEMENT", INT2NUM(ILU_PLACEMENT));
212
+ rb_define_const(mILU, "UPPER_LEFT", INT2NUM(ILU_UPPER_LEFT));
213
+ rb_define_const(mILU, "LOWER_LEFT", INT2NUM(ILU_LOWER_LEFT));
214
+ rb_define_const(mILU, "LOWER_RIGHT", INT2NUM(ILU_LOWER_RIGHT));
215
+ rb_define_const(mILU, "UPPER_RIGHT", INT2NUM(ILU_UPPER_RIGHT));
216
+ rb_define_const(mILU, "CENTER", INT2NUM(ILU_CENTER));
217
+ /* end of constants added by banisterfiend */
218
+
154
219
  }
data/lib/1.8/devil.so CHANGED
Binary file
data/lib/1.9/devil.so CHANGED
Binary file
data/lib/devil.rb CHANGED
@@ -1,235 +1,371 @@
1
- require 'rbconfig'
2
-
3
- direc = File.dirname(__FILE__)
4
- dlext = Config::CONFIG['DLEXT']
5
- begin
6
- if RUBY_VERSION && RUBY_VERSION =~ /1.9/
7
- require "#{direc}/1.9/devil.#{dlext}"
8
- else
9
- require "#{direc}/1.8/devil.#{dlext}"
10
- end
11
- rescue LoadError => e
12
- require "#{direc}/devil.#{dlext}"
13
- end
14
-
15
- # Provides a high level wrapper for the low-level DevIL Ruby bindings
16
- module Devil
17
- VERSION = '0.1.7'
18
-
19
- class << self
20
-
21
- # loads +file+ and returns a new image
22
- # Optionally accepts a block and yields the newly created image to the block.
23
- def load_image(file, &block)
24
- name = IL.GenImages(1).first
25
- IL.BindImage(name)
26
- IL.LoadImage(file)
27
-
28
- if (error_code = IL.GetError) != IL::NO_ERROR
29
- raise RuntimeError, "an error occured while trying to "+
30
- "load the image #{file}. Error code: #{error_code}"
31
- end
32
-
33
- img = Image.new(name, file)
34
- if block
35
- block.call(img)
36
- end
37
-
38
- img
39
- end
40
-
41
- alias_method :with_image, :load_image
42
- alias_method :load, :load_image
43
-
44
- # convert an image +blob+ with +width+ and +height+
45
- # to a bona fide image
46
- def from_blob(blob, width, height)
47
- Image.new(IL.FromBlob(blob, width, height), nil)
48
- end
49
-
50
- # initializes Devil and sets defaults
51
- # This method should never need to be called directly.
52
- def init
53
- # initialize DevIL
54
- IL.Init
55
-
56
- # default options
57
- IL.Enable(IL::FILE_OVERWRITE)
58
- ILU.ImageParameter(ILU::FILTER, ILU::BILINEAR)
59
- end
60
-
61
- end
62
-
63
- class Image
64
- attr_reader :name, :file
65
-
66
- def initialize(name, file)
67
- @name = name
68
- @file = file
69
-
70
- ObjectSpace.define_finalizer( self, proc { IL.DeleteImages(1, [name]) } )
71
- end
72
-
73
- # returns the width of the image
74
- def width
75
- set_binding
76
- IL.GetInteger(IL::IMAGE_WIDTH)
77
- end
78
-
79
- alias_method :columns, :width
80
-
81
- # returns the height of the image
82
- def height
83
- set_binding
84
- IL.GetInteger(IL::IMAGE_HEIGHT)
85
- end
86
-
87
- alias_method :rows, :height
88
-
89
- # saves the image to +file+. If no +file+ is provided default to the opened file.
90
- def save(file = @file)
91
- set_binding
92
- IL.SaveImage(file)
93
- self
94
- end
95
-
96
- # resize the image to +width+ and +height+. Aspect ratios of the image do not have to be the same.
97
- def resize(width, height)
98
- set_binding
99
- ILU.Scale(width, height, 1)
100
- self
101
- end
102
-
103
- # Creates a proportional thumbnail of the image scaled so its longest
104
- # edge is resized to +size+
105
- def thumbnail(size)
106
- # this thumbnail code from image_science.rb
107
-
108
- w, h = width, height
109
- scale = size.to_f / (w > h ? w : h)
110
- resize((w * scale).to_i, (h * scale).to_i)
111
- self
112
- end
113
-
114
- # return a deep copy of the current image
115
- def dup
116
- set_binding
117
- Image.new(IL.CloneCurImage, nil)
118
- end
119
-
120
- alias_method :clone, :dup
121
-
122
- # crop the current image
123
- # +xoff+ number of pixels to skip in x direction
124
- # +yoff+ number of pixels to skip in y direction
125
- # +width+ number of pixels to preserve in x direction
126
- # +height+ number of pixels to preserve in y direction
127
- def crop(xoff, yoff, width, height)
128
- set_binding
129
- ILU.Crop(xoff, yoff, width, height)
130
- self
131
- end
132
-
133
- # performs a gaussian blur on the image. The blur is performed +iter+ times.
134
- def blur(iter)
135
- set_binding
136
- ILU.BlurGaussian(iter)
137
- self
138
- end
139
-
140
- # 'pixelize' the image using a pixel size of +pixel_size+
141
- def pixelize(pixel_size)
142
- set_binding
143
- ILU.Pixelize(pixel_size)
144
- self
145
- end
146
-
147
- # add random noise to the image. +factor+ is the tolerance to use.
148
- # accepeted values range from 0.0 - 1.0
149
- def noisify(factor)
150
- set_binding
151
- ILU.Noisify(factor)
152
- self
153
- end
154
-
155
- # The sharpening +factor+ must be in the range of 0.0 - 2.5. A value of 1.0 for the sharpening
156
- # factor will have no effect on the image. Values in the range 1.0 - 2.5 will sharpen the
157
- # image, with 2.5 having the most pronounced sharpening effect. Values from 0.0 to 1.0 do
158
- # a type of reverse sharpening, blurring the image. Values outside of the 0.0 - 2.5 range
159
- # produce undefined results.
160
- #
161
- # The number of +iter+ (iterations) to perform will usually be 1, but to achieve more sharpening,
162
- # increase the number of iterations.
163
- def sharpen(factor, iter)
164
- set_binding
165
- ILU.Sharpen(factor, iter)
166
- self
167
- end
168
-
169
- # applies gamma correction to an image using an exponential curve.
170
- # +factor+ is gamma correction factor to use.
171
- # A value of 1.0 leaves the image unmodified.
172
- # Values in the range 0.0 - 1.0 darken the image
173
- # Values above 1.0 brighten the image.
174
- def gamma_correct(factor)
175
- set_binding
176
- ILU.GammaCorrect(factor)
177
- self
178
- end
179
-
180
- # invert the color of every pixel in the image.
181
- def negative
182
- set_binding
183
- ILU.Negative
184
- self
185
- end
186
-
187
- # +factor+ describes desired contrast to use
188
- # A value of 1.0 has no effect on the image.
189
- # Values between 1.0 and 1.7 increase the amount of contrast (values above 1.7 have no effect)
190
- # Valid range of +factor+ is 0.0 - 1.7
191
- def contrast(factor)
192
- set_binding
193
- ILU.Contrast(factor)
194
- self
195
- end
196
-
197
- # darkens the bright colours and lightens the dark
198
- # colours, reducing the contrast in an image or 'equalizing' it.
199
- def equalize
200
- set_binding
201
- ILU.Equalize
202
- self
203
- end
204
-
205
- # returns the image data in the form of a ruby string
206
- # The image data is formatted to RGBA / UNSIGNED BYTE
207
- def to_blob
208
- set_binding
209
- IL.ToBlob
210
- end
211
-
212
- # flip the image about its x axis
213
- def flip
214
- set_binding
215
- ILU.FlipImage
216
- self
217
- end
218
-
219
- # rotate an image about its central point by +angle+ degrees
220
- def rotate(angle)
221
- set_binding
222
- ILU.Rotate(angle)
223
- self
224
- end
225
-
226
- private
227
-
228
- def set_binding
229
- IL.BindImage(@name)
230
- end
231
-
232
- end
233
- end
234
-
235
- Devil.init
1
+ # (C) John Mair 2009, under the MIT licence
2
+
3
+ require 'rbconfig'
4
+
5
+ direc = File.dirname(__FILE__)
6
+ dlext = Config::CONFIG['DLEXT']
7
+ begin
8
+ if RUBY_VERSION && RUBY_VERSION =~ /1.9/
9
+ require "#{direc}/1.9/devil.#{dlext}"
10
+ else
11
+ require "#{direc}/1.8/devil.#{dlext}"
12
+ end
13
+ rescue LoadError => e
14
+ require "#{direc}/devil.#{dlext}"
15
+ end
16
+
17
+ # Provides a high level wrapper for the low-level DevIL Ruby bindings
18
+ module Devil
19
+ include IL
20
+ include ILU
21
+
22
+ VERSION = '0.1.8'
23
+
24
+ class << self
25
+
26
+ # loads +file+ and returns a new image
27
+ # Optionally accepts a block and yields the newly created image to the block.
28
+ def load_image(file, &block)
29
+ name = IL.GenImages(1).first
30
+ IL.BindImage(name)
31
+ IL.LoadImage(file)
32
+
33
+ if (error_code = IL.GetError) != IL::NO_ERROR
34
+ raise RuntimeError, "an error occured while trying to "+
35
+ "load the image #{file}. #{ILU.ErrorString(error_code)}"
36
+ end
37
+
38
+ img = Image.new(name, file)
39
+ if block
40
+ block.call(img)
41
+ end
42
+
43
+ img
44
+ end
45
+
46
+ alias_method :with_image, :load_image
47
+ alias_method :load, :load_image
48
+
49
+ # convert an image +blob+ with +width+ and +height+
50
+ # to a bona fide image
51
+ def from_blob(blob, width, height)
52
+ Image.new(IL.FromBlob(blob, width, height), nil)
53
+ end
54
+
55
+ # configure Devil.
56
+ # accepts hash parameters: :scale_filter, :placement, :clear_color,
57
+ # :window_size, :edge_filter.
58
+ #
59
+ # :scale_filter accepts a valid scaling algorithm: (default is LANCZOS3).
60
+ # Devil::NEAREST, Devil::LINEAR, Devil::BILINEAR, Devil::SCALE_BOX,
61
+ # Devil::SCALE_TRIANGLE, Devil::SCALE_BELL, Devil::SCALE_BSPLINE,
62
+ # Devil::SCALE_LANCZOS3, Devil::SCALE_MITCHELL
63
+ #
64
+ # :placement determines where in the canvas the image will be placed after
65
+ # the canvas has been enlarged using the 'enlarge_canvas' method.
66
+ # Valid parameters are: Devil::CENTER, Devil::LOWER_LEFT, Devil::UPPER_RIGHT, etc
67
+ #
68
+ # :clear_color sets the current clearing colour to be used by future
69
+ # calls to clear. rotate and enlarge_canvas both use these values to
70
+ # clear blank space in images, too.
71
+ # e.g Devil.set_options(:clear_color => [255, 255, 0, 255])
72
+ # Above sets the clear color to yellow with full opacity.
73
+ #
74
+ # :window_size sets the display window size Gosu will use when displaying images
75
+ # that invoked the 'show' method. (default is 1024 x 768)
76
+ # e.g Devil.set_options(:window_size => [2000, 768])
77
+ # Example above sets a window size of 2000x768.
78
+ # Note: :window_size is only relevant when require 'devil/gosu' is used.
79
+ #
80
+ # :edge_filter sets the edge detection algorithm to use when invoking
81
+ # the 'edge_detect' method. (defaults to :prewitt)
82
+ # Allowed values are :prewitt and :sobel
83
+ def set_options(options={})
84
+ @options.merge!(options)
85
+
86
+ # update the scale_filter
87
+ ILU.ImageParameter(ILU::FILTER, @options[:scale_filter])
88
+ ILU.ImageParameter(ILU::PLACEMENT, @options[:placement])
89
+ IL.ClearColour(*@options[:clear_color])
90
+ end
91
+
92
+ # return the current Devil configuration.
93
+ def get_options
94
+ @options
95
+ end
96
+
97
+ # initializes Devil and sets defaults.
98
+ # This method should never need to be called directly.
99
+ def init
100
+ # initialize DevIL
101
+ IL.Init
102
+ ILU.Init
103
+
104
+ set_option_defaults
105
+ end
106
+
107
+ private
108
+
109
+ def set_option_defaults
110
+ @options = {
111
+ :scale_filter => ILU::SCALE_LANCZOS3,
112
+ :edge_filter => :prewitt,
113
+ :window_size => [1024, 768],
114
+ :clear_color => [255, 248, 230, 0],
115
+ :placement => ILU::CENTER,
116
+ }
117
+
118
+ # configurable options
119
+ ILU.ImageParameter(ILU::FILTER, @options[:scale_filter])
120
+ ILU.ImageParameter(ILU::PLACEMENT, @options[:placement])
121
+ IL.ClearColour(*@options[:clear_color])
122
+
123
+ # fixed options
124
+ IL.Enable(IL::FILE_OVERWRITE)
125
+ end
126
+ end
127
+
128
+ class Image
129
+ attr_reader :name, :file
130
+
131
+ def initialize(name, file)
132
+ @name = name
133
+ @file = file
134
+
135
+ ObjectSpace.define_finalizer( self, proc { IL.DeleteImages(1, [name]) } )
136
+ end
137
+
138
+ # returns the width of the image.
139
+ def width
140
+ action { IL.GetInteger(IL::IMAGE_WIDTH) }
141
+ end
142
+
143
+ alias_method :columns, :width
144
+
145
+ # returns the height of the image.
146
+ def height
147
+ action { IL.GetInteger(IL::IMAGE_HEIGHT) }
148
+ end
149
+
150
+ alias_method :rows, :height
151
+
152
+ # saves the image to +file+. If no +file+ is provided default to the opened file.
153
+ def save(file = @file)
154
+ raise "This image does not have an associated file. Please provide an explicit file name when saving." if !file
155
+
156
+ action { IL.SaveImage(file) }
157
+ self
158
+ end
159
+
160
+ # resize the image to +width+ and +height+. Aspect ratios of the image do not have to be the same.
161
+ def resize(width, height)
162
+ action { ILU.Scale(width, height, 1) }
163
+ self
164
+ end
165
+
166
+ # Creates a proportional thumbnail of the image scaled so its longest.
167
+ # edge is resized to +size+.
168
+ def thumbnail(size)
169
+
170
+ # this thumbnail code from image_science.rb
171
+ w, h = width, height
172
+ scale = size.to_f / (w > h ? w : h)
173
+ resize((w * scale).to_i, (h * scale).to_i)
174
+ self
175
+ end
176
+
177
+ # return a deep copy of the current image.
178
+ def dup
179
+ new_image_name = action { IL.CloneCurImage }
180
+ Image.new(new_image_name, nil)
181
+ end
182
+
183
+ alias_method :clone, :dup
184
+
185
+ # crop the current image.
186
+ # +xoff+ number of pixels to skip in x direction.
187
+ # +yoff+ number of pixels to skip in y direction.
188
+ # +width+ number of pixels to preserve in x direction.
189
+ # +height+ number of pixels to preserve in y direction.
190
+ def crop(xoff, yoff, width, height)
191
+ action { ILU.Crop(xoff, yoff, 1, width, height, 1) }
192
+ self
193
+ end
194
+
195
+ # enlarge the canvas of current image to +width+ and +height+.
196
+ def enlarge_canvas(width, height)
197
+ if width < self.width || height < self.height
198
+ raise "width and height parameters must be larger than current image width and height"
199
+ end
200
+
201
+ action { ILU.EnlargeCanvas(width, height, 1) }
202
+ self
203
+ end
204
+
205
+ # splice the +source+ image into current image at position +x+ and +y+.
206
+ # Takes an optional +:crop+ hash parameter that has the following format: +:crop => [sx, sy, width, height]+
207
+ # +sx+, +sy+, +width, +height+ crop the source image to be spliced.
208
+ # +sx+ is how many pixels to skip in x direction of source image.
209
+ # +sy+ is how many pixels to skip in y direction of source image.
210
+ # +width+ number of pixels to preserve in x direction of source image.
211
+ # +height+ number of pixels to preserve in y direction of source image.
212
+ # if no +:crop+ parameter is provided then the whole image is spliced in.
213
+ def blit(source, x, y, options = {})
214
+ options = {
215
+ :crop => [0, 0, source.width, source.height]
216
+ }.merge!(options)
217
+
218
+ action do
219
+ IL.Blit(source.name, x, y, 0, options[:crop][0], options[:crop][1], 0,
220
+ options[:crop][2], options[:crop][3], 1)
221
+ end
222
+
223
+ self
224
+ end
225
+
226
+ alias_method :composite, :blit
227
+
228
+ # reflect image about its y axis.
229
+ def mirror
230
+ action { ILU.Mirror }
231
+ self
232
+ end
233
+
234
+ # use prewitt or sobel filters to detect the edges in the current image.
235
+ def edge_detect
236
+ case Devil.get_options[:edge_filter]
237
+ when :prewitt
238
+ action { ILU.EdgeDetectP }
239
+ when :sobel
240
+ action { ILU.EdgeDetectS }
241
+ else
242
+ raise "No such edge filter #{Devil.get_options[:edge_filter]}. Use :prewitt or :sobel"
243
+ end
244
+ self
245
+ end
246
+
247
+ # embosses an image, causing it to have a "relief" feel to it using a convolution filter.
248
+ def emboss
249
+ action { ILU.Emboss }
250
+ self
251
+ end
252
+
253
+ # applies a strange color distortion effect to the image giving a preternatural feel
254
+ def alienify
255
+ action { ILU.Alienify }
256
+ self
257
+ end
258
+
259
+ # performs a gaussian blur on the image. The blur is performed +iter+ times.
260
+ def blur(iter)
261
+ action { ILU.BlurGaussian(iter) }
262
+ self
263
+ end
264
+
265
+ # 'pixelize' the image using a pixel size of +pixel_size+.
266
+ def pixelize(pixel_size)
267
+ action { ILU.Pixelize(pixel_size) }
268
+ self
269
+ end
270
+
271
+ # add random noise to the image. +factor+ is the tolerance to use.
272
+ # accepeted values range from 0.0 - 1.0.
273
+ def noisify(factor)
274
+ action { ILU.Noisify(factor) }
275
+ self
276
+ end
277
+
278
+ # The sharpening +factor+ must be in the range of 0.0 - 2.5. A value of 1.0 for the sharpening.
279
+ # factor will have no effect on the image. Values in the range 1.0 - 2.5 will sharpen the
280
+ # image, with 2.5 having the most pronounced sharpening effect. Values from 0.0 to 1.0 do
281
+ # a type of reverse sharpening, blurring the image. Values outside of the 0.0 - 2.5 range
282
+ # produce undefined results.
283
+ #
284
+ # The number of +iter+ (iterations) to perform will usually be 1, but to achieve more sharpening,
285
+ # increase the number of iterations.
286
+ def sharpen(factor, iter)
287
+ action { ILU.Sharpen(factor, iter) }
288
+ self
289
+ end
290
+
291
+ # applies gamma correction to an image using an exponential curve.
292
+ # +factor+ is gamma correction factor to use.
293
+ # A value of 1.0 leaves the image unmodified.
294
+ # Values in the range 0.0 - 1.0 darken the image
295
+ # Values above 1.0 brighten the image.
296
+ def gamma_correct(factor)
297
+ action { ILU.GammaCorrect(factor) }
298
+ self
299
+ end
300
+
301
+ # invert the color of every pixel in the image.
302
+ def negate
303
+ action { ILU.Negative }
304
+ self
305
+ end
306
+
307
+ alias_method :negative, :negate
308
+
309
+ # +factor+ describes desired contrast to use
310
+ # A value of 1.0 has no effect on the image.
311
+ # Values between 1.0 and 1.7 increase the amount of contrast (values above 1.7 have no effect)
312
+ # Valid range of +factor+ is 0.0 - 1.7.
313
+ def contrast(factor)
314
+ action { ILU.Contrast(factor) }
315
+ self
316
+ end
317
+
318
+ # darkens the bright colours and lightens the dark
319
+ # colours, reducing the contrast in an image or 'equalizing' it.
320
+ def equalize
321
+ action { ILU.Equalize }
322
+ self
323
+ end
324
+
325
+ # returns the image data in the form of a ruby string.
326
+ # The image data is formatted to RGBA / UNSIGNED BYTE.
327
+ def to_blob
328
+ action { IL.ToBlob }
329
+ end
330
+
331
+ # flip the image about its x axis.
332
+ def flip
333
+ action { ILU.FlipImage }
334
+ self
335
+ end
336
+
337
+ # rotate an image about its central point by +angle+ degrees (counter clockwise).
338
+ def rotate(angle)
339
+ action { ILU.Rotate(angle) }
340
+ self
341
+ end
342
+
343
+ # simply clears the image to the 'clear color' (specified using Devil.set_options(:clear_color => [r, g, b, a])
344
+ def clear
345
+ action { IL.ClearImage }
346
+ self
347
+ end
348
+
349
+ private
350
+
351
+ def set_binding
352
+ IL.BindImage(@name)
353
+ end
354
+
355
+ def error_check
356
+ if (error_code = IL.GetError) != IL::NO_ERROR
357
+ raise RuntimeError, "An error occured. #{ILU.ErrorString(error_code)}"
358
+ end
359
+ end
360
+
361
+ def action
362
+ set_binding
363
+ result = yield
364
+ error_check
365
+
366
+ result
367
+ end
368
+ end
369
+ end
370
+
371
+ Devil.init