summaryrefslogtreecommitdiff
path: root/src/static_libs/draw/draw.h
blob: 9f4089aba04384503b153c2f3941c160dc8c500f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
#ifndef EFL_DRAW_H
#define EFL_DRAW_H

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <Eina.h>
#include "efl/interfaces/efl_gfx_types.eot.h"

/* FIXME: naming convention */
typedef void (*RGBA_Comp_Func)       (uint32_t *dest, const uint32_t *src, int length, uint32_t mul_col, uint32_t const_alpha);
typedef void (*RGBA_Comp_Func_Solid) (uint32_t *dest, int length, uint32_t color, uint32_t const_alpha);
typedef void (*RGBA_Comp_Func_Mask)  (uint32_t *dest, uint8_t *mask, int length, uint32_t color);
typedef void (*Draw_Func_ARGB_Mix3)  (uint32_t *dest, uint32_t *src, uint32_t *mul, int len, uint32_t color);
typedef void (*Alpha_Gfx_Func)       (uint8_t *src, uint8_t *dst, int len);
typedef Eina_Bool (*Cspace_Convert_Func) (void *dst, const void *src, int w, int h, int src_stride, int dst_stride, Eina_Bool has_alpha, Efl_Gfx_Colorspace srccs, Efl_Gfx_Colorspace dstcs);

int efl_draw_init(void);

RGBA_Comp_Func       efl_draw_func_span_get         (Efl_Gfx_Render_Op op, uint32_t color, Eina_Bool src_alpha);
RGBA_Comp_Func_Solid efl_draw_func_solid_span_get   (Efl_Gfx_Render_Op op, uint32_t color);
RGBA_Comp_Func_Mask  efl_draw_func_mask_span_get    (Efl_Gfx_Render_Op op, uint32_t color);
Draw_Func_ARGB_Mix3  efl_draw_func_argb_mix3_get    (Efl_Gfx_Render_Op op, uint32_t color);
Alpha_Gfx_Func       efl_draw_alpha_func_get        (Efl_Gfx_Render_Op op, Eina_Bool has_mask);
Cspace_Convert_Func  efl_draw_convert_func_get      (Efl_Gfx_Colorspace origcs, Efl_Gfx_Colorspace dstcs, Eina_Bool *region_can);


/* common sw draw helpers */

#ifndef MIN
#define MIN( a, b )  ( (a) < (b) ? (a) : (b) )
#endif

#ifndef MAX
#define MAX( a, b )  ( (a) > (b) ? (a) : (b) )
#endif

#ifndef A_VAL
#ifndef WORDS_BIGENDIAN
/* x86 */
#define A_VAL(p) (((uint8_t *)(p))[3])
#define R_VAL(p) (((uint8_t *)(p))[2])
#define G_VAL(p) (((uint8_t *)(p))[1])
#define B_VAL(p) (((uint8_t *)(p))[0])
#define AR_VAL(p) ((uint16_t *)(p)[1])
#define GB_VAL(p) ((uint16_t *)(p)[0])
#else
/* ppc */
#define A_VAL(p) (((uint8_t *)(p))[0])
#define R_VAL(p) (((uint8_t *)(p))[1])
#define G_VAL(p) (((uint8_t *)(p))[2])
#define B_VAL(p) (((uint8_t *)(p))[3])
#define AR_VAL(p) ((uint16_t *)(p)[0])
#define GB_VAL(p) ((uint16_t *)(p)[1])
#endif
#endif

#define DRAW_ARGB_JOIN(a,r,g,b) \
        (((a) << 24) + ((r) << 16) + ((g) << 8) + (b))

/* argb multiply */
#define DRAW_MUL4_SYM(x, y) \
 ( ((((((x) >> 16) & 0xff00) * (((y) >> 16) & 0xff00)) + 0xff0000) & 0xff000000) + \
   ((((((x) >> 8) & 0xff00) * (((y) >> 16) & 0xff)) + 0xff00) & 0xff0000) + \
   ((((((x) & 0xff00) * ((y) & 0xff00)) + 0xff0000) >> 16) & 0xff00) + \
   (((((x) & 0xff) * ((y) & 0xff)) + 0xff) >> 8) )

/* alpha from 1 to 256 */
static inline uint32_t
draw_mul_256(int a, uint32_t c)
{
   return (((((c) >> 8) & 0x00ff00ff) * (a)) & 0xff00ff00) |
         (((((c) & 0x00ff00ff) * (a)) >> 8) & 0x00ff00ff);
}

static inline uint32_t
draw_interpolate_256(uint32_t x, int a, uint32_t y, int b)
{
   uint32_t t = (x & 0xff00ff) * a + (y & 0xff00ff) * b;
   t >>= 8;
   t &= 0xff00ff;
   x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b;
   x &= 0xff00ff00;
   x |= t;
   return x;
}

static inline void
draw_memset32(uint32_t *dest, uint32_t value, int length)
{
   int n;

   if (length <= 0)
     return;

   n = (length + 7) / 8;
   switch (length & 0x07)
     {
        case 0: do { *dest++ = value;
        case 7:      *dest++ = value;
        case 6:      *dest++ = value;
        case 5:      *dest++ = value;
        case 4:      *dest++ = value;
        case 3:      *dest++ = value;
        case 2:      *dest++ = value;
        case 1:      *dest++ = value;
        } while (--n > 0);
     }
}

#endif