From a50cbbcfb6c2994e71f2113f1ba3cab77cf1c53f Mon Sep 17 00:00:00 2001 From: Tom Black Date: Wed, 7 Jun 2017 11:26:18 -0400 Subject: Set image width and height in constructor --- ext/ruby2d/ruby2d.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ext') diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c index 3aad03e..d8d6f35 100644 --- a/ext/ruby2d/ruby2d.c +++ b/ext/ruby2d/ruby2d.c @@ -174,8 +174,14 @@ static R_VAL ruby2d_image_init(R_VAL self, R_VAL path) { sprintf(S2D_msg, "Init image: %s", RSTRING_PTR(path)); S2D_Log(S2D_msg, S2D_INFO); S2D_Image *img = S2D_CreateImage(RSTRING_PTR(path)); - r_iv_set(self, "@width", INT2NUM(img->width)); - r_iv_set(self, "@height", INT2NUM(img->height)); + + // Get width and height from Ruby class. If set, use it, else choose the + // native dimensions of the image. + R_VAL w = r_iv_get(self, "@width"); + R_VAL h = r_iv_get(self, "@height"); + r_iv_set(self, "@width" , r_test(w) ? w : INT2NUM(img->width)); + r_iv_set(self, "@height", r_test(h) ? h : INT2NUM(img->height)); + r_iv_set(self, "@data", r_data_wrap_struct(image, img)); return R_NIL; } -- cgit v1.2.3