| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef Sk4pxXfermode_DEFINED | 8 #ifndef Sk4pxXfermode_DEFINED |
| 9 #define Sk4pxXfermode_DEFINED | 9 #define Sk4pxXfermode_DEFINED |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // There's no chance of underflow, and if we subtract p before adding src+ds
t, no overflow. | 61 // There's no chance of underflow, and if we subtract p before adding src+ds
t, no overflow. |
| 62 return (s - p) + (d - p.zeroAlphas()); | 62 return (s - p) + (d - p.zeroAlphas()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 XFERMODE(HardLight) { | 65 XFERMODE(HardLight) { |
| 66 auto alphas = SrcOver::Xfer(s,d); | 66 auto alphas = SrcOver::Xfer(s,d); |
| 67 | 67 |
| 68 auto sa = s.alphas(), | 68 auto sa = s.alphas(), |
| 69 da = d.alphas(); | 69 da = d.alphas(); |
| 70 | 70 |
| 71 auto isLite = (sa-s) < s; | 71 auto isLite = ((sa-s) < s).widenLoHi(); |
| 72 | 72 |
| 73 auto dark = s*d << 1, | 73 auto dark = s*d << 1, |
| 74 lite = sa*da - ((da-d)*(sa-s) << 1), | 74 lite = sa*da - ((da-d)*(sa-s) << 1), |
| 75 both = s*da.inv() + d*sa.inv(); | 75 both = s*da.inv() + d*sa.inv(); |
| 76 | 76 |
| 77 // TODO: do isLite in 16-bit so we only have to div255() once. | 77 auto colors = (both + isLite.thenElse(lite, dark)).div255(); |
| 78 auto colors = isLite.thenElse((lite + both).div255(), | |
| 79 (dark + both).div255()); | |
| 80 return alphas.zeroColors() + colors.zeroAlphas(); | 78 return alphas.zeroColors() + colors.zeroAlphas(); |
| 81 } | 79 } |
| 82 XFERMODE(Overlay) { return HardLight::Xfer(d,s); } | 80 XFERMODE(Overlay) { return HardLight::Xfer(d,s); } |
| 83 | 81 |
| 84 XFERMODE(Darken) { | 82 XFERMODE(Darken) { |
| 85 auto sda = s.approxMulDiv255(d.alphas()), | 83 auto sda = s.approxMulDiv255(d.alphas()), |
| 86 dsa = d.approxMulDiv255(s.alphas()); | 84 dsa = d.approxMulDiv255(s.alphas()); |
| 87 auto srcover = s + (d - dsa), | 85 auto srcover = s + (d - dsa), |
| 88 dstover = d + (s - sda); | 86 dstover = d + (s - sda); |
| 89 auto alphas = srcover, | 87 auto alphas = srcover, |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 #endif | 271 #endif |
| 274 default: break; | 272 default: break; |
| 275 } | 273 } |
| 276 #endif | 274 #endif |
| 277 return nullptr; | 275 return nullptr; |
| 278 } | 276 } |
| 279 | 277 |
| 280 } // namespace | 278 } // namespace |
| 281 | 279 |
| 282 #endif//Sk4pxXfermode_DEFINED | 280 #endif//Sk4pxXfermode_DEFINED |
| OLD | NEW |