#include "rays/ruby/image.h" #include "rays/ruby/color_space.h" #include "rays/ruby/bitmap.h" #include "rays/ruby/painter.h" #include "defs.h" RUCY_DEFINE_VALUE_FROM_TO(RAYS_EXPORT, Rays::Image) #define THIS to(self) #define CHECK RUCY_CHECK_OBJECT(Rays::Image, self) static VALUE alloc(VALUE klass) { return new_type(klass); } static VALUE initialize(VALUE self, VALUE args, VALUE pixel_density, VALUE smooth) { RUCY_CHECK_OBJ(Rays::Image, self); size_t argc = args.size(); check_arg_count(__FILE__, __LINE__, "Image#initialize!", argc, 1, 2, 3); float pd = to(pixel_density); if (args[0].is_a(Rays::bitmap_class())) { const Rays::Bitmap* bmp = to(args[0]); if (!bmp) argument_error(__FILE__, __LINE__); *THIS = Rays::Image(*bmp, pd, smooth); } else { int width = to(args[0]); int height = to(args[1]); auto cs = (argc >= 3) ? to(args[2]) : Rays::RGBA; *THIS = Rays::Image(width, height, cs, pd, smooth); } return self; } static VALUE initialize_copy(VALUE self, VALUE obj) { RUCY_CHECK_OBJ(Rays::Image, self); *THIS = to(obj).dup(); return self; } static VALUE save(VALUE self, VALUE path) { CHECK; THIS->save(path.c_str()); 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 pixel_density(VALUE self) { CHECK; return value(THIS->pixel_density()); } static VALUE painter(VALUE self) { CHECK; return value(THIS->painter()); } static VALUE get_bitmap(VALUE self, VALUE modify) { CHECK; return value(THIS->bitmap(modify)); } static VALUE set_smooth(VALUE self, VALUE smooth) { CHECK; THIS->set_smooth(smooth); return smooth; } static VALUE get_smooth(VALUE self) { CHECK; return value(THIS->smooth()); } static VALUE load(VALUE self, VALUE path) { return value(Rays::load_image(path.c_str())); } static Class cImage; void Init_rays_image () { Module mRays = rb_define_module("Rays"); cImage = rb_define_class_under(mRays, "Image", rb_cObject); rb_define_alloc_func(cImage, alloc); cImage.define_private_method("initialize!", initialize); rb_define_private_method(cImage, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1); rb_define_method(cImage, "save", RUBY_METHOD_FUNC(save), 1); rb_define_method(cImage, "width", RUBY_METHOD_FUNC(width), 0); rb_define_method(cImage, "height", RUBY_METHOD_FUNC(height), 0); rb_define_method(cImage, "color_space", RUBY_METHOD_FUNC(color_space), 0); rb_define_method(cImage, "pixel_density", RUBY_METHOD_FUNC(pixel_density), 0); rb_define_method(cImage, "painter", RUBY_METHOD_FUNC(painter), 0); rb_define_private_method(cImage, "get_bitmap", RUBY_METHOD_FUNC(get_bitmap), 1); rb_define_method(cImage, "smooth=", RUBY_METHOD_FUNC(set_smooth), 1); rb_define_method(cImage, "smooth", RUBY_METHOD_FUNC(get_smooth), 0); rb_define_module_function(cImage, "load", RUBY_METHOD_FUNC(load), 1); } namespace Rays { Class image_class () { return cImage; } }// Rays