~habnabit/caca-python/master

« back to all changes in this revision

Viewing changes to cacax/dither.pyx

  • Committer: ferazel
  • Date: 2009-05-04 02:08:27 UTC
  • Revision ID: svn-v4:369ffef2-ccd3-42fb-80ba-5443f1475c69:trunk/hab/caca:1060
Renamed caca -> cucul in a lot of places, made some methods take keyword-only arguments, added Font.from_glyph_map, changed some things around with python-like code vs. C API calls, and fixed the caca color/style defines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import itertools
2
2
 
3
3
cdef class Dither:
4
 
    cdef caca_dither_t *dither
 
4
    cdef cucul_dither_t *dither
5
5
    cdef readonly object size
6
6
    cdef readonly object depth
7
7
    cdef readonly object mask
16
16
            pitch_v = width * depth / 8
17
17
        else:
18
18
            pitch_v = pitch
19
 
        self.dither = caca_create_dither(
 
19
        self.dither = cucul_create_dither(
20
20
            depth, width, height, pitch_v, rmask, gmask, bmask, amask)
21
21
        if self.dither == NULL:
22
22
            if errno == EINVAL:
38
38
    
39
39
    def __dealloc__(self):
40
40
        if self.dither != NULL:
41
 
            caca_free_dither(self.dither)
 
41
            cucul_free_dither(self.dither)
42
42
    
43
43
    #def set_palette(self, rgbas):
44
44
    #    cdef uint32_t *rgba_buf = NULL, *rp, *bp, *gp, *ap
50
50
    #        bp = rgba_buf + 256
51
51
    #        gp = rgba_buf + (256 * 2)
52
52
    #        ap = rgba_buf + (256 * 3)
53
 
    #        caca_set_dither_palette(self.dither, rp, bp, gp, ap)
 
53
    #        cucul_set_dither_palette(self.dither, rp, bp, gp, ap)
54
54
    #    finally:
55
55
    #        free(rgba_buf)
56
56
    
72
72
                bp[idx] = b * 0xf
73
73
                gp[idx] = g * 0xf
74
74
                ap[idx] = 0
75
 
            caca_set_dither_palette(self.dither, rp, bp, gp, ap)
 
75
            cucul_set_dither_palette(self.dither, rp, bp, gp, ap)
76
76
        finally:
77
77
            free(rgba_buf)
78
78
    
79
79
    property brightness:
80
80
        def __get__(self):
81
 
            return caca_get_dither_brightness(self.dither)
 
81
            return cucul_get_dither_brightness(self.dither)
82
82
        def __set__(self, brightness):
83
 
            if caca_set_dither_brightness(self.dither, brightness) == -1:
 
83
            if cucul_set_dither_brightness(self.dither, brightness) == -1:
84
84
                raise ValueError('invalid value: %r' % (brightness,))
85
85
    
86
86
    property gamma:
87
87
        def __get__(self):
88
 
            return caca_get_dither_gamma(self.dither)
 
88
            return cucul_get_dither_gamma(self.dither)
89
89
        def __set__(self, gamma):
90
 
            if caca_set_dither_gamma(self.dither, gamma) == -1:
 
90
            if cucul_set_dither_gamma(self.dither, gamma) == -1:
91
91
                raise ValueError('invalid value: %r' % (gamma,))
92
92
    
93
93
    property contrast:
94
94
        def __get__(self):
95
 
            return caca_get_dither_contrast(self.dither)
 
95
            return cucul_get_dither_contrast(self.dither)
96
96
        def __set__(self, contrast):
97
 
            if caca_set_dither_contrast(self.dither, contrast) == -1:
 
97
            if cucul_set_dither_contrast(self.dither, contrast) == -1:
98
98
                raise ValueError('invalid value: %r' % (contrast,))
99
99
    
100
100
    property antialias:
101
101
        def __get__(self):
102
 
            return caca_get_dither_antialias(self.dither)
 
102
            return cucul_get_dither_antialias(self.dither)
103
103
        def __set__(self, antialias):
104
 
            if caca_set_dither_antialias(self.dither, antialias) == -1:
 
104
            if cucul_set_dither_antialias(self.dither, antialias) == -1:
105
105
                raise ValueError('invalid value: %r' % (antialias,))
106
106
    
107
107
    property color:
108
108
        def __get__(self):
109
 
            return caca_get_dither_color(self.dither)
 
109
            return cucul_get_dither_color(self.dither)
110
110
        def __set__(self, color):
111
 
            if caca_set_dither_color(self.dither, color) == -1:
 
111
            if cucul_set_dither_color(self.dither, color) == -1:
112
112
                raise ValueError('invalid value: %r' % (color,))
113
113
    
114
114
    property charset:
115
115
        def __get__(self):
116
 
            return caca_get_dither_charset(self.dither)
 
116
            return cucul_get_dither_charset(self.dither)
117
117
        def __set__(self, charset):
118
 
            if caca_set_dither_charset(self.dither, charset) == -1:
 
118
            if cucul_set_dither_charset(self.dither, charset) == -1:
119
119
                raise ValueError('invalid value: %r' % (charset,))
120
120
    
121
121
    property algorithm:
122
122
        def __get__(self):
123
 
            return caca_get_dither_algorithm(self.dither)
 
123
            return cucul_get_dither_algorithm(self.dither)
124
124
        def __set__(self, algorithm):
125
 
            if caca_set_dither_algorithm(self.dither, algorithm) == -1:
 
125
            if cucul_set_dither_algorithm(self.dither, algorithm) == -1:
126
126
                raise ValueError('invalid value: %r' % (algorithm,))
127
127
    
128
128
    def get_antialias_list(self):
129
 
        return deinterlace(<char **>caca_get_dither_antialias_list(self.dither))
 
129
        return deinterlace(<char **>cucul_get_dither_antialias_list(self.dither))
130
130
    
131
131
    def get_charset_list(self):
132
 
        return deinterlace(<char **>caca_get_dither_charset_list(self.dither))
 
132
        return deinterlace(<char **>cucul_get_dither_charset_list(self.dither))
133
133
    
134
134
    def get_algorithm_list(self):
135
 
        return deinterlace(<char **>caca_get_dither_algorithm_list(self.dither))
 
135
        return deinterlace(<char **>cucul_get_dither_algorithm_list(self.dither))
136
136
    
137
137
    def get_color_list(self):
138
 
        return deinterlace(<char **>caca_get_dither_color_list(self.dither))
 
138
        return deinterlace(<char **>cucul_get_dither_color_list(self.dither))