1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*
* This file is part of the libpayload project.
*
* Copyright (C) 2015 Google, Inc.
*/
#include <libpayload.h>
#include <arch/types.h>
#include <stddef.h>
/*
* API error codes
*/
#define CBGFX_SUCCESS 0
/* unknown error */
#define CBGFX_ERROR_UNKNOWN 1
/* failed to initialize cbgfx library */
#define CBGFX_ERROR_INIT 2
/* drawing beyond canvas boundary */
#define CBGFX_ERROR_BOUNDARY 3
/* bitmap error: signature mismatch */
#define CBGFX_ERROR_BITMAP_SIGNATURE 0x10
/* bitmap error: unsupported format */
#define CBGFX_ERROR_BITMAP_FORMAT 0x11
/* bitmap error: invalid data */
#define CBGFX_ERROR_BITMAP_DATA 0x12
/* bitmap error: scaling out of range */
#define CBGFX_ERROR_SCALE_OUT_OF_RANGE 0x13
struct vector {
union {
uint32_t x;
uint32_t width;
};
union {
uint32_t y;
uint32_t height;
};
};
struct rgb_color {
uint8_t red;
uint8_t green;
uint8_t blue;
};
/*
* Resolution of scale parameters used to describe height, width, coordinate,
* etc. relative to the canvas. For example, if it's 100, scales range from 0 to
* 100%.
*/
#define CANVAS_SCALE 100
/*
* The coordinate system is expected to have (0, 0) at top left corner with
* y values increasing towards bottom of screen.
*/
/*
* draw a box filled with a color on screen
*
* top_left_rel: coordinate of top left corner of the box, relative to canvas.
* (0 - CANVAS_SCALE).
* size_rel: width and height of the box, relative to canvas. (0 - CANVAS_SCALE)
* rgb: RGB color of the box.
*
* return: CBGFX_* error codes
*/
int draw_box(const struct vector *top_left_rel,
const struct vector *size_rel,
const struct rgb_color *rgb);
/*
* Clear the canvas
*/
int clear_canvas(struct rgb_color *rgb);
/*
* Draw a bitmap image on screen.
*
* top_left_rel: coordinate of the top left corner of the image relative to the
* canvas (0 - CANVAS_SCALE).
* scale_rel: scale factor relative to the canvas width (0 - CANVAS_SCALE).
* bitmap: pointer to the bitmap data, starting from the file header.
* size: size of the bitmap data
*
* return: CBGFX_* error codes
*/
int draw_bitmap(const struct vector *top_left_rel,
size_t scale_rel, const void *bitmap, size_t size);
|