|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 tinyVision.ai Inc. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <stdint.h> |
| 8 | + |
| 9 | +#include <zephyr/sys/util.h> |
| 10 | +#include <zephyr/pixel/print.h> |
| 11 | +#include <zephyr/logging/log.h> |
| 12 | + |
| 13 | +LOG_MODULE_REGISTER(app, LOG_LEVEL_INF); |
| 14 | + |
| 15 | +static uint8_t rgb24frame[16 * 32 * 3]; |
| 16 | + |
| 17 | +void print_image(void) |
| 18 | +{ |
| 19 | + const uint8_t beg[] = {0x00, 0x70, 0xc5}; |
| 20 | + const uint8_t end[] = {0x79, 0x29, 0xd2}; |
| 21 | + |
| 22 | + /* Generate an image with a gradient of the two colors above */ |
| 23 | + for (size_t i = 0, size = sizeof(rgb24frame); i + 3 <= size; i += 3) { |
| 24 | + rgb24frame[i + 0] = (beg[0] * (size - i) + end[0] * i) / size; |
| 25 | + rgb24frame[i + 1] = (beg[1] * (size - i) + end[1] * i) / size; |
| 26 | + rgb24frame[i + 2] = (beg[2] * (size - i) + end[2] * i) / size; |
| 27 | + } |
| 28 | + |
| 29 | + LOG_INF("Printing the gradient #%02x%02x%02x -> #%02x%02x%02x", |
| 30 | + beg[0], beg[1], beg[2], end[0], end[1], end[2]); |
| 31 | + |
| 32 | + LOG_INF("hexdump:"); |
| 33 | + pixel_print_rgb24frame_hex(rgb24frame, sizeof(rgb24frame), 16, 32); |
| 34 | + |
| 35 | + LOG_INF("truecolor:"); |
| 36 | + pixel_print_rgb24frame_truecolor(rgb24frame, sizeof(rgb24frame), 16, 32); |
| 37 | + |
| 38 | + LOG_INF("256color:"); |
| 39 | + pixel_print_rgb24frame_256color(rgb24frame, sizeof(rgb24frame), 16, 32); |
| 40 | +} |
| 41 | + |
| 42 | +void print_histogram(void) |
| 43 | +{ |
| 44 | + static const uint16_t rgb24hist[] = { |
| 45 | + 9, 4, 7, 1, 0, 5, 1, 0, 0, 2, 2, 3, 0, 1, 3, 0, |
| 46 | + 7, 6, 5, 1, 1, 4, 2, 0, 1, 2, 3, 4, 1, 1, 2, 2, |
| 47 | + 8, 4, 7, 4, 2, 3, 1, 2, 2, 2, 2, 2, 0, 0, 1, 1, |
| 48 | + }; |
| 49 | + |
| 50 | + static const uint16_t y8hist[] = { |
| 51 | + 8, 5, 6, 2, 1, 4, 1, 1, 1, 2, 3, 3, 1, 1, 2, 1, |
| 52 | + }; |
| 53 | + |
| 54 | + LOG_INF("Printing a histogram of %zu RGB buckets", ARRAY_SIZE(rgb24hist)); |
| 55 | + pixel_print_rgb24hist(rgb24hist, ARRAY_SIZE(rgb24hist), 8); |
| 56 | + |
| 57 | + LOG_INF("Printing a histogram of %zu Y (luma) buckets", ARRAY_SIZE(y8hist)); |
| 58 | + pixel_print_y8hist(y8hist, ARRAY_SIZE(y8hist), 8); |
| 59 | +} |
| 60 | + |
| 61 | +int main(void) |
| 62 | +{ |
| 63 | + print_image(); |
| 64 | + print_histogram(); |
| 65 | + |
| 66 | + return 0; |
| 67 | +} |
0 commit comments