devil 0.1.6-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README +29 -0
- data/Rakefile +76 -0
- data/ext/devil/extconf.rb +19 -0
- data/ext/devil/ruby_devil_ext.c +11 -0
- data/ext/devil/ruby_devil_ext.h +11 -0
- data/ext/devil/ruby_il.c +446 -0
- data/ext/devil/ruby_ilu.c +154 -0
- data/lib/1.8/devil.so +0 -0
- data/lib/1.9/devil.so +0 -0
- data/lib/devil.rb +226 -0
- data/lib/devil/gosu.rb +96 -0
- data/test/screenshot.png +0 -0
- data/test/tank-modified.png +0 -0
- data/test/tank.png +0 -0
- data/test/test_clone_and_crop.rb +25 -0
- data/test/test_gosu_load.rb +26 -0
- data/test/test_gosu_save.rb +26 -0
- data/test/test_gosu_show.rb +10 -0
- data/test/test_new_api.rb +25 -0
- data/test/test_screenshot.rb +33 -0
- data/test/test_thumbnail.rb +12 -0
- data/test/texture.jpg +0 -0
- data/test/texture.png +0 -0
- metadata +78 -0
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,29 @@
|
|
1
|
+
Devil version 0.1.6
|
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
|
+
For windows:
|
13
|
+
* download devil.dll and ilu.dll from here http://openil.sourceforge.net
|
14
|
+
* and copy devil.dll and ilu.dll to c:\windows\system\
|
15
|
+
|
16
|
+
For other systems:
|
17
|
+
* install libdevil and lib-devil-dev using your package manager
|
18
|
+
* OR download and install the libraries from http://openil.sourceforge.net
|
19
|
+
|
20
|
+
If you wish to use the Gosu and TexPlay extensions, it is necessary to also have:
|
21
|
+
* the Gosu gem (gem install gosu)
|
22
|
+
* the TexPlay gem (gem install texplay)
|
23
|
+
* ruby-opengl (gem install ruby-opengl)
|
24
|
+
|
25
|
+
For now, there is support for just a subset of DevIL functions, but it is enough
|
26
|
+
for 95% things you may want to do.
|
27
|
+
|
28
|
+
For example uses, see test/ directory
|
29
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
|
3
|
+
if RUBY_PLATFORM !~ /win/
|
4
|
+
require 'rake/extensiontask'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rake/gempackagetask'
|
8
|
+
require 'rake/testtask'
|
9
|
+
require 'rake/rdoctask'
|
10
|
+
|
11
|
+
DEVIL_VERSION = "0.1.6"
|
12
|
+
|
13
|
+
dlext = Config::CONFIG['DLEXT']
|
14
|
+
|
15
|
+
CLEAN.include("ext/**/*.#{dlext}", "ext/**/.log", "ext/**/.o", "ext/**/*~", "ext/**/*#*", "ext/**/.obj", "ext/**/.def", "ext/**/.pdb")
|
16
|
+
CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o", "doc/**")
|
17
|
+
|
18
|
+
spec = Gem::Specification.new do |s|
|
19
|
+
s.name = "devil"
|
20
|
+
s.summary = "ruby bindings for devil cross platform image loading library"
|
21
|
+
s.description = s.summary
|
22
|
+
s.version = DEVIL_VERSION
|
23
|
+
s.author = "Jaroslaw Tworek, John Mair (banisterfiend)"
|
24
|
+
s.email = 'jrmair@gmail.com'
|
25
|
+
s.date = Time.now.strftime '%Y-%m-%d'
|
26
|
+
s.require_path = 'lib'
|
27
|
+
s.homepage = "http://banisterfiend.wordpress.com"
|
28
|
+
|
29
|
+
if RUBY_PLATFORM =~ /win/
|
30
|
+
s.platform = Gem::Platform::CURRENT
|
31
|
+
else
|
32
|
+
s.platform = Gem::Platform::RUBY
|
33
|
+
end
|
34
|
+
|
35
|
+
if RUBY_PLATFORM !~ /win/
|
36
|
+
s.extensions = FileList["ext/**/extconf.rb"]
|
37
|
+
end
|
38
|
+
|
39
|
+
s.has_rdoc = true
|
40
|
+
s.extra_rdoc_files = ["README", "lib/devil/gosu.rb"]
|
41
|
+
s.rdoc_options << '--main' << 'README'
|
42
|
+
s.files = ["Rakefile", "README", "LICENSE", "lib/devil.rb", "lib/devil/gosu.rb"] +
|
43
|
+
FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "test/test*.rb", "test/*.jpg", "test/*.png"].to_a
|
44
|
+
|
45
|
+
if RUBY_PLATFORM =~ /win/
|
46
|
+
s.files += ["lib/1.8/devil.so", "lib/1.9/devil.so"]
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
52
|
+
pkg.need_zip = false
|
53
|
+
pkg.need_tar = false
|
54
|
+
end
|
55
|
+
|
56
|
+
task :compile => :clean
|
57
|
+
|
58
|
+
if RUBY_PLATFORM !~ /win/
|
59
|
+
Rake::ExtensionTask.new('devil', spec) do |ext|
|
60
|
+
ext.config_script = 'extconf.rb'
|
61
|
+
ext.cross_compile = true
|
62
|
+
ext.cross_platform = 'i386-mswin32'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
Rake::TestTask.new do |t|
|
67
|
+
t.libs << "lib"
|
68
|
+
t.test_files = FileList['test/test*.rb']
|
69
|
+
t.verbose = true
|
70
|
+
end
|
71
|
+
|
72
|
+
Rake::RDocTask.new do |rd|
|
73
|
+
rd.main = "README"
|
74
|
+
rd.rdoc_files.include("README", "lib/devil.rb", "lib/devil/gosu.rb")
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
if RUBY_PLATFORM =~ /mingw/
|
4
|
+
$CFLAGS += ' -I/home/john/.rake-compiler/ruby/ruby-1.8.6-p287/include/'
|
5
|
+
$LDFLAGS += ' -L/home/john/.rake-compiler/ruby/ruby-1.8.6-p287/lib/'
|
6
|
+
end
|
7
|
+
|
8
|
+
puts "platform is #{RUBY_PLATFORM}"
|
9
|
+
if RUBY_PLATFORM =~ /win/ || RUBY_PLATFORM =~ /mingw/
|
10
|
+
exit unless have_library("DevIL");
|
11
|
+
else
|
12
|
+
exit unless have_library("IL");
|
13
|
+
end
|
14
|
+
|
15
|
+
exit unless have_library("ILU");
|
16
|
+
|
17
|
+
#have_library("ILUT", "ilutInit");
|
18
|
+
|
19
|
+
create_makefile('devil')
|
data/ext/devil/ruby_il.c
ADDED
@@ -0,0 +1,446 @@
|
|
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
|
+
|
121
|
+
/* from ILvoid */
|
122
|
+
void* data = ImageData2Arr(rb_data);
|
123
|
+
|
124
|
+
ILboolean flag = ilTexImage(width, height, depth,
|
125
|
+
bpp, format, type, data);
|
126
|
+
return flag ? Qtrue : Qfalse;
|
127
|
+
}
|
128
|
+
|
129
|
+
static VALUE il_GetData(VALUE obj) {
|
130
|
+
ILubyte* data = ilGetData();
|
131
|
+
return MakeImageData(data);
|
132
|
+
}
|
133
|
+
|
134
|
+
/* ILuint ilCopyPixels(ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width, */
|
135
|
+
/* /\* changed from ILvoid *\/ */
|
136
|
+
/* ILuint Height, ILuint Depth, ILenum Format, ILenum Type, void */
|
137
|
+
/* *Data); */
|
138
|
+
|
139
|
+
/* static VALUE il_CopyPixels(VALUE obj, VALUE rb_XOff, VALUE rb_YOff, VALUE rb_ZOff, */
|
140
|
+
/* VALUE rb_Width, VALUE rb_Height, VALUE rb_Depth, VALUE rb_Format, */
|
141
|
+
/* VALUE rb_Type, VALUE rb_data) { */
|
142
|
+
/* ILuint XOff = NUM2INT(rb_XOff); */
|
143
|
+
/* ILuint YOff = NUM2INT(rb_YOff); */
|
144
|
+
/* ILuint ZOff = NUM2INT(rb_ZOff); */
|
145
|
+
/* ILuint Width = NUM2INT(rb_Width); */
|
146
|
+
/* ILuint Height = NUM2INT(rb_Height); */
|
147
|
+
/* ILuint Depth = NUM2INT(rb_Depth); */
|
148
|
+
/* ILenum Format = NUM2INT(rb_Format); */
|
149
|
+
/* ILenum Type = NUM2INT(rb_Type); */
|
150
|
+
/* /\* ILvoid *\/ */
|
151
|
+
/* void* data = ImageData2Arr(rb_data); */
|
152
|
+
|
153
|
+
/* ILuint uint = ilCopyPixels(XOff, YOff, ZOff, Width, Height, Depth, Format, Type, data); */
|
154
|
+
/* return INT2FIX(uint); */
|
155
|
+
/* } */
|
156
|
+
|
157
|
+
static VALUE il_SetData(VALUE obj, VALUE rb_Data) {
|
158
|
+
/* ILvoid */
|
159
|
+
void* data = ImageData2Arr(rb_Data);
|
160
|
+
ILboolean flag = ilSetData(data);
|
161
|
+
return flag ? Qtrue : Qfalse;
|
162
|
+
}
|
163
|
+
|
164
|
+
static VALUE il_SetPixels(VALUE obj, VALUE rb_XOff, VALUE rb_YOff, VALUE rb_ZOff,
|
165
|
+
VALUE rb_Width, VALUE rb_Height, VALUE rb_Depth, VALUE rb_Format,
|
166
|
+
VALUE rb_Type, VALUE rb_data) {
|
167
|
+
ILuint XOff = NUM2INT(rb_XOff);
|
168
|
+
ILuint YOff = NUM2INT(rb_YOff);
|
169
|
+
ILuint ZOff = NUM2INT(rb_ZOff);
|
170
|
+
ILuint Width = NUM2INT(rb_Width);
|
171
|
+
ILuint Height = NUM2INT(rb_Height);
|
172
|
+
ILuint Depth = NUM2INT(rb_Depth);
|
173
|
+
ILenum Format = NUM2INT(rb_Format);
|
174
|
+
ILenum Type = NUM2INT(rb_Type);
|
175
|
+
/* ILvoid */
|
176
|
+
void* data = ImageData2Arr(rb_data);
|
177
|
+
|
178
|
+
ilSetPixels(XOff, YOff, ZOff, Width, Height, Depth, Format, Type, data);
|
179
|
+
return Qnil;
|
180
|
+
}
|
181
|
+
|
182
|
+
|
183
|
+
static VALUE il_CopyImage(VALUE obj, VALUE rb_Src){
|
184
|
+
ILuint Src = NUM2INT(rb_Src);
|
185
|
+
ILboolean flag = ilCopyImage(Src);
|
186
|
+
return flag ? Qtrue : Qfalse;
|
187
|
+
}
|
188
|
+
|
189
|
+
static VALUE il_OverlayImage(VALUE obj, VALUE rb_Source, VALUE rb_XCoord,
|
190
|
+
VALUE rb_YCoord, VALUE rb_ZCoord) {
|
191
|
+
ILuint Source = NUM2INT(rb_Source);
|
192
|
+
ILint XCoord = NUM2INT(rb_XCoord);
|
193
|
+
ILint YCoord = NUM2INT(rb_YCoord);
|
194
|
+
ILint ZCoord = NUM2INT(rb_ZCoord);
|
195
|
+
ILboolean flag = ilOverlayImage(Source, XCoord, YCoord,ZCoord);
|
196
|
+
|
197
|
+
return flag ? Qtrue : Qfalse;
|
198
|
+
}
|
199
|
+
|
200
|
+
|
201
|
+
static VALUE il_Blit(VALUE obj, VALUE rb_Source, VALUE rb_DestX, VALUE
|
202
|
+
rb_DestY, VALUE rb_DestZ, VALUE rb_SrcX, VALUE rb_SrcY, VALUE
|
203
|
+
rb_SrcZ, VALUE rb_Width, VALUE rb_Height, VALUE rb_Depth) {
|
204
|
+
ILuint Source = NUM2INT(rb_Source);
|
205
|
+
ILint DestX = NUM2INT(rb_DestX);
|
206
|
+
ILint DestY = NUM2INT(rb_DestY);
|
207
|
+
ILint DestZ = NUM2INT(rb_DestZ);
|
208
|
+
ILint SrcX = NUM2INT(rb_SrcX);
|
209
|
+
ILint SrcY = NUM2INT(rb_SrcY);
|
210
|
+
ILint SrcZ = NUM2INT(rb_SrcZ);
|
211
|
+
ILuint Width = NUM2INT(rb_Width);
|
212
|
+
ILuint Height = NUM2INT(rb_Height);
|
213
|
+
ILuint Depth = NUM2INT(rb_Depth);
|
214
|
+
|
215
|
+
ILboolean flag = ilBlit(Source, DestX,DestY, DestZ,SrcX, SrcY, SrcZ,
|
216
|
+
Width,Height,Depth);
|
217
|
+
return flag ? Qtrue : Qfalse;
|
218
|
+
}
|
219
|
+
|
220
|
+
static VALUE il_GetError(VALUE obj) {
|
221
|
+
ILenum num = ilGetError();
|
222
|
+
return INT2FIX(num);
|
223
|
+
}
|
224
|
+
|
225
|
+
static VALUE il_ActiveMipmap(VALUE obj, VALUE rb_Number) {
|
226
|
+
ILuint Number = NUM2INT(rb_Number);
|
227
|
+
ILboolean flag = ilActiveMipmap(Number);
|
228
|
+
return flag ? Qtrue : Qfalse;
|
229
|
+
}
|
230
|
+
|
231
|
+
static VALUE il_ActiveImage(VALUE obj, VALUE rb_Number){
|
232
|
+
ILuint Number = NUM2INT(rb_Number);
|
233
|
+
ILboolean flag = ilActiveImage(Number);
|
234
|
+
return flag ? Qtrue : Qfalse;
|
235
|
+
}
|
236
|
+
|
237
|
+
/* methods below added by banisterfiend */
|
238
|
+
static VALUE il_Enable(VALUE obj, VALUE rb_mode) {
|
239
|
+
ILenum mode = NUM2INT(rb_mode);
|
240
|
+
|
241
|
+
ILboolean flag = ilEnable(mode);
|
242
|
+
return flag ? Qtrue : Qfalse;
|
243
|
+
}
|
244
|
+
|
245
|
+
static VALUE il_GetInteger(VALUE obj, VALUE rb_mode) {
|
246
|
+
ILenum mode = NUM2INT(rb_mode);
|
247
|
+
|
248
|
+
ILint result = ilGetInteger(mode);
|
249
|
+
return INT2NUM(result);
|
250
|
+
}
|
251
|
+
|
252
|
+
static VALUE il_ConvertImage(VALUE obj, VALUE rb_destformat, VALUE rb_desttype)
|
253
|
+
{
|
254
|
+
ILenum destformat = NUM2INT(rb_destformat);
|
255
|
+
ILenum desttype = NUM2INT(rb_desttype);
|
256
|
+
|
257
|
+
ILboolean flag = ilConvertImage(destformat, desttype);
|
258
|
+
return flag ? Qtrue : Qfalse;
|
259
|
+
}
|
260
|
+
|
261
|
+
/* this function is not actualy in the DevIL API, but im adding it here for convenience */
|
262
|
+
static VALUE bf_ToBlob(VALUE obj)
|
263
|
+
{
|
264
|
+
ILuint width, height;
|
265
|
+
char * img_ptr;
|
266
|
+
VALUE blob;
|
267
|
+
|
268
|
+
ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
|
269
|
+
|
270
|
+
width = ilGetInteger(IL_IMAGE_WIDTH);
|
271
|
+
height = ilGetInteger(IL_IMAGE_HEIGHT);
|
272
|
+
|
273
|
+
img_ptr = (char *)ilGetData();
|
274
|
+
|
275
|
+
blob = rb_str_new(img_ptr, 4 * width * height);
|
276
|
+
|
277
|
+
return blob;
|
278
|
+
}
|
279
|
+
|
280
|
+
static VALUE bf_FromBlob(VALUE obj, VALUE blob, VALUE rb_width, VALUE rb_height)
|
281
|
+
{
|
282
|
+
ILubyte * data;
|
283
|
+
ILuint width, height;
|
284
|
+
ILuint image;
|
285
|
+
|
286
|
+
width = NUM2INT(rb_width);
|
287
|
+
height = NUM2INT(rb_height);
|
288
|
+
|
289
|
+
data = (ILubyte *) RSTRING_PTR(blob);
|
290
|
+
|
291
|
+
ilGenImages(1, &image);
|
292
|
+
ilBindImage(image);
|
293
|
+
|
294
|
+
ilTexImage(width, height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, data);
|
295
|
+
|
296
|
+
return INT2NUM(image);
|
297
|
+
}
|
298
|
+
|
299
|
+
static VALUE il_CloneCurImage(VALUE obj)
|
300
|
+
{
|
301
|
+
ILuint clone = ilCloneCurImage();
|
302
|
+
|
303
|
+
return INT2NUM(clone);
|
304
|
+
}
|
305
|
+
/* end of banisterfiend additions */
|
306
|
+
|
307
|
+
void
|
308
|
+
InitializeIL() {
|
309
|
+
mIL = rb_define_module("IL");
|
310
|
+
//////////////////////////////////
|
311
|
+
//CLASSES
|
312
|
+
//////////////////////////////////
|
313
|
+
cImageData = rb_define_class_under(mIL, "ImageData", rb_cObject);
|
314
|
+
cNullImageData = MakeImageData(NULL);
|
315
|
+
rb_define_const(cImageData, "NullData", cNullImageData);
|
316
|
+
//////////////////////////////////
|
317
|
+
//METHODS
|
318
|
+
//////////////////////////////////
|
319
|
+
rb_define_module_function(mIL, "Init", il_Init, 0);
|
320
|
+
rb_define_module_function(mIL, "GenImages", il_GenImages, 1);
|
321
|
+
rb_define_module_function(mIL, "BindImage", il_BindImage, 1);
|
322
|
+
rb_define_module_function(mIL, "DeleteImages", il_DeleteImages, 1);
|
323
|
+
rb_define_module_function(mIL, "LoadImage", il_LoadImage, 1);
|
324
|
+
rb_define_module_function(mIL, "Load", il_Load, 2);
|
325
|
+
rb_define_module_function(mIL, "SaveImage", il_SaveImage, 1);
|
326
|
+
rb_define_module_function(mIL, "Save", il_Save, 2);
|
327
|
+
rb_define_module_function(mIL, "TexImage", il_TexImage, 7);
|
328
|
+
rb_define_module_function(mIL, "GetData", il_GetData, 0);
|
329
|
+
/* rb_define_module_function(mIL, "CopyPixels", il_CopyPixels, 9); */
|
330
|
+
rb_define_module_function(mIL, "SetData", il_SetData, 1);
|
331
|
+
rb_define_module_function(mIL, "SetPixels", il_SetPixels, 9);
|
332
|
+
rb_define_module_function(mIL, "CopyImage", il_CopyImage, 1);
|
333
|
+
rb_define_module_function(mIL, "OverlayImage", il_OverlayImage, 4);
|
334
|
+
rb_define_module_function(mIL, "Blit", il_Blit, 10);
|
335
|
+
rb_define_module_function(mIL, "GetError", il_GetError, 0);
|
336
|
+
rb_define_module_function(mIL, "ActiveMipmap", il_ActiveMipmap, 1);
|
337
|
+
rb_define_module_function(mIL, "ActiveImage", il_ActiveImage, 1);
|
338
|
+
|
339
|
+
/* methods added by baniterfiend */
|
340
|
+
rb_define_module_function(mIL, "Enable", il_Enable, 1);
|
341
|
+
rb_define_module_function(mIL, "GetInteger", il_GetInteger, 1);
|
342
|
+
rb_define_module_function(mIL, "ConvertImage", il_ConvertImage, 2);
|
343
|
+
rb_define_module_function(mIL, "ToBlob", bf_ToBlob, 0);
|
344
|
+
rb_define_module_function(mIL, "FromBlob", bf_FromBlob, 3);
|
345
|
+
rb_define_module_function(mIL, "CloneCurImage", il_CloneCurImage, 0);
|
346
|
+
/* end of methods added by banisterfiend */
|
347
|
+
|
348
|
+
//////////////////////////////////
|
349
|
+
//CONSTANTS
|
350
|
+
//////////////////////////////////
|
351
|
+
rb_define_const(mIL, "TYPE_UNKNOWN", INT2NUM(IL_TYPE_UNKNOWN));
|
352
|
+
rb_define_const(mIL, "BMP", INT2NUM(IL_BMP));
|
353
|
+
rb_define_const(mIL, "CUT", INT2NUM(IL_CUT));
|
354
|
+
rb_define_const(mIL, "DOOM", INT2NUM(IL_DOOM));
|
355
|
+
rb_define_const(mIL, "DOOM_FLAT", INT2NUM(IL_DOOM_FLAT));
|
356
|
+
rb_define_const(mIL, "ICO", INT2NUM(IL_ICO));
|
357
|
+
rb_define_const(mIL, "JPG", INT2NUM(IL_JPG));
|
358
|
+
rb_define_const(mIL, "JFIF", INT2NUM(IL_JFIF));
|
359
|
+
|
360
|
+
#ifdef _WIN32
|
361
|
+
rb_define_const(mIL, "LBM", INT2NUM(IL_ILBM));
|
362
|
+
#else
|
363
|
+
rb_define_const(mIL, "LBM", INT2NUM(IL_LBM));
|
364
|
+
#endif
|
365
|
+
|
366
|
+
rb_define_const(mIL, "PCD", INT2NUM(IL_PCD));
|
367
|
+
rb_define_const(mIL, "PCX", INT2NUM(IL_PCX));
|
368
|
+
rb_define_const(mIL, "PIC", INT2NUM(IL_PIC));
|
369
|
+
rb_define_const(mIL, "PNG", INT2NUM(IL_PNG));
|
370
|
+
rb_define_const(mIL, "PNM", INT2NUM(IL_PNM));
|
371
|
+
rb_define_const(mIL, "SGI", INT2NUM(IL_SGI));
|
372
|
+
rb_define_const(mIL, "TGA", INT2NUM(IL_TGA));
|
373
|
+
rb_define_const(mIL, "TIF", INT2NUM(IL_TIF));
|
374
|
+
rb_define_const(mIL, "CHEAD", INT2NUM(IL_CHEAD));
|
375
|
+
rb_define_const(mIL, "RAW", INT2NUM(IL_RAW));
|
376
|
+
rb_define_const(mIL, "MDL", INT2NUM(IL_MDL));
|
377
|
+
rb_define_const(mIL, "WAL", INT2NUM(IL_WAL));
|
378
|
+
rb_define_const(mIL, "LIF", INT2NUM(IL_LIF));
|
379
|
+
rb_define_const(mIL, "MNG", INT2NUM(IL_MNG));
|
380
|
+
rb_define_const(mIL, "JNG", INT2NUM(IL_JNG));
|
381
|
+
rb_define_const(mIL, "GIF", INT2NUM(IL_GIF));
|
382
|
+
rb_define_const(mIL, "DDS", INT2NUM(IL_DDS));
|
383
|
+
rb_define_const(mIL, "DCX", INT2NUM(IL_DCX));
|
384
|
+
rb_define_const(mIL, "PSD", INT2NUM(IL_PSD));
|
385
|
+
rb_define_const(mIL, "EXIF", INT2NUM(IL_EXIF));
|
386
|
+
rb_define_const(mIL, "PSP", INT2NUM(IL_PSP));
|
387
|
+
rb_define_const(mIL, "PIX", INT2NUM(IL_PIX));
|
388
|
+
rb_define_const(mIL, "PXR", INT2NUM(IL_PXR));
|
389
|
+
rb_define_const(mIL, "XPM", INT2NUM(IL_XPM));
|
390
|
+
rb_define_const(mIL, "HDR", INT2NUM(IL_HDR));
|
391
|
+
rb_define_const(mIL, "JASC_PAL", INT2NUM(IL_JASC_PAL));
|
392
|
+
|
393
|
+
rb_define_const(mIL, "COLOUR_INDEX", INT2NUM(IL_COLOUR_INDEX));
|
394
|
+
rb_define_const(mIL, "COLOR_INDEX", INT2NUM(IL_COLOR_INDEX));
|
395
|
+
rb_define_const(mIL, "RGB", INT2NUM(IL_RGB));
|
396
|
+
rb_define_const(mIL, "RGBA", INT2NUM(IL_RGBA));
|
397
|
+
rb_define_const(mIL, "BGR", INT2NUM(IL_BGR));
|
398
|
+
rb_define_const(mIL, "BGRA", INT2NUM(IL_BGRA));
|
399
|
+
rb_define_const(mIL, "LUMINANCE", INT2NUM(IL_LUMINANCE));
|
400
|
+
rb_define_const(mIL, "LUMINANCE_ALPHA", INT2NUM(IL_LUMINANCE_ALPHA));
|
401
|
+
|
402
|
+
rb_define_const(mIL, "UNSIGNED_BYTE", INT2NUM(IL_UNSIGNED_BYTE));
|
403
|
+
rb_define_const(mIL, "SHORT", INT2NUM(IL_SHORT));
|
404
|
+
rb_define_const(mIL, "UNSIGNED_SHORT", INT2NUM(IL_UNSIGNED_SHORT));
|
405
|
+
rb_define_const(mIL, "INT", INT2NUM(IL_INT));
|
406
|
+
rb_define_const(mIL, "UNSIGNED_INT", INT2NUM(IL_UNSIGNED_INT));
|
407
|
+
rb_define_const(mIL, "FLOAT", INT2NUM(IL_FLOAT));
|
408
|
+
rb_define_const(mIL, "DOUBLE", INT2NUM(IL_DOUBLE));
|
409
|
+
|
410
|
+
rb_define_const(mIL, "NO_ERROR", INT2NUM(IL_NO_ERROR));
|
411
|
+
rb_define_const(mIL, "INVALID_ENUM", INT2NUM(IL_INVALID_ENUM));
|
412
|
+
rb_define_const(mIL, "OUT_OF_MEMORY", INT2NUM(IL_OUT_OF_MEMORY));
|
413
|
+
rb_define_const(mIL, "FORMAT_NOT_SUPPORTED", INT2NUM(IL_FORMAT_NOT_SUPPORTED));
|
414
|
+
rb_define_const(mIL, "INTERNAL_ERROR", INT2NUM(IL_INTERNAL_ERROR));
|
415
|
+
rb_define_const(mIL, "INVALID_VALUE", INT2NUM(IL_INVALID_VALUE));
|
416
|
+
rb_define_const(mIL, "ILLEGAL_OPERATION", INT2NUM(IL_ILLEGAL_OPERATION));
|
417
|
+
rb_define_const(mIL, "ILLEGAL_FILE_VALUE", INT2NUM(IL_ILLEGAL_FILE_VALUE));
|
418
|
+
rb_define_const(mIL, "INVALID_FILE_HEADER", INT2NUM(IL_INVALID_FILE_HEADER));
|
419
|
+
rb_define_const(mIL, "INVALID_PARAM", INT2NUM(IL_INVALID_PARAM));
|
420
|
+
rb_define_const(mIL, "COULD_NOT_OPEN_FILE", INT2NUM(IL_COULD_NOT_OPEN_FILE));
|
421
|
+
rb_define_const(mIL, "INVALID_EXTENSION", INT2NUM(IL_INVALID_EXTENSION));
|
422
|
+
rb_define_const(mIL, "FILE_ALREADY_EXISTS", INT2NUM(IL_FILE_ALREADY_EXISTS));
|
423
|
+
rb_define_const(mIL, "OUT_FORMAT_SAME", INT2NUM(IL_OUT_FORMAT_SAME));
|
424
|
+
rb_define_const(mIL, "STACK_OVERFLOW", INT2NUM(IL_STACK_OVERFLOW));
|
425
|
+
rb_define_const(mIL, "STACK_UNDERFLOW", INT2NUM(IL_STACK_UNDERFLOW));
|
426
|
+
rb_define_const(mIL, "INVALID_CONVERSION", INT2NUM(IL_INVALID_CONVERSION));
|
427
|
+
rb_define_const(mIL, "BAD_DIMENSIONS", INT2NUM(IL_BAD_DIMENSIONS));
|
428
|
+
rb_define_const(mIL, "FILE_READ_ERROR", INT2NUM(IL_FILE_READ_ERROR));
|
429
|
+
rb_define_const(mIL, "FILE_WRITE_ERROR", INT2NUM(IL_FILE_WRITE_ERROR));
|
430
|
+
rb_define_const(mIL, "LIB_GIF_ERROR", INT2NUM(IL_LIB_GIF_ERROR));
|
431
|
+
rb_define_const(mIL, "LIB_JPEG_ERROR", INT2NUM(IL_LIB_JPEG_ERROR));
|
432
|
+
rb_define_const(mIL, "LIB_PNG_ERROR", INT2NUM(IL_LIB_PNG_ERROR));
|
433
|
+
rb_define_const(mIL, "LIB_TIFF_ERROR", INT2NUM(IL_LIB_TIFF_ERROR));
|
434
|
+
rb_define_const(mIL, "LIB_MNG_ERROR", INT2NUM(IL_LIB_MNG_ERROR));
|
435
|
+
rb_define_const(mIL, "UNKNOWN_ERROR", INT2NUM(IL_UNKNOWN_ERROR));
|
436
|
+
|
437
|
+
// CONSTANTS BELOW ADDED BY BANISTERFIEND
|
438
|
+
rb_define_const(mIL, "IMAGE_WIDTH", INT2NUM(IL_IMAGE_WIDTH));
|
439
|
+
rb_define_const(mIL, "IMAGE_HEIGHT", INT2NUM(IL_IMAGE_HEIGHT));
|
440
|
+
rb_define_const(mIL, "IMAGE_FORMAT", INT2NUM(IL_IMAGE_FORMAT));
|
441
|
+
rb_define_const(mIL, "FILE_OVERWRITE", INT2NUM(IL_FILE_OVERWRITE));
|
442
|
+
}
|
443
|
+
//////////////////////////////////////////
|
444
|
+
|
445
|
+
//////////////////////////////////////////
|
446
|
+
|