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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/*
# (C) 2008 Hans de Goede <hdegoede@redhat.com>
# This program 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 2.1 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __LIBV4LCONVERT_PRIV_H
#define __LIBV4LCONVERT_PRIV_H
#include <stdio.h>
#include <sys/types.h>
#include "libv4lconvert.h"
#include "control/libv4lcontrol.h"
#include "processing/libv4lprocessing.h"
#include "tinyjpeg.h"
/* Workaround these potentially missing from videodev2.h */
#ifndef V4L2_PIX_FMT_SPCA501
#define V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S','5','0','1') /* YUYV per line */
#endif
#ifndef V4L2_PIX_FMT_SPCA505
#define V4L2_PIX_FMT_SPCA505 v4l2_fourcc('S','5','0','5') /* YYUV per line */
#endif
#ifndef V4L2_PIX_FMT_SPCA508
#define V4L2_PIX_FMT_SPCA508 v4l2_fourcc('S','5','0','8') /* YUVY per line */
#endif
#ifndef V4L2_PIX_FMT_SPCA561
#define V4L2_PIX_FMT_SPCA561 v4l2_fourcc('S','5','6','1')
#endif
#ifndef V4L2_PIX_FMT_PAC207
#define V4L2_PIX_FMT_PAC207 v4l2_fourcc('P','2','0','7')
#endif
#ifndef V4L2_PIX_FMT_MR97310A
#define V4L2_PIX_FMT_MR97310A v4l2_fourcc('M','3','1','0')
#endif
#ifndef V4L2_PIX_FMT_SN9C2028
#define V4L2_PIX_FMT_SN9C2028 v4l2_fourcc('S', 'O', 'N', 'X')
#endif
#ifndef V4L2_PIX_FMT_SQ905C
#define V4L2_PIX_FMT_SQ905C v4l2_fourcc('9', '0', '5', 'C')
#endif
#ifndef V4L2_PIX_FMT_PJPG
#define V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G')
#endif
#ifndef V4L2_PIX_FMT_SGBRG8
#define V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G','B','R','G')
#endif
#ifndef V4L2_PIX_FMT_SGRBG8
#define V4L2_PIX_FMT_SGRBG8 v4l2_fourcc('G','R','B','G')
#endif
#ifndef V4L2_PIX_FMT_SRGGB8
#define V4L2_PIX_FMT_SRGGB8 v4l2_fourcc('R','G','G','B')
#endif
#ifndef V4L2_PIX_FMT_YVYU
#define V4L2_PIX_FMT_YVYU v4l2_fourcc('Y', 'V', 'Y', 'U')
#endif
#ifndef V4L2_PIX_FMT_HM12
#define V4L2_PIX_FMT_HM12 v4l2_fourcc('H', 'M', '1', '2')
#endif
#ifndef V4L2_PIX_FMT_SN9C20X_I420
#define V4L2_PIX_FMT_SN9C20X_I420 v4l2_fourcc('S', '9', '2', '0')
#endif
#ifndef V4L2_PIX_FMT_OV511
#define V4L2_PIX_FMT_OV511 v4l2_fourcc('O', '5', '1', '1')
#endif
#ifndef V4L2_PIX_FMT_OV518
#define V4L2_PIX_FMT_OV518 v4l2_fourcc('O', '5', '1', '8') /* ov518 JPEG */
#endif
#ifndef V4L2_FMT_FLAG_EMULATED
#define V4L2_FMT_FLAG_EMULATED 0x0002
#endif
#define ARRAY_SIZE(x) ((int)sizeof(x)/(int)sizeof((x)[0]))
#define V4LCONVERT_ERROR_MSG_SIZE 256
#define V4LCONVERT_MAX_FRAMESIZES 16
#define V4LCONVERT_ERR(...) \
snprintf(data->error_msg, V4LCONVERT_ERROR_MSG_SIZE, \
"v4l-convert: error " __VA_ARGS__)
/* Card flags */
#define V4LCONVERT_IS_UVC 0x01
#define V4LCONVERT_IS_SN9C20X 0x02
/* Pixformat flags */
#define V4LCONVERT_COMPRESSED 0x01 /* Compressed format */
#define V4LCONVERT_NEEDS_CONVERSION 0x02 /* Apps likely wont know this */
#define V4LCONVERT_COMPRESSED_AND_NEEDS_CONVERSION 0x03
struct v4lconvert_data {
int fd;
int flags; /* bitfield */
int control_flags; /* bitfield */
int supported_src_formats; /* bitfield */
unsigned int no_formats;
char error_msg[V4LCONVERT_ERROR_MSG_SIZE];
struct jdec_private *jdec;
struct v4l2_frmsizeenum framesizes[V4LCONVERT_MAX_FRAMESIZES];
unsigned int no_framesizes;
int convert1_buf_size;
int convert2_buf_size;
int rotate90_buf_size;
int flip_buf_size;
int convert_pixfmt_buf_size;
unsigned char *convert1_buf;
unsigned char *convert2_buf;
unsigned char *rotate90_buf;
unsigned char *flip_buf;
unsigned char *convert_pixfmt_buf;
struct v4lcontrol_data *control;
struct v4lprocessing_data *processing;
/* Data for external decompression helpers code */
pid_t decompress_pid;
int decompress_in_pipe[2]; /* Data from helper to us */
int decompress_out_pipe[2]; /* Data from us to helper */
};
struct v4lconvert_pixfmt {
unsigned int fmt;
int flags;
};
void v4lconvert_fixup_fmt(struct v4l2_format *fmt);
void v4lconvert_rgb24_to_yuv420(const unsigned char *src, unsigned char *dest,
const struct v4l2_format *src_fmt, int bgr, int yvu);
void v4lconvert_yuv420_to_rgb24(const unsigned char *src, unsigned char *dst,
int width, int height, int yvu);
void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dst,
int width, int height, int yvu);
void v4lconvert_yuyv_to_rgb24(const unsigned char *src, unsigned char *dst,
int width, int height);
void v4lconvert_yuyv_to_bgr24(const unsigned char *src, unsigned char *dst,
int width, int height);
void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dst,
int width, int height, int yvu);
void v4lconvert_yvyu_to_rgb24(const unsigned char *src, unsigned char *dst,
int width, int height);
void v4lconvert_yvyu_to_bgr24(const unsigned char *src, unsigned char *dst,
int width, int height);
void v4lconvert_uyvy_to_rgb24(const unsigned char *src, unsigned char *dst,
int width, int height);
void v4lconvert_uyvy_to_bgr24(const unsigned char *src, unsigned char *dst,
int width, int height);
void v4lconvert_uyvy_to_yuv420(const unsigned char *src, unsigned char *dst,
int width, int height, int yvu);
void v4lconvert_swap_rgb(const unsigned char *src, unsigned char *dst,
int width, int height);
void v4lconvert_swap_uv(const unsigned char *src, unsigned char *dst,
const struct v4l2_format *src_fmt);
void v4lconvert_rgb565_to_rgb24(const unsigned char *src, unsigned char *dest,
int width, int height);
void v4lconvert_rgb565_to_bgr24(const unsigned char *src, unsigned char *dest,
int width, int height);
void v4lconvert_rgb565_to_yuv420(const unsigned char *src, unsigned char *dest,
const struct v4l2_format *src_fmt, int yvu);
void v4lconvert_spca501_to_yuv420(const unsigned char *src, unsigned char *dst,
int width, int height, int yvu);
void v4lconvert_spca505_to_yuv420(const unsigned char *src, unsigned char *dst,
int width, int height, int yvu);
void v4lconvert_spca508_to_yuv420(const unsigned char *src, unsigned char *dst,
int width, int height, int yvu);
void v4lconvert_sn9c20x_to_yuv420(const unsigned char *src, unsigned char *dst,
int width, int height, int yvu);
void v4lconvert_decode_spca561(const unsigned char *src, unsigned char *dst,
int width, int height);
void v4lconvert_decode_sn9c10x(const unsigned char *src, unsigned char *dst,
int width, int height);
int v4lconvert_decode_pac207(struct v4lconvert_data *data,
const unsigned char *inp, int src_size, unsigned char *outp,
int width, int height);
void v4lconvert_decode_mr97310a(const unsigned char *src, unsigned char *dst,
int width, int height);
void v4lconvert_decode_sn9c2028(const unsigned char *src, unsigned char *dst,
int width, int height);
void v4lconvert_decode_sq905c(const unsigned char *src, unsigned char *dst,
int width, int height);
void v4lconvert_bayer_to_rgb24(const unsigned char *bayer,
unsigned char *rgb, int width, int height, unsigned int pixfmt);
void v4lconvert_bayer_to_bgr24(const unsigned char *bayer,
unsigned char *rgb, int width, int height, unsigned int pixfmt);
void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv,
int width, int height, unsigned int src_pixfmt, int yvu);
void v4lconvert_hm12_to_rgb24(const unsigned char *src,
unsigned char *dst, int width, int height);
void v4lconvert_hm12_to_bgr24(const unsigned char *src,
unsigned char *dst, int width, int height);
void v4lconvert_hm12_to_yuv420(const unsigned char *src,
unsigned char *dst, int width, int height, int yvu);
void v4lconvert_rotate90(unsigned char *src, unsigned char *dest,
struct v4l2_format *fmt);
void v4lconvert_flip(unsigned char *src, unsigned char *dest,
struct v4l2_format *fmt, int hflip, int vflip);
void v4lconvert_crop(unsigned char *src, unsigned char *dest,
const struct v4l2_format *src_fmt, const struct v4l2_format *dest_fmt);
int v4lconvert_helper_decompress(struct v4lconvert_data *data,
const char *helper, const unsigned char *src, int src_size,
unsigned char *dest, int dest_size, int width, int height, int command);
void v4lconvert_helper_cleanup(struct v4lconvert_data *data);
#endif
|