Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
WebpTest.cpp File Reference
#include "include/codec/SkCodec.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkImageInfo.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 (WebpCodecBlend, r)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( WebpCodecBlend  ,
 
)

Definition at line 18 of file WebpTest.cpp.

18 {
19 const char* path = "images/blendBG.webp";
20 auto codec = SkCodec::MakeFromData(GetResourceAsData(path));
21 if (!codec) {
22 ERRORF(r, "Failed to open/decode %s", path);
23 return;
24 }
25
26 // Previously, a bug in SkWebpCodec resulted in different output depending
27 // on whether kPremul or kOpaque SkAlphaType was passed to getPixels().
28 // Decode each frame twice, once with kPremul and once with kOpaque if the
29 // frame is opaque, and verify they look the same.
30 auto premulInfo = codec->getInfo().makeAlphaType(kPremul_SkAlphaType);
31 SkBitmap premulBm, changeBm;
32 premulBm.allocPixels(premulInfo);
33 changeBm.allocPixels(premulInfo); // The SkBitmap's SkAlphaType is unrelated to the bug.
34
35 for (int i = 0; i < codec->getFrameCount(); i++) {
38 auto result = codec->getPixels(premulBm.pixmap(), &options);
40 ERRORF(r, "Failed to decode %s frame %i (premul) - error %s", path, i,
42 return;
43 }
44
45 SkCodec::FrameInfo frameInfo;
46 if (!codec->getFrameInfo(i, &frameInfo)) {
47 ERRORF(r, "Failed to getFrameInfo for %s frame %i", path, i);
48 return;
49 }
50
51 auto alphaType = frameInfo.fAlphaType == kOpaque_SkAlphaType ? kOpaque_SkAlphaType
53 result = codec->getPixels(premulInfo.makeAlphaType(alphaType), changeBm.getPixels(),
54 changeBm.rowBytes(), &options);
56 ERRORF(r, "Failed to decode %s frame %i (change) - error %s", path, i,
58 return;
59 }
60
61 REPORTER_ASSERT(r, ToolUtils::equal_pixels(premulBm, changeBm), "%s frame %i does not match"
62 " with mismatched SkAlphaType", path, i);
63 }
64}
const char * options
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition Resources.cpp:42
@ kOpaque_SkAlphaType
pixel is opaque
Definition SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define ERRORF(r,...)
Definition Test.h:293
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 > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
Definition SkCodec.cpp:241
static const char * ResultToString(Result)
Definition SkCodec.cpp:880
@ kSuccess
Definition SkCodec.h:80
GAsyncResult * result
bool equal_pixels(const SkPixmap &a, const SkPixmap &b)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
SkAlphaType fAlphaType
Definition SkCodec.h:689