Host C Specs


Directory: src/c/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 25 / 0 / 25
Functions: 100.0% 2 / 0 / 2
Branches: 80.0% 16 / 0 / 20

core/wire/music_art.c
Line Branch Exec Source
1 /**
2 * @file music_art.c
3 * @brief Checking the now playing art the phone sent, and laying its rows into a bitmap.
4 *
5 * @ingroup lib_core
6 */
7 #include "wire/music_art.h"
8
9 #include <string.h>
10
11 8 bool music_art_read(const uint8_t *buf, uint16_t len, MusicArt *out)
12 {
13
3/4
✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 4 not taken.
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 7 times.
8 if (!buf || len < MUSIC_ART_HEADER)
14 {
15 1 return false;
16 }
17
18 7 uint8_t width = buf[0];
19 7 uint8_t height = buf[1];
20 7 uint8_t colours = buf[2];
21
22
6/8
✓ Branch 5 → 6 taken 6 times.
✓ Branch 5 → 9 taken 1 time.
✓ Branch 6 → 7 taken 6 times.
✗ Branch 6 → 9 not taken.
✓ Branch 7 → 8 taken 5 times.
✓ Branch 7 → 9 taken 1 time.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 5 times.
7 if (width == 0 || height == 0 || width > MUSIC_ART_SIDE_MAX || height > MUSIC_ART_SIDE_MAX)
23 {
24 2 return false;
25 }
26
27
3/4
✓ Branch 10 → 11 taken 5 times.
✗ Branch 10 → 12 not taken.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 13 taken 4 times.
5 if (colours == 0 || colours > MUSIC_ART_COLOURS_MAX)
28 {
29 1 return false;
30 }
31
32 // the length has to be exactly what the header says, since a short run would leave the bottom
33 // rows reading past the message and a long one means the two sides disagree on the layout
34 4 uint16_t row_bytes = (uint16_t)((width + 1) / 2);
35 4 uint32_t want = (uint32_t)MUSIC_ART_HEADER + colours + (uint32_t)row_bytes * height;
36
37
2/2
✓ Branch 13 → 14 taken 2 times.
✓ Branch 13 → 15 taken 2 times.
4 if (len != want)
38 {
39 2 return false;
40 }
41
42 2 out->width = width;
43 2 out->height = height;
44 2 out->colours = colours;
45 2 out->palette = buf + MUSIC_ART_HEADER;
46 2 out->pixels = buf + MUSIC_ART_HEADER + colours;
47 2 out->row_bytes = row_bytes;
48 2 return true;
49 }
50
51 1 void music_art_copy_rows(const MusicArt *art, uint8_t *dst, uint16_t dst_row_bytes)
52 {
53
2/2
✓ Branch 4 → 3 taken 2 times.
✓ Branch 4 → 5 taken 1 time.
3 for (uint8_t row = 0; row < art->height; row++)
54 {
55 2 memcpy(dst + (uint32_t)row * dst_row_bytes, art->pixels + (uint32_t)row * art->row_bytes, art->row_bytes);
56 }
57 1 }
58