Added Evas::Image#data, data= and data_update_add.
[ruby-evas.git] / src / rb_image.c
index 7bd0f06a0ad9398d5c2ffac2e6bf438bb3705ae8..a3b96b81629190d2556c92ea2b1f1287882d2eca 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_image.c 284 2005-03-15 18:00:33Z tilman $
+ * $Id: rb_image.c 376 2006-02-25 10:10:31Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
 #include "rb_evas.h"
 #include "rb_evas_object.h"
 
-static void c_free (RbEvasObject *e)
-{
-       c_evas_object_free (e, true);
-}
-
 /*
  * call-seq:
  *  Evas::Image.new(evas) => img
  *
  * Creates an Evas::Image object.
  */
-static VALUE c_new (VALUE klass, VALUE evas)
+static VALUE c_init (VALUE self, VALUE evas)
 {
-       VALUE self, argv[1];
-       RbEvasObject *img;
-
        CHECK_CLASS (evas, cEvas);
        GET_OBJ (evas, RbEvas, e);
+       GET_OBJ (self, RbEvasObject, img);
 
-       self = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark,
-                                c_free, img);
        img->real = evas_object_image_add (e->real);
 
-       argv[0] = evas;
-       rb_obj_call_init (self, 1, argv);
+       rb_call_super (1, &evas);
 
        return self;
 }
@@ -265,11 +255,51 @@ static VALUE c_reload (VALUE self)
        return Qnil;
 }
 
+static VALUE c_data_get (int argc, VALUE *argv, VALUE self)
+{
+       VALUE read_write = Qfalse;
+       void *data;
+       int w = 0, h = 0;
+
+       GET_OBJ (self, RbEvasObject, e);
+
+       rb_scan_args (argc, argv, "01", &read_write);
+
+       if (NIL_P (read_write))
+               read_write = Qfalse;
+
+       data = evas_object_image_data_get (e->real, read_write == Qtrue);
+       evas_object_image_size_get (e->real, &w, &h);
+
+       return rb_str_new (data, h * w * 4);
+}
+
+static VALUE c_data_set (VALUE self, VALUE data)
+{
+       GET_OBJ (self, RbEvasObject, e);
+
+       evas_object_image_data_set (e->real, StringValuePtr (data));
+
+       return Qnil;
+}
+
+static VALUE c_data_update_add (VALUE self, VALUE x, VALUE y,
+                                VALUE w, VALUE h)
+{
+       GET_OBJ (self, RbEvasObject, e);
+
+       evas_object_image_data_update_add (e->real,
+                                          FIX2INT (x), FIX2INT (y),
+                                          FIX2INT (w), FIX2INT (h));
+
+       return Qnil;
+}
+
 void Init_Image (void)
 {
        VALUE c = rb_define_class_under (mEvas, "Image", cEvasObject);
 
-       rb_define_singleton_method (c, "new", c_new, 1);
+       rb_define_method (c, "initialize", c_init, 1);
        rb_define_method (c, "get_file", c_get_file, -1);
        rb_define_method (c, "set_file", c_set_file, -1);
        rb_define_method (c, "has_alpha?", c_has_alpha_get, 0);
@@ -281,4 +311,7 @@ void Init_Image (void)
        rb_define_method (c, "get_border", c_get_border, 0);
        rb_define_method (c, "set_border", c_set_border, 4);
        rb_define_method (c, "reload", c_reload, 0);
+       rb_define_method (c, "data", c_data_get, -1);
+       rb_define_method (c, "data=", c_data_set, 1);
+       rb_define_method (c, "data_update_add", c_data_update_add, 4);
 }