and add in the 8bpp gray stuff
[framework/uifw/evas.git] / src / lib / include / evas_common_soft8.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 GRY_8_BLEND(a, b, alpha)        \
20    ((b) + (a) - ((((b) * ((alpha) + 1)) >> 8) & 0xff))
21
22 #define GRY_8_BLEND_UNMUL(a, b, alpha)  \
23    ((b) + ((((a) - (b)) * ((alpha) + 1)) >> 8))
24
25 #if 0
26 #define GRY_8_FROM_COMPONENTS(r, g, b)  \
27      (((307 * (r)) +    \
28        (604 * (g)) +    \
29        (113 * (b))) >> 10)
30
31 #define GRY_8_FROM_RGB(rgb)     \
32      GRY_8_FROM_COMPONENTS(R_VAL(rgb), G_VAL(rgb), B_VAL(rgb))
33 #endif
34
35 //Y = R * 0.2126 + G * 0.7152 + B * 0.0722
36
37 #define GRY_8_FROM_COMPONENTS(r, g, b)  \
38      (((218 * (r)) +    \
39        (732 * (g)) +    \
40        (74  * (b))) >> 10)
41
42 #define GRY_8_FROM_RGB(rgb)     \
43      GRY_8_FROM_COMPONENTS(R_VAL(rgb), G_VAL(rgb), B_VAL(rgb))
44
45 #define UNROLL2(op...) op op
46 #define UNROLL4(op...) UNROLL2(op) UNROLL2(op)
47 #define UNROLL8(op...) UNROLL4(op) UNROLL4(op)
48 #define UNROLL16(op...) UNROLL8(op) UNROLL8(op)
49
50 #if defined(__ARM_ARCH_3M__)
51 # define __ARM_ARCH__ 40
52 #endif
53 #if defined(__ARM_ARCH_4__)
54 # define __ARM_ARCH__ 40
55 #endif
56 #if defined(__ARM_ARCH_4T__)
57 # define __ARM_ARCH__ 41
58 #endif
59
60 #if defined(__ARM_ARCH_5__)
61 # define __ARM_ARCH__ 50
62 #endif
63 #if defined(__ARM_ARCH_5T__)
64 # define __ARM_ARCH__ 51
65 #endif
66 #if defined(__ARM_ARCH_5E__)
67 # define __ARM_ARCH__ 52
68 #endif
69 #if defined(__ARM_ARCH_5TE__)
70 # define __ARM_ARCH__ 53
71 #endif
72 #if defined(__ARM_ARCH_5TEJ__)
73 # define __ARM_ARCH__ 54
74 #endif
75
76 #if defined(__ARM_ARCH_6__)
77 # define __ARM_ARCH__ 60
78 #endif
79 #if defined(__ARM_ARCH_6J__)
80 # define __ARM_ARCH__ 61
81 #endif
82 #if defined(__ARM_ARCH_6K__)
83 # define __ARM_ARCH__ 62
84 #endif
85 #if defined(__ARM_ARCH_6Z__)
86 # define __ARM_ARCH__ 63
87 #endif
88 #if defined(__ARM_ARCH_6ZK__)
89 # define __ARM_ARCH__ 64
90 #endif
91 #if defined(__ARM_ARCH_6T2__)
92 # define __ARM_ARCH__ 65
93 #endif
94
95 #if defined(__ARM_ARCH_7__)
96 # define __ARM_ARCH__ 70
97 #endif
98 #if defined(__ARM_ARCH_7A__)
99 # define __ARM_ARCH__ 71
100 #endif
101 #if defined(__ARM_ARCH_7R__)
102 # define __ARM_ARCH__ 72
103 #endif
104 #if defined(__ARM_ARCH_7M__)
105 # define __ARM_ARCH__ 73
106 #endif
107
108 #if defined(__ARM_ARCH__) && (__ARM_ARCH__ >= 52)
109 /* tested on ARMv6 (arm1136j-s), Nokia N800 CPU */
110 #define pld(addr, off)                                                  \
111    __asm__("pld [%[address], %[offset]]"::                              \
112            [address] "r" (addr), [offset] "i" (off))
113 #else
114 #define pld(addr, off)
115 #endif /* __ARMEL__ */
116
117 static inline int
118 _calc_stride(int w)
119 {
120    int pad;
121
122    pad = w % 4;
123    if (!pad)  return w;
124    else return w + 4 - pad;
125 }
126
127 #define IMG_BYTE_SIZE(stride, height, has_alpha)                       \
128    ((stride) * (height) * (!(has_alpha) ? 1 : 2))
129
130 typedef struct _Soft8_Image Soft8_Image;
131 struct _Soft8_Image
132 {
133    Image_Entry    cache_entry;
134
135    RGBA_Image    *source;
136
137    int            stride;     // pixel stride
138    DATA8        *pixels;      // 8bpp pixels gry8
139    DATA8         *alpha;      // 8bit alpha mask - optional. points into pixels
140
141    void                *extended_info;
142
143    struct
144    {
145 /*      unsigned char  have_alpha  : 1; // 1 if we have halpha */
146      unsigned char  free_pixels : 1; // 1 if pixels should be freed
147      unsigned char  free_alpha  : 1; // 1 if alpha mask should be freed
148    } flags;
149 };
150
151 /**
152  * Image (evas_soft8_main.c)
153  */
154 EAPI void                evas_common_soft8_image_init(void);
155 EAPI void                evas_common_soft8_image_shutdown(void);
156 EAPI Evas_Cache_Image   *evas_common_soft8_image_cache_get(void);
157
158 EAPI void                soft8_image_draw(Soft8_Image *src, Soft8_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);
159 EAPI Soft8_Image       *soft8_image_alpha_set(Soft8_Image *im, int have_alpha);
160
161 void                     soft8_image_draw_unscaled(Soft8_Image *src, Soft8_Image *dst, RGBA_Draw_Context *dc, const Eina_Rectangle sr, const Eina_Rectangle dr, const Eina_Rectangle cr);
162 void                     soft8_image_draw_scaled_sampled(Soft8_Image *src, Soft8_Image *dst, RGBA_Draw_Context *dc, const Eina_Rectangle sr, const Eina_Rectangle dr, const Eina_Rectangle cr);
163
164 /* convert/dither functions */
165 void                     soft8_image_convert_from_rgb(Soft8_Image *im, const DATA32 *src);
166 void                     soft8_image_convert_from_rgba(Soft8_Image *im, const DATA32 *src);
167
168 /**
169  * Rectangle (evas_soft8_rectangle.c)
170  */
171 EAPI void                soft8_rectangle_draw(Soft8_Image *dst, RGBA_Draw_Context *dc, int x, int y, int w, int h);
172
173 /**
174  * Polygon (evas_soft8_polygon.c)
175  */
176 EAPI void                soft8_polygon_draw(Soft8_Image *dst, RGBA_Draw_Context *dc, RGBA_Polygon_Point *points, int x, int y);
177
178 /**
179  * Line (evas_soft8_line.c)
180  */
181 EAPI void                soft8_line_draw(Soft8_Image *dst, RGBA_Draw_Context *dc, int x0, int y0, int x1, int y1);
182
183 /**
184  * Font (evas_soft8_font.c)
185  */
186 EAPI void               *soft8_font_glyph_new(void *data, RGBA_Font_Glyph *fg);
187 EAPI void                soft8_font_glyph_free(void *ext_dat);
188 EAPI void                soft8_font_glyph_draw(void *data, void *dest, void *context, RGBA_Font_Glyph *fg, int x, int y);
189
190 #ifdef __cplusplus
191 }
192 #endif
193
194 #endif