• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "include/codec/SkCodec.h"
9 #include "include/core/SkBitmap.h"
10 #include "include/core/SkColorSpace.h"
11 #include "include/core/SkColorType.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"
18 #include "tools/Resources.h"
19 #include "tools/ToolUtils.h"
20 
21 #include <memory>
22 #include <utility>
23 
DEF_TEST(AlphaEncodedInfo,r)24 DEF_TEST(AlphaEncodedInfo, r) {
25     auto codec = SkCodec::MakeFromStream(GetResourceAsStream("images/grayscale.jpg"));
26     REPORTER_ASSERT(r, codec->getInfo().colorType() == kGray_8_SkColorType);
27 
28     SkBitmap bm;
29     bm.allocPixels(codec->getInfo().makeColorType(kAlpha_8_SkColorType).makeColorSpace(nullptr));
30     auto result = codec->getPixels(codec->getInfo(), bm.getPixels(), bm.rowBytes());
31     REPORTER_ASSERT(r, result == SkCodec::kSuccess);
32 
33     auto data = SkEncodeBitmap(bm, SkEncodedImageFormat::kPNG, 100);
34     REPORTER_ASSERT(r, data);
35 
36     codec = SkCodec::MakeFromData(std::move(data));
37     REPORTER_ASSERT(r, codec);
38     // TODO: Make SkEncodedInfo public and compare to its version of kAlpha_8.
39     REPORTER_ASSERT(r, codec->getInfo().colorType() == kAlpha_8_SkColorType);
40 
41     SkBitmap bm2;
42     bm2.allocPixels(codec->getInfo().makeColorSpace(nullptr));
43     result = codec->getPixels(bm2.pixmap());
44     REPORTER_ASSERT(r, result == SkCodec::kSuccess);
45 
46     REPORTER_ASSERT(r, ToolUtils::equal_pixels(bm.pixmap(), bm2.pixmap()));
47 }
48