Changeset 4105 for libcaca/trunk


Ignore:
Timestamp:
Dec 7, 2009, 6:21:25 PM (10 years ago)
Author:
Pascal Terjan
Message:
  • Bind area import/export functions
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/ruby/caca-canvas.c

    r4104 r4105  
    608608}
    609609
     610static VALUE import_area_from_memory(VALUE self, VALUE x, VALUE y, VALUE data, VALUE format)
     611{
     612    long int bytes;
     613    bytes = caca_import_area_from_memory (_SELF, NUM2INT(x), NUM2INT(y), StringValuePtr(data), RSTRING(StringValue(data))->len, StringValuePtr(format));
     614    if(bytes <= 0)
     615        rb_raise(rb_eRuntimeError, strerror(errno));
     616
     617    return self;
     618}
     619
    610620static VALUE import_from_file(VALUE self, VALUE filename, VALUE format)
    611621{
     
    616626
    617627    return self;
     628}
     629
     630static VALUE import_area_from_file(VALUE self, VALUE x, VALUE y, VALUE filename, VALUE format)
     631{
     632    long int bytes;
     633    bytes = caca_import_area_from_file (_SELF, NUM2INT(x), NUM2INT(y), StringValuePtr(filename), StringValuePtr(format));
     634    if(bytes <= 0)
     635        rb_raise(rb_eRuntimeError, strerror(errno));
     636
     637    return self;
     638}
     639
     640static VALUE export_area_to_memory(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE format)
     641{
     642    size_t bytes;
     643    void *result;
     644    VALUE ret;
     645    result = caca_export_canvas_to_memory (_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), StringValuePtr(format), &bytes);
     646    ret = rb_str_new(result, bytes);
     647    free(result);
     648    return ret;
    618649}
    619650
     
    755786    rb_define_method(cCanvas, "render", render_canvas, 4);
    756787    rb_define_method(cCanvas, "import_from_memory", import_from_memory, 2);
     788    rb_define_method(cCanvas, "import_area_from_memory", import_area_from_memory, 4);
    757789    rb_define_method(cCanvas, "import_from_file", import_from_file, 2);
     790    rb_define_method(cCanvas, "import_area_from_file", import_area_from_file, 4);
    758791    rb_define_method(cCanvas, "export_to_memory", export_to_memory, 1);
     792    rb_define_method(cCanvas, "export_area_to_memory", export_area_to_memory, 5);
    759793    rb_define_singleton_method(cCanvas, "export_list", export_list, 0);
    760794    rb_define_singleton_method(cCanvas, "import_list", import_list, 0);
Note: See TracChangeset for help on using the changeset viewer.