Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 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" |
Ben Wagner | 501c17c | 2018-03-12 20:04:31 +0000 | [diff] [blame] | 10 | #include "SkCodec.h" |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 11 | #include "SkColorSpace.h" |
| 12 | #include "SkEncodedImageFormat.h" |
| 13 | #include "SkImageEncoder.h" |
| 14 | #include "SkImageInfo.h" |
| 15 | #include "SkStream.h" |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 16 | |
Ben Wagner | 501c17c | 2018-03-12 20:04:31 +0000 | [diff] [blame] | 17 | #include "Test.h" |
Ben Wagner | 1a462bd | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 18 | |
Leon Scroggins III | c8037dc | 2017-12-05 13:55:24 -0500 | [diff] [blame] | 19 | DEF_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 | } |