Flutter Engine
The Flutter Engine
Functions
SamplingTest.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "src/base/SkRandom.h"
#include "src/core/SkSamplingPriv.h"
#include "tests/Test.h"
#include "tools/DecodeUtils.h"
#include "tools/ToolUtils.h"
#include <initializer_list>

Go to the source code of this file.

Functions

 DEF_TEST (sampling_with_identity_matrix, r)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( sampling_with_identity_matrix  ,
 
)

Definition at line 26 of file SamplingTest.cpp.

26 {
27 const char* names[] = {
28 "images/mandrill_128.png", "images/color_wheel.jpg",
29 };
30
31 SkRandom rand;
32 for (auto name : names) {
34 auto surf = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(src->width(), src->height()));
35 auto canvas = surf->getCanvas();
36
37 auto dotest = [&](const SkSamplingOptions& sampling, bool expect_same) {
38 canvas->clear(0);
39 canvas->drawImage(src.get(), 0, 0, sampling, nullptr);
40 auto dst = surf->makeImageSnapshot();
41
43 REPORTER_ASSERT(r, ToolUtils::equal_pixels(src.get(), dst.get()) == expect_same);
44 };
45
46 // Exercise all non-cubics -- expecting no changes
49 dotest(SkSamplingOptions(f, m), true);
50 }
51 }
52
53 // Exercise cubic variants with B zero and non-zero
54 constexpr int N = 30; // try a bunch of random values
55 for (int i = 0; i < N; ++i) {
56 float C = rand.nextF();
57 dotest(SkSamplingOptions({0, C}), true);
58
59 float B = rand.nextF() * 0.9f + 0.05f; // non-zero but still within (0,,,1]
60 SkASSERT(B != 0);
61 dotest(SkSamplingOptions({B, C}), false);
62 }
63 }
64}
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define N
Definition: beziers.cpp:19
float nextF()
Definition: SkRandom.h:55
static bool NoChangeWithIdentityMatrix(const SkSamplingOptions &sampling)
#define B
SkSamplingOptions sampling
Definition: SkRecords.h:337
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
bool equal_pixels(const SkPixmap &a, const SkPixmap &b)
Definition: ToolUtils.cpp:456
static const char *const names[]
Definition: symbols.cc:24
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
dst
Definition: cp.py:12
SkSamplingOptions(SkFilterMode::kLinear))
static SkImageInfo MakeN32Premul(int width, int height)