diff options
author | Matt Sarett <msarett@google.com> | 2017-03-06 10:28:24 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-06 16:24:43 +0000 |
commit | 0bb6f38e511365670b9917ad76ece6f0bee9e282 (patch) | |
tree | 5438545c31de0240f560c697b179210c751b38ae /tests | |
parent | ce540eae37a4e6aab8e888991e4d40c83a93f427 (diff) |
Add unit tests for SkImage::colorSpace()
BUG=skia:
Change-Id: I1cb4bd1b5ca02f37bd08679803cf645b4d5ecc00
Reviewed-on: https://skia-review.googlesource.com/9297
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ImageTest.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 83f9e81af3..720f016c05 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -12,6 +12,7 @@ #include "SkAutoPixmapStorage.h" #include "SkBitmap.h" #include "SkCanvas.h" +#include "SkColorSpacePriv.h" #include "SkData.h" #include "SkImageEncoder.h" #include "SkImageGenerator.h" @@ -27,6 +28,7 @@ #include "SkUtils.h" #include "Test.h" +#include "Resources.h" #include "sk_tool_utils.h" #if SK_SUPPORT_GPU @@ -1040,6 +1042,48 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredTextureImage, reporter, ctxInfo) { /////////////////////////////////////////////////////////////////////////////////////////////////// +static sk_sp<SkImage> create_picture_image(sk_sp<SkColorSpace> space) { + SkPictureRecorder recorder; + SkCanvas* canvas = recorder.beginRecording(10, 10); + canvas->clear(SK_ColorCYAN); + return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), SkISize::Make(10, 10), + nullptr, nullptr, SkImage::BitDepth::kU8, std::move(space)); +}; + +DEF_TEST(Image_ColorSpace, r) { + sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB(); + sk_sp<SkImage> image = GetResourceAsImage("mandrill_512_q075.jpg"); + REPORTER_ASSERT(r, srgb.get() == image->colorSpace()); + + image = GetResourceAsImage("webp-color-profile-lossy.webp"); + SkColorSpaceTransferFn fn; + bool success = image->colorSpace()->isNumericalTransferFn(&fn); + REPORTER_ASSERT(r, success); + REPORTER_ASSERT(r, color_space_almost_equal(1.8f, fn.fG)); + + sk_sp<SkColorSpace> rec2020 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, + SkColorSpace::kRec2020_Gamut); + image = create_picture_image(rec2020); + REPORTER_ASSERT(r, SkColorSpace::Equals(rec2020.get(), image->colorSpace())); + + SkBitmap bitmap; + SkImageInfo info = SkImageInfo::MakeN32(10, 10, kPremul_SkAlphaType, rec2020); + bitmap.allocPixels(info); + image = SkImage::MakeFromBitmap(bitmap); + REPORTER_ASSERT(r, SkColorSpace::Equals(rec2020.get(), image->colorSpace())); + + sk_sp<SkSurface> surface = SkSurface::MakeRaster( + SkImageInfo::MakeN32Premul(SkISize::Make(10, 10))); + image = surface->makeImageSnapshot(); + REPORTER_ASSERT(r, nullptr == image->colorSpace()); + + surface = SkSurface::MakeRaster(info); + image = surface->makeImageSnapshot(); + REPORTER_ASSERT(r, SkColorSpace::Equals(rec2020.get(), image->colorSpace())); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// + static void make_all_premul(SkBitmap* bm) { bm->allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType)); for (int a = 0; a < 256; ++a) { |