From dedd6a4ddf1ef722f1871f5033fdd4f1fc0180e5 Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Wed, 9 Jan 2019 16:52:47 +0900 Subject: [PATCH] lottie/vector: added destIn and destOut comp function. Change-Id: I50a0cf16f5a8438006c8e82074f72da46c87a108 --- src/vector/vcompositionfunctions.cpp | 72 +++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/src/vector/vcompositionfunctions.cpp b/src/vector/vcompositionfunctions.cpp index c160419..02459fe 100644 --- a/src/vector/vcompositionfunctions.cpp +++ b/src/vector/vcompositionfunctions.cpp @@ -55,6 +55,37 @@ void comp_func_solid_SourceOver(uint32_t *dest, int length, uint32_t color, for (i = 0; i < length; ++i) dest[i] = color + BYTE_MUL(dest[i], ialpha); } +/* + result = d * sa + dest = d * sa * ca + d * cia + = d * (sa * ca + cia) +*/ +static void comp_func_solid_DestinationIn(uint *dest, int length, uint color, uint const_alpha) +{ + uint a = vAlpha(color); + if (const_alpha != 255) { + a = BYTE_MUL(a, const_alpha) + 255 - const_alpha; + } + for (int i = 0; i < length; ++i) { + dest[i] = BYTE_MUL(dest[i], a); + } +} + +/* + result = d * sia + dest = d * sia * ca + d * cia + = d * (sia * ca + cia) +*/ +static void comp_func_solid_DestinationOut(uint *dest, int length, uint color, uint const_alpha) +{ + uint a = vAlpha(~color); + if (const_alpha != 255) + a = BYTE_MUL(a, const_alpha) + 255 - const_alpha; + for (int i = 0; i < length; ++i) { + dest[i] = BYTE_MUL(dest[i], a); + } +} + void comp_func_Source(uint32_t *dest, const uint32_t *src, int length, uint32_t const_alpha) { @@ -99,10 +130,47 @@ void comp_func_SourceOver(uint32_t *dest, const uint32_t *src, int length, } } +void comp_func_DestinationIn(uint *dest, const uint *src, int length, uint const_alpha) +{ + if (const_alpha == 255) { + for (int i = 0; i < length; ++i) { + dest[i] = BYTE_MUL(dest[i], vAlpha(src[i])); + } + } else { + uint cia = 255 - const_alpha; + for (int i = 0; i < length; ++i) { + uint a = BYTE_MUL(vAlpha(src[i]), const_alpha) + cia; + dest[i] = BYTE_MUL(dest[i], a); + } + } +} + +void comp_func_DestinationOut(uint *dest, const uint *src, int length, uint const_alpha) +{ + if (const_alpha == 255) { + for (int i = 0; i < length; ++i) { + dest[i] = BYTE_MUL(dest[i], vAlpha(~src[i])); + } + } else { + uint cia = 255 - const_alpha; + for (int i = 0; i < length; ++i) { + uint sia = BYTE_MUL(vAlpha(~src[i]), const_alpha) + cia; + dest[i] = BYTE_MUL(dest[i], sia); + } + } +} + CompositionFunctionSolid COMP_functionForModeSolid_C[] = { - comp_func_solid_Source, comp_func_solid_SourceOver}; + comp_func_solid_Source, + comp_func_solid_SourceOver, + comp_func_solid_DestinationIn, + comp_func_solid_DestinationOut + }; CompositionFunction COMP_functionForMode_C[] = {comp_func_Source, - comp_func_SourceOver}; + comp_func_SourceOver, + comp_func_DestinationIn, + comp_func_DestinationOut + }; void vInitBlendFunctions() {} -- 2.7.4