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