1 #include "evas_common_soft16.h"
2 #include "evas_soft16_scanline_blend.c"
4 static always_inline void
5 _glyph_pt_mask_solid_solid(DATA16 *dst,
7 const DATA32 rgb565_unpack,
10 DATA8 alpha = *mask >> 3;
12 if (alpha == 31) *dst = rgb565;
17 d = RGB_565_UNPACK(*dst);
18 d = RGB_565_UNPACKED_BLEND_UNMUL(rgb565_unpack, d, alpha);
19 *dst = RGB_565_PACK(d);
24 _glyph_scanline_mask_solid_solid(DATA16 *dst,
27 const DATA32 rgb565_unpack,
35 end = start + (size & ~3);
42 _glyph_pt_mask_solid_solid(start, rgb565, rgb565_unpack, mask);
48 end = start + (size & 3);
49 for (; start < end; start++, mask++)
50 _glyph_pt_mask_solid_solid(start, rgb565, rgb565_unpack, mask);
53 static always_inline void
54 _glyph_pt_mask_transp_solid(DATA16 *dst,
62 rel_alpha = *mask >> 3;
63 alpha = (alpha * rel_alpha) >> 5;
69 a = ((rgb565_unpack * rel_alpha) >> 5) & RGB_565_UNPACKED_MASK;
70 b = RGB_565_UNPACK(*dst);
71 b = RGB_565_UNPACKED_BLEND(a, b, alpha);
72 *dst = RGB_565_PACK(b);
76 _glyph_scanline_mask_transp_solid(DATA16 *dst,
78 const DATA32 rgb565_unpack,
79 const DATA8 rel_alpha,
87 end = start + (size & ~3);
94 _glyph_pt_mask_transp_solid(start, rgb565_unpack, rel_alpha, mask);
100 end = start + (size & 3);
101 for (; start < end; start++, mask++)
102 _glyph_pt_mask_transp_solid(start, rgb565_unpack, rel_alpha, mask);
106 _calc_ext(const Soft16_Image *dst, const RGBA_Draw_Context *dc,
111 ext->w = dst->cache_entry.w;
112 ext->h = dst->cache_entry.h;
133 v = dst->cache_entry.w - ext->x;
134 if (ext->w > v) ext->w = v;
136 v = dst->cache_entry.h - ext->y;
137 if (ext->h > v) ext->h = v;
142 _glyph_scanline(Soft16_Image *dst, const DATA8 *p_mask,
143 const Evas_Rectangle ext, int dx, int dy, int max_x, int max_y,
144 int w, DATA8 alpha, const DATA16 rgb565,
145 const DATA32 rgb565_unpack)
147 int size, in_x, in_w;
150 if ((dx >= max_x) || (dy < ext.y) || (dy >= max_y)) return;
155 if (dx + w > max_x) in_w += (dx + w) - max_x;
165 p_pixels = dst->pixels + (dy * dst->stride) + dx;
171 _glyph_scanline_mask_solid_solid
172 (p_pixels, size, rgb565, rgb565_unpack, p_mask);
174 _glyph_scanline_mask_transp_solid
175 (p_pixels, size, rgb565_unpack, alpha, p_mask);
180 _glyph_pt_mask_solid_solid(p_pixels, rgb565, rgb565_unpack, p_mask);
182 _glyph_pt_mask_transp_solid(p_pixels, rgb565_unpack, alpha, p_mask);
187 _soft16_font_glyph_draw_grayscale(Soft16_Image *dst,
188 RGBA_Draw_Context *dc, RGBA_Font_Glyph *fg,
189 int x, int y, DATA8 alpha, DATA16 rgb565,
190 const Evas_Rectangle ext, int bw, int bh,
191 int bpitch, const DATA8 *bitmap)
193 const DATA32 rgb565_unpack = RGB_565_UNPACK(rgb565);
196 max_x = ext.x + ext.w;
197 max_y = ext.y + ext.h;
199 for (i = 0; i < bh; i++, bitmap += bpitch)
200 _glyph_scanline(dst, bitmap, ext, x, y + i, max_x, max_y, bw,
201 alpha, rgb565, rgb565_unpack);
205 _glyph_create_mask_line(DATA8 *mask, const DATA8 *bitmap, int w)
207 const DATA8 bitrepl[2] = {0x0, 0xff};
210 for (i = 0; i < w; i += 8, bitmap++)
215 if (i + 8 < w) size = 8;
220 for (j = size - 1; j >= 0; j--, mask++)
221 *mask = bitrepl[(bits >> j) & 0x1];
226 _soft16_font_glyph_draw_mono(Soft16_Image *dst,
227 RGBA_Draw_Context *dc, RGBA_Font_Glyph *fg,
228 int x, int y, DATA8 alpha, DATA16 rgb565,
229 const Evas_Rectangle ext, int bw, int bh,
230 int bpitch, const DATA8 *bitmap)
232 const DATA32 rgb565_unpack = RGB_565_UNPACK(rgb565);
236 max_x = ext.x + ext.w;
237 max_y = ext.y + ext.h;
239 mask = alloca(bpitch);
240 for (i = 0; i < bh; i++, bitmap += bpitch)
242 _glyph_create_mask_line(mask, bitmap, bw);
243 _glyph_scanline(dst, mask, ext, x, y + i, max_x, max_y, bw,
244 alpha, rgb565, rgb565_unpack);
249 soft16_font_glyph_draw(void *data, void *dest, void *context,
250 RGBA_Font_Glyph *fg, int x, int y)
253 RGBA_Draw_Context *dc;
255 DATA8 alpha, r, g, b;
263 alpha = A_VAL(&dc->col.col) >> 3;
264 if (alpha == 0) return; /* precision is 5 bits, 3 bits lost */
266 r = R_VAL(&dc->col.col) >> 3;
267 g = G_VAL(&dc->col.col) >> 2;
268 b = B_VAL(&dc->col.col) >> 3;
270 if (r > alpha) r = alpha;
271 if (g > (alpha << 1)) g = (alpha << 1);
272 if (b > alpha) b = alpha;
274 rgb565 = (r << 11) | (g << 5) | b;
276 bitmap = fg->glyph_out->bitmap.buffer;
277 bh = fg->glyph_out->bitmap.rows;
278 bw = fg->glyph_out->bitmap.width;
279 bpitch = fg->glyph_out->bitmap.pitch;
280 if (bpitch < bw) bpitch = bw;
282 _calc_ext(dst, dc, &ext);
284 if ((fg->glyph_out->bitmap.num_grays == 256) &&
285 (fg->glyph_out->bitmap.pixel_mode == ft_pixel_mode_grays))
286 _soft16_font_glyph_draw_grayscale(dst, dc, fg, x, y, alpha, rgb565,
287 ext, bw, bh, bpitch, bitmap);
289 _soft16_font_glyph_draw_mono(dst, dc, fg, x, y, alpha, rgb565,
290 ext, bw, bh, bpitch, bitmap);
294 soft16_font_glyph_new(void *data, RGBA_Font_Glyph *fg)
296 return (void *)1; /* core requires != NULL to work */
300 soft16_font_glyph_free(void *ext_dat)