Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
tests
SamplingTest.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2020 Google LLC
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/core/SkCanvas.h
"
9
#include "
include/core/SkImage.h
"
10
#include "
include/core/SkImageInfo.h
"
11
#include "
include/core/SkRefCnt.h
"
12
#include "
include/core/SkSamplingOptions.h
"
13
#include "
include/core/SkSurface.h
"
14
#include "
include/core/SkTypes.h
"
15
#include "
src/base/SkRandom.h
"
16
#include "
src/core/SkSamplingPriv.h
"
17
#include "
tests/Test.h
"
18
#include "
tools/DecodeUtils.h
"
19
#include "
tools/ToolUtils.h
"
20
21
#include <initializer_list>
22
23
// In general, sampling under identity matrix should not affect the pixels. However,
24
// cubic resampling when B != 0 is expected to change pixels.
25
//
26
DEF_TEST
(sampling_with_identity_matrix, r) {
27
const
char
* names[] = {
28
"images/mandrill_128.png"
,
"images/color_wheel.jpg"
,
29
};
30
31
SkRandom
rand;
32
for
(
auto
name
: names) {
33
auto
src =
ToolUtils::GetResourceAsImage
(
name
);
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
42
REPORTER_ASSERT
(r,
SkSamplingPriv::NoChangeWithIdentityMatrix
(sampling) == expect_same);
43
REPORTER_ASSERT
(r,
ToolUtils::equal_pixels
(src.get(), dst.get()) == expect_same);
44
};
45
46
// Exercise all non-cubics -- expecting no changes
47
for
(
auto
m : {
SkMipmapMode::kNone
,
SkMipmapMode::kNearest
,
SkMipmapMode::kLinear
}) {
48
for
(
auto
f : {
SkFilterMode::kNearest
,
SkFilterMode::kLinear
}) {
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
}
DecodeUtils.h
SkASSERT
#define SkASSERT(cond)
Definition
SkAssert.h:116
SkCanvas.h
SkImageInfo.h
SkImage.h
SkRandom.h
SkRefCnt.h
SkSamplingOptions.h
SkFilterMode::kLinear
@ kLinear
SkFilterMode::kNearest
@ kNearest
SkMipmapMode::kNone
@ kNone
SkMipmapMode::kLinear
@ kLinear
SkMipmapMode::kNearest
@ kNearest
SkSamplingPriv.h
SkSurface.h
SkTypes.h
Test.h
DEF_TEST
#define DEF_TEST(name, reporter)
Definition
Test.h:312
REPORTER_ASSERT
#define REPORTER_ASSERT(r, cond,...)
Definition
Test.h:286
ToolUtils.h
N
#define N
Definition
beziers.cpp:19
B
Definition
GrMemoryPoolTest.cpp:72
C
Definition
GrMemoryPoolTest.cpp:90
SkRandom
Definition
SkRandom.h:27
SkRandom::nextF
float nextF()
Definition
SkRandom.h:55
SkSamplingPriv::NoChangeWithIdentityMatrix
static bool NoChangeWithIdentityMatrix(const SkSamplingOptions &sampling)
Definition
SkSamplingPriv.h:48
name
const char * name
Definition
fuchsia.cc:50
B
#define B
Definition
kernel_binary_flowgraph.cc:27
SkSurfaces::Raster
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
Definition
SkSurface_Raster.cpp:186
ToolUtils::GetResourceAsImage
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition
DecodeUtils.h:25
ToolUtils::equal_pixels
bool equal_pixels(const SkPixmap &a, const SkPixmap &b)
Definition
ToolUtils.cpp:456
SkImageInfo::MakeN32Premul
static SkImageInfo MakeN32Premul(int width, int height)
Definition
SkImageInfo.cpp:157
SkSamplingOptions
Definition
SkSamplingOptions.h:58
Generated on Fri Apr 26 2024 06:18:01 for Flutter Engine by
1.9.8