• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SkAndroidCodec.h"
9 #include "SkBitmap.h"
10 #include "SkCodec.h"
11 #include "SkColorSpace.h"
12 #include "SkEncodedImageFormat.h"
13 #include "SkImageEncoder.h"
14 #include "SkImageInfo.h"
15 #include "SkStream.h"
16 
17 #include "Test.h"
18 
DEF_TEST(Codec_recommendedF16,r)19 DEF_TEST(Codec_recommendedF16, r) {
20     // Encode an F16 bitmap. SkEncodeImage will encode this to a true-color PNG
21     // with a bit depth of 16. SkAndroidCodec should always recommend F16 for
22     // such a PNG.
23     SkBitmap bm;
24     bm.allocPixels(SkImageInfo::Make(10, 10, kRGBA_F16_SkColorType,
25             kPremul_SkAlphaType, SkColorSpace::MakeSRGBLinear()));
26     // What is drawn is not important.
27     bm.eraseColor(SK_ColorBLUE);
28 
29     SkDynamicMemoryWStream wstream;
30     REPORTER_ASSERT(r, SkEncodeImage(&wstream, bm, SkEncodedImageFormat::kPNG, 100));
31     auto data = wstream.detachAsData();
32     auto androidCodec = SkAndroidCodec::MakeFromData(std::move(data));
33     if (!androidCodec) {
34         ERRORF(r, "Failed to create SkAndroidCodec");
35         return;
36     }
37 
38     REPORTER_ASSERT(r, androidCodec->computeOutputColorType(kN32_SkColorType)
39             == kRGBA_F16_SkColorType);
40 }
41