Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
EncodedInfoTest.cpp File Reference
#include "include/codec/SkCodec.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkDataTable.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkStream.h"
#include "include/encode/SkPngEncoder.h"
#include "tests/Test.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include <memory>

Go to the source code of this file.

Functions

 DEF_TEST (AlphaEncodedInfo, r)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( AlphaEncodedInfo  ,
 
)

Definition at line 22 of file EncodedInfoTest.cpp.

22 {
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
32 REPORTER_ASSERT(r, SkPngEncoder::Encode(&stream, bm.pixmap(), {}));
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}
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)