Instrument Neutral Distributed Interface INDI 2.2.5
v4l2_builtin_decoder.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2005 by Jasem Mutlaq <[email protected]>
3 Copyright (C) 2014 by geehalel <[email protected]>
4
5 V4L2 Builtin Decoder
6
7 As of August 2015 gst-lauch-1.0 and v4l2loopback do not work together well (https://github.com/umlaeute/v4l2loopback/issues/83)
8 Still use v4l2loopback (see below) but with ffmpeg:
9 ffmpeg -f lavfi -re -i "smptebars=size=640x480:rate=30" -pix_fmt yuv420p -f v4l2 /dev/video8
10 Use the -re flag to really get frame rate otherwise ffmpeg outputs frames as fast as possible (400 to 700fps).
11 With indi-opencv-ccd use /dev/video1 as v4l2loopback device
12 for 16 bits gray
13 ffmpeg -f lavfi -re -i "testsrc=size=640x480:rate=30" -pix_fmt gray16le -f v4l2 /dev/video1
14 Profiling
15 cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_CXX_FLAGS=-pg /nfs/devel/sourceforge/indi-code/libindi/
16 kill indiserver with the kill command, not ctrl-c
17
18 To test decoders, use gstreamer and the v4l2loopback kernel module
19 Use the experimental git branch of v4l2loopback to get more pixel formats
20 git clone https://github.com/umlaeute/v4l2loopback/ -b experimental
21 cd v4l2loopback; make; sudo make install
22 sudo modprobe v4l2loopback video_nr=8 card_label="Indi V4L2 Test Loopback" # debug=n
23 gst-launch-1.0 -v videotestsrc ! video/x-raw,format=\‍(string\‍)UYVY,width=1024,height=576,framerate=\‍(fraction\‍)30/1 ! v4l2sink device=/dev/video8
24 gst-launch-1.0 -v v4l2src device=/dev/video0 ! jpegdec ! videoconvert! video/x-raw,format=\‍(string\‍)UYVY,width=1280,height=960,framerate=\‍(fraction\‍)5/1 ! v4l2sink device=/dev/video8
25
26 For Bayer I used gst-launch-0.10
27 modprobe v4l2loopback video_nr=8 card_label="Indi Loopback" exclusive_caps=0,0
28 gst-launch-0.10 -v videotestsrc ! 'video/x-raw-bayer, format=(string)bggr, width=640, height=480, framerate=(fraction)2/1' ! v4l2sink device=/dev/video8
29
30 For Gray16 format I use gst-launch with a videotstsrc in GRAY16 format writing in a FIFO and a C program reading the FIFO into the v4l2loopback device
31 mkfifo /tmp/videopipe
32 gst-launch-1.0 -v videotestsrc ! video/x-raw,format=\‍(string\‍)GRAY16_LE,width=1024,height=576,framerate=\‍(fraction\‍)25/1 ! filesink location =/tmp/videopipe
33 ./gray16_to_v4l2 /dev/video8 < /tmp/videopipe &
34 The C program ./gray16_to_v4l2 is adapated from https://github.com/umlaeute/v4l2loopback/blob/master/examples/yuv4mpeg_to_v4l2.c :
35 process_header/read_header calls are suppressed (copy_frames uses a while (true) loop), frame_width and frame_height are constant
36 and V4L2 pixel format is set to V4L2_PIX_FMT_Y16.
37
38 To repeat an avi stream
39 ./v4l2loopback-ctl set-caps 'video/x-raw-yuv,width=720,height=576' /dev/video8
40 ./v4l2loopback-ctl set-fps 25/1 /dev/video8
41 as normal user
42 while true; do gst-launch-0.10 -vvv filesrc location=chi-aquarius.avi ! avidemux name=demux demux.video_00 ! queue ! decodebin ! videoscale add-borders=true ! v4l2sink device=/dev/video8 ; done
43
44 This library is free software; you can redistribute it and/or
45 modify it under the terms of the GNU Lesser General Public
46 License as published by the Free Software Foundation; either
47 version 2.1 of the License, or (at your option) any later version.
48
49 This library is distributed in the hope that it will be useful,
50 but WITHOUT ANY WARRANTY; without even the implied warranty of
51 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
52 Lesser General Public License for more details.
53
54 You should have received a copy of the GNU Lesser General Public
55 License along with this library; if not, write to the Free Software
56 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
57
58*/
59
61
62//#include "indilogger.h"
63#include "ccvt.h"
64#include "v4l2_colorspace.h"
65
66#include <cstring> // memcpy
67
69{
70 unsigned int i;
71 name = "Builtin decoder";
72 useSoftCrop = false;
73 doCrop = false;
74 doQuantization = false;
75 YBuf = nullptr;
76 UBuf = nullptr;
77 VBuf = nullptr;
78 yuvBuffer = nullptr;
79 yuyvBuffer = nullptr;
80 colorBuffer = nullptr;
81 rgb24_buffer = nullptr;
82 linearBuffer = nullptr;
83 //cropbuf = nullptr;
84 for (i = 0; i < 32; i++)
85 {
86 lut5[i] = (char)(((float)i * 255.0) / 31.0);
87 }
88 for (i = 0; i < 64; i++)
89 {
90 lut6[i] = (char)(((float)i * 255.0) / 63.0);
91 }
93 bpp = 8;
94}
95
97{
98 YBuf = nullptr;
99 UBuf = nullptr;
100 VBuf = nullptr;
101 if (yuvBuffer)
102 delete[](yuvBuffer);
103 yuvBuffer = nullptr;
104 if (yuyvBuffer)
105 delete[](yuyvBuffer);
106 yuyvBuffer = nullptr;
107 if (colorBuffer)
108 delete[](colorBuffer);
109 colorBuffer = nullptr;
110 if (rgb24_buffer)
111 delete[](rgb24_buffer);
112 rgb24_buffer = nullptr;
113 if (linearBuffer)
114 delete[](linearBuffer);
115 linearBuffer = nullptr;
116};
117
122
123void V4L2_Builtin_Decoder::decode(unsigned char *frame, struct v4l2_buffer *buf, bool native)
124{
125 //LOG_INFO("Calling builtin decoder decode");
126 //IDLog("Decoding buffer at %lx, len %d, bytesused %d, bytesperline %d, sequence %d, flag %x, field %x, use soft crop %c, do crop %c\n", frame, buf->length, buf->bytesused, fmt.fmt.pix.bytesperline, buf->sequence, buf->flags, buf->field, (useSoftCrop?'y':'n'), (doCrop?'y':'n'));
127
128 switch (fmt.fmt.pix.pixelformat)
129 {
130 case V4L2_PIX_FMT_GREY:
131 if (useSoftCrop && doCrop)
132 {
133 unsigned char *src = frame + crop.c.left + (crop.c.top * fmt.fmt.pix.width);
134 unsigned char *dest = YBuf;
135
136 for (unsigned int i = 0; i < (unsigned int)crop.c.height; i++)
137 {
138 memcpy(dest, src, crop.c.width);
139 src += fmt.fmt.pix.width;
140 dest += crop.c.width;
141 }
142 }
143 else
144 {
145 memcpy(YBuf, frame, bufwidth * bufheight);
146 }
147 break;
148
149 case V4L2_PIX_FMT_Y16:
150 if (useSoftCrop && doCrop)
151 {
152 unsigned char *src = frame + 2 * (crop.c.left) + (crop.c.top * fmt.fmt.pix.bytesperline);
153 unsigned char *dest = yuyvBuffer;
154
155 for (unsigned int i = 0; i < (unsigned int)crop.c.height; i++)
156 {
157 memcpy(dest, src, 2 * crop.c.width);
158 src += fmt.fmt.pix.bytesperline;
159 dest += 2 * crop.c.width;
160 }
161 }
162 else // No soft crop
163 {
164 unsigned char *src = frame;
165 unsigned char *dest = yuyvBuffer;
166 for (unsigned int i = 0; i < bufheight; i++)
167 {
168 memcpy(dest, src, 2 * bufwidth); // Copy 2 * width bytes for each line
169 src += fmt.fmt.pix.bytesperline; // Advance source by its stride
170 dest += 2 * bufwidth; // Advance destination by its stride (2 * width)
171 }
172 }
173 break;
174
175 case V4L2_PIX_FMT_YUV420:
176 case V4L2_PIX_FMT_YVU420:
177 if (useSoftCrop && doCrop)
178 {
179 unsigned char *src = frame + crop.c.left + (crop.c.top * fmt.fmt.pix.width);
180 unsigned char *dest = YBuf;
181
182 //IDLog("grabImage: src=%d dest=%d\n", src, dest);
183 for (unsigned int i = 0; i < (unsigned int)crop.c.height; i++)
184 {
185 memcpy(dest, src, crop.c.width);
186 src += fmt.fmt.pix.width;
187 dest += crop.c.width;
188 }
189
190 dest = UBuf;
191 src = frame + (fmt.fmt.pix.width * fmt.fmt.pix.height) +
192 ((crop.c.left + (crop.c.top * fmt.fmt.pix.width) / 2) / 2);
193 if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YVU420)
194 {
195 dest = VBuf;
196 }
197 for (unsigned int i = 0; i < (unsigned int)crop.c.height / 2; i++)
198 {
199 memcpy(dest, src, crop.c.width / 2);
200 src += fmt.fmt.pix.width / 2;
201 dest += crop.c.width / 2;
202 }
203
204 dest = VBuf;
205 src = frame + (fmt.fmt.pix.width * fmt.fmt.pix.height) +
206 ((fmt.fmt.pix.width * fmt.fmt.pix.height) / 4) +
207 ((crop.c.left + (crop.c.top * fmt.fmt.pix.width) / 2) / 2);
208 if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YVU420)
209 {
210 dest = UBuf;
211 }
212 for (unsigned int i = 0; i < (unsigned int)crop.c.height / 2; i++)
213 {
214 memcpy(dest, src, crop.c.width / 2);
215 src += fmt.fmt.pix.width / 2;
216 dest += crop.c.width / 2;
217 }
218 }
219 else
220 {
221 memcpy(YBuf, frame, bufwidth * bufheight);
222 if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YUV420)
223 {
224 memcpy(UBuf, frame + bufwidth * bufheight, (bufwidth / 2) * (bufheight / 2));
225 memcpy(VBuf, frame + bufwidth * bufheight + (bufwidth / 2) * (bufheight / 2),
226 (bufwidth / 2) * (bufheight / 2));
227 }
228 else
229 {
230 if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YVU420)
231 {
232 memcpy(VBuf, frame + bufwidth * bufheight, (bufwidth / 2) * (bufheight / 2));
233 memcpy(UBuf, frame + bufwidth * bufheight + (bufwidth / 2) * (bufheight / 2),
234 (bufwidth / 2) * (bufheight / 2));
235 }
236 }
237 }
238 break;
239
240 case V4L2_PIX_FMT_NV12:
241 case V4L2_PIX_FMT_NV21:
242 if (useSoftCrop && doCrop)
243 {
244 unsigned char *src = frame + crop.c.left + (crop.c.top * fmt.fmt.pix.bytesperline);
245 unsigned char *dest = YBuf, *destv = nullptr;
246
247 //IDLog("grabImage: src=%d dest=%d\n", src, dest);
248 for (unsigned int i = 0; i < (unsigned int)crop.c.height; i++)
249 {
250 memcpy(dest, src, crop.c.width);
251 src += fmt.fmt.pix.bytesperline;
252 dest += crop.c.width;
253 }
254
255 dest = UBuf;
256 destv = VBuf;
257 src = frame + (fmt.fmt.pix.bytesperline * fmt.fmt.pix.height) +
258 ((crop.c.left + (crop.c.top * fmt.fmt.pix.bytesperline) / 2) / 2);
259 if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_NV21)
260 {
261 dest = VBuf;
262 destv = UBuf;
263 }
264 for (unsigned int i = 0; i < (unsigned int)crop.c.height / 2; i++)
265 {
266 unsigned char *s = src;
267 for (unsigned int j = 0; j < (unsigned int)crop.c.width; j += 2)
268 {
269 *(dest++) = *(s++);
270 *(destv++) = *(s++);
271 }
272 src += fmt.fmt.pix.bytesperline;
273 }
274 }
275 else
276 {
277 unsigned char *src = frame;
278 unsigned char *dest = YBuf;
279 unsigned char *destv = VBuf;
280 unsigned char *s = nullptr;
281
282 for (unsigned int i = 0; i < bufheight; i++)
283 {
284 memcpy(dest, src, bufwidth);
285 src += fmt.fmt.pix.bytesperline;
286 dest += bufwidth;
287 }
288 dest = UBuf;
289 src = frame + (fmt.fmt.pix.bytesperline * bufheight);
290 if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_NV21)
291 {
292 dest = VBuf;
293 destv = UBuf;
294 }
295 for (unsigned int i = 0; i < bufheight / 2; i++)
296 {
297 s = src;
298 //IDLog("NV12: converting UV line %d at %p, offset %d, pUbuf %p offset %d, pVbuf %p offset %d\n", i, s, s- (frame + (fmt.fmt.pix.bytesperline * bufheight)), dest, dest-UBuf, destv, destv-VBuf);
299 for (unsigned int j = 0; j < bufwidth; j += 2)
300 {
301 *(dest++) = *(s++);
302 *(destv++) = *(s++);
303 }
304 src += fmt.fmt.pix.bytesperline;
305 }
306 }
307 break;
308
309 case V4L2_PIX_FMT_YUYV:
310 if (useSoftCrop && doCrop)
311 {
312 unsigned char *src = frame + 2 * (crop.c.left) + (crop.c.top * fmt.fmt.pix.bytesperline);
313 unsigned char *dest = yuyvBuffer;
314
315 for (unsigned int i = 0; i < (unsigned int)crop.c.height; i++)
316 {
317 memcpy(dest, src, 2 * crop.c.width);
318 src += fmt.fmt.pix.bytesperline;
319 dest += 2 * crop.c.width;
320 }
321 }
322 else
323 {
324 memcpy(yuyvBuffer, frame, 2 * bufwidth * bufheight);
325 }
326 break;
327
328 case V4L2_PIX_FMT_UYVY:
329 case V4L2_PIX_FMT_VYUY:
330 case V4L2_PIX_FMT_YVYU:
331 {
332 unsigned char *src = nullptr;
333 unsigned char *dest = yuyvBuffer;
334 unsigned char *s = nullptr, *s1 = nullptr, *s2 = nullptr, *s3 = nullptr, *s4 = nullptr;
335
336 if (useSoftCrop && doCrop)
337 {
338 src = frame + 2 * (crop.c.left) + (crop.c.top * fmt.fmt.pix.bytesperline);
339 //IDLog("Decoding UYVY with cropping %dx%d frame at %lx\n", width, height, src);
340 }
341 else
342 {
343 src = frame;
344 //IDLog("Decoding UYVY %dx%d frame at %lx\n", width, height, src);
345 }
346 for (int i = 0; i < (int)bufheight; i++)
347 {
348 s = src;
349 switch (fmt.fmt.pix.pixelformat)
350 {
351 case V4L2_PIX_FMT_UYVY:
352 s1 = (s + 1);
353 s2 = (s);
354 s3 = (s + 3);
355 s4 = (s + 2);
356 break;
357 case V4L2_PIX_FMT_VYUY:
358 s1 = (s + 1);
359 s2 = (s + 2);
360 s3 = (s + 3);
361 s4 = (s);
362 break;
363 case V4L2_PIX_FMT_YVYU:
364 s1 = (s);
365 s2 = (s + 3);
366 s3 = (s + 2);
367 s4 = (s + 1);
368 break;
369 }
370 for (int j = 0; j < (int)(bufwidth / 2); j++)
371 {
372 *(dest++) = *(s1);
373 *(dest++) = *(s2);
374 *(dest++) = *(s3);
375 *(dest++) = *(s4);
376 s1 += 4;
377 s2 += 4;
378 s3 += 4;
379 s4 += 4;
380 }
381 src += fmt.fmt.pix.bytesperline;
382 }
383 }
384 break;
385
386 case V4L2_PIX_FMT_RGB24:
387 {
388 unsigned char *src = nullptr, *dest = rgb24_buffer;
389
390 if (useSoftCrop && doCrop)
391 {
392 src = frame + (3 * (crop.c.left)) + (crop.c.top * fmt.fmt.pix.bytesperline);
393 }
394 else
395 {
396 src = frame;
397 }
398 for (unsigned int i = 0; i < bufheight; i++)
399 {
400 memcpy(dest, src, 3 * bufwidth);
401 src += fmt.fmt.pix.bytesperline;
402 dest += 3 * bufwidth;
403 }
404 //memcpy(rgb24_buffer, frame, fmt.fmt.pix.width * fmt.fmt.pix.height * 3);
405 }
406 break;
407
408 case V4L2_PIX_FMT_RGB555:
409 {
410 unsigned char *src, *dest = rgb24_buffer;
411
412 if (useSoftCrop && doCrop)
413 {
414 src = frame + (2 * (crop.c.left)) + (crop.c.top * fmt.fmt.pix.bytesperline);
415 }
416 else
417 {
418 src = frame;
419 }
420 for (unsigned int i = 0; i < bufheight; i++)
421 {
422 unsigned char *s = src;
423 for (unsigned int j = 0; j < bufwidth; j++)
424 {
425 *(dest++) = lut5[((*(s + 1) & 0x7C) >> 2)]; // R
426 *(dest++) = lut5[(((*(s + 1) & 0x03) << 3) | ((*(s) & 0xE0) >> 5))]; // G
427 *(dest++) = lut5[((*s) & 0x1F)]; // B
428 s += 2;
429 }
430 src += fmt.fmt.pix.bytesperline;
431 }
432 }
433 break;
434
435 case V4L2_PIX_FMT_RGB565:
436 {
437 unsigned char *src = nullptr, *dest = rgb24_buffer;
438
439 if (useSoftCrop && doCrop)
440 {
441 src = frame + (2 * (crop.c.left)) + (crop.c.top * fmt.fmt.pix.bytesperline);
442 }
443 else
444 {
445 src = frame;
446 }
447 for (unsigned int i = 0; i < bufheight; i++)
448 {
449 unsigned char *s = src;
450 for (unsigned int j = 0; j < bufwidth; j++)
451 {
452 *(dest++) = lut5[((*(s + 1) & 0xF8) >> 3)]; // R
453 *(dest++) = lut6[(((*(s + 1) & 0x07) << 3) | ((*(s) & 0xE0) >> 5))]; // G
454 *(dest++) = lut5[((*s) & 0x1F)]; // B
455 s += 2;
456 }
457 src += fmt.fmt.pix.bytesperline;
458 }
459 }
460 break;
461
462 case V4L2_PIX_FMT_SBGGR8:
463 bayer2rgb24(rgb24_buffer, frame, fmt.fmt.pix.width, fmt.fmt.pix.height);
464 break;
465
466 case V4L2_PIX_FMT_SRGGB8:
467 bayer_rggb_2rgb24(rgb24_buffer, frame, fmt.fmt.pix.width, fmt.fmt.pix.height);
468 break;
469 case V4L2_PIX_FMT_SGRBG8:
470 bayer_grbg_to_rgb24(rgb24_buffer, frame, fmt.fmt.pix.width, fmt.fmt.pix.height);
471 break;
472 case V4L2_PIX_FMT_SBGGR16:
473 bayer16_2_rgb24((unsigned short *)rgb24_buffer, (unsigned short *)frame, fmt.fmt.pix.width,
474 fmt.fmt.pix.height);
475 break;
476
477 case V4L2_PIX_FMT_JPEG:
478 case V4L2_PIX_FMT_MJPEG:
479 if (native)
480 memcpy(yuvBuffer, frame, buf->bytesused);
481 else
482 mjpegtoyuv420p(yuvBuffer, frame, fmt.fmt.pix.width, fmt.fmt.pix.height, buf->bytesused);
483 m_Size = buf->bytesused;
484 break;
485 default:
486 {
487 unsigned char *src = YBuf;
488
489 for (unsigned int i = 0; i < bufheight * bufwidth; i++)
490 {
491 *(src++) = random() % 255;
492 }
493 }
494 }
495}
496
497bool V4L2_Builtin_Decoder::setcrop(struct v4l2_crop c)
498{
499 crop = c;
500 IDLog("Decoder set crop: %dx%d at (%d, %d)\n", crop.c.width, crop.c.height, crop.c.left, crop.c.top);
501 if (supported_formats.count(fmt.fmt.pix.pixelformat) > 0 && supported_formats[fmt.fmt.pix.pixelformat]->softcrop)
502 {
503 doCrop = true;
504 allocBuffers();
505 return true;
506 }
507 else
508 {
509 doCrop = false;
510 return false;
511 }
512}
513
515{
516 IDLog("Decoder reset crop\n");
517 doCrop = false;
518 allocBuffers();
519}
520
522{
523 IDLog("Decoder usesoftcrop %s\n", (c ? "true" : "false"));
524 useSoftCrop = c;
525}
526
527void V4L2_Builtin_Decoder::setformat(struct v4l2_format f, bool use_ext_pix_format)
528{
529 (void)use_ext_pix_format;
530 fmt = f;
531 if (supported_formats.count(fmt.fmt.pix.pixelformat) == 1)
532 bpp = supported_formats.at(fmt.fmt.pix.pixelformat)->bpp;
533 else
534 bpp = 8;
535 IDLog("Decoder set format: %c%c%c%c size %dx%d bpp %d\n", (fmt.fmt.pix.pixelformat) & 0xFF,
536 (fmt.fmt.pix.pixelformat >> 8) & 0xFF, (fmt.fmt.pix.pixelformat >> 16) & 0xFF,
537 (fmt.fmt.pix.pixelformat >> 24) & 0xFF, f.fmt.pix.width, f.fmt.pix.height, bpp);
538 /* kernel 3.19
539 if (use_ext_pix_format && fmt.fmt.pix.priv == V4L2_PIX_FMT_PRIV_MAGIC)
540 IDLog("Decoder: Colorspace is %d, YCbCr encoding is %d, Quantization is %d\n", fmt.fmt.pix.colorspace, fmt.fmt.pix.ycbcr_enc, fmt.fmt.pix.quantization);
541 else
542 */
543 IDLog("Decoder: Colorspace is %d, using default ycbcr encoding and quantization\n", fmt.fmt.pix.colorspace);
544 doCrop = false;
545 allocBuffers();
546}
547
549{
550 return fmt.fmt.pix.pixelformat;
551}
552
554{
555 doQuantization = doquantization;
556}
558{
559 doLinearization = dolinearization;
560 if (doLinearization)
561 bpp = 16;
562 else if (supported_formats.count(fmt.fmt.pix.pixelformat) == 1)
563 bpp = supported_formats.at(fmt.fmt.pix.pixelformat)->bpp;
564 else
565 bpp = 8;
566}
568{
569 YBuf = nullptr;
570 UBuf = nullptr;
571 VBuf = nullptr;
572 if (yuvBuffer)
573 delete[](yuvBuffer);
574 yuvBuffer = nullptr;
575 if (yuyvBuffer)
576 delete[](yuyvBuffer);
577 yuyvBuffer = nullptr;
578 if (colorBuffer)
579 delete[](colorBuffer);
580 colorBuffer = nullptr;
581 if (rgb24_buffer)
582 delete[](rgb24_buffer);
583 rgb24_buffer = nullptr;
584 if (linearBuffer)
585 delete[](linearBuffer);
586 linearBuffer = nullptr;
587 //if (cropbuf) free(cropbuf); cropbuf=nullptr;
588
589 if (doCrop)
590 {
591 bufwidth = crop.c.width;
592 bufheight = crop.c.height;
593 }
594 else
595 {
596 bufwidth = fmt.fmt.pix.width;
597 bufheight = fmt.fmt.pix.height;
598 }
599
600 switch (fmt.fmt.pix.pixelformat)
601 {
602 case V4L2_PIX_FMT_GREY:
603 case V4L2_PIX_FMT_JPEG:
604 case V4L2_PIX_FMT_MJPEG:
605 case V4L2_PIX_FMT_YUV420:
606 case V4L2_PIX_FMT_YVU420:
607 case V4L2_PIX_FMT_NV12:
608 case V4L2_PIX_FMT_NV21:
609 yuvBuffer = new unsigned char[(bufwidth * bufheight) + ((bufwidth * bufheight) / 2)];
610 YBuf = yuvBuffer;
612 VBuf = UBuf + ((bufwidth * bufheight) / 4);
613 // bzero(Ubuf, ((bufwidth * bufheight) / 2));
614 break;
615 case V4L2_PIX_FMT_Y16:
616 case V4L2_PIX_FMT_YUYV:
617 case V4L2_PIX_FMT_UYVY:
618 case V4L2_PIX_FMT_VYUY:
619 case V4L2_PIX_FMT_YVYU:
620 yuyvBuffer = new unsigned char[(bufwidth * bufheight) * 2];
621 break;
622 case V4L2_PIX_FMT_RGB24:
623 case V4L2_PIX_FMT_RGB555:
624 case V4L2_PIX_FMT_RGB565:
625 case V4L2_PIX_FMT_SBGGR8:
626 case V4L2_PIX_FMT_SRGGB8:
627 case V4L2_PIX_FMT_SGRBG8:
628 case V4L2_PIX_FMT_SBGGR16:
629 rgb24_buffer = new unsigned char[(bufwidth * bufheight) * (bpp / 8) * 3];
630 break;
631 default:
632 yuvBuffer = new unsigned char[(bufwidth * bufheight) + ((bufwidth * bufheight) / 2)];
633 YBuf = yuvBuffer;
635 VBuf = UBuf + ((bufwidth * bufheight) / 4);
636 break;
637 }
638 IDLog("Decoder allocBuffers cropping %s\n", (doCrop ? "true" : "false"));
639}
640
642{
643 unsigned char *src = YBuf;
644 float *dest;
645 unsigned int i;
646 if (!linearBuffer)
647 {
648 linearBuffer = new float[(bufwidth * bufheight)];
649 }
650 dest = linearBuffer;
651 for (i = 0; i < bufwidth * bufheight; i++)
652 *dest++ = (*src++) / 255.0;
654}
656{
657 if (!yuvBuffer)
658 {
659 yuvBuffer = new unsigned char[(bufwidth * bufheight) + ((bufwidth * bufheight) / 2)];
660 YBuf = yuvBuffer;
662 VBuf = UBuf + ((bufwidth * bufheight) / 4);
663 }
664 switch (fmt.fmt.pix.pixelformat)
665 {
666 case V4L2_PIX_FMT_RGB24:
667 case V4L2_PIX_FMT_RGB555:
668 case V4L2_PIX_FMT_RGB565:
669 case V4L2_PIX_FMT_SBGGR8:
670 case V4L2_PIX_FMT_SRGGB8:
671 case V4L2_PIX_FMT_SGRBG8:
673 break;
674 case V4L2_PIX_FMT_YUYV:
675 case V4L2_PIX_FMT_UYVY:
676 case V4L2_PIX_FMT_VYUY:
677 case V4L2_PIX_FMT_YVYU:
678 // todo handcopy only Ybuf using an int, byfwidth should be even
680 break;
681 }
682}
683
685{
686 if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_Y16)
687 return yuyvBuffer;
688 makeY();
691 if (doLinearization)
692 {
693 unsigned int i;
694 float *src;
695 unsigned short *dest;
696 if (!yuyvBuffer)
697 yuyvBuffer = new unsigned char[(bufwidth * bufheight) * 2];
698 makeLinearY();
699 src = linearBuffer;
700 dest = (unsigned short *)yuyvBuffer;
701 for (i = 0; i < bufwidth * bufheight; i++)
702 *dest++ = (unsigned short)(*src++ * 65535.0);
703 return yuyvBuffer;
704 }
705 return YBuf;
706}
707
716
718{
719 return UBuf;
720}
721
723{
724 return VBuf;
725}
726
727/* used for streaming/exposure */
728#if 0
729unsigned char * V4L2_Builtin_Decoder::geColorBuffer()
730{
731 //cerr << "in get color buffer " << endl;
732 //IDLog("Decoder geRGBBuffer %s\n", (doCrop?"true":"false"));
733 if (!colorBuffer) colorBuffer = new unsigned char[(bufwidth * bufheight) * (bpp / 8) * 4];
734 switch (fmt.fmt.pix.pixelformat)
735 {
736 case V4L2_PIX_FMT_GREY:
737 case V4L2_PIX_FMT_JPEG:
738 case V4L2_PIX_FMT_MJPEG:
739 case V4L2_PIX_FMT_YUV420:
740 case V4L2_PIX_FMT_YVU420:
741 case V4L2_PIX_FMT_NV12:
742 case V4L2_PIX_FMT_NV21:
744 break;
745
746 case V4L2_PIX_FMT_YUYV:
747 case V4L2_PIX_FMT_UYVY:
748 case V4L2_PIX_FMT_VYUY:
749 case V4L2_PIX_FMT_YVYU:
751 break;
752 case V4L2_PIX_FMT_RGB24:
753 case V4L2_PIX_FMT_RGB555:
754 case V4L2_PIX_FMT_RGB565:
755 case V4L2_PIX_FMT_SBGGR8:
756 case V4L2_PIX_FMT_SRGGB8:
758 break;
759 case V4L2_PIX_FMT_Y16:
760 /* OOOps this is planar ARGB */
761 /*
762 bzero(colorBuffer, bufwidth * bufheight * 2);
763 memcpy(colorBuffer + (bufwidth * bufheight * 2), yuyvBuffer, bufwidth * bufheight * 2);
764 memcpy(colorBuffer + 2 * (bufwidth * bufheight * 2), yuyvBuffer, bufwidth * bufheight * 2);
765 memcpy(colorBuffer + 3 * (bufwidth * bufheight * 2), yuyvBuffer, bufwidth * bufheight * 2);
766 */
767 {
768 /* this is bgra , use unsigned short here... */
769 unsigned int i;
770 unsigned char * src = yuyvBuffer;
771 unsigned char * dest = colorBuffer;
772 for (i = 0; i < bufwidth * bufheight; i += 1)
773 {
774 *dest++ = *src;
775 *dest++ = *(src + 1);
776 *dest++ = *src;
777 *dest++ = *(src + 1);
778 *dest++ = *src;
779 *dest++ = *(src + 1);
780 *dest++ = 0;
781 *dest++ = 0;
782 src += 2;
783 }
784 }
785 break;
786 case V4L2_PIX_FMT_SBGGR16:
787 {
788 /* this is bgra , now I use unsigned short! */
789 unsigned int i;
790 unsigned short * src = (unsigned short *)rgb24_buffer;
791 unsigned short * dest = (unsigned short *)colorBuffer;
792 for (i = 0; i < bufwidth * bufheight; i += 1)
793 {
794 *dest++ = *(src + 2);
795 *dest++ = *(src + 1);
796 *dest++ = *(src);
797 *dest++ = 0;
798 src += 3;
799 }
800 }
801 default:
803 break;
804 }
805 return colorBuffer;
806}
807#endif
808
810{
811 if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG)
812 {
813 size = m_Size;
814 return yuvBuffer;
815 }
816 else
817 return nullptr;
818}
819
820/* used for SER recorder */
822{
823 //cerr << "in get color buffer " << endl;
824 //IDLog("Decoder geRGBBuffer %s\n", (doCrop?"true":"false"));
825 if (!rgb24_buffer)
826 rgb24_buffer = new unsigned char[(bufwidth * bufheight) * 3];
827 switch (fmt.fmt.pix.pixelformat)
828 {
829 case V4L2_PIX_FMT_GREY:
830 case V4L2_PIX_FMT_JPEG:
831 case V4L2_PIX_FMT_MJPEG:
832 case V4L2_PIX_FMT_YUV420:
833 case V4L2_PIX_FMT_YVU420:
834 case V4L2_PIX_FMT_NV12:
835 case V4L2_PIX_FMT_NV21:
837 break;
838 case V4L2_PIX_FMT_YUYV:
839 case V4L2_PIX_FMT_UYVY:
840 case V4L2_PIX_FMT_VYUY:
841 case V4L2_PIX_FMT_YVYU:
842 //if (!colorBuffer) colorBuffer = new unsigned char[(bufwidth * bufheight) * 4];
843 //ccvt_yuyv_bgr32(bufwidth, bufheight, yuyvBuffer, rgb24_buffer);
844 //ccvt_bgr32_rgb24(bufwidth, bufheight, colorBuffer, (void*)rgb24_buffer);
846 break;
847 case V4L2_PIX_FMT_RGB24:
848 case V4L2_PIX_FMT_RGB555:
849 case V4L2_PIX_FMT_RGB565:
850 case V4L2_PIX_FMT_SBGGR8:
851 case V4L2_PIX_FMT_SRGGB8:
852 case V4L2_PIX_FMT_SGRBG8:
853 case V4L2_PIX_FMT_SBGGR16:
854 break;
855 default:
857 break;
858 }
859 return rgb24_buffer;
860}
861
863{
864 return (int)(bpp);
865}
866
868{
869 //IDLog("Checking support for %c%c%c%c: %c\n", format&0xFF, (format>>8)&0xFF, (format>>16)&0xFF,(format>>24)&0xFF, (supported_formats.count(format) > 0)?'y':'n');
870 return (supported_formats.count(format) > 0);
871}
872
873const std::vector<unsigned int> &V4L2_Builtin_Decoder::getsupportedformats()
874{
875 return vsuppformats;
876}
877
879{
880 /* RGB formats */
881 // V4L2_PIX_FMT_RGB332 , // v4l2_fourcc('R', 'G', 'B', '1') /* 8 RGB-3-3-2 */
882 // V4L2_PIX_FMT_RGB444 , // v4l2_fourcc('R', '4', '4', '4') /* 16 xxxxrrrr ggggbbbb */
883 // V4L2_PIX_FMT_RGB555 , // v4l2_fourcc('R', 'G', 'B', 'O') /* 16 RGB-5-5-5 */
884 supported_formats.insert(
885 std::make_pair(V4L2_PIX_FMT_RGB555, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_RGB555, 8, true)));
886 // V4L2_PIX_FMT_RGB565 , // v4l2_fourcc('R', 'G', 'B', 'P') /* 16 RGB-5-6-5 */
887 supported_formats.insert(
888 std::make_pair(V4L2_PIX_FMT_RGB565, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_RGB565, 8, true)));
889 // V4L2_PIX_FMT_RGB555X , // v4l2_fourcc('R', 'G', 'B', 'Q') /* 16 RGB-5-5-5 BE */
890 // V4L2_PIX_FMT_RGB565X , // v4l2_fourcc('R', 'G', 'B', 'R') /* 16 RGB-5-6-5 BE */
891 // V4L2_PIX_FMT_BGR666 , // v4l2_fourcc('B', 'G', 'R', 'H') /* 18 BGR-6-6-6 */
892 // V4L2_PIX_FMT_BGR24 , // v4l2_fourcc('B', 'G', 'R', '3') /* 24 BGR-8-8-8 */
893 // V4L2_PIX_FMT_RGB24 , // v4l2_fourcc('R', 'G', 'B', '3') /* 24 RGB-8-8-8 */
894 supported_formats.insert(
895 std::make_pair(V4L2_PIX_FMT_RGB24, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_RGB24, 8, true)));
896 // V4L2_PIX_FMT_BGR32 , // v4l2_fourcc('B', 'G', 'R', '4') /* 32 BGR-8-8-8-8 */
897 // V4L2_PIX_FMT_RGB32 , // v4l2_fourcc('R', 'G', 'B', '4') /* 32 RGB-8-8-8-8 */
898
899 /* Grey formats */
900 //V4L2_PIX_FMT_GREY , // v4l2_fourcc('G', 'R', 'E', 'Y') /* 8 Greyscale */
901 supported_formats.insert(
902 std::make_pair(V4L2_PIX_FMT_GREY, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_GREY, 8, true)));
903 // V4L2_PIX_FMT_Y4 , // v4l2_fourcc('Y', '0', '4', ' ') /* 4 Greyscale */
904 // V4L2_PIX_FMT_Y6 , // v4l2_fourcc('Y', '0', '6', ' ') /* 6 Greyscale */
905 // V4L2_PIX_FMT_Y10 , // v4l2_fourcc('Y', '1', '0', ' ') /* 10 Greyscale */
906 // V4L2_PIX_FMT_Y12 , // v4l2_fourcc('Y', '1', '2', ' ') /* 12 Greyscale */
907 // V4L2_PIX_FMT_Y16 , // v4l2_fourcc('Y', '1', '6', ' ') /* 16 Greyscale */
908 supported_formats.insert(
909 std::make_pair(V4L2_PIX_FMT_Y16, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_Y16, 16, true)));
910
911 /* Grey bit-packed formats */
912 // V4L2_PIX_FMT_Y10BPACK , // v4l2_fourcc('Y', '1', '0', 'B') /* 10 Greyscale bit-packed */
913
914 /* Palette formats */
915 // V4L2_PIX_FMT_PAL8 , // v4l2_fourcc('P', 'A', 'L', '8') /* 8 8-bit palette */
916
917 /* Chrominance formats */
918 // V4L2_PIX_FMT_UV8 , // v4l2_fourcc('U', 'V', '8', ' ') /* 8 UV 4:4 */
919
920 /* Luminance+Chrominance formats */
921 // V4L2_PIX_FMT_YVU410 , // v4l2_fourcc('Y', 'V', 'U', '9') /* 9 YVU 4:1:0 */
922 // V4L2_PIX_FMT_YVU420 , // v4l2_fourcc('Y', 'V', '1', '2') /* 12 YVU 4:2:0 */
923 supported_formats.insert(
924 std::make_pair(V4L2_PIX_FMT_YVU420, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_YVU420, 8, true)));
925 // V4L2_PIX_FMT_YUYV , // v4l2_fourcc('Y', 'U', 'Y', 'V') /* 16 YUV 4:2:2 */
926 supported_formats.insert(
927 std::make_pair(V4L2_PIX_FMT_YUYV, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_YUYV, 8, true)));
928 // V4L2_PIX_FMT_YYUV , // v4l2_fourcc('Y', 'Y', 'U', 'V') /* 16 YUV 4:2:2 */
929 // V4L2_PIX_FMT_YVYU , // v4l2_fourcc('Y', 'V', 'Y', 'U') /* 16 YVU 4:2:2 */
930 supported_formats.insert(
931 std::make_pair(V4L2_PIX_FMT_YVYU, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_YVYU, 8, true)));
932 // V4L2_PIX_FMT_UYVY , // v4l2_fourcc('U', 'Y', 'V', 'Y') /* 16 YUV 4:2:2 */
933 supported_formats.insert(
934 std::make_pair(V4L2_PIX_FMT_UYVY, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_UYVY, 8, true)));
935 // V4L2_PIX_FMT_VYUY , // v4l2_fourcc('V', 'Y', 'U', 'Y') /* 16 YUV 4:2:2 */
936 supported_formats.insert(
937 std::make_pair(V4L2_PIX_FMT_VYUY, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_VYUY, 8, true)));
938 // V4L2_PIX_FMT_YUV422P , // v4l2_fourcc('4', '2', '2', 'P') /* 16 YVU422 planar */
939 // V4L2_PIX_FMT_YUV411P , // v4l2_fourcc('4', '1', '1', 'P') /* 16 YVU411 planar */
940 // V4L2_PIX_FMT_Y41P , // v4l2_fourcc('Y', '4', '1', 'P') /* 12 YUV 4:1:1 */
941 // V4L2_PIX_FMT_YUV444 , // v4l2_fourcc('Y', '4', '4', '4') /* 16 xxxxyyyy uuuuvvvv */
942 // V4L2_PIX_FMT_YUV555 , // v4l2_fourcc('Y', 'U', 'V', 'O') /* 16 YUV-5-5-5 */
943 // V4L2_PIX_FMT_YUV565 , // v4l2_fourcc('Y', 'U', 'V', 'P') /* 16 YUV-5-6-5 */
944 // V4L2_PIX_FMT_YUV32 , // v4l2_fourcc('Y', 'U', 'V', '4') /* 32 YUV-8-8-8-8 */
945 // V4L2_PIX_FMT_YUV410 , // v4l2_fourcc('Y', 'U', 'V', '9') /* 9 YUV 4:1:0 */
946 // V4L2_PIX_FMT_YUV420 , // v4l2_fourcc('Y', 'U', '1', '2') /* 12 YUV 4:2:0 */
947 supported_formats.insert(
948 std::make_pair(V4L2_PIX_FMT_YUV420, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_YUV420, 8, true)));
949 // V4L2_PIX_FMT_HI240 , // v4l2_fourcc('H', 'I', '2', '4') /* 8 8-bit color */
950 // V4L2_PIX_FMT_HM12 , // v4l2_fourcc('H', 'M', '1', '2') /* 8 YUV 4:2:0 16x16 macroblocks */
951 // V4L2_PIX_FMT_M420 , // v4l2_fourcc('M', '4', '2', '0') /* 12 YUV 4:2:0 2 lines y, 1 line uv interleaved */
952
953 /* two planes -- one Y, one Cr + Cb interleaved */
954 // V4L2_PIX_FMT_NV12 , // v4l2_fourcc('N', 'V', '1', '2') /* 12 Y/CbCr 4:2:0 */
955 supported_formats.insert(
956 std::make_pair(V4L2_PIX_FMT_NV12, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_NV12, 8, true)));
957 // V4L2_PIX_FMT_NV21 , // v4l2_fourcc('N', 'V', '2', '1') /* 12 Y/CrCb 4:2:0 */
958 supported_formats.insert(
959 std::make_pair(V4L2_PIX_FMT_NV21, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_NV21, 8, true)));
960 // V4L2_PIX_FMT_NV16 , // v4l2_fourcc('N', 'V', '1', '6') /* 16 Y/CbCr 4:2:2 */
961 // V4L2_PIX_FMT_NV61 , // v4l2_fourcc('N', 'V', '6', '1') /* 16 Y/CrCb 4:2:2 */
962 // V4L2_PIX_FMT_NV24 , // v4l2_fourcc('N', 'V', '2', '4') /* 24 Y/CbCr 4:4:4 */
963 // V4L2_PIX_FMT_NV42 , // v4l2_fourcc('N', 'V', '4', '2') /* 24 Y/CrCb 4:4:4 */
964
965 /* two non contiguous planes - one Y, one Cr + Cb interleaved */
966 // V4L2_PIX_FMT_NV12M , // v4l2_fourcc('N', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 */
967 // V4L2_PIX_FMT_NV21M , // v4l2_fourcc('N', 'M', '2', '1') /* 21 Y/CrCb 4:2:0 */
968 // V4L2_PIX_FMT_NV16M , // v4l2_fourcc('N', 'M', '1', '6') /* 16 Y/CbCr 4:2:2 */
969 // V4L2_PIX_FMT_NV61M , // v4l2_fourcc('N', 'M', '6', '1') /* 16 Y/CrCb 4:2:2 */
970 // V4L2_PIX_FMT_NV12MT , // v4l2_fourcc('T', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 64x32 macroblocks */
971 // V4L2_PIX_FMT_NV12MT_16X16 , // v4l2_fourcc('V', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 16x16 macroblocks */
972
973 /* three non contiguous planes - Y, Cb, Cr */
974 // V4L2_PIX_FMT_YUV420M , // v4l2_fourcc('Y', 'M', '1', '2') /* 12 YUV420 planar */
975 // V4L2_PIX_FMT_YVU420M , // v4l2_fourcc('Y', 'M', '2', '1') /* 12 YVU420 planar */
976
977 /* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */
978 // V4L2_PIX_FMT_SBGGR8 , // v4l2_fourcc('B', 'A', '8', '1') /* 8 BGBG.. GRGR.. */
979 supported_formats.insert(
980 std::make_pair(V4L2_PIX_FMT_SBGGR8, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_SBGGR8, 8, false)));
981 // V4L2_PIX_FMT_SGBRG8 , // v4l2_fourcc('G', 'B', 'R', 'G') /* 8 GBGB.. RGRG.. */
982 // V4L2_PIX_FMT_SGRBG8 , // v4l2_fourcc('G', 'R', 'B', 'G') /* 8 GRGR.. BGBG.. */
983 supported_formats.insert(
984 std::make_pair(V4L2_PIX_FMT_SGRBG8, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_SGRBG8, 8, false)));
985 // V4L2_PIX_FMT_SRGGB8 , // v4l2_fourcc('R', 'G', 'G', 'B') /* 8 RGRG.. GBGB.. */
986 supported_formats.insert(
987 std::make_pair(V4L2_PIX_FMT_SRGGB8, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_SRGGB8, 8, false)));
988 // V4L2_PIX_FMT_SBGGR10 , // v4l2_fourcc('B', 'G', '1', '0') /* 10 BGBG.. GRGR.. */
989 // V4L2_PIX_FMT_SGBRG10 , // v4l2_fourcc('G', 'B', '1', '0') /* 10 GBGB.. RGRG.. */
990 // V4L2_PIX_FMT_SGRBG10 , // v4l2_fourcc('B', 'A', '1', '0') /* 10 GRGR.. BGBG.. */
991 // V4L2_PIX_FMT_SRGGB10 , // v4l2_fourcc('R', 'G', '1', '0') /* 10 RGRG.. GBGB.. */
992 // V4L2_PIX_FMT_SBGGR12 , // v4l2_fourcc('B', 'G', '1', '2') /* 12 BGBG.. GRGR.. */
993 // V4L2_PIX_FMT_SGBRG12 , // v4l2_fourcc('G', 'B', '1', '2') /* 12 GBGB.. RGRG.. */
994 // V4L2_PIX_FMT_SGRBG12 , // v4l2_fourcc('B', 'A', '1', '2') /* 12 GRGR.. BGBG.. */
995 // V4L2_PIX_FMT_SRGGB12 , // v4l2_fourcc('R', 'G', '1', '2') /* 12 RGRG.. GBGB.. */
996 /* 10bit raw bayer a-law compressed to 8 bits */
997 // V4L2_PIX_FMT_SBGGR10ALAW8 , // v4l2_fourcc('a', 'B', 'A', '8')
998 // V4L2_PIX_FMT_SGBRG10ALAW8 , // v4l2_fourcc('a', 'G', 'A', '8')
999 // V4L2_PIX_FMT_SGRBG10ALAW8 , // v4l2_fourcc('a', 'g', 'A', '8')
1000 // V4L2_PIX_FMT_SRGGB10ALAW8 , // v4l2_fourcc('a', 'R', 'A', '8')
1001 /* 10bit raw bayer DPCM compressed to 8 bits */
1002 // V4L2_PIX_FMT_SBGGR10DPCM8 , // v4l2_fourcc('b', 'B', 'A', '8')
1003 // V4L2_PIX_FMT_SGBRG10DPCM8 , // v4l2_fourcc('b', 'G', 'A', '8')
1004 // V4L2_PIX_FMT_SGRBG10DPCM8 , // v4l2_fourcc('B', 'D', '1', '0')
1005 // V4L2_PIX_FMT_SRGGB10DPCM8 , // v4l2_fourcc('b', 'R', 'A', '8')
1006 /*
1007 * 10bit raw bayer, expanded to 16 bits
1008 * xxxxrrrrrrrrrrxxxxgggggggggg xxxxggggggggggxxxxbbbbbbbbbb...
1009 */
1010 // V4L2_PIX_FMT_SBGGR16 , // v4l2_fourcc('B', 'Y', 'R', '2') /* 16 BGBG.. GRGR.. */
1011 supported_formats.insert(
1012 std::make_pair(V4L2_PIX_FMT_SBGGR16, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_SBGGR16, 16, false)));
1013
1014 /* compressed formats */
1015 // V4L2_PIX_FMT_MJPEG , // v4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG */
1016 supported_formats.insert(
1017 std::make_pair(V4L2_PIX_FMT_MJPEG, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_MJPEG, 8, false)));
1018 // V4L2_PIX_FMT_JPEG , // v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG */
1019 supported_formats.insert(
1020 std::make_pair(V4L2_PIX_FMT_JPEG, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_JPEG, 8, false)));
1021 // V4L2_PIX_FMT_DV , // v4l2_fourcc('d', 'v', 's', 'd') /* 1394 */
1022 // V4L2_PIX_FMT_MPEG , // v4l2_fourcc('M', 'P', 'E', 'G') /* MPEG-1/2/4 Multiplexed */
1023 // V4L2_PIX_FMT_H264 , // v4l2_fourcc('H', '2', '6', '4') /* H264 with start codes */
1024 // V4L2_PIX_FMT_H264_NO_SC , // v4l2_fourcc('A', 'V', 'C', '1') /* H264 without start codes */
1025 // V4L2_PIX_FMT_H264_MVC , // v4l2_fourcc('M', '2', '6', '4') /* H264 MVC */
1026 // V4L2_PIX_FMT_H263 , // v4l2_fourcc('H', '2', '6', '3') /* H263 */
1027 // V4L2_PIX_FMT_MPEG1 , // v4l2_fourcc('M', 'P', 'G', '1') /* MPEG-1 ES */
1028 // V4L2_PIX_FMT_MPEG2 , // v4l2_fourcc('M', 'P', 'G', '2') /* MPEG-2 ES */
1029 // V4L2_PIX_FMT_MPEG4 , // v4l2_fourcc('M', 'P', 'G', '4') /* MPEG-4 part 2 ES */
1030 // V4L2_PIX_FMT_XVID , // v4l2_fourcc('X', 'V', 'I', 'D') /* Xvid */
1031 // V4L2_PIX_FMT_VC1_ANNEX_G , // v4l2_fourcc('V', 'C', '1', 'G') /* SMPTE 421M Annex G compliant stream */
1032 // V4L2_PIX_FMT_VC1_ANNEX_L , // v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */
1033 // V4L2_PIX_FMT_VP8 , // v4l2_fourcc('V', 'P', '8', '0') /* VP8 */
1034
1035 /* Vendor-specific formats */
1036 // V4L2_PIX_FMT_CPIA1 , // v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */
1037 // V4L2_PIX_FMT_WNVA , // v4l2_fourcc('W', 'N', 'V', 'A') /* Winnov hw compress */
1038 // V4L2_PIX_FMT_SN9C10X , // v4l2_fourcc('S', '9', '1', '0') /* SN9C10x compression */
1039 // V4L2_PIX_FMT_SN9C20X_I420 , // v4l2_fourcc('S', '9', '2', '0') /* SN9C20x YUV 4:2:0 */
1040 // V4L2_PIX_FMT_PWC1 , // v4l2_fourcc('P', 'W', 'C', '1') /* pwc older webcam */
1041 // V4L2_PIX_FMT_PWC2 , // v4l2_fourcc('P', 'W', 'C', '2') /* pwc newer webcam */
1042 // V4L2_PIX_FMT_ET61X251 , // v4l2_fourcc('E', '6', '2', '5') /* ET61X251 compression */
1043 // V4L2_PIX_FMT_SPCA501 , // v4l2_fourcc('S', '5', '0', '1') /* YUYV per line */
1044 // V4L2_PIX_FMT_SPCA505 , // v4l2_fourcc('S', '5', '0', '5') /* YYUV per line */
1045 // V4L2_PIX_FMT_SPCA508 , // v4l2_fourcc('S', '5', '0', '8') /* YUVY per line */
1046 // V4L2_PIX_FMT_SPCA561 , // v4l2_fourcc('S', '5', '6', '1') /* compressed GBRG bayer */
1047 // V4L2_PIX_FMT_PAC207 , // v4l2_fourcc('P', '2', '0', '7') /* compressed BGGR bayer */
1048 // V4L2_PIX_FMT_MR97310A , // v4l2_fourcc('M', '3', '1', '0') /* compressed BGGR bayer */
1049 // V4L2_PIX_FMT_JL2005BCD , // v4l2_fourcc('J', 'L', '2', '0') /* compressed RGGB bayer */
1050 // V4L2_PIX_FMT_SN9C2028 , // v4l2_fourcc('S', 'O', 'N', 'X') /* compressed GBRG bayer */
1051 // V4L2_PIX_FMT_SQ905C , // v4l2_fourcc('9', '0', '5', 'C') /* compressed RGGB bayer */
1052 // V4L2_PIX_FMT_PJPG , // v4l2_fourcc('P', 'J', 'P', 'G') /* Pixart 73xx JPEG */
1053 // V4L2_PIX_FMT_OV511 , // v4l2_fourcc('O', '5', '1', '1') /* ov511 JPEG */
1054 // V4L2_PIX_FMT_OV518 , // v4l2_fourcc('O', '5', '1', '8') /* ov518 JPEG */
1055 // V4L2_PIX_FMT_STV0680 , // v4l2_fourcc('S', '6', '8', '0') /* stv0680 bayer */
1056 // V4L2_PIX_FMT_TM6000 , // v4l2_fourcc('T', 'M', '6', '0') /* tm5600/tm60x0 */
1057 // V4L2_PIX_FMT_CIT_YYVYUY , // v4l2_fourcc('C', 'I', 'T', 'V') /* one line of Y then 1 line of VYUY */
1058 // V4L2_PIX_FMT_KONICA420 , // v4l2_fourcc('K', 'O', 'N', 'I') /* YUV420 planar in blocks of 256 pixels */
1059 // V4L2_PIX_FMT_JPGL , // v4l2_fourcc('J', 'P', 'G', 'L') /* JPEG-Lite */
1060 // V4L2_PIX_FMT_SE401 , // v4l2_fourcc('S', '4', '0', '1') /* se401 janggu compressed rgb */
1061 // V4L2_PIX_FMT_S5C_UYVY_JPG // v4l2_fourcc('S', '5', 'C', 'I') /* S5C73M3 interleaved UYVY/JPEG */
1062
1063 for (std::map<unsigned int, struct format *>::iterator it = supported_formats.begin();
1064 it != supported_formats.end(); ++it)
1065 vsuppformats.push_back(it->first);
1066}
void bayer_grbg_to_rgb24(unsigned char *dst, unsigned char *srcc, long int WIDTH, long int HEIGHT)
Definition ccvt_misc.c:545
void ccvt_420p_rgb24(int width, int height, const void *src, void *dst)
Definition ccvt_c2.c:128
void bayer16_2_rgb24(unsigned short *dst, unsigned short *src, long int WIDTH, long int HEIGHT)
Definition ccvt_misc.c:357
void ccvt_yuyv_bgr32(int width, int height, const void *src, void *dst)
Definition ccvt_misc.c:81
void bayer2rgb24(unsigned char *dst, unsigned char *src, long int WIDTH, long int HEIGHT)
Definition ccvt_misc.c:263
int mjpegtoyuv420p(unsigned char *map, unsigned char *cap_map, int width, int height, unsigned int size)
mjpegtoyuv420p MPEG to YUV 420 P
Definition ccvt_misc.c:723
void bayer_rggb_2rgb24(unsigned char *dst, unsigned char *srcc, long int WIDTH, long int HEIGHT)
Definition ccvt_misc.c:451
void ccvt_yuyv_rgb24(int width, int height, const void *src, void *dst)
Definition ccvt_misc.c:173
void ccvt_420p_bgr32(int width, int height, const void *src, void *dst)
Definition ccvt_c2.c:113
void ccvt_rgb24_bgr32(int width, int height, const void *const src, void *const dst)
void ccvt_yuyv_420p(int width, int height, const void *src, void *dsty, void *dstu, void *dstv)
Definition ccvt_misc.c:219
int RGB2YUV(int x_dim, int y_dim, void *bmp, void *y_out, void *u_out, void *v_out, int flip)
Definition ccvt_misc.c:787
virtual void usesoftcrop(bool c)
virtual void decode(unsigned char *frame, struct v4l2_buffer *buf, bool native)
virtual const std::vector< unsigned int > & getsupportedformats()
virtual void setQuantization(bool)
virtual bool setcrop(struct v4l2_crop c)
virtual unsigned char * getU()
virtual unsigned char * getRGBBuffer()
virtual unsigned char * getY()
virtual unsigned char * getMJPEGBuffer(int &size)
virtual void setformat(struct v4l2_format f, bool use_ext_pix_format)
virtual bool issupportedformat(unsigned int format)
virtual void setLinearization(bool)
virtual unsigned char * getV()
std::map< unsigned int, struct format * > supported_formats
std::vector< unsigned int > vsuppformats
const char * name
Definition v4l2_decode.h:64
void IDLog(const char *fmt,...)
Definition indicom.c:305
void initColorSpace()
void rangeY8(unsigned char *buf, unsigned int len)
unsigned int getQuantization(struct v4l2_format *fmt)
void linearize(float *buf, unsigned int len, struct v4l2_format *fmt)
#define QUANTIZATION_LIM_RANGE