Debian Codegraph @

modules/lsp-runtime-lib/src/test/utest/mm/bitmap.cpp

raw
1 /*
2 * Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2026 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 29 янв. 2026 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <lsp-plug.in/test-fw/utest.h>
23 #include <lsp-plug.in/common/endian.h>
24 #include <lsp-plug.in/mm/Bitmap.h>
25
26 static const char *bitmap =
27 "10000000"
28 "10022200"
29 "10200330"
30 "10200303"
31 "11122303"
32 "00000330"
33 "00000300"
34 "00222300";
35
36 static const uint32_t rgba_colors[] =
37 {
38 0x00000000,
39 0xff0000ff,
40 0xff00ff00,
41 0xffff0000
42 };
43
44 static const uint32_t bgra_colors[] =
45 {
46 0x00000000,
47 0xffff0000,
48 0xff00ff00,
49 0xff0000ff
50 };
51
52 UTEST_BEGIN("runtime.mm", bitmap)
53
54 void test_load_bitmap(const char *file, mm::pixel_format_t format)
55 {
56 io::Path path;
57
58 UTEST_ASSERT(path.fmt("%s/mm/bitmap/%s", resources(), file));
59 printf("Reading %s bitmap from file %s\n", mm::pixel_format_name(format), path.as_native());
60
61 mm::Bitmap bmp;
62 UTEST_ASSERT(bmp.load(&path, format) == STATUS_OK);
63 UTEST_ASSERT(bmp.width() == 8);
64 UTEST_ASSERT(bmp.height() == 8);
65
66 const uint32_t *colors =
67 ((format == mm::PIXFMT_RGBA8888) || (format == mm::PIXFMT_PRGBA8888)) ?
68 rgba_colors : bgra_colors;
69
70 for (size_t y=0; y<8; ++y)
71 {
72 const uint32_t * const row = reinterpret_cast<const uint32_t *>(bmp.row(y));
73 UTEST_ASSERT(row != NULL);
74
75 for (size_t x=0; x<8; ++x)
76 {
77 const uint32_t rc = colors[bitmap[y*8 + x] - '0'];
78 const uint32_t sc = LE_TO_CPU(row[x]);
79 UTEST_ASSERT_MSG(rc == sc, "Failed color check at point (%d, %d)", int(x), int(y));
80 }
81 }
82 }
83
84 UTEST_MAIN
85 {
86 test_load_bitmap("test.xpm", mm::PIXFMT_RGBA8888);
87 test_load_bitmap("test.xpm", mm::PIXFMT_PRGBA8888);
88 test_load_bitmap("test.xpm", mm::PIXFMT_BGRA8888);
89 test_load_bitmap("test.xpm", mm::PIXFMT_PBGRA8888);
90 }
91 UTEST_END;
92
93
94
95
96