blob: a8b74370a11c4a5261aebcdcfb3f58b842b4a269 [file] [log] [blame]
Leon Scroggins III36f7e322018-08-27 11:55:46 -04001/*
2 * Copyright 2018 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 "Resources.h"
9#include "Test.h"
10#include "sk_tool_utils.h"
11
12#include "SkBitmap.h"
13#include "SkCodec.h"
14#include "SkData.h"
15#include "SkEncodedImageFormat.h"
16#include "SkImageInfo.h"
17#include "SkImageEncoder.h"
18
19DEF_TEST(AlphaEncodedInfo, r) {
20 auto codec = SkCodec::MakeFromStream(GetResourceAsStream("images/grayscale.jpg"));
21 REPORTER_ASSERT(r, codec->getInfo().colorType() == kGray_8_SkColorType);
22
23 SkBitmap bm;
24 bm.allocPixels(codec->getInfo().makeColorType(kAlpha_8_SkColorType).makeColorSpace(nullptr));
25 auto result = codec->getPixels(codec->getInfo(), bm.getPixels(), bm.rowBytes());
26 REPORTER_ASSERT(r, result == SkCodec::kSuccess);
27
28 auto data = SkEncodeBitmap(bm, SkEncodedImageFormat::kPNG, 100);
29 REPORTER_ASSERT(r, data);
30
31 codec = SkCodec::MakeFromData(std::move(data));
32 REPORTER_ASSERT(r, codec);
33 // TODO: Make SkEncodedInfo public and compare to its version of kAlpha_8.
34 REPORTER_ASSERT(r, codec->getInfo().colorType() == kAlpha_8_SkColorType);
35
36 SkBitmap bm2;
37 bm2.allocPixels(codec->getInfo().makeColorSpace(nullptr));
38 result = codec->getPixels(bm2.pixmap());
39 REPORTER_ASSERT(r, result == SkCodec::kSuccess);
40
Brian Osman1b151982018-09-20 12:47:39 -040041 REPORTER_ASSERT(r, sk_tool_utils::equal_pixels(bm.pixmap(), bm2.pixmap()));
Leon Scroggins III36f7e322018-08-27 11:55:46 -040042}