aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2018-05-10 11:29:15 -0400
committerGravatar Mike Klein <mtklein@chromium.org>2018-05-10 18:26:22 +0000
commitce4cf72e3487f661e53f6d0c3416c9b58da4fd00 (patch)
tree5e8a5b884c787a095ea25ea93070569731e937a1 /tests
parent024615e9752d93c842ad3cad597fd65382ddb678 (diff)
non-linear blending first steps
Code: - Add a non-linear blending bit and makeNonlinearBlending() to SkColorSpace - remove enough F16=linear checks to make it possible to create surfaces and encode pngs with nonlinear F16 Testing: - add "esrgb" software config to DM, run it - add "srgbnl" software config, run it - deemphasize importance of "srgb" config on bots - update unit tests to reflect relaxed F16 constraints - add a new unit test file with _really_ basic tests, and a new unit test that's not working yet Bug: skia:7942 Change-Id: I8ac042bdf9f3d791765393b68fd9256375184d83 Reviewed-on: https://skia-review.googlesource.com/127325 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/CodecTest.cpp10
-rw-r--r--tests/NonlinearBlendingTest.cpp76
-rw-r--r--tests/SurfaceTest.cpp4
3 files changed, 83 insertions, 7 deletions
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index ceb10a10df..474cdc6931 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -1144,22 +1144,22 @@ static void test_conversion_possible(skiatest::Reporter* r, const char* path,
SkBitmap bm;
bm.allocPixels(infoF16);
SkCodec::Result result = codec->getPixels(infoF16, bm.getPixels(), bm.rowBytes());
- REPORTER_ASSERT(r, SkCodec::kInvalidConversion == result);
+ REPORTER_ASSERT(r, SkCodec::kSuccess == result);
result = codec->startScanlineDecode(infoF16);
if (supportsScanlineDecoder) {
- REPORTER_ASSERT(r, SkCodec::kInvalidConversion == result);
+ REPORTER_ASSERT(r, SkCodec::kSuccess == result);
} else {
REPORTER_ASSERT(r, SkCodec::kUnimplemented == result
- || SkCodec::kInvalidConversion == result);
+ || SkCodec::kSuccess == result);
}
result = codec->startIncrementalDecode(infoF16, bm.getPixels(), bm.rowBytes());
if (supportsIncrementalDecoder) {
- REPORTER_ASSERT(r, SkCodec::kInvalidConversion == result);
+ REPORTER_ASSERT(r, SkCodec::kSuccess == result);
} else {
REPORTER_ASSERT(r, SkCodec::kUnimplemented == result
- || SkCodec::kInvalidConversion == result);
+ || SkCodec::kSuccess == result);
}
infoF16 = infoF16.makeColorSpace(infoF16.colorSpace()->makeLinearGamma());
diff --git a/tests/NonlinearBlendingTest.cpp b/tests/NonlinearBlendingTest.cpp
new file mode 100644
index 0000000000..10c12aa280
--- /dev/null
+++ b/tests/NonlinearBlendingTest.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Test.h"
+#include "SkHalf.h"
+#include "SkSurface.h"
+#include "SkCanvas.h"
+
+DEF_TEST(NonlinearBlending, r) {
+
+ // First check our familiar basics with linear F16.
+ {
+ auto info = SkImageInfo::Make(1,1, kRGBA_F16_SkColorType, kPremul_SkAlphaType,
+ SkColorSpace::MakeSRGBLinear());
+
+ auto surface = SkSurface::MakeRaster(info);
+ surface->getCanvas()->clear(0xff808080);
+ uint64_t pix;
+ REPORTER_ASSERT(r, surface->readPixels(info, &pix, sizeof(pix),0,0));
+
+ // 0x80 in sRGB is ≈ 0.22 linear.
+ REPORTER_ASSERT(r, SkHalfToFloat(pix & 0xffff) < 0.25f);
+ }
+
+ // Test that we support sRGB-encoded F16. This is somewhat new.
+ {
+ auto info = SkImageInfo::Make(1,1, kRGBA_F16_SkColorType, kPremul_SkAlphaType,
+ SkColorSpace::MakeSRGB());
+
+ auto surface = SkSurface::MakeRaster(info);
+ surface->getCanvas()->clear(0xff808080);
+ uint64_t pix;
+ REPORTER_ASSERT(r, surface->readPixels(info, &pix, sizeof(pix),0,0));
+
+ // 0x80 sRGB is ≈ 0.501.
+ REPORTER_ASSERT(r, SkHalfToFloat(pix & 0xffff) >= 0.5f);
+ }
+
+ // Since we're only clear()ing, this should work the same as the last block.
+ {
+ auto info = SkImageInfo::Make(1,1, kRGBA_F16_SkColorType, kPremul_SkAlphaType,
+ SkColorSpace::MakeSRGB()->makeNonlinearBlending());
+
+ auto surface = SkSurface::MakeRaster(info);
+ surface->getCanvas()->clear(0xff808080);
+ uint64_t pix;
+ REPORTER_ASSERT(r, surface->readPixels(info, &pix, sizeof(pix),0,0));
+
+ // 0x80 sRGB is ≈ 0.501.
+ REPORTER_ASSERT(r, SkHalfToFloat(pix & 0xffff) >= 0.5f);
+ }
+
+ // This won't work until we actually support color spaces with non-linear blending.
+ if (0) {
+ auto info = SkImageInfo::Make(1,1, kRGBA_F16_SkColorType, kPremul_SkAlphaType,
+ SkColorSpace::MakeSRGB()->makeNonlinearBlending());
+
+ auto surface = SkSurface::MakeRaster(info);
+
+ surface->getCanvas()->clear(SK_ColorWHITE);
+ SkPaint p;
+ p.setColor(0x80000000);
+ surface->getCanvas()->drawPaint(p);
+
+ uint64_t pix;
+ REPORTER_ASSERT(r, surface->readPixels(info, &pix, sizeof(pix),0,0));
+
+ // 0x80 sRGB is ≈ 0.501. A likely failure here is ~0.75, linear blending.
+ REPORTER_ASSERT(r, SkHalfToFloat(pix & 0xffff) >= 0.45f &&
+ SkHalfToFloat(pix & 0xffff) <= 0.55f);
+ }
+}
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index 835e9ffc7f..e757230aa1 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -951,8 +951,8 @@ static void test_surface_creation_and_snapshot_with_color_space(
{ kN32_SkColorType, oddColorSpace, false, "N32-odd" },
{ kRGBA_F16_SkColorType, nullptr, true, "F16-nullptr" },
{ kRGBA_F16_SkColorType, linearColorSpace, true, "F16-linear" },
- { kRGBA_F16_SkColorType, srgbColorSpace, false, "F16-srgb" },
- { kRGBA_F16_SkColorType, oddColorSpace, false, "F16-odd" },
+ { kRGBA_F16_SkColorType, srgbColorSpace, true, "F16-srgb" },
+ { kRGBA_F16_SkColorType, oddColorSpace, true, "F16-odd" },
{ kRGB_565_SkColorType, srgbColorSpace, false, "565-srgb" },
{ kAlpha_8_SkColorType, srgbColorSpace, false, "A8-srgb" },
{ kRGBA_1010102_SkColorType, nullptr, true, "1010102-nullptr" },