Class: Caca::Dither

Inherits:
Object
  • Object
show all
Defined in:
ext/caca/caca-dither.c

Instance Method Summary collapse

Constructor Details

#initialize(bpp, w, h, pitch, rmask, gmask, bmask, amask) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'ext/caca/caca-dither.c', line 31

static VALUE dither_initialize(VALUE self, VALUE bpp, VALUE w, VALUE h, VALUE pitch, VALUE rmask, VALUE gmask, VALUE bmask, VALUE amask)
{
    caca_dither_t *dither;

    dither = caca_create_dither(NUM2UINT(bpp), NUM2UINT(w), NUM2UINT(h), NUM2UINT(pitch), NUM2ULONG(rmask), NUM2ULONG(gmask), NUM2ULONG(bmask), NUM2ULONG(amask));
    if(dither == NULL)
    {
        rb_raise(rb_eRuntimeError, "%s", strerror(errno));
    }
    _SELF = dither;
    return self;
}

Instance Method Details

#algorithm=Object

#algorithm_listObject

#antialias=Object

#antialias_listObject

#brightness=Object

#charset=Object

#charset_listObject

#color=Object

#color_listObject

#contrast=Object

#gamma=Object

#palette=(palette) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'ext/caca/caca-dither.c', line 44

static VALUE set_dither_palette(VALUE self, VALUE palette)
{
    int i;
    unsigned int *red, *blue, *green, *alpha;
    VALUE v, r, g, b, a;
    int error = 0;

    if(RARRAY_LEN(palette) != 256)
    {
        rb_raise(rb_eArgError, "Palette must contain 256 elements");
    }

    red = ALLOC_N(unsigned int, 256);
    if(!red)
        rb_raise(rb_eNoMemError,"Out of memory");

    green = ALLOC_N(unsigned int, 256);
    if(!green)
    {
        free(red);
        rb_raise(rb_eNoMemError,"Out of memory");
    }

    blue = ALLOC_N(unsigned int, 256);
    if(!blue)
    {
        free(red);
        free(green);
        rb_raise(rb_eNoMemError,"Out of memory");
    }

    alpha = ALLOC_N(unsigned int, 256);
    if(!alpha)
    {
        free(red);
        free(green);
        free(blue);
        rb_raise(rb_eNoMemError,"Out of memory");
    }

    for(i=0; i<256; i++)
    {
        v = rb_ary_entry(palette, i);
        if((TYPE(v) == T_ARRAY) && (RARRAY_LEN(v) == 4))
        {
            r = rb_ary_entry(v,0);
            g = rb_ary_entry(v,1);
            b = rb_ary_entry(v,2);
            a = rb_ary_entry(v,3);
            if(rb_obj_is_kind_of(r, rb_cInteger) &&
               rb_obj_is_kind_of(g, rb_cInteger) &&
               rb_obj_is_kind_of(b, rb_cInteger) &&
               rb_obj_is_kind_of(a, rb_cInteger))
            {
                red[i]   = NUM2INT(r);
                green[i] = NUM2INT(g);
                blue[i]  = NUM2INT(b);
                alpha[i] = NUM2INT(a);
            } else
                error = 1;
        }
        else
            error = 1;
    }

    if(error)
    {
        free(red);
        free(green);
        free(blue);
        free(alpha);
        rb_raise(rb_eArgError, "Invalid palette");
    }

    if(caca_set_dither_palette(_SELF, red, green, blue, alpha)<0)
    {
        free(red);
        free(green);
        free(blue);
        free(alpha);
        rb_raise(rb_eRuntimeError, "%s", strerror(errno));
    }

    free(red);
    free(green);
    free(blue);
    free(alpha);

    return palette;
}

#set_algorithmObject

#set_antialiasObject

#set_brightnessObject

#set_charsetObject

#set_colorObject

#set_contrastObject

#set_gammaObject

#set_palette(palette) ⇒ Object



135
136
137
138
139
# File 'ext/caca/caca-dither.c', line 135

static VALUE set_dither_palette2(VALUE self, VALUE palette)
{
    set_dither_palette(self, palette);
    return self;
}