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
|
/* ****************************************************************************
* libcasio/picture.h -- picture formats managed by libcasio.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3.0 of the License,
* or (at your option) any later version.
*
* libcasio 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#ifndef LIBCASIO_PICTURE_H
# define LIBCASIO_PICTURE_H
# include "cdefs.h"
CASIO_BEGIN_NAMESPACE
CASIO_STRUCT(casio_picture, casio_picture_t)
/* Pixel definition, with utilities. */
typedef casio_uint32_t casio_pixel_t;
# define casio_pixel(CASIO__R, CASIO__G, CASIO__B) \
((casio_pixel_t)(((CASIO__R) & 0xFF) << 16) | (((CASIO__G) & 0xFF) << 8) \
| ((CASIO__B) & 0xFF))
# define casio_set_pixel(CASIO__PIX, CASIO__R, CASIO__G, CASIO__B) \
(CASIO__PIX = casio_pixel(CASIO__R, CASIO__G, CASIO__B))
# define casio_pixel_with_r(CASIO__PIX, CASIO__VAL) \
((CASIO__PIX & ~0xFF0000) | (((CASIO__VAL) & 0xFF) << 16))
# define casio_pixel_with_g(CASIO__PIX, CASIO__VAL) \
((CASIO__PIX & ~0xFF00) | (((CASIO__VAL) & 0xFF) << 8))
# define casio_pixel_with_b(CASIO__PIX, CASIO__VAL) \
((CASIO__PIX & ~0xFF) | ((CASIO__VAL) & 0xFF))
# define casio_set_pixel_r(CASIO__PIX, CASIO__VAL) \
(CASIO__PIX = casio_pixel_with_r(CASIO__PIX, CASIO__VAL))
# define casio_set_pixel_g(CASIO__PIX, CASIO__VAL) \
(CASIO__PIX = casio_pixel_with_g(CASIO__PIX, CASIO__VAL))
# define casio_set_pixel_b(CASIO__PIX, CASIO__VAL) \
(CASIO__PIX = casio_pixel_with_b(CASIO__PIX, CASIO__VAL))
# define casio_pixel_r(CASIO__PIX) \
((int)((CASIO__PIX) >> 16) & 0xFF)
# define casio_pixel_g(CASIO__PIX) \
((int)((CASIO__PIX) >> 8) & 0xFF)
# define casio_pixel_b(CASIO__PIX) \
((int) (CASIO__PIX) & 0xFF)
/* Color code definitions. */
typedef int casio_colorcode_t;
# define casio_colorcode_black 0x0 /* 0x000000 */
# define casio_colorcode_blue 0x1 /* 0x0000FF */
# define casio_colorcode_green 0x2 /* 0x00FF00 */
# define casio_colorcode_cyan 0x3 /* 0x00FFFF */
# define casio_colorcode_red 0x4 /* 0xFF0000 */
# define casio_colorcode_magenta 0x5 /* 0xFF00FF */
# define casio_colorcode_yellow 0x6 /* 0xFFFF00 */
# define casio_colorcode_white 0x7 /* 0xFFFFFF */
/* Picture format definitions.
*
* The rule of thumb for the values defined here is that they should be more
* or less `0xBBVS`, where `BB` is the number of bits each pixel
* occupy (in total), `V` is the variation for this number of bits,
* and `S` is the special hex digit (e.g. reverse); this rule might change
* later, so don't rely on it. */
typedef unsigned int casio_pictureformat_t;
# define casio_pictureformat_1bit 0x0100
# define casio_pictureformat_1bit_r 0x0101
# define casio_pictureformat_1bit_packed 0x0110
# define casio_pictureformat_1bit_packed_r 0x0111
# define casio_pictureformat_1bit_old 0x0120
# define casio_pictureformat_2bit_dual 0x0200
# define casio_pictureformat_4bit 0x0400
# define casio_pictureformat_4bit_rgb 0x0400
# define casio_pictureformat_4bit_code 0x0410
# define casio_pictureformat_4bit_color 0x0420
# define casio_pictureformat_4bit_mono 0x0421
# define casio_pictureformat_casemul 0x0800
# define casio_pictureformat_16bit 0x1000
/* ---
* Utilities.
* --- */
CASIO_BEGIN_DECLS
/* Picture management. */
CASIO_EXTERN(void) casio_free_picture
OF((casio_picture_t *casio__picture));
CASIO_EXTERN(int) casio_get_picture_dimensions
OF((casio_picture_t *casio__picture, unsigned int casio__widthp,
unsigned int casio__heightp));
CASIO_EXTERN(int) casio_access_pixels
OF((casio_picture_t *casio__picture, casio_pixel_t ***casio__pixelsp));
/* Picture encoding and decoding. */
CASIO_EXTERN(int) casio_decode_picture
OF((casio_picture_t **casio__picturep, unsigned int casio__width,
unsigned int casio__height, casio_pictureformat_t casio__format,
tio_stream_t *casio__buffer));
CASIO_EXTERN(int) casio_decode_picture_buffer
OF((casio_picture_t **casio__picturep, unsigned int casio__width,
unsigned int casio__height, casio_pictureformat_t casio__format,
void const *casio__data, size_t casio__data_size));
CASIO_EXTERN(int) casio_get_picture_encoded_size
OF((casio_picture_t *casio__picture, casio_pictureformat_t casio__format,
size_t *casio__sizep));
CASIO_EXTERN(int) casio_encode_picture
OF((casio_picture_t *casio__picture,
void *casio__buf, size_t casio__buf_size));
CASIO_END_DECLS
CASIO_END_NAMESPACE
#endif /* LIBCASIO_PICTURE_H */
|