devil 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (C) 2006 Jaroslaw Tworek
2
+ Copyright (C) 2009 John Mair
3
+
4
+ This software is provided 'as-is', without any express or implied
5
+ warranty. In no event will the authors be held liable for any damages
6
+ arising from the use of this software.
7
+
8
+ Permission is granted to anyone to use this software for any purpose,
9
+ including commercial applications, and to alter it and redistribute it
10
+ freely, subject to the following restrictions:
11
+
12
+ 1. The origin of this software must not be misrepresented; you must not
13
+ claim that you wrote the original software. If you use this software
14
+ in a product, an acknowledgment in the product documentation would be
15
+ appreciated but is not required.
16
+ 2. Altered source versions must be plainly marked as such, and must not be
17
+ misrepresented as being the original software.
18
+ 3. This notice may not be removed or altered from any source distribution.
19
+
20
+ Jaroslaw Tworek < dev.jrx@gmail.com >
21
+ John Mair, http://banisterfiend.wordpress.com
data/README ADDED
@@ -0,0 +1,25 @@
1
+ Devil version 0.1.0
2
+
3
+ * Original author: Jaroslaw Tworek <dev.jrx@gmail.com>
4
+ * Current maintainer: John Mair (banisterfiend) http://banisterfiend.wordpress.com
5
+
6
+ Ruby bindings for the Developer's Image Library
7
+ You need DevIL installed to build this extension
8
+
9
+ For debian:
10
+ * install the libdevil and libdevil-dev packages
11
+
12
+ Or go here to download the libraries:
13
+ http://openil.sourceforge.net
14
+
15
+ It's also worth having Ruby OpenGL bindings to use the extensions.
16
+
17
+ http://www2.geganet.net/~yoshi/
18
+
19
+ See INSTALL for installation instructions.
20
+
21
+ For now, there is support for just a subset of DevIL functions, but it is enough
22
+ for 95% things you may want to do.
23
+
24
+ For example uses, see test/ directory
25
+
@@ -0,0 +1,54 @@
1
+ require 'rake/clean'
2
+ require 'rake/extensiontask'
3
+ require 'rake/gempackagetask'
4
+ require 'rake/testtask'
5
+ require 'rake/rdoctask'
6
+
7
+ DEVIL_VERSION = "0.1.0"
8
+
9
+ dlext = Config::CONFIG['DLEXT']
10
+
11
+ CLEAN.include("ext/**/*.#{dlext}", "ext/**/.log", "ext/**/.o", "ext/**/*~", "ext/**/*#*", "ext/**/.obj", "ext/**/.def", "ext/**/.pdb")
12
+ CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o", "doc/**")
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.name = "devil"
16
+ s.summary = "ruby bindings for devil cross platform image loading library"
17
+ s.description = s.summary
18
+ s.version = DEVIL_VERSION
19
+ s.author = "Jaroslaw Tworek, John Mair (banisterfiend)"
20
+ s.email = 'jrmair@gmail.com'
21
+ s.date = Time.now.strftime '%Y-%m-%d'
22
+ s.require_path = 'lib'
23
+ s.homepage = "http://banisterfiend.wordpress.com"
24
+ s.platform = Gem::Platform::RUBY
25
+ s.extensions = FileList["ext/**/extconf.rb"]
26
+ s.has_rdoc = true
27
+ s.extra_rdoc_files = ["README"]
28
+ s.rdoc_options << '--main' << 'README'
29
+ s.files = ["Rakefile", "README", "LICENSE", "lib/devil.rb"] +
30
+ FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
31
+ end
32
+
33
+ Rake::GemPackageTask.new(spec) do |pkg|
34
+ pkg.need_zip = false
35
+ pkg.need_tar = false
36
+ end
37
+
38
+ Rake::ExtensionTask.new('devil', spec) do |ext|
39
+ ext.config_script = 'extconf.rb'
40
+ ext.cross_compile = true
41
+ ext.cross_platform = 'i386-mswin32'
42
+ end
43
+
44
+ Rake::TestTask.new do |t|
45
+ t.libs << "lib"
46
+ t.test_files = FileList['test/test*.rb']
47
+ t.verbose = true
48
+ end
49
+
50
+ Rake::RDocTask.new do |rd|
51
+ rd.main = "README"
52
+ rd.rdoc_files.include("README", "lib/devil.rb")
53
+ end
54
+
@@ -0,0 +1,7 @@
1
+ require 'mkmf'
2
+
3
+ have_library("IL", "ilInit");
4
+ have_library("ILU", "iluInit");
5
+ have_library("ILUT", "ilutInit");
6
+
7
+ create_makefile('devil')
@@ -0,0 +1,9 @@
1
+ #include "ruby_devil_ext.h"
2
+
3
+
4
+ void
5
+ Init_devil() {
6
+ InitializeIL();
7
+ InitializeILU();
8
+ InitializeILUT();
9
+ }
@@ -0,0 +1,9 @@
1
+ #include <ruby.h>
2
+
3
+ #include <stdio.h>
4
+
5
+ typedef struct RArray RArray;
6
+
7
+ extern void InitializeIL();
8
+ extern void InitializeILU();
9
+ extern void InitializeILUT();
@@ -0,0 +1,375 @@
1
+ #include "ruby_devil_ext.h"
2
+ #include <IL/il.h>
3
+
4
+ struct ImageData {
5
+ ILubyte* data;
6
+ };
7
+
8
+ static VALUE mIL;
9
+ static VALUE cImageData;
10
+ static VALUE cNullImageData;
11
+
12
+
13
+ inline ILubyte* ImageData2Arr(VALUE obj) {
14
+ struct ImageData* arr;
15
+ Data_Get_Struct(obj, struct ImageData, arr);
16
+ return arr->data;
17
+ }
18
+
19
+ inline VALUE MakeImageData(ILubyte* image_data) {
20
+ struct ImageData* c_data;
21
+ VALUE ret = Data_Make_Struct(cImageData, struct ImageData, 0, NULL, c_data);
22
+ c_data->data = image_data;
23
+ return ret;
24
+ }
25
+
26
+
27
+ static VALUE il_Init(VALUE obj) {
28
+ ilInit();
29
+ return Qnil;
30
+ }
31
+
32
+ static VALUE il_GenImages(VALUE obj, VALUE num_names) {
33
+ ILsizei num = NUM2INT(num_names);
34
+ ILuint* names = ALLOC_N(ILuint, num);
35
+ RArray* ret;
36
+ int i;
37
+
38
+ if (!names)
39
+ rb_raise(rb_eRuntimeError, "IL.GenImages memory allocation");
40
+
41
+ ilGenImages(num, names);
42
+
43
+ ret = RARRAY( rb_ary_new2(num));
44
+ for(i = 0; i < num; ++i)
45
+ rb_ary_push( (VALUE)ret, INT2NUM(names[i]));
46
+ free(names);
47
+
48
+ return (VALUE)ret;
49
+ }
50
+
51
+ static VALUE il_BindImage(VALUE obj, VALUE image) {
52
+ ILuint u_image = NUM2INT(image);
53
+ ilBindImage(u_image);
54
+ return Qnil;
55
+ }
56
+
57
+ static VALUE il_DeleteImages(VALUE obj, VALUE images) {
58
+ ILsizei num;
59
+ ILuint* u_images;
60
+ RArray* ary;
61
+ VALUE entry;
62
+ int i = 0;
63
+
64
+ if(TYPE(images) != T_ARRAY)
65
+ rb_raise(rb_eTypeError, "type mismatch:%s", rb_class2name(images));
66
+
67
+ ary = RARRAY(images);
68
+ num = RARRAY_LEN(images);
69
+ u_images = ALLOC_N(ILuint, num);
70
+
71
+ for(i = 0; i < num; ++i) {
72
+ entry = rb_ary_entry((VALUE)ary, i);
73
+ u_images[i] = NUM2INT(entry);
74
+ }
75
+
76
+ ilDeleteImages(num, u_images);
77
+
78
+ free(u_images);
79
+ return Qnil;
80
+ }
81
+
82
+ static VALUE il_LoadImage(VALUE obj, VALUE rb_filename) {
83
+ char* filename = STR2CSTR(rb_filename);
84
+ ILboolean load = ilLoadImage(filename);
85
+ return load ? Qtrue : Qfalse;
86
+ }
87
+
88
+ static VALUE il_Load(VALUE obj, VALUE rb_type, VALUE rb_filename) {
89
+ ILenum type = NUM2INT(rb_type);
90
+ char* filename = STR2CSTR(rb_filename);
91
+
92
+ ILboolean load = ilLoad(type, filename);
93
+ return load ? Qtrue : Qfalse;
94
+ }
95
+
96
+ static VALUE il_SaveImage(VALUE obj, VALUE rb_filename) {
97
+ char* filename = STR2CSTR(rb_filename);
98
+ ILboolean load = ilSaveImage(filename);
99
+
100
+ return load ? Qtrue : Qfalse;
101
+ }
102
+
103
+ static VALUE il_Save(VALUE obj, VALUE rb_type, VALUE rb_filename) {
104
+ ILenum type = NUM2INT(rb_type);
105
+ char* filename = STR2CSTR(rb_filename);
106
+ ILboolean load = ilSave(type, filename);
107
+
108
+ return load ? Qtrue : Qfalse;
109
+ }
110
+
111
+ static VALUE il_TexImage(VALUE obj, VALUE rb_width, VALUE rb_height,
112
+ VALUE rb_depth, VALUE rb_bpp, VALUE rb_format, VALUE rb_type,
113
+ VALUE rb_data) {
114
+ ILuint width = NUM2INT(rb_width);
115
+ ILuint height = NUM2INT(rb_height);
116
+ ILuint depth = NUM2INT(rb_depth);
117
+ ILubyte bpp = NUM2INT(rb_bpp);
118
+ ILenum format = NUM2INT(rb_format);
119
+ ILenum type = NUM2INT(rb_type);
120
+ ILvoid* data = ImageData2Arr(rb_data);
121
+
122
+ ILboolean flag = ilTexImage(width, height, depth,
123
+ bpp, format, type, data);
124
+ return flag ? Qtrue : Qfalse;
125
+ }
126
+
127
+ static VALUE il_GetData(VALUE obj) {
128
+ ILubyte* data = ilGetData();
129
+ return MakeImageData(data);
130
+ }
131
+
132
+ ILuint ilCopyPixels(ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width,
133
+ ILuint Height, ILuint Depth, ILenum Format, ILenum Type, ILvoid
134
+ *Data);
135
+
136
+ static VALUE il_CopyPixels(VALUE obj, VALUE rb_XOff, VALUE rb_YOff, VALUE rb_ZOff,
137
+ VALUE rb_Width, VALUE rb_Height, VALUE rb_Depth, VALUE rb_Format,
138
+ VALUE rb_Type, VALUE rb_data) {
139
+ ILuint XOff = NUM2INT(rb_XOff);
140
+ ILuint YOff = NUM2INT(rb_YOff);
141
+ ILuint ZOff = NUM2INT(rb_ZOff);
142
+ ILuint Width = NUM2INT(rb_Width);
143
+ ILuint Height = NUM2INT(rb_Height);
144
+ ILuint Depth = NUM2INT(rb_Depth);
145
+ ILenum Format = NUM2INT(rb_Format);
146
+ ILenum Type = NUM2INT(rb_Type);
147
+ ILvoid* data = ImageData2Arr(rb_data);
148
+
149
+ ILuint uint = ilCopyPixels(XOff, YOff, ZOff, Width, Height, Depth, Format, Type, data);
150
+ return INT2FIX(uint);
151
+ }
152
+
153
+ static VALUE il_SetData(VALUE obj, VALUE rb_Data) {
154
+ ILvoid* data = ImageData2Arr(rb_Data);
155
+ ILboolean flag = ilSetData(data);
156
+ return flag ? Qtrue : Qfalse;
157
+ }
158
+
159
+ static VALUE il_SetPixels(VALUE obj, VALUE rb_XOff, VALUE rb_YOff, VALUE rb_ZOff,
160
+ VALUE rb_Width, VALUE rb_Height, VALUE rb_Depth, VALUE rb_Format,
161
+ VALUE rb_Type, VALUE rb_data) {
162
+ ILuint XOff = NUM2INT(rb_XOff);
163
+ ILuint YOff = NUM2INT(rb_YOff);
164
+ ILuint ZOff = NUM2INT(rb_ZOff);
165
+ ILuint Width = NUM2INT(rb_Width);
166
+ ILuint Height = NUM2INT(rb_Height);
167
+ ILuint Depth = NUM2INT(rb_Depth);
168
+ ILenum Format = NUM2INT(rb_Format);
169
+ ILenum Type = NUM2INT(rb_Type);
170
+ ILvoid* data = ImageData2Arr(rb_data);
171
+
172
+ ilSetPixels(XOff, YOff, ZOff, Width, Height, Depth, Format, Type, data);
173
+ return Qnil;
174
+ }
175
+
176
+
177
+ static VALUE il_CopyImage(VALUE obj, VALUE rb_Src){
178
+ ILuint Src = NUM2INT(rb_Src);
179
+ ILboolean flag = ilCopyImage(Src);
180
+ return flag ? Qtrue : Qfalse;
181
+ }
182
+
183
+ static VALUE il_OverlayImage(VALUE obj, VALUE rb_Source, VALUE rb_XCoord,
184
+ VALUE rb_YCoord, VALUE rb_ZCoord) {
185
+ ILuint Source = NUM2INT(rb_Source);
186
+ ILint XCoord = NUM2INT(rb_XCoord);
187
+ ILint YCoord = NUM2INT(rb_YCoord);
188
+ ILint ZCoord = NUM2INT(rb_ZCoord);
189
+ ILboolean flag = ilOverlayImage(Source, XCoord, YCoord,ZCoord);
190
+
191
+ return flag ? Qtrue : Qfalse;
192
+ }
193
+
194
+
195
+ static VALUE il_Blit(VALUE obj, VALUE rb_Source, VALUE rb_DestX, VALUE
196
+ rb_DestY, VALUE rb_DestZ, VALUE rb_SrcX, VALUE rb_SrcY, VALUE
197
+ rb_SrcZ, VALUE rb_Width, VALUE rb_Height, VALUE rb_Depth) {
198
+ ILuint Source = NUM2INT(rb_Source);
199
+ ILint DestX = NUM2INT(rb_DestX);
200
+ ILint DestY = NUM2INT(rb_DestY);
201
+ ILint DestZ = NUM2INT(rb_DestZ);
202
+ ILint SrcX = NUM2INT(rb_SrcX);
203
+ ILint SrcY = NUM2INT(rb_SrcY);
204
+ ILint SrcZ = NUM2INT(rb_SrcZ);
205
+ ILuint Width = NUM2INT(rb_Width);
206
+ ILuint Height = NUM2INT(rb_Height);
207
+ ILuint Depth = NUM2INT(rb_Depth);
208
+
209
+ ILboolean flag = ilBlit(Source, DestX,DestY, DestZ,SrcX, SrcY, SrcZ,
210
+ Width,Height,Depth);
211
+ return flag ? Qtrue : Qfalse;
212
+ }
213
+
214
+ static VALUE il_GetError(VALUE obj) {
215
+ ILenum num = ilGetError();
216
+ return INT2FIX(num);
217
+ }
218
+
219
+ static VALUE il_ActiveMipmap(VALUE obj, VALUE rb_Number) {
220
+ ILuint Number = NUM2INT(rb_Number);
221
+ ILboolean flag = ilActiveMipmap(Number);
222
+ return flag ? Qtrue : Qfalse;
223
+ }
224
+
225
+ static VALUE il_ActiveImage(VALUE obj, VALUE rb_Number){
226
+ ILuint Number = NUM2INT(rb_Number);
227
+ ILboolean flag = ilActiveImage(Number);
228
+ return flag ? Qtrue : Qfalse;
229
+ }
230
+
231
+ /* added by banisterfiend */
232
+ static VALUE il_Enable(VALUE obj, VALUE rb_mode) {
233
+ ILenum mode = NUM2INT(rb_mode);
234
+
235
+ ILboolean flag = ilEnable(mode);
236
+ return flag ? Qtrue : Qfalse;
237
+ }
238
+
239
+ static VALUE il_GetInteger(VALUE obj, VALUE rb_mode) {
240
+ ILenum mode = NUM2INT(rb_mode);
241
+
242
+ ILint result = ilGetInteger(mode);
243
+ return INT2NUM(result);
244
+ }
245
+ /* end of banisterfiend additions */
246
+
247
+ void
248
+ InitializeIL() {
249
+ mIL = rb_define_module("IL");
250
+ //////////////////////////////////
251
+ //CLASSES
252
+ //////////////////////////////////
253
+ cImageData = rb_define_class_under(mIL, "ImageData", rb_cObject);
254
+ cNullImageData = MakeImageData(NULL);
255
+ rb_define_const(cImageData, "NullData", cNullImageData);
256
+ //////////////////////////////////
257
+ //METHODS
258
+ //////////////////////////////////
259
+ rb_define_module_function(mIL, "Init", il_Init, 0);
260
+ rb_define_module_function(mIL, "GenImages", il_GenImages, 1);
261
+ rb_define_module_function(mIL, "BindImage", il_BindImage, 1);
262
+ rb_define_module_function(mIL, "DeleteImages", il_DeleteImages, 1);
263
+ rb_define_module_function(mIL, "LoadImage", il_LoadImage, 1);
264
+ rb_define_module_function(mIL, "Load", il_Load, 2);
265
+ rb_define_module_function(mIL, "SaveImage", il_SaveImage, 1);
266
+ rb_define_module_function(mIL, "Save", il_Save, 2);
267
+ rb_define_module_function(mIL, "TexImage", il_TexImage, 7);
268
+ rb_define_module_function(mIL, "GetData", il_GetData, 0);
269
+ rb_define_module_function(mIL, "CopyPixels", il_CopyPixels, 9);
270
+ rb_define_module_function(mIL, "SetData", il_SetData, 1);
271
+ rb_define_module_function(mIL, "SetPixels", il_SetPixels, 9);
272
+ rb_define_module_function(mIL, "CopyImage", il_CopyImage, 1);
273
+ rb_define_module_function(mIL, "OverlayImage", il_OverlayImage, 4);
274
+ rb_define_module_function(mIL, "Blit", il_Blit, 10);
275
+ rb_define_module_function(mIL, "GetError", il_GetError, 0);
276
+ rb_define_module_function(mIL, "ActiveMipmap", il_ActiveMipmap, 1);
277
+ rb_define_module_function(mIL, "ActiveImage", il_ActiveImage, 1);
278
+
279
+ // METHODS ADDED BY BANISTERFIEND
280
+ rb_define_module_function(mIL, "Enable", il_Enable, 1);
281
+ rb_define_module_function(mIL, "GetInteger", il_GetInteger, 1);
282
+
283
+
284
+ //////////////////////////////////
285
+ //CONSTANTS
286
+ //////////////////////////////////
287
+ rb_define_const(mIL, "TYPE_UNKNOWN", INT2NUM(IL_TYPE_UNKNOWN));
288
+ rb_define_const(mIL, "BMP", INT2NUM(IL_BMP));
289
+ rb_define_const(mIL, "CUT", INT2NUM(IL_CUT));
290
+ rb_define_const(mIL, "DOOM", INT2NUM(IL_DOOM));
291
+ rb_define_const(mIL, "DOOM_FLAT", INT2NUM(IL_DOOM_FLAT));
292
+ rb_define_const(mIL, "ICO", INT2NUM(IL_ICO));
293
+ rb_define_const(mIL, "JPG", INT2NUM(IL_JPG));
294
+ rb_define_const(mIL, "JFIF", INT2NUM(IL_JFIF));
295
+ rb_define_const(mIL, "LBM", INT2NUM(IL_LBM));
296
+ rb_define_const(mIL, "PCD", INT2NUM(IL_PCD));
297
+ rb_define_const(mIL, "PCX", INT2NUM(IL_PCX));
298
+ rb_define_const(mIL, "PIC", INT2NUM(IL_PIC));
299
+ rb_define_const(mIL, "PNG", INT2NUM(IL_PNG));
300
+ rb_define_const(mIL, "PNM", INT2NUM(IL_PNM));
301
+ rb_define_const(mIL, "SGI", INT2NUM(IL_SGI));
302
+ rb_define_const(mIL, "TGA", INT2NUM(IL_TGA));
303
+ rb_define_const(mIL, "TIF", INT2NUM(IL_TIF));
304
+ rb_define_const(mIL, "CHEAD", INT2NUM(IL_CHEAD));
305
+ rb_define_const(mIL, "RAW", INT2NUM(IL_RAW));
306
+ rb_define_const(mIL, "MDL", INT2NUM(IL_MDL));
307
+ rb_define_const(mIL, "WAL", INT2NUM(IL_WAL));
308
+ rb_define_const(mIL, "LIF", INT2NUM(IL_LIF));
309
+ rb_define_const(mIL, "MNG", INT2NUM(IL_MNG));
310
+ rb_define_const(mIL, "JNG", INT2NUM(IL_JNG));
311
+ rb_define_const(mIL, "GIF", INT2NUM(IL_GIF));
312
+ rb_define_const(mIL, "DDS", INT2NUM(IL_DDS));
313
+ rb_define_const(mIL, "DCX", INT2NUM(IL_DCX));
314
+ rb_define_const(mIL, "PSD", INT2NUM(IL_PSD));
315
+ rb_define_const(mIL, "EXIF", INT2NUM(IL_EXIF));
316
+ rb_define_const(mIL, "PSP", INT2NUM(IL_PSP));
317
+ rb_define_const(mIL, "PIX", INT2NUM(IL_PIX));
318
+ rb_define_const(mIL, "PXR", INT2NUM(IL_PXR));
319
+ rb_define_const(mIL, "XPM", INT2NUM(IL_XPM));
320
+ rb_define_const(mIL, "HDR", INT2NUM(IL_HDR));
321
+ rb_define_const(mIL, "JASC_PAL", INT2NUM(IL_JASC_PAL));
322
+
323
+ rb_define_const(mIL, "COLOUR_INDEX", INT2NUM(IL_COLOUR_INDEX));
324
+ rb_define_const(mIL, "COLOR_INDEX", INT2NUM(IL_COLOR_INDEX));
325
+ rb_define_const(mIL, "RGB", INT2NUM(IL_RGB));
326
+ rb_define_const(mIL, "RGBA", INT2NUM(IL_RGBA));
327
+ rb_define_const(mIL, "BGR", INT2NUM(IL_BGR));
328
+ rb_define_const(mIL, "BGRA", INT2NUM(IL_BGRA));
329
+ rb_define_const(mIL, "LUMINANCE", INT2NUM(IL_LUMINANCE));
330
+ rb_define_const(mIL, "LUMINANCE_ALPHA", INT2NUM(IL_LUMINANCE_ALPHA));
331
+
332
+ rb_define_const(mIL, "UNSIGNED_BYTE", INT2NUM(IL_UNSIGNED_BYTE));
333
+ rb_define_const(mIL, "SHORT", INT2NUM(IL_SHORT));
334
+ rb_define_const(mIL, "UNSIGNED_SHORT", INT2NUM(IL_UNSIGNED_SHORT));
335
+ rb_define_const(mIL, "INT", INT2NUM(IL_INT));
336
+ rb_define_const(mIL, "UNSIGNED_INT", INT2NUM(IL_UNSIGNED_INT));
337
+ rb_define_const(mIL, "FLOAT", INT2NUM(IL_FLOAT));
338
+ rb_define_const(mIL, "DOUBLE", INT2NUM(IL_DOUBLE));
339
+
340
+ rb_define_const(mIL, "NO_ERROR", INT2NUM(IL_NO_ERROR));
341
+ rb_define_const(mIL, "INVALID_ENUM", INT2NUM(IL_INVALID_ENUM));
342
+ rb_define_const(mIL, "OUT_OF_MEMORY", INT2NUM(IL_OUT_OF_MEMORY));
343
+ rb_define_const(mIL, "FORMAT_NOT_SUPPORTED", INT2NUM(IL_FORMAT_NOT_SUPPORTED));
344
+ rb_define_const(mIL, "INTERNAL_ERROR", INT2NUM(IL_INTERNAL_ERROR));
345
+ rb_define_const(mIL, "INVALID_VALUE", INT2NUM(IL_INVALID_VALUE));
346
+ rb_define_const(mIL, "ILLEGAL_OPERATION", INT2NUM(IL_ILLEGAL_OPERATION));
347
+ rb_define_const(mIL, "ILLEGAL_FILE_VALUE", INT2NUM(IL_ILLEGAL_FILE_VALUE));
348
+ rb_define_const(mIL, "INVALID_FILE_HEADER", INT2NUM(IL_INVALID_FILE_HEADER));
349
+ rb_define_const(mIL, "INVALID_PARAM", INT2NUM(IL_INVALID_PARAM));
350
+ rb_define_const(mIL, "COULD_NOT_OPEN_FILE", INT2NUM(IL_COULD_NOT_OPEN_FILE));
351
+ rb_define_const(mIL, "INVALID_EXTENSION", INT2NUM(IL_INVALID_EXTENSION));
352
+ rb_define_const(mIL, "FILE_ALREADY_EXISTS", INT2NUM(IL_FILE_ALREADY_EXISTS));
353
+ rb_define_const(mIL, "OUT_FORMAT_SAME", INT2NUM(IL_OUT_FORMAT_SAME));
354
+ rb_define_const(mIL, "STACK_OVERFLOW", INT2NUM(IL_STACK_OVERFLOW));
355
+ rb_define_const(mIL, "STACK_UNDERFLOW", INT2NUM(IL_STACK_UNDERFLOW));
356
+ rb_define_const(mIL, "INVALID_CONVERSION", INT2NUM(IL_INVALID_CONVERSION));
357
+ rb_define_const(mIL, "BAD_DIMENSIONS", INT2NUM(IL_BAD_DIMENSIONS));
358
+ rb_define_const(mIL, "FILE_READ_ERROR", INT2NUM(IL_FILE_READ_ERROR));
359
+ rb_define_const(mIL, "FILE_WRITE_ERROR", INT2NUM(IL_FILE_WRITE_ERROR));
360
+ rb_define_const(mIL, "LIB_GIF_ERROR", INT2NUM(IL_LIB_GIF_ERROR));
361
+ rb_define_const(mIL, "LIB_JPEG_ERROR", INT2NUM(IL_LIB_JPEG_ERROR));
362
+ rb_define_const(mIL, "LIB_PNG_ERROR", INT2NUM(IL_LIB_PNG_ERROR));
363
+ rb_define_const(mIL, "LIB_TIFF_ERROR", INT2NUM(IL_LIB_TIFF_ERROR));
364
+ rb_define_const(mIL, "LIB_MNG_ERROR", INT2NUM(IL_LIB_MNG_ERROR));
365
+ rb_define_const(mIL, "UNKNOWN_ERROR", INT2NUM(IL_UNKNOWN_ERROR));
366
+
367
+ // CONSTANTS BELOW ADDED BY BANISTERFIEND
368
+ rb_define_const(mIL, "IMAGE_WIDTH", INT2NUM(IL_IMAGE_WIDTH));
369
+ rb_define_const(mIL, "IMAGE_HEIGHT", INT2NUM(IL_IMAGE_HEIGHT));
370
+ rb_define_const(mIL, "FILE_OVERWRITE", INT2NUM(IL_FILE_OVERWRITE));
371
+ }
372
+ //////////////////////////////////////////
373
+
374
+ //////////////////////////////////////////
375
+
@@ -0,0 +1,121 @@
1
+ #include <ruby.h>
2
+ #include <IL/ilu.h>
3
+ #include "ruby_devil_ext.h"
4
+
5
+ static VALUE mILU;
6
+
7
+ static VALUE ilu_Init(VALUE obj) {
8
+ iluInit();
9
+ return Qnil;
10
+ }
11
+
12
+ static VALUE ilu_ErrorString(VALUE obj, VALUE rb_error) {
13
+ ILenum num = NUM2INT(rb_error);
14
+ const char* error = iluErrorString(num);
15
+ return rb_str_new2(error);
16
+ }
17
+
18
+ static VALUE ilu_Alienify(VALUE obj) {
19
+ ILboolean flag = iluAlienify();
20
+ return flag ? Qtrue : Qfalse;
21
+ }
22
+
23
+ static VALUE ilu_BlurAvg(VALUE obj, VALUE rb_iter) {
24
+ ILuint iter = NUM2INT(rb_iter);
25
+ ILboolean flag = iluBlurAvg(iter);
26
+ return flag ? Qtrue : Qfalse;
27
+ }
28
+
29
+ static VALUE ilu_BlurGaussian(VALUE obj, VALUE rb_iter) {
30
+ ILuint iter = NUM2INT(rb_iter);
31
+ ILboolean flag = iluBlurGaussian(iter);
32
+ return flag ? Qtrue : Qfalse;
33
+ }
34
+
35
+ static VALUE ilu_Contrast(VALUE obj, VALUE rb_cont) {
36
+ ILfloat cont = NUM2DBL(rb_cont);
37
+ ILboolean flag = iluContrast(cont);
38
+ return flag ? Qtrue : Qfalse;
39
+ }
40
+
41
+ static VALUE ilu_Equalize(VALUE obj) {
42
+ ILboolean flag = iluEqualize();
43
+ return flag ? Qtrue : Qfalse;
44
+ }
45
+
46
+ static VALUE ilu_GammaCorrect (VALUE obj, VALUE rb_gamma) {
47
+ ILfloat gamma = NUM2DBL(rb_gamma);
48
+ ILboolean flag = iluGammaCorrect(gamma);
49
+ return flag ? Qtrue : Qfalse;
50
+ }
51
+ static VALUE ilu_Negative (VALUE obj) {
52
+ ILboolean flag = iluNegative();
53
+ return flag ? Qtrue : Qfalse;
54
+ }
55
+ static VALUE ilu_Noisify (VALUE obj, VALUE rb_tolerance) {
56
+ ILclampf tolerance = NUM2DBL(rb_tolerance);
57
+ ILboolean flag = iluNoisify(tolerance);
58
+ return flag ? Qtrue : Qfalse;
59
+ }
60
+ static VALUE ilu_Pixelize (VALUE obj, VALUE rb_pix_size) {
61
+ ILuint pix = NUM2INT(rb_pix_size);
62
+ ILboolean flag = iluPixelize(pix);
63
+ return flag ? Qtrue : Qfalse;
64
+ }
65
+ static VALUE ilu_Sharpen (VALUE obj, VALUE rb_factor, VALUE rb_iter) {
66
+ ILfloat factor = NUM2DBL(rb_factor);
67
+ ILuint iter = NUM2INT(rb_iter);
68
+ ILboolean flag = iluSharpen(factor, iter);
69
+ return flag ? Qtrue : Qfalse;
70
+ }
71
+
72
+ static VALUE ilu_Scale(VALUE obj, VALUE rb_Width, VALUE rb_Height, VALUE rb_Depth) {
73
+ ILuint Width = NUM2INT(rb_Width);
74
+ ILuint Height = NUM2INT(rb_Height);
75
+ ILuint Depth = NUM2INT(rb_Depth);
76
+ ILboolean flag = iluScale(Width, Height, Depth);
77
+ return flag ? Qtrue : Qfalse;
78
+ }
79
+
80
+ static VALUE ilu_ImageParameter(VALUE obj, VALUE rb_PName, VALUE rb_Param) {
81
+ ILenum PName = NUM2INT(rb_PName);
82
+ ILenum Param = NUM2INT(rb_Param);
83
+ iluImageParameter(PName, Param);
84
+ return Qnil;
85
+ }
86
+
87
+ static VALUE ilu_BuildMipmaps(VALUE obj) {
88
+ ILboolean flag = iluBuildMipmaps();
89
+ return flag ? Qtrue : Qfalse;
90
+ }
91
+
92
+ void
93
+ InitializeILU() {
94
+ mILU = rb_define_module("ILU");
95
+ rb_define_module_function(mILU, "Init", ilu_Init, 0);
96
+ rb_define_module_function(mILU, "ErrorString", ilu_ErrorString, 1);
97
+ rb_define_module_function(mILU, "Alienify", ilu_Alienify, 0);
98
+ rb_define_module_function(mILU, "BlurAvg", ilu_BlurAvg, 1);
99
+ rb_define_module_function(mILU, "BlurGaussian", ilu_BlurGaussian, 1);
100
+ rb_define_module_function(mILU, "Contrast",ilu_Contrast , 1);
101
+ rb_define_module_function(mILU, "Equalize",ilu_Equalize , 0);
102
+ rb_define_module_function(mILU, "GammaCorrect",ilu_GammaCorrect , 1);
103
+ rb_define_module_function(mILU, "Negative", ilu_Negative , 0);
104
+ rb_define_module_function(mILU, "Noisify", ilu_Noisify , 1);
105
+ rb_define_module_function(mILU, "Pixelize", ilu_Pixelize , 1);
106
+ rb_define_module_function(mILU, "Sharpen", ilu_Sharpen, 2);
107
+ rb_define_module_function(mILU, "Scale", ilu_Scale , 3);
108
+ rb_define_module_function(mILU, "ImageParameter", ilu_ImageParameter , 2);
109
+ rb_define_module_function(mILU, "BuildMipmaps", ilu_BuildMipmaps, 0);
110
+
111
+ rb_define_const(mILU, "FILTER", INT2NUM(ILU_FILTER));
112
+ rb_define_const(mILU, "NEAREST", INT2NUM(ILU_NEAREST));
113
+ rb_define_const(mILU, "LINEAR", INT2NUM(ILU_LINEAR));
114
+ rb_define_const(mILU, "BILINEAR", INT2NUM(ILU_BILINEAR));
115
+ rb_define_const(mILU, "SCALE_BOX", INT2NUM(ILU_SCALE_BOX));
116
+ rb_define_const(mILU, "SCALE_TRIANGLE", INT2NUM(ILU_SCALE_TRIANGLE));
117
+ rb_define_const(mILU, "SCALE_BELL", INT2NUM(ILU_SCALE_BELL));
118
+ rb_define_const(mILU, "SCALE_BSPLINE", INT2NUM(ILU_SCALE_BSPLINE));
119
+ rb_define_const(mILU, "SCALE_LANCZOS3", INT2NUM(ILU_SCALE_LANCZOS3));
120
+ rb_define_const(mILU, "SCALE_MITCHELL", INT2NUM(ILU_SCALE_MITCHELL));
121
+ }
@@ -0,0 +1,98 @@
1
+ #include <ruby.h>
2
+ #include <IL/ilut.h>
3
+ #include "ruby_devil_ext.h"
4
+
5
+ static VALUE mILUT;
6
+
7
+ static VALUE ilut_Renderer(VALUE obj, VALUE ilut_enum) {
8
+ ILenum renderer = NUM2INT(ilut_enum);
9
+ ilutRenderer(renderer);
10
+ return Qnil;
11
+ }
12
+
13
+ static VALUE ilut_Enable(VALUE obj, VALUE rb_Mode) {
14
+ ILenum Mode = NUM2INT(rb_Mode);
15
+ ILboolean flag = ilutEnable(Mode);
16
+ return flag ? Qtrue : Qfalse;
17
+ }
18
+
19
+ static VALUE ilut_GLTexImage(VALUE obj, VALUE rb_Level) {
20
+ ILuint Level = NUM2INT(rb_Level);
21
+ ILboolean flag = ilutGLTexImage(Level);
22
+ return flag ? Qtrue : Qfalse;
23
+ }
24
+
25
+ static VALUE ilut_GLBindTexImage(VALUE obj) {
26
+ GLuint ret = ilutGLBindTexImage();
27
+ return INT2FIX(ret);
28
+ }
29
+
30
+ static VALUE ilut_GLBuildMipmaps(VALUE obj) {
31
+ ILboolean flag = ilutGLBuildMipmaps();
32
+ return flag ? Qtrue : Qfalse;
33
+ }
34
+
35
+ static VALUE ilut_GLBindMipmaps(VALUE obj) {
36
+ ILuint ret = ilutGLBindMipmaps();
37
+ return INT2FIX(ret);
38
+ }
39
+
40
+ static VALUE ilut_GLLoadImage(VALUE obj, VALUE rb_FileName) {
41
+ const ILstring FileName = STR2CSTR(rb_FileName);
42
+ GLuint ret = ilutGLLoadImage(FileName);
43
+ return INT2FIX(ret);
44
+ }
45
+
46
+ static VALUE ilut_GLScreen(VALUE obj) {
47
+ ILboolean flag = ilutGLScreen();
48
+ return flag ? Qtrue : Qfalse;
49
+ }
50
+
51
+ static VALUE ilut_GLScreenie(VALUE obj) {
52
+ ILboolean flag = ilutGLScreenie();
53
+ return flag ? Qtrue : Qfalse;
54
+ }
55
+
56
+
57
+
58
+ void
59
+ InitializeILUT() {
60
+ mILUT = rb_define_module("ILUT");
61
+ //////////////////////////////////
62
+ //METHODS
63
+ //////////////////////////////////
64
+ rb_define_module_function(mILUT, "Renderer", ilut_Renderer, 1);
65
+ rb_define_module_function(mILUT, "Enable", ilut_Enable , 1);
66
+ rb_define_module_function(mILUT, "GLTexImage", ilut_GLTexImage, 1);
67
+ rb_define_module_function(mILUT, "GLBindTexImage", ilut_GLBindTexImage, 0);
68
+ rb_define_module_function(mILUT, "GLBuildMipmaps", ilut_GLBuildMipmaps , 0);
69
+ rb_define_module_function(mILUT, "GLBindMipmaps", ilut_GLBindMipmaps , 0);
70
+ rb_define_module_function(mILUT, "GLLoadImage", ilut_GLLoadImage, 1);
71
+ rb_define_module_function(mILUT, "GLScreen", ilut_GLScreen , 1);
72
+ rb_define_module_function(mILUT, "GLScreenie", ilut_GLScreenie , 1);
73
+
74
+ //////////////////////////////////
75
+ //CONSTANTS
76
+ //////////////////////////////////
77
+ rb_define_const(mILUT, "OPENGL", INT2NUM(ILUT_OPENGL));
78
+ rb_define_const(mILUT, "ALLEGRO", INT2NUM(ILUT_ALLEGRO));
79
+ rb_define_const(mILUT, "WIN32", INT2NUM(ILUT_WIN32));
80
+ rb_define_const(mILUT, "DIRECT3D8", INT2NUM(ILUT_DIRECT3D8));
81
+ rb_define_const(mILUT, "DIRECT3D9", INT2NUM(ILUT_DIRECT3D9));
82
+
83
+ rb_define_const(mILUT, "PALETTE_MODE", INT2NUM(ILUT_PALETTE_MODE));
84
+ rb_define_const(mILUT, "OPENGL_CONV", INT2NUM(ILUT_OPENGL_CONV));
85
+ rb_define_const(mILUT, "D3D_MIPLEVELS", INT2NUM(ILUT_D3D_MIPLEVELS));
86
+ rb_define_const(mILUT, "MAXTEX_WIDTH", INT2NUM(ILUT_MAXTEX_WIDTH));
87
+ rb_define_const(mILUT, "MAXTEX_HEIGHT", INT2NUM(ILUT_MAXTEX_HEIGHT));
88
+ rb_define_const(mILUT, "MAXTEX_DEPTH", INT2NUM(ILUT_MAXTEX_DEPTH));
89
+ rb_define_const(mILUT, "GL_USE_S3TC", INT2NUM(ILUT_GL_USE_S3TC));
90
+ rb_define_const(mILUT, "D3D_USE_DXTC", INT2NUM(ILUT_D3D_USE_DXTC));
91
+ rb_define_const(mILUT, "GL_GEN_S3TC", INT2NUM(ILUT_GL_GEN_S3TC));
92
+ rb_define_const(mILUT, "D3D_GEN_DXTC", INT2NUM(ILUT_D3D_GEN_DXTC));
93
+ rb_define_const(mILUT, "S3TC_FORMAT", INT2NUM(ILUT_S3TC_FORMAT));
94
+ rb_define_const(mILUT, "DXTC_FORMAT", INT2NUM(ILUT_DXTC_FORMAT));
95
+ rb_define_const(mILUT, "D3D_POOL", INT2NUM(ILUT_D3D_POOL));
96
+ rb_define_const(mILUT, "D3D_ALPHA_KEY_COLOR", INT2NUM(ILUT_D3D_ALPHA_KEY_COLOR));
97
+ rb_define_const(mILUT, "D3D_ALPHA_KEY_COLOUR", INT2NUM(ILUT_D3D_ALPHA_KEY_COLOUR));
98
+ }
@@ -0,0 +1,154 @@
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.0'
18
+
19
+ # loads +file+ and returns a new image
20
+ # Optionally accepts a block and yields the newly created image to the block.
21
+ def self.load_image(file, &block)
22
+ name = IL.GenImages(1).first
23
+ IL.BindImage(name)
24
+ IL.LoadImage(file)
25
+
26
+ img = Image.new(name, file)
27
+ if block
28
+ block.call(img)
29
+ end
30
+
31
+ img
32
+ end
33
+
34
+ # initializes Devil and sets defaults
35
+ # This method should never need to be called directly.
36
+ def self.init
37
+ # initialize DevIL
38
+ IL.Init
39
+
40
+ # default options
41
+ IL.Enable(IL::FILE_OVERWRITE)
42
+ ILU.ImageParameter(ILU::FILTER, ILU::BILINEAR)
43
+ end
44
+
45
+ class << self
46
+ alias_method :with_image, :load_image
47
+ end
48
+
49
+ class Image
50
+ def initialize(name, file)
51
+ @name = name
52
+ @file = file
53
+
54
+ ObjectSpace.define_finalizer( self, proc { IL.DeleteImages(1, [name]) } )
55
+ end
56
+
57
+ # returns the width of the image
58
+ def width
59
+ set_binding
60
+ IL.GetInteger(IL::IMAGE_WIDTH)
61
+ end
62
+
63
+ # returns the height of the image
64
+ def height
65
+ set_binding
66
+ IL.GetInteger(IL::IMAGE_HEIGHT)
67
+ end
68
+
69
+ # saves the image to +file+. If no +file+ is provided default to the opened file.
70
+ def save(file = @file)
71
+ set_binding
72
+ IL.SaveImage(file)
73
+ end
74
+
75
+
76
+ # resize the image to +width+ and +height+. Aspect ratios of the image do not have to be the same.
77
+ def resize(width, height)
78
+ set_binding
79
+ ILU.Scale(width, height, 1)
80
+ end
81
+
82
+ # performs a gaussian blur on the image. The blur is performed +iter+ times.
83
+ def blur(iter)
84
+ set_binding
85
+ ILU.BlurGaussian(iter)
86
+ end
87
+
88
+ # 'pixelize' the image using a pixel size of +pixel_size+
89
+ def pixelize(pixel_size)
90
+ set_binding
91
+ ILU.Pixelize(pixel_size)
92
+ end
93
+
94
+ # add random noise to the image. +factor+ is the tolerance to use.
95
+ # accepeted values range from 0.0 - 1.0
96
+ def noisify(factor)
97
+ set_binding
98
+ ILU.Noisify(factor)
99
+ end
100
+
101
+ # The sharpening +factor+ must be in the range of 0.0 - 2.5. A value of 1.0 for the sharpening
102
+ # factor will have no effect on the image. Values in the range 1.0 - 2.5 will sharpen the
103
+ # image, with 2.5 having the most pronounced sharpening effect. Values from 0.0 to 1.0 do
104
+ # a type of reverse sharpening, blurring the image. Values outside of the 0.0 - 2.5 range
105
+ # produce undefined results.
106
+ #
107
+ # The number of +iter+ (iterations) to perform will usually be 1, but to achieve more sharpening,
108
+ # increase the number of iterations.
109
+ def sharpen(factor, iter)
110
+ set_binding
111
+ ILU.Sharpen(factor, iter)
112
+ end
113
+
114
+ # applies gamma correction to an image using an exponential curve.
115
+ # +factor+ is gamma correction factor to use.
116
+ # A value of 1.0 leaves the image unmodified.
117
+ # Values in the range 0.0 - 1.0 darken the image
118
+ # Values above 1.0 brighten the image.
119
+ def gamma_correct(factor)
120
+ set_binding
121
+ ILU.GammaCorrect(factor)
122
+ end
123
+
124
+ # invert the color of every pixel in the image.
125
+ def negative
126
+ set_binding
127
+ ILU.Negative
128
+ end
129
+
130
+ # +factor+ describes desired contrast to use
131
+ # A value of 1.0 has no effect on the image.
132
+ # Values between 1.0 and 1.7 increase the amount of contrast (values above 1.7 have no effect)
133
+ # Valid range of +factor+ is 0.0 - 1.7
134
+ def contrast(factor)
135
+ set_binding
136
+ ILU.Contrast(factor)
137
+ end
138
+
139
+ # darkens the bright colours and lightens the dark
140
+ # colours, reducing the contrast in an image or 'equalizing' it.
141
+ def equalize
142
+ set_binding
143
+ ILU.Equalize
144
+ end
145
+
146
+ private
147
+
148
+ def set_binding
149
+ IL.BindImage(@name)
150
+ end
151
+ end
152
+ end
153
+
154
+ Devil.init
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devil
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jaroslaw Tworek, John Mair (banisterfiend)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-07 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ruby bindings for devil cross platform image loading library
17
+ email: jrmair@gmail.com
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/devil/extconf.rb
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - Rakefile
26
+ - README
27
+ - LICENSE
28
+ - lib/devil.rb
29
+ - ext/devil/extconf.rb
30
+ - ext/devil/ruby_devil_ext.h
31
+ - ext/devil/ruby_ilut.c
32
+ - ext/devil/ruby_devil_ext.c
33
+ - ext/devil/ruby_il.c
34
+ - ext/devil/ruby_ilu.c
35
+ has_rdoc: true
36
+ homepage: http://banisterfiend.wordpress.com
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --main
40
+ - README
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: ruby bindings for devil cross platform image loading library
62
+ test_files: []
63
+