1141cc406Sopenharmony_ci/* sane - Scanner Access Now Easy.
2141cc406Sopenharmony_ci
3141cc406Sopenharmony_ci   Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
4141cc406Sopenharmony_ci
5141cc406Sopenharmony_ci   This file is part of the SANE package.
6141cc406Sopenharmony_ci
7141cc406Sopenharmony_ci   This program is free software; you can redistribute it and/or
8141cc406Sopenharmony_ci   modify it under the terms of the GNU General Public License as
9141cc406Sopenharmony_ci   published by the Free Software Foundation; either version 2 of the
10141cc406Sopenharmony_ci   License, or (at your option) any later version.
11141cc406Sopenharmony_ci
12141cc406Sopenharmony_ci   This program is distributed in the hope that it will be useful, but
13141cc406Sopenharmony_ci   WITHOUT ANY WARRANTY; without even the implied warranty of
14141cc406Sopenharmony_ci   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15141cc406Sopenharmony_ci   General Public License for more details.
16141cc406Sopenharmony_ci
17141cc406Sopenharmony_ci   You should have received a copy of the GNU General Public License
18141cc406Sopenharmony_ci   along with this program.  If not, see <https://www.gnu.org/licenses/>.
19141cc406Sopenharmony_ci*/
20141cc406Sopenharmony_ci
21141cc406Sopenharmony_ci#define DEBUG_DECLARE_ONLY
22141cc406Sopenharmony_ci
23141cc406Sopenharmony_ci#include "tests.h"
24141cc406Sopenharmony_ci#include "tests_printers.h"
25141cc406Sopenharmony_ci#include "minigtest.h"
26141cc406Sopenharmony_ci
27141cc406Sopenharmony_ci#include "../../../backend/genesys/image.h"
28141cc406Sopenharmony_ci#include "../../../backend/genesys/image_pipeline.h"
29141cc406Sopenharmony_ci#include <vector>
30141cc406Sopenharmony_ci
31141cc406Sopenharmony_cinamespace genesys {
32141cc406Sopenharmony_ci
33141cc406Sopenharmony_civoid test_get_pixel_from_row()
34141cc406Sopenharmony_ci{
35141cc406Sopenharmony_ci    std::vector<std::uint8_t> data = {
36141cc406Sopenharmony_ci        0x12, 0x34, 0x56, 0x67, 0x89, 0xab,
37141cc406Sopenharmony_ci        0xcd, 0xef, 0x21, 0x43, 0x65, 0x87
38141cc406Sopenharmony_ci    };
39141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 0, PixelFormat::I1),
40141cc406Sopenharmony_ci              Pixel(0, 0, 0));
41141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 3, PixelFormat::I1),
42141cc406Sopenharmony_ci              Pixel(0xffff, 0xffff, 0xffff));
43141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 0, PixelFormat::RGB111),
44141cc406Sopenharmony_ci              Pixel(0, 0, 0));
45141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 1, PixelFormat::RGB111),
46141cc406Sopenharmony_ci              Pixel(0xffff, 0, 0));
47141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 2, PixelFormat::RGB111),
48141cc406Sopenharmony_ci              Pixel(0xffff, 0, 0));
49141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 3, PixelFormat::RGB111),
50141cc406Sopenharmony_ci              Pixel(0, 0xffff, 0xffff));
51141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 0, PixelFormat::I8),
52141cc406Sopenharmony_ci              Pixel(0x1212, 0x1212, 0x1212));
53141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 1, PixelFormat::I8),
54141cc406Sopenharmony_ci              Pixel(0x3434, 0x3434, 0x3434));
55141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 0, PixelFormat::RGB888),
56141cc406Sopenharmony_ci              Pixel(0x1212, 0x3434, 0x5656));
57141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 1, PixelFormat::RGB888),
58141cc406Sopenharmony_ci              Pixel(0x6767, 0x8989, 0xabab));
59141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 0, PixelFormat::BGR888),
60141cc406Sopenharmony_ci              Pixel(0x5656, 0x3434, 0x1212));
61141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 1, PixelFormat::BGR888),
62141cc406Sopenharmony_ci              Pixel(0xabab, 0x8989, 0x6767));
63141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 0, PixelFormat::I16),
64141cc406Sopenharmony_ci              Pixel(0x3412, 0x3412, 0x3412));
65141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 1, PixelFormat::I16),
66141cc406Sopenharmony_ci              Pixel(0x6756, 0x6756, 0x6756));
67141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 0, PixelFormat::RGB161616),
68141cc406Sopenharmony_ci              Pixel(0x3412, 0x6756, 0xab89));
69141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 1, PixelFormat::RGB161616),
70141cc406Sopenharmony_ci              Pixel(0xefcd, 0x4321, 0x8765));
71141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 0, PixelFormat::BGR161616),
72141cc406Sopenharmony_ci              Pixel(0xab89, 0x6756, 0x3412));
73141cc406Sopenharmony_ci    ASSERT_EQ(get_pixel_from_row(data.data(), 1, PixelFormat::BGR161616),
74141cc406Sopenharmony_ci              Pixel(0x8765, 0x4321, 0xefcd));
75141cc406Sopenharmony_ci}
76141cc406Sopenharmony_ci
77141cc406Sopenharmony_civoid test_set_pixel_to_row()
78141cc406Sopenharmony_ci{
79141cc406Sopenharmony_ci    using Data = std::vector<std::uint8_t>;
80141cc406Sopenharmony_ci    Data data;
81141cc406Sopenharmony_ci    data.resize(12, 0);
82141cc406Sopenharmony_ci
83141cc406Sopenharmony_ci    auto reset = [&]() { std::fill(data.begin(), data.end(), 0); };
84141cc406Sopenharmony_ci
85141cc406Sopenharmony_ci    Pixel pixel;
86141cc406Sopenharmony_ci
87141cc406Sopenharmony_ci    pixel = Pixel(0x8000, 0x8000, 0x8000);
88141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 0, pixel, PixelFormat::I1);
89141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
90141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
91141cc406Sopenharmony_ci    reset();
92141cc406Sopenharmony_ci
93141cc406Sopenharmony_ci    pixel = Pixel(0x8000, 0x8000, 0x8000);
94141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 2, pixel, PixelFormat::I1);
95141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
96141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
97141cc406Sopenharmony_ci    reset();
98141cc406Sopenharmony_ci
99141cc406Sopenharmony_ci    pixel = Pixel(0x8000, 0x8000, 0x8000);
100141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 8, pixel, PixelFormat::I1);
101141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
102141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
103141cc406Sopenharmony_ci    reset();
104141cc406Sopenharmony_ci
105141cc406Sopenharmony_ci    pixel = Pixel(0x8000, 0x0000, 0x8000);
106141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 0, pixel, PixelFormat::RGB111);
107141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0xa0, 0x00, 0x00, 0x00, 0x00, 0x00,
108141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
109141cc406Sopenharmony_ci    reset();
110141cc406Sopenharmony_ci
111141cc406Sopenharmony_ci    pixel = Pixel(0x8000, 0x0000, 0x8000);
112141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 1, pixel, PixelFormat::RGB111);
113141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x14, 0x00, 0x00, 0x00, 0x00, 0x00,
114141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
115141cc406Sopenharmony_ci    reset();
116141cc406Sopenharmony_ci
117141cc406Sopenharmony_ci    pixel = Pixel(0x8000, 0x0000, 0x8000);
118141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 8, pixel, PixelFormat::RGB111);
119141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0xa0, 0x00, 0x00,
120141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
121141cc406Sopenharmony_ci    reset();
122141cc406Sopenharmony_ci
123141cc406Sopenharmony_ci    pixel = Pixel(0x1200, 0x1200, 0x1200);
124141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 0, pixel, PixelFormat::I8);
125141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x12, 0x00, 0x00, 0x00, 0x00, 0x00,
126141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
127141cc406Sopenharmony_ci    reset();
128141cc406Sopenharmony_ci
129141cc406Sopenharmony_ci    pixel = Pixel(0x1200, 0x1200, 0x1200);
130141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 2, pixel, PixelFormat::I8);
131141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
132141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
133141cc406Sopenharmony_ci    reset();
134141cc406Sopenharmony_ci
135141cc406Sopenharmony_ci    pixel = Pixel(0x1200, 0x3400, 0x5600);
136141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 0, pixel, PixelFormat::RGB888);
137141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x12, 0x34, 0x56, 0x00, 0x00, 0x00,
138141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
139141cc406Sopenharmony_ci    reset();
140141cc406Sopenharmony_ci
141141cc406Sopenharmony_ci    pixel = Pixel(0x1200, 0x3400, 0x5600);
142141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 1, pixel, PixelFormat::RGB888);
143141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x12, 0x34, 0x56,
144141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
145141cc406Sopenharmony_ci    reset();
146141cc406Sopenharmony_ci
147141cc406Sopenharmony_ci    pixel = Pixel(0x1200, 0x3400, 0x5600);
148141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 0, pixel, PixelFormat::BGR888);
149141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x56, 0x34, 0x12, 0x00, 0x00, 0x00,
150141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
151141cc406Sopenharmony_ci    reset();
152141cc406Sopenharmony_ci
153141cc406Sopenharmony_ci    pixel = Pixel(0x1200, 0x3400, 0x5600);
154141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 1, pixel, PixelFormat::BGR888);
155141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x56, 0x34, 0x12,
156141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
157141cc406Sopenharmony_ci    reset();
158141cc406Sopenharmony_ci
159141cc406Sopenharmony_ci    pixel = Pixel(0x1234, 0x1234, 0x1234);
160141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 0, pixel, PixelFormat::I16);
161141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x34, 0x12, 0x00, 0x00, 0x00, 0x00,
162141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
163141cc406Sopenharmony_ci    reset();
164141cc406Sopenharmony_ci
165141cc406Sopenharmony_ci    pixel = Pixel(0x1234, 0x1234, 0x1234);
166141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 1, pixel, PixelFormat::I16);
167141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x34, 0x12, 0x00, 0x00,
168141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
169141cc406Sopenharmony_ci    reset();
170141cc406Sopenharmony_ci
171141cc406Sopenharmony_ci    pixel = Pixel(0x1234, 0x5678, 0x9abc);
172141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 0, pixel, PixelFormat::RGB161616);
173141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x34, 0x12, 0x78, 0x56, 0xbc, 0x9a,
174141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
175141cc406Sopenharmony_ci    reset();
176141cc406Sopenharmony_ci
177141cc406Sopenharmony_ci    pixel = Pixel(0x1234, 0x5678, 0x9abc);
178141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 1, pixel, PixelFormat::RGB161616);
179141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180141cc406Sopenharmony_ci                          0x34, 0x12, 0x78, 0x56, 0xbc, 0x9a}));
181141cc406Sopenharmony_ci    reset();
182141cc406Sopenharmony_ci
183141cc406Sopenharmony_ci    pixel = Pixel(0x1234, 0x5678, 0x9abc);
184141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 0, pixel, PixelFormat::BGR161616);
185141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
186141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
187141cc406Sopenharmony_ci    reset();
188141cc406Sopenharmony_ci
189141cc406Sopenharmony_ci    pixel = Pixel(0x1234, 0x5678, 0x9abc);
190141cc406Sopenharmony_ci    set_pixel_to_row(data.data(), 1, pixel, PixelFormat::BGR161616);
191141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
192141cc406Sopenharmony_ci                          0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12}));
193141cc406Sopenharmony_ci    reset();
194141cc406Sopenharmony_ci}
195141cc406Sopenharmony_ci
196141cc406Sopenharmony_civoid test_get_raw_pixel_from_row()
197141cc406Sopenharmony_ci{
198141cc406Sopenharmony_ci    std::vector<std::uint8_t> data = {
199141cc406Sopenharmony_ci        0x12, 0x34, 0x56, 0x67, 0x89, 0xab,
200141cc406Sopenharmony_ci        0xcd, 0xef, 0x21, 0x43, 0x65, 0x87
201141cc406Sopenharmony_ci    };
202141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 0, PixelFormat::I1),
203141cc406Sopenharmony_ci              RawPixel(0x0));
204141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 3, PixelFormat::I1),
205141cc406Sopenharmony_ci              RawPixel(0x1));
206141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 0, PixelFormat::RGB111),
207141cc406Sopenharmony_ci              RawPixel(0));
208141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 1, PixelFormat::RGB111),
209141cc406Sopenharmony_ci              RawPixel(0x4));
210141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 2, PixelFormat::RGB111),
211141cc406Sopenharmony_ci              RawPixel(0x4));
212141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 3, PixelFormat::RGB111),
213141cc406Sopenharmony_ci              RawPixel(0x3));
214141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 0, PixelFormat::I8),
215141cc406Sopenharmony_ci              RawPixel(0x12));
216141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 1, PixelFormat::I8),
217141cc406Sopenharmony_ci              RawPixel(0x34));
218141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 0, PixelFormat::RGB888),
219141cc406Sopenharmony_ci              RawPixel(0x12, 0x34, 0x56));
220141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 1, PixelFormat::RGB888),
221141cc406Sopenharmony_ci              RawPixel(0x67, 0x89, 0xab));
222141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 0, PixelFormat::BGR888),
223141cc406Sopenharmony_ci              RawPixel(0x12, 0x34, 0x56));
224141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 1, PixelFormat::BGR888),
225141cc406Sopenharmony_ci              RawPixel(0x67, 0x89, 0xab));
226141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 0, PixelFormat::I16),
227141cc406Sopenharmony_ci              RawPixel(0x12, 0x34));
228141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 1, PixelFormat::I16),
229141cc406Sopenharmony_ci              RawPixel(0x56, 0x67));
230141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 0, PixelFormat::RGB161616),
231141cc406Sopenharmony_ci              RawPixel(0x12, 0x34, 0x56, 0x67, 0x89, 0xab));
232141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 1, PixelFormat::RGB161616),
233141cc406Sopenharmony_ci              RawPixel(0xcd, 0xef, 0x21, 0x43, 0x65, 0x87));
234141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 0, PixelFormat::BGR161616),
235141cc406Sopenharmony_ci              RawPixel(0x12, 0x34, 0x56, 0x67, 0x89, 0xab));
236141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_pixel_from_row(data.data(), 1, PixelFormat::BGR161616),
237141cc406Sopenharmony_ci              RawPixel(0xcd, 0xef, 0x21, 0x43, 0x65, 0x87));
238141cc406Sopenharmony_ci}
239141cc406Sopenharmony_ci
240141cc406Sopenharmony_civoid test_set_raw_pixel_to_row()
241141cc406Sopenharmony_ci{
242141cc406Sopenharmony_ci    using Data = std::vector<std::uint8_t>;
243141cc406Sopenharmony_ci    Data data;
244141cc406Sopenharmony_ci    data.resize(12, 0);
245141cc406Sopenharmony_ci
246141cc406Sopenharmony_ci    auto reset = [&]() { std::fill(data.begin(), data.end(), 0); };
247141cc406Sopenharmony_ci
248141cc406Sopenharmony_ci    RawPixel pixel;
249141cc406Sopenharmony_ci
250141cc406Sopenharmony_ci    pixel = RawPixel(0x01);
251141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 0, pixel, PixelFormat::I1);
252141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
253141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
254141cc406Sopenharmony_ci    reset();
255141cc406Sopenharmony_ci
256141cc406Sopenharmony_ci    pixel = RawPixel(0x01);
257141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 2, pixel, PixelFormat::I1);
258141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
259141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
260141cc406Sopenharmony_ci    reset();
261141cc406Sopenharmony_ci
262141cc406Sopenharmony_ci    pixel = RawPixel(0x01);
263141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 8, pixel, PixelFormat::I1);
264141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
265141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
266141cc406Sopenharmony_ci    reset();
267141cc406Sopenharmony_ci
268141cc406Sopenharmony_ci    pixel = RawPixel(0x05);
269141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 0, pixel, PixelFormat::RGB111);
270141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0xa0, 0x00, 0x00, 0x00, 0x00, 0x00,
271141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
272141cc406Sopenharmony_ci    reset();
273141cc406Sopenharmony_ci
274141cc406Sopenharmony_ci    pixel = RawPixel(0x05);
275141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 1, pixel, PixelFormat::RGB111);
276141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x14, 0x00, 0x00, 0x00, 0x00, 0x00,
277141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
278141cc406Sopenharmony_ci    reset();
279141cc406Sopenharmony_ci
280141cc406Sopenharmony_ci    pixel = RawPixel(0x05);
281141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 8, pixel, PixelFormat::RGB111);
282141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0xa0, 0x00, 0x00,
283141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
284141cc406Sopenharmony_ci    reset();
285141cc406Sopenharmony_ci
286141cc406Sopenharmony_ci    pixel = RawPixel(0x12);
287141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 0, pixel, PixelFormat::I8);
288141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x12, 0x00, 0x00, 0x00, 0x00, 0x00,
289141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
290141cc406Sopenharmony_ci    reset();
291141cc406Sopenharmony_ci
292141cc406Sopenharmony_ci    pixel = RawPixel(0x12);
293141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 2, pixel, PixelFormat::I8);
294141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
295141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
296141cc406Sopenharmony_ci    reset();
297141cc406Sopenharmony_ci
298141cc406Sopenharmony_ci    pixel = RawPixel(0x12, 0x34, 0x56);
299141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 0, pixel, PixelFormat::RGB888);
300141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x12, 0x34, 0x56, 0x00, 0x00, 0x00,
301141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
302141cc406Sopenharmony_ci    reset();
303141cc406Sopenharmony_ci
304141cc406Sopenharmony_ci    pixel = RawPixel(0x12, 0x34, 0x56);
305141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 1, pixel, PixelFormat::RGB888);
306141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x12, 0x34, 0x56,
307141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
308141cc406Sopenharmony_ci    reset();
309141cc406Sopenharmony_ci
310141cc406Sopenharmony_ci    pixel = RawPixel(0x12, 0x34, 0x56);
311141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 0, pixel, PixelFormat::BGR888);
312141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x12, 0x34, 0x56, 0x00, 0x00, 0x00,
313141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
314141cc406Sopenharmony_ci    reset();
315141cc406Sopenharmony_ci
316141cc406Sopenharmony_ci    pixel = RawPixel(0x12, 0x34, 0x56);
317141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 1, pixel, PixelFormat::BGR888);
318141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x12, 0x34, 0x56,
319141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
320141cc406Sopenharmony_ci    reset();
321141cc406Sopenharmony_ci
322141cc406Sopenharmony_ci    pixel = RawPixel(0x34, 0x12);
323141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 0, pixel, PixelFormat::I16);
324141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x34, 0x12, 0x00, 0x00, 0x00, 0x00,
325141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
326141cc406Sopenharmony_ci    reset();
327141cc406Sopenharmony_ci
328141cc406Sopenharmony_ci    pixel = RawPixel(0x34, 0x12);
329141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 1, pixel, PixelFormat::I16);
330141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x34, 0x12, 0x00, 0x00,
331141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
332141cc406Sopenharmony_ci    reset();
333141cc406Sopenharmony_ci
334141cc406Sopenharmony_ci    pixel = RawPixel(0x34, 0x12, 0x78, 0x56, 0xbc, 0x9a);
335141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 0, pixel, PixelFormat::RGB161616);
336141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x34, 0x12, 0x78, 0x56, 0xbc, 0x9a,
337141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
338141cc406Sopenharmony_ci    reset();
339141cc406Sopenharmony_ci
340141cc406Sopenharmony_ci    pixel = RawPixel(0x34, 0x12, 0x78, 0x56, 0xbc, 0x9a);
341141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 1, pixel, PixelFormat::RGB161616);
342141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
343141cc406Sopenharmony_ci                          0x34, 0x12, 0x78, 0x56, 0xbc, 0x9a}));
344141cc406Sopenharmony_ci    reset();
345141cc406Sopenharmony_ci
346141cc406Sopenharmony_ci    pixel = RawPixel(0x34, 0x12, 0x78, 0x56, 0xbc, 0x9a);
347141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 0, pixel, PixelFormat::BGR161616);
348141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x34, 0x12, 0x78, 0x56, 0xbc, 0x9a,
349141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
350141cc406Sopenharmony_ci    reset();
351141cc406Sopenharmony_ci
352141cc406Sopenharmony_ci    pixel = RawPixel(0x34, 0x12, 0x78, 0x56, 0xbc, 0x9a);
353141cc406Sopenharmony_ci    set_raw_pixel_to_row(data.data(), 1, pixel, PixelFormat::BGR161616);
354141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
355141cc406Sopenharmony_ci                          0x34, 0x12, 0x78, 0x56, 0xbc, 0x9a}));
356141cc406Sopenharmony_ci    reset();
357141cc406Sopenharmony_ci}
358141cc406Sopenharmony_ci
359141cc406Sopenharmony_civoid test_get_raw_channel_from_row()
360141cc406Sopenharmony_ci{
361141cc406Sopenharmony_ci    std::vector<std::uint8_t> data = {
362141cc406Sopenharmony_ci        0x12, 0x34, 0x56, 0x67, 0x89, 0xab,
363141cc406Sopenharmony_ci        0xcd, 0xef, 0x21, 0x43, 0x65, 0x87
364141cc406Sopenharmony_ci    };
365141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 0, PixelFormat::I1), 0);
366141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 3, 0, PixelFormat::I1), 1);
367141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 0, PixelFormat::RGB111), 0);
368141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 1, PixelFormat::RGB111), 0);
369141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 2, PixelFormat::RGB111), 0);
370141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 0, PixelFormat::RGB111), 1);
371141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 1, PixelFormat::RGB111), 0);
372141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 2, PixelFormat::RGB111), 0);
373141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 2, 0, PixelFormat::RGB111), 1);
374141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 2, 1, PixelFormat::RGB111), 0);
375141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 2, 2, PixelFormat::RGB111), 0);
376141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 3, 0, PixelFormat::RGB111), 0);
377141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 3, 1, PixelFormat::RGB111), 1);
378141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 3, 2, PixelFormat::RGB111), 1);
379141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 0, PixelFormat::I8), 0x12);
380141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 0, PixelFormat::I8), 0x34);
381141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 0, PixelFormat::RGB888), 0x12);
382141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 1, PixelFormat::RGB888), 0x34);
383141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 2, PixelFormat::RGB888), 0x56);
384141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 0, PixelFormat::RGB888), 0x67);
385141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 1, PixelFormat::RGB888), 0x89);
386141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 2, PixelFormat::RGB888), 0xab);
387141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 0, PixelFormat::BGR888), 0x12);
388141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 1, PixelFormat::BGR888), 0x34);
389141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 2, PixelFormat::BGR888), 0x56);
390141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 0, PixelFormat::BGR888), 0x67);
391141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 1, PixelFormat::BGR888), 0x89);
392141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 2, PixelFormat::BGR888), 0xab);
393141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 0, PixelFormat::I16), 0x3412);
394141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 0, PixelFormat::I16), 0x6756);
395141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 0, PixelFormat::RGB161616), 0x3412);
396141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 1, PixelFormat::RGB161616), 0x6756);
397141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 2, PixelFormat::RGB161616), 0xab89);
398141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 0, PixelFormat::RGB161616), 0xefcd);
399141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 1, PixelFormat::RGB161616), 0x4321);
400141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 2, PixelFormat::RGB161616), 0x8765);
401141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 0, PixelFormat::BGR161616), 0x3412);
402141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 1, PixelFormat::BGR161616), 0x6756);
403141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 0, 2, PixelFormat::BGR161616), 0xab89);
404141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 0, PixelFormat::BGR161616), 0xefcd);
405141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 1, PixelFormat::BGR161616), 0x4321);
406141cc406Sopenharmony_ci    ASSERT_EQ(get_raw_channel_from_row(data.data(), 1, 2, PixelFormat::BGR161616), 0x8765);
407141cc406Sopenharmony_ci}
408141cc406Sopenharmony_ci
409141cc406Sopenharmony_civoid test_set_raw_channel_to_row()
410141cc406Sopenharmony_ci{
411141cc406Sopenharmony_ci    using Data = std::vector<std::uint8_t>;
412141cc406Sopenharmony_ci    Data data;
413141cc406Sopenharmony_ci    data.resize(12, 0);
414141cc406Sopenharmony_ci
415141cc406Sopenharmony_ci    auto reset = [&]() { std::fill(data.begin(), data.end(), 0); };
416141cc406Sopenharmony_ci
417141cc406Sopenharmony_ci    set_raw_channel_to_row(data.data(), 0, 0, 1, PixelFormat::I1);
418141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
419141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
420141cc406Sopenharmony_ci    reset();
421141cc406Sopenharmony_ci
422141cc406Sopenharmony_ci    set_raw_channel_to_row(data.data(), 2, 0, 1, PixelFormat::I1);
423141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
424141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
425141cc406Sopenharmony_ci    reset();
426141cc406Sopenharmony_ci
427141cc406Sopenharmony_ci    set_raw_channel_to_row(data.data(), 8, 0, 1, PixelFormat::I1);
428141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
429141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
430141cc406Sopenharmony_ci    reset();
431141cc406Sopenharmony_ci
432141cc406Sopenharmony_ci    set_raw_channel_to_row(data.data(), 0, 0, 1, PixelFormat::RGB111);
433141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
434141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
435141cc406Sopenharmony_ci    reset();
436141cc406Sopenharmony_ci
437141cc406Sopenharmony_ci    set_raw_channel_to_row(data.data(), 0, 1, 1, PixelFormat::RGB111);
438141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
439141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
440141cc406Sopenharmony_ci    reset();
441141cc406Sopenharmony_ci
442141cc406Sopenharmony_ci    set_raw_channel_to_row(data.data(), 0, 2, 1, PixelFormat::RGB111);
443141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
444141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
445141cc406Sopenharmony_ci    reset();
446141cc406Sopenharmony_ci
447141cc406Sopenharmony_ci    set_raw_channel_to_row(data.data(), 8, 0, 1, PixelFormat::RGB111);
448141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
449141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
450141cc406Sopenharmony_ci    reset();
451141cc406Sopenharmony_ci
452141cc406Sopenharmony_ci    set_raw_channel_to_row(data.data(), 0, 0, 0x12, PixelFormat::I8);
453141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x12, 0x00, 0x00, 0x00, 0x00, 0x00,
454141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
455141cc406Sopenharmony_ci    reset();
456141cc406Sopenharmony_ci
457141cc406Sopenharmony_ci    set_raw_channel_to_row(data.data(), 2, 0, 0x12, PixelFormat::I8);
458141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
459141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
460141cc406Sopenharmony_ci    reset();
461141cc406Sopenharmony_ci
462141cc406Sopenharmony_ci    for (auto format : { PixelFormat::RGB888, PixelFormat::BGR888 }) {
463141cc406Sopenharmony_ci        set_raw_channel_to_row(data.data(), 0, 0, 0x12, format);
464141cc406Sopenharmony_ci        ASSERT_EQ(data, Data({0x12, 0x00, 0x00, 0x00, 0x00, 0x00,
465141cc406Sopenharmony_ci                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
466141cc406Sopenharmony_ci        reset();
467141cc406Sopenharmony_ci
468141cc406Sopenharmony_ci        set_raw_channel_to_row(data.data(), 0, 1, 0x12, format);
469141cc406Sopenharmony_ci        ASSERT_EQ(data, Data({0x00, 0x12, 0x00, 0x00, 0x00, 0x00,
470141cc406Sopenharmony_ci                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
471141cc406Sopenharmony_ci        reset();
472141cc406Sopenharmony_ci
473141cc406Sopenharmony_ci        set_raw_channel_to_row(data.data(), 0, 2, 0x12, format);
474141cc406Sopenharmony_ci        ASSERT_EQ(data, Data({0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
475141cc406Sopenharmony_ci                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
476141cc406Sopenharmony_ci        reset();
477141cc406Sopenharmony_ci
478141cc406Sopenharmony_ci        set_raw_channel_to_row(data.data(), 1, 0, 0x12, format);
479141cc406Sopenharmony_ci        ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x12, 0x00, 0x00,
480141cc406Sopenharmony_ci                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
481141cc406Sopenharmony_ci        reset();
482141cc406Sopenharmony_ci
483141cc406Sopenharmony_ci        set_raw_channel_to_row(data.data(), 1, 1, 0x12, format);
484141cc406Sopenharmony_ci        ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x00, 0x12, 0x00,
485141cc406Sopenharmony_ci                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
486141cc406Sopenharmony_ci        reset();
487141cc406Sopenharmony_ci
488141cc406Sopenharmony_ci        set_raw_channel_to_row(data.data(), 1, 2, 0x12, format);
489141cc406Sopenharmony_ci        ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x00, 0x00, 0x12,
490141cc406Sopenharmony_ci                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
491141cc406Sopenharmony_ci        reset();
492141cc406Sopenharmony_ci    }
493141cc406Sopenharmony_ci
494141cc406Sopenharmony_ci    set_raw_channel_to_row(data.data(), 0, 0, 0x1234, PixelFormat::I16);
495141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x34, 0x12, 0x00, 0x00, 0x00, 0x00,
496141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
497141cc406Sopenharmony_ci    reset();
498141cc406Sopenharmony_ci
499141cc406Sopenharmony_ci    set_raw_channel_to_row(data.data(), 1, 0, 0x1234, PixelFormat::I16);
500141cc406Sopenharmony_ci    ASSERT_EQ(data, Data({0x00, 0x00, 0x34, 0x12, 0x00, 0x00,
501141cc406Sopenharmony_ci                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
502141cc406Sopenharmony_ci    reset();
503141cc406Sopenharmony_ci
504141cc406Sopenharmony_ci    for (auto format : { PixelFormat::RGB161616, PixelFormat::BGR161616 }) {
505141cc406Sopenharmony_ci        set_raw_channel_to_row(data.data(), 0, 0, 0x1234, format);
506141cc406Sopenharmony_ci        ASSERT_EQ(data, Data({0x34, 0x12, 0x00, 0x00, 0x00, 0x00,
507141cc406Sopenharmony_ci                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
508141cc406Sopenharmony_ci        reset();
509141cc406Sopenharmony_ci
510141cc406Sopenharmony_ci        set_raw_channel_to_row(data.data(), 0, 1, 0x1234, format);
511141cc406Sopenharmony_ci        ASSERT_EQ(data, Data({0x00, 0x00, 0x34, 0x12, 0x00, 0x00,
512141cc406Sopenharmony_ci                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
513141cc406Sopenharmony_ci        reset();
514141cc406Sopenharmony_ci
515141cc406Sopenharmony_ci        set_raw_channel_to_row(data.data(), 0, 2, 0x1234, format);
516141cc406Sopenharmony_ci        ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x00, 0x34, 0x12,
517141cc406Sopenharmony_ci                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
518141cc406Sopenharmony_ci        reset();
519141cc406Sopenharmony_ci
520141cc406Sopenharmony_ci        set_raw_channel_to_row(data.data(), 1, 0, 0x1234, format);
521141cc406Sopenharmony_ci        ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
522141cc406Sopenharmony_ci                              0x34, 0x12, 0x00, 0x00, 0x00, 0x00}));
523141cc406Sopenharmony_ci        reset();
524141cc406Sopenharmony_ci
525141cc406Sopenharmony_ci        set_raw_channel_to_row(data.data(), 1, 1, 0x1234, format);
526141cc406Sopenharmony_ci        ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
527141cc406Sopenharmony_ci                              0x00, 0x00, 0x34, 0x12, 0x00, 0x00}));
528141cc406Sopenharmony_ci        reset();
529141cc406Sopenharmony_ci
530141cc406Sopenharmony_ci        set_raw_channel_to_row(data.data(), 1, 2, 0x1234, format);
531141cc406Sopenharmony_ci        ASSERT_EQ(data, Data({0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
532141cc406Sopenharmony_ci                              0x00, 0x00, 0x00, 0x00, 0x34, 0x12}));
533141cc406Sopenharmony_ci        reset();
534141cc406Sopenharmony_ci    }
535141cc406Sopenharmony_ci}
536141cc406Sopenharmony_ci
537141cc406Sopenharmony_civoid test_convert_pixel_row_format()
538141cc406Sopenharmony_ci{
539141cc406Sopenharmony_ci    // The actual work is done in set_channel_to_row and get_channel_from_row, so we don't need
540141cc406Sopenharmony_ci    // to test all format combinations.
541141cc406Sopenharmony_ci    using Data = std::vector<std::uint8_t>;
542141cc406Sopenharmony_ci
543141cc406Sopenharmony_ci    Data in_data = {
544141cc406Sopenharmony_ci        0x12, 0x34, 0x56,
545141cc406Sopenharmony_ci        0x78, 0x98, 0xab,
546141cc406Sopenharmony_ci        0xcd, 0xef, 0x21,
547141cc406Sopenharmony_ci    };
548141cc406Sopenharmony_ci    Data out_data;
549141cc406Sopenharmony_ci    out_data.resize(in_data.size() * 2);
550141cc406Sopenharmony_ci
551141cc406Sopenharmony_ci    convert_pixel_row_format(in_data.data(), PixelFormat::RGB888,
552141cc406Sopenharmony_ci                             out_data.data(), PixelFormat::BGR161616, 3);
553141cc406Sopenharmony_ci
554141cc406Sopenharmony_ci    Data expected_data = {
555141cc406Sopenharmony_ci        0x56, 0x56, 0x34, 0x34, 0x12, 0x12,
556141cc406Sopenharmony_ci        0xab, 0xab, 0x98, 0x98, 0x78, 0x78,
557141cc406Sopenharmony_ci        0x21, 0x21, 0xef, 0xef, 0xcd, 0xcd,
558141cc406Sopenharmony_ci    };
559141cc406Sopenharmony_ci
560141cc406Sopenharmony_ci    ASSERT_EQ(out_data, expected_data);
561141cc406Sopenharmony_ci}
562141cc406Sopenharmony_ci
563141cc406Sopenharmony_civoid test_image()
564141cc406Sopenharmony_ci{
565141cc406Sopenharmony_ci    test_get_pixel_from_row();
566141cc406Sopenharmony_ci    test_set_pixel_to_row();
567141cc406Sopenharmony_ci    test_get_raw_pixel_from_row();
568141cc406Sopenharmony_ci    test_set_raw_pixel_to_row();
569141cc406Sopenharmony_ci    test_get_raw_channel_from_row();
570141cc406Sopenharmony_ci    test_set_raw_channel_to_row();
571141cc406Sopenharmony_ci    test_convert_pixel_row_format();
572141cc406Sopenharmony_ci}
573141cc406Sopenharmony_ci
574141cc406Sopenharmony_ci} // namespace genesys
575