Plumb through need for unpremul/premul
Update unittest to build test image with legal premul pixels.
Bug: skia:
Change-Id: Iebd1d2f81cac77f8913bd79f6ac25983ed710641
Reviewed-on: https://skia-review.googlesource.com/21735
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/tests/ApplyGammaTest.cpp b/tests/ApplyGammaTest.cpp
index 79dbfc7..83b5968 100644
--- a/tests/ApplyGammaTest.cpp
+++ b/tests/ApplyGammaTest.cpp
@@ -44,10 +44,17 @@
result = false;
}
+ // need to unpremul before we can perform srgb magic
+ float invScale = 0;
+ float alpha = SkGetPackedA32(src);
+ if (alpha) {
+ invScale = 255.0f / alpha;
+ }
+
for (int c = 0; c < 3; ++c) {
- uint8_t srcComponent = (src & (0xff << (c * 8))) >> (c * 8);
- float lower = SkTMax(0.f, (float)srcComponent - error);
- float upper = SkTMin(255.f, (float)srcComponent + error);
+ float srcComponent = ((src & (0xff << (c * 8))) >> (c * 8)) * invScale;
+ float lower = SkTMax(0.f, srcComponent - error);
+ float upper = SkTMin(255.f, srcComponent + error);
if (toSRGB) {
lower = linear_to_srgb(lower / 255.f);
upper = linear_to_srgb(upper / 255.f);
@@ -55,14 +62,16 @@
lower = srgb_to_linear(lower / 255.f);
upper = srgb_to_linear(upper / 255.f);
}
+ lower *= alpha;
+ upper *= alpha;
SkASSERT(lower >= 0.f && lower <= 255.f);
SkASSERT(upper >= 0.f && upper <= 255.f);
uint8_t dstComponent = (dst & (0xff << (c * 8))) >> (c * 8);
- if (dstComponent < SkScalarFloorToInt(lower * 255.f) ||
- dstComponent > SkScalarCeilToInt(upper * 255.f)) {
+ if (dstComponent < SkScalarFloorToInt(lower) ||
+ dstComponent > SkScalarCeilToInt(upper)) {
result = false;
}
- uint8_t expectedComponent = SkScalarRoundToInt((lower + upper) * 127.5f);
+ uint8_t expectedComponent = SkScalarRoundToInt((lower + upper) * 0.5f);
expectedColor |= expectedComponent << (c * 8);
}
@@ -72,8 +81,8 @@
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ApplyGamma, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext();
- static const int kW = 10;
- static const int kH = 10;
+ static const int kW = 256;
+ static const int kH = 256;
static const size_t kRowBytes = sizeof(uint32_t) * kW;
GrSurfaceDesc baseDesc;
@@ -84,8 +93,10 @@
const SkImageInfo ii = SkImageInfo::MakeN32Premul(kW, kH);
SkAutoTMalloc<uint32_t> srcPixels(kW * kH);
- for (int i = 0; i < kW * kH; ++i) {
- srcPixels.get()[i] = i;
+ for (int y = 0; y < kH; ++y) {
+ for (int x = 0; x < kW; ++x) {
+ srcPixels.get()[y*kW+x] = SkPreMultiplyARGB(x, y, x, 0xFF);
+ }
}
SkBitmap bm;