blob: 53b6427938069f48952026786c145432d92409a3 [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
8#include "SkAndroidCodec.h"
9#include "SkBitmap.h"
Ben Wagnerb607a8f2018-03-12 13:46:21 -040010#include "SkColor.h"
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050011#include "SkColorSpace.h"
Ben Wagnerb607a8f2018-03-12 13:46:21 -040012#include "SkData.h"
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050013#include "SkEncodedImageFormat.h"
14#include "SkImageEncoder.h"
15#include "SkImageInfo.h"
16#include "SkStream.h"
Ben Wagner501c17c2018-03-12 20:04:31 +000017#include "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}