@@ -4,7 +4,7 @@ This a Ruby binding for libcucul, libcaca will be added later. | |||||
There is no real documentation but "methods" on any object should help you :) | There is no real documentation but "methods" on any object should help you :) | ||||
The objects available for now are : | |||||
The objects available are : | |||||
- Cucul::Canvas (functions that have a cucul_canvas_t* as first argument) | - Cucul::Canvas (functions that have a cucul_canvas_t* as first argument) | ||||
@@ -13,6 +13,8 @@ The objects available for now are : | |||||
- Cucul::Font (functions that have a cucul_font_t* as first argument) | - Cucul::Font (functions that have a cucul_font_t* as first argument) | ||||
* The constructor can currently only accept the name of a builtin font | * The constructor can currently only accept the name of a builtin font | ||||
The character set conversion functions are not available yet in the binding. | |||||
I tried to follow Ruby spirit meaning that : | I tried to follow Ruby spirit meaning that : | ||||
- most of the methods return self | - most of the methods return self | ||||
- the methods set_foo with only an argument are also available as foo= | - the methods set_foo with only an argument are also available as foo= | ||||
@@ -68,8 +70,11 @@ Cucul::Font.ancestors[1].instance_methods | |||||
\code | \code | ||||
irb(main):006:0> Cucul::Dither.instance_methods.sort - | irb(main):006:0> Cucul::Dither.instance_methods.sort - | ||||
Cucul::Dither.ancestors[1].instance_methods => ["brightness=", | |||||
"contrast=", "gamma=", "palette=", "set_brightness", "set_contrast", | |||||
Cucul::Dither.ancestors[1].instance_methods | |||||
=> ["algorithm=", "algorithm_list", "antialias=", "antialias_list", | |||||
"brightness=", "charset=", "charset_list", "color=", "color_list", | |||||
"contrast=", "gamma=", "palette=", "set_algorithm", "set_antialias", | |||||
"set_brightness", "set_charset", "set_color", "set_contrast", | |||||
"set_gamma", "set_palette"] | "set_gamma", "set_palette"] | ||||
\endcode | \endcode | ||||
@@ -3,4 +3,46 @@ | |||||
#define _SELF (DATA_PTR(self)) | #define _SELF (DATA_PTR(self)) | ||||
#define get_singleton_double_list(x) \ | |||||
static VALUE x##_list(void) \ | |||||
{ \ | |||||
VALUE ary, ary2; \ | |||||
char const* const* list; \ | |||||
\ | |||||
list = cucul_get_##x##_list(); \ | |||||
ary = rb_ary_new(); \ | |||||
while (*list != NULL) \ | |||||
{ \ | |||||
ary2 = rb_ary_new(); \ | |||||
rb_ary_push(ary2, rb_str_new2(*list)); \ | |||||
list++; \ | |||||
rb_ary_push(ary2, rb_str_new2(*list)); \ | |||||
list++; \ | |||||
rb_ary_push(ary, ary2); \ | |||||
} \ | |||||
\ | |||||
return ary; \ | |||||
} | |||||
#define get_double_list(x) \ | |||||
static VALUE x##_list(VALUE self) \ | |||||
{ \ | |||||
VALUE ary, ary2; \ | |||||
char const* const* list; \ | |||||
\ | |||||
list = cucul_get_##x##_list(_SELF); \ | |||||
ary = rb_ary_new(); \ | |||||
while (*list != NULL) \ | |||||
{ \ | |||||
ary2 = rb_ary_new(); \ | |||||
rb_ary_push(ary2, rb_str_new2(*list)); \ | |||||
list++; \ | |||||
rb_ary_push(ary2, rb_str_new2(*list)); \ | |||||
list++; \ | |||||
rb_ary_push(ary, ary2); \ | |||||
} \ | |||||
\ | |||||
return ary; \ | |||||
} | |||||
#endif | #endif |
@@ -12,6 +12,7 @@ | |||||
#include <ruby.h> | #include <ruby.h> | ||||
#include <cucul.h> | #include <cucul.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include "cucul-dither.h" | |||||
#include "cucul-font.h" | #include "cucul-font.h" | ||||
#include "common.h" | #include "common.h" | ||||
@@ -438,6 +439,16 @@ static VALUE fill_triangle(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, V | |||||
return self; | return self; | ||||
} | } | ||||
static VALUE dither_bitmap(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE d, VALUE pixels) | |||||
{ | |||||
if(CLASS_OF(d) != cDither) | |||||
rb_raise(rb_eArgError, "d is not a Cucul::Dither"); | |||||
Check_Type(pixels, T_STRING); | |||||
cucul_dither_bitmap(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), DATA_PTR(d), StringValuePtr(pixels)); | |||||
return self; | |||||
} | |||||
/****/ | /****/ | ||||
get_int(frame_count) | get_int(frame_count) | ||||
@@ -549,51 +560,8 @@ static VALUE export_memory(VALUE self, VALUE format) | |||||
return ret; | return ret; | ||||
} | } | ||||
static VALUE export_list(void) | |||||
{ | |||||
VALUE ary, ary2; | |||||
char const* const* list; | |||||
list = cucul_get_export_list(); | |||||
ary = rb_ary_new(); | |||||
while (*list != NULL) | |||||
{ | |||||
ary2 = rb_ary_new(); | |||||
rb_ary_push(ary2, rb_str_new2(*list)); | |||||
list++; | |||||
rb_ary_push(ary2, rb_str_new2(*list)); | |||||
list++; | |||||
rb_ary_push(ary, ary2); | |||||
} | |||||
return ary; | |||||
} | |||||
static VALUE import_list(void) | |||||
{ | |||||
VALUE ary, ary2; | |||||
char const* const* list; | |||||
list = cucul_get_import_list(); | |||||
ary = rb_ary_new(); | |||||
while (*list != NULL) | |||||
{ | |||||
ary2 = rb_ary_new(); | |||||
rb_ary_push(ary2, rb_str_new2(*list)); | |||||
list++; | |||||
rb_ary_push(ary2, rb_str_new2(*list)); | |||||
list++; | |||||
rb_ary_push(ary, ary2); | |||||
} | |||||
return ary; | |||||
} | |||||
get_singleton_double_list(export) | |||||
get_singleton_double_list(import) | |||||
/****/ | /****/ | ||||
@@ -658,6 +626,7 @@ void Init_cucul_canvas(VALUE mCucul) | |||||
rb_define_method(cCanvas, "draw_triangle", draw_triangle, 7); | rb_define_method(cCanvas, "draw_triangle", draw_triangle, 7); | ||||
rb_define_method(cCanvas, "draw_thin_triangle", draw_thin_triangle, 6); | rb_define_method(cCanvas, "draw_thin_triangle", draw_thin_triangle, 6); | ||||
rb_define_method(cCanvas, "fill_triangle", fill_triangle, 7); | rb_define_method(cCanvas, "fill_triangle", fill_triangle, 7); | ||||
rb_define_method(cCanvas, "dither_bitmap", dither_bitmap, 6); | |||||
rb_define_method(cCanvas, "frame_count", get_frame_count, 0); | rb_define_method(cCanvas, "frame_count", get_frame_count, 0); | ||||
rb_define_method(cCanvas, "frame=", set_frame, 1); | rb_define_method(cCanvas, "frame=", set_frame, 1); | ||||
@@ -14,7 +14,7 @@ | |||||
#include <errno.h> | #include <errno.h> | ||||
#include "common.h" | #include "common.h" | ||||
VALUE cFont; | |||||
VALUE cDither; | |||||
void dither_free(void *dither) | void dither_free(void *dither) | ||||
{ | { | ||||
@@ -139,7 +139,7 @@ static VALUE set_dither_palette2(VALUE self, VALUE palette) | |||||
} | } | ||||
#define set_float(x) \ | #define set_float(x) \ | ||||
static VALUE set_##x (VALUE self, VALUE x) \ | |||||
static VALUE set_##x(VALUE self, VALUE x) \ | |||||
{ \ | { \ | ||||
if(cucul_set_dither_##x(_SELF, (float)NUM2DBL(x))<0)\ | if(cucul_set_dither_##x(_SELF, (float)NUM2DBL(x))<0)\ | ||||
rb_raise(rb_eRuntimeError, strerror(errno)); \ | rb_raise(rb_eRuntimeError, strerror(errno)); \ | ||||
@@ -147,7 +147,7 @@ static VALUE set_##x (VALUE self, VALUE x) \ | |||||
return x; \ | return x; \ | ||||
} \ | } \ | ||||
\ | \ | ||||
static VALUE set_##x##2 (VALUE self, VALUE x) \ | |||||
static VALUE set_##x##2(VALUE self, VALUE x) \ | |||||
{ \ | { \ | ||||
set_##x(self, x); \ | set_##x(self, x); \ | ||||
return self; \ | return self; \ | ||||
@@ -157,24 +157,53 @@ set_float(brightness) | |||||
set_float(gamma) | set_float(gamma) | ||||
set_float(contrast) | set_float(contrast) | ||||
/* | |||||
int cucul_set_dither_invert (cucul_dither_t *, int) | |||||
Invert colors of dither. | |||||
*/ | |||||
#define get_set_str_from_list(x) \ | |||||
get_double_list(dither_##x) \ | |||||
static VALUE set_dither_##x(VALUE self, VALUE x) \ | |||||
{ \ | |||||
if(cucul_set_dither_##x(_SELF, StringValuePtr(x))<0) \ | |||||
{ \ | |||||
rb_raise(rb_eRuntimeError, strerror(errno)); \ | |||||
} \ | |||||
return x; \ | |||||
} \ | |||||
\ | |||||
static VALUE set_dither_##x##2(VALUE self, VALUE x) \ | |||||
{ \ | |||||
set_dither_##x(self, x); \ | |||||
return self; \ | |||||
} | |||||
get_set_str_from_list(antialias) | |||||
get_set_str_from_list(color) | |||||
get_set_str_from_list(charset) | |||||
get_set_str_from_list(algorithm) | |||||
void Init_cucul_dither(VALUE mCucul) | void Init_cucul_dither(VALUE mCucul) | ||||
{ | { | ||||
cFont = rb_define_class_under(mCucul, "Dither", rb_cObject); | |||||
rb_define_alloc_func(cFont, dither_alloc); | |||||
rb_define_method(cFont, "initialize", dither_initialize, 8); | |||||
rb_define_method(cFont, "palette=", set_dither_palette, 1); | |||||
rb_define_method(cFont, "set_palette", set_dither_palette2, 1); | |||||
rb_define_method(cFont, "brightness=", set_brightness, 1); | |||||
rb_define_method(cFont, "set_brightness", set_brightness2, 1); | |||||
rb_define_method(cFont, "gamma=", set_gamma, 1); | |||||
rb_define_method(cFont, "set_gamma", set_gamma2, 1); | |||||
rb_define_method(cFont, "contrast=", set_contrast, 1); | |||||
rb_define_method(cFont, "set_contrast", set_contrast2, 1); | |||||
cDither = rb_define_class_under(mCucul, "Dither", rb_cObject); | |||||
rb_define_alloc_func(cDither, dither_alloc); | |||||
rb_define_method(cDither, "initialize", dither_initialize, 8); | |||||
rb_define_method(cDither, "palette=", set_dither_palette, 1); | |||||
rb_define_method(cDither, "set_palette", set_dither_palette2, 1); | |||||
rb_define_method(cDither, "brightness=", set_brightness, 1); | |||||
rb_define_method(cDither, "set_brightness", set_brightness2, 1); | |||||
rb_define_method(cDither, "gamma=", set_gamma, 1); | |||||
rb_define_method(cDither, "set_gamma", set_gamma2, 1); | |||||
rb_define_method(cDither, "contrast=", set_contrast, 1); | |||||
rb_define_method(cDither, "set_contrast", set_contrast2, 1); | |||||
rb_define_method(cDither, "antialias_list", dither_antialias_list, 0); | |||||
rb_define_method(cDither, "antialias=", set_dither_antialias, 1); | |||||
rb_define_method(cDither, "set_antialias", set_dither_antialias2, 1); | |||||
rb_define_method(cDither, "color_list", dither_color_list, 0); | |||||
rb_define_method(cDither, "color=", set_dither_color, 1); | |||||
rb_define_method(cDither, "set_color", set_dither_color2, 1); | |||||
rb_define_method(cDither, "charset_list", dither_charset_list, 0); | |||||
rb_define_method(cDither, "charset=", set_dither_charset, 1); | |||||
rb_define_method(cDither, "set_charset", set_dither_charset2, 1); | |||||
rb_define_method(cDither, "algorithm_list", dither_algorithm_list, 0); | |||||
rb_define_method(cDither, "algorithm=", set_dither_algorithm, 1); | |||||
rb_define_method(cDither, "set_algorithm", set_dither_algorithm2, 1); | |||||
} | } | ||||