Index: src/core/SkConfig8888.cpp |
diff --git a/src/core/SkConfig8888.cpp b/src/core/SkConfig8888.cpp |
index f889f20744fa3b3f3c20189ae9ea56f31ac96a78..3364f445a62bc6baa8672cd11d1370556d941214 100644 |
--- a/src/core/SkConfig8888.cpp |
+++ b/src/core/SkConfig8888.cpp |
@@ -1,5 +1,6 @@ |
#include "SkConfig8888.h" |
#include "SkMathPriv.h" |
+#include "SkUnPreMultiply.h" |
namespace { |
@@ -57,23 +58,21 @@ inline uint32_t convert_pixel(uint32_t pixel) { |
uint32_t a, r, g, b; |
unpack_config8888<IN_A_IDX, IN_R_IDX, IN_G_IDX, IN_B_IDX>(pixel, &a, &r, &g, &b); |
if (IN_PM && !OUT_PM) { |
- // We're doing the explicit divide to match WebKit layout |
- // test expectations. We can modify and rebaseline if there |
- // it can be shown that there is a more performant way to |
- // unpremul. |
+ // It is verified that using SkUnPreMultiply::ApplyScale is a more |
+ // performant way to unpremul than (value * 0xff) / a. |
Noel Gordon
2013/06/04 05:55:18
Does (v * 255 / a) equal your SkUnPreMultiply::App
Jun Jiang
2013/06/04 06:35:10
Hi, Noel. (v * 255 / a) doesn't equal SkUnPreMulti
Tom Hudson
2013/06/10 09:35:18
Nit: better grammar: "Using SkUnPreMultiply::Apply
|
if (a) { |
- r = r * 0xff / a; |
- g = g * 0xff / a; |
- b = b * 0xff / a; |
+ SkUnPreMultiply::Scale scale = SkUnPreMultiply::GetScale(a); |
+ r = SkUnPreMultiply::ApplyScale(scale, r); |
+ g = SkUnPreMultiply::ApplyScale(scale, g); |
+ b = SkUnPreMultiply::ApplyScale(scale, b); |
} else { |
return 0; |
} |
} else if (!IN_PM && OUT_PM) { |
- // This matches WebKit's conversion which we are replacing. |
- // We can consider alternative rounding rules for performance. |
- r = SkMulDiv255Ceiling(r, a); |
- g = SkMulDiv255Ceiling(g, a); |
- b = SkMulDiv255Ceiling(b, a); |
+ // This matches SkUnPreMultiply conversion which we are replacing. |
+ r = SkDiv255Round(r * a); |
Noel Gordon
2013/06/04 07:16:06
Could you test using the following here and tell m
|
+ g = SkDiv255Round(g * a); |
+ b = SkDiv255Round(b * a); |
} |
return pack_config8888<OUT_A_IDX, OUT_R_IDX, OUT_G_IDX, OUT_B_IDX>(a, r, g, b); |
} |