blob: 180bf2f8da912d0deba6c76f941123ea2dfa448d [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 Wagner501c17c2018-03-12 20:04:31 +000010#include "SkCodec.h"
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050011#include "SkColorSpace.h"
12#include "SkEncodedImageFormat.h"
13#include "SkImageEncoder.h"
14#include "SkImageInfo.h"
15#include "SkStream.h"
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050016
Ben Wagner501c17c2018-03-12 20:04:31 +000017#include "Test.h"
Ben Wagner1a462bd2018-03-12 13:46:21 -040018
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050019DEF_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}