Flutter Engine
The Flutter Engine
EncodedInfoTest.cpp
Go to the documentation of this file.
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
16#include "tests/Test.h"
17#include "tools/Resources.h"
18#include "tools/ToolUtils.h"
19
20#include <memory>
21
22DEF_TEST(AlphaEncodedInfo, r) {
23 auto codec = SkCodec::MakeFromStream(GetResourceAsStream("images/grayscale.jpg"));
24 REPORTER_ASSERT(r, codec->getInfo().colorType() == kGray_8_SkColorType);
25
26 SkBitmap bm;
27 bm.allocPixels(codec->getInfo().makeColorType(kAlpha_8_SkColorType).makeColorSpace(nullptr));
28 auto result = codec->getPixels(codec->getInfo(), bm.getPixels(), bm.rowBytes());
30
33 REPORTER_ASSERT(r, stream.bytesWritten() > 0);
34
35 codec = SkCodec::MakeFromData(stream.detachAsData());
36 REPORTER_ASSERT(r, codec);
37 // TODO: Make SkEncodedInfo public and compare to its version of kAlpha_8.
38 REPORTER_ASSERT(r, codec->getInfo().colorType() == kAlpha_8_SkColorType);
39
40 SkBitmap bm2;
41 bm2.allocPixels(codec->getInfo().makeColorSpace(nullptr));
42 result = codec->getPixels(bm2.pixmap());
44
46}
DEF_TEST(AlphaEncodedInfo, r)
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
Definition: Resources.cpp:31
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition: SkColorType.h:21
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition: SkColorType.h:35
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
const SkPixmap & pixmap() const
Definition: SkBitmap.h:133
size_t rowBytes() const
Definition: SkBitmap.h:238
void * getPixels() const
Definition: SkBitmap.h:283
static std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream >, SkSpan< const SkCodecs::Decoder > decoders, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
Definition: SkCodec.cpp:163
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
Definition: SkCodec.cpp:241
@ kSuccess
Definition: SkCodec.h:80
GAsyncResult * result
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
bool equal_pixels(const SkPixmap &a, const SkPixmap &b)
Definition: ToolUtils.cpp:456