Code

a little optimization by making some macros into inlined functions
[inkscape.git] / src / libnr / nr-pixops.h
1 #ifndef __NR_PIXOPS_H__
2 #define __NR_PIXOPS_H__
4 /*
5  * Pixel buffer rendering library
6  *
7  * Authors:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *   bulia byak <buliabyak@users.sf.net>
10  *
11  * This code is in public domain
12  */
14 #define NR_RGBA32_R(v) (unsigned char) (((v) >> 24) & 0xff)
15 #define NR_RGBA32_G(v) (unsigned char) (((v) >> 16) & 0xff)
16 #define NR_RGBA32_B(v) (unsigned char) (((v) >> 8) & 0xff)
17 #define NR_RGBA32_A(v) (unsigned char) ((v) & 0xff)
19 #define FAST_DIVIDE_BY_255(v) ((((v) << 8) + (v) + 257) >> 16)
21 #define NR_A7(fa,ba) (65025 - (255 - fa) * (255 - ba))
22 #define NR_COMPOSENNN_A7(fc,fa,bc,ba,a) (((255 - (fa)) * (bc) * (ba) + (fa) * (fc) * 255 + 127) / a)
23 #define NR_COMPOSEPNN_A7(fc,fa,bc,ba,a) (((255 - (fa)) * (bc) * (ba) + (fc) * 65025 + 127) / a)
24 #define NR_COMPOSENNP(fc,fa,bc,ba) (((255 - (fa)) * (bc) * (ba) + (fa) * (fc) * 255 + 32512) / 65025)
25 #define NR_COMPOSEPNP(fc,fa,bc,ba) (((255 - (fa)) * (bc) * (ba) + (fc) * 65025 + 32512) / 65025)
26 #define INK_COMPOSE(f,a,b) ( ( ((guchar) b) * ((guchar) (0xff - a)) + ((guchar) ((b ^ ~f) + b/4 - (b>127? 63 : 0))) * ((guchar) a) ) >>8)
27 #define NR_PREMUL(c,a) (FAST_DIVIDE_BY_255(((c) * (a) + 127)))
28 #define NR_PREMUL_SINGLE(c) (FAST_DIVIDE_BY_255((c) + 127))
30 #if 0
32 #define NR_A7_NORMALIZED(fa,ba) (FAST_DIVIDE_BY_255((65025 - (255 - (fa)) * (255 - (ba))) + 127))
33 #define NR_COMPOSENPP(fc,fa,bc,ba) (FAST_DIVIDE_BY_255((255 - (fa)) * (bc) + (fa) * (fc) + 127))
34 #define NR_COMPOSEPPP(fc,fa,bc,ba) (FAST_DIVIDE_BY_255((255 - (fa)) * (bc) + (fc) * 255 + 127))
35 #define NR_COMPOSEP11(fc,fa,bc) (FAST_DIVIDE_BY_255((255 - (fa)) * (bc) + (fc) * 255 + 127))
36 #define NR_COMPOSEN11(fc,fa,bc) (FAST_DIVIDE_BY_255((255 - (fa)) * (bc) + (fc) * (fa) + 127))
38 #else
40 inline int NR_A7_NORMALIZED(int fa,int ba) {int temp=(65025 - (255 - (fa)) * (255 - (ba))) + 127; return FAST_DIVIDE_BY_255(temp);}
41 inline int NR_COMPOSENPP(int fc,int fa,int bc,int ba) {int temp=(255 - (fa)) * (bc) + (fa) * (fc) + 127; return FAST_DIVIDE_BY_255(temp);}
42 inline int NR_COMPOSEPPP(int fc,int fa,int bc,int ba) {int temp=(255 - (fa)) * (bc) + (fc) * 255 + 127; return FAST_DIVIDE_BY_255(temp);}
43 inline int NR_COMPOSEP11(int fc,int fa,int bc) {int temp=(255 - (fa)) * (bc) + (fc) * 255 + 127; return FAST_DIVIDE_BY_255(temp);}
44 inline int NR_COMPOSEN11(int fc,int fa,int bc) {int temp=(255 - (fa)) * (bc) + (fc) * (fa) + 127; return FAST_DIVIDE_BY_255(temp);}
46 #endif
48 #endif
50 /*
51   Local Variables:
52   mode:c++
53   c-file-style:"stroustrup"
54   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
55   indent-tabs-mode:nil
56   fill-column:99
57   End:
58 */
59 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :