Changeset 2009


Ignore:
Timestamp:
11/17/07 14:36:15 (6 years ago)
Author:
pterjan
Message:
  • Finish Cucul::Dither
Location:
libcaca/trunk/ruby
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/ruby/README

    r2008 r2009  
    55There is no real documentation but "methods" on any object should help you :) 
    66 
    7 The objects available for now are : 
     7The objects available are : 
    88 
    99- Cucul::Canvas (functions that have a cucul_canvas_t* as first argument) 
     
    1313- Cucul::Font (functions that have a cucul_font_t* as first argument) 
    1414 * The constructor can currently only accept the name of a builtin font 
     15 
     16The character set conversion functions are not available yet in the binding. 
    1517 
    1618I tried to follow Ruby spirit meaning that : 
     
    6971\code 
    7072irb(main):006:0> Cucul::Dither.instance_methods.sort - 
    71 Cucul::Dither.ancestors[1].instance_methods => ["brightness=", 
    72 "contrast=", "gamma=", "palette=", "set_brightness", "set_contrast", 
     73Cucul::Dither.ancestors[1].instance_methods 
     74=> ["algorithm=", "algorithm_list", "antialias=", "antialias_list", 
     75"brightness=", "charset=", "charset_list", "color=", "color_list", 
     76"contrast=", "gamma=", "palette=", "set_algorithm", "set_antialias", 
     77"set_brightness", "set_charset", "set_color", "set_contrast", 
    7378"set_gamma", "set_palette"] 
    7479\endcode 
  • libcaca/trunk/ruby/common.h

    r1995 r2009  
    44#define _SELF  (DATA_PTR(self)) 
    55 
     6#define get_singleton_double_list(x)                      \ 
     7static VALUE x##_list(void)                     \ 
     8{                                               \ 
     9    VALUE ary, ary2;                            \ 
     10    char const* const* list;                    \ 
     11                                                \ 
     12    list = cucul_get_##x##_list();              \ 
     13    ary = rb_ary_new();                         \ 
     14    while (*list != NULL)                       \ 
     15    {                                           \ 
     16        ary2 = rb_ary_new();                    \ 
     17        rb_ary_push(ary2, rb_str_new2(*list));  \ 
     18        list++;                                 \ 
     19        rb_ary_push(ary2, rb_str_new2(*list));  \ 
     20        list++;                                 \ 
     21        rb_ary_push(ary, ary2);                 \ 
     22    }                                           \ 
     23                                                \ 
     24    return ary;                                 \ 
     25} 
     26 
     27#define get_double_list(x)                      \ 
     28static VALUE x##_list(VALUE self)               \ 
     29{                                               \ 
     30    VALUE ary, ary2;                            \ 
     31    char const* const* list;                    \ 
     32                                                \ 
     33    list = cucul_get_##x##_list(_SELF);         \ 
     34    ary = rb_ary_new();                         \ 
     35    while (*list != NULL)                       \ 
     36    {                                           \ 
     37        ary2 = rb_ary_new();                    \ 
     38        rb_ary_push(ary2, rb_str_new2(*list));  \ 
     39        list++;                                 \ 
     40        rb_ary_push(ary2, rb_str_new2(*list));  \ 
     41        list++;                                 \ 
     42        rb_ary_push(ary, ary2);                 \ 
     43    }                                           \ 
     44                                                \ 
     45    return ary;                                 \ 
     46} 
     47 
    648#endif 
  • libcaca/trunk/ruby/cucul-canvas.c

    r2004 r2009  
    1313#include <cucul.h> 
    1414#include <errno.h> 
     15#include "cucul-dither.h" 
    1516#include "cucul-font.h" 
    1617#include "common.h" 
     
    439440} 
    440441 
     442static VALUE dither_bitmap(VALUE self, VALUE x, VALUE y, VALUE w, VALUE h, VALUE d, VALUE pixels) 
     443{ 
     444    if(CLASS_OF(d) != cDither) 
     445        rb_raise(rb_eArgError, "d is not a Cucul::Dither"); 
     446    Check_Type(pixels, T_STRING); 
     447 
     448    cucul_dither_bitmap(_SELF, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h), DATA_PTR(d), StringValuePtr(pixels)); 
     449    return self; 
     450} 
     451 
    441452/****/ 
    442453 
     
    550561} 
    551562 
    552 static VALUE export_list(void) 
    553 { 
    554     VALUE ary, ary2; 
    555      
    556     char const* const* list; 
    557      
    558     list = cucul_get_export_list(); 
    559      
    560     ary = rb_ary_new(); 
    561      
    562     while (*list != NULL) 
    563     { 
    564         ary2 = rb_ary_new(); 
    565         rb_ary_push(ary2, rb_str_new2(*list)); 
    566         list++; 
    567         rb_ary_push(ary2, rb_str_new2(*list)); 
    568         list++; 
    569         rb_ary_push(ary, ary2); 
    570     } 
    571  
    572     return ary; 
    573 } 
    574  
    575 static VALUE import_list(void) 
    576 { 
    577     VALUE ary, ary2; 
    578      
    579     char const* const* list; 
    580      
    581     list = cucul_get_import_list(); 
    582      
    583     ary = rb_ary_new(); 
    584      
    585     while (*list != NULL) 
    586     { 
    587         ary2 = rb_ary_new(); 
    588         rb_ary_push(ary2, rb_str_new2(*list)); 
    589         list++; 
    590         rb_ary_push(ary2, rb_str_new2(*list)); 
    591         list++; 
    592         rb_ary_push(ary, ary2); 
    593     } 
    594  
    595     return ary; 
    596 } 
     563get_singleton_double_list(export) 
     564get_singleton_double_list(import) 
    597565 
    598566/****/ 
     
    659627    rb_define_method(cCanvas, "draw_thin_triangle", draw_thin_triangle, 6); 
    660628    rb_define_method(cCanvas, "fill_triangle", fill_triangle, 7); 
     629    rb_define_method(cCanvas, "dither_bitmap", dither_bitmap, 6); 
    661630 
    662631    rb_define_method(cCanvas, "frame_count", get_frame_count, 0); 
  • libcaca/trunk/ruby/cucul-dither.c

    r2008 r2009  
    1515#include "common.h" 
    1616 
    17 VALUE cFont; 
     17VALUE cDither; 
    1818 
    1919void dither_free(void *dither) 
     
    140140 
    141141#define set_float(x)                                    \ 
    142 static VALUE set_##x (VALUE self, VALUE x)              \ 
     142static VALUE set_##x(VALUE self, VALUE x)              \ 
    143143{                                                       \ 
    144144    if(cucul_set_dither_##x(_SELF, (float)NUM2DBL(x))<0)\ 
     
    148148}                                                       \ 
    149149                                                        \ 
    150 static VALUE set_##x##2 (VALUE self, VALUE x)           \ 
     150static VALUE set_##x##2(VALUE self, VALUE x)           \ 
    151151{                                                       \ 
    152152    set_##x(self, x);                                   \ 
     
    158158set_float(contrast) 
    159159 
    160 /* 
    161        int cucul_set_dither_invert (cucul_dither_t *, int) 
    162            Invert colors of dither. 
    163 */ 
     160#define get_set_str_from_list(x)                         \ 
     161get_double_list(dither_##x)                              \ 
     162static VALUE set_dither_##x(VALUE self, VALUE x)         \ 
     163{                                                        \ 
     164    if(cucul_set_dither_##x(_SELF, StringValuePtr(x))<0) \ 
     165    {                                                    \ 
     166        rb_raise(rb_eRuntimeError, strerror(errno));     \ 
     167    }                                                    \ 
     168    return x;                                            \ 
     169}                                                        \ 
     170                                                         \ 
     171static VALUE set_dither_##x##2(VALUE self, VALUE x)      \ 
     172{                                                        \ 
     173     set_dither_##x(self, x);                            \ 
     174     return self;                                        \ 
     175} 
     176 
     177get_set_str_from_list(antialias) 
     178get_set_str_from_list(color) 
     179get_set_str_from_list(charset) 
     180get_set_str_from_list(algorithm) 
    164181 
    165182void Init_cucul_dither(VALUE mCucul) 
    166183{ 
    167     cFont = rb_define_class_under(mCucul, "Dither", rb_cObject); 
    168     rb_define_alloc_func(cFont, dither_alloc); 
    169  
    170     rb_define_method(cFont, "initialize", dither_initialize, 8); 
    171     rb_define_method(cFont, "palette=", set_dither_palette, 1); 
    172     rb_define_method(cFont, "set_palette", set_dither_palette2, 1); 
    173     rb_define_method(cFont, "brightness=", set_brightness, 1); 
    174     rb_define_method(cFont, "set_brightness", set_brightness2, 1); 
    175     rb_define_method(cFont, "gamma=", set_gamma, 1); 
    176     rb_define_method(cFont, "set_gamma", set_gamma2, 1); 
    177     rb_define_method(cFont, "contrast=", set_contrast, 1); 
    178     rb_define_method(cFont, "set_contrast", set_contrast2, 1); 
    179 } 
    180  
     184    cDither = rb_define_class_under(mCucul, "Dither", rb_cObject); 
     185    rb_define_alloc_func(cDither, dither_alloc); 
     186 
     187    rb_define_method(cDither, "initialize", dither_initialize, 8); 
     188    rb_define_method(cDither, "palette=", set_dither_palette, 1); 
     189    rb_define_method(cDither, "set_palette", set_dither_palette2, 1); 
     190    rb_define_method(cDither, "brightness=", set_brightness, 1); 
     191    rb_define_method(cDither, "set_brightness", set_brightness2, 1); 
     192    rb_define_method(cDither, "gamma=", set_gamma, 1); 
     193    rb_define_method(cDither, "set_gamma", set_gamma2, 1); 
     194    rb_define_method(cDither, "contrast=", set_contrast, 1); 
     195    rb_define_method(cDither, "set_contrast", set_contrast2, 1); 
     196    rb_define_method(cDither, "antialias_list", dither_antialias_list, 0); 
     197    rb_define_method(cDither, "antialias=", set_dither_antialias, 1); 
     198    rb_define_method(cDither, "set_antialias", set_dither_antialias2, 1); 
     199    rb_define_method(cDither, "color_list", dither_color_list, 0); 
     200    rb_define_method(cDither, "color=", set_dither_color, 1); 
     201    rb_define_method(cDither, "set_color", set_dither_color2, 1); 
     202    rb_define_method(cDither, "charset_list", dither_charset_list, 0); 
     203    rb_define_method(cDither, "charset=", set_dither_charset, 1); 
     204    rb_define_method(cDither, "set_charset", set_dither_charset2, 1); 
     205    rb_define_method(cDither, "algorithm_list", dither_algorithm_list, 0); 
     206    rb_define_method(cDither, "algorithm=", set_dither_algorithm, 1); 
     207    rb_define_method(cDither, "set_algorithm", set_dither_algorithm2, 1); 
     208} 
     209 
Note: See TracChangeset for help on using the changeset viewer.