Evas: Move alpha functions to static_libs/draw

This is a pretty simple code refactor, moving pixel handling
to the new draw lib.
This commit is contained in:
Jean-Philippe Andre 2015-12-03 15:29:32 +09:00
parent 4bcea3eada
commit b5500a8644
9 changed files with 74 additions and 94 deletions

View File

@ -259,6 +259,10 @@ lib/evas/canvas/evas_vg_gradient_radial.c \
lib/evas/canvas/evas_vg_utils.c \
lib/evas/canvas/evas_vg_shape.c
# Static draw lib
lib_evas_libevas_la_SOURCES += \
static_libs/draw/draw_alpha_main.c
# Engine
lib_evas_libevas_la_SOURCES += \
lib/evas/common/evas_op_copy_main_.c \
@ -267,7 +271,6 @@ lib/evas/common/evas_op_add_main_.c \
lib/evas/common/evas_op_sub_main_.c \
lib/evas/common/evas_op_mask_main_.c \
lib/evas/common/evas_op_mul_main_.c \
lib/evas/common/evas_alpha_main.c \
lib/evas/common/evas_blend_main.c \
lib/evas/common/evas_blit_main.c \
lib/evas/common/evas_convert_color.c \

View File

@ -1,81 +0,0 @@
#include "evas_common_private.h"
#include "evas_blend_private.h"
/** default op: d = d*(1-sa) + s */
static void
_alpha_func_blend(DATA8 *src, DATA8 *dst, int len)
{
int k;
EINA_SAFETY_ON_NULL_RETURN(src);
EINA_SAFETY_ON_NULL_RETURN(dst);
for (k = len; k; k--)
{
int val = (*dst * (255 - *src)) / 255 + *src;
*dst++ = val;
src++;
}
}
/** d = s */
static void
_alpha_func_copy(DATA8 *src, DATA8 *dst, int len)
{
EINA_SAFETY_ON_NULL_RETURN(src);
EINA_SAFETY_ON_NULL_RETURN(dst);
memcpy(dst, src, len);
}
/** d = d*s */
static void
_alpha_func_mul(DATA8 *src, DATA8 *dst, int len)
{
int k;
EINA_SAFETY_ON_NULL_RETURN(src);
EINA_SAFETY_ON_NULL_RETURN(dst);
for (k = len; k; k--)
{
int val = (*dst * *src) / 255;
*dst++ = val;
src++;
}
}
#if 0
// Reference ops. In case of alpha, s == sa.
EVAS_RENDER_BLEND = 0, /**< default op: d = d*(1-sa) + s */
EVAS_RENDER_BLEND_REL = 1, /**< d = d*(1 - sa) + s*da */
EVAS_RENDER_COPY = 2, /**< d = s */
EVAS_RENDER_COPY_REL = 3, /**< d = s*da */
EVAS_RENDER_ADD = 4, /* d = d + s */
EVAS_RENDER_ADD_REL = 5, /**< d = d + s*da */
EVAS_RENDER_SUB = 6, /**< d = d - s */
EVAS_RENDER_SUB_REL = 7, /* d = d - s*da */
EVAS_RENDER_TINT = 8, /**< d = d*s + d*(1 - sa) + s*(1 - da) */
EVAS_RENDER_TINT_REL = 9, /**< d = d*(1 - sa + s) */
EVAS_RENDER_MASK = 10, /**< d = d*sa */
EVAS_RENDER_MUL = 11, /**< d = d*s */
#endif
Alpha_Gfx_Func
evas_common_alpha_func_get(int op)
{
switch (op)
{
case EVAS_RENDER_BLEND:
return _alpha_func_blend;
case EVAS_RENDER_COPY:
return _alpha_func_copy;
case EVAS_RENDER_MASK:
case EVAS_RENDER_MUL:
return _alpha_func_mul;
default:
ERR("Not implemented yet.");
return NULL;
}
}

View File

@ -27,8 +27,4 @@ RGBA_Gfx_Pt_Func evas_common_gfx_func_composite_pixel_color_pt_get (Eina_B
RGBA_Gfx_Pt_Func evas_common_gfx_func_composite_mask_color_pt_get (DATA32 col, Eina_Bool dst_alpha, int op);
RGBA_Gfx_Pt_Func evas_common_gfx_func_composite_pixel_mask_pt_get (Eina_Bool src_alpha, Eina_Bool dst_alpha, int op);
/* Alpha/mask functions */
Alpha_Gfx_Func evas_common_alpha_func_get (int op);
#endif /* _EVAS_BLEND_PRIVATE_H */

View File

@ -9,6 +9,7 @@
#include "evas_font_private.h"
#include "evas_blend_private.h"
#include "draw.h"
#ifdef EVAS_CSERVE2
# include "../cserve2/evas_cs2_private.h"
@ -512,7 +513,7 @@ evas_common_font_glyph_draw(RGBA_Font_Glyph *fg,
DATA8 *src8;
int row;
func = evas_common_alpha_func_get(dc->render_op);
func = efl_draw_alpha_func_get(dc->render_op, EINA_FALSE);
src8 = evas_common_font_glyph_uncompress(fg, NULL, NULL);
if (!src8) return;

View File

@ -1,6 +1,7 @@
#include "evas_filter.h"
#include "evas_filter_private.h"
#include "evas_blend_private.h"
#include "draw.h"
// Use a better formula than R+G+B for rgba to alpha conversion (RGB to YCbCr)
#define RGBA2ALPHA_WEIGHTED 1
@ -32,7 +33,7 @@ _image_draw_cpu_alpha2alpha(void *data EINA_UNUSED, void *context,
EINA_SAFETY_ON_FALSE_RETURN_VAL((src_w == dst_w) && (src_h == dst_h), EINA_FALSE);
func = evas_common_alpha_func_get(dc->render_op);
func = efl_draw_alpha_func_get(dc->render_op, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(func, EINA_FALSE);
sw = src->cache_entry.w;

View File

@ -2,7 +2,7 @@
#include "evas_filter_private.h"
#include "evas_blend_private.h"
#include "draw.h"
// Naming convention: _func_engine_incolor_maskcolor_outcolor()
static Eina_Bool _mask_cpu_alpha_alpha_alpha(Evas_Filter_Command *cmd);
@ -110,7 +110,7 @@ _mask_cpu_alpha_alpha_alpha(Evas_Filter_Command *cmd)
memcpy(dst, src, w * h * sizeof(DATA8));
// Second pass: apply render op
func = evas_common_alpha_func_get(render_op);
func = efl_draw_alpha_func_get(render_op, EINA_FALSE);
for (y = 0, my = 0; y < h; y++, my++, msk += mw)
{
if (my >= mh)
@ -314,7 +314,7 @@ _mask_cpu_alpha_alpha_rgba(Evas_Filter_Command *cmd)
span = malloc(stepsize * sizeof(DATA8));
func = evas_common_gfx_func_composite_mask_color_span_get(color, out->cache_entry.flags.alpha, 1, op);
span_func = evas_common_alpha_func_get(EVAS_RENDER_MASK);
span_func = efl_draw_alpha_func_get(cmd->draw.render_op, EINA_TRUE);
for (y = 0, my = 0; y < h; y++, my++, msk += mw)
{

View File

@ -456,7 +456,6 @@ typedef void (*RGBA_Gfx_Pt_Func) (DATA32 src, DATA8 mask, DATA32 col, DATA32 *ds
typedef void (*Gfx_Func_Copy) (DATA32 *src, DATA32 *dst, int len);
typedef void (*Gfx_Func_Convert) (DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x, int dith_y, DATA8 *pal);
typedef void (*Alpha_Gfx_Func) (DATA8 *src, DATA8 *dst, int len);
typedef void (*Evas_Render_Done_Cb)(void *);

View File

@ -7,13 +7,15 @@
#include <Efl.h>
typedef void (*RGBA_Comp_Func)(uint *dest, const uint *src, int length, uint mul_col, uint const_alpha);
typedef void (*RGBA_Comp_Func_Solid)(uint *dest, int length, uint color, uint const_alpha);
typedef void (*RGBA_Comp_Func) (uint *dest, const uint *src, int length, uint mul_col, uint const_alpha);
typedef void (*RGBA_Comp_Func_Solid) (uint *dest, int length, uint color, uint const_alpha);
typedef void (*Alpha_Gfx_Func) (uint8_t *src, uint8_t *dst, int len);
int efl_draw_init(void);
RGBA_Comp_Func_Solid efl_draw_func_solid_span_get(Efl_Gfx_Render_Op op, uint color);
RGBA_Comp_Func efl_draw_func_span_get(Efl_Gfx_Render_Op op, uint color, Eina_Bool src_alpha);
Alpha_Gfx_Func efl_draw_alpha_func_get(Efl_Gfx_Render_Op op, Eina_Bool has_mask);
/* common sw draw helpers */

View File

@ -0,0 +1,59 @@
#include "draw_private.h"
/** default op: d = d*(1-sa) + s */
static void
_alpha_func_blend(uint8_t *src, uint8_t *dst, int len)
{
int k;
EINA_SAFETY_ON_NULL_RETURN(src);
EINA_SAFETY_ON_NULL_RETURN(dst);
for (k = len; k; k--)
{
int val = (*dst * (255 - *src)) / 255 + *src;
*dst++ = val;
src++;
}
}
/** d = s */
static void
_alpha_func_copy(uint8_t *src, uint8_t *dst, int len)
{
EINA_SAFETY_ON_NULL_RETURN(src);
EINA_SAFETY_ON_NULL_RETURN(dst);
memcpy(dst, src, len);
}
/** d = d*s */
static void
_alpha_func_mul(uint8_t *src, uint8_t *dst, int len)
{
int k;
EINA_SAFETY_ON_NULL_RETURN(src);
EINA_SAFETY_ON_NULL_RETURN(dst);
for (k = len; k; k--)
{
int val = (*dst * *src) / 255;
*dst++ = val;
src++;
}
}
Alpha_Gfx_Func
efl_draw_alpha_func_get(Efl_Gfx_Render_Op op, Eina_Bool has_mask)
{
if (!has_mask)
{
if (op == EFL_GFX_RENDER_OP_BLEND)
return _alpha_func_blend;
else
return _alpha_func_copy;
}
else
return _alpha_func_mul;
}