1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
|
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
/************************************************
rbgdk-pixbuf.c -
$Author: ggc $
$Date: 2005/09/28 20:37:27 $
Copyright (C) 2002-2004 Masao Mutoh
Copyright (C) 2000 Yasushi Shoji
************************************************/
#include "rbgdk-pixbuf.h"
#ifdef HAVE_GDK_PIXBUF_GDK_PIXBUF_IO_H
#define GDK_PIXBUF_ENABLE_BACKEND
#include <gdk-pixbuf/gdk-pixbuf-io.h>
#endif
#define _SELF(s) GDK_PIXBUF(RVAL2GOBJ(s))
#define NOMEM_ERROR(error) g_set_error(error,\
GDK_PIXBUF_ERROR,\
GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,\
"Insufficient memory to load image file");
static ID id_pixdata;
/****************************************************/
/* The GdkPixbuf Structure */
static VALUE
get_colorspace(self)
VALUE self;
{
return GENUM2RVAL(gdk_pixbuf_get_colorspace(_SELF(self)), GDK_TYPE_COLORSPACE);
}
static VALUE
get_n_channels(self)
VALUE self;
{
return INT2FIX(gdk_pixbuf_get_n_channels(_SELF(self)));
}
static VALUE
get_has_alpha(self)
VALUE self;
{
return CBOOL2RVAL(gdk_pixbuf_get_has_alpha(_SELF(self)));
}
static VALUE
get_bits_per_sample(self)
VALUE self;
{
return INT2FIX(gdk_pixbuf_get_bits_per_sample(_SELF(self)));
}
static VALUE
get_pixels(self)
VALUE self;
{
GdkPixbuf *pixbuf = _SELF(self);
int size, height, width, rowstride, n_channels, bits_per_sample;
height = gdk_pixbuf_get_height(pixbuf);
width = gdk_pixbuf_get_width(pixbuf);
rowstride = gdk_pixbuf_get_rowstride(pixbuf);
n_channels = gdk_pixbuf_get_n_channels(pixbuf);
bits_per_sample = gdk_pixbuf_get_bits_per_sample(pixbuf);
size = ((height - 1) * rowstride +
width * ((n_channels * bits_per_sample + 7) / 8));
return rb_str_new((const char*)gdk_pixbuf_get_pixels(pixbuf), size);
}
static VALUE
get_width(self)
VALUE self;
{
return INT2FIX(gdk_pixbuf_get_width(_SELF(self)));
}
static VALUE
get_height(self)
VALUE self;
{
return INT2FIX(gdk_pixbuf_get_height(_SELF(self)));
}
static VALUE
get_rowstride(self)
VALUE self;
{
return INT2FIX(gdk_pixbuf_get_rowstride(_SELF(self)));
}
static VALUE
get_option(self, key)
VALUE self, key;
{
const gchar* ret = gdk_pixbuf_get_option(_SELF(self), RVAL2CSTR(key));
return ret ? CSTR2RVAL(ret) : Qnil;
}
/****************************************************/
/* File opening */
/* Image Data in Memory */
static VALUE
initialize(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
GdkPixbuf* buf;
GError* error = NULL;
VALUE arg1, arg2, arg3, arg4, arg5, arg6, arg7;
rb_scan_args(argc, argv, "16", &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7);
if (argc == 7){
buf = gdk_pixbuf_new_from_data((const guchar*)RVAL2CSTR(arg1),
RVAL2GENUM(arg2, GDK_TYPE_COLORSPACE),
RTEST(arg3), NUM2INT(arg4),
NUM2INT(arg5), NUM2INT(arg6),
NUM2INT(arg7), NULL, NULL);
if (buf == NULL){
rb_gc();
buf = gdk_pixbuf_new_from_data((const guchar*)RVAL2CSTR(arg1),
RVAL2GENUM(arg2, GDK_TYPE_COLORSPACE),
RTEST(arg3), NUM2INT(arg4),
NUM2INT(arg5), NUM2INT(arg6),
NUM2INT(arg7), NULL, NULL);
if (buf == NULL) NOMEM_ERROR(&error);
}
// Save a reference to the string because the pixbuf doesn't copy it.
G_RELATIVE(self, arg1);
} else if (argc == 5){
if (rb_obj_is_kind_of(arg1, GTYPE2CLASS(GDK_TYPE_PIXBUF))){
buf = gdk_pixbuf_new_subpixbuf(_SELF(arg1),
NUM2INT(arg2), NUM2INT(arg3),
NUM2INT(arg4), NUM2INT(arg5));
if (buf == NULL){
rb_gc();
buf = gdk_pixbuf_new_subpixbuf(_SELF(arg1),
NUM2INT(arg2), NUM2INT(arg3),
NUM2INT(arg4), NUM2INT(arg5));
if (buf == NULL) NOMEM_ERROR(&error);
}
} else if (rb_obj_is_kind_of(arg1, GTYPE2CLASS(GDK_TYPE_COLORSPACE))){
buf = gdk_pixbuf_new(RVAL2GENUM(arg1, GDK_TYPE_COLORSPACE),
RTEST(arg2), NUM2INT(arg3),
NUM2INT(arg4), NUM2INT(arg5));
if (buf == NULL){
rb_gc();
buf = gdk_pixbuf_new(RVAL2GENUM(arg1, GDK_TYPE_COLORSPACE),
RTEST(arg2), NUM2INT(arg3),
NUM2INT(arg4), NUM2INT(arg5));
if (buf == NULL) NOMEM_ERROR(&error);
}
} else {
rb_raise(rb_eArgError, "Wrong type of 1st argument or wrong number of arguments");
}
} else if (argc == 4) {
#if RBGDK_PIXBUF_CHECK_VERSION(2,6,0)
buf = gdk_pixbuf_new_from_file_at_scale(RVAL2CSTR(arg1),
NUM2INT(arg2), NUM2INT(arg3),
RTEST(arg4), &error);
if (buf == NULL){
rb_gc();
error = NULL;
buf = gdk_pixbuf_new_from_file_at_scale(RVAL2CSTR(arg1),
NUM2INT(arg2), NUM2INT(arg3),
RTEST(arg4), &error);
}
#else
rb_warning("Not supported in GTK+-2.4.x.");
buf = gdk_pixbuf_new_from_file(RVAL2CSTR(arg1), &error);
if (buf == NULL){
error = NULL;
rb_gc();
buf = gdk_pixbuf_new_from_file(RVAL2CSTR(arg1), &error);
}
#endif
} else if (argc == 3) {
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
buf = gdk_pixbuf_new_from_file_at_size(RVAL2CSTR(arg1),
NUM2INT(arg2), NUM2INT(arg3), &error);
if (buf == NULL){
rb_gc();
error = NULL;
buf = gdk_pixbuf_new_from_file_at_size(RVAL2CSTR(arg1),
NUM2INT(arg2), NUM2INT(arg3), &error);
}
#else
rb_warning("Not supported in GTK+-2.0.x.");
buf = gdk_pixbuf_new_from_file(RVAL2CSTR(arg1), &error);
if (buf == NULL){
error = NULL;
rb_gc();
buf = gdk_pixbuf_new_from_file(RVAL2CSTR(arg1), &error);
}
#endif
} else if (argc == 2){
int i;
int len = RARRAY(arg1)->len;
guint8 *gstream = g_new(guint8, len);
for (i = 0; i < len; i++){
gstream[i] = (guint8)NUM2UINT(RARRAY(arg1)->ptr[i]);
}
buf = gdk_pixbuf_new_from_inline(len, gstream, RTEST(arg2), &error);
if (buf == NULL){
rb_gc();
error = NULL;
buf = gdk_pixbuf_new_from_inline(len, gstream, RTEST(arg2), &error);
}
/* need to manage the returned value */
rb_ivar_set(self, id_pixdata, Data_Wrap_Struct(rb_cData, NULL, g_free, gstream));
} else if (argc == 1){
if (TYPE(arg1) == T_STRING) {
buf = gdk_pixbuf_new_from_file(RVAL2CSTR(arg1), &error);
if (buf == NULL){
rb_gc();
error = NULL;
buf = gdk_pixbuf_new_from_file(RVAL2CSTR(arg1), &error);
}
} else if (TYPE(arg1) == T_ARRAY) {
int i;
gchar** data = ALLOCA_N(gchar*, RARRAY(arg1)->len);
for (i=0; i < RARRAY(arg1)->len; i++) {
data[i] = RVAL2CSTR(RARRAY(arg1)->ptr[i]);
}
buf = gdk_pixbuf_new_from_xpm_data((const gchar**)data);
if (buf == NULL){
rb_gc();
buf = gdk_pixbuf_new_from_xpm_data((const gchar**)data);
if (buf == NULL) NOMEM_ERROR(&error);
}
} else {
rb_raise(rb_eArgError, "Wrong type of 1st argument or wrong number of arguments");
}
} else {
rb_raise(rb_eArgError, "Wrong number of arguments");
}
if (error || ! buf) RAISE_GERROR(error);
G_INITIALIZE(self, buf);
return Qnil;
}
static VALUE
copy(self)
VALUE self;
{
return GOBJ2RVAL(gdk_pixbuf_copy(_SELF(self)));
}
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
static VALUE
get_file_info(self, filename)
VALUE self, filename;
{
gint width, height;
GdkPixbufFormat* format = gdk_pixbuf_get_file_info(RVAL2CSTR(filename),
&width, &height);
return format ? rb_ary_new3(3, BOXED2RVAL(format, GDK_TYPE_PIXBUF_FORMAT), INT2NUM(width), INT2NUM(height)) : Qnil;
}
#endif
/****************************************************/
/* File saving */
static VALUE
save(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
VALUE filename, type, options, key, str;
GError* error = NULL;
gboolean result;
gchar** keys = NULL;
gchar** values = NULL;
gint len, i;
ID to_s = rb_intern("to_s");
VALUE ary;
rb_scan_args(argc, argv, "21", &filename, &type, &options);
if (options != Qnil){
Check_Type(options, T_HASH);
ary = rb_funcall(options, rb_intern("to_a"), 0);
len = RARRAY(ary)->len;
keys = ALLOCA_N(gchar*, len + 1);
values = ALLOCA_N(gchar*, len + 1);
for (i = 0; i < len; i++) {
key = RARRAY(RARRAY(ary)->ptr[i])->ptr[0];
if (SYMBOL_P(key)) {
keys[i] = rb_id2name(SYM2ID(key));
} else {
keys[i] = RVAL2CSTR(key);
}
str = rb_funcall(RARRAY(RARRAY(ary)->ptr[i])->ptr[1], to_s, 0);
values[i] = RVAL2CSTR(str);
}
keys[len] = NULL;
values[len] = NULL;
}
result = gdk_pixbuf_savev(_SELF(self), RVAL2CSTR(filename),
RVAL2CSTR(type), keys, values, &error);
if (! result) RAISE_GERROR(error);
return self;
}
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
/* XXX
gboolean gdk_pixbuf_save_to_callbackv (GdkPixbuf *pixbuf,
GdkPixbufSaveFunc save_func,
gpointer user_data,
const char *type,
char **option_keys,
char **option_values,
GError **error);
*/
static VALUE
save_to_buffer(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
VALUE type, options, key, str;
GError* error = NULL;
gboolean result;
gchar** keys = NULL;
gchar** values = NULL;
gchar* buffer;
gsize buffer_size;
gint len, i;
ID to_s = rb_intern("to_s");
VALUE ary;
rb_scan_args(argc, argv, "11", &type, &options);
if (options != Qnil){
Check_Type(options, T_HASH);
ary = rb_funcall(options, rb_intern("to_a"), 0);
len = RARRAY(ary)->len;
keys = ALLOCA_N(gchar*, len + 1);
values = ALLOCA_N(gchar*, len + 1);
for (i = 0; i < len; i++) {
key = RARRAY(RARRAY(ary)->ptr[i])->ptr[0];
if (SYMBOL_P(key)) {
keys[i] = rb_id2name(SYM2ID(key));
} else {
keys[i] = RVAL2CSTR(key);
}
str = rb_funcall(RARRAY(RARRAY(ary)->ptr[i])->ptr[1], to_s, 0);
values[i] = RVAL2CSTR(str);
}
keys[len] = NULL;
values[len] = NULL;
}
result = gdk_pixbuf_save_to_bufferv(_SELF(self), &buffer, &buffer_size,
RVAL2CSTR(type), keys, values, &error);
if (! result) RAISE_GERROR(error);
return rb_str_new(buffer, buffer_size);
}
#endif
/****************************************************/
/* Scaling */
static VALUE
scale_simple(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
GdkPixbuf* dest;
VALUE dest_width, dest_height, interp_type, ret;
GdkInterpType type = GDK_INTERP_BILINEAR;
rb_scan_args(argc, argv, "21", &dest_width, &dest_height,
&interp_type);
if (!NIL_P(interp_type))
type = RVAL2GENUM(interp_type, GDK_TYPE_INTERP_TYPE);
dest = gdk_pixbuf_scale_simple(_SELF(self),
NUM2INT(dest_width),
NUM2INT(dest_height),
type);
ret = GOBJ2RVAL(dest);
g_object_unref(dest);
return ret;
}
static VALUE
scale(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
GdkInterpType type = GDK_INTERP_BILINEAR;
VALUE dest, dest_x, dest_y, dest_width, dest_height;
VALUE offset_x, offset_y, scale_x, scale_y, interp_type;
rb_scan_args(argc, argv, "91", &dest, &dest_x, &dest_y,
&dest_width, &dest_height, &offset_x, &offset_y,
&scale_x, &scale_y, &interp_type);
if (!NIL_P(interp_type))
type = RVAL2GENUM(interp_type, GDK_TYPE_INTERP_TYPE);
gdk_pixbuf_scale(_SELF(dest), _SELF(self),
NUM2INT(dest_x), NUM2INT(dest_y),
NUM2INT(dest_width), NUM2INT(dest_height),
NUM2DBL(offset_x), NUM2DBL(offset_y),
NUM2DBL(scale_x), NUM2DBL(scale_y), type);
return self;
}
static VALUE
composite_simple(self, dest_width, dest_height, interp_type, overall_alpha,
check_size, color1, color2)
VALUE self, dest_width, dest_height, interp_type, overall_alpha,
check_size, color1, color2;
{
GdkPixbuf* dest;
VALUE ret;
GdkInterpType type = GDK_INTERP_BILINEAR;
if (!NIL_P(interp_type))
type = RVAL2GENUM(interp_type, GDK_TYPE_INTERP_TYPE);
dest = gdk_pixbuf_composite_color_simple(
_SELF(self), NUM2INT(dest_width), NUM2INT(dest_height),
type, NUM2INT(overall_alpha), NUM2INT(check_size),
NUM2UINT(color1), NUM2UINT(color2));
ret = GOBJ2RVAL(dest);
g_object_unref(dest);
return ret;
}
static VALUE
composite(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
VALUE ret;
VALUE args[16];
GdkInterpType interp_type = GDK_INTERP_BILINEAR;
rb_scan_args(argc, argv, "97",
&args[0], &args[1], &args[2], &args[3], &args[4],
&args[5], &args[6], &args[7], &args[8], &args[9],
&args[10], &args[11], &args[12], &args[13], &args[14],
&args[15]);
switch (argc) {
case 11:
if (!NIL_P(args[9]))
interp_type = RVAL2GENUM(args[9], GDK_TYPE_INTERP_TYPE);
gdk_pixbuf_composite(_SELF(args[0]), _SELF(self),
NUM2INT(args[1]), NUM2INT(args[2]),
NUM2INT(args[3]), NUM2INT(args[4]),
NUM2DBL(args[5]), NUM2DBL(args[6]),
NUM2DBL(args[7]), NUM2DBL(args[8]),
interp_type, NUM2INT(args[10]));
ret = self;
break;
case 16:
if (!NIL_P(args[9]))
interp_type = RVAL2GENUM(args[9], GDK_TYPE_INTERP_TYPE);
gdk_pixbuf_composite_color(_SELF(args[0]), _SELF(self),
NUM2INT(args[1]), NUM2INT(args[2]),
NUM2INT(args[3]), NUM2INT(args[4]),
NUM2DBL(args[5]), NUM2DBL(args[6]),
NUM2DBL(args[7]), NUM2DBL(args[8]),
interp_type, NUM2INT(args[10]),
NUM2INT(args[11]), NUM2INT(args[12]),
NUM2INT(args[13]), NUM2UINT(args[14]),
NUM2UINT(args[15]));
ret = self;
break;
default:
rb_raise(rb_eArgError, "Wrong number of arguments: %d", argc);
break;
}
return ret;
}
#if RBGDK_PIXBUF_CHECK_VERSION(2,6,0)
static VALUE
rotate_simple(self, angle)
VALUE self, angle;
{
return GOBJ2RVAL(gdk_pixbuf_rotate_simple(_SELF(self), RVAL2GENUM(angle, GDK_TYPE_PIXBUF_ROTATION)));
}
static VALUE
flip(self, horizontal)
VALUE self, horizontal;
{
return GOBJ2RVAL(gdk_pixbuf_flip(_SELF(self), RTEST(horizontal)));
}
#endif
static VALUE
add_alpha(self, substitute_color, r, g, b)
VALUE self, substitute_color, r, g, b;
{
VALUE ret = Qnil;
GdkPixbuf* buf = gdk_pixbuf_add_alpha(_SELF(self),
RTEST(substitute_color),
FIX2INT(r), FIX2INT(g), FIX2INT(b));
if (buf){
ret = GOBJ2RVAL(buf);
g_object_unref(buf);
}
return ret;
}
static VALUE
copy_area(self, src_x, src_y, width, height, dest, dest_x, dest_y)
VALUE self, src_x, src_y, width, height, dest, dest_x, dest_y;
{
gdk_pixbuf_copy_area(_SELF(self), NUM2INT(src_x), NUM2INT(src_y),
NUM2INT(width), NUM2INT(height),
_SELF(dest), NUM2INT(dest_x), NUM2INT(dest_y));
return dest;
}
static VALUE
saturate_and_pixelate(self, staturation, pixelate)
VALUE self, staturation, pixelate;
{
GdkPixbuf* dest = gdk_pixbuf_copy(_SELF(self));
gdk_pixbuf_saturate_and_pixelate(_SELF(self), dest,
NUM2DBL(staturation), RTEST(pixelate));
return GOBJ2RVAL(dest);
}
static VALUE
fill(self, pixel)
VALUE self, pixel;
{
gdk_pixbuf_fill(_SELF(self), NUM2UINT(pixel));
return self;
}
/* From Module Interface */
#if RBGDK_PIXBUF_CHECK_VERSION(2,2,0)
static VALUE
get_formats(self)
VALUE self;
{
return GSLIST2ARY2(gdk_pixbuf_get_formats(), GDK_TYPE_PIXBUF_FORMAT);
}
static VALUE
set_option(self, key, value)
VALUE self, key, value;
{
#if HAVE_GDK_PIXBUF_SET_OPTION
return CBOOL2RVAL(gdk_pixbuf_set_option(_SELF(self),
RVAL2CSTR(key), RVAL2CSTR(value)));
#else
rb_warning("not supported in this version of GTK+");
return Qfalse;
#endif
}
#endif
void
Init_gdk_pixbuf2()
{
VALUE mGdk = rb_define_module("Gdk");
VALUE gdkPixbuf = G_DEF_CLASS(GDK_TYPE_PIXBUF, "Pixbuf", mGdk);
id_pixdata = rb_intern("pixdata");
/*
gdk_rgb_init();*/ /* initialize it anyway */
/*
* Initialization and Versions
*/
/* Removed. This crashes Ruby/GTK on Windows + GTK+-2.4.x.
Pointed out by Laurent.
#ifdef HAVE_GDK_PIXBUF_VERSION
rb_define_const(gdkPixbuf, "VERSION", CSTR2RVAL(gdk_pixbuf_version));
#endif
*/
rb_define_const(gdkPixbuf, "MAJOR", INT2FIX(GDK_PIXBUF_MAJOR));
rb_define_const(gdkPixbuf, "MINOR", INT2FIX(GDK_PIXBUF_MINOR));
rb_define_const(gdkPixbuf, "MICRO", INT2FIX(GDK_PIXBUF_MICRO));
/*
* The GdkPixbuf Structure
*/
rb_define_method(gdkPixbuf, "colorspace", get_colorspace, 0);
rb_define_method(gdkPixbuf, "n_channels", get_n_channels, 0);
rb_define_method(gdkPixbuf, "has_alpha?", get_has_alpha, 0);
rb_define_method(gdkPixbuf, "bits_per_sample", get_bits_per_sample, 0);
rb_define_method(gdkPixbuf, "pixels", get_pixels, 0);
rb_define_method(gdkPixbuf, "width", get_width, 0);
rb_define_method(gdkPixbuf, "height", get_height, 0);
rb_define_method(gdkPixbuf, "rowstride", get_rowstride, 0);
rb_define_method(gdkPixbuf, "get_option", get_option, 1);
/* GdkPixbufError */
G_DEF_ERROR(GDK_PIXBUF_ERROR, "PixbufError", mGdk, rb_eRuntimeError, GDK_TYPE_PIXBUF_ERROR);
/* GdkColorspace */
G_DEF_CLASS(GDK_TYPE_COLORSPACE, "ColorSpace", gdkPixbuf);
G_DEF_CONSTANTS(gdkPixbuf, GDK_TYPE_COLORSPACE, "GDK_");
/* GdkPixbufAlphaMode */
G_DEF_CLASS(GDK_TYPE_PIXBUF_ALPHA_MODE, "AlphaMode", gdkPixbuf);
G_DEF_CONSTANTS(gdkPixbuf, GDK_TYPE_PIXBUF_ALPHA_MODE, "GDK_PIXBUF_");
/*
* File Loading, Image Data in Memory
*/
rb_define_method(gdkPixbuf, "initialize", initialize, -1);
rb_define_method(gdkPixbuf, "dup", copy, 0);
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
rb_define_singleton_method(gdkPixbuf, "get_file_info", get_file_info, 1);
#endif
/*
* File saving
*/
rb_define_method(gdkPixbuf, "save", save, -1);
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
rb_define_method(gdkPixbuf, "save_to_buffer", save_to_buffer, -1);
#endif
/*
* Scaling
*/
rb_define_method(gdkPixbuf, "scale", scale_simple, -1);
rb_define_method(gdkPixbuf, "scale!", scale, -1);
rb_define_method(gdkPixbuf, "composite", composite_simple, 7);
rb_define_method(gdkPixbuf, "composite!", composite, -1);
#if RBGDK_PIXBUF_CHECK_VERSION(2,6,0)
rb_define_method(gdkPixbuf, "rotate", rotate_simple, 1);
rb_define_method(gdkPixbuf, "flip", flip, 1);
#endif
/* GdkInterpType */
G_DEF_CLASS(GDK_TYPE_INTERP_TYPE, "InterpType", gdkPixbuf);
G_DEF_CONSTANTS(gdkPixbuf, GDK_TYPE_INTERP_TYPE, "GDK_");
#if RBGDK_PIXBUF_CHECK_VERSION(2,6,0)
/* GdkPixbufRotation */
G_DEF_CLASS(GDK_TYPE_PIXBUF_ROTATION, "GdkPixbufRotation", gdkPixbuf);
G_DEF_CONSTANTS(gdkPixbuf, GDK_TYPE_PIXBUF_ROTATION, "GDK_PIXBUF_");
#endif
/*
* Utilities
*/
rb_define_method(gdkPixbuf, "add_alpha", add_alpha, 4);
rb_define_method(gdkPixbuf, "copy_area", copy_area, 7);
rb_define_method(gdkPixbuf, "saturate_and_pixelate", saturate_and_pixelate, 2);
rb_define_method(gdkPixbuf, "fill!", fill, 1);
/*
* Module Interface
*/
#if RBGDK_PIXBUF_CHECK_VERSION(2,2,0)
rb_define_singleton_method(gdkPixbuf, "formats", get_formats, 0);
rb_define_method(gdkPixbuf, "set_option", set_option, 2);
#endif
Init_gdk_pixbuf_animation(mGdk);
#if RBGDK_PIXBUF_CHECK_VERSION(2,8,0)
Init_gdk_pixbuf_simpleanim(mGdk);
#endif
Init_gdk_pixdata(mGdk);
Init_gdk_pixbuf_loader(mGdk);
Init_gdk_pixbuf_format(mGdk);
}
|