blob: e041c7e73826f94a515db6a2d8b644a9c892bfe9 [file] [log] [blame]
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -05001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/codec/SkAndroidCodec.h"
9#include "include/core/SkBitmap.h"
10#include "include/core/SkColor.h"
11#include "include/core/SkColorSpace.h"
12#include "include/core/SkData.h"
13#include "include/core/SkEncodedImageFormat.h"
14#include "include/core/SkImageEncoder.h"
15#include "include/core/SkImageInfo.h"
16#include "include/core/SkStream.h"
17#include "tests/Test.h"
Ben Wagner1a462bd2018-03-12 13:46:21 -040018
Ben Wagnerb607a8f2018-03-12 13:46:21 -040019#include <memory>
20#include <utility>
21
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050022DEF_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,
Brian Osman6b622962018-08-27 19:16:02 +000028 kPremul_SkAlphaType, SkColorSpace::MakeSRGB()));
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050029 // 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}