| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 |
| 19 | #include "vdrawhelper.h" |
| 20 |
| 21 | /* |
| 22 | result = s |
| 23 | dest = s * ca + d * cia |
| 24 | */ |
| 25 | void comp_func_solid_Source(uint32_t *dest, int length, uint32_t color, |
| 26 | uint32_t const_alpha) |
| 27 | { |
| 28 | int ialpha, i; |
| 29 |
| 30 | if (const_alpha == 255) { |
| 31 | memfill32(dest, color, length); |
| 32 | } else { |
| 33 | ialpha = 255 - const_alpha; |
| 34 | color = BYTE_MUL(color, const_alpha); |
| 35 | for (i = 0; i < length; ++i) |
| 36 | dest[i] = color + BYTE_MUL(dest[i], ialpha); |
| 37 | } |
| 38 | } |
| 39 |
| 40 | /* |
| 41 | r = s + d * sia |
| 42 | dest = r * ca + d * cia |
| 43 | = (s + d * sia) * ca + d * cia |
| 44 | = s * ca + d * (sia * ca + cia) |
| 45 | = s * ca + d * (1 - sa*ca) |
| 46 | = s' + d ( 1 - s'a) |
| 47 | */ |
| 48 | void comp_func_solid_SourceOver(uint32_t *dest, int length, uint32_t color, |
| 49 | uint32_t const_alpha) |
| 50 | { |
| 51 | int ialpha, i; |
| 52 |
| 53 | if (const_alpha != 255) color = BYTE_MUL(color, const_alpha); |
| 54 | ialpha = 255 - vAlpha(color); |
| 55 | for (i = 0; i < length; ++i) dest[i] = color + BYTE_MUL(dest[i], ialpha); |
| 56 | } |
| 57 |
| 58 | /* |
| 59 | result = d * sa |
| 60 | dest = d * sa * ca + d * cia |
| 61 | = d * (sa * ca + cia) |
| 62 | */ |
| 63 | static void comp_func_solid_DestinationIn(uint *dest, int length, uint color, |
| 64 | uint const_alpha) |
| 65 | { |
| 66 | uint a = vAlpha(color); |
| 67 | if (const_alpha != 255) { |
| 68 | a = BYTE_MUL(a, const_alpha) + 255 - const_alpha; |
| 69 | } |
| 70 | for (int i = 0; i < length; ++i) { |
| 71 | dest[i] = BYTE_MUL(dest[i], a); |
| 72 | } |
| 73 | } |
| 74 |
| 75 | /* |
| 76 | result = d * sia |
| 77 | dest = d * sia * ca + d * cia |
| 78 | = d * (sia * ca + cia) |
| 79 | */ |
| 80 | static void comp_func_solid_DestinationOut(uint *dest, int length, uint color, |
| 81 | uint const_alpha) |
| 82 | { |
| 83 | uint a = vAlpha(~color); |
| 84 | if (const_alpha != 255) a = BYTE_MUL(a, const_alpha) + 255 - const_alpha; |
| 85 | for (int i = 0; i < length; ++i) { |
| 86 | dest[i] = BYTE_MUL(dest[i], a); |
| 87 | } |
| 88 | } |
| 89 |
| 90 | void comp_func_Source(uint32_t *dest, const uint32_t *src, int length, |
| 91 | uint32_t const_alpha) |
| 92 | { |
| 93 | if (const_alpha == 255) { |
| 94 | memcpy(dest, src, size_t(length) * sizeof(uint)); |
| 95 | } else { |
| 96 | uint ialpha = 255 - const_alpha; |
| 97 | for (int i = 0; i < length; ++i) { |
| 98 | dest[i] = |
| 99 | INTERPOLATE_PIXEL_255(src[i], const_alpha, dest[i], ialpha); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 |
| 104 | /* s' = s * ca |
| 105 | * d' = s' + d (1 - s'a) |
| 106 | */ |
| 107 | void comp_func_SourceOver(uint32_t *dest, const uint32_t *src, int length, |
| 108 | uint32_t const_alpha) |
| 109 | { |
| 110 | uint s, sia; |
| 111 |
| 112 | if (const_alpha == 255) { |
| 113 | for (int i = 0; i < length; ++i) { |
| 114 | s = src[i]; |
| 115 | if (s >= 0xff000000) |
| 116 | dest[i] = s; |
| 117 | else if (s != 0) { |
| 118 | sia = vAlpha(~s); |
| 119 | dest[i] = s + BYTE_MUL(dest[i], sia); |
| 120 | } |
| 121 | } |
| 122 | } else { |
| 123 | /* source' = source * const_alpha |
| 124 | * dest = source' + dest ( 1- source'a) |
| 125 | */ |
| 126 | for (int i = 0; i < length; ++i) { |
| 127 | uint s = BYTE_MUL(src[i], const_alpha); |
| 128 | sia = vAlpha(~s); |
| 129 | dest[i] = s + BYTE_MUL(dest[i], sia); |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 |
| 134 | void comp_func_DestinationIn(uint *dest, const uint *src, int length, |
| 135 | uint const_alpha) |
| 136 | { |
| 137 | if (const_alpha == 255) { |
| 138 | for (int i = 0; i < length; ++i) { |
| 139 | dest[i] = BYTE_MUL(dest[i], vAlpha(src[i])); |
| 140 | } |
| 141 | } else { |
| 142 | uint cia = 255 - const_alpha; |
| 143 | for (int i = 0; i < length; ++i) { |
| 144 | uint a = BYTE_MUL(vAlpha(src[i]), const_alpha) + cia; |
| 145 | dest[i] = BYTE_MUL(dest[i], a); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 |
| 150 | void comp_func_DestinationOut(uint *dest, const uint *src, int length, |
| 151 | uint const_alpha) |
| 152 | { |
| 153 | if (const_alpha == 255) { |
| 154 | for (int i = 0; i < length; ++i) { |
| 155 | dest[i] = BYTE_MUL(dest[i], vAlpha(~src[i])); |
| 156 | } |
| 157 | } else { |
| 158 | uint cia = 255 - const_alpha; |
| 159 | for (int i = 0; i < length; ++i) { |
| 160 | uint sia = BYTE_MUL(vAlpha(~src[i]), const_alpha) + cia; |
| 161 | dest[i] = BYTE_MUL(dest[i], sia); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 |
| 166 | CompositionFunctionSolid COMP_functionForModeSolid_C[] = { |
| 167 | comp_func_solid_Source, comp_func_solid_SourceOver, |
| 168 | comp_func_solid_DestinationIn, comp_func_solid_DestinationOut}; |
| 169 |
| 170 | CompositionFunction COMP_functionForMode_C[] = { |
| 171 | comp_func_Source, comp_func_SourceOver, comp_func_DestinationIn, |
| 172 | comp_func_DestinationOut}; |
| 173 |
| 174 | void vInitBlendFunctions() {} |
| 175 |