ext/rays/image.cpp in rays-0.1.12 vs ext/rays/image.cpp in rays-0.1.13

- old
+ new

@@ -1,21 +1,14 @@ #include "rays/ruby/image.h" -#include <rucy.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; - - RUCY_DEFINE_VALUE_FROM_TO(Rays::Image) #define THIS to<Rays::Image*>(self) #define CHECK RUCY_CHECK_OBJECT(Rays::Image, self) @@ -30,30 +23,32 @@ static RUCY_DEFN(initialize) { RUCY_CHECK_OBJ(Rays::Image, self); - check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2, 3); + check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2, 3, 4); - if (argc == 0) return self; - if (argv[0].is_kind_of(Rays::bitmap_class())) { check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2); const Rays::Bitmap* bitmap = to<Rays::Bitmap*>(argv[0]); - if (!bitmap) argument_error(__FILE__, __LINE__); + if (!bitmap) + argument_error(__FILE__, __LINE__); - bool alpha_only = (argc == 2) ? to<bool>(argv[1]) : false; - *THIS = Rays::Image(*bitmap, alpha_only); + float pixel_density = (argc >= 2) ? to<float>(argv[1]) : 1; + *THIS = Rays::Image(*bitmap, pixel_density); } else { - int width = to<int>(argv[0]); - int height = to<int>(argv[1]); - uint colorspace = (argc == 3) ? to<uint>(argv[2]) : (uint) Rays::RGBA; - *THIS = Rays::Image(width, height, (Rays::ColorSpaceType) colorspace); + check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 2, 3, 4); + + int width = to<int>(argv[0]); + int height = to<int>(argv[1]); + Rays::ColorSpace cs = (argc >= 3) ? to<Rays::ColorSpace>(argv[2]) : Rays::RGBA; + float pixel_density = (argc >= 4) ? to<float>(argv[3]) : 1; + *THIS = Rays::Image(width, height, cs, pixel_density); } return self; } RUCY_END @@ -61,24 +56,16 @@ static RUCY_DEF1(initialize_copy, obj) { RUCY_CHECK_OBJ(Rays::Image, self); - *THIS = to<Rays::Image&>(obj).copy(); + *THIS = to<Rays::Image&>(obj).dup(); return self; } RUCY_END static -RUCY_DEF0(painter) -{ - CHECK; - return value(THIS->painter()); -} -RUCY_END - -static RUCY_DEF0(width) { CHECK; return value(THIS->width()); } @@ -99,30 +86,30 @@ return value(THIS->color_space()); } RUCY_END static -RUCY_DEF0(alpha_only) +RUCY_DEF0(pixel_density) { CHECK; - return value(THIS->alpha_only()); + return value(THIS->pixel_density()); } RUCY_END static -RUCY_DEF0(bitmap) +RUCY_DEF0(painter) { CHECK; - return value(THIS->bitmap()); + return value(THIS->painter()); } RUCY_END static -RUCY_DEF0(texture) +RUCY_DEF0(bitmap) { CHECK; - return value(THIS->texture()); + return value(THIS->bitmap()); } RUCY_END static RUCY_DEF1(save, path) @@ -133,13 +120,15 @@ } RUCY_END static -RUCY_DEF2(load, path, alpha_only) +RUCY_DEFN(load) { - return value(Rays::load_image(path.c_str(), to<bool>(alpha_only))); + check_arg_count(__FILE__, __LINE__, "Image.load", argc, 1); + + return value(Rays::load_image(argv[0].c_str())); } RUCY_END static Class cImage; @@ -149,20 +138,19 @@ { Module mRays = define_module("Rays"); cImage = mRays.define_class("Image"); cImage.define_alloc_func(alloc); - cImage.define_private_method("initialize", initialize); + cImage.define_private_method("initialize", initialize); cImage.define_private_method("initialize_copy", initialize_copy); - cImage.define_method("painter", painter); cImage.define_method("width", width); cImage.define_method("height", height); cImage.define_method("color_space", color_space); - cImage.define_method("alpha_only", alpha_only); + cImage.define_method("pixel_density", pixel_density); + cImage.define_method("painter", painter); cImage.define_method("bitmap", bitmap); - cImage.define_method("texture", texture); cImage.define_method("save", save); - cImage.define_function("load_image", load); + cImage.define_function("load", load); } namespace Rays {