#include "rays/ruby/bitmap.h" #include "rays/ruby/color_space.h" #include "rays/ruby/color.h" #include "rays/ruby/font.h" #include "defs.h" RUCY_DEFINE_VALUE_FROM_TO(Rays::Bitmap) #define THIS to(self) #define CHECK RUCY_CHECK_OBJECT(Rays::Bitmap, self) static VALUE alloc(VALUE klass) { return new_type(klass); } static VALUE initialize(VALUE self) { RUCY_CHECK_OBJ(Rays::Bitmap, self); check_arg_count(__FILE__, __LINE__, "Bitmap#initialize", argc, 2, 3); *THIS = Rays::Bitmap( to(argv[0]), to(argv[1]), argc >= 3 ? to(argv[2]) : Rays::RGBA); return self; } static VALUE initialize_copy(VALUE self, VALUE obj) { RUCY_CHECK_OBJ(Rays::Bitmap, self); *THIS = to(obj).dup(); return self; } static VALUE width(VALUE self) { CHECK; return value(THIS->width()); } static VALUE height(VALUE self) { CHECK; return value(THIS->height()); } static VALUE color_space(VALUE self) { CHECK; return value(THIS->color_space()); } static VALUE set_at(VALUE self) { CHECK; check_arg_count(__FILE__, __LINE__, "Bitmap#set_at", argc, 3, 4, 5, 6); int x = to(argv[0]); int y = to(argv[1]); Rays::Color color = to(argc - 2, argv + 2); color.get(THIS->at(x, y), THIS->color_space()); return value(color); } static VALUE get_at(VALUE self, VALUE x, VALUE y) { CHECK; int xx = to(x); int yy = to(y); return value(Rays::Color(THIS->at(xx, yy), THIS->color_space())); } static Class cBitmap; void Init_rays_bitmap () { Module mRays = rb_define_module("Rays"); cBitmap = rb_define_class_under(mRays, "Bitmap", rb_cObject); rb_define_alloc_func(cBitmap, alloc); rb_define_private_method(cBitmap, "initialize", RUBY_METHOD_FUNC(initialize), -1); rb_define_private_method(cBitmap, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1); rb_define_method(cBitmap, "width", RUBY_METHOD_FUNC(width), 0); rb_define_method(cBitmap, "height", RUBY_METHOD_FUNC(height), 0); rb_define_method(cBitmap, "color_space", RUBY_METHOD_FUNC(color_space), 0); cBitmap.define_method("[]=", set_at); cBitmap.define_method("[]", get_at); } namespace Rays { Class bitmap_class () { return cBitmap; } }// Rays