Module: IL

Included in:
Devil
Defined in:
ext/devil/ruby_il.c

Defined Under Namespace

Classes: ImageData

Constant Summary

TYPE_UNKNOWN =

////////////////////////////////

INT2NUM(IL_TYPE_UNKNOWN)
BMP =
INT2NUM(IL_BMP)
CUT =
INT2NUM(IL_CUT)
DOOM =
INT2NUM(IL_DOOM)
DOOM_FLAT =
INT2NUM(IL_DOOM_FLAT)
ICO =
INT2NUM(IL_ICO)
JPG =
INT2NUM(IL_JPG)
JFIF =
INT2NUM(IL_JFIF)
LBM =
INT2NUM(IL_LBM)
PCD =
INT2NUM(IL_PCD)
PCX =
INT2NUM(IL_PCX)
PIC =
INT2NUM(IL_PIC)
PNG =
INT2NUM(IL_PNG)
PNM =
INT2NUM(IL_PNM)
SGI =
INT2NUM(IL_SGI)
TGA =
INT2NUM(IL_TGA)
TIF =
INT2NUM(IL_TIF)
CHEAD =
INT2NUM(IL_CHEAD)
RAW =
INT2NUM(IL_RAW)
MDL =
INT2NUM(IL_MDL)
WAL =
INT2NUM(IL_WAL)
LIF =
INT2NUM(IL_LIF)
MNG =
INT2NUM(IL_MNG)
JNG =
INT2NUM(IL_JNG)
GIF =
INT2NUM(IL_GIF)
DDS =
INT2NUM(IL_DDS)
DCX =
INT2NUM(IL_DCX)
PSD =
INT2NUM(IL_PSD)
EXIF =
INT2NUM(IL_EXIF)
PSP =
INT2NUM(IL_PSP)
PIX =
INT2NUM(IL_PIX)
PXR =
INT2NUM(IL_PXR)
XPM =
INT2NUM(IL_XPM)
HDR =
INT2NUM(IL_HDR)
JASC_PAL =
INT2NUM(IL_JASC_PAL)
COLOUR_INDEX =
INT2NUM(IL_COLOUR_INDEX)
COLOR_INDEX =
INT2NUM(IL_COLOR_INDEX)
RGB =
INT2NUM(IL_RGB)
RGBA =
INT2NUM(IL_RGBA)
BGR =
INT2NUM(IL_BGR)
BGRA =
INT2NUM(IL_BGRA)
LUMINANCE =
INT2NUM(IL_LUMINANCE)
LUMINANCE_ALPHA =
INT2NUM(IL_LUMINANCE_ALPHA)
UNSIGNED_BYTE =
INT2NUM(IL_UNSIGNED_BYTE)
SHORT =
INT2NUM(IL_SHORT)
UNSIGNED_SHORT =
INT2NUM(IL_UNSIGNED_SHORT)
INT =
INT2NUM(IL_INT)
UNSIGNED_INT =
INT2NUM(IL_UNSIGNED_INT)
FLOAT =
INT2NUM(IL_FLOAT)
DOUBLE =
INT2NUM(IL_DOUBLE)
NO_ERROR =
INT2NUM(IL_NO_ERROR)
INVALID_ENUM =
INT2NUM(IL_INVALID_ENUM)
OUT_OF_MEMORY =
INT2NUM(IL_OUT_OF_MEMORY)
FORMAT_NOT_SUPPORTED =
INT2NUM(IL_FORMAT_NOT_SUPPORTED)
INTERNAL_ERROR =
INT2NUM(IL_INTERNAL_ERROR)
INVALID_VALUE =
INT2NUM(IL_INVALID_VALUE)
ILLEGAL_OPERATION =
INT2NUM(IL_ILLEGAL_OPERATION)
ILLEGAL_FILE_VALUE =
INT2NUM(IL_ILLEGAL_FILE_VALUE)
INVALID_FILE_HEADER =
INT2NUM(IL_INVALID_FILE_HEADER)
INVALID_PARAM =
INT2NUM(IL_INVALID_PARAM)
COULD_NOT_OPEN_FILE =
INT2NUM(IL_COULD_NOT_OPEN_FILE)
INVALID_EXTENSION =
INT2NUM(IL_INVALID_EXTENSION)
FILE_ALREADY_EXISTS =
INT2NUM(IL_FILE_ALREADY_EXISTS)
OUT_FORMAT_SAME =
INT2NUM(IL_OUT_FORMAT_SAME)
STACK_OVERFLOW =
INT2NUM(IL_STACK_OVERFLOW)
STACK_UNDERFLOW =
INT2NUM(IL_STACK_UNDERFLOW)
INVALID_CONVERSION =
INT2NUM(IL_INVALID_CONVERSION)
BAD_DIMENSIONS =
INT2NUM(IL_BAD_DIMENSIONS)
FILE_READ_ERROR =
INT2NUM(IL_FILE_READ_ERROR)
FILE_WRITE_ERROR =
INT2NUM(IL_FILE_WRITE_ERROR)
LIB_GIF_ERROR =
INT2NUM(IL_LIB_GIF_ERROR)
LIB_JPEG_ERROR =
INT2NUM(IL_LIB_JPEG_ERROR)
LIB_PNG_ERROR =
INT2NUM(IL_LIB_PNG_ERROR)
LIB_TIFF_ERROR =
INT2NUM(IL_LIB_TIFF_ERROR)
LIB_MNG_ERROR =
INT2NUM(IL_LIB_MNG_ERROR)
UNKNOWN_ERROR =
INT2NUM(IL_UNKNOWN_ERROR)
IMAGE_DEPTH =

CONSTANTS BELOW ADDED BY BANISTERFIEND

INT2NUM(IL_IMAGE_DEPTH)
IMAGE_WIDTH =
INT2NUM(IL_IMAGE_WIDTH)
IMAGE_HEIGHT =
INT2NUM(IL_IMAGE_HEIGHT)
IMAGE_FORMAT =
INT2NUM(IL_IMAGE_FORMAT)
IMAGE_BITS_PER_PIXEL =
INT2NUM(IL_IMAGE_BITS_PER_PIXEL)
IMAGE_BYTES_PER_PIXEL =
INT2NUM(IL_IMAGE_BYTES_PER_PIXEL)
FILE_OVERWRITE =
INT2NUM(IL_FILE_OVERWRITE)
ORIGIN_SET =
INT2NUM(IL_ORIGIN_SET)
CONV_PAL =
INT2NUM(IL_CONV_PAL)
CUR_IMAGE =
INT2NUM(IL_CUR_IMAGE)
ORIGIN_LOWER_LEFT =
INT2NUM(IL_ORIGIN_LOWER_LEFT)
ORIGIN_UPPER_LEFT =
INT2NUM(IL_ORIGIN_UPPER_LEFT)
JPG_QUALITY =
INT2NUM(IL_JPG_QUALITY)

Class Method Summary (collapse)

Class Method Details

+ (Object) ActiveImage



237
238
239
240
241
# File 'ext/devil/ruby_il.c', line 237

static VALUE il_ActiveImage(VALUE obj, VALUE rb_Number){
    ILuint Number = NUM2INT(rb_Number);
    ILboolean flag = ilActiveImage(Number);
    return flag ? Qtrue : Qfalse;
}

+ (Object) ActiveMipmap



231
232
233
234
235
# File 'ext/devil/ruby_il.c', line 231

static VALUE il_ActiveMipmap(VALUE obj, VALUE rb_Number) {
    ILuint Number = NUM2INT(rb_Number);
    ILboolean flag = ilActiveMipmap(Number);
    return flag ? Qtrue : Qfalse;
}

+ (Object) ApplyProfile



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'ext/devil/ruby_il.c', line 258

static VALUE il_ApplyProfile(VALUE obj, VALUE rb_inprofile, VALUE rb_outprofile)
{
    char * inprofile = NULL;
    char * outprofile = StringValuePtr(rb_outprofile);
    ILboolean flag;

    if(NIL_P(rb_inprofile))
        inprofile = NULL;
    else
        inprofile = StringValuePtr(rb_inprofile);

    flag = ilApplyProfile(inprofile, outprofile);

    return flag ? Qtrue : Qfalse;
}

+ (Object) BindImage



51
52
53
54
55
# File 'ext/devil/ruby_il.c', line 51

static VALUE il_BindImage(VALUE obj, VALUE image) {
    ILuint u_image = NUM2INT(image);
    ilBindImage(u_image);
    return Qnil;
}

+ (Object) Blit



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'ext/devil/ruby_il.c', line 207

static VALUE il_Blit(VALUE obj, VALUE rb_Source, VALUE rb_DestX, VALUE
                     rb_DestY, VALUE rb_DestZ, VALUE rb_SrcX, VALUE rb_SrcY, VALUE
                     rb_SrcZ, VALUE rb_Width, VALUE rb_Height, VALUE rb_Depth) {
    ILuint Source = NUM2INT(rb_Source);
    ILint DestX = NUM2INT(rb_DestX);
    ILint DestY = NUM2INT(rb_DestY);
    ILint DestZ = NUM2INT(rb_DestZ);
    ILint SrcX = NUM2INT(rb_SrcX);
    ILint SrcY = NUM2INT(rb_SrcY);
    ILint SrcZ = NUM2INT(rb_SrcZ);
    ILuint Width = NUM2INT(rb_Width);
    ILuint Height = NUM2INT(rb_Height);
    ILuint Depth = NUM2INT(rb_Depth);

    ILboolean flag = ilBlit(Source, DestX,DestY, DestZ,SrcX, SrcY, SrcZ,
                            Width,Height,Depth);
    return flag ? Qtrue : Qfalse;
}

+ (Object) ClearColour



362
363
364
365
366
367
368
369
370
371
372
# File 'ext/devil/ruby_il.c', line 362

static VALUE il_ClearColour(VALUE obj, VALUE rb_red, VALUE rb_green, VALUE rb_blue, VALUE rb_alpha)
{
    ILubyte red = NUM2INT(rb_red);
    ILubyte green = NUM2INT(rb_green);
    ILubyte blue = NUM2INT(rb_blue);
    ILubyte alpha = NUM2INT(rb_alpha);

    ilClearColour(red, green, blue, alpha);

    return Qnil;
}

+ (Object) ClearImage



374
375
376
377
378
# File 'ext/devil/ruby_il.c', line 374

static VALUE il_ClearImage(VALUE obj)
{
    ILboolean flag = ilClearImage();
    return flag ? Qtrue : Qfalse;
}

+ (Object) CloneCurImage



347
348
349
350
351
352
# File 'ext/devil/ruby_il.c', line 347

static VALUE il_CloneCurImage(VALUE obj)
{
    ILuint clone = ilCloneCurImage();

    return INT2NUM(clone);
}

+ (Object) ConvertImage



281
282
283
284
285
286
287
288
# File 'ext/devil/ruby_il.c', line 281

static VALUE il_ConvertImage(VALUE obj, VALUE rb_destformat, VALUE rb_desttype)
{
    ILenum destformat = NUM2INT(rb_destformat);
    ILenum desttype = NUM2INT(rb_desttype);

    ILboolean flag = ilConvertImage(destformat, desttype);
    return flag ? Qtrue : Qfalse;
}

+ (Object) CopyImage



189
190
191
192
193
# File 'ext/devil/ruby_il.c', line 189

static VALUE il_CopyImage(VALUE obj, VALUE rb_Src){
    ILuint Src = NUM2INT(rb_Src);
    ILboolean flag = ilCopyImage(Src);
    return flag ? Qtrue : Qfalse;
}

+ (Object) DeleteImages



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'ext/devil/ruby_il.c', line 57

static VALUE il_DeleteImages(VALUE obj, VALUE images) {
    ILsizei num;
    ILuint* u_images;
    RArray* ary;
    VALUE entry;
    int i = 0;

    if(TYPE(images) != T_ARRAY)
	rb_raise(rb_eTypeError, "type mismatch:%s", rb_class2name(images));

    ary = RARRAY(images);
    num = RARRAY_LEN(images);
    u_images = ALLOC_N(ILuint, num);

    for(i = 0; i < num; ++i) {
	entry = rb_ary_entry((VALUE)ary, i);
	u_images[i] = NUM2INT(entry);
    }

    ilDeleteImages(num, u_images);

    free(u_images);
    return Qnil;
}

+ (Object) Disable



251
252
253
254
255
256
# File 'ext/devil/ruby_il.c', line 251

static VALUE il_Disable(VALUE obj, VALUE rb_mode) {
    ILenum mode = NUM2INT(rb_mode);

    ILboolean flag = ilDisable(mode);
    return flag ? Qtrue : Qfalse;
}

+ (Object) Enable

methods below added by banisterfiend



244
245
246
247
248
249
# File 'ext/devil/ruby_il.c', line 244

static VALUE il_Enable(VALUE obj, VALUE rb_mode) {
    ILenum mode = NUM2INT(rb_mode);

    ILboolean flag = ilEnable(mode);
    return flag ? Qtrue : Qfalse;
}

+ (Object) FromBlob



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'ext/devil/ruby_il.c', line 323

static VALUE bf_FromBlob(VALUE obj, VALUE blob, VALUE rb_width, VALUE rb_height)
{
    ILubyte * data;
    ILuint width, height;
    ILuint image;
    ILuint saved_image;

    width = NUM2INT(rb_width);
    height = NUM2INT(rb_height);

    data = (ILubyte *) RSTRING_PTR(blob);

    saved_image = ilGetInteger(IL_CUR_IMAGE);

    ilGenImages(1, &image);
    ilBindImage(image);

    ilTexImage(width, height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, data);

    ilBindImage(saved_image);

    return INT2NUM(image);
}

+ (Object) GenImages



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'ext/devil/ruby_il.c', line 32

static VALUE il_GenImages(VALUE obj, VALUE num_names) {
    ILsizei num = NUM2INT(num_names);
    ILuint* names = ALLOC_N(ILuint, num);
    RArray* ret;
    int i;

    if (!names)
	rb_raise(rb_eRuntimeError, "IL.GenImages memory allocation");

    ilGenImages(num, names);

    ret = RARRAY( rb_ary_new2(num));
    for(i = 0; i < num; ++i)
	rb_ary_push( (VALUE)ret, INT2NUM(names[i]));
    free(names);

    return (VALUE)ret;
}

+ (Object) GetData



135
136
137
138
# File 'ext/devil/ruby_il.c', line 135

static VALUE il_GetData(VALUE obj) {
    ILubyte* data = ilGetData();
    return MakeImageData(data);
}

+ (Object) GetError



226
227
228
229
# File 'ext/devil/ruby_il.c', line 226

static VALUE il_GetError(VALUE obj) {
    ILenum num = ilGetError();
    return INT2FIX(num);
}

+ (Object) GetInteger



274
275
276
277
278
279
# File 'ext/devil/ruby_il.c', line 274

static VALUE il_GetInteger(VALUE obj, VALUE rb_mode) {
    ILenum mode = NUM2INT(rb_mode);

    ILint result = ilGetInteger(mode);
    return INT2NUM(result);
}

+ (Object) Init

////////////////////////////////



27
28
29
30
# File 'ext/devil/ruby_il.c', line 27

static VALUE il_Init(VALUE obj) {
    ilInit();
    return Qnil;
}

+ (Object) Load



88
89
90
91
92
93
94
# File 'ext/devil/ruby_il.c', line 88

static VALUE il_Load(VALUE obj, VALUE rb_type, VALUE rb_filename) {
    ILenum type = NUM2INT(rb_type);
    char* filename = StringValuePtr(rb_filename);

    ILboolean load = ilLoad(type, filename);
    return load ? Qtrue : Qfalse;
}

+ (Object) LoadImage



82
83
84
85
86
# File 'ext/devil/ruby_il.c', line 82

static VALUE il_LoadImage(VALUE obj, VALUE rb_filename) {
    char* filename = StringValuePtr(rb_filename);
    ILboolean load = ilLoadImage(filename);
    return load ? Qtrue : Qfalse;
}

+ (Object) OriginFunc



354
355
356
357
358
359
360
# File 'ext/devil/ruby_il.c', line 354

static VALUE il_OriginFunc(VALUE obj, VALUE rb_mode)
{
    ILenum mode = NUM2INT(rb_mode);

    ILboolean flag = ilOriginFunc(mode);
    return flag ? Qtrue : Qfalse;    
}

+ (Object) OverlayImage



195
196
197
198
199
200
201
202
203
204
# File 'ext/devil/ruby_il.c', line 195

static VALUE il_OverlayImage(VALUE obj, VALUE rb_Source, VALUE rb_XCoord,
                             VALUE rb_YCoord, VALUE rb_ZCoord) {
    ILuint Source = NUM2INT(rb_Source);
    ILint XCoord = NUM2INT(rb_XCoord);
    ILint YCoord = NUM2INT(rb_YCoord);
    ILint ZCoord = NUM2INT(rb_ZCoord);
    ILboolean flag = ilOverlayImage(Source, XCoord, YCoord,ZCoord);
    
    return flag ? Qtrue : Qfalse;
}

+ (Object) Save



103
104
105
106
107
108
109
# File 'ext/devil/ruby_il.c', line 103

static VALUE il_Save(VALUE obj, VALUE rb_type, VALUE rb_filename) {
    ILenum type = NUM2INT(rb_type);
    char* filename = StringValuePtr(rb_filename);
    ILboolean load = ilSave(type, filename);

    return load ? Qtrue : Qfalse;
}

+ (Object) SaveImage



96
97
98
99
100
101
# File 'ext/devil/ruby_il.c', line 96

static VALUE il_SaveImage(VALUE obj, VALUE rb_filename) {
    char* filename = StringValuePtr(rb_filename);
    ILboolean load = ilSaveImage(filename);

    return load ? Qtrue : Qfalse;
}

+ (Object) SetData

}



163
164
165
166
167
168
# File 'ext/devil/ruby_il.c', line 163

static VALUE il_SetData(VALUE obj, VALUE rb_Data) {
    /* ILvoid */
    void* data = ImageData2Arr(rb_Data);
    ILboolean flag = ilSetData(data);
    return flag ? Qtrue : Qfalse;
}

+ (Object) SetInteger



380
381
382
383
384
385
386
387
388
# File 'ext/devil/ruby_il.c', line 380

static VALUE il_SetInteger(VALUE obj, VALUE rb_mode, VALUE rb_param)
{
    ILenum mode = NUM2INT(rb_mode);
    ILint param = NUM2INT(rb_param);

    ilSetInteger(mode, param);

    return Qnil;
}

+ (Object) SetPixels



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'ext/devil/ruby_il.c', line 170

static VALUE il_SetPixels(VALUE obj, VALUE rb_XOff, VALUE rb_YOff, VALUE rb_ZOff,
                          VALUE rb_Width, VALUE rb_Height, VALUE rb_Depth, VALUE rb_Format,
                          VALUE rb_Type, VALUE rb_data) {
    ILuint XOff = NUM2INT(rb_XOff);
    ILuint YOff = NUM2INT(rb_YOff);
    ILuint ZOff = NUM2INT(rb_ZOff);
    ILuint Width = NUM2INT(rb_Width);
    ILuint Height = NUM2INT(rb_Height);
    ILuint Depth = NUM2INT(rb_Depth);
    ILenum Format = NUM2INT(rb_Format);
    ILenum Type = NUM2INT(rb_Type);
    /* ILvoid */
    void* data = ImageData2Arr(rb_data);

    ilSetPixels(XOff, YOff, ZOff, Width, Height, Depth, Format, Type, data);
    return Qnil;
}

+ (Object) TexImage



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'ext/devil/ruby_il.c', line 111

static VALUE il_TexImage(VALUE obj, VALUE rb_width, VALUE rb_height,
                         VALUE rb_depth, VALUE rb_bpp, VALUE rb_format, VALUE rb_type,
                         VALUE rb_data) {
    ILuint width = NUM2INT(rb_width);
    ILuint height = NUM2INT(rb_height);
    ILuint depth = NUM2INT(rb_depth);
    ILubyte bpp = NUM2INT(rb_bpp);
    ILenum format = NUM2INT(rb_format);
    ILenum type = NUM2INT(rb_type);
    ILboolean flag;

    /* from ILvoid */
    void * data = NULL;
    
    if(NIL_P(rb_data))
        data = NULL;
    else
        data = ImageData2Arr(rb_data);

    flag = ilTexImage(width, height, depth,
                                bpp, format, type, data);
    return flag ? Qtrue : Qfalse;
}

+ (Object) ToBlob

this function is not actually in the DevIL API, but im adding it here for convenience



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'ext/devil/ruby_il.c', line 292

static VALUE bf_ToBlob(VALUE obj)
{
    ILuint width, height, saved_image, copy_image;
    char * img_ptr;
    VALUE blob;

    saved_image = ilGetInteger(IL_CUR_IMAGE);

    /* make a copy of the current image */
    copy_image = ilCloneCurImage();

    ilBindImage(copy_image);
    
    /* ensure the image is int RGBA UNSIGNED_BYTE format for blob */
    ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

    width = ilGetInteger(IL_IMAGE_WIDTH);
    height = ilGetInteger(IL_IMAGE_HEIGHT);

    img_ptr = (char *)ilGetData();

    blob = rb_str_new(img_ptr, 4 * width * height);

    /* restore saved binding */
    ilBindImage(saved_image);

    ilDeleteImages(1, &copy_image);

    return blob;
}