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/CHANGELOG +50 -0
- data/README +52 -52
- data/Rakefile +76 -75
- data/ext/devil/ruby_il.c +65 -3
- data/ext/devil/ruby_ilu.c +68 -3
- data/lib/1.8/devil.so +0 -0
- data/lib/1.9/devil.so +0 -0
- data/lib/devil.rb +371 -235
- data/lib/devil/gosu.rb +10 -4
- data/test/red.png +0 -0
- data/test/test_blit.rb +22 -0
- data/test/test_new_api.rb +8 -8
- data/test/test_scale_algos.rb +30 -0
- data/test/test_thumbnail.rb +1 -2
- metadata +6 -2
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,
|
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,
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
require "#{direc}/1.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
img
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
#
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
#
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
#
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
# +
|
188
|
-
#
|
189
|
-
#
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
ILU.
|
202
|
-
self
|
203
|
-
end
|
204
|
-
|
205
|
-
#
|
206
|
-
#
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
#
|
213
|
-
def
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
self
|
224
|
-
end
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
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
|