evas: handle premultiplying of AGRY88.

This commit is contained in:
Cedric BAIL 2014-03-21 11:53:57 +09:00 committed by Cedric BAIL
parent 516ee8c99e
commit eb7071078a
3 changed files with 30 additions and 1 deletions

View File

@ -1,6 +1,26 @@
#include "evas_common_private.h"
#include "evas_convert_color.h"
EAPI DATA32
evas_common_convert_ag_premul(DATA16 *data, unsigned int len)
{
DATA16 *de = data + len;
DATA32 nas = 0;
while (data < de)
{
DATA16 a = 1 + ((*data >> 8) & 0xff);
*data = (*data & 0xff00) |
((((*data & 0xff) * a) >> 8) & 0xff);
data++;
if ((a == 1) || (a == 256))
nas++;
}
return nas;
}
EAPI DATA32
evas_common_convert_argb_premul(DATA32 *data, unsigned int len)

View File

@ -2,6 +2,7 @@
#define _EVAS_CONVERT_COLOR_H
EAPI DATA32 evas_common_convert_ag_premul (DATA16 *data, unsigned int len);
EAPI DATA32 evas_common_convert_argb_premul (DATA32 *src, unsigned int len);
EAPI void evas_common_convert_argb_unpremul (DATA32 *src, unsigned int len);
EAPI void evas_common_convert_color_argb_premul (int a, int *r, int *g, int *b);

View File

@ -998,7 +998,15 @@ evas_common_image_premul(Image_Entry *ie)
if (!evas_cache_image_pixels(ie)) return;
if (!ie->flags.alpha) return;
nas = evas_common_convert_argb_premul(evas_cache_image_pixels(ie), ie->w * ie->h);
switch (ie->space)
{
case EVAS_COLORSPACE_ARGB8888:
nas = evas_common_convert_argb_premul(evas_cache_image_pixels(ie), ie->w * ie->h);
break;
case EVAS_COLORSPACE_AGRY88:
nas = evas_common_convert_ag_premul((void*) evas_cache_image_pixels(ie), ie->w * ie->h);
default: return;
}
if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (ie->w * ie->h))
ie->flags.alpha_sparse = 1;
}