1 #if LV_BUILD_TEST
2 #include "../lvgl.h"
3 #include "../../lvgl_private.h"
4
5 #include "unity/unity.h"
6
setUp(void)7 void setUp(void)
8 {
9 /* Function run before every test */
10 }
11
tearDown(void)12 void tearDown(void)
13 {
14 /* Function run after every test */
15 }
16
test_rotate90_RGB565(void)17 void test_rotate90_RGB565(void)
18 {
19 uint16_t srcArray[3 * 2] = {
20 0x1110, 0x2220, 0x3330,
21 0x4440, 0x5550, 0x6660
22 };
23 uint16_t dstArray[2 * 3] = {0};
24
25 uint16_t expectedArray[2 * 3] = {
26 0x3330, 0x6660,
27 0x2220, 0x5550,
28 0x1110, 0x4440,
29 };
30
31 lv_draw_sw_rotate(srcArray, dstArray,
32 3, 2,
33 3 * sizeof(uint16_t),
34 2 * sizeof(uint16_t),
35 LV_DISPLAY_ROTATION_90,
36 LV_COLOR_FORMAT_RGB565);
37
38 TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedArray, dstArray, sizeof(dstArray));
39 }
40
test_rotate180_RGB565(void)41 void test_rotate180_RGB565(void)
42 {
43 uint16_t srcArray[3 * 2] = {
44 0x1110, 0x2220, 0x3330,
45 0x4440, 0x5550, 0x6660
46 };
47 uint16_t dstArray[3 * 2] = {0};
48 uint16_t expectedArray[3 * 2] = {
49 0x6660, 0x5550, 0x4440,
50 0x3330, 0x2220, 0x1110,
51 };
52 lv_draw_sw_rotate(srcArray, dstArray,
53 3, 2,
54 3 * sizeof(uint16_t),
55 3 * sizeof(uint16_t),
56 LV_DISPLAY_ROTATION_180,
57 LV_COLOR_FORMAT_RGB565);
58
59 TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedArray, dstArray, sizeof(dstArray));
60 }
61
test_rotate270_RGB565(void)62 void test_rotate270_RGB565(void)
63 {
64 uint16_t srcArray[3 * 2] = {
65 0x1110, 0x2220, 0x3330,
66 0x4440, 0x5550, 0x6660
67 };
68
69 uint16_t dstArray[2 * 3] = {0};
70
71 uint16_t expectedArray[2 * 3] = {
72 0x4440, 0x1110,
73 0x5550, 0x2220,
74 0x6660, 0x3330
75 };
76 lv_draw_sw_rotate(srcArray, dstArray,
77 3, 2,
78 3 * sizeof(uint16_t),
79 2 * sizeof(uint16_t),
80 LV_DISPLAY_ROTATION_270,
81 LV_COLOR_FORMAT_RGB565);
82
83 TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedArray, dstArray, sizeof(dstArray));
84 }
85
test_rotate90_RGB888(void)86 void test_rotate90_RGB888(void)
87 {
88 uint8_t srcArray[3 * 2 * 3] = {
89 0x11, 0x1A, 0x1B, 0x22, 0x2A, 0x2B, 0x33, 0x3A, 0x3B,
90 0x44, 0x4A, 0x4B, 0x55, 0x5A, 0x5B, 0x66, 0x6A, 0x6B
91 };
92 uint8_t dstArray[2 * 3 * 3] = {0};
93
94 uint8_t expectedArray[2 * 3 * 3] = {
95 0x33, 0x3A, 0x3B, 0x66, 0x6A, 0x6B,
96 0x22, 0x2A, 0x2B, 0x55, 0x5A, 0x5B,
97 0x11, 0x1A, 0x1B, 0x44, 0x4A, 0x4B,
98 };
99
100 lv_draw_sw_rotate(srcArray, dstArray,
101 3, 2,
102 3 * 3,
103 2 * 3,
104 LV_DISPLAY_ROTATION_90,
105 LV_COLOR_FORMAT_RGB888);
106
107 TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedArray, dstArray, sizeof(dstArray));
108 }
109
test_rotate180_RGB888(void)110 void test_rotate180_RGB888(void)
111 {
112 uint8_t srcArray[3 * 2 * 3] = {
113 0x11, 0x1A, 0x1B, 0x22, 0x2A, 0x2B, 0x33, 0x3A, 0x3B,
114 0x44, 0x4A, 0x4B, 0x55, 0x5A, 0x5B, 0x66, 0x6A, 0x6B
115 };
116 uint8_t dstArray[3 * 2 * 3] = {0};
117
118 uint8_t expectedArray[3 * 2 * 3] = {
119 0x66, 0x6A, 0x6B, 0x55, 0x5A, 0x5B, 0x44, 0x4A, 0x4B,
120 0x33, 0x3A, 0x3B, 0x22, 0x2A, 0x2B, 0x11, 0x1A, 0x1B
121 };
122
123 lv_draw_sw_rotate(srcArray, dstArray,
124 2, 3,
125 2 * 3,
126 2 * 3,
127 LV_DISPLAY_ROTATION_180,
128 LV_COLOR_FORMAT_RGB888);
129
130 TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedArray, dstArray, sizeof(dstArray));
131 }
132
test_rotate270_RGB888(void)133 void test_rotate270_RGB888(void)
134 {
135 uint8_t srcArray[3 * 2 * 3] = {
136 0x11, 0x1A, 0x1B, 0x22, 0x2A, 0x2B, 0x33, 0x3A, 0x3B,
137 0x44, 0x4A, 0x4B, 0x55, 0x5A, 0x5B, 0x66, 0x6A, 0x6B
138 };
139 uint8_t dstArray[2 * 3 * 3] = {0};
140
141 uint8_t expectedArray[2 * 3 * 3] = {
142 0x44, 0x4A, 0x4B, 0x11, 0x1A, 0x1B,
143 0x55, 0x5A, 0x5B, 0x22, 0x2A, 0x2B,
144 0x66, 0x6A, 0x6B, 0x33, 0x3A, 0x3B,
145 };
146
147 lv_draw_sw_rotate(srcArray, dstArray,
148 3, 2,
149 3 * 3,
150 2 * 3,
151 LV_DISPLAY_ROTATION_270,
152 LV_COLOR_FORMAT_RGB888);
153
154 TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedArray, dstArray, sizeof(dstArray));
155 }
156
test_rotate90_ARGB8888(void)157 void test_rotate90_ARGB8888(void)
158 {
159 uint32_t srcArray[3 * 2] = {
160 0x111A1B1C, 0x222A2B2C, 0x333A3B3C,
161 0x444A4B4C, 0x555A5B5C, 0x666A6B6C
162
163 };
164 uint32_t dstArray[2 * 3] = {0};
165
166 uint32_t expectedArray[2 * 3] = {
167 0x333A3B3C, 0x666A6B6C,
168 0x222A2B2C, 0x555A5B5C,
169 0x111A1B1C, 0x444A4B4C,
170 };
171
172 lv_draw_sw_rotate(srcArray, dstArray,
173 3, 2,
174 3 * sizeof(uint32_t),
175 2 * sizeof(uint32_t),
176 LV_DISPLAY_ROTATION_90,
177 LV_COLOR_FORMAT_ARGB8888);
178
179 TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedArray, dstArray, sizeof(dstArray));
180 }
181
test_rotate180_ARGB8888(void)182 void test_rotate180_ARGB8888(void)
183 {
184 uint32_t srcArray[3 * 2] = {
185 0xFF0000FF, 0xFF00FF00, // Row 1: Red, Green
186 0xFFFF0000, 0xFFFFFFFF, // Row 2: Blue, White
187 0xFF00FFFF, 0xFFFFFF00 // Row 3: Cyan, Yellow
188 };
189 uint32_t dstArray[3 * 2] = {0};
190 uint32_t expectedArray[3 * 2] = {
191 0xFFFFFF00, 0xFF00FFFF, // Rotated Row 1
192 0xFFFFFFFF, 0xFFFF0000, // Rotated Row 2
193 0xFF00FF00, 0xFF0000FF // Rotated Row 3
194 };
195
196 lv_draw_sw_rotate(srcArray, dstArray,
197 2, 3,
198 2 * sizeof(uint32_t),
199 2 * sizeof(uint32_t),
200 LV_DISPLAY_ROTATION_180,
201 LV_COLOR_FORMAT_ARGB8888);
202
203 TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedArray, dstArray, sizeof(dstArray));
204 }
205
test_rotate270_ARGB8888(void)206 void test_rotate270_ARGB8888(void)
207 {
208 uint32_t srcArray[3 * 2] = {
209 0x111A1B1C, 0x222A2B2C, 0x333A3B3C,
210 0x444A4B4C, 0x555A5B5C, 0x666A6B6C
211 };
212 uint32_t dstArray[2 * 3] = {0};
213 uint32_t expectedArray[2 * 3] = {
214 0x444A4B4C, 0x111A1B1C,
215 0x555A5B5C, 0x222A2B2C,
216 0x666A6B6C, 0x333A3B3C
217 };
218 lv_draw_sw_rotate(srcArray, dstArray,
219 3, 2,
220 3 * sizeof(uint32_t),
221 2 * sizeof(uint32_t),
222 LV_DISPLAY_ROTATION_270,
223 LV_COLOR_FORMAT_ARGB8888);
224
225 TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedArray, dstArray, sizeof(dstArray));
226 }
227
test_rotate90_L8(void)228 void test_rotate90_L8(void)
229 {
230 uint8_t srcArray[3 * 2] = {
231 0x11, 0x22, 0x33,
232 0x44, 0x55, 0x66
233 };
234 uint8_t dstArray[2 * 3] = {0};
235
236 uint8_t expectedArray[2 * 3] = {
237 0x33, 0x66,
238 0x22, 0x55,
239 0x11, 0x44,
240 };
241
242 lv_draw_sw_rotate(srcArray, dstArray,
243 3, 2,
244 3 * sizeof(uint8_t),
245 2 * sizeof(uint8_t),
246 LV_DISPLAY_ROTATION_90,
247 LV_COLOR_FORMAT_L8);
248
249 TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedArray, dstArray, sizeof(dstArray));
250 }
251
252
test_rotate180_L8(void)253 void test_rotate180_L8(void)
254 {
255 uint8_t srcArray[3 * 2] = {
256 0x11, 0x22, 0x33,
257 0x44, 0x55, 0x66
258 };
259 uint8_t dstArray[3 * 2] = {0};
260 uint8_t expectedArray[3 * 2] = {
261 0x66, 0x55, 0x44,
262 0x33, 0x22, 0x11,
263 };
264 lv_draw_sw_rotate(srcArray, dstArray,
265 3, 2,
266 3 * sizeof(uint8_t),
267 3 * sizeof(uint8_t),
268 LV_DISPLAY_ROTATION_180,
269 LV_COLOR_FORMAT_L8);
270
271 TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedArray, dstArray, sizeof(dstArray));
272 }
273
test_rotate270_L8(void)274 void test_rotate270_L8(void)
275 {
276 uint8_t srcArray[3 * 2] = {
277 0x11, 0x22, 0x33,
278 0x44, 0x55, 0x66
279 };
280
281 uint8_t dstArray[2 * 3] = {0};
282
283 uint8_t expectedArray[2 * 3] = {
284 0x44, 0x11,
285 0x55, 0x22,
286 0x66, 0x33
287 };
288 lv_draw_sw_rotate(srcArray, dstArray,
289 3, 2,
290 3 * sizeof(uint8_t),
291 2 * sizeof(uint8_t),
292 LV_DISPLAY_ROTATION_270,
293 LV_COLOR_FORMAT_L8);
294
295 TEST_ASSERT_EQUAL_UINT8_ARRAY(expectedArray, dstArray, sizeof(dstArray));
296 }
297
test_invert(void)298 void test_invert(void)
299 {
300 uint8_t expected_buf[10] = {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6};
301
302 /*Aligned start and aligned end*/
303 uint8_t buf1[10] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};
304 lv_draw_sw_i1_invert(buf1, 8);
305 TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_buf, buf1, 8);
306
307 /*Unaligned start and unaligned end*/
308 uint8_t buf2[10] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};
309 lv_draw_sw_i1_invert(&buf2[3], 6);
310 TEST_ASSERT_EQUAL_UINT8_ARRAY(&expected_buf[3], &buf2[3], 6);
311
312 /*Small buffer*/
313 uint8_t buf3[10] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};
314 lv_draw_sw_i1_invert(&buf3[3], 2);
315 TEST_ASSERT_EQUAL_UINT8_ARRAY(&expected_buf[3], &buf3[3], 2);
316 }
317
test_vtile_small(void)318 void test_vtile_small(void)
319 {
320 uint8_t src_buf[8] = {0x3C, 0x42, 0x81, 0xA5, 0x81, 0x81, 0x42, 0x3C};
321 uint8_t dst_buf[8] = {0};
322
323 uint8_t expected_buf_msb[8] = {0x3C, 0x42, 0x91, 0x81, 0x81, 0x91, 0x42, 0x3C};
324 uint8_t expected_buf_lsb[8] = {0x3C, 0x42, 0x89, 0x81, 0x81, 0x89, 0x42, 0x3C};
325
326 lv_draw_sw_i1_convert_to_vtiled(src_buf, 8, 8, 8, dst_buf, 8, false);
327 TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_buf_msb, dst_buf, 8);
328
329 lv_draw_sw_i1_convert_to_vtiled(src_buf, 8, 8, 8, dst_buf, 8, true);
330 TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_buf_lsb, dst_buf, 8);
331 }
332
test_vtile_rectangular(void)333 void test_vtile_rectangular(void)
334 {
335 uint8_t src_buf[80] = {
336 0x00, 0x00, 0x00, 0x00, 0x00,
337 0x40, 0x80, 0x83, 0xE1, 0x00,
338 0x40, 0x80, 0x84, 0x01, 0x00,
339 0x40, 0x41, 0x08, 0x01, 0x00,
340 0x40, 0x41, 0x10, 0x01, 0x00,
341 0x40, 0x41, 0x20, 0x01, 0x00,
342 0x40, 0x41, 0x20, 0x01, 0x00,
343 0x40, 0x41, 0x20, 0x01, 0x00,
344 0x40, 0x41, 0x20, 0x01, 0x00,
345 0x40, 0x23, 0x20, 0x01, 0x00,
346 0x40, 0x22, 0x20, 0xF1, 0x00,
347 0x40, 0x14, 0x20, 0x11, 0x00,
348 0x40, 0x14, 0x10, 0x11, 0x00,
349 0x40, 0x08, 0x08, 0x11, 0x00,
350 0x7E, 0x08, 0x07, 0xF1, 0xF8,
351 0x00, 0x00, 0x00, 0x00, 0x00,
352 };
353 uint8_t dst_buf[80] = {0};
354
355 uint8_t expected_buf_msb[80] = {
356 0x00, 0x00,
357 0x7F, 0xFE,
358 0x00, 0x02,
359 0x00, 0x02,
360 0x00, 0x02,
361 0x00, 0x02,
362 0x00, 0x02,
363 0x00, 0x00,
364 0x60, 0x00,
365 0x1F, 0x80,
366 0x00, 0x60,
367 0x00, 0x18,
368 0x00, 0x06,
369 0x00, 0x18,
370 0x00, 0x60,
371 0x3F, 0x80,
372 0xC0, 0x00,
373 0x00, 0x00,
374 0x07, 0xF0,
375 0x08, 0x08,
376 0x10, 0x04,
377 0x20, 0x02,
378 0x80, 0x02,
379 0x80, 0x02,
380 0x80, 0x22,
381 0x80, 0x22,
382 0x80, 0x22,
383 0x00, 0x3E,
384 0x00, 0x00,
385 0x00, 0x00,
386 0x00, 0x00,
387 0xFF, 0xFE,
388 0x00, 0x02,
389 0x00, 0x02,
390 0x00, 0x02,
391 0x00, 0x02,
392 0x00, 0x02,
393 0x00, 0x00,
394 0x00, 0x00,
395 0x00, 0x00,
396 };
397 uint8_t expected_buf_lsb[80] = {
398 0x00, 0x00,
399 0xFE, 0x7F,
400 0x00, 0x40,
401 0x00, 0x40,
402 0x00, 0x40,
403 0x00, 0x40,
404 0x00, 0x40,
405 0x00, 0x00,
406 0x06, 0x00,
407 0xF8, 0x01,
408 0x00, 0x06,
409 0x00, 0x18,
410 0x00, 0x60,
411 0x00, 0x18,
412 0x00, 0x06,
413 0xF8, 0x03,
414 0x06, 0x00,
415 0x00, 0x00,
416 0xE0, 0x0F,
417 0x10, 0x10,
418 0x08, 0x20,
419 0x04, 0x40,
420 0x02, 0x40,
421 0x02, 0x40,
422 0x02, 0x44,
423 0x02, 0x44,
424 0x02, 0x44,
425 0x00, 0x7C,
426 0x00, 0x00,
427 0x00, 0x00,
428 0x00, 0x00,
429 0xFE, 0x7F,
430 0x00, 0x40,
431 0x00, 0x40,
432 0x00, 0x40,
433 0x00, 0x40,
434 0x00, 0x40,
435 0x00, 0x00,
436 0x00, 0x00,
437 0x00, 0x00,
438 };
439
440 lv_draw_sw_i1_convert_to_vtiled(src_buf, 80, 40, 16, dst_buf, 80, false);
441 TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_buf_msb, dst_buf, 8);
442
443 lv_draw_sw_i1_convert_to_vtiled(src_buf, 80, 40, 16, dst_buf, 80, true);
444 TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_buf_lsb, dst_buf, 8);
445 }
446
447 #endif
448