Instrument Neutral Distributed Interface INDI  2.0.2
v4l2_builtin_decoder.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2005 by Jasem Mutlaq <mutlaqja@ikarustech.com>
3  Copyright (C) 2014 by geehalel <geehalel@gmail.com>
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 reding 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 adpated 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 
60 #include "v4l2_builtin_decoder.h"
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 
119 {
121 };
122 
123 void 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
163  {
164  memcpy(yuyvBuffer, frame, 2 * bufwidth * bufheight);
165  }
166  break;
167 
168  case V4L2_PIX_FMT_YUV420:
169  case V4L2_PIX_FMT_YVU420:
170  if (useSoftCrop && doCrop)
171  {
172  unsigned char *src = frame + crop.c.left + (crop.c.top * fmt.fmt.pix.width);
173  unsigned char *dest = YBuf;
174 
175  //IDLog("grabImage: src=%d dest=%d\n", src, dest);
176  for (unsigned int i = 0; i < (unsigned int)crop.c.height; i++)
177  {
178  memcpy(dest, src, crop.c.width);
179  src += fmt.fmt.pix.width;
180  dest += crop.c.width;
181  }
182 
183  dest = UBuf;
184  src = frame + (fmt.fmt.pix.width * fmt.fmt.pix.height) +
185  ((crop.c.left + (crop.c.top * fmt.fmt.pix.width) / 2) / 2);
186  if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YVU420)
187  {
188  dest = VBuf;
189  }
190  for (unsigned int i = 0; i < (unsigned int)crop.c.height / 2; i++)
191  {
192  memcpy(dest, src, crop.c.width / 2);
193  src += fmt.fmt.pix.width / 2;
194  dest += crop.c.width / 2;
195  }
196 
197  dest = VBuf;
198  src = frame + (fmt.fmt.pix.width * fmt.fmt.pix.height) +
199  ((fmt.fmt.pix.width * fmt.fmt.pix.height) / 4) +
200  ((crop.c.left + (crop.c.top * fmt.fmt.pix.width) / 2) / 2);
201  if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YVU420)
202  {
203  dest = UBuf;
204  }
205  for (unsigned int i = 0; i < (unsigned int)crop.c.height / 2; i++)
206  {
207  memcpy(dest, src, crop.c.width / 2);
208  src += fmt.fmt.pix.width / 2;
209  dest += crop.c.width / 2;
210  }
211  }
212  else
213  {
214  memcpy(YBuf, frame, bufwidth * bufheight);
215  if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YUV420)
216  {
217  memcpy(UBuf, frame + bufwidth * bufheight, (bufwidth / 2) * (bufheight / 2));
218  memcpy(VBuf, frame + bufwidth * bufheight + (bufwidth / 2) * (bufheight / 2),
219  (bufwidth / 2) * (bufheight / 2));
220  }
221  else
222  {
223  if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YVU420)
224  {
225  memcpy(VBuf, frame + bufwidth * bufheight, (bufwidth / 2) * (bufheight / 2));
226  memcpy(UBuf, frame + bufwidth * bufheight + (bufwidth / 2) * (bufheight / 2),
227  (bufwidth / 2) * (bufheight / 2));
228  }
229  }
230  }
231  break;
232 
233  case V4L2_PIX_FMT_NV12:
234  case V4L2_PIX_FMT_NV21:
235  if (useSoftCrop && doCrop)
236  {
237  unsigned char *src = frame + crop.c.left + (crop.c.top * fmt.fmt.pix.bytesperline);
238  unsigned char *dest = YBuf, *destv = nullptr;
239 
240  //IDLog("grabImage: src=%d dest=%d\n", src, dest);
241  for (unsigned int i = 0; i < (unsigned int)crop.c.height; i++)
242  {
243  memcpy(dest, src, crop.c.width);
244  src += fmt.fmt.pix.bytesperline;
245  dest += crop.c.width;
246  }
247 
248  dest = UBuf;
249  destv = VBuf;
250  src = frame + (fmt.fmt.pix.bytesperline * fmt.fmt.pix.height) +
251  ((crop.c.left + (crop.c.top * fmt.fmt.pix.bytesperline) / 2) / 2);
252  if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_NV21)
253  {
254  dest = VBuf;
255  destv = UBuf;
256  }
257  for (unsigned int i = 0; i < (unsigned int)crop.c.height / 2; i++)
258  {
259  unsigned char *s = src;
260  for (unsigned int j = 0; j < (unsigned int)crop.c.width; j += 2)
261  {
262  *(dest++) = *(s++);
263  *(destv++) = *(s++);
264  }
265  src += fmt.fmt.pix.bytesperline;
266  }
267  }
268  else
269  {
270  unsigned char *src = frame;
271  unsigned char *dest = YBuf;
272  unsigned char *destv = VBuf;
273  unsigned char *s = nullptr;
274 
275  for (unsigned int i = 0; i < bufheight; i++)
276  {
277  memcpy(dest, src, bufwidth);
278  src += fmt.fmt.pix.bytesperline;
279  dest += bufwidth;
280  }
281  dest = UBuf;
282  src = frame + (fmt.fmt.pix.bytesperline * bufheight);
283  if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_NV21)
284  {
285  dest = VBuf;
286  destv = UBuf;
287  }
288  for (unsigned int i = 0; i < bufheight / 2; i++)
289  {
290  s = src;
291  //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);
292  for (unsigned int j = 0; j < bufwidth; j += 2)
293  {
294  *(dest++) = *(s++);
295  *(destv++) = *(s++);
296  }
297  src += fmt.fmt.pix.bytesperline;
298  }
299  }
300  break;
301 
302  case V4L2_PIX_FMT_YUYV:
303  if (useSoftCrop && doCrop)
304  {
305  unsigned char *src = frame + 2 * (crop.c.left) + (crop.c.top * fmt.fmt.pix.bytesperline);
306  unsigned char *dest = yuyvBuffer;
307 
308  for (unsigned int i = 0; i < (unsigned int)crop.c.height; i++)
309  {
310  memcpy(dest, src, 2 * crop.c.width);
311  src += fmt.fmt.pix.bytesperline;
312  dest += 2 * crop.c.width;
313  }
314  }
315  else
316  {
317  memcpy(yuyvBuffer, frame, 2 * bufwidth * bufheight);
318  }
319  break;
320 
321  case V4L2_PIX_FMT_UYVY:
322  case V4L2_PIX_FMT_VYUY:
323  case V4L2_PIX_FMT_YVYU:
324  {
325  unsigned char *src = nullptr;
326  unsigned char *dest = yuyvBuffer;
327  unsigned char *s = nullptr, *s1 = nullptr, *s2 = nullptr, *s3 = nullptr, *s4 = nullptr;
328 
329  if (useSoftCrop && doCrop)
330  {
331  src = frame + 2 * (crop.c.left) + (crop.c.top * fmt.fmt.pix.bytesperline);
332  //IDLog("Decoding UYVY with cropping %dx%d frame at %lx\n", width, height, src);
333  }
334  else
335  {
336  src = frame;
337  //IDLog("Decoding UYVY %dx%d frame at %lx\n", width, height, src);
338  }
339  for (int i = 0; i < (int)bufheight; i++)
340  {
341  s = src;
342  switch (fmt.fmt.pix.pixelformat)
343  {
344  case V4L2_PIX_FMT_UYVY:
345  s1 = (s + 1);
346  s2 = (s);
347  s3 = (s + 3);
348  s4 = (s + 2);
349  break;
350  case V4L2_PIX_FMT_VYUY:
351  s1 = (s + 1);
352  s2 = (s + 2);
353  s3 = (s + 3);
354  s4 = (s);
355  break;
356  case V4L2_PIX_FMT_YVYU:
357  s1 = (s);
358  s2 = (s + 3);
359  s3 = (s + 2);
360  s4 = (s + 1);
361  break;
362  }
363  for (int j = 0; j < (int)(bufwidth / 2); j++)
364  {
365  *(dest++) = *(s1);
366  *(dest++) = *(s2);
367  *(dest++) = *(s3);
368  *(dest++) = *(s4);
369  s1 += 4;
370  s2 += 4;
371  s3 += 4;
372  s4 += 4;
373  }
374  src += fmt.fmt.pix.bytesperline;
375  }
376  }
377  break;
378 
379  case V4L2_PIX_FMT_RGB24:
380  {
381  unsigned char *src = nullptr, *dest = rgb24_buffer;
382 
383  if (useSoftCrop && doCrop)
384  {
385  src = frame + (3 * (crop.c.left)) + (crop.c.top * fmt.fmt.pix.bytesperline);
386  }
387  else
388  {
389  src = frame;
390  }
391  for (unsigned int i = 0; i < bufheight; i++)
392  {
393  memcpy(dest, src, 3 * bufwidth);
394  src += fmt.fmt.pix.bytesperline;
395  dest += 3 * bufwidth;
396  }
397  //memcpy(rgb24_buffer, frame, fmt.fmt.pix.width * fmt.fmt.pix.height * 3);
398  }
399  break;
400 
401  case V4L2_PIX_FMT_RGB555:
402  {
403  unsigned char *src, *dest = rgb24_buffer;
404 
405  if (useSoftCrop && doCrop)
406  {
407  src = frame + (2 * (crop.c.left)) + (crop.c.top * fmt.fmt.pix.bytesperline);
408  }
409  else
410  {
411  src = frame;
412  }
413  for (unsigned int i = 0; i < bufheight; i++)
414  {
415  unsigned char *s = src;
416  for (unsigned int j = 0; j < bufwidth; j++)
417  {
418  *(dest++) = lut5[((*(s + 1) & 0x7C) >> 2)]; // R
419  *(dest++) = lut5[(((*(s + 1) & 0x03) << 3) | ((*(s) & 0xE0) >> 5))]; // G
420  *(dest++) = lut5[((*s) & 0x1F)]; // B
421  s += 2;
422  }
423  src += fmt.fmt.pix.bytesperline;
424  }
425  }
426  break;
427 
428  case V4L2_PIX_FMT_RGB565:
429  {
430  unsigned char *src = nullptr, *dest = rgb24_buffer;
431 
432  if (useSoftCrop && doCrop)
433  {
434  src = frame + (2 * (crop.c.left)) + (crop.c.top * fmt.fmt.pix.bytesperline);
435  }
436  else
437  {
438  src = frame;
439  }
440  for (unsigned int i = 0; i < bufheight; i++)
441  {
442  unsigned char *s = src;
443  for (unsigned int j = 0; j < bufwidth; j++)
444  {
445  *(dest++) = lut5[((*(s + 1) & 0xF8) >> 3)]; // R
446  *(dest++) = lut6[(((*(s + 1) & 0x07) << 3) | ((*(s) & 0xE0) >> 5))]; // G
447  *(dest++) = lut5[((*s) & 0x1F)]; // B
448  s += 2;
449  }
450  src += fmt.fmt.pix.bytesperline;
451  }
452  }
453  break;
454 
455  case V4L2_PIX_FMT_SBGGR8:
456  bayer2rgb24(rgb24_buffer, frame, fmt.fmt.pix.width, fmt.fmt.pix.height);
457  break;
458 
459  case V4L2_PIX_FMT_SRGGB8:
460  bayer_rggb_2rgb24(rgb24_buffer, frame, fmt.fmt.pix.width, fmt.fmt.pix.height);
461  break;
462  case V4L2_PIX_FMT_SGRBG8:
463  bayer_grbg_to_rgb24(rgb24_buffer, frame, fmt.fmt.pix.width, fmt.fmt.pix.height);
464  break;
465  case V4L2_PIX_FMT_SBGGR16:
466  bayer16_2_rgb24((unsigned short *)rgb24_buffer, (unsigned short *)frame, fmt.fmt.pix.width,
467  fmt.fmt.pix.height);
468  break;
469 
470  case V4L2_PIX_FMT_JPEG:
471  case V4L2_PIX_FMT_MJPEG:
472  if (native)
473  memcpy(yuvBuffer, frame, buf->bytesused);
474  else
475  mjpegtoyuv420p(yuvBuffer, frame, fmt.fmt.pix.width, fmt.fmt.pix.height, buf->bytesused);
476  m_Size = buf->bytesused;
477  break;
478  default:
479  {
480  unsigned char *src = YBuf;
481 
482  for (unsigned int i = 0; i < bufheight * bufwidth; i++)
483  {
484  *(src++) = random() % 255;
485  }
486  }
487  }
488 }
489 
490 bool V4L2_Builtin_Decoder::setcrop(struct v4l2_crop c)
491 {
492  crop = c;
493  IDLog("Decoder set crop: %dx%d at (%d, %d)\n", crop.c.width, crop.c.height, crop.c.left, crop.c.top);
494  if (supported_formats.count(fmt.fmt.pix.pixelformat) > 0 && supported_formats[fmt.fmt.pix.pixelformat]->softcrop)
495  {
496  doCrop = true;
497  allocBuffers();
498  return true;
499  }
500  else
501  {
502  doCrop = false;
503  return false;
504  }
505 }
506 
508 {
509  IDLog("Decoder reset crop\n");
510  doCrop = false;
511  allocBuffers();
512 }
513 
515 {
516  IDLog("Decoder usesoftcrop %s\n", (c ? "true" : "false"));
517  useSoftCrop = c;
518 }
519 
520 void V4L2_Builtin_Decoder::setformat(struct v4l2_format f, bool use_ext_pix_format)
521 {
522  (void)use_ext_pix_format;
523  fmt = f;
524  if (supported_formats.count(fmt.fmt.pix.pixelformat) == 1)
525  bpp = supported_formats.at(fmt.fmt.pix.pixelformat)->bpp;
526  else
527  bpp = 8;
528  IDLog("Decoder set format: %c%c%c%c size %dx%d bpp %d\n", (fmt.fmt.pix.pixelformat) & 0xFF,
529  (fmt.fmt.pix.pixelformat >> 8) & 0xFF, (fmt.fmt.pix.pixelformat >> 16) & 0xFF,
530  (fmt.fmt.pix.pixelformat >> 24) & 0xFF, f.fmt.pix.width, f.fmt.pix.height, bpp);
531  /* kernel 3.19
532  if (use_ext_pix_format && fmt.fmt.pix.priv == V4L2_PIX_FMT_PRIV_MAGIC)
533  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);
534  else
535  */
536  IDLog("Decoder: Colorspace is %d, using default ycbcr encoding and quantization\n", fmt.fmt.pix.colorspace);
537  doCrop = false;
538  allocBuffers();
539 }
540 
542 {
543  return fmt.fmt.pix.pixelformat;
544 }
545 
546 void V4L2_Builtin_Decoder::setQuantization(bool doquantization)
547 {
548  doQuantization = doquantization;
549 }
550 void V4L2_Builtin_Decoder::setLinearization(bool dolinearization)
551 {
552  doLinearization = dolinearization;
553  if (doLinearization)
554  bpp = 16;
555  else if (supported_formats.count(fmt.fmt.pix.pixelformat) == 1)
556  bpp = supported_formats.at(fmt.fmt.pix.pixelformat)->bpp;
557  else
558  bpp = 8;
559 }
561 {
562  YBuf = nullptr;
563  UBuf = nullptr;
564  VBuf = nullptr;
565  if (yuvBuffer)
566  delete[](yuvBuffer);
567  yuvBuffer = nullptr;
568  if (yuyvBuffer)
569  delete[](yuyvBuffer);
570  yuyvBuffer = nullptr;
571  if (colorBuffer)
572  delete[](colorBuffer);
573  colorBuffer = nullptr;
574  if (rgb24_buffer)
575  delete[](rgb24_buffer);
576  rgb24_buffer = nullptr;
577  if (linearBuffer)
578  delete[](linearBuffer);
579  linearBuffer = nullptr;
580  //if (cropbuf) free(cropbuf); cropbuf=nullptr;
581 
582  if (doCrop)
583  {
584  bufwidth = crop.c.width;
585  bufheight = crop.c.height;
586  }
587  else
588  {
589  bufwidth = fmt.fmt.pix.width;
590  bufheight = fmt.fmt.pix.height;
591  }
592 
593  switch (fmt.fmt.pix.pixelformat)
594  {
595  case V4L2_PIX_FMT_GREY:
596  case V4L2_PIX_FMT_JPEG:
597  case V4L2_PIX_FMT_MJPEG:
598  case V4L2_PIX_FMT_YUV420:
599  case V4L2_PIX_FMT_YVU420:
600  case V4L2_PIX_FMT_NV12:
601  case V4L2_PIX_FMT_NV21:
602  yuvBuffer = new unsigned char[(bufwidth * bufheight) + ((bufwidth * bufheight) / 2)];
603  YBuf = yuvBuffer;
605  VBuf = UBuf + ((bufwidth * bufheight) / 4);
606  // bzero(Ubuf, ((bufwidth * bufheight) / 2));
607  break;
608  case V4L2_PIX_FMT_Y16:
609  case V4L2_PIX_FMT_YUYV:
610  case V4L2_PIX_FMT_UYVY:
611  case V4L2_PIX_FMT_VYUY:
612  case V4L2_PIX_FMT_YVYU:
613  yuyvBuffer = new unsigned char[(bufwidth * bufheight) * 2];
614  break;
615  case V4L2_PIX_FMT_RGB24:
616  case V4L2_PIX_FMT_RGB555:
617  case V4L2_PIX_FMT_RGB565:
618  case V4L2_PIX_FMT_SBGGR8:
619  case V4L2_PIX_FMT_SRGGB8:
620  case V4L2_PIX_FMT_SGRBG8:
621  case V4L2_PIX_FMT_SBGGR16:
622  rgb24_buffer = new unsigned char[(bufwidth * bufheight) * (bpp / 8) * 3];
623  break;
624  default:
625  yuvBuffer = new unsigned char[(bufwidth * bufheight) + ((bufwidth * bufheight) / 2)];
626  YBuf = yuvBuffer;
628  VBuf = UBuf + ((bufwidth * bufheight) / 4);
629  break;
630  }
631  IDLog("Decoder allocBuffers cropping %s\n", (doCrop ? "true" : "false"));
632 }
633 
635 {
636  unsigned char *src = YBuf;
637  float *dest;
638  unsigned int i;
639  if (!linearBuffer)
640  {
641  linearBuffer = new float[(bufwidth * bufheight)];
642  }
643  dest = linearBuffer;
644  for (i = 0; i < bufwidth * bufheight; i++)
645  *dest++ = (*src++) / 255.0;
647 }
649 {
650  if (!yuvBuffer)
651  {
652  yuvBuffer = new unsigned char[(bufwidth * bufheight) + ((bufwidth * bufheight) / 2)];
653  YBuf = yuvBuffer;
655  VBuf = UBuf + ((bufwidth * bufheight) / 4);
656  }
657  switch (fmt.fmt.pix.pixelformat)
658  {
659  case V4L2_PIX_FMT_RGB24:
660  case V4L2_PIX_FMT_RGB555:
661  case V4L2_PIX_FMT_RGB565:
662  case V4L2_PIX_FMT_SBGGR8:
663  case V4L2_PIX_FMT_SRGGB8:
664  case V4L2_PIX_FMT_SGRBG8:
666  break;
667  case V4L2_PIX_FMT_YUYV:
668  case V4L2_PIX_FMT_UYVY:
669  case V4L2_PIX_FMT_VYUY:
670  case V4L2_PIX_FMT_YVYU:
671  // todo handcopy only Ybuf using an int, byfwidth should be even
673  break;
674  }
675 }
676 
678 {
679  if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_Y16)
680  return yuyvBuffer;
681  makeY();
684  if (doLinearization)
685  {
686  unsigned int i;
687  float *src;
688  unsigned short *dest;
689  if (!yuyvBuffer)
690  yuyvBuffer = new unsigned char[(bufwidth * bufheight) * 2];
691  makeLinearY();
692  src = linearBuffer;
693  dest = (unsigned short *)yuyvBuffer;
694  for (i = 0; i < bufwidth * bufheight; i++)
695  *dest++ = (unsigned short)(*src++ * 65535.0);
696  return yuyvBuffer;
697  }
698  return YBuf;
699 }
700 
702 {
703  makeY();
706  makeLinearY();
707  return linearBuffer;
708 }
709 
711 {
712  return UBuf;
713 }
714 
716 {
717  return VBuf;
718 }
719 
720 /* used for streaming/exposure */
721 #if 0
722 unsigned char * V4L2_Builtin_Decoder::geColorBuffer()
723 {
724  //cerr << "in get color buffer " << endl;
725  //IDLog("Decoder geRGBBuffer %s\n", (doCrop?"true":"false"));
726  if (!colorBuffer) colorBuffer = new unsigned char[(bufwidth * bufheight) * (bpp / 8) * 4];
727  switch (fmt.fmt.pix.pixelformat)
728  {
729  case V4L2_PIX_FMT_GREY:
730  case V4L2_PIX_FMT_JPEG:
731  case V4L2_PIX_FMT_MJPEG:
732  case V4L2_PIX_FMT_YUV420:
733  case V4L2_PIX_FMT_YVU420:
734  case V4L2_PIX_FMT_NV12:
735  case V4L2_PIX_FMT_NV21:
737  break;
738 
739  case V4L2_PIX_FMT_YUYV:
740  case V4L2_PIX_FMT_UYVY:
741  case V4L2_PIX_FMT_VYUY:
742  case V4L2_PIX_FMT_YVYU:
744  break;
745  case V4L2_PIX_FMT_RGB24:
746  case V4L2_PIX_FMT_RGB555:
747  case V4L2_PIX_FMT_RGB565:
748  case V4L2_PIX_FMT_SBGGR8:
749  case V4L2_PIX_FMT_SRGGB8:
751  break;
752  case V4L2_PIX_FMT_Y16:
753  /* OOOps this is planar ARGB */
754  /*
755  bzero(colorBuffer, bufwidth * bufheight * 2);
756  memcpy(colorBuffer + (bufwidth * bufheight * 2), yuyvBuffer, bufwidth * bufheight * 2);
757  memcpy(colorBuffer + 2 * (bufwidth * bufheight * 2), yuyvBuffer, bufwidth * bufheight * 2);
758  memcpy(colorBuffer + 3 * (bufwidth * bufheight * 2), yuyvBuffer, bufwidth * bufheight * 2);
759  */
760  {
761  /* this is bgra , use unsigned short here... */
762  unsigned int i;
763  unsigned char * src = yuyvBuffer;
764  unsigned char * dest = colorBuffer;
765  for (i = 0; i < bufwidth * bufheight; i += 1)
766  {
767  *dest++ = *src;
768  *dest++ = *(src + 1);
769  *dest++ = *src;
770  *dest++ = *(src + 1);
771  *dest++ = *src;
772  *dest++ = *(src + 1);
773  *dest++ = 0;
774  *dest++ = 0;
775  src += 2;
776  }
777  }
778  break;
779  case V4L2_PIX_FMT_SBGGR16:
780  {
781  /* this is bgra , now I use unsigned short! */
782  unsigned int i;
783  unsigned short * src = (unsigned short *)rgb24_buffer;
784  unsigned short * dest = (unsigned short *)colorBuffer;
785  for (i = 0; i < bufwidth * bufheight; i += 1)
786  {
787  *dest++ = *(src + 2);
788  *dest++ = *(src + 1);
789  *dest++ = *(src);
790  *dest++ = 0;
791  src += 3;
792  }
793  }
794  default:
796  break;
797  }
798  return colorBuffer;
799 }
800 #endif
801 
802 unsigned char *V4L2_Builtin_Decoder::getMJPEGBuffer(int &size)
803 {
804  if (fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG)
805  {
806  size = m_Size;
807  return yuvBuffer;
808  }
809  else
810  return nullptr;
811 }
812 
813 /* used for SER recorder */
815 {
816  //cerr << "in get color buffer " << endl;
817  //IDLog("Decoder geRGBBuffer %s\n", (doCrop?"true":"false"));
818  if (!rgb24_buffer)
819  rgb24_buffer = new unsigned char[(bufwidth * bufheight) * 3];
820  switch (fmt.fmt.pix.pixelformat)
821  {
822  case V4L2_PIX_FMT_GREY:
823  case V4L2_PIX_FMT_JPEG:
824  case V4L2_PIX_FMT_MJPEG:
825  case V4L2_PIX_FMT_YUV420:
826  case V4L2_PIX_FMT_YVU420:
827  case V4L2_PIX_FMT_NV12:
828  case V4L2_PIX_FMT_NV21:
830  break;
831  case V4L2_PIX_FMT_YUYV:
832  case V4L2_PIX_FMT_UYVY:
833  case V4L2_PIX_FMT_VYUY:
834  case V4L2_PIX_FMT_YVYU:
835  //if (!colorBuffer) colorBuffer = new unsigned char[(bufwidth * bufheight) * 4];
836  //ccvt_yuyv_bgr32(bufwidth, bufheight, yuyvBuffer, rgb24_buffer);
837  //ccvt_bgr32_rgb24(bufwidth, bufheight, colorBuffer, (void*)rgb24_buffer);
839  break;
840  case V4L2_PIX_FMT_RGB24:
841  case V4L2_PIX_FMT_RGB555:
842  case V4L2_PIX_FMT_RGB565:
843  case V4L2_PIX_FMT_SBGGR8:
844  case V4L2_PIX_FMT_SRGGB8:
845  case V4L2_PIX_FMT_SGRBG8:
846  case V4L2_PIX_FMT_SBGGR16:
847  break;
848  default:
850  break;
851  }
852  return rgb24_buffer;
853 }
854 
856 {
857  return (int)(bpp);
858 }
859 
861 {
862  //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');
863  return (supported_formats.count(format) > 0);
864 }
865 
866 const std::vector<unsigned int> &V4L2_Builtin_Decoder::getsupportedformats()
867 {
868  return vsuppformats;
869 }
870 
872 {
873  /* RGB formats */
874  // V4L2_PIX_FMT_RGB332 , // v4l2_fourcc('R', 'G', 'B', '1') /* 8 RGB-3-3-2 */
875  // V4L2_PIX_FMT_RGB444 , // v4l2_fourcc('R', '4', '4', '4') /* 16 xxxxrrrr ggggbbbb */
876  // V4L2_PIX_FMT_RGB555 , // v4l2_fourcc('R', 'G', 'B', 'O') /* 16 RGB-5-5-5 */
877  supported_formats.insert(
878  std::make_pair(V4L2_PIX_FMT_RGB555, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_RGB555, 8, true)));
879  // V4L2_PIX_FMT_RGB565 , // v4l2_fourcc('R', 'G', 'B', 'P') /* 16 RGB-5-6-5 */
880  supported_formats.insert(
881  std::make_pair(V4L2_PIX_FMT_RGB565, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_RGB565, 8, true)));
882  // V4L2_PIX_FMT_RGB555X , // v4l2_fourcc('R', 'G', 'B', 'Q') /* 16 RGB-5-5-5 BE */
883  // V4L2_PIX_FMT_RGB565X , // v4l2_fourcc('R', 'G', 'B', 'R') /* 16 RGB-5-6-5 BE */
884  // V4L2_PIX_FMT_BGR666 , // v4l2_fourcc('B', 'G', 'R', 'H') /* 18 BGR-6-6-6 */
885  // V4L2_PIX_FMT_BGR24 , // v4l2_fourcc('B', 'G', 'R', '3') /* 24 BGR-8-8-8 */
886  // V4L2_PIX_FMT_RGB24 , // v4l2_fourcc('R', 'G', 'B', '3') /* 24 RGB-8-8-8 */
887  supported_formats.insert(
888  std::make_pair(V4L2_PIX_FMT_RGB24, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_RGB24, 8, true)));
889  // V4L2_PIX_FMT_BGR32 , // v4l2_fourcc('B', 'G', 'R', '4') /* 32 BGR-8-8-8-8 */
890  // V4L2_PIX_FMT_RGB32 , // v4l2_fourcc('R', 'G', 'B', '4') /* 32 RGB-8-8-8-8 */
891 
892  /* Grey formats */
893  //V4L2_PIX_FMT_GREY , // v4l2_fourcc('G', 'R', 'E', 'Y') /* 8 Greyscale */
894  supported_formats.insert(
895  std::make_pair(V4L2_PIX_FMT_GREY, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_GREY, 8, true)));
896  // V4L2_PIX_FMT_Y4 , // v4l2_fourcc('Y', '0', '4', ' ') /* 4 Greyscale */
897  // V4L2_PIX_FMT_Y6 , // v4l2_fourcc('Y', '0', '6', ' ') /* 6 Greyscale */
898  // V4L2_PIX_FMT_Y10 , // v4l2_fourcc('Y', '1', '0', ' ') /* 10 Greyscale */
899  // V4L2_PIX_FMT_Y12 , // v4l2_fourcc('Y', '1', '2', ' ') /* 12 Greyscale */
900  // V4L2_PIX_FMT_Y16 , // v4l2_fourcc('Y', '1', '6', ' ') /* 16 Greyscale */
901  supported_formats.insert(
902  std::make_pair(V4L2_PIX_FMT_Y16, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_Y16, 16, true)));
903 
904  /* Grey bit-packed formats */
905  // V4L2_PIX_FMT_Y10BPACK , // v4l2_fourcc('Y', '1', '0', 'B') /* 10 Greyscale bit-packed */
906 
907  /* Palette formats */
908  // V4L2_PIX_FMT_PAL8 , // v4l2_fourcc('P', 'A', 'L', '8') /* 8 8-bit palette */
909 
910  /* Chrominance formats */
911  // V4L2_PIX_FMT_UV8 , // v4l2_fourcc('U', 'V', '8', ' ') /* 8 UV 4:4 */
912 
913  /* Luminance+Chrominance formats */
914  // V4L2_PIX_FMT_YVU410 , // v4l2_fourcc('Y', 'V', 'U', '9') /* 9 YVU 4:1:0 */
915  // V4L2_PIX_FMT_YVU420 , // v4l2_fourcc('Y', 'V', '1', '2') /* 12 YVU 4:2:0 */
916  supported_formats.insert(
917  std::make_pair(V4L2_PIX_FMT_YVU420, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_YVU420, 8, true)));
918  // V4L2_PIX_FMT_YUYV , // v4l2_fourcc('Y', 'U', 'Y', 'V') /* 16 YUV 4:2:2 */
919  supported_formats.insert(
920  std::make_pair(V4L2_PIX_FMT_YUYV, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_YUYV, 8, true)));
921  // V4L2_PIX_FMT_YYUV , // v4l2_fourcc('Y', 'Y', 'U', 'V') /* 16 YUV 4:2:2 */
922  // V4L2_PIX_FMT_YVYU , // v4l2_fourcc('Y', 'V', 'Y', 'U') /* 16 YVU 4:2:2 */
923  supported_formats.insert(
924  std::make_pair(V4L2_PIX_FMT_YVYU, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_YVYU, 8, true)));
925  // V4L2_PIX_FMT_UYVY , // v4l2_fourcc('U', 'Y', 'V', 'Y') /* 16 YUV 4:2:2 */
926  supported_formats.insert(
927  std::make_pair(V4L2_PIX_FMT_UYVY, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_UYVY, 8, true)));
928  // V4L2_PIX_FMT_VYUY , // v4l2_fourcc('V', 'Y', 'U', 'Y') /* 16 YUV 4:2:2 */
929  supported_formats.insert(
930  std::make_pair(V4L2_PIX_FMT_VYUY, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_VYUY, 8, true)));
931  // V4L2_PIX_FMT_YUV422P , // v4l2_fourcc('4', '2', '2', 'P') /* 16 YVU422 planar */
932  // V4L2_PIX_FMT_YUV411P , // v4l2_fourcc('4', '1', '1', 'P') /* 16 YVU411 planar */
933  // V4L2_PIX_FMT_Y41P , // v4l2_fourcc('Y', '4', '1', 'P') /* 12 YUV 4:1:1 */
934  // V4L2_PIX_FMT_YUV444 , // v4l2_fourcc('Y', '4', '4', '4') /* 16 xxxxyyyy uuuuvvvv */
935  // V4L2_PIX_FMT_YUV555 , // v4l2_fourcc('Y', 'U', 'V', 'O') /* 16 YUV-5-5-5 */
936  // V4L2_PIX_FMT_YUV565 , // v4l2_fourcc('Y', 'U', 'V', 'P') /* 16 YUV-5-6-5 */
937  // V4L2_PIX_FMT_YUV32 , // v4l2_fourcc('Y', 'U', 'V', '4') /* 32 YUV-8-8-8-8 */
938  // V4L2_PIX_FMT_YUV410 , // v4l2_fourcc('Y', 'U', 'V', '9') /* 9 YUV 4:1:0 */
939  // V4L2_PIX_FMT_YUV420 , // v4l2_fourcc('Y', 'U', '1', '2') /* 12 YUV 4:2:0 */
940  supported_formats.insert(
941  std::make_pair(V4L2_PIX_FMT_YUV420, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_YUV420, 8, true)));
942  // V4L2_PIX_FMT_HI240 , // v4l2_fourcc('H', 'I', '2', '4') /* 8 8-bit color */
943  // V4L2_PIX_FMT_HM12 , // v4l2_fourcc('H', 'M', '1', '2') /* 8 YUV 4:2:0 16x16 macroblocks */
944  // V4L2_PIX_FMT_M420 , // v4l2_fourcc('M', '4', '2', '0') /* 12 YUV 4:2:0 2 lines y, 1 line uv interleaved */
945 
946  /* two planes -- one Y, one Cr + Cb interleaved */
947  // V4L2_PIX_FMT_NV12 , // v4l2_fourcc('N', 'V', '1', '2') /* 12 Y/CbCr 4:2:0 */
948  supported_formats.insert(
949  std::make_pair(V4L2_PIX_FMT_NV12, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_NV12, 8, true)));
950  // V4L2_PIX_FMT_NV21 , // v4l2_fourcc('N', 'V', '2', '1') /* 12 Y/CrCb 4:2:0 */
951  supported_formats.insert(
952  std::make_pair(V4L2_PIX_FMT_NV21, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_NV21, 8, true)));
953  // V4L2_PIX_FMT_NV16 , // v4l2_fourcc('N', 'V', '1', '6') /* 16 Y/CbCr 4:2:2 */
954  // V4L2_PIX_FMT_NV61 , // v4l2_fourcc('N', 'V', '6', '1') /* 16 Y/CrCb 4:2:2 */
955  // V4L2_PIX_FMT_NV24 , // v4l2_fourcc('N', 'V', '2', '4') /* 24 Y/CbCr 4:4:4 */
956  // V4L2_PIX_FMT_NV42 , // v4l2_fourcc('N', 'V', '4', '2') /* 24 Y/CrCb 4:4:4 */
957 
958  /* two non contiguous planes - one Y, one Cr + Cb interleaved */
959  // V4L2_PIX_FMT_NV12M , // v4l2_fourcc('N', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 */
960  // V4L2_PIX_FMT_NV21M , // v4l2_fourcc('N', 'M', '2', '1') /* 21 Y/CrCb 4:2:0 */
961  // V4L2_PIX_FMT_NV16M , // v4l2_fourcc('N', 'M', '1', '6') /* 16 Y/CbCr 4:2:2 */
962  // V4L2_PIX_FMT_NV61M , // v4l2_fourcc('N', 'M', '6', '1') /* 16 Y/CrCb 4:2:2 */
963  // V4L2_PIX_FMT_NV12MT , // v4l2_fourcc('T', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 64x32 macroblocks */
964  // V4L2_PIX_FMT_NV12MT_16X16 , // v4l2_fourcc('V', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 16x16 macroblocks */
965 
966  /* three non contiguous planes - Y, Cb, Cr */
967  // V4L2_PIX_FMT_YUV420M , // v4l2_fourcc('Y', 'M', '1', '2') /* 12 YUV420 planar */
968  // V4L2_PIX_FMT_YVU420M , // v4l2_fourcc('Y', 'M', '2', '1') /* 12 YVU420 planar */
969 
970  /* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */
971  // V4L2_PIX_FMT_SBGGR8 , // v4l2_fourcc('B', 'A', '8', '1') /* 8 BGBG.. GRGR.. */
972  supported_formats.insert(
973  std::make_pair(V4L2_PIX_FMT_SBGGR8, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_SBGGR8, 8, false)));
974  // V4L2_PIX_FMT_SGBRG8 , // v4l2_fourcc('G', 'B', 'R', 'G') /* 8 GBGB.. RGRG.. */
975  // V4L2_PIX_FMT_SGRBG8 , // v4l2_fourcc('G', 'R', 'B', 'G') /* 8 GRGR.. BGBG.. */
976  supported_formats.insert(
977  std::make_pair(V4L2_PIX_FMT_SGRBG8, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_SGRBG8, 8, false)));
978  // V4L2_PIX_FMT_SRGGB8 , // v4l2_fourcc('R', 'G', 'G', 'B') /* 8 RGRG.. GBGB.. */
979  supported_formats.insert(
980  std::make_pair(V4L2_PIX_FMT_SRGGB8, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_SRGGB8, 8, false)));
981  // V4L2_PIX_FMT_SBGGR10 , // v4l2_fourcc('B', 'G', '1', '0') /* 10 BGBG.. GRGR.. */
982  // V4L2_PIX_FMT_SGBRG10 , // v4l2_fourcc('G', 'B', '1', '0') /* 10 GBGB.. RGRG.. */
983  // V4L2_PIX_FMT_SGRBG10 , // v4l2_fourcc('B', 'A', '1', '0') /* 10 GRGR.. BGBG.. */
984  // V4L2_PIX_FMT_SRGGB10 , // v4l2_fourcc('R', 'G', '1', '0') /* 10 RGRG.. GBGB.. */
985  // V4L2_PIX_FMT_SBGGR12 , // v4l2_fourcc('B', 'G', '1', '2') /* 12 BGBG.. GRGR.. */
986  // V4L2_PIX_FMT_SGBRG12 , // v4l2_fourcc('G', 'B', '1', '2') /* 12 GBGB.. RGRG.. */
987  // V4L2_PIX_FMT_SGRBG12 , // v4l2_fourcc('B', 'A', '1', '2') /* 12 GRGR.. BGBG.. */
988  // V4L2_PIX_FMT_SRGGB12 , // v4l2_fourcc('R', 'G', '1', '2') /* 12 RGRG.. GBGB.. */
989  /* 10bit raw bayer a-law compressed to 8 bits */
990  // V4L2_PIX_FMT_SBGGR10ALAW8 , // v4l2_fourcc('a', 'B', 'A', '8')
991  // V4L2_PIX_FMT_SGBRG10ALAW8 , // v4l2_fourcc('a', 'G', 'A', '8')
992  // V4L2_PIX_FMT_SGRBG10ALAW8 , // v4l2_fourcc('a', 'g', 'A', '8')
993  // V4L2_PIX_FMT_SRGGB10ALAW8 , // v4l2_fourcc('a', 'R', 'A', '8')
994  /* 10bit raw bayer DPCM compressed to 8 bits */
995  // V4L2_PIX_FMT_SBGGR10DPCM8 , // v4l2_fourcc('b', 'B', 'A', '8')
996  // V4L2_PIX_FMT_SGBRG10DPCM8 , // v4l2_fourcc('b', 'G', 'A', '8')
997  // V4L2_PIX_FMT_SGRBG10DPCM8 , // v4l2_fourcc('B', 'D', '1', '0')
998  // V4L2_PIX_FMT_SRGGB10DPCM8 , // v4l2_fourcc('b', 'R', 'A', '8')
999  /*
1000  * 10bit raw bayer, expanded to 16 bits
1001  * xxxxrrrrrrrrrrxxxxgggggggggg xxxxggggggggggxxxxbbbbbbbbbb...
1002  */
1003  // V4L2_PIX_FMT_SBGGR16 , // v4l2_fourcc('B', 'Y', 'R', '2') /* 16 BGBG.. GRGR.. */
1004  supported_formats.insert(
1005  std::make_pair(V4L2_PIX_FMT_SBGGR16, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_SBGGR16, 16, false)));
1006 
1007  /* compressed formats */
1008  // V4L2_PIX_FMT_MJPEG , // v4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG */
1009  supported_formats.insert(
1010  std::make_pair(V4L2_PIX_FMT_MJPEG, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_MJPEG, 8, false)));
1011  // V4L2_PIX_FMT_JPEG , // v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG */
1012  supported_formats.insert(
1013  std::make_pair(V4L2_PIX_FMT_JPEG, new V4L2_Builtin_Decoder::format(V4L2_PIX_FMT_JPEG, 8, false)));
1014  // V4L2_PIX_FMT_DV , // v4l2_fourcc('d', 'v', 's', 'd') /* 1394 */
1015  // V4L2_PIX_FMT_MPEG , // v4l2_fourcc('M', 'P', 'E', 'G') /* MPEG-1/2/4 Multiplexed */
1016  // V4L2_PIX_FMT_H264 , // v4l2_fourcc('H', '2', '6', '4') /* H264 with start codes */
1017  // V4L2_PIX_FMT_H264_NO_SC , // v4l2_fourcc('A', 'V', 'C', '1') /* H264 without start codes */
1018  // V4L2_PIX_FMT_H264_MVC , // v4l2_fourcc('M', '2', '6', '4') /* H264 MVC */
1019  // V4L2_PIX_FMT_H263 , // v4l2_fourcc('H', '2', '6', '3') /* H263 */
1020  // V4L2_PIX_FMT_MPEG1 , // v4l2_fourcc('M', 'P', 'G', '1') /* MPEG-1 ES */
1021  // V4L2_PIX_FMT_MPEG2 , // v4l2_fourcc('M', 'P', 'G', '2') /* MPEG-2 ES */
1022  // V4L2_PIX_FMT_MPEG4 , // v4l2_fourcc('M', 'P', 'G', '4') /* MPEG-4 part 2 ES */
1023  // V4L2_PIX_FMT_XVID , // v4l2_fourcc('X', 'V', 'I', 'D') /* Xvid */
1024  // V4L2_PIX_FMT_VC1_ANNEX_G , // v4l2_fourcc('V', 'C', '1', 'G') /* SMPTE 421M Annex G compliant stream */
1025  // V4L2_PIX_FMT_VC1_ANNEX_L , // v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */
1026  // V4L2_PIX_FMT_VP8 , // v4l2_fourcc('V', 'P', '8', '0') /* VP8 */
1027 
1028  /* Vendor-specific formats */
1029  // V4L2_PIX_FMT_CPIA1 , // v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */
1030  // V4L2_PIX_FMT_WNVA , // v4l2_fourcc('W', 'N', 'V', 'A') /* Winnov hw compress */
1031  // V4L2_PIX_FMT_SN9C10X , // v4l2_fourcc('S', '9', '1', '0') /* SN9C10x compression */
1032  // V4L2_PIX_FMT_SN9C20X_I420 , // v4l2_fourcc('S', '9', '2', '0') /* SN9C20x YUV 4:2:0 */
1033  // V4L2_PIX_FMT_PWC1 , // v4l2_fourcc('P', 'W', 'C', '1') /* pwc older webcam */
1034  // V4L2_PIX_FMT_PWC2 , // v4l2_fourcc('P', 'W', 'C', '2') /* pwc newer webcam */
1035  // V4L2_PIX_FMT_ET61X251 , // v4l2_fourcc('E', '6', '2', '5') /* ET61X251 compression */
1036  // V4L2_PIX_FMT_SPCA501 , // v4l2_fourcc('S', '5', '0', '1') /* YUYV per line */
1037  // V4L2_PIX_FMT_SPCA505 , // v4l2_fourcc('S', '5', '0', '5') /* YYUV per line */
1038  // V4L2_PIX_FMT_SPCA508 , // v4l2_fourcc('S', '5', '0', '8') /* YUVY per line */
1039  // V4L2_PIX_FMT_SPCA561 , // v4l2_fourcc('S', '5', '6', '1') /* compressed GBRG bayer */
1040  // V4L2_PIX_FMT_PAC207 , // v4l2_fourcc('P', '2', '0', '7') /* compressed BGGR bayer */
1041  // V4L2_PIX_FMT_MR97310A , // v4l2_fourcc('M', '3', '1', '0') /* compressed BGGR bayer */
1042  // V4L2_PIX_FMT_JL2005BCD , // v4l2_fourcc('J', 'L', '2', '0') /* compressed RGGB bayer */
1043  // V4L2_PIX_FMT_SN9C2028 , // v4l2_fourcc('S', 'O', 'N', 'X') /* compressed GBRG bayer */
1044  // V4L2_PIX_FMT_SQ905C , // v4l2_fourcc('9', '0', '5', 'C') /* compressed RGGB bayer */
1045  // V4L2_PIX_FMT_PJPG , // v4l2_fourcc('P', 'J', 'P', 'G') /* Pixart 73xx JPEG */
1046  // V4L2_PIX_FMT_OV511 , // v4l2_fourcc('O', '5', '1', '1') /* ov511 JPEG */
1047  // V4L2_PIX_FMT_OV518 , // v4l2_fourcc('O', '5', '1', '8') /* ov518 JPEG */
1048  // V4L2_PIX_FMT_STV0680 , // v4l2_fourcc('S', '6', '8', '0') /* stv0680 bayer */
1049  // V4L2_PIX_FMT_TM6000 , // v4l2_fourcc('T', 'M', '6', '0') /* tm5600/tm60x0 */
1050  // V4L2_PIX_FMT_CIT_YYVYUY , // v4l2_fourcc('C', 'I', 'T', 'V') /* one line of Y then 1 line of VYUY */
1051  // V4L2_PIX_FMT_KONICA420 , // v4l2_fourcc('K', 'O', 'N', 'I') /* YUV420 planar in blocks of 256 pixels */
1052  // V4L2_PIX_FMT_JPGL , // v4l2_fourcc('J', 'P', 'G', 'L') /* JPEG-Lite */
1053  // V4L2_PIX_FMT_SE401 , // v4l2_fourcc('S', '4', '0', '1') /* se401 janggu compressed rgb */
1054  // V4L2_PIX_FMT_S5C_UYVY_JPG // v4l2_fourcc('S', '5', 'C', 'I') /* S5C73M3 interleaved UYVY/JPEG */
1055 
1056  for (std::map<unsigned int, struct format *>::iterator it = supported_formats.begin();
1057  it != supported_formats.end(); ++it)
1058  vsuppformats.push_back(it->first);
1059 }
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:721
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:785
virtual void usesoftcrop(bool c)
virtual void decode(unsigned char *frame, struct v4l2_buffer *buf, bool native)
unsigned char * yuyvBuffer
virtual const std::vector< unsigned int > & getsupportedformats()
virtual float * getLinearY()
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)
unsigned char * colorBuffer
virtual void setformat(struct v4l2_format f, bool use_ext_pix_format)
virtual bool issupportedformat(unsigned int format)
struct v4l2_format fmt
virtual void setLinearization(bool)
virtual unsigned char * getV()
std::map< unsigned int, struct format * > supported_formats
std::vector< unsigned int > vsuppformats
unsigned char * rgb24_buffer
const char * name
Definition: v4l2_decode.h:60
void IDLog(const char *fmt,...)
Definition: indicom.c:316
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