Clean up structure, split into files.

SVN revision: 30413
This commit is contained in:
Gustavo Sverzut Barbieri 2007-06-20 19:10:15 +00:00
parent 2993abfb7d
commit ca8f71f595
7 changed files with 631 additions and 631 deletions

View File

@ -13,7 +13,8 @@ module_la_SOURCES = \
evas_engine.c \
evas_soft16.h \
evas_soft16_main.c \
evas_soft16_font.c
evas_soft16_font.c \
evas_soft16_rectangle.c
module_la_LIBADD = $(top_builddir)/src/lib/libevas.la
module_la_LDFLAGS = -module -avoid-version -L$(top_builddir)/src/lib -L$(top_builddir)/src/lib/.libs
@ -25,4 +26,8 @@ EXTRA_DIST = \
evas_engine.c \
evas_soft16.h \
evas_soft16_main.c \
evas_soft16_font.c
evas_soft16_font.c \
evas_soft16_rectangle.c \
evas_soft16_scanline_fill.c \
evas_soft16_scanline_blend.c

View File

@ -2,8 +2,8 @@
#define EVAS_SOFT16_H
#include "Evas.h"
#include "evas_private.h"
#include "evas_common.h"
#include "evas_private.h"
#define RGB_565_UNPACKED_MASK 0x07e0f81f
#define RGB_565_UNPACK(rgb) \
@ -35,7 +35,7 @@
#endif /* __ARMEL__ */
typedef struct _Soft16_Image Soft16_Image;
struct _Soft16_Image
{
const char *file; // file source - optional
@ -50,31 +50,31 @@ struct _Soft16_Image
RGBA_Image *source_im; // original source rgba image - if still reffed
Evas_Image_Load_Opts lo; // load options
unsigned char have_alpha : 1; // 1 if we have halpha
unsigned char free_pixels : 1; // 1 if pixels should be freed
unsigned char free_alpha : 1; // 1 if alpha mask should be freed
};
Soft16_Image *soft16_image_new(int w, int h, int stride, int have_alpha,
DATA16 *pixels, int copy);
/**
* Image (evas_soft16_main.c)
*/
Soft16_Image *soft16_image_new(int w, int h, int stride, int have_alpha, DATA16 *pixels, int copy);
void soft16_image_free(Soft16_Image *im);
Soft16_Image *soft16_image_load(const char *file, const char *key, int *error,
Evas_Image_Load_Opts *lo);
Soft16_Image *soft16_image_load(const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo);
void soft16_image_load_data(Soft16_Image *im);
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);
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);
/**
* Rectangle (evas_soft16_rectangle.c)
*/
void soft16_rectangle_draw(Soft16_Image *dst, RGBA_Draw_Context *dc,
int x, int y, int w, int h);
/**
* Font (evas_soft16_font.c)
*/
void *soft16_font_glyph_new(void *data, RGBA_Font_Glyph *fg);
void soft16_font_glyph_free(void *ext_dat);
void soft16_font_glyph_draw(Soft16_Image *dst, void *data, RGBA_Draw_Context *dc, RGBA_Font_Glyph *fg, int x, int y);

View File

@ -1,5 +1,3 @@
#include "evas_common.h"
#include "evas_private.h"
#include "evas_soft16.h"
static inline void

View File

@ -1,26 +1,9 @@
#include "evas_common.h"
#include "evas_private.h"
#include "evas_soft16.h"
#include "evas_soft16_scanline_blend.c"
#define IMG_BYTE_SIZE(stride, height, has_alpha) \
((stride) * (height) * (!(has_alpha) ? 2 : 3))
static inline void _soft16_scanline_blend_solid_solid(DATA16 *src, DATA16 *dst, int size);
static inline void _soft16_scanline_blend_transp_solid(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size);
static inline void _soft16_scanline_blend_solid_solid_mul_alpha(DATA16 *src, DATA16 *dst, int size, char rel_alpha);
static inline void _soft16_scanline_blend_transp_solid_mul_alpha(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size, char rel_alpha);
static inline void _soft16_scanline_blend_solid_solid_mul_color_transp(DATA16 *src, DATA16 *dst, int size, char rel_alpha, short r, short g, short b);
static inline void _soft16_scanline_blend_transp_solid_mul_color_transp(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size, char rel_alpha, short r, short g, short b);
static inline void _soft16_scanline_blend_solid_solid_mul_color_solid(DATA16 *src, DATA16 *dst, int size, short r, short g, short b);
static inline void _soft16_scanline_blend_transp_solid_mul_color_solid(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size, short r, short g, short b);
static inline void _soft16_scanline_fill_solid_solid(DATA16 *dst, int size, DATA16 rgb565);
static inline void _soft16_scanline_fill_transp_solid(DATA16 *dst, int size, DATA32 rgb565_unpack, char alpha);
static Evas_Hash *_soft16_image_cache_hash = NULL;
static inline int
@ -911,597 +894,3 @@ soft16_image_draw(Soft16_Image *src, Soft16_Image *dst,
dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
}
static inline void
_soft16_rectangle_draw_solid_solid(Soft16_Image *dst, RGBA_Draw_Context *dc,
int offset, int w, int h)
{
DATA16 *dst_itr, rgb565;
int i;
dst_itr = dst->pixels + offset;
rgb565 = RGB_565_FROM_COMPONENTS(R_VAL(&dc->col.col),
G_VAL(&dc->col.col),
B_VAL(&dc->col.col));
for (i = 0; i < h; i++, dst_itr += dst->stride)
_soft16_scanline_fill_solid_solid(dst_itr, w, rgb565);
}
static inline void
_soft16_rectangle_draw_transp_solid(Soft16_Image *dst, RGBA_Draw_Context *dc,
int offset, int w, int h)
{
char alpha;
alpha = A_VAL(&dc->col.col) >> 3;
if (alpha == 31) _soft16_rectangle_draw_solid_solid(dst, dc, offset, w, h);
else if (alpha != 0)
{
DATA16 *dst_itr;
DATA32 rgb565;
int i;
dst_itr = dst->pixels + offset;
rgb565 = RGB_565_FROM_COMPONENTS(R_VAL(&dc->col.col),
G_VAL(&dc->col.col),
B_VAL(&dc->col.col));
rgb565 = RGB_565_UNPACK(rgb565);
for (i = 0; i < h; i++, dst_itr += dst->stride)
_soft16_scanline_fill_transp_solid(dst_itr, w, rgb565, alpha);
}
}
static void
_soft16_rectangle_draw_int(Soft16_Image *dst, RGBA_Draw_Context *dc,
Evas_Rectangle dr)
{
int dst_offset;
if (_is_empty_rectangle(&dr)) return;
RECTS_CLIP_TO_RECT(dr.x, dr.y, dr.w, dr.h, 0, 0, dst->w, dst->h);
if (_is_empty_rectangle(&dr)) return;
if (dc->clip.use)
RECTS_CLIP_TO_RECT(dr.x, dr.y, dr.w, dr.h, dc->clip.x,
dc->clip.y, dc->clip.w, dc->clip.h);
if (_is_empty_rectangle(&dr)) return;
if (A_VAL(&dc->col.col) == 0) return;
dst_offset = dr.x + (dr.y * dst->w);
if (!dst->have_alpha)
{
if (A_VAL(&dc->col.col) == 255)
_soft16_rectangle_draw_solid_solid
(dst, dc, dst_offset, dr.w, dr.h);
else
_soft16_rectangle_draw_transp_solid
(dst, dc, dst_offset, dr.w, dr.h);
}
else
fprintf(stderr,
"Unsupported feature: drawing rectangle to non-opaque "
"destination.\n");
}
void
soft16_rectangle_draw(Soft16_Image *dst, RGBA_Draw_Context *dc,
int x, int y, int w, int h)
{
Evas_Rectangle dr;
Cutout_Rects *rects;
Cutout_Rect *r;
int c, cx, cy, cw, ch;
int i;
/* handle cutouts here! */
dr.x = x;
dr.y = y;
dr.w = w;
dr.h = h;
if (_is_empty_rectangle(&dr)) return;
if (!(RECTS_INTERSECT(dr.x, dr.y, dr.w, dr.h, 0, 0, dst->w, dst->h)))
return;
/* no cutouts - cut right to the chase */
if (!dc->cutout.rects)
{
_soft16_rectangle_draw_int(dst, dc, dr);
return;
}
/* save out clip info */
c = dc->clip.use; cx = dc->clip.x; cy = dc->clip.y; cw = dc->clip.w; ch = dc->clip.h;
evas_common_draw_context_clip_clip(dc, 0, 0, dst->w, dst->h);
evas_common_draw_context_clip_clip(dc, x, y, w, h);
/* our clip is 0 size.. abort */
if ((dc->clip.w <= 0) || (dc->clip.h <= 0))
{
dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
return;
}
rects = evas_common_draw_context_apply_cutouts(dc);
for (i = 0; i < rects->active; ++i)
{
r = rects->rects + i;
evas_common_draw_context_set_clip(dc, r->x, r->y, r->w, r->h);
_soft16_rectangle_draw_int(dst, dc, dr);
}
evas_common_draw_context_apply_clear_cutouts(rects);
/* restore clip info */
dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
}
/*****************************************************************************
* Scanline processing
*
* _soft16_scanline_<description>_<src>_<dst>[_<modifier>]()
*
****************************************************************************/
/***********************************************************************
* fill operations
*/
static inline void
_soft16_scanline_fill_solid_solid(DATA16 *dst, int size, DATA16 rgb565)
{
DATA16 *start, *end;
DATA32 rgb565_double;
start = dst;
end = start + (size & ~7);
rgb565_double = (rgb565 << 16) | rgb565;
while (start < end)
{
DATA32 *p = (DATA32 *)start;
p[0] = rgb565_double;
p[1] = rgb565_double;
p[2] = rgb565_double;
p[3] = rgb565_double;
start += 8;
}
end = start + (size & 7);
for (; start < end; start++)
*start = rgb565;
}
static inline void
_soft16_scanline_fill_transp_solid(DATA16 *dst, int size, DATA32 rgb565_unpack, char alpha)
{
DATA16 *start, *end;
DATA32 a;
start = dst;
pld(start, 0);
end = start + (size & ~7);
#define BLEND(dst) \
{ DATA32 b; \
b = RGB_565_UNPACK(dst); \
b = RGB_565_UNPACKED_BLEND(rgb565_unpack, b, alpha); \
dst = RGB_565_PACK(b); }
while (start < end)
{
pld(start, 32);
UNROLL8({
BLEND(*start);
start++;
});
}
end = start + (size & 7);
for (; start < end; start++)
BLEND(*start);
#undef BLEND
}
/***********************************************************************
* Regular blend operations
*/
static inline void
_soft16_scanline_blend_transp_solid(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(alpha, 0);
pld(src, 0);
#define BLEND(dst, src, alpha) \
if (UNLIKELY(alpha == 31)) \
(dst) = (src); \
else if (alpha != 0) \
{ \
DATA32 a, b; \
a = RGB_565_UNPACK(src); \
b = RGB_565_UNPACK(dst); \
b = RGB_565_UNPACKED_BLEND(a, b, alpha); \
dst = RGB_565_PACK(b); \
}
/* work on 8 pixels per time, do data preload */
while (start < end)
{
DATA8 alpha1, alpha2;
alpha1 = alpha[0];
alpha += 8;
/* empirical tests show these give the best performance */
pld(alpha, 8);
pld(src, 32);
src += 8;
start += 8;
alpha2 = alpha[-7];
BLEND(start[-8], src[-8], alpha1);
alpha1 = alpha[-6];
BLEND(start[-7], src[-7], alpha2);
alpha2 = alpha[-5];
BLEND(start[-6], src[-6], alpha1);
alpha1 = alpha[-4];
BLEND(start[-5], src[-5], alpha2);
alpha2 = alpha[-3];
BLEND(start[-4], src[-4], alpha1);
alpha1 = alpha[-2];
BLEND(start[-3], src[-3], alpha2);
alpha2 = alpha[-1];
BLEND(start[-2], src[-2], alpha1);
BLEND(start[-1], src[-1], alpha2);
}
/* remaining pixels (up to 7) */
end = start + (size & 7);
for (; start < end; start++, src++, alpha++)
BLEND(*start, *src, *alpha);
#undef BLEND
}
static inline void
_soft16_scanline_blend_solid_solid(DATA16 *src, DATA16 *dst, int size)
{
memcpy(dst, src, size * sizeof(DATA16));
}
/***********************************************************************
* Blend operations taking an extra alpha (fade in, out)
*/
static inline void _soft16_scanline_blend_transp_solid_mul_alpha(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size, char rel_alpha)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(alpha, 0);
pld(src, 0);
#define BLEND(dst, src, alpha) \
if (alpha > rel_alpha) \
{ \
DATA32 a, b; \
a = RGB_565_UNPACK(src); \
b = RGB_565_UNPACK(dst); \
b = RGB_565_UNPACKED_BLEND(a, b, alpha - rel_alpha); \
dst = RGB_565_PACK(b); \
}
while (start < end)
{
DATA8 alpha1, alpha2;
alpha1 = alpha[0];
alpha += 8;
pld(alpha, 8);
pld(src, 32);
src += 8;
start += 8;
alpha2 = alpha[-7];
BLEND(start[-8], src[-8], alpha1);
alpha1 = alpha[-6];
BLEND(start[-7], src[-7], alpha2);
alpha2 = alpha[-5];
BLEND(start[-6], src[-6], alpha1);
alpha1 = alpha[-4];
BLEND(start[-5], src[-5], alpha2);
alpha2 = alpha[-3];
BLEND(start[-4], src[-4], alpha1);
alpha1 = alpha[-2];
BLEND(start[-3], src[-3], alpha2);
alpha2 = alpha[-1];
BLEND(start[-2], src[-2], alpha1);
BLEND(start[-1], src[-1], alpha2);
}
end = start + (size & 7);
for (; start < end; start++, src++, alpha++)
BLEND(*start, *src, *alpha);
#undef BLEND
}
static inline void
_soft16_scanline_blend_solid_solid_mul_alpha(DATA16 *src, DATA16 *dst, int size, char rel_alpha)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(src, 0);
#define BLEND(dst, src) \
{ \
DATA32 a, b; \
a = RGB_565_UNPACK(src); \
b = RGB_565_UNPACK(dst); \
b = RGB_565_UNPACKED_BLEND(a, b, rel_alpha); \
dst = RGB_565_PACK(b); \
}
while (start < end)
{
pld(src, 32);
UNROLL8({
BLEND(*start, *src);
start++;
src++;
});
}
end = start + (size & 7);
for (; start < end; start++, src++)
BLEND(*start, *src);
#undef BLEND
}
/***********************************************************************
* Blend operations with extra alpha and multiply color
*/
static inline void _soft16_scanline_blend_transp_solid_mul_color_transp(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size, char rel_alpha, short r, short g, short b)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(alpha, 0);
pld(src, 0);
/* rel_alpha is always > 0, so (alpha - rel_alpha) is always < 31 */
#define BLEND(dst, src, alpha) \
if ((alpha) > rel_alpha) \
{ \
short r1, g1, b1; \
int rgb, d; \
r1 = ((((src) >> 11) & 0x1f) * r) >> 8; \
g1 = ((((src) >> 5) & 0x3f) * g) >> 8; \
b1 = (((src) & 0x1f) * b) >> 8; \
rgb = ((r1 << 11) | (g1 << 21) | b1) & RGB_565_UNPACKED_MASK; \
d = RGB_565_UNPACK(dst); \
d = RGB_565_UNPACKED_BLEND(rgb, d, alpha - rel_alpha); \
dst = RGB_565_PACK(d); \
}
while (start < end)
{
DATA8 alpha1, alpha2;
alpha1 = alpha[0];
alpha += 8;
pld(src, 32);
pld(start, 32);
src += 8;
start += 8;
alpha2 = alpha[-7];
BLEND(start[-8], src[-8], alpha1);
alpha1 = alpha[-6];
BLEND(start[-7], src[-7], alpha2);
alpha2 = alpha[-5];
BLEND(start[-6], src[-6], alpha1);
alpha1 = alpha[-4];
BLEND(start[-5], src[-5], alpha2);
alpha2 = alpha[-3];
BLEND(start[-4], src[-4], alpha1);
alpha1 = alpha[-2];
BLEND(start[-3], src[-3], alpha2);
alpha2 = alpha[-1];
BLEND(start[-2], src[-2], alpha1);
BLEND(start[-1], src[-1], alpha2);
}
end = start + (size & 7);
for (; start < end; start++, src++, alpha++)
BLEND(*start, *src, *alpha);
#undef BLEND
}
static inline void
_soft16_scanline_blend_solid_solid_mul_color_transp(DATA16 *src, DATA16 *dst, int size, char rel_alpha, short r, short g, short b)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(src, 0);
#define BLEND(dst, src) \
{ \
short r1, g1, b1; \
int rgb, d; \
r1 = ((((src) >> 11) & 0x1f) * r) >> 8; \
g1 = ((((src) >> 5) & 0x3f) * g) >> 8; \
b1 = (((src) & 0x1f) * b) >> 8; \
rgb = ((r1 << 11) | (g1 << 21) | b1) & RGB_565_UNPACKED_MASK; \
d = RGB_565_UNPACK(dst); \
d = RGB_565_UNPACKED_BLEND(rgb, d, rel_alpha); \
dst = RGB_565_PACK(d); \
}
while (start < end)
{
pld(src, 32);
UNROLL8({
BLEND(*start, *src);
start++;
src++;
});
}
end = start + (size & 7);
for (; start < end; start++, src++)
BLEND(*start, *src);
#undef BLEND
}
/***********************************************************************
* Blend operations with extra multiply color
*/
static inline void _soft16_scanline_blend_transp_solid_mul_color_solid(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size, short r, short g, short b)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(alpha, 0);
pld(src, 0);
#define BLEND(dst, src, alpha) \
if (UNLIKELY(alpha == 31)) \
{ \
short r1, g1, b1; \
r1 = (((((src) >> 11) & 0x1f) * r) >> 8) & 0x1f; \
g1 = (((((src) >> 5) & 0x3f) * g) >> 8) & 0x3f; \
b1 = ((((src) & 0x1f) * b) >> 8) & 0x1f; \
dst = ((r1 << 11) | (g1 << 5) | b1); \
} \
else if (alpha != 0) \
{ \
short r1, g1, b1; \
int rgb, d; \
r1 = ((((src) >> 11) & 0x1f) * r) >> 8; \
g1 = ((((src) >> 5) & 0x3f) * g) >> 8; \
b1 = (((src) & 0x1f) * b) >> 8; \
rgb = ((r1 << 11) | (g1 << 21) | b1) & RGB_565_UNPACKED_MASK; \
d = RGB_565_UNPACK(dst); \
d = RGB_565_UNPACKED_BLEND(rgb, d, alpha); \
dst = RGB_565_PACK(d); \
}
while (start < end)
{
DATA8 alpha1, alpha2;
alpha1 = alpha[0];
alpha += 8;
pld(alpha, 8);
pld(src, 32);
src += 8;
start += 8;
alpha2 = alpha[-7];
BLEND(start[-8], src[-8], alpha1);
alpha1 = alpha[-6];
BLEND(start[-7], src[-7], alpha2);
alpha2 = alpha[-5];
BLEND(start[-6], src[-6], alpha1);
alpha1 = alpha[-4];
BLEND(start[-5], src[-5], alpha2);
alpha2 = alpha[-3];
BLEND(start[-4], src[-4], alpha1);
alpha1 = alpha[-2];
BLEND(start[-3], src[-3], alpha2);
alpha2 = alpha[-1];
BLEND(start[-2], src[-2], alpha1);
BLEND(start[-1], src[-1], alpha2);
}
end = start + (size & 7);
for (; start < end; start++, src++, alpha++)
BLEND(*start, *src, *alpha);
#undef BLEND
}
static inline void
_soft16_scanline_blend_solid_solid_mul_color_solid(DATA16 *src, DATA16 *dst, int size, short r, short g, short b)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(src, 0);
#define BLEND(dst, src) \
{ \
short r1, g1, b1; \
r1 = (((((src) >> 11) & 0x1f) * r) >> 8) & 0x1f; \
g1 = (((((src) >> 5) & 0x3f) * g) >> 8) & 0x3f; \
b1 = ((((src) & 0x1f) * b) >> 8) & 0x1f; \
dst = ((r1 << 11) | (g1 << 5) | b1); \
}
while (start < end)
{
pld(src, 32);
UNROLL8({
BLEND(*start, *src);
start++;
src++;
});
}
end = start + (size & 7);
for (; start < end; start++, src++)
BLEND(*start, *src);
#undef BLEND
}

View File

@ -0,0 +1,132 @@
#include "evas_soft16.h"
#include "evas_soft16_scanline_fill.c"
static inline int
_is_empty_rectangle(const Evas_Rectangle *r)
{
return (r->w < 1) || (r->h < 1);
}
static inline void
_soft16_rectangle_draw_solid_solid(Soft16_Image *dst, RGBA_Draw_Context *dc,
int offset, int w, int h)
{
DATA16 *dst_itr, rgb565;
int i;
dst_itr = dst->pixels + offset;
rgb565 = RGB_565_FROM_COMPONENTS(R_VAL(&dc->col.col),
G_VAL(&dc->col.col),
B_VAL(&dc->col.col));
for (i = 0; i < h; i++, dst_itr += dst->stride)
_soft16_scanline_fill_solid_solid(dst_itr, w, rgb565);
}
static inline void
_soft16_rectangle_draw_transp_solid(Soft16_Image *dst, RGBA_Draw_Context *dc,
int offset, int w, int h)
{
char alpha;
alpha = A_VAL(&dc->col.col) >> 3;
if (alpha == 31) _soft16_rectangle_draw_solid_solid(dst, dc, offset, w, h);
else if (alpha != 0)
{
DATA16 *dst_itr;
DATA32 rgb565;
int i;
dst_itr = dst->pixels + offset;
rgb565 = RGB_565_FROM_COMPONENTS(R_VAL(&dc->col.col),
G_VAL(&dc->col.col),
B_VAL(&dc->col.col));
rgb565 = RGB_565_UNPACK(rgb565);
for (i = 0; i < h; i++, dst_itr += dst->stride)
_soft16_scanline_fill_transp_solid(dst_itr, w, rgb565, alpha);
}
}
static void
_soft16_rectangle_draw_int(Soft16_Image *dst, RGBA_Draw_Context *dc,
Evas_Rectangle dr)
{
int dst_offset;
if (_is_empty_rectangle(&dr)) return;
RECTS_CLIP_TO_RECT(dr.x, dr.y, dr.w, dr.h, 0, 0, dst->w, dst->h);
if (_is_empty_rectangle(&dr)) return;
if (dc->clip.use)
RECTS_CLIP_TO_RECT(dr.x, dr.y, dr.w, dr.h, dc->clip.x,
dc->clip.y, dc->clip.w, dc->clip.h);
if (_is_empty_rectangle(&dr)) return;
if (A_VAL(&dc->col.col) == 0) return;
dst_offset = dr.x + (dr.y * dst->w);
if (!dst->have_alpha)
{
if (A_VAL(&dc->col.col) == 255)
_soft16_rectangle_draw_solid_solid
(dst, dc, dst_offset, dr.w, dr.h);
else
_soft16_rectangle_draw_transp_solid
(dst, dc, dst_offset, dr.w, dr.h);
}
else
fprintf(stderr,
"Unsupported feature: drawing rectangle to non-opaque "
"destination.\n");
}
void
soft16_rectangle_draw(Soft16_Image *dst, RGBA_Draw_Context *dc,
int x, int y, int w, int h)
{
Evas_Rectangle dr;
Cutout_Rects *rects;
Cutout_Rect *r;
int c, cx, cy, cw, ch;
int i;
/* handle cutouts here! */
dr.x = x;
dr.y = y;
dr.w = w;
dr.h = h;
if (_is_empty_rectangle(&dr)) return;
if (!(RECTS_INTERSECT(dr.x, dr.y, dr.w, dr.h, 0, 0, dst->w, dst->h)))
return;
/* no cutouts - cut right to the chase */
if (!dc->cutout.rects)
{
_soft16_rectangle_draw_int(dst, dc, dr);
return;
}
/* save out clip info */
c = dc->clip.use; cx = dc->clip.x; cy = dc->clip.y; cw = dc->clip.w; ch = dc->clip.h;
evas_common_draw_context_clip_clip(dc, 0, 0, dst->w, dst->h);
evas_common_draw_context_clip_clip(dc, x, y, w, h);
/* our clip is 0 size.. abort */
if ((dc->clip.w <= 0) || (dc->clip.h <= 0))
{
dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
return;
}
rects = evas_common_draw_context_apply_cutouts(dc);
for (i = 0; i < rects->active; ++i)
{
r = rects->rects + i;
evas_common_draw_context_set_clip(dc, r->x, r->y, r->w, r->h);
_soft16_rectangle_draw_int(dst, dc, dr);
}
evas_common_draw_context_apply_clear_cutouts(rects);
/* restore clip info */
dc->clip.use = c; dc->clip.x = cx; dc->clip.y = cy; dc->clip.w = cw; dc->clip.h = ch;
}

View File

@ -0,0 +1,410 @@
/** NOTE: This file is meant to be included by users **/
/*****************************************************************************
* Scanline processing
*
* _soft16_scanline_<description>_<src>_<dst>[_<modifier>]()
*
****************************************************************************/
/***********************************************************************
* Regular blend operations
*/
static inline void
_soft16_scanline_blend_transp_solid(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(alpha, 0);
pld(src, 0);
#define BLEND(dst, src, alpha) \
if (UNLIKELY(alpha == 31)) \
(dst) = (src); \
else if (alpha != 0) \
{ \
DATA32 a, b; \
a = RGB_565_UNPACK(src); \
b = RGB_565_UNPACK(dst); \
b = RGB_565_UNPACKED_BLEND(a, b, alpha); \
dst = RGB_565_PACK(b); \
}
/* work on 8 pixels per time, do data preload */
while (start < end)
{
DATA8 alpha1, alpha2;
alpha1 = alpha[0];
alpha += 8;
/* empirical tests show these give the best performance */
pld(alpha, 8);
pld(src, 32);
src += 8;
start += 8;
alpha2 = alpha[-7];
BLEND(start[-8], src[-8], alpha1);
alpha1 = alpha[-6];
BLEND(start[-7], src[-7], alpha2);
alpha2 = alpha[-5];
BLEND(start[-6], src[-6], alpha1);
alpha1 = alpha[-4];
BLEND(start[-5], src[-5], alpha2);
alpha2 = alpha[-3];
BLEND(start[-4], src[-4], alpha1);
alpha1 = alpha[-2];
BLEND(start[-3], src[-3], alpha2);
alpha2 = alpha[-1];
BLEND(start[-2], src[-2], alpha1);
BLEND(start[-1], src[-1], alpha2);
}
/* remaining pixels (up to 7) */
end = start + (size & 7);
for (; start < end; start++, src++, alpha++)
BLEND(*start, *src, *alpha);
#undef BLEND
}
static inline void
_soft16_scanline_blend_solid_solid(DATA16 *src, DATA16 *dst, int size)
{
memcpy(dst, src, size * sizeof(DATA16));
}
/***********************************************************************
* Blend operations taking an extra alpha (fade in, out)
*/
static inline void _soft16_scanline_blend_transp_solid_mul_alpha(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size, char rel_alpha)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(alpha, 0);
pld(src, 0);
#define BLEND(dst, src, alpha) \
if (alpha > rel_alpha) \
{ \
DATA32 a, b; \
a = RGB_565_UNPACK(src); \
b = RGB_565_UNPACK(dst); \
b = RGB_565_UNPACKED_BLEND(a, b, alpha - rel_alpha); \
dst = RGB_565_PACK(b); \
}
while (start < end)
{
DATA8 alpha1, alpha2;
alpha1 = alpha[0];
alpha += 8;
pld(alpha, 8);
pld(src, 32);
src += 8;
start += 8;
alpha2 = alpha[-7];
BLEND(start[-8], src[-8], alpha1);
alpha1 = alpha[-6];
BLEND(start[-7], src[-7], alpha2);
alpha2 = alpha[-5];
BLEND(start[-6], src[-6], alpha1);
alpha1 = alpha[-4];
BLEND(start[-5], src[-5], alpha2);
alpha2 = alpha[-3];
BLEND(start[-4], src[-4], alpha1);
alpha1 = alpha[-2];
BLEND(start[-3], src[-3], alpha2);
alpha2 = alpha[-1];
BLEND(start[-2], src[-2], alpha1);
BLEND(start[-1], src[-1], alpha2);
}
end = start + (size & 7);
for (; start < end; start++, src++, alpha++)
BLEND(*start, *src, *alpha);
#undef BLEND
}
static inline void
_soft16_scanline_blend_solid_solid_mul_alpha(DATA16 *src, DATA16 *dst, int size, char rel_alpha)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(src, 0);
#define BLEND(dst, src) \
{ \
DATA32 a, b; \
a = RGB_565_UNPACK(src); \
b = RGB_565_UNPACK(dst); \
b = RGB_565_UNPACKED_BLEND(a, b, rel_alpha); \
dst = RGB_565_PACK(b); \
}
while (start < end)
{
pld(src, 32);
UNROLL8({
BLEND(*start, *src);
start++;
src++;
});
}
end = start + (size & 7);
for (; start < end; start++, src++)
BLEND(*start, *src);
#undef BLEND
}
/***********************************************************************
* Blend operations with extra alpha and multiply color
*/
static inline void _soft16_scanline_blend_transp_solid_mul_color_transp(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size, char rel_alpha, short r, short g, short b)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(alpha, 0);
pld(src, 0);
/* rel_alpha is always > 0, so (alpha - rel_alpha) is always < 31 */
#define BLEND(dst, src, alpha) \
if ((alpha) > rel_alpha) \
{ \
short r1, g1, b1; \
int rgb, d; \
r1 = ((((src) >> 11) & 0x1f) * r) >> 8; \
g1 = ((((src) >> 5) & 0x3f) * g) >> 8; \
b1 = (((src) & 0x1f) * b) >> 8; \
rgb = ((r1 << 11) | (g1 << 21) | b1) & RGB_565_UNPACKED_MASK; \
d = RGB_565_UNPACK(dst); \
d = RGB_565_UNPACKED_BLEND(rgb, d, alpha - rel_alpha); \
dst = RGB_565_PACK(d); \
}
while (start < end)
{
DATA8 alpha1, alpha2;
alpha1 = alpha[0];
alpha += 8;
pld(src, 32);
pld(start, 32);
src += 8;
start += 8;
alpha2 = alpha[-7];
BLEND(start[-8], src[-8], alpha1);
alpha1 = alpha[-6];
BLEND(start[-7], src[-7], alpha2);
alpha2 = alpha[-5];
BLEND(start[-6], src[-6], alpha1);
alpha1 = alpha[-4];
BLEND(start[-5], src[-5], alpha2);
alpha2 = alpha[-3];
BLEND(start[-4], src[-4], alpha1);
alpha1 = alpha[-2];
BLEND(start[-3], src[-3], alpha2);
alpha2 = alpha[-1];
BLEND(start[-2], src[-2], alpha1);
BLEND(start[-1], src[-1], alpha2);
}
end = start + (size & 7);
for (; start < end; start++, src++, alpha++)
BLEND(*start, *src, *alpha);
#undef BLEND
}
static inline void
_soft16_scanline_blend_solid_solid_mul_color_transp(DATA16 *src, DATA16 *dst, int size, char rel_alpha, short r, short g, short b)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(src, 0);
#define BLEND(dst, src) \
{ \
short r1, g1, b1; \
int rgb, d; \
r1 = ((((src) >> 11) & 0x1f) * r) >> 8; \
g1 = ((((src) >> 5) & 0x3f) * g) >> 8; \
b1 = (((src) & 0x1f) * b) >> 8; \
rgb = ((r1 << 11) | (g1 << 21) | b1) & RGB_565_UNPACKED_MASK; \
d = RGB_565_UNPACK(dst); \
d = RGB_565_UNPACKED_BLEND(rgb, d, rel_alpha); \
dst = RGB_565_PACK(d); \
}
while (start < end)
{
pld(src, 32);
UNROLL8({
BLEND(*start, *src);
start++;
src++;
});
}
end = start + (size & 7);
for (; start < end; start++, src++)
BLEND(*start, *src);
#undef BLEND
}
/***********************************************************************
* Blend operations with extra multiply color
*/
static inline void _soft16_scanline_blend_transp_solid_mul_color_solid(DATA16 *src, DATA8 *alpha, DATA16 *dst, int size, short r, short g, short b)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(alpha, 0);
pld(src, 0);
#define BLEND(dst, src, alpha) \
if (UNLIKELY(alpha == 31)) \
{ \
short r1, g1, b1; \
r1 = (((((src) >> 11) & 0x1f) * r) >> 8) & 0x1f; \
g1 = (((((src) >> 5) & 0x3f) * g) >> 8) & 0x3f; \
b1 = ((((src) & 0x1f) * b) >> 8) & 0x1f; \
dst = ((r1 << 11) | (g1 << 5) | b1); \
} \
else if (alpha != 0) \
{ \
short r1, g1, b1; \
int rgb, d; \
r1 = ((((src) >> 11) & 0x1f) * r) >> 8; \
g1 = ((((src) >> 5) & 0x3f) * g) >> 8; \
b1 = (((src) & 0x1f) * b) >> 8; \
rgb = ((r1 << 11) | (g1 << 21) | b1) & RGB_565_UNPACKED_MASK; \
d = RGB_565_UNPACK(dst); \
d = RGB_565_UNPACKED_BLEND(rgb, d, alpha); \
dst = RGB_565_PACK(d); \
}
while (start < end)
{
DATA8 alpha1, alpha2;
alpha1 = alpha[0];
alpha += 8;
pld(alpha, 8);
pld(src, 32);
src += 8;
start += 8;
alpha2 = alpha[-7];
BLEND(start[-8], src[-8], alpha1);
alpha1 = alpha[-6];
BLEND(start[-7], src[-7], alpha2);
alpha2 = alpha[-5];
BLEND(start[-6], src[-6], alpha1);
alpha1 = alpha[-4];
BLEND(start[-5], src[-5], alpha2);
alpha2 = alpha[-3];
BLEND(start[-4], src[-4], alpha1);
alpha1 = alpha[-2];
BLEND(start[-3], src[-3], alpha2);
alpha2 = alpha[-1];
BLEND(start[-2], src[-2], alpha1);
BLEND(start[-1], src[-1], alpha2);
}
end = start + (size & 7);
for (; start < end; start++, src++, alpha++)
BLEND(*start, *src, *alpha);
#undef BLEND
}
static inline void
_soft16_scanline_blend_solid_solid_mul_color_solid(DATA16 *src, DATA16 *dst, int size, short r, short g, short b)
{
DATA16 *start, *end;
start = dst;
end = start + (size & ~7);
pld(src, 0);
#define BLEND(dst, src) \
{ \
short r1, g1, b1; \
r1 = (((((src) >> 11) & 0x1f) * r) >> 8) & 0x1f; \
g1 = (((((src) >> 5) & 0x3f) * g) >> 8) & 0x3f; \
b1 = ((((src) & 0x1f) * b) >> 8) & 0x1f; \
dst = ((r1 << 11) | (g1 << 5) | b1); \
}
while (start < end)
{
pld(src, 32);
UNROLL8({
BLEND(*start, *src);
start++;
src++;
});
}
end = start + (size & 7);
for (; start < end; start++, src++)
BLEND(*start, *src);
#undef BLEND
}

View File

@ -0,0 +1,66 @@
/** NOTE: This file is meant to be included by users **/
/*****************************************************************************
* Scanline processing
*
* _soft16_scanline_<description>_<src>_<dst>[_<modifier>]()
*
****************************************************************************/
static inline void
_soft16_scanline_fill_solid_solid(DATA16 *dst, int size, DATA16 rgb565)
{
DATA16 *start, *end;
DATA32 rgb565_double;
start = dst;
end = start + (size & ~7);
rgb565_double = (rgb565 << 16) | rgb565;
while (start < end)
{
DATA32 *p = (DATA32 *)start;
p[0] = rgb565_double;
p[1] = rgb565_double;
p[2] = rgb565_double;
p[3] = rgb565_double;
start += 8;
}
end = start + (size & 7);
for (; start < end; start++)
*start = rgb565;
}
static inline void
_soft16_scanline_fill_transp_solid(DATA16 *dst, int size, DATA32 rgb565_unpack, char alpha)
{
DATA16 *start, *end;
DATA32 a;
start = dst;
pld(start, 0);
end = start + (size & ~7);
#define BLEND(dst) \
{ DATA32 b; \
b = RGB_565_UNPACK(dst); \
b = RGB_565_UNPACKED_BLEND(rgb565_unpack, b, alpha); \
dst = RGB_565_PACK(b); }
while (start < end)
{
pld(start, 32);
UNROLL8({
BLEND(*start);
start++;
});
}
end = start + (size & 7);
for (; start < end; start++)
BLEND(*start);
#undef BLEND
}