我有一个 alpha 预乘图像,需要更改它的不透明度。应用于图像的不透明度变化可以从 0.0 到 1.0。
使用以下公式很容易实现此过程:
Cn = C*alpha;
An = A*alpha;
但是,我试图避免自己编写此代码,并允许高度优化的库 pixman 完成这项工作。它们提供了各种混合选项,但我不太确定如何使用遮罩或使用哪个混合选项。我曾尝试使用 MULTIPLY 但这只是让图像像预期的那样变暗,我猜......
我应该使用哪个潜在的混合选项有什么想法吗?
{ "CLEAR", PIXMAN_OP_CLEAR },
{ "SRC", PIXMAN_OP_SRC },
{ "DST", PIXMAN_OP_DST },
{ "OVER", PIXMAN_OP_OVER },
{ "OVER_REVERSE", PIXMAN_OP_OVER_REVERSE },
{ "IN", PIXMAN_OP_IN },
{ "IN_REVERSE", PIXMAN_OP_IN_REVERSE },
{ "OUT", PIXMAN_OP_OUT },
{ "OUT_REVERSE", PIXMAN_OP_OUT_REVERSE },
{ "ATOP", PIXMAN_OP_ATOP },
{ "ATOP_REVERSE", PIXMAN_OP_ATOP_REVERSE },
{ "XOR", PIXMAN_OP_XOR },
{ "ADD", PIXMAN_OP_ADD },
{ "SATURATE", PIXMAN_OP_SATURATE },
{ "MULTIPLY", PIXMAN_OP_MULTIPLY },
{ "SCREEN", PIXMAN_OP_SCREEN },
{ "OVERLAY", PIXMAN_OP_OVERLAY },
{ "DARKEN", PIXMAN_OP_DARKEN },
{ "LIGHTEN", PIXMAN_OP_LIGHTEN },
{ "COLOR_DODGE", PIXMAN_OP_COLOR_DODGE },
{ "COLOR_BURN", PIXMAN_OP_COLOR_BURN },
{ "HARD_LIGHT", PIXMAN_OP_HARD_LIGHT },
{ "SOFT_LIGHT", PIXMAN_OP_SOFT_LIGHT },
{ "DIFFERENCE", PIXMAN_OP_DIFFERENCE },
{ "EXCLUSION", PIXMAN_OP_EXCLUSION },
{ "HSL_HUE", PIXMAN_OP_HSL_HUE },
{ "HSL_SATURATION", PIXMAN_OP_HSL_SATURATION },
{ "HSL_COLOR", PIXMAN_OP_HSL_COLOR },
{ "HSL_LUMINOSITY", PIXMAN_OP_HSL_LUMINOSITY },
这是实际的复合函数:
void pixman_image_composite(pixman_op_t op,
pixman_image_t *src,
pixman_image_t *mask,
pixman_image_t *dest,
int16_t src_x,
int16_t src_y,
int16_t mask_x,
int16_t mask_y,
int16_t dest_x,
int16_t dest_y,
uint16_t width,
uint16_t height);