.doc/ext/rays/image.cpp in rays-0.1.6 vs .doc/ext/rays/image.cpp in rays-0.1.7

- old
+ new

@@ -1,87 +1,53 @@ #include "rays/ruby/image.h" #include <rucy.h> -#include <rays/ruby/bitmap.h> -#include <rays/ruby/texture.h> +#include "rays/ruby/color_space.h" +#include "rays/ruby/bitmap.h" +#include "rays/ruby/texture.h" +#include "rays/ruby/painter.h" #include "defs.h" using namespace Rucy; using Rays::coord; static Class cImage; +RUCY_DEFINE_VALUE_FROM_TO(Rays::Image, cImage) -namespace Rays -{ +#define THIS to<Rays::Image*>(self) +#define CHECK RUCY_CHECK_OBJECT(Rays::Image, cImage, self) - Class - image_class () - { - return cImage; - } - -}// Rays - - -namespace Rucy -{ - - - Value - value (const Rays::Image& obj) - { - return new_type(cImage, new Rays::Image(obj)); - } - - Value - value (const Rays::Image* obj) - { - return obj ? value(*obj) : nil(); - } - - -}// Rucy - - -#define THIS to<Rays::Image*>(self) - -#define CHECK RUCY_CHECK_OBJECT(self, Rays::Image, cImage) - - static VALUE alloc(VALUE klass) { return new_type<Rays::Image>(klass); } static VALUE initialize(VALUE self) { - RUCY_CHECK_OBJ(self, Rays::Image, cImage); + RUCY_CHECK_OBJ(Rays::Image, cImage, self); + check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2, 3); - if (argc < 1 || 3 < argc) - arg_count_error("Image#initialize", argc, 1, 2, 3); - if (argc == 0) return self; if (argv[0].is_kind_of(Rays::bitmap_class())) { - if (argc < 1 || 2 < argc) - arg_count_error("Image#initialize", argc, 1, 2); + check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2); const Rays::Bitmap* bitmap = to<Rays::Bitmap*>(argv[0]); - if (!bitmap) argument_error(); + if (!bitmap) argument_error(__FILE__, __LINE__); - bool alphaonly = (argc == 2) ? to<bool>(argv[1]) : false; - *THIS = Rays::Image(*bitmap, alphaonly); + bool alpha_only = (argc == 2) ? to<bool>(argv[1]) : false; + *THIS = Rays::Image(*bitmap, alpha_only); } else { int width = to<int>(argv[0]); int height = to<int>(argv[1]); @@ -91,67 +57,80 @@ return self; } static -VALUE width(VALUE self) +VALUE initialize_copy(VALUE self, VALUE obj) { + RUCY_CHECK_OBJ(Rays::Image, cImage, self); + + *THIS = to<Rays::Image&>(obj).copy(); + return self; +} + +static +VALUE painter(VALUE self) +{ CHECK; + return value(THIS->painter()); +} +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()); +} - return value(THIS->color_space().type()); +static +VALUE alpha_only(VALUE self) +{ + CHECK; + return value(THIS->alpha_only()); } static VALUE bitmap(VALUE self) { CHECK; - return value(THIS->bitmap()); } static VALUE texture(VALUE self) { CHECK; - return value(THIS->texture()); } - static -VALUE load(VALUE self) +VALUE save(VALUE self, VALUE path) { - if (argc != 1 && argc != 2) arg_count_error("Image.load", argc, 1, 2); + CHECK; + Rays::save_image(*THIS, path.c_str()); + return self; +} - Rays::String path = argv[0].c_str(); - bool alphaonly = (argc == 2) ? to<bool>(argv[1]) : false; - Rays::Image img; - if (!Rays::load_image(&img, path.c_str(), alphaonly)) - { - rays_error( - "Image.load('%s', %s) failed.", - path.c_str(), alphaonly ? "true" : "false"); - } - - return value(img); +static +VALUE load(VALUE self, VALUE path, VALUE alpha_only) +{ + return value(Rays::load_image(path.c_str(), to<bool>(alpha_only))); } void Init_image () @@ -159,12 +138,30 @@ Module mRays = rb_define_module("Rays"); cImage = rb_define_class_under(mRays, "Image", rb_cObject); rb_define_alloc_func(cImage, alloc); rb_define_private_method(cImage, "initialize", RUBY_METHOD_FUNC(initialize), -1); + rb_define_private_method(cImage, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1); + rb_define_method(cImage, "painter", RUBY_METHOD_FUNC(painter), 0); 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, "alpha_only", RUBY_METHOD_FUNC(alpha_only), 0); rb_define_method(cImage, "bitmap", RUBY_METHOD_FUNC(bitmap), 0); rb_define_method(cImage, "texture", RUBY_METHOD_FUNC(texture), 0); - rb_define_function(cImage, "load", RUBY_METHOD_FUNC(load), -1); + rb_define_method(cImage, "save", RUBY_METHOD_FUNC(save), 1); + rb_define_function(cImage, "load_image", RUBY_METHOD_FUNC(load), 2); } + + +namespace Rays +{ + + + Class + image_class () + { + return cImage; + } + + +}// Rays