-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbmp.h
221 lines (186 loc) · 4.62 KB
/
bmp.h
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#ifndef _bmp_h_
#define _bmp_h_
/** \file
* Drawing routines for the bitmap VRAM.
*
* These are Magic Lantern routines to draw shapes and text into
* the LVRAM for display on the LCD or HDMI output.
*/
/*
* Copyright (C) 2009 Trammell Hudson <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "dryos.h"
#include "font.h"
/** Returns a pointer to the real BMP vram */
static inline uint8_t *
bmp_vram(void)
{
return bmp_vram_info[0].vram2;
}
/** Returns the width, pitch and height of the BMP vram.
* These should check the current mode since we might be in
* HDMI output mode, which uses the full 960x540 space.
*/
static inline uint32_t bmp_width(void) { return 720; }
static inline uint32_t bmp_pitch(void) { return 960; }
static inline uint32_t bmp_height(void) { return 480; }
/** Font specifiers include the font, the fg color and bg color */
#define FONT_MASK 0x00FF0000
#define FONT_MONO 0x00100000
#define FONT_HUGE 0x00080000
#define FONT_LARGE 0x00030000
#define FONT_MED 0x00020000
#define FONT_SMALL 0x00010000
#define FONT(font,fg,bg) ( 0 \
| ((font) & FONT_MASK) \
| ((bg) & 0xFF) << 8 \
| ((fg) & 0xFF) << 0 \
)
static inline const canon_font_t *
fontspec_font(
unsigned fontspec
)
{
switch( fontspec & FONT_MASK )
{
case FONT_MED: return &font_med;
case FONT_LARGE: return &font_gothic_30;
case FONT_HUGE: return &font_gothic_36;
case FONT_MONO: return &font_mono_24;
default:
case FONT_SMALL: return &font_small;
}
}
/** Return the approximate width of an m in the font. */
extern unsigned
fontspec_width(
unsigned fontspec
);
static inline unsigned
fontspec_fg(
unsigned fontspec
)
{
return (fontspec >> 0) & 0xFF;
}
static inline unsigned
fontspec_bg(
unsigned fontspec
)
{
return (fontspec >> 8) & 0xFF;
}
static inline unsigned
fontspec_height(
unsigned fontspec
)
{
return fontspec_font(fontspec)->height;
}
extern void
bmp_printf(
unsigned fontspec,
unsigned x,
unsigned y,
const char * fmt,
...
) __attribute__((format(printf,4,5)));
extern void
con_printf(
unsigned fontspec,
const char * fmt,
...
) __attribute__((format(printf,2,3)));
extern void
bmp_hexdump(
unsigned fontspec,
unsigned x,
unsigned y,
const void * buf,
size_t len
);
extern void
bmp_puts(
unsigned fontspec,
unsigned * x,
unsigned * y,
const char * s
);
/** Fill the screen with a bitmap palette */
extern void
bmp_draw_palette( void );
/** Fill a section of bitmap memory with solid color
* Only has a four-pixel resolution in X.
*/
extern void
bmp_fill(
uint8_t color,
uint32_t x,
uint32_t y,
uint32_t w,
uint32_t h
);
/** Some selected colors */
#define COLOR_EMPTY 0x00 // total transparent
#define COLOR_BG 0x03 // transparent black
#define COLOR_WHITE 0x01 // Normal white
#define COLOR_BLUE 0x0B // normal blue
#define COLOR_RED 0x08 // normal red
#define COLOR_YELLOW 0x0F // normal yellow
static inline uint32_t
color_word(
uint8_t color
)
{
return 0
| ( color << 24 )
| ( color << 16 )
| ( color << 8 )
| ( color << 0 )
;
}
/** BMP file format.
* Offsets and meaning from:
* http://www.fastgraph.com/help/bmp_header_format.html
*/
struct bmp_file_t
{
uint16_t signature; // off 0
uint32_t size; // off 2, in bytes
uint16_t res_0; // off 6, must be 0
uint16_t res_1; // off 8. must be 0
uint8_t * image; // off 10, offset in bytes
uint32_t hdr_size; // off 14, must be 40
uint32_t width; // off 18, in pixels
uint32_t height; // off 22, in pixels
uint16_t planes; // off 26, must be 1
uint16_t bits_per_pixel; // off 28, 1, 4, 8 or 24
uint32_t compression; // off 30, 0=none, 1=RLE8, 2=RLE4
uint32_t image_size; // off 34, in bytes + padding
uint32_t hpix_per_meter; // off 38, unreliable
uint32_t vpix_per_meter; // off 42, unreliable
uint32_t num_colors; // off 46
uint32_t num_imp_colors; // off 50
} PACKED;
SIZE_CHECK_STRUCT( bmp_file_t, 54 );
extern struct bmp_file_t *
bmp_load(
const char * name
);
#endif