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
|
/* See LICENSE file for copyright and license details. */
#ifndef LIBBLIND_H
#define LIBBLIND_H
#include <stdlib.h>
#ifdef LIBBLIND_NO_NAMESPACE
/* errors and error related functions are still namespaced */
# define libblind_dimension dimension
# define LIBBLIND_WIDTH WIDTH
# define LIBBLIND_HEIGHT HEIGHT
# define LIBBLIND_LENGTH LENGTH
# define libblind_colour_space colour_space
# define LIBBLIND_CIEXYZ CIEXYZ
# define LIBBLIND_YUV_NONLINEAR YUV_NONLINEAR
# define LIBBLIND_SRGB_NONLINEAR SRGB_NONLINEAR
# define LIBBLIND_SRGB SRGB
# define libblind_alpha alpha
# define LIBBLIND_NO_ALPHA NO_ALPHA
# define LIBBLIND_UNPREMULTIPLIED UNPREMULTIPLIED
# define LIBBLIND_PREMULTIPLIED PREMULTIPLIED
# define libblind_encoding encoding
# define LIBBLIND_FLOAT FLOAT
# define LIBBLIND_DOUBLE DOUBLE
# define LIBBLIND_LONG_DOUBLE LONG_DOUBLE
# define LIBBLIND_UINT8 UINT8
# define LIBBLIND_UINT16 UINT16
# define LIBBLIND_UINT32 UINT32
# define LIBBLIND_UINT64 UINT64
# define libblind_endian endian
# define LIBBLIND_HOST HOST
# define LIBBLIND_LITTLE LITTLE
# define LIBBLIND_BIG BIG
# define libblind_stream stream
# define get_pixfmt libblind_get_pixfmt
# define set_pixfmt libblind_set_pixfmt
# define read_stream libblind_read_stream
# define init_stream libblind_init_stream
# define check_dimensions libblind_check_dimensions
# define read_segment libblind_read_segment
# define read_frame libblind_read_frame
# define read_row libblind_read_row
# define read_pixel libblind_read_pixel
# define send_frames libblind_send_frames
# define send_rows libblind_send_rows
# define send_pixels libblind_send_pixels
# define send_stream libblind_send_stream
#endif
#ifndef LIBBLIND_BUFSIZ
# define LIBBLIND_BUFSIZ 8192
#endif
#define LIBBLIND_HEAD_MAX\
(((sizeof(size_t) == 1 ? 3 : (5 * sizeof(size_t) / 2)) + ((size_t)-1 < 1))\
* 3 + sizeof(((struct libblind_stream *)0)->pixfmt) + 10)
enum libblind_dimension {
LIBBLIND_WIDTH = 1,
LIBBLIND_HEIGHT = 2,
LIBBLIND_LENGTH = 4
};
enum libblind_colour_space {
LIBBLIND_CIEXYZ,
LIBBLIND_YUV_NONLINEAR,
LIBBLIND_SRGB_NONLINEAR,
LIBBLIND_SRGB
};
enum libblind_alpha {
LIBBLIND_NO_ALPHA,
LIBBLIND_UNPREMULTIPLIED,
LIBBLIND_PREMULTIPLIED /* currently unused */
};
enum libblind_encoding {
LIBBLIND_FLOAT,
LIBBLIND_DOUBLE,
LIBBLIND_LONG_DOUBLE, /* currently unused */
LIBBLIND_UINT8, /* currently unused */
LIBBLIND_UINT16,
LIBBLIND_UINT32, /* currently unused */
LIBBLIND_UINT64 /* currently unused */
};
enum libblind_endian {
LIBBLIND_HOST,
LIBBLIND_LITTLE,
LIBBLIND_BIG /* currently unused */
};
struct libblind_stream {
size_t frames;
size_t width;
size_t height;
size_t n_chan;
size_t chan_size;
size_t pixel_size;
char pixfmt[32];
enum libblind_colour_space space;
enum libblind_alpha alpha;
enum libblind_encoding encoding;
enum libblind_endian endian;
short int alpha_chan;
short int luma_chan;
int fd;
size_t ptr;
size_t xptr;
char buf[LIBBLIND_BUFSIZ];
const char *file;
size_t headlen;
size_t row_size;
size_t col_size;
size_t frame_size;
};
#define LIBBLIND_LIST_ERRORS(_)\
_( -2, LIBBLIND_EVIDTOOLONG, "Video is too long")\
_( -3, LIBBLIND_EVIDTOOWIDE, "Video is too wide")\
_( -4, LIBBLIND_EVIDTOOTALL, "Video is too tall")\
_( -5, LIBBLIND_EVIDTOOLARGE, "Video is too large")\
_( -6, LIBBLIND_EFRMTOOWIDE, "Video frame is too wide")\
_( -7, LIBBLIND_EFRMTOOTALL, "Video frame is too tall")\
_( -8, LIBBLIND_EFRMTOOLARGE, "Video frame is too large")\
_( -9, LIBBLIND_EZEROWIDTH, "Video has zero width")\
_(-10, LIBBLIND_EZEROHEIGHT, "Video has zero height")\
_(-11, LIBBLIND_EBADFORMAT, "File format not supported")\
_(-12, LIBBLIND_EPIXFMTNOSUPPORT, "Pixel format not supported")\
_(-13, LIBBLIND_EGEOMDIFF, "Videos do not have the same geometries")\
_(-14, LIBBLIND_EGEOMNOCOMPAT, "Videos have incompatible geometries")\
_(-15, LIBBLIND_EPIXFMTDIFF, "Videos do not have the same pixel formats")\
_(-16, LIBBLIND_EPIXFMTNOCOMPAT, "Videos have incompatible pixel formats")\
_(-17, LIBBLIND_ECORRUPTSTATE, "State corrupted")\
_(-18, LIBBLIND_EINCOMPLETE, "Incomplete segment")\
_(-19, LIBBLIND_EINCOMPLETEFRAME, "Incomplete frame")\
_(-20, LIBBLIND_EINCOMPLETEROW, "Incomplete row")\
_(-21, LIBBLIND_EINCOMPLETEPIX, "Incomplete pixel")
enum {
LIBBLIND_ESYSTEM = -1 /* errno set */
#define LIBBLIND_X(NUM, NAM, STR) , NAM = NUM
LIBBLIND_LIST_ERRORS(LIBBLIND_X)
#undef LIBBLIND_X
};
const char *libblind_strerror(int);
void libblind_perror(const char *, int);
const char *libblind_get_pixfmt(const char *, const char *);
int libblind_set_pixfmt(struct libblind_stream *, const char *);
ssize_t libblind_read_stream(struct libblind_stream *, size_t);
int libblind_init_stream(struct libblind_stream *);
int libblind_check_dimensions(const struct libblind_stream *, enum dimension);
int libblind_read_segment(struct libblind_stream *, void *, size_t);
ssize_t libblind_send_frames(struct libblind_stream *, int, size_t, int *);
ssize_t libblind_send_rows(struct libblind_stream *, int, size_t, int *);
ssize_t libblind_send_pixels(struct libblind_stream *, int, size_t, int *);
int libblind_send_stream(struct libblind_stream *, int, int *);
static inline int
libblind_read_frame(struct libblind_stream *stream, void *buf)
{
int r = libblind_read_segment(stream, buf, stream->frame_size);
return r == LIBBLIND_EINCOMPLETE ? LIBBLIND_EINCOMPLETEFRAME : r;
}
static inline int
libblind_read_row(struct libblind_stream *stream, void *buf)
{
int r = libblind_read_segment(stream, buf, stream->row_size);
return r == LIBBLIND_EINCOMPLETE ? LIBBLIND_EINCOMPLETEROW : r;
}
static inline int
libblind_read_pixel(struct libblind_stream *stream, void *buf)
{
int r = libblind_read_segment(stream, buf, stream->pixel_size);
return r == LIBBLIND_EINCOMPLETE ? LIBBLIND_EINCOMPLETEROW : r;
}
#endif
|