File: render_test.cpp

package info (click to toggle)
swayimg 4.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,764 kB
  • sloc: ansic: 13,338; cpp: 2,470; makefile: 9
file content (118 lines) | stat: -rw-r--r-- 2,995 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// SPDX-License-Identifier: MIT
// Copyright (C) 2024 Abe Wieland <abe.wieland@gmail.com>

extern "C" {
#include "render.h"
}

#include "pixmap_test.h"

class RenderTest : public PixmapTest {
protected:
    void ScaleCopy(enum aa_mode scaler, const struct pixmap& src, size_t w,
                   size_t h, float scale, ssize_t x, ssize_t y)
    {
        struct pixmap full, dst1, dst2;
        pixmap_create(&full, pixmap_argb, src.width * scale,
                      src.height * scale);
        pixmap_create(&dst1, pixmap_argb, w, h);
        pixmap_create(&dst2, pixmap_argb, w, h);
        software_render(&src, &full, 0, 0, scale, scaler, false);
        pixmap_copy(&full, &dst1, x, y);
        software_render(&src, &dst2, x, y, scale, scaler, false);
        Compare(dst2, dst1.data);
        pixmap_free(&full);
        pixmap_free(&dst1);
        pixmap_free(&dst2);
    }
};

TEST_F(RenderTest, ScaleCopyUp)
{
    // clang-format off
    argb_t src[] = {
        0x00, 0x01, 0x02, 0x03,
        0x10, 0x11, 0x12, 0x13,
        0x20, 0x21, 0x22, 0x23,
        0x30, 0x31, 0x32, 0x33,
    };
    // clang-format on

    const struct pixmap pm = { pixmap_argb, 4, 4, src };
    ScaleCopy(aa_bilinear, pm, 2, 2, 2.0, 0, 0);
}

TEST_F(RenderTest, ScaleCopyUpNeg)
{
    // clang-format off
    argb_t src[] = {
        0x00, 0x01, 0x02, 0x03,
        0x10, 0x11, 0x12, 0x13,
        0x20, 0x21, 0x22, 0x23,
        0x30, 0x31, 0x32, 0x33,
    };
    // clang-format on

    const struct pixmap pm = { pixmap_argb, 4, 4, src };
    ScaleCopy(aa_bilinear, pm, 2, 2, 2.0, -1, -1);
}

TEST_F(RenderTest, ScaleCopyUpPos)
{
    // clang-format off
    argb_t src[] = {
        0x00, 0x01, 0x02, 0x03,
        0x10, 0x11, 0x12, 0x13,
        0x20, 0x21, 0x22, 0x23,
        0x30, 0x31, 0x32, 0x33,
    };
    // clang-format on

    const struct pixmap pm = { pixmap_argb, 4, 4, src };
    ScaleCopy(aa_bilinear, pm, 2, 2, 2.0, 1, 1);
}

TEST_F(RenderTest, ScaleCopyDown)
{
    // clang-format off
    argb_t src[] = {
        0x00, 0x01, 0x02, 0x03,
        0x10, 0x11, 0x12, 0x13,
        0x20, 0x21, 0x22, 0x23,
        0x30, 0x31, 0x32, 0x33,
    };
    // clang-format on

    const struct pixmap pm = { pixmap_argb, 4, 4, src };
    ScaleCopy(aa_bilinear, pm, 2, 2, 0.5, 0, 0);
}

TEST_F(RenderTest, ScaleCopyDownNeg)
{
    // clang-format off
    argb_t src[] = {
        0x00, 0x01, 0x02, 0x03,
        0x10, 0x11, 0x12, 0x13,
        0x20, 0x21, 0x22, 0x23,
        0x30, 0x31, 0x32, 0x33,
    };
    // clang-format on

    const struct pixmap pm = { pixmap_argb, 4, 4, src };
    ScaleCopy(aa_bilinear, pm, 2, 2, 0.5, -1, -1);
}

TEST_F(RenderTest, ScaleCopyDownPos)
{
    // clang-format off
    argb_t src[] = {
        0x00, 0x01, 0x02, 0x03,
        0x10, 0x11, 0x12, 0x13,
        0x20, 0x21, 0x22, 0x23,
        0x30, 0x31, 0x32, 0x33,
    };
    // clang-format on

    const struct pixmap pm = { pixmap_argb, 4, 4, src };
    ScaleCopy(aa_bilinear, pm, 2, 2, 0.5, 1, 1);
}