This source file includes following definitions.
- raise_imlib_error
- set_context_color
- border_new
- border_init
- border_left
- border_set_left
- border_right
- border_set_right
- border_top
- border_set_top
- border_bottom
- border_set_bottom
- cache_image
- cache_set_image
- cache_font
- cache_set_font
- cache_flush_font
- rgba_color_new
- rgba_color_init
- rgba_color_red
- rgba_color_set_red
- rgba_color_blue
- rgba_color_set_blue
- rgba_color_green
- rgba_color_set_green
- rgba_color_alpha
- rgba_color_set_alpha
- hsva_color_new
- hsva_color_init
- hsva_color_hue
- hsva_color_set_hue
- hsva_color_value
- hsva_color_set_value
- hsva_color_saturation
- hsva_color_set_saturation
- hsva_color_alpha
- hsva_color_set_alpha
- hlsa_color_new
- hlsa_color_init
- hlsa_color_hue
- hlsa_color_set_hue
- hlsa_color_saturation
- hlsa_color_set_saturation
- hlsa_color_lightness
- hlsa_color_set_lightness
- hlsa_color_alpha
- hlsa_color_set_alpha
- cmya_color_new
- cmya_color_init
- cmya_color_cyan
- cmya_color_set_cyan
- cmya_color_yellow
- cmya_color_set_yellow
- cmya_color_magenta
- cmya_color_set_magenta
- cmya_color_alpha
- cmya_color_set_alpha
- disp_free
- display_new
- display_init
- visual_free
- visual_new
- visual_init
- cmap_free
- cmap_new
- cmap_init
- drawable_init
- im_struct_free
- image_new
- image_dp_workaround
- image_set_dp_workaround
- image_create_using_data
- image_create_using_copied_data
- image_load
- image_load_image
- image_load_immediately
- image_load_without_cache
- image_load_immediately_without_cache
- image_load_with_error_return
- image_save
- image_save_image
- image_save_with_error_return
- image_clone
- image_initialize
- image_delete
- image_width
- image_height
- image_filename
- image_data
- image_data_ro
- image_put_data
- image_has_alpha
- image_set_has_alpha
- image_changes_on_disk
- image_get_border
- image_set_border
- image_get_format
- image_set_format
- image_irrelevant_format
- image_irrelevant_border
- image_irrelevant_alpha
- image_query_pixel
- image_query_pixel_hsva
- image_query_pixel_hlsa
- image_query_pixel_cmya
- image_crop
- image_crop_inline
- image_crop_scaled
- image_crop_scaled_inline
- image_flip_horizontal
- image_flip_horizontal_inline
- image_flip_vertical
- image_flip_vertical_inline
- image_flip_diagonal
- image_flip_diagonal_inline
- image_orientate
- image_orientate_inline
- image_blur
- image_blur_inline
- image_sharpen
- image_sharpen_inline
- image_tile_horizontal
- image_tile_horizontal_inline
- image_tile_vertical
- image_tile_vertical_inline
- image_tile
- image_tile_inline
- image_clear
- image_clear_color
- image_clear_color_inline
- image_draw_pixel
- image_draw_line
- image_draw_rect
- image_fill_rect
- image_copy_alpha
- image_copy_alpha_rect
- image_scroll_rect
- image_copy_rect
- image_draw_ellipse
- image_fill_ellipse
- image_blend_image_inline
- image_blend_image
- image_rotate
- image_rotate_inline
- image_draw_text
- image_fill_gradient
- image_draw_poly
- image_fill_poly
- image_static_filter
- image_script_filter
- image_filter
- image_apply_cmod
- image_render_pixmap
- image_attach_val
- image_get_attach_val
- image_rm_attach_val
- cmod_free
- cmod_new
- cmod_init
- cmod_gamma
- cmod_brightness
- cmod_contrast
- cmod_reset
- font_free
- font_new
- font_init
- font_text_size
- font_text_advance
- font_text_inset
- font_text_index
- font_text_location
- font_ascent
- font_descent
- font_maximum_ascent
- font_maximum_descent
- font_list_fonts
- font_add_path
- font_remove_path
- font_list_paths
- gradient_free
- gradient_new
- gradient_add_color
- gradient_init
- poly_free
- poly_new
- poly_add_point
- poly_init
- poly_bounds
- poly_contains
- filter_free
- filter_new
- filter_init
- filter_set
- filter_set_red
- filter_set_green
- filter_set_blue
- filter_set_alpha
- filter_constants
- filter_divisors
- ctx_free
- ctx_new
- ctx_init
- ctx_pop
- ctx_get
- ctx_push
- ctx_set_dither_mask
- ctx_dither_mask
- ctx_set_aa
- ctx_aa
- ctx_set_dither
- ctx_dither
- ctx_set_blend
- ctx_blend
- ctx_set_cmod
- ctx_cmod
- ctx_set_op
- ctx_op
- ctx_set_font
- ctx_font
- ctx_set_dir
- ctx_dir
- ctx_set_angle
- ctx_angle
- ctx_set_color
- ctx_color
- ctx_set_gradient
- ctx_gradient
- ctx_set_progress_granularity
- ctx_progress_granularity
- ctx_set_image
- ctx_image
- ctx_set_cliprect
- ctx_cliprect
- ctx_set_encoding
- ctx_encoding
- ctx_set_display
- ctx_display
- ctx_set_visual
- ctx_visual
- ctx_set_colormap
- ctx_colormap
- ctx_set_drawable
- ctx_drawable
- ctx_set_mask
- ctx_mask
- setup_color_constants
- setup_error_constants
- Init_imlib2
#include <stdio.h>
#ifndef X_DISPLAY_MISSING
#include <X11/Xlib.h>
#endif
#include <Imlib2.h>
#include <ruby.h>
#define UNUSED(a) ((void) (a))
#define VERSION "0.5.2"
static VALUE mImlib2,
mError,
cFileError,
cDeletedError,
cBorder,
mCache,
mColor,
mTextDir,
cRgbaColor,
cHsvaColor,
cHlsaColor,
cCmyaColor,
cContext,
cGradient,
cImage,
cFilter,
cFont,
cColorMod,
cPolygon,
mOp,
mOperation,
mEncoding;
#ifndef X_DISPLAY_MISSING
static VALUE mX11,
cDisplay,
cPixmap,
cVisual,
cDrawable,
cColormap;
#endif
#ifdef DISABLE_DRAW_PIXEL_WORKAROUND
static char draw_pixel_workaround = 0;
#else
static char draw_pixel_workaround = 1;
#endif
static struct {
VALUE exception;
char *name,
*description;
} imlib_errors[] = {
{ 0, "NONE", "No error" },
{ 0, "FILE_DOES_NOT_EXIST", "File does not exist" },
{ 0, "FILE_IS_DIRECTORY", "File is directory" },
{ 0, "PERMISSION_DENIED_TO_READ", "Permission denied to read" },
{ 0, "NO_LOADER_FOR_FILE_FORMAT", "No loader for file format" },
{ 0, "PATH_TOO_LONG", "Path too long" },
{ 0, "PATH_COMPONENT_NON_EXISTANT", "Path component nonexistant" },
{ 0, "PATH_COMPONENT_NOT_DIRECTORY", "Path component not directory" },
{ 0, "PATH_POINTS_OUTSIDE_ADDRESS_SPACE","Path points outside address space"},
{ 0, "TOO_MANY_SYMBOLIC_LINKS", "Too many symbolic links" },
{ 0, "OUT_OF_MEMORY", "Out of memory" },
{ 0, "OUT_OF_FILE_DESCRIPTORS", "Out of file descriptors" },
{ 0, "PERMISSION_DENIED_TO_WRITE", "Permission denied to write" },
{ 0, "OUT_OF_DISK_SPACE", "Out of disk space" },
{ 0, "UNKNOWN", "Unknown or unspecified error" }
};
typedef struct {
Imlib_Image im;
} ImStruct;
#define GET_AND_CHECK_IMAGE(src, image) do { \
Data_Get_Struct((src), ImStruct, (image)); \
if (!(image)->im) { \
rb_raise(cDeletedError, "image deleted"); \
return Qnil; \
} \
} while (0)
typedef struct {
double hue,
saturation,
value;
int alpha;
} HsvaColor;
typedef struct {
double hue,
lightness,
saturation;
int alpha;
} HlsaColor;
typedef struct {
int cyan,
magenta,
yellow,
alpha;
} CmyaColor;
static void raise_imlib_error(const char *path, int err) {
char buf[1024];
if (err < IMLIB_LOAD_ERROR_NONE || err > IMLIB_LOAD_ERROR_UNKNOWN)
err = IMLIB_LOAD_ERROR_UNKNOWN;
snprintf(buf, sizeof(buf), "\"%s\": %s", path, imlib_errors[err].description);
rb_raise(imlib_errors[err].exception, buf);
}
static void set_context_color(VALUE color) {
if (rb_obj_is_kind_of(color, cRgbaColor) == Qtrue) {
Imlib_Color *c;
Data_Get_Struct(color, Imlib_Color, c);
imlib_context_set_color(c->red, c->green, c->blue, c->alpha);
} else if (rb_obj_is_kind_of(color, cHsvaColor) == Qtrue) {
HsvaColor *c;
Data_Get_Struct(color, HsvaColor, c);
imlib_context_set_color_hsva(c->hue, c->saturation, c->value, c->alpha);
} else if (rb_obj_is_kind_of(color, cHlsaColor) == Qtrue) {
HlsaColor *c;
Data_Get_Struct(color, HlsaColor, c);
imlib_context_set_color_hsva(c->hue, c->lightness, c->saturation, c->alpha);
} else if (rb_obj_is_kind_of(color, cCmyaColor) == Qtrue) {
CmyaColor *c;
Data_Get_Struct(color, CmyaColor, c);
imlib_context_set_color_hsva(c->cyan, c->magenta, c->yellow, c->alpha);
} else {
rb_raise(rb_eTypeError, "Invalid argument type (not "
"Imlib2::Color::RgbaColor, "
"Imlib2::Color::HvsaColor, "
"Imlib2::Color::HslaColor, or "
"Imlib2::Color::CmyaColor)");
}
}
VALUE border_new(int argc, VALUE *argv, VALUE klass) {
Imlib_Border *border;
VALUE b_o;
border = malloc(sizeof(Imlib_Border));
memset(border, 0, sizeof(Imlib_Border));
b_o = Data_Wrap_Struct(klass, 0, free, border);
rb_obj_call_init(b_o, argc, argv);
return b_o;
}
static VALUE border_init(int argc, VALUE *argv, VALUE self) {
Imlib_Border *border;
Data_Get_Struct(self, Imlib_Border, border);
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
border->left = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("left")));
border->top = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("top")));
border->right = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("right")));
border->bottom = NUM2INT(rb_hash_aref(argv[0],rb_str_new2("bottom")));
break;
case T_ARRAY:
border->left = NUM2INT(rb_ary_entry(argv[0], 0));
border->top = NUM2INT(rb_ary_entry(argv[0], 1));
border->right = NUM2INT(rb_ary_entry(argv[0], 2));
border->bottom = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 4:
border->left = NUM2INT(argv[0]);
border->top = NUM2INT(argv[1]);
border->right = NUM2INT(argv[2]);
border->bottom = NUM2INT(argv[3]);
break;
default:
break;
}
return self;
}
static VALUE border_left(VALUE self) {
Imlib_Border *b;
Data_Get_Struct(self, Imlib_Border, b);
return INT2FIX(b->left);
}
static VALUE border_set_left(VALUE self, VALUE val) {
Imlib_Border *b;
Data_Get_Struct(self, Imlib_Border, b);
b->left = NUM2INT(val);
return val;
}
static VALUE border_right(VALUE self) {
Imlib_Border *b;
Data_Get_Struct(self, Imlib_Border, b);
return INT2FIX(b->right);
}
static VALUE border_set_right(VALUE self, VALUE val) {
Imlib_Border *b;
Data_Get_Struct(self, Imlib_Border, b);
b->right = NUM2INT(val);
return val;
}
static VALUE border_top(VALUE self) {
Imlib_Border *b;
Data_Get_Struct(self, Imlib_Border, b);
return INT2FIX(b->top);
}
static VALUE border_set_top(VALUE self, VALUE val) {
Imlib_Border *b;
Data_Get_Struct(self, Imlib_Border, b);
b->top = NUM2INT(val);
return val;
}
static VALUE border_bottom(VALUE self) {
Imlib_Border *b;
Data_Get_Struct(self, Imlib_Border, b);
return INT2FIX(b->bottom);
}
static VALUE border_set_bottom(VALUE self, VALUE val) {
Imlib_Border *b;
Data_Get_Struct(self, Imlib_Border, b);
b->bottom = NUM2INT(val);
return val;
}
static VALUE cache_image(VALUE klass) {
UNUSED(klass);
return INT2FIX(imlib_get_cache_size());
}
static VALUE cache_set_image(VALUE klass, VALUE val) {
UNUSED(klass);
imlib_set_cache_size(NUM2INT(val));
return Qtrue;
}
static VALUE cache_font(VALUE klass) {
UNUSED(klass);
return INT2FIX(imlib_get_font_cache_size());
}
static VALUE cache_set_font(VALUE klass, VALUE val) {
UNUSED(klass);
imlib_set_font_cache_size(NUM2INT(val));
return Qtrue;
}
static VALUE cache_flush_font(VALUE klass) {
imlib_flush_font_cache();
return cache_font(klass);
}
VALUE rgba_color_new(int argc, VALUE *argv, VALUE klass) {
Imlib_Color *color;
VALUE c_o;
color = malloc(sizeof(Imlib_Color));
memset(color, 0, sizeof(Imlib_Color));
c_o = Data_Wrap_Struct(klass, 0, free, color);
rb_obj_call_init(c_o, argc, argv);
return c_o;
}
static VALUE rgba_color_init(int argc, VALUE *argv, VALUE self) {
Imlib_Color *color = NULL;
Data_Get_Struct(self, Imlib_Color, color);
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
color->red = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("red")));
color->green = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("green")));
color->blue = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("blue")));
color->alpha = NUM2INT(rb_hash_aref(argv[0],rb_str_new2("alpha")));
break;
case T_ARRAY:
color->red = NUM2INT(rb_ary_entry(argv[0], 0));
color->green = NUM2INT(rb_ary_entry(argv[0], 1));
color->blue = NUM2INT(rb_ary_entry(argv[0], 2));
color->alpha = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid arguments (not array or hash)");
}
break;
case 4:
color->red = NUM2INT(argv[0]);
color->green = NUM2INT(argv[1]);
color->blue = NUM2INT(argv[2]);
color->alpha = NUM2INT(argv[3]);
break;
default:
break;
}
return self;
}
static VALUE rgba_color_red(VALUE self) {
Imlib_Color *b;
Data_Get_Struct(self, Imlib_Color, b);
return INT2FIX(b->red);
}
static VALUE rgba_color_set_red(VALUE self, VALUE val) {
Imlib_Color *b;
Data_Get_Struct(self, Imlib_Color, b);
b->red = NUM2INT(val);
return val;
}
static VALUE rgba_color_blue(VALUE self) {
Imlib_Color *b;
Data_Get_Struct(self, Imlib_Color, b);
return INT2FIX(b->blue);
}
static VALUE rgba_color_set_blue(VALUE self, VALUE val) {
Imlib_Color *b;
Data_Get_Struct(self, Imlib_Color, b);
b->blue = NUM2INT(val);
return val;
}
static VALUE rgba_color_green(VALUE self) {
Imlib_Color *b;
Data_Get_Struct(self, Imlib_Color, b);
return INT2FIX(b->green);
}
static VALUE rgba_color_set_green(VALUE self, VALUE val) {
Imlib_Color *b;
Data_Get_Struct(self, Imlib_Color, b);
b->green = NUM2INT(val);
return val;
}
static VALUE rgba_color_alpha(VALUE self) {
Imlib_Color *b;
Data_Get_Struct(self, Imlib_Color, b);
return INT2FIX(b->alpha);
}
static VALUE rgba_color_set_alpha(VALUE self, VALUE val) {
Imlib_Color *b;
Data_Get_Struct(self, Imlib_Color, b);
b->alpha = NUM2INT(val);
return val;
}
VALUE hsva_color_new(int argc, VALUE *argv, VALUE klass) {
HsvaColor *color;
VALUE c_o;
color = malloc(sizeof(HsvaColor));
memset(color, 0, sizeof(HsvaColor));
c_o = Data_Wrap_Struct(klass, 0, free, color);
rb_obj_call_init(c_o, argc, argv);
return c_o;
}
static VALUE hsva_color_init(int argc, VALUE *argv, VALUE self) {
HsvaColor *color;
Data_Get_Struct(self, HsvaColor, color);
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
color->hue = NUM2DBL(rb_hash_aref(argv[0], rb_str_new2("hue")));
color->saturation = NUM2DBL(rb_hash_aref(argv[0], rb_str_new2("saturation")));
color->value = NUM2DBL(rb_hash_aref(argv[0], rb_str_new2("value")));
color->alpha = NUM2INT(rb_hash_aref(argv[0],rb_str_new2("alpha")));
break;
case T_ARRAY:
color->hue = NUM2DBL(rb_ary_entry(argv[0], 0));
color->saturation = NUM2DBL(rb_ary_entry(argv[0], 1));
color->value = NUM2DBL(rb_ary_entry(argv[0], 2));
color->alpha = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 4:
color->hue = NUM2DBL(argv[0]);
color->saturation = NUM2DBL(argv[1]);
color->value = NUM2DBL(argv[2]);
color->alpha = NUM2INT(argv[3]);
break;
default:
break;
}
return self;
}
static VALUE hsva_color_hue(VALUE self) {
HsvaColor *b;
Data_Get_Struct(self, HsvaColor, b);
return rb_float_new(b->hue);
}
static VALUE hsva_color_set_hue(VALUE self, VALUE val) {
HsvaColor *b;
Data_Get_Struct(self, HsvaColor, b);
b->hue = NUM2DBL(val);
return val;
}
static VALUE hsva_color_value(VALUE self) {
HsvaColor *b;
Data_Get_Struct(self, HsvaColor, b);
return rb_float_new(b->value);
}
static VALUE hsva_color_set_value(VALUE self, VALUE val) {
HsvaColor *b;
Data_Get_Struct(self, HsvaColor, b);
b->value = NUM2DBL(val);
return val;
}
static VALUE hsva_color_saturation(VALUE self) {
HsvaColor *b;
Data_Get_Struct(self, HsvaColor, b);
return rb_float_new(b->saturation);
}
static VALUE hsva_color_set_saturation(VALUE self, VALUE val) {
HsvaColor *b;
Data_Get_Struct(self, HsvaColor, b);
b->saturation = NUM2DBL(val);
return val;
}
static VALUE hsva_color_alpha(VALUE self) {
HsvaColor *b;
Data_Get_Struct(self, HsvaColor, b);
return INT2FIX(b->alpha);
}
static VALUE hsva_color_set_alpha(VALUE self, VALUE val) {
HsvaColor *b;
Data_Get_Struct(self, HsvaColor, b);
b->alpha = NUM2INT(val);
return val;
}
VALUE hlsa_color_new(int argc, VALUE *argv, VALUE klass) {
HlsaColor *color;
VALUE c_o;
color = malloc(sizeof(HlsaColor));
memset(color, 0, sizeof(HlsaColor));
c_o = Data_Wrap_Struct(klass, 0, free, color);
rb_obj_call_init(c_o, argc, argv);
return c_o;
}
static VALUE hlsa_color_init(int argc, VALUE *argv, VALUE self) {
HlsaColor *color;
Data_Get_Struct(self, HlsaColor, color);
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
color->hue = NUM2DBL(rb_hash_aref(argv[0], rb_str_new2("hue")));
color->lightness = NUM2DBL(rb_hash_aref(argv[0], rb_str_new2("lightness")));
color->saturation = NUM2DBL(rb_hash_aref(argv[0], rb_str_new2("saturation")));
color->alpha = NUM2INT(rb_hash_aref(argv[0],rb_str_new2("alpha")));
break;
case T_ARRAY:
color->hue = NUM2DBL(rb_ary_entry(argv[0], 0));
color->lightness = NUM2DBL(rb_ary_entry(argv[0], 1));
color->saturation = NUM2DBL(rb_ary_entry(argv[0], 2));
color->alpha = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 4:
color->hue = NUM2DBL(argv[0]);
color->lightness = NUM2DBL(argv[1]);
color->saturation = NUM2DBL(argv[2]);
color->alpha = NUM2INT(argv[3]);
break;
default:
break;
}
return self;
}
static VALUE hlsa_color_hue(VALUE self) {
HlsaColor *b;
Data_Get_Struct(self, HlsaColor, b);
return rb_float_new(b->hue);
}
static VALUE hlsa_color_set_hue(VALUE self, VALUE val) {
HlsaColor *b;
Data_Get_Struct(self, HlsaColor, b);
b->hue = NUM2DBL(val);
return val;
}
static VALUE hlsa_color_saturation(VALUE self) {
HlsaColor *b;
Data_Get_Struct(self, HlsaColor, b);
return rb_float_new(b->saturation);
}
static VALUE hlsa_color_set_saturation(VALUE self, VALUE val) {
HlsaColor *b;
Data_Get_Struct(self, HlsaColor, b);
b->saturation = NUM2DBL(val);
return val;
}
static VALUE hlsa_color_lightness(VALUE self) {
HlsaColor *b;
Data_Get_Struct(self, HlsaColor, b);
return rb_float_new(b->lightness);
}
static VALUE hlsa_color_set_lightness(VALUE self, VALUE val) {
HlsaColor *b;
Data_Get_Struct(self, HlsaColor, b);
b->lightness = NUM2DBL(val);
return val;
}
static VALUE hlsa_color_alpha(VALUE self) {
HlsaColor *b;
Data_Get_Struct(self, HlsaColor, b);
return INT2FIX(b->alpha);
}
static VALUE hlsa_color_set_alpha(VALUE self, VALUE val) {
HlsaColor *b;
Data_Get_Struct(self, HlsaColor, b);
b->alpha = NUM2INT(val);
return val;
}
VALUE cmya_color_new(int argc, VALUE *argv, VALUE klass) {
CmyaColor *color;
VALUE c_o;
color = malloc(sizeof(CmyaColor));
memset(color, 0, sizeof(CmyaColor));
c_o = Data_Wrap_Struct(klass, 0, free, color);
rb_obj_call_init(c_o, argc, argv);
return c_o;
}
static VALUE cmya_color_init(int argc, VALUE *argv, VALUE self) {
CmyaColor *color;
Data_Get_Struct(self, CmyaColor, color);
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
color->cyan = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("cyan")));
color->magenta = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("magenta")));
color->yellow = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("yellow")));
color->alpha = NUM2INT(rb_hash_aref(argv[0],rb_str_new2("alpha")));
break;
case T_ARRAY:
color->cyan = NUM2INT(rb_ary_entry(argv[0], 0));
color->magenta = NUM2INT(rb_ary_entry(argv[0], 1));
color->yellow = NUM2INT(rb_ary_entry(argv[0], 2));
color->alpha = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 4:
color->cyan = NUM2INT(argv[0]);
color->magenta = NUM2INT(argv[1]);
color->yellow = NUM2INT(argv[2]);
color->alpha = NUM2INT(argv[3]);
break;
default:
break;
}
return self;
}
static VALUE cmya_color_cyan(VALUE self) {
CmyaColor *b;
Data_Get_Struct(self, CmyaColor, b);
return INT2FIX(b->cyan);
}
static VALUE cmya_color_set_cyan(VALUE self, VALUE val) {
CmyaColor *b;
Data_Get_Struct(self, CmyaColor, b);
b->cyan = NUM2INT(val);
return val;
}
static VALUE cmya_color_yellow(VALUE self) {
CmyaColor *b;
Data_Get_Struct(self, CmyaColor, b);
return INT2FIX(b->yellow);
}
static VALUE cmya_color_set_yellow(VALUE self, VALUE val) {
CmyaColor *b;
Data_Get_Struct(self, CmyaColor, b);
b->yellow = NUM2INT(val);
return val;
}
static VALUE cmya_color_magenta(VALUE self) {
CmyaColor *b;
Data_Get_Struct(self, CmyaColor, b);
return INT2FIX(b->magenta);
}
static VALUE cmya_color_set_magenta(VALUE self, VALUE val) {
CmyaColor *b;
Data_Get_Struct(self, CmyaColor, b);
b->magenta = NUM2INT(val);
return val;
}
static VALUE cmya_color_alpha(VALUE self) {
CmyaColor *b;
Data_Get_Struct(self, CmyaColor, b);
return INT2FIX(b->alpha);
}
static VALUE cmya_color_set_alpha(VALUE self, VALUE val) {
CmyaColor *b;
Data_Get_Struct(self, CmyaColor, b);
b->alpha = NUM2INT(val);
return val;
}
#ifndef X_DISPLAY_MISSING
static void disp_free(void *disp) {
XFree(disp);
}
VALUE display_new(VALUE klass, VALUE display) {
Display *disp;
VALUE self;
if (display == Qnil) {
char *env = getenv("DISPLAY");
disp = XOpenDisplay(env);
} else {
disp = XOpenDisplay(StringValuePtr(display));
}
if (!disp)
rb_raise(rb_eRuntimeError, "Couldn't open display");
self = Data_Wrap_Struct(klass, 0, disp_free, disp);
rb_obj_call_init(self, 0, NULL);
return self;
}
static VALUE display_init(VALUE self) {
return self;
}
static void visual_free(void *vis) {
}
VALUE visual_new(VALUE klass, VALUE display, VALUE screen) {
Display *disp;
Visual *vis;
VALUE self;
if (display == Qnil)
display = display_new(cDisplay, Qnil);
Data_Get_Struct(display, Display, disp);
vis = DefaultVisual(disp, NUM2INT(screen));
self = Data_Wrap_Struct(klass, 0, visual_free, vis);
rb_obj_call_init(self, 0, NULL);
return self;
}
static VALUE visual_init(VALUE self) {
return self;
}
static void cmap_free(void *vis) {
}
VALUE cmap_new(VALUE klass, VALUE display, VALUE screen) {
Display *disp;
Colormap *cmap;
VALUE self;
if (display == Qnil)
display = display_new(cDisplay, Qnil);
Data_Get_Struct(display, Display, disp);
cmap = malloc(sizeof(Colormap));
*cmap = DefaultColormap(disp, NUM2INT(screen));
self = Data_Wrap_Struct(klass, 0, dont_free, cmap);
rb_obj_call_init(self, 0, NULL);
return self;
}
static VALUE cmap_init(VALUE self) {
return self;
}
static VALUE drawable_init(VALUE self) {
return self;
}
#endif
static void im_struct_free(void *val) {
ImStruct *im = (ImStruct*) val;
if (im) {
if (im->im) {
imlib_context_set_image(im->im);
imlib_free_image();
}
free(im);
}
}
VALUE image_new(VALUE klass, VALUE w, VALUE h) {
ImStruct *im = malloc(sizeof(ImStruct));
VALUE im_o;
im->im = imlib_create_image(NUM2INT(w), NUM2INT(h));
im_o = Data_Wrap_Struct(klass, 0, im_struct_free, im);
rb_obj_call_init(im_o, 0, NULL);
return im_o;
}
VALUE image_dp_workaround(VALUE klass) {
UNUSED(klass);
return draw_pixel_workaround ? Qtrue : Qfalse;
}
VALUE image_set_dp_workaround(VALUE klass, VALUE val) {
UNUSED(klass);
draw_pixel_workaround = (val == Qtrue);
return val;
}
VALUE image_create_using_data(VALUE klass, VALUE w, VALUE h, VALUE data) {
ImStruct *im;
VALUE im_o;
im = malloc(sizeof(ImStruct));
im->im = imlib_create_image_using_data(NUM2INT(w), NUM2INT(h), (DATA32 *) StringValuePtr (data));
im_o = Data_Wrap_Struct(klass, 0, im_struct_free, im);
rb_obj_call_init(im_o, 0, NULL);
return im_o;
}
VALUE image_create_using_copied_data(VALUE klass, VALUE w, VALUE h, VALUE data) {
ImStruct *im;
VALUE im_o;
im = malloc(sizeof(ImStruct));
im->im = imlib_create_image_using_copied_data(NUM2INT(w), NUM2INT(h), (DATA32 *) StringValuePtr (data));
im_o = Data_Wrap_Struct(klass, 0, im_struct_free, im);
rb_obj_call_init(im_o, 0, NULL);
return im_o;
}
static VALUE image_load(VALUE klass, VALUE filename) {
ImStruct *im;
Imlib_Image iim;
Imlib_Load_Error err;
VALUE im_o = Qnil;
char *path;
path = StringValuePtr(filename);
iim = imlib_load_image_with_error_return(path, &err);
if (err == IMLIB_LOAD_ERROR_NONE) {
im = malloc(sizeof(ImStruct));
im->im = iim;
im_o = Data_Wrap_Struct(klass, 0, im_struct_free, im);
if (rb_block_given_p())
rb_yield(im_o);
} else {
if (!rb_block_given_p())
raise_imlib_error(path, err);
}
return im_o;
}
static VALUE image_load_image(VALUE klass, VALUE filename) {
ImStruct *im = malloc(sizeof(ImStruct));
VALUE im_o;
im->im = imlib_load_image(StringValuePtr(filename));
im_o = Data_Wrap_Struct(klass, 0, im_struct_free, im);
return im_o;
}
static VALUE image_load_immediately(VALUE klass, VALUE filename) {
ImStruct *im = malloc(sizeof(ImStruct));
VALUE im_o;
im->im = imlib_load_image_immediately(StringValuePtr(filename));
im_o = Data_Wrap_Struct(klass, 0, im_struct_free, im);
return im_o;
}
static VALUE image_load_without_cache(VALUE klass, VALUE filename) {
ImStruct *im = malloc(sizeof(ImStruct));
VALUE im_o;
im->im = imlib_load_image_without_cache(StringValuePtr(filename));
im_o = Data_Wrap_Struct(klass, 0, im_struct_free, im);
return im_o;
}
static VALUE image_load_immediately_without_cache(VALUE klass, VALUE filename) {
ImStruct *im = malloc(sizeof(ImStruct));
VALUE im_o;
im->im = imlib_load_image_immediately_without_cache(StringValuePtr(filename));
im_o = Data_Wrap_Struct(klass, 0, im_struct_free, im);
return im_o;
}
static VALUE image_load_with_error_return(VALUE klass, VALUE filename) {
ImStruct *im = malloc(sizeof(ImStruct));
Imlib_Load_Error er;
VALUE hash, im_o;
im->im = imlib_load_image_with_error_return(StringValuePtr(filename), &er);
im_o = Data_Wrap_Struct(klass, 0, im_struct_free, im);
hash = rb_hash_new();
rb_hash_aset(hash, rb_str_new2("image"), im_o);
rb_hash_aset(hash, rb_str_new2("error"), INT2FIX(er));
return hash;
}
static VALUE image_save(VALUE self, VALUE val) {
ImStruct *im;
Imlib_Load_Error er;
char *path;
path = StringValuePtr(val);
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_save_image_with_error_return(path, &er);
if (er == IMLIB_LOAD_ERROR_NONE)
return self;
if (er > IMLIB_LOAD_ERROR_UNKNOWN)
er = IMLIB_LOAD_ERROR_UNKNOWN;
raise_imlib_error(path, er);
return Qnil;
}
static VALUE image_save_image(VALUE self, VALUE val) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_save_image(StringValuePtr(val));
return self;
}
static VALUE image_save_with_error_return(VALUE self, VALUE val) {
ImStruct *im;
Imlib_Load_Error er;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_save_image_with_error_return(StringValuePtr(val), &er);
if (er > IMLIB_LOAD_ERROR_UNKNOWN)
er = IMLIB_LOAD_ERROR_UNKNOWN;
return INT2FIX(er);
}
static VALUE image_clone(VALUE self) {
ImStruct *old_im, *new_im;
VALUE im_o;
new_im = malloc(sizeof(ImStruct));
GET_AND_CHECK_IMAGE(self, old_im);
imlib_context_set_image(old_im->im);
new_im->im = imlib_clone_image();
im_o = Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
return im_o;
}
static VALUE image_initialize(VALUE self) {
return self;
}
static VALUE image_delete(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
if (argc > 0 && argv[0] != Qnil && argv[0] != Qfalse)
imlib_free_image_and_decache();
else
imlib_free_image();
im->im = NULL;
return Qnil;
}
static VALUE image_width(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
return INT2FIX(imlib_image_get_width());
}
static VALUE image_height(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
return INT2FIX(imlib_image_get_height());
}
static VALUE image_filename(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
return rb_str_new2(imlib_image_get_filename());
}
static VALUE image_data(VALUE self) {
ImStruct *im;
int w, h;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
w = imlib_image_get_width();
h = imlib_image_get_height();
return rb_str_new((char*) imlib_image_get_data(), h * w * 4);
}
static VALUE image_data_ro(VALUE self) {
ImStruct *im;
int w, h;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
w = imlib_image_get_width();
h = imlib_image_get_height();
return rb_str_new((char*) imlib_image_get_data_for_reading_only(), h * w * 4);
}
static VALUE image_put_data(VALUE self, VALUE str) {
ImStruct *im;
DATA32 *old_data, *new_data;
int w, h, old_size;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
old_data = imlib_image_get_data();
w = imlib_image_get_width();
h = imlib_image_get_height();
old_size = w * h * 4;
new_data = (DATA32*) StringValuePtr(str);
if (RSTRING(str)->len != old_size)
rb_raise(rb_eArgError, "invalid buffer size");
if (old_data != new_data)
memcpy(old_data, new_data, old_size);
imlib_image_put_back_data(old_data);
return Qtrue;
}
static VALUE image_has_alpha(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
return imlib_image_has_alpha() ? Qtrue : Qfalse;
}
static VALUE image_set_has_alpha(VALUE self, VALUE val) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_set_has_alpha(val == Qtrue);
return val;
}
static VALUE image_changes_on_disk(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_set_changes_on_disk();
return Qtrue;
}
static VALUE image_get_border(VALUE self) {
ImStruct *im;
Imlib_Border *border;
VALUE argv[4];
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
border = malloc(sizeof(Imlib_Border));
imlib_image_get_border(border);
argv[0] = INT2NUM(border->left);
argv[1] = INT2NUM(border->top);
argv[2] = INT2NUM(border->right);
argv[3] = INT2NUM(border->bottom);
free(border);
return border_new(4, argv, cBorder);
}
static VALUE image_set_border(VALUE self, VALUE border) {
ImStruct *im;
Imlib_Border *b;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
Data_Get_Struct(border, Imlib_Border, b);
imlib_image_set_border(b);
return border;
}
static VALUE image_get_format(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
return rb_str_new2(imlib_image_format());
}
static VALUE image_set_format(VALUE self, VALUE format) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_set_format(StringValuePtr(format));
return format;
}
static VALUE image_irrelevant_format(VALUE self, VALUE val) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_set_irrelevant_format(val != Qfalse);
return val;
}
static VALUE image_irrelevant_border(VALUE self, VALUE val) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_set_irrelevant_border(val != Qfalse);
return val;
}
static VALUE image_irrelevant_alpha(VALUE self, VALUE val) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_set_irrelevant_alpha(val != Qfalse);
return val;
}
static VALUE image_query_pixel(VALUE self, VALUE x, VALUE y) {
ImStruct *im;
Imlib_Color color;
VALUE argv[4];
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_query_pixel(NUM2INT(x), NUM2INT(y), &color);
argv[0] = INT2NUM(color.red);
argv[1] = INT2NUM(color.green);
argv[2] = INT2NUM(color.blue);
argv[3] = INT2NUM(color.alpha);
return rgba_color_new(4, argv, cRgbaColor);
}
static VALUE image_query_pixel_hsva(VALUE self, VALUE x, VALUE y) {
ImStruct *im;
float hue, saturation, value;
int alpha;
VALUE argv[4];
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_query_pixel_hsva(NUM2INT(x), NUM2INT(y), &hue, &saturation, &value, &alpha);
argv[0] = rb_float_new(hue);
argv[1] = rb_float_new(saturation);
argv[2] = rb_float_new(value);
argv[3] = INT2NUM(alpha);
return hsva_color_new(4, argv, cHsvaColor);
}
static VALUE image_query_pixel_hlsa(VALUE self, VALUE x, VALUE y) {
ImStruct *im;
float hue, lightness, saturation;
int alpha;
VALUE argv[4];
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_query_pixel_hsva(NUM2INT(x), NUM2INT(y), &hue, &lightness, &saturation, &alpha);
argv[0] = rb_float_new(hue);
argv[1] = rb_float_new(lightness);
argv[2] = rb_float_new(saturation);
argv[3] = INT2NUM(alpha);
return hlsa_color_new(4, argv, cHlsaColor);
}
static VALUE image_query_pixel_cmya(VALUE self, VALUE x, VALUE y) {
ImStruct *im;
CmyaColor color;
VALUE argv[4];
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_query_pixel_cmya(NUM2INT(x), NUM2INT(y), &color.cyan, &color.magenta, &color.yellow, &color.alpha);
argv[0] = INT2NUM(color.cyan);
argv[1] = INT2NUM(color.magenta);
argv[2] = INT2NUM(color.yellow);
argv[3] = INT2NUM(color.alpha);
return cmya_color_new(4, argv, cCmyaColor);
}
static VALUE image_crop(int argc, VALUE *argv, VALUE self) {
ImStruct *old_im, *new_im;
VALUE im_o;
int x = 0, y = 0, w = 0, h = 0;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 4:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
break;
default:
rb_raise(rb_eTypeError,"Invalid argument count (not 1 or 4)");
}
GET_AND_CHECK_IMAGE(self, old_im);
imlib_context_set_image(old_im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_create_cropped_image(x, y, w, h);
im_o = Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
return im_o;
}
static VALUE image_crop_inline(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
Imlib_Image old_im;
int x = 0, y = 0, w = 0, h = 0;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 4:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
break;
default:
rb_raise(rb_eTypeError,"Invalid argument count (not 1 or 4)");
}
GET_AND_CHECK_IMAGE(self, im);
old_im = im->im;
imlib_context_set_image(old_im);
im->im = imlib_create_cropped_image(x, y, w, h);
imlib_context_set_image(old_im);
imlib_free_image();
return self;
}
static VALUE image_crop_scaled(int argc, VALUE *argv, VALUE self) {
ImStruct *old_im, *new_im;
VALUE im_o;
int x = 0, y = 0, w = 0, h = 0, dw = 0, dh = 0;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
dw = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("dw")));
dh = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("dh")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
dw = NUM2INT(rb_ary_entry(argv[0], 4));
dh = NUM2INT(rb_ary_entry(argv[0], 5));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 6:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
dw = NUM2INT(argv[4]);
dh = NUM2INT(argv[5]);
break;
default:
rb_raise(rb_eTypeError,"Invalid argument count (not 1 or 6)");
}
GET_AND_CHECK_IMAGE(self, old_im);
imlib_context_set_image(old_im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_create_cropped_scaled_image(x, y, w, h, dw, dh);
im_o = Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
return im_o;
}
static VALUE image_crop_scaled_inline(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
Imlib_Image old_im;
int x = 0, y = 0, w = 0, h = 0, dw = 0, dh = 0;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
dw = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("dw")));
dh = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("dh")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
dw = NUM2INT(rb_ary_entry(argv[0], 4));
dh = NUM2INT(rb_ary_entry(argv[0], 5));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 6:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
dw = NUM2INT(argv[4]);
dh = NUM2INT(argv[5]);
break;
default:
rb_raise(rb_eTypeError,"Invalid argument count (not 1 or 6)");
}
GET_AND_CHECK_IMAGE(self, im);
old_im = im->im;
imlib_context_set_image(old_im);
im->im = imlib_create_cropped_scaled_image(x, y, w, h, dw, dh);
imlib_context_set_image(old_im);
imlib_free_image();
return self;
}
static VALUE image_flip_horizontal(VALUE self) {
ImStruct *im, *new_im;
VALUE im_o;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_clone_image();
im_o = Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
imlib_context_set_image(new_im->im);
imlib_image_flip_horizontal();
return im_o;
}
static VALUE image_flip_horizontal_inline(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_flip_horizontal();
return self;
}
static VALUE image_flip_vertical(VALUE self) {
ImStruct *im, *new_im;
VALUE im_o;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_clone_image();
im_o = Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
imlib_context_set_image(new_im->im);
imlib_image_flip_vertical();
return im_o;
}
static VALUE image_flip_vertical_inline(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_flip_vertical();
return self;
}
static VALUE image_flip_diagonal(VALUE self) {
ImStruct *im, *new_im;
VALUE im_o;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_clone_image();
im_o = Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
imlib_context_set_image(new_im->im);
imlib_image_flip_diagonal();
return im_o;
}
static VALUE image_flip_diagonal_inline(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_flip_diagonal();
return self;
}
static VALUE image_orientate(VALUE self, VALUE val) {
ImStruct *im, *new_im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_clone_image();
imlib_context_set_image(new_im->im);
imlib_image_orientate(NUM2INT(val));
return Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
}
static VALUE image_orientate_inline(VALUE self, VALUE val) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_orientate(NUM2INT(val));
return self;
}
static VALUE image_blur(VALUE self, VALUE val) {
ImStruct *im, *new_im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_clone_image();
imlib_context_set_image(new_im->im);
imlib_image_blur(NUM2INT(val));
return Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
}
static VALUE image_blur_inline(VALUE self, VALUE val) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_blur(NUM2INT(val));
return self;
}
static VALUE image_sharpen(VALUE self, VALUE val) {
ImStruct *im, *new_im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_clone_image();
imlib_context_set_image(new_im->im);
imlib_image_sharpen(NUM2INT(val));
return Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
}
static VALUE image_sharpen_inline(VALUE self, VALUE val) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_sharpen(NUM2INT(val));
return self;
}
static VALUE image_tile_horizontal(VALUE self) {
ImStruct *im, *new_im;
VALUE im_o;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_clone_image();
im_o = Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
imlib_context_set_image(new_im->im);
imlib_image_tile_horizontal();
return im_o;
}
static VALUE image_tile_horizontal_inline(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_tile_horizontal();
return self;
}
static VALUE image_tile_vertical(VALUE self) {
ImStruct *im, *new_im;
VALUE im_o;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_clone_image();
im_o = Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
imlib_context_set_image(new_im->im);
imlib_image_tile_vertical();
return im_o;
}
static VALUE image_tile_vertical_inline(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_tile_vertical();
return self;
}
static VALUE image_tile(VALUE self) {
ImStruct *im, *new_im;
VALUE im_o;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_clone_image();
im_o = Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
imlib_context_set_image(new_im->im);
imlib_image_tile();
return im_o;
}
static VALUE image_tile_inline(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_tile();
return self;
}
static VALUE image_clear(VALUE self) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_clear();
return self;
}
static VALUE image_clear_color(VALUE self, VALUE rgba_color) {
ImStruct *im, *new_im;
Imlib_Color *color;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_clone_image();
imlib_context_set_image(new_im->im);
Data_Get_Struct(rgba_color, Imlib_Color, color);
imlib_image_clear_color(color->red, color->blue, color->green, color->alpha);
return Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
}
static VALUE image_clear_color_inline(VALUE self, VALUE rgba_color) {
ImStruct *im;
Imlib_Color *color;
GET_AND_CHECK_IMAGE(self, im);
Data_Get_Struct(rgba_color, Imlib_Color, color);
imlib_context_set_image(im->im);
imlib_image_clear_color(color->red, color->blue, color->green, color->alpha);
return self;
}
static VALUE image_draw_pixel(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
VALUE color = Qnil;
int x = 0, y = 0;
int blend, aa;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 2:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
color = argv[1];
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
color = argv[1];
break;
case T_FIXNUM:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 3:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
color = argv[2];
break;
default:
rb_raise(rb_eTypeError,"Invalid argument count (not 1, 2, or 3)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
if (color != Qnil)
set_context_color(color);
if (draw_pixel_workaround) {
blend = imlib_context_get_blend();
aa = imlib_context_get_anti_alias();
imlib_image_draw_rectangle(x, y, 1, 1);
imlib_context_set_blend(blend);
imlib_context_set_anti_alias(aa);
} else {
(void) imlib_image_draw_pixel(x, y, 0);
}
return self;
}
static VALUE image_draw_line(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
VALUE color = Qnil;
int i = 0, x[2] = {0, 0}, y[2] = {0, 0};
switch (argc) {
case 2:
for (i = 0; i < 2; i++) {
switch (TYPE(argv[i])) {
case T_HASH:
x[i] = NUM2INT(rb_hash_aref(argv[i], rb_str_new2("x")));
y[i] = NUM2INT(rb_hash_aref(argv[i], rb_str_new2("y")));
break;
case T_ARRAY:
x[i] = NUM2INT(rb_ary_entry(argv[i], 0));
y[i] = NUM2INT(rb_ary_entry(argv[i], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
}
break;
case 3:
for (i = 0; i < 2; i++) {
switch (TYPE(argv[i])) {
case T_HASH:
x[i] = NUM2INT(rb_hash_aref(argv[i], rb_str_new2("x")));
y[i] = NUM2INT(rb_hash_aref(argv[i], rb_str_new2("y")));
break;
case T_ARRAY:
x[i] = NUM2INT(rb_ary_entry(argv[i], 0));
y[i] = NUM2INT(rb_ary_entry(argv[i], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
}
color = argv[2];
break;
case 5:
color = argv[4];
case 4:
x[0] = NUM2INT(argv[0]);
y[0] = NUM2INT(argv[1]);
x[1] = NUM2INT(argv[2]);
y[1] = NUM2INT(argv[3]);
break;
default:
rb_raise(rb_eTypeError,"Invalid argument count (not 2, 3, 4, or 5)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
if (color != Qnil)
set_context_color(color);
(void) imlib_image_draw_line(x[0], y[0], x[1], y[1], 0);
return self;
}
static VALUE image_draw_rect(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
VALUE color = Qnil;
int x, y, w, h;
x = y = w = h = 0;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 2:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
color = argv[1];
}
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
color = argv[1];
}
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 3:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
color = argv[2];
break;
case 4:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
break;
case 5:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
color = argv[4];
break;
default:
rb_raise(rb_eTypeError,"Invalid argument count (not 1, 2, 3, 4, or 5)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
if (color != Qnil)
set_context_color(color);
imlib_image_draw_rectangle(x, y, w, h);
return self;
}
static VALUE image_fill_rect(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
VALUE color = Qnil;
int x, y, w, h;
x = y = w = h = 0;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 2:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
color = argv[1];
}
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
color = argv[1];
}
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 3:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
color = argv[2];
break;
case 4:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
break;
case 5:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
color = argv[4];
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 1, 2, 3, 4, or 5)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
if (color != Qnil)
set_context_color(color);
imlib_image_fill_rectangle(x, y, w, h);
return self;
}
static VALUE image_copy_alpha(int argc, VALUE *argv, VALUE self) {
ImStruct *src_im, *im;
VALUE src;
int x, y;
src = argv[0];
switch (argc) {
case 2:
switch (TYPE(argv[1])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[1], 0));
y = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 3:
x = NUM2INT(argv[1]);
y = NUM2INT(argv[2]);
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 2 or 3)");
}
GET_AND_CHECK_IMAGE(src, src_im);
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_copy_alpha_to_image(src_im->im, x, y);
return self;
}
static VALUE image_copy_alpha_rect(int argc, VALUE *argv, VALUE self) {
ImStruct *src_im, *im;
VALUE src;
int x, y, w, h, dx, dy;
x = y = w = h = dx = dy = 0;
src = argv[0];
switch (argc) {
case 2:
switch (TYPE(argv[1])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
dx = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("dy")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[1], 0));
y = NUM2INT(rb_ary_entry(argv[1], 1));
w = NUM2INT(rb_ary_entry(argv[1], 2));
h = NUM2INT(rb_ary_entry(argv[1], 3));
dx = NUM2INT(rb_ary_entry(argv[1], 4));
dy = NUM2INT(rb_ary_entry(argv[1], 5));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 3:
switch (TYPE(argv[1])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[1], 0));
y = NUM2INT(rb_ary_entry(argv[1], 1));
w = NUM2INT(rb_ary_entry(argv[1], 2));
h = NUM2INT(rb_ary_entry(argv[1], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
switch (TYPE(argv[2])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[1], 0));
dy = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 4:
switch (TYPE(argv[1])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("y")));
switch (TYPE(argv[2])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("h")));
switch (TYPE(argv[3])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[3], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[3], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[3], 0));
dy = NUM2INT(rb_ary_entry(argv[3], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[2], 0));
h = NUM2INT(rb_ary_entry(argv[2], 1));
switch (TYPE(argv[3])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[3], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[3], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[3], 0));
dy = NUM2INT(rb_ary_entry(argv[3], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
default:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
dx = NUM2INT(argv[2]);
dy = NUM2INT(argv[3]);
}
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[1], 0));
y = NUM2INT(rb_ary_entry(argv[1], 1));
switch (TYPE(argv[2])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("h")));
switch (TYPE(argv[3])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[3], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[3], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[3], 0));
dy = NUM2INT(rb_ary_entry(argv[3], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[2], 0));
h = NUM2INT(rb_ary_entry(argv[2], 1));
switch (TYPE(argv[3])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[3], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[3], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[3], 0));
dy = NUM2INT(rb_ary_entry(argv[3], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
default:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
dx = NUM2INT(argv[2]);
dy = NUM2INT(argv[3]);
}
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 5:
switch (TYPE(argv[1])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[1], 0));
y = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
switch (TYPE(argv[2])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[2], 0));
h = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
dx = NUM2INT(argv[3]);
dy = NUM2INT(argv[4]);
case 6:
switch (TYPE(argv[1])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("y")));
switch (TYPE(argv[2])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[2], 0));
h = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[1], 0));
y = NUM2INT(rb_ary_entry(argv[1], 1));
switch (TYPE(argv[2])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[2], 0));
h = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
default:
x = NUM2INT(argv[1]);
y = NUM2INT(argv[2]);
w = NUM2INT(argv[3]);
h = NUM2INT(argv[4]);
}
break;
case 7:
x = NUM2INT(argv[1]);
y = NUM2INT(argv[2]);
w = NUM2INT(argv[3]);
h = NUM2INT(argv[4]);
dx = NUM2INT(argv[5]);
dy = NUM2INT(argv[6]);
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count "
"(not 2, 3, 4, 5, 6, or 7)");
}
GET_AND_CHECK_IMAGE(src, src_im);
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_copy_alpha_rectangle_to_image(src_im->im, x, y, w, h, dx, dy);
return self;
}
static VALUE image_scroll_rect(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
int x, y, w, h, dx, dy;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
dx = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("dy")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
dx = NUM2INT(rb_ary_entry(argv[0], 4));
dy = NUM2INT(rb_ary_entry(argv[0], 5));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 2:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
switch (TYPE(argv[1])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[1], 0));
dy = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 3:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
switch (TYPE(argv[2])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[2], 0));
dy = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
switch (TYPE(argv[2])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[2], 0));
dy = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
default:
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
dx = NUM2INT(argv[1]);
dy = NUM2INT(argv[2]);
}
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
switch (TYPE(argv[2])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[2], 0));
dy = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
switch (TYPE(argv[2])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[2], 0));
dy = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
default:
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
dx = NUM2INT(argv[1]);
dy = NUM2INT(argv[2]);
}
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 4:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
dx = NUM2INT(argv[2]);
dy = NUM2INT(argv[3]);
break;
case 5:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
switch (TYPE(argv[4])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[4], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[4], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[4], 0));
dy = NUM2INT(rb_ary_entry(argv[4], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 6:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
dx = NUM2INT(argv[4]);
dy = NUM2INT(argv[5]);
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count "
"(not 2, 3, 4, 5, 6, or 7)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_scroll_rect(x, y, w, h, dx, dy);
return self;
}
static VALUE image_copy_rect(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
int x, y, w, h, dx, dy;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
dx = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("dy")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
dx = NUM2INT(rb_ary_entry(argv[0], 4));
dy = NUM2INT(rb_ary_entry(argv[0], 5));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 2:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
switch (TYPE(argv[1])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[1], 0));
dy = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 3:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
switch (TYPE(argv[2])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[2], 0));
dy = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
switch (TYPE(argv[2])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[2], 0));
dy = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
default:
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
dx = NUM2INT(argv[1]);
dy = NUM2INT(argv[2]);
}
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
switch (TYPE(argv[2])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[2], 0));
dy = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
switch (TYPE(argv[2])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[2], 0));
dy = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not array or hash)");
}
break;
default:
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
dx = NUM2INT(argv[1]);
dy = NUM2INT(argv[2]);
}
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 4:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
dx = NUM2INT(argv[2]);
dy = NUM2INT(argv[3]);
break;
case 5:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
switch (TYPE(argv[4])) {
case T_HASH:
dx = NUM2INT(rb_hash_aref(argv[4], rb_str_new2("dx")));
dy = NUM2INT(rb_hash_aref(argv[4], rb_str_new2("dy")));
break;
case T_ARRAY:
dx = NUM2INT(rb_ary_entry(argv[4], 0));
dy = NUM2INT(rb_ary_entry(argv[4], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 6:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
dx = NUM2INT(argv[4]);
dy = NUM2INT(argv[5]);
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count "
"(not 2, 3, 4, 5, 6, or 7)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_image_copy_rect(x, y, w, h, dx, dy);
return self;
}
static VALUE image_draw_ellipse(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
VALUE color = Qnil;
int x, y, w, h;
x = y = w = h = 0;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 2:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
color = argv[1];
}
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
color = argv[1];
}
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 3:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
color = argv[2];
break;
case 4:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
break;
case 5:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
color = argv[4];
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 1, 2, 3, 4, or 5)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
if (color != Qnil)
set_context_color(color);
imlib_image_draw_ellipse(x, y, w, h);
return self;
}
static VALUE image_fill_ellipse(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
VALUE color = Qnil;
int x, y, w, h;
x = y = w = h = 0;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 2:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
color = argv[1];
}
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
w = NUM2INT(rb_ary_entry(argv[0], 2));
h = NUM2INT(rb_ary_entry(argv[0], 3));
color = argv[1];
}
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 3:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
switch (TYPE(argv[1])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[1], 0));
h = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
color = argv[2];
break;
case 4:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
break;
case 5:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
w = NUM2INT(argv[2]);
h = NUM2INT(argv[3]);
color = argv[4];
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 1, 2, 3, 4, or 5)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
if (color != Qnil)
set_context_color(color);
imlib_image_fill_ellipse(x, y, w, h);
return self;
}
static VALUE image_blend_image_inline(int argc, VALUE *argv, VALUE self) {
ImStruct *im, *src_im;
int i, s[4], d[4];
char merge_alpha = 1;
switch (argc) {
case 4:
merge_alpha = (argv[3] == Qtrue) ? 1 : 0;
case 3:
switch (TYPE(argv[1])) {
case T_HASH:
s[0] = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("x")));
s[1] = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("y")));
s[2] = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
s[3] = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
for (i = 0; i < 4; i++)
s[i] = NUM2INT(rb_ary_entry(argv[1], i));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
switch (TYPE(argv[2])) {
case T_HASH:
d[0] = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("x")));
d[1] = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("y")));
d[2] = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("w")));
d[3] = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("h")));
break;
case T_ARRAY:
for (i = 0; i < 4; i++)
d[i] = NUM2INT(rb_ary_entry(argv[2], i));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 6:
merge_alpha = (argv[5] == Qtrue) ? 1 : 0;
case 5:
switch (TYPE(argv[1])) {
case T_HASH:
s[0] = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("x")));
s[1] = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("y")));
break;
case T_ARRAY:
for (i = 0; i < 2; i++)
s[i] = NUM2INT(rb_ary_entry(argv[1], i));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
switch (TYPE(argv[2])) {
case T_HASH:
s[2] = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("s")));
s[3] = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("h")));
break;
case T_ARRAY:
for (i = 0; i < 2; i++)
s[i + 2] = NUM2INT(rb_ary_entry(argv[2], i));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
switch (TYPE(argv[3])) {
case T_HASH:
d[0] = NUM2INT(rb_hash_aref(argv[3], rb_str_new2("x")));
d[1] = NUM2INT(rb_hash_aref(argv[3], rb_str_new2("y")));
break;
case T_ARRAY:
for (i = 0; i < 2; i++)
d[i] = NUM2INT(rb_ary_entry(argv[3], i));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
switch (TYPE(argv[4])) {
case T_HASH:
d[2] = NUM2INT(rb_hash_aref(argv[4], rb_str_new2("s")));
d[3] = NUM2INT(rb_hash_aref(argv[4], rb_str_new2("h")));
break;
case T_ARRAY:
for (i = 0; i < 2; i++)
d[i + 2] = NUM2INT(rb_ary_entry(argv[4], i));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 10:
merge_alpha = (argv[9] == Qtrue) ? 1 : 0;
case 9:
for (i = 0; i < 4; i++)
s[i] = NUM2INT(argv[i + 1]);
for (i = 0; i < 4; i++)
d[i] = NUM2INT(argv[i + 5]);
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count "
"(not 3, 4, 5, 6, 9, or 10)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
GET_AND_CHECK_IMAGE(argv[0], src_im);
imlib_blend_image_onto_image(src_im->im, merge_alpha,
s[0], s[1], s[2], s[3],
d[0], d[1], d[2], d[3]);
return self;
}
static VALUE image_blend_image(int argc, VALUE *argv, VALUE self) {
ImStruct *im, *new_im;
VALUE i_o;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
new_im = malloc(sizeof(ImStruct));
new_im->im = imlib_clone_image();
i_o = Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
return image_blend_image_inline(argc, argv, i_o);
}
static VALUE image_rotate(VALUE self, VALUE angle) {
ImStruct *new_im, *im;
double a;
new_im = malloc(sizeof(ImStruct));
GET_AND_CHECK_IMAGE(self, im);
a = rb_float_new(angle);
imlib_context_set_image(im->im);
new_im->im = imlib_create_rotated_image(a);
return Data_Wrap_Struct(cImage, 0, im_struct_free, new_im);
}
static VALUE image_rotate_inline(VALUE self, VALUE angle) {
ImStruct *im;
Imlib_Image new_im;
double a;
GET_AND_CHECK_IMAGE(self, im);
a = rb_float_new(angle);
imlib_context_set_image(im->im);
new_im = imlib_create_rotated_image(a);
imlib_context_set_image(im->im);
imlib_free_image();
im->im = new_im;
return self;
}
static VALUE image_draw_text(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
Imlib_Font *font;
VALUE text, ary, color = Qnil, dir = Qnil;
int x, y, i, r[] = { 0, 0, 0, 0 }, old_dir = -1;
switch (argc) {
case 3:
switch (TYPE(argv[2])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[2], 0));
y = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 2 or 3)");
}
break;
case 4:
switch (TYPE(argv[2])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("y")));
if (FIXNUM_P(argv[3]))
dir = argv[3];
else
color = argv[3];
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[2], 0));
y = NUM2INT(rb_ary_entry(argv[2], 1));
break;
if (FIXNUM_P(argv[3]))
dir = argv[3];
else
color = argv[3];
default:
x = NUM2INT(argv[2]);
y = NUM2INT(argv[3]);
}
break;
case 5:
if (FIXNUM_P(argv[2])) {
x = NUM2INT(argv[2]);
y = NUM2INT(argv[3]);
color = argv[4];
} else {
switch (TYPE(argv[2])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[2], 0));
y = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type "
"(not Array or Hash)");
}
color = argv[3];
dir = argv[4];
}
break;
case 6:
x = NUM2INT(argv[2]);
y = NUM2INT(argv[3]);
color = argv[4];
dir = argv[5];
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 3, 4, or 5)");
}
Data_Get_Struct(argv[0], Imlib_Font, font);
GET_AND_CHECK_IMAGE(self, im);
text = argv[1];
imlib_context_set_font(*font);
imlib_context_set_image(im->im);
if (color != Qnil)
set_context_color(color);
if (dir != Qnil) {
old_dir = imlib_context_get_direction();
imlib_context_set_direction(NUM2INT(dir));
}
imlib_text_draw_with_return_metrics(x, y, StringValuePtr(text),
&r[0], &r[1], &r[2], &r[3]);
if (dir != Qnil)
imlib_context_set_direction(old_dir);
ary = rb_ary_new();
for (i = 0; i < 4; i++)
rb_ary_push(ary, INT2FIX(r[i]));
return ary;
}
static VALUE image_fill_gradient(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
Imlib_Color_Range *grad;
int x, y, w, h;
double angle;
switch (argc) {
case 3:
switch (TYPE(argv[1])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[1], 0));
y = NUM2INT(rb_ary_entry(argv[1], 1));
w = NUM2INT(rb_ary_entry(argv[1], 2));
h = NUM2INT(rb_ary_entry(argv[1], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
angle = NUM2DBL(argv[2]);
break;
case 4:
switch (TYPE(argv[1])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[1], 0));
y = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
switch (TYPE(argv[2])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[2], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[2], 0));
h = NUM2INT(rb_ary_entry(argv[2], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
angle = NUM2DBL(argv[3]);
break;
case 6:
x = NUM2INT(argv[1]);
y = NUM2INT(argv[2]);
w = NUM2INT(argv[3]);
h = NUM2INT(argv[4]);
angle = NUM2DBL(argv[5]);
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 3, 4, or 6)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
Data_Get_Struct(argv[0], Imlib_Color_Range, grad);
imlib_context_set_color_range(*grad);
imlib_image_fill_color_range_rectangle(x, y, w, h, angle);
return self;
}
static VALUE image_draw_poly(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
ImlibPolygon *poly;
VALUE color = Qnil;
unsigned char closed = Qtrue;
switch (argc) {
case 1:
break;
case 2:
if ((rb_obj_is_kind_of(argv[1], cRgbaColor) == Qtrue) ||
(rb_obj_is_kind_of(argv[1], cHsvaColor) == Qtrue) ||
(rb_obj_is_kind_of(argv[1], cHlsaColor) == Qtrue) ||
(rb_obj_is_kind_of(argv[1], cCmyaColor) == Qtrue)) {
color = argv[1];
} else {
closed = (argv[1] == Qtrue) ? 1 : 0;
}
break;
case 3:
closed = (argv[1] == Qtrue) ? 1 : 0;
color = argv[2];
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 3, 4, or 6)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
if (color != Qnil)
set_context_color(color);
Data_Get_Struct(argv[0], ImlibPolygon, poly);
imlib_image_draw_polygon(*poly, closed);
return self;
}
static VALUE image_fill_poly(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
ImlibPolygon *poly;
VALUE color = Qnil;
switch (argc) {
case 1:
break;
case 2:
color = argv[1];
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 3, 4, or 6)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
if (color != Qnil)
set_context_color(color);
Data_Get_Struct(argv[0], ImlibPolygon, poly);
imlib_image_fill_polygon(*poly);
return self;
}
static VALUE image_static_filter(VALUE self, VALUE filter) {
ImStruct *im;
Imlib_Filter *f;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
Data_Get_Struct(filter, Imlib_Filter, f);
imlib_context_set_filter(*f);
imlib_image_filter();
return self;
}
static VALUE image_script_filter(VALUE self, VALUE filter) {
ImStruct *im;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
imlib_apply_filter(StringValuePtr(filter));
return self;
}
static VALUE image_filter(VALUE self, VALUE filter) {
if (rb_obj_is_kind_of(self, rb_cString) == Qtrue) {
return image_static_filter(self, filter);
} else if (rb_obj_is_kind_of(self, cFilter) == Qtrue) {
return image_script_filter(self, filter);
} else {
rb_raise(rb_eTypeError, "Invalid argument type "
"(not String or Imlib2::Filter)");
}
return self;
}
static VALUE image_apply_cmod(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
Imlib_Color_Modifier *cmod;
char whole_image = 0;
int x, y, w, h;
x = y = w = h = 0;
switch (argc) {
case 1:
whole_image = 1;
break;
case 2:
switch (TYPE(argv[1])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("y")));
w = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("h")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[1], 0));
y = NUM2INT(rb_ary_entry(argv[1], 1));
w = NUM2INT(rb_ary_entry(argv[1], 2));
h = NUM2INT(rb_ary_entry(argv[1], 3));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 5:
x = NUM2INT(argv[1]);
y = NUM2INT(argv[2]);
w = NUM2INT(argv[3]);
h = NUM2INT(argv[4]);
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 1, 2, or 5)");
}
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
Data_Get_Struct(argv[0], Imlib_Color_Modifier, cmod);
imlib_context_set_color_modifier(*cmod);
if (whole_image)
imlib_apply_color_modifier();
else
imlib_apply_color_modifier_to_rectangle(x, y, w, h);
return self;
}
#ifndef X_DISPLAY_MISSING
static VALUE image_render_pixmap(int argc, VALUE *argv, VALUE self) {
ImStruct *im;
Imlib_Image old_im;
Pixmap *pmap, *mask;
VALUE ary;
int w, h;
char at_size = 0;
switch (argc) {
case 0:
at_size = 0;
break;
case 1:
at_size = 1;
switch (TYPE(argv[0])) {
case T_HASH:
w = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("w")));
h = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("h")));
break;
case T_ARRAY:
w = NUM2INT(rb_ary_entry(argv[0], 0));
h = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError,"Invalid argument type (not array or hash)");
}
break;
case 2:
at_size = 1;
w = NUM2INT(argv[0]);
h = NUM2INT(argv[1]);
break;
default:
rb_raise(rb_eArgError, "Invalid argument count (not 0, 1, or 2)");
}
old_im = imlib_context_get_image();
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
if (at_size)
imlib_render_pixmaps_for_whole_image_at_size(pmap, mask, w, h);
else
imlib_render_pixmaps_for_whole_image(pmap, mask);
imlib_context_set_image(old_im);
ary = rb_ary_new();
rb_ary_push(ary, Data_Wrap_Struct(cPixmap, 0, free, pmap));
rb_ary_push(ary, Data_Wrap_Struct(cPixmap, 0, free, mask));
return ary;
}
#endif
static VALUE image_attach_val(VALUE self, VALUE key_o, VALUE val_o) {
ImStruct *im;
char *key;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
key = StringValuePtr(key_o);
if (rb_obj_is_kind_of(val_o, rb_cNumeric)) {
int val = NUM2INT(val_o);
imlib_image_attach_data_value(key, NULL, val, NULL);
} else {
rb_raise(rb_eTypeError, "Invalid argument (not string or integer)");
}
return val_o;
}
static VALUE image_get_attach_val(VALUE self, VALUE key_o) {
ImStruct *im;
VALUE ret;
char *key;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
key = StringValuePtr(key_o);
ret = INT2FIX(imlib_image_get_attached_value(key));
return ret;
}
static VALUE image_rm_attach_val(VALUE self, VALUE key_o) {
ImStruct *im;
char *key;
GET_AND_CHECK_IMAGE(self, im);
imlib_context_set_image(im->im);
key = StringValuePtr(key_o);
imlib_image_remove_attached_data_value(key);
return Qnil;
}
static void cmod_free(void *val) {
Imlib_Color_Modifier *cmod = (Imlib_Color_Modifier*) val;
imlib_context_set_color_modifier(*cmod);
imlib_free_color_modifier();
free(cmod);
}
VALUE cmod_new(VALUE klass) {
Imlib_Color_Modifier *cmod;
VALUE self;
cmod = malloc(sizeof(Imlib_Color_Modifier));
self = Data_Wrap_Struct(klass, 0, cmod_free, cmod);
rb_obj_call_init(self, 0, NULL);
return self;
}
static VALUE cmod_init(VALUE self) {
return self;
}
static VALUE cmod_gamma(VALUE self, VALUE gamma) {
Imlib_Color_Modifier *cmod;
Data_Get_Struct(self, Imlib_Color_Modifier, cmod);
imlib_context_set_color_modifier(*cmod);
imlib_modify_color_modifier_gamma(NUM2DBL(gamma));
return self;
}
static VALUE cmod_brightness(VALUE self, VALUE brightness) {
Imlib_Color_Modifier *cmod;
Data_Get_Struct(self, Imlib_Color_Modifier, cmod);
imlib_context_set_color_modifier(*cmod);
imlib_modify_color_modifier_brightness(NUM2DBL(brightness));
return self;
}
static VALUE cmod_contrast(VALUE self, VALUE contrast) {
Imlib_Color_Modifier *cmod;
Data_Get_Struct(self, Imlib_Color_Modifier, cmod);
imlib_context_set_color_modifier(*cmod);
imlib_modify_color_modifier_contrast(NUM2DBL(contrast));
return self;
}
static VALUE cmod_reset(VALUE self) {
Imlib_Color_Modifier *cmod;
Data_Get_Struct(self, Imlib_Color_Modifier, cmod);
imlib_context_set_color_modifier(*cmod);
imlib_reset_color_modifier();
return self;
}
static void font_free(void *val) {
Imlib_Font *font = (Imlib_Font*) val;
imlib_context_set_font(*font);
imlib_free_font();
free(font);
}
VALUE font_new(VALUE klass, VALUE font_name) {
Imlib_Font *font;
VALUE f_o;
font = malloc(sizeof(Imlib_Font*));
*font = imlib_load_font(StringValuePtr(font_name));
f_o = Data_Wrap_Struct(klass, 0, font_free, font);
rb_obj_call_init(f_o, 0, NULL);
return f_o;
}
static VALUE font_init(VALUE self) {
return self;
}
static VALUE font_text_size(VALUE self, VALUE text) {
Imlib_Font *font;
int sw = 0, sh = 0;
Data_Get_Struct(self, Imlib_Font, font);
imlib_context_set_font(*font);
imlib_get_text_size(StringValuePtr(text), &sw, &sh);
return rb_ary_new3 (2, INT2FIX(sw), INT2FIX(sh));
}
static VALUE font_text_advance(VALUE self, VALUE text) {
Imlib_Font *font;
int sw = 0, sh = 0;
Data_Get_Struct(self, Imlib_Font, font);
imlib_context_set_font(*font);
imlib_get_text_advance(StringValuePtr(text), &sw, &sh);
return rb_ary_new3 (2, INT2FIX(sw), INT2FIX (sh));
}
static VALUE font_text_inset(VALUE self, VALUE text) {
Imlib_Font *font;
Data_Get_Struct(self, Imlib_Font, font);
imlib_context_set_font(*font);
return INT2FIX(imlib_get_text_inset(StringValuePtr(text)));
}
static VALUE font_text_index(int argc, VALUE *argv, VALUE self) {
Imlib_Font *font;
VALUE text, ary;
int x, y, i, r[] = { 0, 0, 0, 0 };
text = argv[0];
switch (argc) {
case 2:
switch (TYPE(argv[1])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[1], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[1], 0));
y = NUM2INT(rb_ary_entry(argv[1], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 2 or 3)");
}
break;
case 3:
x = NUM2INT(argv[1]);
y = NUM2INT(argv[2]);
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 2 or 3)");
}
Data_Get_Struct(self, Imlib_Font, font);
imlib_context_set_font(*font);
imlib_text_get_index_and_location(StringValuePtr(text), x, y,
&r[0], &r[1], &r[2], &r[3]);
ary = rb_ary_new();
for (i = 0; i < 4; i++)
rb_ary_push(ary, INT2FIX(r[i]));
return ary;
}
static VALUE font_text_location(VALUE self, VALUE text, VALUE index) {
Imlib_Font *font;
VALUE ary;
int i, r[] = { 0, 0, 0, 0 };
Data_Get_Struct(self, Imlib_Font, font);
imlib_context_set_font(*font);
imlib_text_get_location_at_index(StringValuePtr(text), NUM2INT(index),
&r[0], &r[1], &r[2], &r[3]);
ary = rb_ary_new();
for (i = 0; i < 4; i++)
rb_ary_push(ary, INT2FIX(r[i]));
return ary;
}
static VALUE font_ascent(VALUE self) {
Imlib_Font *font;
Data_Get_Struct(self, Imlib_Font, font);
imlib_context_set_font(*font);
return INT2FIX(imlib_get_font_ascent());
}
static VALUE font_descent(VALUE self) {
Imlib_Font *font;
Data_Get_Struct(self, Imlib_Font, font);
imlib_context_set_font(*font);
return INT2FIX(imlib_get_font_descent());
}
static VALUE font_maximum_ascent(VALUE self) {
Imlib_Font *font;
Data_Get_Struct(self, Imlib_Font, font);
imlib_context_set_font(*font);
return INT2FIX(imlib_get_maximum_font_ascent());
}
static VALUE font_maximum_descent(VALUE self) {
Imlib_Font *font;
Data_Get_Struct(self, Imlib_Font, font);
imlib_context_set_font(*font);
return INT2FIX(imlib_get_maximum_font_descent());
}
static VALUE font_list_fonts(VALUE klass) {
VALUE ary;
char **list;
int i, len;
UNUSED(klass);
list = imlib_list_fonts(&len);
ary = rb_ary_new();
for (i = 0; i < len; i++)
rb_ary_push(ary, rb_str_new2(list[i]));
imlib_free_font_list(list, len);
return ary;
}
static VALUE font_add_path(VALUE klass, VALUE path) {
UNUSED(klass);
imlib_add_path_to_font_path(StringValuePtr(path));
return Qtrue;
}
static VALUE font_remove_path(VALUE klass, VALUE path) {
UNUSED(klass);
imlib_remove_path_from_font_path(StringValuePtr(path));
return Qtrue;
}
static VALUE font_list_paths(VALUE klass) {
VALUE ary;
char **list;
int i, len;
UNUSED(klass);
list = imlib_list_font_path(&len);
ary = rb_ary_new();
for (i = 0; i < len; i++)
rb_ary_push(ary, rb_str_new2(list[i]));
imlib_free_font_list(list, len);
return ary;
}
static void gradient_free(void *val) {
Imlib_Color_Range *range = (Imlib_Color_Range*) val;
imlib_context_set_color_range(*range);
imlib_free_color_range();
free(range);
}
VALUE gradient_new(int argc, VALUE *argv, VALUE klass) {
Imlib_Color_Range *range;
VALUE g_o;
range = malloc(sizeof(Imlib_Color_Range*));
*range = imlib_create_color_range();
g_o = Data_Wrap_Struct(klass, 0, gradient_free, range);
rb_obj_call_init(g_o, argc, argv);
return g_o;
}
static VALUE gradient_add_color(int argc, VALUE *argv, VALUE self) {
Imlib_Color_Range *grad;
VALUE color = Qnil;
int distance;
switch (argc) {
case 1:
distance = NUM2INT(argv[0]);
break;
case 2:
distance = NUM2INT(argv[0]);
color = argv[1];
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 1 or 2)");
}
Data_Get_Struct(self, Imlib_Color_Range, grad);
imlib_context_set_color_range(*grad);
if (color != Qnil)
set_context_color(color);
imlib_add_color_to_color_range(distance);
return self;
}
static VALUE gradient_init(int argc, VALUE *argv, VALUE self) {
int i;
for (i = 0; i < argc; i++) {
VALUE args[2];
args[0]= rb_ary_entry(argv[i], 0);
args[1] = rb_ary_entry(argv[i], 1);
gradient_add_color(2, args, self);
}
return self;
}
static void poly_free(void *val) {
ImlibPolygon *poly = (ImlibPolygon*) val;
imlib_polygon_free(*poly);
free(poly);
}
VALUE poly_new(int argc, VALUE *argv, VALUE klass) {
ImlibPolygon *poly;
VALUE p_o;
poly = malloc(sizeof(ImlibPolygon*));
*poly = imlib_polygon_new();
p_o = Data_Wrap_Struct(klass, 0, poly_free, poly);
rb_obj_call_init(p_o, argc, argv);
return p_o;
}
static VALUE poly_add_point(int argc, VALUE *argv, VALUE self) {
ImlibPolygon *poly;
int x, y;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 2 or 3)");
}
break;
case 2:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 2 or 3)");
}
Data_Get_Struct(self, ImlibPolygon, poly);
imlib_polygon_add_point(*poly, x, y);
return self;
}
static VALUE poly_init(int argc, VALUE *argv, VALUE self) {
VALUE args[1];
int i;
for (i = 0; i < argc; i++) {
args[0] = argv[i];
poly_add_point(1, args, self);
}
return self;
}
static VALUE poly_bounds(VALUE self) {
ImlibPolygon *poly;
VALUE ary;
int i, r[4] = { 0, 0, 0, 0 };
Data_Get_Struct(self, ImlibPolygon, poly);
imlib_polygon_get_bounds(*poly, &r[0], &r[1], &r[2], &r[3]);
ary = rb_ary_new();
for (i = 0; i < 4; i++)
rb_ary_push(ary, INT2FIX(r[i]));
return ary;
}
static VALUE poly_contains(int argc, char *argv, VALUE self) {
ImlibPolygon *poly;
int x, y;
switch (argc) {
case 1:
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 2:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 2 or 3)");
}
Data_Get_Struct(self, ImlibPolygon, poly);
return imlib_polygon_contains_point(*poly, x, y) ? Qtrue : Qfalse;
}
static void filter_free(void *filter) {
Imlib_Filter *f = (Imlib_Filter*) filter;
imlib_context_set_filter(*f);
imlib_free_filter();
free(f);
}
VALUE filter_new(VALUE initsize, VALUE klass) {
Imlib_Filter *f = malloc(sizeof(Imlib_Filter));
VALUE f_o, vals[1];
*f = imlib_create_filter(NUM2INT(initsize));
f_o = Data_Wrap_Struct(klass, 0, filter_free, f);
vals[0] = initsize;
rb_obj_call_init(f_o, 1, vals);
return f_o;
}
VALUE filter_init(VALUE self, VALUE initsize) {
UNUSED(initsize);
return self;
}
VALUE filter_set(int argc, VALUE *argv, VALUE self) {
Imlib_Filter *f;
Imlib_Color *c;
int x, y;
VALUE color;
switch (argc) {
case 2:
color = argv[1];
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 3:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
color = argv[2];
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 2 or 3)");
}
Data_Get_Struct(self, Imlib_Filter, f);
Data_Get_Struct(color, Imlib_Color, c);
imlib_context_set_filter(*f);
imlib_filter_set(x, y, c->alpha, c->red, c->green, c->blue);
return self;
}
VALUE filter_set_red(int argc, VALUE *argv, VALUE self) {
Imlib_Filter *f;
Imlib_Color *c;
int x, y;
VALUE color;
switch (argc) {
case 2:
color = argv[1];
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 3:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
color = argv[2];
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 2 or 3)");
}
Data_Get_Struct(self, Imlib_Filter, f);
Data_Get_Struct(color, Imlib_Color, c);
imlib_context_set_filter(*f);
imlib_filter_set_red(x, y, c->alpha, c->red, c->green, c->blue);
return self;
}
VALUE filter_set_green(int argc, VALUE *argv, VALUE self) {
Imlib_Filter *f;
Imlib_Color *c;
int x, y;
VALUE color;
switch (argc) {
case 2:
color = argv[1];
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 3:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
color = argv[2];
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 2 or 3)");
}
Data_Get_Struct(self, Imlib_Filter, f);
Data_Get_Struct(color, Imlib_Color, c);
imlib_context_set_filter(*f);
imlib_filter_set_green(x, y, c->alpha, c->red, c->green, c->blue);
return self;
}
VALUE filter_set_blue(int argc, VALUE *argv, VALUE self) {
Imlib_Filter *f;
Imlib_Color *c;
int x, y;
VALUE color;
switch (argc) {
case 2:
color = argv[1];
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 3:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
color = argv[2];
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 2 or 3)");
}
Data_Get_Struct(self, Imlib_Filter, f);
Data_Get_Struct(color, Imlib_Color, c);
imlib_context_set_filter(*f);
imlib_filter_set_blue(x, y, c->alpha, c->red, c->green, c->blue);
return self;
}
VALUE filter_set_alpha(int argc, VALUE *argv, VALUE self) {
Imlib_Filter *f;
Imlib_Color *c;
int x, y;
VALUE color;
switch (argc) {
case 2:
color = argv[1];
switch (TYPE(argv[0])) {
case T_HASH:
x = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("x")));
y = NUM2INT(rb_hash_aref(argv[0], rb_str_new2("y")));
break;
case T_ARRAY:
x = NUM2INT(rb_ary_entry(argv[0], 0));
y = NUM2INT(rb_ary_entry(argv[0], 1));
break;
default:
rb_raise(rb_eTypeError, "Invalid argument type (not array or hash)");
}
break;
case 3:
x = NUM2INT(argv[0]);
y = NUM2INT(argv[1]);
color = argv[2];
break;
default:
rb_raise(rb_eTypeError, "Invalid argument count (not 2 or 3)");
}
Data_Get_Struct(self, Imlib_Filter, f);
Data_Get_Struct(color, Imlib_Color, c);
imlib_context_set_filter(*f);
imlib_filter_set_alpha(x, y, c->alpha, c->red, c->green, c->blue);
return self;
}
VALUE filter_constants(VALUE self, VALUE color) {
Imlib_Filter *f;
Imlib_Color *c;
Data_Get_Struct(self, Imlib_Filter, f);
Data_Get_Struct(color, Imlib_Color, c);
imlib_context_set_filter(*f);
imlib_filter_constants(c->alpha, c->red, c->green, c->blue);
return self;
}
VALUE filter_divisors(VALUE self, VALUE color) {
Imlib_Filter *f;
Imlib_Color *c;
Data_Get_Struct(self, Imlib_Filter, f);
Data_Get_Struct(color, Imlib_Color, c);
imlib_context_set_filter(*f);
imlib_filter_divisors(c->alpha, c->red, c->green, c->blue);
return self;
}
static void ctx_free(void *val) {
Imlib_Context *ctx = (Imlib_Context *) val;
imlib_context_free(*ctx);
free(ctx);
}
VALUE ctx_new(VALUE klass) {
VALUE self;
Imlib_Context *ctx;
ctx = malloc(sizeof(Imlib_Context));
*ctx = imlib_context_new();
self = Data_Wrap_Struct(klass, 0, ctx_free, ctx);
rb_obj_call_init(self, 0, NULL);
return self;
}
static VALUE ctx_init(VALUE self) {
return self;
}
VALUE ctx_pop(VALUE klass) {
Imlib_Context *ctx;
ctx = (Imlib_Context *) malloc(sizeof(Imlib_Context));
imlib_context_pop();
*ctx = imlib_context_get();
return Data_Wrap_Struct(klass, 0, ctx_free, ctx);
}
VALUE ctx_get(VALUE klass) {
Imlib_Context *ctx;
ctx = (Imlib_Context *) malloc(sizeof(Imlib_Context));
*ctx = imlib_context_get();
return Data_Wrap_Struct(klass, 0, ctx_free, ctx);
}
static VALUE ctx_push(VALUE self) {
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
return self;
}
static VALUE ctx_set_dither_mask(VALUE self, VALUE val) {
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
imlib_context_set_dither_mask(val != Qnil && val != Qfalse);
imlib_context_pop();
return self;
}
static VALUE ctx_dither_mask(VALUE self) {
Imlib_Context *ctx;
VALUE r = Qfalse;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
r = imlib_context_get_dither_mask() ? Qtrue : Qfalse;
imlib_context_pop();
return r;
}
static VALUE ctx_set_aa(VALUE self, VALUE val) {
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
imlib_context_set_anti_alias(val != Qnil && val != Qfalse);
imlib_context_pop();
return self;
}
static VALUE ctx_aa(VALUE self) {
Imlib_Context *ctx;
VALUE r = Qfalse;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
r = imlib_context_get_anti_alias() ? Qtrue : Qfalse;
imlib_context_pop();
return r;
}
static VALUE ctx_set_dither(VALUE self, VALUE val) {
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
imlib_context_set_dither(val != Qnil && val != Qfalse);
imlib_context_pop();
return self;
}
static VALUE ctx_dither(VALUE self) {
Imlib_Context *ctx;
VALUE r = Qfalse;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
r = imlib_context_get_dither() ? Qtrue : Qfalse;
imlib_context_pop();
return r;
}
static VALUE ctx_set_blend(VALUE self, VALUE val) {
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
imlib_context_set_blend(val != Qnil && val != Qfalse);
imlib_context_pop();
return self;
}
static VALUE ctx_blend(VALUE self) {
Imlib_Context *ctx;
VALUE r = Qfalse;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
r = imlib_context_get_blend() ? Qtrue : Qfalse;
imlib_context_pop();
return r;
}
static VALUE ctx_set_cmod(VALUE self, VALUE val) {
Imlib_Context *ctx;
Imlib_Color_Modifier *cmod;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
Data_Get_Struct(val, Imlib_Color_Modifier, cmod);
imlib_context_set_color_modifier(*cmod);
imlib_context_pop();
return self;
}
static VALUE ctx_cmod(VALUE self) {
Imlib_Context *ctx;
Imlib_Color_Modifier *cmod;
cmod = malloc(sizeof(Imlib_Color_Modifier));
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
*cmod = imlib_context_get_color_modifier();
imlib_context_pop();
return Data_Wrap_Struct(cColorMod, 0, cmod_free, cmod);
}
static VALUE ctx_set_op(VALUE self, VALUE val) {
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
imlib_context_set_operation(NUM2INT(val));
imlib_context_pop();
return self;
}
static VALUE ctx_op(VALUE self) {
Imlib_Context *ctx;
VALUE r = Qnil;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
r = INT2FIX(imlib_context_get_operation());
imlib_context_pop();
return r;
}
static VALUE ctx_set_font(VALUE self, VALUE val) {
Imlib_Context *ctx;
Imlib_Font *font;
font = malloc(sizeof(Imlib_Font));
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
Data_Get_Struct(val, Imlib_Font, font);
imlib_context_set_font(*font);
imlib_context_pop();
return self;
}
static VALUE ctx_font(VALUE self) {
Imlib_Context *ctx;
VALUE r = Qnil;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
r = Data_Wrap_Struct(cFont, 0, font_free, imlib_context_get_font());
imlib_context_pop();
return r;
}
static VALUE ctx_set_dir(VALUE self, VALUE val) {
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
imlib_context_set_direction(NUM2INT(val));
imlib_context_pop();
return self;
}
static VALUE ctx_dir(VALUE self) {
Imlib_Context *ctx;
VALUE r = Qnil;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
r = INT2FIX(imlib_context_get_direction());
imlib_context_pop();
return r;
}
static VALUE ctx_set_angle(VALUE self, VALUE val) {
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
imlib_context_set_angle(NUM2DBL(val));
imlib_context_pop();
return self;
}
static VALUE ctx_angle(VALUE self) {
Imlib_Context *ctx;
VALUE r = Qnil;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
r = rb_float_new(imlib_context_get_angle());
imlib_context_pop();
return r;
}
static VALUE ctx_set_color(VALUE self, VALUE val) {
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
set_context_color(val);
imlib_context_pop();
return self;
}
static VALUE ctx_color(VALUE self) {
Imlib_Context *ctx;
VALUE argv[4];
int i, r[4];
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
imlib_context_get_color(&(r[0]), &(r[1]), &(r[2]), &(r[3]));
imlib_context_pop();
for (i = 0; i < 4; i++)
argv[i] = INT2NUM(r[i]);
return rgba_color_new(4, argv, cRgbaColor);
}
static VALUE ctx_set_gradient(VALUE self, VALUE val) {
Imlib_Context *ctx;
Imlib_Color_Range *gradient;
gradient = malloc(sizeof(Imlib_Color_Range));
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
Data_Get_Struct(val, Imlib_Color_Range, gradient);
imlib_context_set_color_range(*gradient);
imlib_context_pop();
return self;
}
static VALUE ctx_gradient(VALUE self) {
Imlib_Context *ctx;
VALUE r = Qnil;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
r = Data_Wrap_Struct(cGradient, 0, gradient_free, imlib_context_get_color_range());
imlib_context_pop();
return r;
}
static VALUE ctx_set_progress_granularity(VALUE self, VALUE val) {
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
imlib_context_set_progress_granularity(NUM2INT(val));
imlib_context_pop();
return self;
}
static VALUE ctx_progress_granularity(VALUE self) {
Imlib_Context *ctx;
VALUE r = Qnil;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
r = INT2FIX(imlib_context_get_progress_granularity());
imlib_context_pop();
return r;
}
static VALUE ctx_set_image(VALUE self, VALUE val) {
Imlib_Context *ctx;
ImStruct *im;
im = malloc(sizeof(ImStruct));
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
GET_AND_CHECK_IMAGE(val, im);
imlib_context_set_image(im->im);
imlib_context_pop();
return self;
}
static VALUE ctx_image(VALUE self) {
Imlib_Context *ctx;
ImStruct *im;
VALUE r = Qnil;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
im = malloc(sizeof(ImStruct));
im->im = imlib_context_get_image();
r = Data_Wrap_Struct(cImage, 0, im_struct_free, im);
imlib_context_pop();
return r;
}
static VALUE ctx_set_cliprect(VALUE self, VALUE val) {
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
imlib_context_set_cliprect(
NUM2INT(rb_ary_entry(val, 0)),
NUM2INT(rb_ary_entry(val, 1)),
NUM2INT(rb_ary_entry(val, 2)),
NUM2INT(rb_ary_entry(val, 3))
);
imlib_context_pop();
return self;
}
static VALUE ctx_cliprect(VALUE self) {
Imlib_Context *ctx;
int i, r[4];
VALUE ary;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
imlib_context_get_cliprect(&(r[0]), &(r[1]), &(r[2]), &(r[3]));
imlib_context_pop();
ary = rb_ary_new();
for (i = 0; i < 4; i++);
rb_ary_push(ary, NUM2INT(r[i]));
return ary;
}
static VALUE ctx_set_encoding(VALUE self, VALUE val) {
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
imlib_context_set_TTF_encoding(NUM2INT(val));
imlib_context_pop();
return self;
}
static VALUE ctx_encoding(VALUE self) {
Imlib_Context *ctx;
VALUE r = Qnil;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
r = INT2FIX(imlib_context_get_TTF_encoding());
imlib_context_pop();
return r;
}
#ifndef X_DISPLAY_MISSING
static VALUE ctx_set_display(VALUE self, VALUE display) {
Display *disp;
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
Data_Get_Struct(display, Display, disp);
imlib_context_push(*ctx);
imlib_context_set_display(disp);
imlib_context_pop();
return display;
}
static VALUE ctx_display(VALUE self) {
Imlib_Context *ctx;
VALUE disp;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
disp = Data_Wrap_Struct(cDisplay, NULL, XFree, imlib_context_get_display());
imlib_context_pop();
return disp;
}
static VALUE ctx_set_visual(VALUE self, VALUE visual) {
Visual *vis;
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
Data_Get_Struct(visual, Visual, vis);
imlib_context_push(*ctx);
imlib_context_set_visual(vis);
imlib_context_pop();
return visual;
}
static VALUE ctx_visual(VALUE self) {
Imlib_Context *ctx;
VALUE vis;
Data_Get_Struct(self, Imlib_Context, ctx);
imlib_context_push(*ctx);
vis = Data_Wrap_Struct(cVisual, NULL, XFree, imlib_context_get_visual());
imlib_context_pop();
return vis;
}
static VALUE ctx_set_colormap(VALUE self, VALUE colormap) {
Colormap *cmap;
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
Data_Get_Struct(colormap, Colormap, cmap);
imlib_context_push(*ctx);
imlib_context_set_colormap(*cmap);
imlib_context_pop();
return colormap;
}
static VALUE ctx_colormap(VALUE self) {
Imlib_Context *ctx;
Colormap *cmap;
VALUE colormap;
Data_Get_Struct(self, Imlib_Context, ctx);
cmap = malloc(sizeof(Colormap));
imlib_context_push(*ctx);
*cmap = imlib_context_get_colormap();
colormap = Data_Wrap_Struct(cColormap, 0, dont_free, cmap);
imlib_context_pop();
return colormap;
}
static VALUE ctx_set_drawable(VALUE self, VALUE drawable) {
Drawable *draw;
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
Data_Get_Struct(drawable, Drawable, draw);
imlib_context_push(*ctx);
imlib_context_set_drawable(*draw);
imlib_context_pop();
return drawable;
}
static VALUE ctx_drawable(VALUE self) {
Imlib_Context *ctx;
Drawable *draw;
VALUE drawable;
Data_Get_Struct(self, Imlib_Context, ctx);
draw = malloc(sizeof(Drawable));
imlib_context_push(*ctx);
*draw = imlib_context_get_drawable();
drawable = Data_Wrap_Struct(cDrawable, NULL, dont_free, draw);
imlib_context_pop();
return drawable;
}
static VALUE ctx_set_mask(VALUE self, VALUE mask_o) {
Pixmap *mask;
Imlib_Context *ctx;
Data_Get_Struct(self, Imlib_Context, ctx);
Data_Get_Struct(mask_o, Pixmap, mask);
imlib_context_push(*ctx);
imlib_context_set_mask(*mask);
imlib_context_pop();
return mask_o;
}
static VALUE ctx_mask(VALUE self) {
Imlib_Context *ctx;
Pixmap *pmap;
VALUE mask;
Data_Get_Struct(self, Imlib_Context, ctx);
pmap = malloc(sizeof(Pixmap));
imlib_context_push(*ctx);
*pmap = imlib_context_get_mask();
mask = Data_Wrap_Struct(cPixmap, NULL, pmap_free, pmap);
imlib_context_pop();
return mask;
}
#endif
void setup_color_constants(void) {
static struct {
char *name;
int r, g, b, a;
} color_constants[] = {
{ "CLEAR", 0, 0, 0, 0 },
{ "TRANSPARENT",0, 0, 0, 0 },
{ "TRANSLUCENT",0, 0, 0, 0 },
{ "SHADOW", 0, 0, 0, 64 },
{ "BLACK", 0, 0, 0, 255 },
{ "DARKGRAY", 64, 64, 64, 255 },
{ "DARKGREY", 64, 64, 64, 255 },
{ "GRAY", 128, 128, 128, 255 },
{ "GREY", 128, 128, 128, 255 },
{ "LIGHTGRAY", 192, 192, 192, 255 },
{ "LIGHTGREY", 192, 192, 192, 255 },
{ "WHITE", 255, 255, 255, 255 },
{ "RED", 255, 0, 0, 255 },
{ "GREEN", 0, 255, 0, 255 },
{ "BLUE", 0, 0, 255, 255 },
{ "YELLOW", 255, 255, 0, 255 },
{ "ORANGE", 255, 128, 0, 255 },
{ "BROWN", 128, 64, 0, 255 },
{ "MAGENTA", 255, 0, 128, 255 },
{ "VIOLET", 255, 0, 255, 255 },
{ "PURPLE", 128, 0, 255, 255 },
{ "INDEGO", 128, 0, 255, 255 },
{ "CYAN", 0, 255, 255, 255 },
{ "AQUA", 0, 128, 255, 255 },
{ "AZURE", 0, 128, 255, 255 },
{ "TEAL", 0, 255, 128, 255 },
{ "DARKRED", 128, 0, 0, 255 },
{ "DARKGREEN", 0, 128, 0, 255 },
{ "DARKBLUE", 0, 0, 128, 255 },
{ "DARKYELLOW", 128, 128, 0, 255 },
{ "DARKORANGE", 128, 64, 0, 255 },
{ "DARKBROWN", 64, 32, 0, 255 },
{ "DARKMAGENTA",128, 0, 64, 255 },
{ "DARKVIOLET", 128, 0, 128, 255 },
{ "DARKPURPLE", 64, 0, 128, 255 },
{ "DARKINDEGO", 64, 0, 128, 255 },
{ "DARKCYAN", 0, 128, 128, 255 },
{ "DARKAQUA", 0, 64, 128, 255 },
{ "DARKAZURE", 0, 64, 128, 255 },
{ "DARKTEAL", 0, 128, 64, 255 },
{ NULL, 0, 0, 0, 0 }
};
int i;
VALUE args[4];
for (i = 0; color_constants[i].name != NULL; i++) {
args[0] = INT2FIX(color_constants[i].r);
args[1] = INT2FIX(color_constants[i].g);
args[2] = INT2FIX(color_constants[i].b);
args[3] = INT2FIX(color_constants[i].a);
rb_define_const(mColor,
color_constants[i].name,
rgba_color_new(4, args, cRgbaColor));
}
}
void setup_error_constants(void) {
int i = 0;
cFileError = rb_define_class_under(mImlib2, "FileError", rb_eException);
mError = rb_define_module_under(mImlib2, "Error");
cDeletedError = rb_define_class_under(mError, "DeletedError", rb_eException);
for (i = 0; i <= IMLIB_LOAD_ERROR_UNKNOWN; i++)
imlib_errors[i].exception = rb_define_class_under(mError,
imlib_errors[i].name,
cFileError);
}
void Init_imlib2() {
mImlib2 = rb_define_module("Imlib2");
rb_define_const(mImlib2, "VERSION", rb_str_new2(VERSION));
#ifdef X_DISPLAY_MISSING
rb_define_const(mImlib2, "X11_SUPPORT", Qfalse);
#else
rb_define_const(mImlib2, "X11_SUPPORT", Qtrue);
#endif
cContext = rb_define_class_under(mImlib2, "Context", rb_cObject);
rb_define_singleton_method(cContext, "new", ctx_new, 0);
rb_define_method(cContext, "initialize", ctx_init, 0);
rb_define_method(cContext, "push", ctx_push, 0);
rb_define_singleton_method(cContext, "pop", ctx_pop, 0);
rb_define_singleton_method(cContext, "get", ctx_get, 0);
rb_define_singleton_method(cContext, "current", ctx_get, 0);
rb_define_method(cContext, "set_dither", ctx_set_dither, 1);
rb_define_method(cContext, "dither=", ctx_set_dither, 1);
rb_define_method(cContext, "get_dither", ctx_dither, 0);
rb_define_method(cContext, "dither", ctx_dither, 0);
rb_define_method(cContext, "set_dither_mask", ctx_set_dither_mask, 1);
rb_define_method(cContext, "dither_mask=", ctx_set_dither_mask, 1);
rb_define_method(cContext, "get_dither_mask", ctx_dither_mask, 0);
rb_define_method(cContext, "dither_mask", ctx_dither_mask, 0);
rb_define_method(cContext, "set_anti_alias", ctx_set_aa, 1);
rb_define_method(cContext, "anti_alias=", ctx_set_aa, 1);
rb_define_method(cContext, "aa=", ctx_set_aa, 1);
rb_define_method(cContext, "get_anti_alias", ctx_aa, 0);
rb_define_method(cContext, "anti_alias", ctx_aa, 0);
rb_define_method(cContext, "aa", ctx_aa, 0);
rb_define_method(cContext, "set_blend", ctx_set_blend, 1);
rb_define_method(cContext, "blend=", ctx_set_blend, 1);
rb_define_method(cContext, "get_blend", ctx_blend, 0);
rb_define_method(cContext, "blend", ctx_blend, 0);
rb_define_method(cContext, "set_color_modifier", ctx_set_cmod, 1);
rb_define_method(cContext, "color_modifier=", ctx_set_cmod, 1);
rb_define_method(cContext, "cmod=", ctx_set_cmod, 1);
rb_define_method(cContext, "get_color_modifier", ctx_cmod, 0);
rb_define_method(cContext, "color_modifier", ctx_cmod, 0);
rb_define_method(cContext, "cmod", ctx_cmod, 0);
rb_define_method(cContext, "set_operation", ctx_set_op, 1);
rb_define_method(cContext, "operation=", ctx_set_op, 1);
rb_define_method(cContext, "op=", ctx_set_op, 1);
rb_define_method(cContext, "get_operation", ctx_op, 0);
rb_define_method(cContext, "operation", ctx_op, 0);
rb_define_method(cContext, "op", ctx_op, 0);
rb_define_method(cContext, "set_font", ctx_set_font, 1);
rb_define_method(cContext, "font=", ctx_set_font, 1);
rb_define_method(cContext, "get_font", ctx_font, 0);
rb_define_method(cContext, "font", ctx_font, 0);
rb_define_method(cContext, "set_direction", ctx_set_dir, 1);
rb_define_method(cContext, "direction=", ctx_set_dir, 1);
rb_define_method(cContext, "dir=", ctx_set_dir, 1);
rb_define_method(cContext, "get_direction", ctx_dir, 0);
rb_define_method(cContext, "direction", ctx_dir, 0);
rb_define_method(cContext, "dir", ctx_dir, 0);
rb_define_method(cContext, "set_angle", ctx_set_angle, 1);
rb_define_method(cContext, "angle=", ctx_set_angle, 1);
rb_define_method(cContext, "get_angle", ctx_angle, 0);
rb_define_method(cContext, "angle", ctx_angle, 0);
rb_define_method(cContext, "set_color", ctx_set_color, 1);
rb_define_method(cContext, "color=", ctx_set_color, 1);
rb_define_method(cContext, "get_color", ctx_color, 0);
rb_define_method(cContext, "color", ctx_color, 0);
rb_define_method(cContext, "set_gradient", ctx_set_gradient, 1);
rb_define_method(cContext, "gradient=", ctx_set_gradient, 1);
rb_define_method(cContext, "get_gradient", ctx_gradient, 0);
rb_define_method(cContext, "gradient", ctx_gradient, 0);
rb_define_method(cContext, "set_progress_granularity", ctx_set_progress_granularity, 1);
rb_define_method(cContext, "progress_granularity=", ctx_set_progress_granularity, 1);
rb_define_method(cContext, "get_progress_granularity", ctx_progress_granularity, 0);
rb_define_method(cContext, "progress_granularity", ctx_progress_granularity, 0);
rb_define_method(cContext, "set_image", ctx_set_image, 1);
rb_define_method(cContext, "image=", ctx_set_image, 1);
rb_define_method(cContext, "get_image", ctx_image, 0);
rb_define_method(cContext, "image", ctx_image, 0);
rb_define_method(cContext, "set_cliprect", ctx_set_cliprect, 1);
rb_define_method(cContext, "cliprect=", ctx_set_cliprect, 1);
rb_define_method(cContext, "get_cliprect", ctx_cliprect, 0);
rb_define_method(cContext, "cliprect", ctx_cliprect, 0);
rb_define_method(cContext, "set_ttf_encoding", ctx_set_encoding, 1);
rb_define_method(cContext, "set_encoding", ctx_set_encoding, 1);
rb_define_method(cContext, "encoding=", ctx_set_encoding, 1);
rb_define_method(cContext, "get_encoding", ctx_encoding, 0);
rb_define_method(cContext, "get_ttf_encoding", ctx_encoding, 0);
rb_define_method(cContext, "encoding", ctx_encoding, 0);
#ifndef X_DISPLAY_MISSING
rb_define_method(cContext, "set_display", ctx_set_display, 1);
rb_define_method(cContext, "display=", ctx_set_display, 1);
rb_define_method(cContext, "get_display", ctx_display, 0);
rb_define_method(cContext, "display", ctx_display, 0);
rb_define_method(cContext, "set_visual", ctx_set_visual, 1);
rb_define_method(cContext, "visual=", ctx_set_visual, 1);
rb_define_method(cContext, "get_visual", ctx_visual, 0);
rb_define_method(cContext, "visual", ctx_visual, 0);
rb_define_method(cContext, "set_colormap", ctx_set_cmap, 1);
rb_define_method(cContext, "colormap=", ctx_set_cmap, 1);
rb_define_method(cContext, "set_cmap", ctx_set_cmap, 1);
rb_define_method(cContext, "cmap=", ctx_set_cmap, 1);
rb_define_method(cContext, "get_colormap", ctx_cmap, 0);
rb_define_method(cContext, "colormap", ctx_cmap, 0);
rb_define_method(cContext, "get_cmap", ctx_cmap, 0);
rb_define_method(cContext, "cmap", ctx_cmap, 0);
rb_define_method(cContext, "set_drawable", ctx_set_drawable, 1);
rb_define_method(cContext, "drawable=", ctx_set_drawable, 1);
rb_define_method(cContext, "get_drawable", ctx_drawable, 0);
rb_define_method(cContext, "drawable", ctx_drawable, 0);
rb_define_method(cContext, "set_mask", ctx_set_mask, 1);
rb_define_method(cContext, "mask=", ctx_set_mask, 1);
rb_define_method(cContext, "get_mask", ctx_mask, 0);
rb_define_method(cContext, "mask", ctx_mask, 0);
rb_define_method(cContext, "get_visual", ctx_visual, -1);
rb_define_method(cContext, "visual", ctx_visual, -1);
rb_define_method(cContext, "get_best_visual", ctx_visual, -1);
rb_define_method(cContext, "best_visual", ctx_visual, -1);
#endif
setup_error_constants();
mTextDir = rb_define_module_under(mImlib2, "Dir");
rb_define_const(mTextDir, "RIGHT", INT2FIX(IMLIB_TEXT_TO_RIGHT));
rb_define_const(mTextDir, "LEFT", INT2FIX(IMLIB_TEXT_TO_LEFT));
rb_define_const(mTextDir, "DOWN", INT2FIX(IMLIB_TEXT_TO_DOWN));
rb_define_const(mTextDir, "UP", INT2FIX(IMLIB_TEXT_TO_UP));
rb_define_const(mTextDir, "ANGLE", INT2FIX(IMLIB_TEXT_TO_ANGLE));
mTextDir = rb_define_module_under(mImlib2, "Direction");
rb_define_const(mTextDir, "RIGHT", INT2FIX(IMLIB_TEXT_TO_RIGHT));
rb_define_const(mTextDir, "LEFT", INT2FIX(IMLIB_TEXT_TO_LEFT));
rb_define_const(mTextDir, "DOWN", INT2FIX(IMLIB_TEXT_TO_DOWN));
rb_define_const(mTextDir, "UP", INT2FIX(IMLIB_TEXT_TO_UP));
rb_define_const(mTextDir, "ANGLE", INT2FIX(IMLIB_TEXT_TO_ANGLE));
mOp = rb_define_module_under(mImlib2, "Op");
rb_define_const(mOp, "COPY", INT2FIX(IMLIB_OP_COPY));
rb_define_const(mOp, "ADD", INT2FIX(IMLIB_OP_ADD));
rb_define_const(mOp, "SUBTRACT", INT2FIX(IMLIB_OP_SUBTRACT));
rb_define_const(mOp, "RESHADE", INT2FIX(IMLIB_OP_RESHADE));
mOperation = rb_define_module_under(mImlib2, "Operation");
rb_define_const(mOperation, "COPY", INT2FIX(IMLIB_OP_COPY));
rb_define_const(mOperation, "ADD", INT2FIX(IMLIB_OP_ADD));
rb_define_const(mOperation, "SUBTRACT", INT2FIX(IMLIB_OP_SUBTRACT));
rb_define_const(mOperation, "RESHADE", INT2FIX(IMLIB_OP_RESHADE));
mEncoding = rb_define_module_under(mImlib2, "Encoding");
rb_define_const(mEncoding, "ISO_8859_1", INT2FIX(IMLIB_TTF_ENCODING_ISO_8859_1));
rb_define_const(mEncoding, "ISO_8859_2", INT2FIX(IMLIB_TTF_ENCODING_ISO_8859_2));
rb_define_const(mEncoding, "ISO_8859_3", INT2FIX(IMLIB_TTF_ENCODING_ISO_8859_3));
rb_define_const(mEncoding, "ISO_8859_4", INT2FIX(IMLIB_TTF_ENCODING_ISO_8859_4));
rb_define_const(mEncoding, "ISO_8859_5", INT2FIX(IMLIB_TTF_ENCODING_ISO_8859_5));
cBorder = rb_define_class_under(mImlib2, "Border", rb_cObject);
rb_define_singleton_method(cBorder, "new", border_new, -1);
rb_define_method(cBorder, "initialize", border_init, -1);
rb_define_method(cBorder, "left", border_left, 0);
rb_define_method(cBorder, "left=", border_set_left, 1);
rb_define_alias(cBorder, "l", "left");
rb_define_alias(cBorder, "l=", "left=");
rb_define_method(cBorder, "right", border_right, 0);
rb_define_method(cBorder, "right=", border_set_right, 1);
rb_define_alias(cBorder, "r", "right");
rb_define_alias(cBorder, "r=", "right=");
rb_define_method(cBorder, "top", border_top, 0);
rb_define_method(cBorder, "top=", border_set_top, 1);
rb_define_alias(cBorder, "t", "top");
rb_define_alias(cBorder, "t=", "top=");
rb_define_method(cBorder, "bottom", border_bottom, 0);
rb_define_method(cBorder, "bottom=", border_set_bottom, 1);
rb_define_alias(cBorder, "b", "bottom");
rb_define_alias(cBorder, "b=", "bottom=");
mCache = rb_define_module_under(mImlib2, "Cache");
rb_define_singleton_method(mCache, "image", cache_image, 0);
rb_define_singleton_method(mCache, "image=", cache_set_image, 1);
rb_define_singleton_method(mCache, "image_cache", cache_image, 0);
rb_define_singleton_method(mCache, "image_cache=", cache_set_image, 1);
rb_define_singleton_method(mCache, "get_image_cache", cache_image, 0);
rb_define_singleton_method(mCache, "set_image_cache", cache_set_image, 1);
rb_define_singleton_method(mCache, "font", cache_font, 0);
rb_define_singleton_method(mCache, "font=", cache_set_font, 1);
rb_define_singleton_method(mCache, "font_cache", cache_font, 0);
rb_define_singleton_method(mCache, "font_cache=", cache_set_font, 1);
rb_define_singleton_method(mCache, "get_font_cache", cache_font, 0);
rb_define_singleton_method(mCache, "set_font_cache", cache_set_font, 1);
rb_define_singleton_method(mCache, "flush_font_cache", cache_flush_font, 0);
mColor = rb_define_module_under(mImlib2, "Color");
cRgbaColor = rb_define_class_under(mColor, "RgbaColor", rb_cObject);
rb_define_singleton_method(cRgbaColor, "new", rgba_color_new, -1);
rb_define_method(cRgbaColor, "initialize", rgba_color_init, -1);
rb_define_method(cRgbaColor, "r", rgba_color_red, 0);
rb_define_method(cRgbaColor, "r=", rgba_color_set_red, 1);
rb_define_method(cRgbaColor, "red", rgba_color_red, 0);
rb_define_method(cRgbaColor, "red=", rgba_color_set_red, 1);
rb_define_method(cRgbaColor, "g", rgba_color_green, 0);
rb_define_method(cRgbaColor, "g=", rgba_color_set_green, 1);
rb_define_method(cRgbaColor, "green", rgba_color_green, 0);
rb_define_method(cRgbaColor, "green=", rgba_color_set_green, 1);
rb_define_method(cRgbaColor, "b", rgba_color_blue, 0);
rb_define_method(cRgbaColor, "b=", rgba_color_set_blue, 1);
rb_define_method(cRgbaColor, "blue", rgba_color_blue, 0);
rb_define_method(cRgbaColor, "blue=", rgba_color_set_blue, 1);
rb_define_method(cRgbaColor, "a", rgba_color_alpha, 0);
rb_define_method(cRgbaColor, "a=", rgba_color_set_alpha, 1);
rb_define_method(cRgbaColor, "alpha", rgba_color_alpha, 0);
rb_define_method(cRgbaColor, "alpha=", rgba_color_set_alpha, 1);
cHsvaColor = rb_define_class_under(mColor, "HsvaColor", rb_cObject);
rb_define_singleton_method(cHsvaColor, "new", hsva_color_new, -1);
rb_define_method(cHsvaColor, "initialize", hsva_color_init, -1);
rb_define_method(cHsvaColor, "h", hsva_color_hue, 0);
rb_define_method(cHsvaColor, "h=", hsva_color_set_hue, 1);
rb_define_method(cHsvaColor, "hue", hsva_color_hue, 0);
rb_define_method(cHsvaColor, "hue=", hsva_color_set_hue, 1);
rb_define_method(cHsvaColor, "s", hsva_color_saturation, 0);
rb_define_method(cHsvaColor, "s=", hsva_color_set_saturation, 1);
rb_define_method(cHsvaColor, "saturation", hsva_color_saturation, 0);
rb_define_method(cHsvaColor, "saturation=", hsva_color_set_saturation, 1);
rb_define_method(cHsvaColor, "v", hsva_color_value, 0);
rb_define_method(cHsvaColor, "v=", hsva_color_set_value, 1);
rb_define_method(cHsvaColor, "value", hsva_color_value, 0);
rb_define_method(cHsvaColor, "value=", hsva_color_set_value, 1);
rb_define_method(cHsvaColor, "a", hsva_color_alpha, 0);
rb_define_method(cHsvaColor, "a=", hsva_color_set_alpha, 1);
rb_define_method(cHsvaColor, "alpha", hsva_color_alpha, 0);
rb_define_method(cHsvaColor, "alpha=", hsva_color_set_alpha, 1);
cHlsaColor = rb_define_class_under(mColor, "HlsaColor", rb_cObject);
rb_define_singleton_method(cHlsaColor, "new", hlsa_color_new, -1);
rb_define_method(cHlsaColor, "initialize", hlsa_color_init, -1);
rb_define_method(cHlsaColor, "h", hlsa_color_hue, 0);
rb_define_method(cHlsaColor, "h=", hlsa_color_set_hue, 1);
rb_define_method(cHlsaColor, "hue", hlsa_color_hue, 0);
rb_define_method(cHlsaColor, "hue=", hlsa_color_set_hue, 1);
rb_define_method(cHlsaColor, "l", hlsa_color_lightness, 0);
rb_define_method(cHlsaColor, "l=", hlsa_color_set_lightness, 1);
rb_define_method(cHlsaColor, "lightness", hlsa_color_lightness, 0);
rb_define_method(cHlsaColor, "lightness=", hlsa_color_set_lightness, 1);
rb_define_method(cHlsaColor, "s", hlsa_color_saturation, 0);
rb_define_method(cHlsaColor, "s=", hlsa_color_set_saturation, 1);
rb_define_method(cHlsaColor, "saturation", hlsa_color_saturation, 0);
rb_define_method(cHlsaColor, "saturation=", hlsa_color_set_saturation, 1);
rb_define_method(cHlsaColor, "a", hlsa_color_alpha, 0);
rb_define_method(cHlsaColor, "a=", hlsa_color_set_alpha, 1);
rb_define_method(cHlsaColor, "alpha", hlsa_color_alpha, 0);
rb_define_method(cHlsaColor, "alpha=", hlsa_color_set_alpha, 1);
cCmyaColor = rb_define_class_under(mColor, "CmyaColor", rb_cObject);
rb_define_singleton_method(cCmyaColor, "new", cmya_color_new, -1);
rb_define_method(cCmyaColor, "initialize", cmya_color_init, -1);
rb_define_method(cCmyaColor, "c", cmya_color_cyan, 0);
rb_define_method(cCmyaColor, "c=", cmya_color_set_cyan, 1);
rb_define_method(cCmyaColor, "cyan", cmya_color_cyan, 0);
rb_define_method(cCmyaColor, "cyan=", cmya_color_set_cyan, 1);
rb_define_method(cCmyaColor, "m", cmya_color_magenta, 0);
rb_define_method(cCmyaColor, "m=", cmya_color_set_magenta, 1);
rb_define_method(cCmyaColor, "magenta", cmya_color_magenta, 0);
rb_define_method(cCmyaColor, "magenta=", cmya_color_set_magenta, 1);
rb_define_method(cCmyaColor, "y", cmya_color_yellow, 0);
rb_define_method(cCmyaColor, "y=", cmya_color_set_yellow, 1);
rb_define_method(cCmyaColor, "yellow", cmya_color_yellow, 0);
rb_define_method(cCmyaColor, "yellow=", cmya_color_set_yellow, 1);
rb_define_method(cCmyaColor, "a", cmya_color_alpha, 0);
rb_define_method(cCmyaColor, "a=", cmya_color_set_alpha, 1);
rb_define_method(cCmyaColor, "alpha", cmya_color_alpha, 0);
rb_define_method(cCmyaColor, "alpha=", cmya_color_set_alpha, 1);
setup_color_constants();
cColorMod = rb_define_class_under(mImlib2, "ColorModifier", rb_cObject);
rb_define_singleton_method(cColorMod, "new", cmod_new, -1);
rb_define_method(cColorMod, "initialize", cmod_init, -1);
rb_define_method(cColorMod, "gamma=", cmod_gamma, 1);
rb_define_method(cColorMod, "brightness=", cmod_brightness, 1);
rb_define_method(cColorMod, "contrast=", cmod_contrast, 1);
rb_define_method(cColorMod, "reset", cmod_reset, 0);
cGradient = rb_define_class_under(mImlib2, "Gradient", rb_cObject);
rb_define_singleton_method(cGradient, "new", gradient_new, -1);
rb_define_method(cGradient, "initialize", gradient_init, -1);
rb_define_method(cGradient, "add_color", gradient_add_color, 2);
cImage = rb_define_class_under(mImlib2, "Image", rb_cObject);
rb_define_singleton_method(cImage, "new", image_new, 2);
rb_define_method(cImage, "initialize", image_initialize, 0);
rb_define_singleton_method(cImage, "draw_pixel_workaround?", image_dp_workaround, 0);
rb_define_singleton_method(cImage, "bypass_draw_pixel?", image_dp_workaround, 0);
rb_define_singleton_method(cImage, "draw_pixel_workaround=", image_dp_workaround, 1);
rb_define_singleton_method(cImage, "bypass_draw_pixel=", image_dp_workaround, 1);
rb_define_singleton_method(cImage, "create", image_new, 2);
rb_define_singleton_method(cImage, "create_using_data", image_create_using_data, 3);
rb_define_singleton_method(cImage, "create_using_copied_data", image_create_using_copied_data, 3);
rb_define_singleton_method(cImage, "load", image_load, 1);
rb_define_singleton_method(cImage, "load_image", image_load_image, 1);
rb_define_singleton_method(cImage, "load_immediately", image_load_immediately, 1);
rb_define_singleton_method(cImage, "load_without_cache", image_load_without_cache, 1);
rb_define_singleton_method(cImage, "load_immediately_without_cache", image_load_immediately_without_cache, 1);
rb_define_singleton_method(cImage, "load_with_error_return", image_load_with_error_return, 1);
rb_define_method(cImage, "save", image_save, 1);
rb_define_method(cImage, "save_image", image_save_image, 1);
rb_define_method(cImage, "save_with_error_return", image_save_with_error_return, 1);
rb_define_method(cImage, "delete!", image_delete, -1);
rb_define_method(cImage, "width", image_width, 0);
rb_define_method(cImage, "w", image_width, 0);
rb_define_method(cImage, "height", image_height, 0);
rb_define_method(cImage, "h", image_height, 0);
rb_define_method(cImage, "filename", image_filename, 0);
rb_define_method(cImage, "data", image_data, 0);
rb_define_method(cImage, "data_for_reading_only", image_data_ro, 0);
rb_define_method(cImage, "data!", image_data_ro, 0);
rb_define_method(cImage, "data=", image_put_data, 1);
rb_define_method(cImage, "put_back_data", image_put_data, 1);
rb_define_method(cImage, "has_alpha", image_has_alpha, 0);
rb_define_method(cImage, "has_alpha?", image_has_alpha, 0);
rb_define_method(cImage, "has_alpha=", image_set_has_alpha, 1);
rb_define_method(cImage, "set_has_alpha", image_set_has_alpha, 1);
rb_define_method(cImage, "changes_on_disk", image_changes_on_disk, 0);
rb_define_method(cImage, "set_changes_on_disk", image_changes_on_disk, 0);
rb_define_method(cImage, "border", image_get_border, 0);
rb_define_method(cImage, "get_border", image_get_border, 0);
rb_define_method(cImage, "border=", image_set_border, 1);
rb_define_method(cImage, "set_border", image_set_border, 1);
rb_define_method(cImage, "format", image_get_format, 0);
rb_define_method(cImage, "get_format", image_get_format, 0);
rb_define_method(cImage, "format=", image_set_format, 1);
rb_define_method(cImage, "set_format", image_set_format, 1);
rb_define_method(cImage, "irrelevant_format=", image_irrelevant_format, 1);
rb_define_method(cImage, "set_irrelevant_format", image_irrelevant_format, 1);
rb_define_method(cImage, "irrelevant_border=", image_irrelevant_border, 1);
rb_define_method(cImage, "set_irrelevant_border", image_irrelevant_border, 1);
rb_define_method(cImage, "irrelevant_alpha=", image_irrelevant_alpha, 1);
rb_define_method(cImage, "set_irrelevant_alpha", image_irrelevant_alpha, 1);
rb_define_method(cImage, "pixel", image_query_pixel, 2);
rb_define_method(cImage, "pixel_rgba", image_query_pixel, 2);
rb_define_method(cImage, "query_pixel", image_query_pixel, 2);
rb_define_method(cImage, "query_pixel_rgba", image_query_pixel, 2);
rb_define_method(cImage, "pixel_hsva", image_query_pixel_hsva, 2);
rb_define_method(cImage, "query_pixel_hsva", image_query_pixel_hsva, 2);
rb_define_method(cImage, "pixel_hlsa", image_query_pixel_hlsa, 2);
rb_define_method(cImage, "query_pixel_hlsa", image_query_pixel_hlsa, 2);
rb_define_method(cImage, "pixel_cmya", image_query_pixel_cmya, 2);
rb_define_method(cImage, "query_pixel_cmya", image_query_pixel_cmya, 2);
rb_define_method(cImage, "crop", image_crop, -1);
rb_define_method(cImage, "create_cropped", image_crop, -1);
rb_define_method(cImage, "crop!", image_crop_inline, -1);
rb_define_method(cImage, "create_cropped!", image_crop_inline, -1);
rb_define_method(cImage, "crop_scaled", image_crop_scaled, -1);
rb_define_method(cImage, "create_cropped_scaled", image_crop_scaled, -1);
rb_define_method(cImage, "crop_scaled!", image_crop_scaled_inline, -1);
rb_define_method(cImage, "create_cropped_scaled!", image_crop_scaled_inline, -1);
rb_define_method(cImage, "flip_horizontal", image_flip_horizontal, 0);
rb_define_method(cImage, "flip_horizontal!", image_flip_horizontal_inline, 0);
rb_define_method(cImage, "flip_vertical", image_flip_vertical, 0);
rb_define_method(cImage, "flip_vertical!", image_flip_vertical_inline, 0);
rb_define_method(cImage, "flip_diagonal", image_flip_diagonal, 0);
rb_define_method(cImage, "flip_diagonal!", image_flip_diagonal_inline, 0);
rb_define_method(cImage, "orientate", image_orientate, 1);
rb_define_method(cImage, "orientate!", image_orientate_inline, 1);
rb_define_method(cImage, "blur", image_blur, 1);
rb_define_method(cImage, "blur!", image_blur_inline, 1);
rb_define_method(cImage, "sharpen", image_sharpen, 1);
rb_define_method(cImage, "sharpen!", image_sharpen_inline, 1);
rb_define_method(cImage, "tile_horizontal", image_tile_horizontal, 0);
rb_define_method(cImage, "tile_horizontal!", image_tile_horizontal_inline, 0);
rb_define_method(cImage, "tile_vertical", image_tile_vertical, 0);
rb_define_method(cImage, "tile_vertical!", image_tile_vertical_inline, 0);
rb_define_method(cImage, "tile", image_tile, 0);
rb_define_method(cImage, "tile!", image_tile_inline, 0);
rb_define_method(cImage, "draw_pixel", image_draw_pixel, -1);
rb_define_method(cImage, "draw_line", image_draw_line, -1);
rb_define_method(cImage, "draw_rect", image_draw_rect, -1);
rb_define_method(cImage, "draw_rectangle", image_draw_rect, -1);
rb_define_method(cImage, "fill_rect", image_fill_rect, -1);
rb_define_method(cImage, "fill_rectangle", image_fill_rect, -1);
rb_define_method(cImage, "copy_alpha", image_copy_alpha, -1);
rb_define_method(cImage, "copy_alpha_rect", image_copy_alpha_rect, -1);
rb_define_method(cImage, "scroll_rect", image_scroll_rect, -1);
rb_define_method(cImage, "copy_rect", image_copy_rect, -1);
rb_define_method(cImage, "draw_ellipse", image_draw_ellipse, -1);
rb_define_method(cImage, "draw_oval", image_draw_ellipse, -1);
rb_define_method(cImage, "fill_ellipse", image_fill_ellipse, -1);
rb_define_method(cImage, "fill_oval", image_fill_ellipse, -1);
rb_define_method(cImage, "draw_text", image_draw_text, -1);
rb_define_method(cImage, "gradient", image_fill_gradient, -1);
rb_define_method(cImage, "fill_gradient", image_fill_gradient, -1);
rb_define_method(cImage, "color_range", image_fill_gradient, -1);
rb_define_method(cImage, "fill_color_range", image_fill_gradient, -1);
rb_define_method(cImage, "draw_poly", image_draw_poly, -1);
rb_define_method(cImage, "draw_polygon", image_draw_poly, -1);
rb_define_method(cImage, "fill_poly", image_fill_poly, -1);
rb_define_method(cImage, "fill_polygon", image_fill_poly, -1);
rb_define_method(cImage, "blend!", image_blend_image_inline, -1);
rb_define_method(cImage, "blend_image!", image_blend_image_inline, -1);
rb_define_method(cImage, "blend", image_blend_image, -1);
rb_define_method(cImage, "blend_image", image_blend_image, -1);
rb_define_method(cImage, "rotate", image_rotate, 1);
rb_define_method(cImage, "rotate!", image_rotate_inline, 1);
rb_define_method(cImage, "clone", image_clone, 0);
rb_define_method(cImage, "dup", image_clone, 0);
rb_define_method(cImage, "clear", image_clear, 0);
rb_define_method(cImage, "clear_color", image_clear_color, 1);
rb_define_method(cImage, "clear_color!", image_clear_color_inline, 1);
rb_define_method(cImage, "filter", image_filter, 1);
rb_define_method(cImage, "apply_filter", image_filter, 1);
rb_define_method(cImage, "static_filter", image_static_filter, 1);
rb_define_method(cImage, "script_filter", image_script_filter, 1);
rb_define_method(cImage, "apply_color_modifier", image_apply_cmod, 1);
rb_define_method(cImage, "apply_cmod", image_apply_cmod, 1);
rb_define_method(cImage, "apply", image_apply_cmod, 1);
rb_define_method(cImage, "attach_value", image_attach_val, 2);
rb_define_method(cImage, "get_attached_value", image_get_attach_val, 1);
rb_define_method(cImage, "remove_attached_value", image_rm_attach_val, 1);
rb_define_method(cImage, "[]", image_get_attach_val, 1);
rb_define_method(cImage, "[]=", image_attach_val, 2);
#ifndef X_DISPLAY_MISSING
rb_define_method(cImage, "render_pixmap", image_render_pmap, -1);
rb_define_method(cImage, "pixmap", image_render_pmap, -1);
rb_define_method(cImage, "render_on_drawable", image_render_on_drawable, -1);
rb_define_singleton_method(cImage, "create_from_drawable", image_create_from_drawable, -1);
rb_define_singleton_method(cImage, "create_from_ximage", image_create_from_ximage, -1);
rb_define_method(cImage, "copy_drawable", image_copy_drawable, -1);
rb_define_method(cImage, "blend_drawable", image_blend_drawable, -1);
rb_define_method(cImage, "render_on_drawable_skewed", image_render_drawable_skewed, -1);
rb_define_method(cImage, "render_on_drawable_at_angle", image_render_drawable_angle, -1);
#endif
cFilter = rb_define_class_under(mImlib2, "Filter", rb_cObject);
rb_define_singleton_method(cFilter, "new", filter_new, 1);
rb_define_method(cFilter, "initialize", filter_init, 1);
rb_define_method(cFilter, "set", filter_set, -1);
rb_define_method(cFilter, "red", filter_set_red, -1);
rb_define_method(cFilter, "set_red", filter_set_red, -1);
rb_define_method(cFilter, "green", filter_set_green, -1);
rb_define_method(cFilter, "set_green", filter_set_green, -1);
rb_define_method(cFilter, "blue", filter_set_blue, -1);
rb_define_method(cFilter, "set_blue", filter_set_blue, -1);
rb_define_method(cFilter, "alpha", filter_set_alpha, -1);
rb_define_method(cFilter, "set_alpha", filter_set_alpha, -1);
rb_define_method(cFilter, "constants", filter_constants, 1);
rb_define_method(cFilter, "divisors", filter_divisors, 1);
cFont = rb_define_class_under(mImlib2, "Font", rb_cObject);
rb_define_singleton_method(cFont, "new", font_new, 1);
rb_define_singleton_method(cFont, "load", font_new, 1);
rb_define_method(cFont, "initialize", font_init, 0);
rb_define_method(cFont, "size", font_text_size, 1);
rb_define_method(cFont, "text_size", font_text_size, 1);
rb_define_method(cFont, "get_text_size", font_text_size, 1);
rb_define_method(cFont, "advance", font_text_advance, 1);
rb_define_method(cFont, "text_advance", font_text_advance, 1);
rb_define_method(cFont, "get_text_advance", font_text_advance, 1);
rb_define_method(cFont, "inset", font_text_inset, 1);
rb_define_method(cFont, "text_inset", font_text_inset, 1);
rb_define_method(cFont, "get_text_inset", font_text_inset, 1);
rb_define_method(cFont, "index", font_text_index, -1);
rb_define_method(cFont, "text_index", font_text_index, -1);
rb_define_method(cFont, "text_index_and_location", font_text_index, -1);
rb_define_method(cFont, "get_text_index_and_location", font_text_index, -1);
rb_define_method(cFont, "location", font_text_location, 2);
rb_define_method(cFont, "text_location", font_text_location, 2);
rb_define_method(cFont, "text_location_at_index", font_text_location, 2);
rb_define_method(cFont, "get_text_location_at_index", font_text_location, 2);
rb_define_method(cFont, "ascent", font_ascent, 0);
rb_define_method(cFont, "get_ascent", font_ascent, 0);
rb_define_method(cFont, "descent", font_descent, 0);
rb_define_method(cFont, "get_descent", font_descent, 0);
rb_define_method(cFont, "maximum_ascent", font_maximum_ascent, 0);
rb_define_method(cFont, "get_maximum_ascent", font_maximum_ascent, 0);
rb_define_method(cFont, "maximum_descent", font_maximum_descent, 0);
rb_define_method(cFont, "get_maximum_descent", font_maximum_descent, 0);
rb_define_singleton_method(cFont, "list", font_list_fonts, 0);
rb_define_singleton_method(cFont, "fonts", font_list_fonts, 0);
rb_define_singleton_method(cFont, "list_fonts", font_list_fonts, 0);
rb_define_singleton_method(cFont, "add_path", font_add_path, 1);
rb_define_singleton_method(cFont, "remove_path", font_remove_path, 1);
rb_define_singleton_method(cFont, "paths", font_list_paths, 0);
rb_define_singleton_method(cFont, "list_paths", font_list_paths, 0);
cPolygon = rb_define_class_under(mImlib2, "Polygon", rb_cObject);
rb_define_singleton_method(cPolygon, "new", poly_new, -1);
rb_define_method(cPolygon, "initialize", poly_init, -1);
rb_define_method(cPolygon, "add_point", poly_add_point, -1);
rb_define_method(cPolygon, "bounds", poly_bounds, 0);
rb_define_method(cPolygon, "get_bounds", poly_bounds, 0);
rb_define_method(cPolygon, "contains?", poly_contains, -1);
rb_define_method(cPolygon, "contains_point?", poly_contains, -1);
#ifndef X_DISPLAY_MISSING
mX11 = rb_define_module_under(mImlib2, "X11", rb_cObject);
cDisplay = rb_define_class_under(mX11, "Display", rb_cObject);
rb_define_singleton_method(cDisplay, "new", disp_new, 0);
rb_define_method(cDisplay, "initialize", disp_init, 0);
cVisual = rb_define_class_under(mX11, "Visual", rb_cObject);
rb_define_singleton_method(cVisual, "new", vis_new, 2);
rb_define_method(cVisual, "initialize", vis_init, 2);
cColormap = rb_define_class_under(mX11, "Colormap", rb_cObject);
rb_define_singleton_method(cColormap, "new", cmap_new, 0);
rb_define_method(cColormap, "initialize", cmap_init, 0);
cDrawable = rb_define_class_under(mX11, "Drawable", rb_cObject);
rb_define_singleton_method(cDrawable, "new", drawable_new, 0);
rb_define_method(cDrawable, "initialize", drawable_init, 0);
cPixmap = rb_define_class_under(mX11, "Pixmap", rb_cObject);
rb_define_singleton_method(cPixmap, "new", pmap_new, 0);
rb_define_method(cPixmap, "initialize", pmap_init, 0);
#endif
}