• 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 "SkColor.h"
11 #include "SkColorSpace.h"
12 #include "SkData.h"
13 #include "SkEncodedImageFormat.h"
14 #include "SkImageEncoder.h"
15 #include "SkImageInfo.h"
16 #include "SkStream.h"
17 #include "Test.h"
18 
19 #include <memory>
20 #include <utility>
21 
DEF_TEST(Codec_recommendedF16,r)22 DEF_TEST(Codec_recommendedF16, r) {
23     // Encode an F16 bitmap. SkEncodeImage will encode this to a true-color PNG
24     // with a bit depth of 16. SkAndroidCodec should always recommend F16 for
25     // such a PNG.
26     SkBitmap bm;
27     bm.allocPixels(SkImageInfo::Make(10, 10, kRGBA_F16_SkColorType,
28             kPremul_SkAlphaType, SkColorSpace::MakeSRGB()));
29     // What is drawn is not important.
30     bm.eraseColor(SK_ColorBLUE);
31 
32     SkDynamicMemoryWStream wstream;
33     REPORTER_ASSERT(r, SkEncodeImage(&wstream, bm, SkEncodedImageFormat::kPNG, 100));
34     auto data = wstream.detachAsData();
35     auto androidCodec = SkAndroidCodec::MakeFromData(std::move(data));
36     if (!androidCodec) {
37         ERRORF(r, "Failed to create SkAndroidCodec");
38         return;
39     }
40 
41     REPORTER_ASSERT(r, androidCodec->computeOutputColorType(kN32_SkColorType)
42             == kRGBA_F16_SkColorType);
43 }
44