move around - flatter.
[profile/ivi/evas.git] / src / lib / include / evas_common_soft16.h
1 #ifndef EVAS_COMMON_SOFT16_H
2 #define EVAS_COMMON_SOFT16_H
3
4 #include "evas_common.h"
5 #include "evas_private.h"
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 #ifndef always_inline
12 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
13 #    define always_inline __attribute__((always_inline)) inline
14 #else
15 #    define always_inline inline
16 #endif
17 #endif
18
19 #define RGB_565_UNPACKED_MASK 0x07e0f81f
20 #define RGB_565_UNPACK(rgb)                                             \
21    (((rgb) | ((rgb) << 16)) & RGB_565_UNPACKED_MASK)
22 #define RGB_565_PACK(rgb)                                               \
23   ((((rgb) & RGB_565_UNPACKED_MASK) |                                   \
24    ((rgb) & RGB_565_UNPACKED_MASK) >> 16) & 0xffff)
25 #define RGB_565_UNPACKED_BLEND(a, b, alpha)                             \
26    ((b) + (a) - ((((b) * (alpha)) >> 5) & RGB_565_UNPACKED_MASK))
27 #define RGB_565_UNPACKED_BLEND_UNMUL(a, b, alpha)                       \
28    ((b) + ((((a) - (b)) * (alpha)) >> 5))
29
30 #define RGB_565_FROM_COMPONENTS(r, g, b)                                \
31   (((((r) >> 3) & 0x1f) << 11) |                                        \
32    ((((g) >> 2) & 0x3f) << 5) |                                         \
33    (((b) >> 3) & 0x1f))
34
35 #define UNROLL2(op...) op op
36 #define UNROLL4(op...) UNROLL2(op) UNROLL2(op)
37 #define UNROLL8(op...) UNROLL4(op) UNROLL4(op)
38 #define UNROLL16(op...) UNROLL8(op) UNROLL8(op)
39
40 #if defined(__ARM_ARCH_3M__) || defined(__ARM_ARCH_4__) || \
41     defined(__ARM_ARCH_4T__)
42 # define __ARM_ARCH__ 4
43 #endif
44
45 #if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || \
46     defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || \
47     defined(__ARM_ARCH_5TEJ__)
48 # define __ARM_ARCH__ 5
49 #endif
50
51 #if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || \
52     defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || \
53     defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__)
54 # define __ARM_ARCH__ 6
55 #endif
56
57 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || \
58     defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__)
59 # define __ARM_ARCH__ 7
60 #endif
61
62
63 #if defined(__ARM_ARCH__) && (__ARM_ARCH__ >= 5)
64 /* tested on ARMv6 (arm1136j-s), Nokia N800 CPU */
65 #define pld(addr, off)                                                  \
66    __asm__("pld [%[address], %[offset]]"::                              \
67            [address] "r" (addr), [offset] "i" (off))
68 #else
69 #define pld(addr, off)
70 #endif /* __ARMEL__ */
71
72 static inline int
73 _calc_stride(int w)
74 {
75    int pad;
76
77    pad = w % 4;
78    if (!pad)  return w;
79    else return w + 4 - pad;
80 }
81
82 #define IMG_BYTE_SIZE(stride, height, has_alpha)                       \
83    ((stride) * (height) * (!(has_alpha) ? 2 : 3))
84
85 typedef struct _Soft16_Image Soft16_Image;
86 struct _Soft16_Image
87 {
88    Image_Entry    cache_entry;
89
90    RGBA_Image    *source;
91
92    int            stride;     // pixel stride - likely a multiple of 2
93    DATA16        *pixels;     // 16bpp pixels rgb565
94    DATA8         *alpha;      // 8bit alpha mask - optional. points into pixels
95
96    struct
97    {
98 /*      unsigned char  have_alpha  : 1; // 1 if we have halpha */
99      unsigned char  free_pixels : 1; // 1 if pixels should be freed
100      unsigned char  free_alpha  : 1; // 1 if alpha mask should be freed
101    } flags;
102 };
103
104 /**
105  * Image (evas_soft16_main.c)
106  */
107 EAPI void                evas_common_soft16_image_init(void);
108 EAPI void                evas_common_soft16_image_shutdown(void);
109 EAPI Evas_Cache_Image   *evas_common_soft16_image_cache_get(void);
110
111 EAPI void                soft16_image_draw(Soft16_Image *src, Soft16_Image *dst, RGBA_Draw_Context *dc, int src_region_x, int src_region_y, int src_region_w, int src_region_h, int dst_region_x, int dst_region_y, int dst_region_w, int dst_region_h, int smooth);
112 EAPI Soft16_Image       *soft16_image_alpha_set(Soft16_Image *im, int have_alpha);
113
114 void                     soft16_image_draw_unscaled(Soft16_Image *src, Soft16_Image *dst, RGBA_Draw_Context *dc, const Evas_Rectangle sr, const Evas_Rectangle dr, const Evas_Rectangle cr);
115 void                     soft16_image_draw_scaled_sampled(Soft16_Image *src, Soft16_Image *dst, RGBA_Draw_Context *dc, const Evas_Rectangle sr, const Evas_Rectangle dr, const Evas_Rectangle cr);
116
117 /* convert/dither functions */
118 void                     soft16_image_convert_from_rgb(Soft16_Image *im, const DATA32 *src);
119 void                     soft16_image_convert_from_rgba(Soft16_Image *im, const DATA32 *src);
120
121 /**
122  * Rectangle (evas_soft16_rectangle.c)
123  */
124 EAPI void                soft16_rectangle_draw(Soft16_Image *dst, RGBA_Draw_Context *dc, int x, int y, int w, int h);
125
126 /**
127  * Polygon (evas_soft16_polygon.c)
128  */
129 EAPI void                soft16_polygon_draw(Soft16_Image *dst, RGBA_Draw_Context *dc, RGBA_Polygon_Point *points);
130
131 /**
132  * Line (evas_soft16_line.c)
133  */
134 EAPI void                soft16_line_draw(Soft16_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1);
135
136 /**
137  * Font (evas_soft16_font.c)
138  */
139 EAPI void               *soft16_font_glyph_new(void *data, RGBA_Font_Glyph *fg);
140 EAPI void                soft16_font_glyph_free(void *ext_dat);
141 EAPI void                soft16_font_glyph_draw(void *data, void *dest, void *context, RGBA_Font_Glyph *fg, int x, int y);
142
143 #ifdef __cplusplus
144 }
145 #endif
146
147 #endif