OSDN Git Service

Changed the directory structure of the utilities.
[bluetank/bluetank.git] / soft / utils / common / tinybmpio / bmpimg.h
1 /**
2  * @file bmpimg.h
3  * @author Shinichiro Nakamura
4  * @brief 小規模組み込みシステム向けBMP I/Oの実装。
5  */
6
7 /*
8  * ===============================================================
9  *  Tiny BMP I/O Module
10  *  Version 0.0.1
11  * ===============================================================
12  * Copyright (c) 2010-2011 Shinichiro Nakamura
13  *
14  * Permission is hereby granted, free of charge, to any person
15  * obtaining a copy of this software and associated documentation
16  * files (the "Software"), to deal in the Software without
17  * restriction, including without limitation the rights to use,
18  * copy, modify, merge, publish, distribute, sublicense, and/or
19  * sell copies of the Software, and to permit persons to whom the
20  * Software is furnished to do so, subject to the following
21  * conditions:
22  *
23  * The above copyright notice and this permission notice shall be
24  * included in all copies or substantial portions of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
28  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
30  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
31  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33  * OTHER DEALINGS IN THE SOFTWARE.
34  * ===============================================================
35  */
36
37 #ifndef BMPIMG_H
38 #define BMPIMG_H
39
40 #include "bmpint.h"
41
42 /**
43  * @brief BMP画像ハンドラの実装。
44  */
45 typedef struct {
46     int w;                  /**< 画像横方向サイズ。 */
47     int h;                  /**< 画像縦方向サイズ。 */
48     void (*func_pixel_write)(const int x, const int y, const uint8_t r, const uint8_t g, const uint8_t b, void *extobj_pixel_write);
49     void *extobj_pixel_write;
50     void (*func_pixel_read)(const int x, const int y, uint8_t *r, uint8_t *g, uint8_t *b, void *extobj_pixel_read);
51     void *extobj_pixel_read;
52 } bmpimg_t;
53
54 #define BMPIMG_GET_W(BMPIMG)    ((BMPIMG)->w)
55 #define BMPIMG_GET_H(BMPIMG)    ((BMPIMG)->h)
56
57 /**
58  * @brief 色定義。
59  * @brief 8ビットでフルレンジ。
60  */
61 typedef struct {
62     unsigned char r; /**< 赤。 */
63     unsigned char g; /**< 緑。 */
64     unsigned char b; /**< 青。 */
65 } bmpcol_t;
66
67 #define BMPIMG_FONT_DOT_WIDTH   (5) /**< フォントの横方向ドット数。 */
68 #define BMPIMG_FONT_DOT_HEIGHT  (7) /**< フォンとの縦方向ドット数。 */
69
70 /**
71  * @brief 色を設定する。
72  *
73  * @param COL 色定義。
74  * @param R 赤。
75  * @param G 緑。
76  * @param B 青。
77  */
78 #define BMPIMG_SET_COLOR(COL, R, G, B)  do { (COL).r = (unsigned char)(R); (COL).g = (unsigned char)(G); (COL).b = (unsigned char)(B); } while (0)
79
80 /**
81  * @brief 文字列の幅を取得する。
82  *
83  * @param SIZE サイズ。
84  * @param NSTR 文字列の長さ。
85  *
86  * @return 文字列の幅。
87  */
88 #define BMPIMG_GET_STRING_WIDTH(SIZE, NSTR) \
89     ((((SIZE) * (BMPIMG_FONT_DOT_WIDTH + 1)) * ((NSTR) - 1)) + ((SIZE) * (BMPIMG_FONT_DOT_WIDTH)))
90
91 /**
92  * @brief 文字列の高さを取得する。
93  *
94  * @param SIZE サイズ。
95  *
96  * @return 文字列の高さ。
97  */
98 #define BMPIMG_GET_STRING_HEIGHT(SIZE) \
99     ((SIZE) * (BMPIMG_FONT_DOT_HEIGHT))
100
101 /**
102  * @brief BMP画像をオープンする。
103  *
104  * @param p BMP画像ハンドラ。
105  * @param w 画像横方向サイズ。
106  * @param h 画像縦方向サイズ。
107  * @param func_pixel_write ピクセル書き込み関数。
108  * @param extobj_pixel_write ピクセル書き込み関数に渡すパラメータ。
109  * @param func_pixel_read ピクセル読み込み関数。
110  * @param extobj_pixel_read ピクセル読み込み関数に渡すパラメータ。
111  */
112 void bmpimg_open(
113         bmpimg_t *p,
114         const int w,
115         const int h,
116         void (*func_pixel_write)(const int x, const int y, const uint8_t r, const uint8_t g, const uint8_t b, void *extobj_pixel_write),
117         void *extobj_pixel_write,
118         void (*func_pixel_read)(const int x, const int y, uint8_t *r, uint8_t *g, uint8_t *b, void *extobj_pixel_read),
119         void *extobj_pixel_read);
120
121 /**
122  * @brief ボックスを描画する。
123  *
124  * @param p BMP画像ハンドラ。
125  * @param x1 始点X座標。
126  * @param y1 始点Y座標。
127  * @param x2 終点X座標。
128  * @param y2 終点Y座標。
129  * @param color 色。
130  *
131  * @retval 0 成功。
132  * @retval !0 失敗。
133  */
134 int bmpimg_draw_box(bmpimg_t *p, const int x1, const int y1, const int x2, const int y2, bmpcol_t *color);
135
136 /**
137  * @brief ボックスを描画する。
138  *
139  * @param p BMP画像ハンドラ。
140  * @param x1 始点X座標。
141  * @param y1 始点Y座標。
142  * @param x2 終点X座標。
143  * @param y2 終点Y座標。
144  * @param color 色。
145  *
146  * @retval 0 成功。
147  * @retval !0 失敗。
148  */
149 int bmpimg_fill_box(bmpimg_t *p, const int x1, const int y1, const int x2, const int y2, bmpcol_t *color);
150
151 /**
152  * @brief 文字列を描画する。
153  *
154  * @param p BMP画像ハンドラ。
155  * @param x 横方向描画開始ピクセル位置。
156  * @param y 縦方向描画開始ピクセル位置。
157  * @param size 1ピクセルのサイズ。
158  * @param text 文字列。
159  * @param color 描画色。
160  */
161 int bmpimg_draw_string(bmpimg_t *p, const int x, const int y, const int size, const char *text, bmpcol_t *color);
162
163 /**
164  * @brief 線を描画する。
165  *
166  * @param p BMP画像ハンドラ。
167  * @param x1 始点X座標。
168  * @param y1 始点Y座標。
169  * @param x2 終点X座標。
170  * @param y2 終点Y座標。
171  * @param color 色。
172  *
173  * @retval 0 成功。
174  * @retval !0 失敗。
175  */
176 int bmpimg_draw_line(bmpimg_t *p, const int x1, const int y1, const int x2, const int y2, bmpcol_t *color);
177
178 /**
179  * @brief 点を描画する。
180  *
181  * @param p BMP画像ハンドラ。
182  * @param x X座標。
183  * @param y Y座標。
184  * @param color 色。
185  *
186  * @retval 0 成功。
187  * @retval !0 失敗。
188  */
189 int bmpimg_draw_pixel(bmpimg_t *p, const int x, const int y, bmpcol_t *color);
190
191 /**
192  * @brief チェックボックスを描画する。
193  *
194  * @param p BMP画像ハンドラ。
195  * @param x1 始点X座標。
196  * @param y1 始点Y座標。
197  * @param x2 終点X座標。
198  * @param y2 終点Y座標。
199  * @param state 選択状態。
200  * @param color 色。
201  *
202  * @retval 0 成功。
203  * @retval !0 失敗。
204  */
205 void bmpimg_draw_checkbox(
206         bmpimg_t *p,
207         const int x1,
208         const int y1,
209         const int x2,
210         const int y2,
211         const int state,
212         bmpcol_t *color);
213
214 /**
215  * @brief プログレスバーを描画する。
216  *
217  * @param p BMP画像ハンドラ。
218  * @param x1 始点X座標。
219  * @param y1 始点Y座標。
220  * @param x2 終点X座標。
221  * @param y2 終点Y座標。
222  * @param min 最小値。
223  * @param max 最大値。
224  * @param value 現在値。
225  * @param color 色。
226  *
227  * @retval 0 成功。
228  * @retval !0 失敗。
229  */
230 void bmpimg_draw_progressbar(
231         bmpimg_t *p,
232         const int x1,
233         const int y1,
234         const int x2,
235         const int y2,
236         const int min,
237         const int max,
238         const int value,
239         bmpcol_t *color);
240
241 /**
242  * @brief BMPファイルから読み込む。
243  *
244  * @param p BMP画像ハンドラ。
245  * @param filename ファイル名。
246  *
247  * @retval 0 成功。
248  * @retval !0 失敗。
249  */
250 int bmpimg_bmp_read(
251         bmpimg_t *p,
252         int (*func_fread)(void *buf, const uint32_t size, void *extobj_func_fread),
253         void *extobj_func_fread);
254
255 /**
256  * @brief BMPファイルに書き込む。
257  *
258  * @param p BMP画像ハンドラ。
259  * @param filename ファイル名。
260  *
261  * @retval 0 成功。
262  * @retval !0 失敗。
263  */
264 int bmpimg_bmp_write(
265         bmpimg_t *p,
266         int (*func_fwrite)(const void *buf, const uint32_t size, void *extobj_func_fwrite),
267         void *extobj_func_fwrite);
268
269 /**
270  * @brief BMP画像をクローズする。
271  *
272  * @param bit ビット深度。
273  *
274  * @retval 0 成功。
275  * @retval !0 失敗。
276  */
277 int bmpimg_close(bmpimg_t *p);
278
279 #endif
280