patch_v4l2.diff

Ingo Flaschberger, 2010-03-13 02:47 am

Download (7 kB)

 
src/highgui/cvcap_v4l.cpp 2010-03-13 02:16:20.000000000 +0100
269 269
#define V4L2_PIX_FMT_SGBRG v4l2_fourcc('G','B','R','G') /* bayer GBRG   GBGB.. RGRG.. */
270 270
#endif
271 271

  
272
#endif  /* HAVE_CAMV4L2 */
272
#define PALETTE_BGR24 1
273
#define PALETTE_YVU420 2
274
#define PALETTE_YUV411P 3
275
#define PALETTE_YUYV 4
276
#define PALETTE_UYVY 5
277
#define PALETTE_SBGGR8 6
278
#define PALETTE_SN9C10X 7
279
#define PALETTE_MJPEG 8
280
#define PALETTE_SGBRG 9
273 281

  
274
int  PALETTE_BGR24 = 0,
275
     PALETTE_YVU420 = 0,
276
     PALETTE_YUV411P = 0,
277
     PALETTE_YUYV = 0,
278
     PALETTE_UYVY= 0,
279
     PALETTE_SBGGR8 = 0,
280
     PALETTE_SN9C10X = 0,
281
     PALETTE_MJPEG = 0,
282
     PALETTE_SGBRG = 0;
282
#endif  /* HAVE_CAMV4L2 */
283 283

  
284 284
typedef struct CvCaptureCAM_V4L
285 285
{
......
317 317
   int v4l2_gain, v4l2_gain_min, v4l2_gain_max;
318 318
   int v4l2_exposure, v4l2_exposure_min, v4l2_exposure_max;
319 319

  
320
   int v4l2_palette;
321

  
320 322
#endif /* HAVE_CAMV4L2 */
321 323

  
322 324
}
......
529 531
{
530 532
  if (try_palette_v4l2(capture, V4L2_PIX_FMT_BGR24) == 0)
531 533
  {
532
    PALETTE_BGR24 = 1;
534
	capture->v4l2_palette = PALETTE_BGR24;
533 535
  }
534 536
  else
535 537
  if (try_palette_v4l2(capture, V4L2_PIX_FMT_YVU420) == 0)
536 538
  {
537
    PALETTE_YVU420 = 1;
539
	capture->v4l2_palette = PALETTE_YVU420;
538 540
  }
539 541
  else
540 542
  if (try_palette_v4l2(capture, V4L2_PIX_FMT_YUV411P) == 0)
541 543
  {
542
    PALETTE_YUV411P = 1;
544
	capture->v4l2_palette = PALETTE_YUV411P;
543 545
  }
544 546
  else
545 547

  
......
551 553
  if (try_palette_v4l2(capture, V4L2_PIX_FMT_MJPEG) == 0 ||
552 554
      try_palette_v4l2(capture, V4L2_PIX_FMT_JPEG) == 0)
553 555
  {
554
    PALETTE_MJPEG = 1;
556
	capture->v4l2_palette = PALETTE_MJPEG;
555 557
  }
556 558
  else
557 559
#endif
......
559 561

  
560 562
  if (try_palette_v4l2(capture, V4L2_PIX_FMT_YUYV) == 0)
561 563
  {
562
    PALETTE_YUYV = 1;
564
	capture->v4l2_palette = PALETTE_YUYV;
563 565
  }
564 566
  else if (try_palette_v4l2(capture, V4L2_PIX_FMT_UYVY) == 0)
565 567
  {
566
    PALETTE_UYVY = 1;
568
	capture->v4l2_palette = PALETTE_UYVY;
567 569
  }
568 570
  else
569 571
  if (try_palette_v4l2(capture, V4L2_PIX_FMT_SN9C10X) == 0)
570 572
  {
571
    PALETTE_SN9C10X = 1;
573
	capture->v4l2_palette = PALETTE_SN9C10X;
572 574
  } else
573 575
  if (try_palette_v4l2(capture, V4L2_PIX_FMT_SBGGR8) == 0)
574 576
  {
575
    PALETTE_SBGGR8 = 1;
577
	capture->v4l2_palette = PALETTE_SBGGR8;
576 578
  } else
577 579
  if (try_palette_v4l2(capture, V4L2_PIX_FMT_SGBRG) == 0)
578 580
  {
579
    PALETTE_SGBRG = 1;
581
	capture->v4l2_palette = PALETTE_SGBRG;
580 582
  }
581 583
      else
582 584
  {
......
2122 2124
  if (V4L2_SUPPORT == 1)
2123 2125
  {
2124 2126

  
2125
    if (PALETTE_BGR24 == 1)
2126
      memcpy((char *)capture->frame.imageData,
2127
             (char *)capture->buffers[capture->bufferIndex].start,
2128
             capture->frame.imageSize);
2129

  
2130
    if (PALETTE_YVU420 == 1)
2131
      yuv420p_to_rgb24(capture->form.fmt.pix.width,
2132
                       capture->form.fmt.pix.height,
2133
                       (unsigned char*)(capture->buffers[capture->bufferIndex].start),
2134
                       (unsigned char*)capture->frame.imageData);
2135

  
2136
    if (PALETTE_YUV411P == 1)
2137
      yuv411p_to_rgb24(capture->form.fmt.pix.width,
2138
                       capture->form.fmt.pix.height,
2139
                       (unsigned char*)(capture->buffers[capture->bufferIndex].start),
2140
                       (unsigned char*)capture->frame.imageData);
2127
    switch( capture->v4l2_palette) {
2128
      case PALETTE_BGR24:
2129
        memcpy((char *)capture->frame.imageData,
2130
               (char *)capture->buffers[capture->bufferIndex].start,
2131
               capture->frame.imageSize);
2132
        break;
2133
      case PALETTE_YVU420:
2134
        yuv420p_to_rgb24(capture->form.fmt.pix.width,
2135
                         capture->form.fmt.pix.height,
2136
                         (unsigned char*)(capture->buffers[capture->bufferIndex].start),
2137
                         (unsigned char*)capture->frame.imageData);
2138
        break;
2139
      case PALETTE_YUV411P:
2140
        yuv411p_to_rgb24(capture->form.fmt.pix.width,
2141
                         capture->form.fmt.pix.height,
2142
                         (unsigned char*)(capture->buffers[capture->bufferIndex].start),
2143
                         (unsigned char*)capture->frame.imageData);
2144
        break;
2141 2145

  
2142 2146
#ifdef HAVE_JPEG
2143 2147
#ifdef __USE_GNU
2144 2148
    /* support for MJPEG is only available with libjpeg and gcc,
2145 2149
       because it's use libjepg and fmemopen()
2146 2150
    */
2147
    if (PALETTE_MJPEG == 1)
2148
      if (!mjpeg_to_rgb24(capture->form.fmt.pix.width,
2149
			  capture->form.fmt.pix.height,
2150
			  (unsigned char*)(capture->buffers[capture->bufferIndex]
2151
					   .start),
2152
			  capture->buffers[capture->bufferIndex].length,
2153
			  (unsigned char*)capture->frame.imageData))
2154
	return 0;
2151
      case PALETTE_MJPEG:
2152
        if (!mjpeg_to_rgb24(capture->form.fmt.pix.width,
2153
	  		  capture->form.fmt.pix.height,
2154
	  		  (unsigned char*)(capture->buffers[capture->bufferIndex]
2155
	  				   .start),
2156
	  		  capture->buffers[capture->bufferIndex].length,
2157
	  		  (unsigned char*)capture->frame.imageData))
2158
	  return 0;
2159
        break;
2155 2160
#endif
2156 2161
#endif
2157 2162

  
2158
    if (PALETTE_YUYV == 1)
2163
      case PALETTE_YUYV:
2159 2164
	yuyv_to_rgb24(capture->form.fmt.pix.width,
2160 2165
		      capture->form.fmt.pix.height,
2161 2166
		      (unsigned char*)(capture->buffers[capture->bufferIndex].start),
2162 2167
		      (unsigned char*)capture->frame.imageData);
2168
        break;
2163 2169

  
2164
    if (PALETTE_UYVY == 1)
2170
      case PALETTE_UYVY:
2165 2171
	uyvy_to_rgb24(capture->form.fmt.pix.width,
2166 2172
		      capture->form.fmt.pix.height,
2167 2173
		      (unsigned char*)(capture->buffers[capture->bufferIndex].start),
2168 2174
		      (unsigned char*)capture->frame.imageData);
2175
        break;
2169 2176

  
2170
    if (PALETTE_SBGGR8 == 1)
2171
    {
2172
      bayer2rgb24(capture->form.fmt.pix.width,
2177
      case PALETTE_SBGGR8:
2178
        bayer2rgb24(capture->form.fmt.pix.width,
2173 2179
                  capture->form.fmt.pix.height,
2174 2180
                  (unsigned char*)capture->buffers[capture->bufferIndex].start,
2175 2181
                  (unsigned char*)capture->frame.imageData);
2176
    }
2182
        break;
2177 2183

  
2178
    if (PALETTE_SN9C10X == 1)
2179
    {
2180
      sonix_decompress_init();
2184
      case PALETTE_SN9C10X:
2185
        sonix_decompress_init();
2181 2186

  
2182
      sonix_decompress(capture->form.fmt.pix.width,
2187
        sonix_decompress(capture->form.fmt.pix.width,
2183 2188
                       capture->form.fmt.pix.height,
2184 2189
                       (unsigned char*)capture->buffers[capture->bufferIndex].start,
2185 2190
                       (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start);
2186 2191

  
2187
      bayer2rgb24(capture->form.fmt.pix.width,
2192
        bayer2rgb24(capture->form.fmt.pix.width,
2188 2193
                  capture->form.fmt.pix.height,
2189 2194
                  (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start,
2190 2195
                  (unsigned char*)capture->frame.imageData);
2191
    }
2196
        break;
2192 2197

  
2193
    if (PALETTE_SGBRG == 1)
2194
    {
2195
       sgbrg2rgb24(capture->form.fmt.pix.width,
2198
      case PALETTE_SGBRG:
2199
        sgbrg2rgb24(capture->form.fmt.pix.width,
2196 2200
                  capture->form.fmt.pix.height,
2197 2201
                  (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start,
2198 2202
                  (unsigned char*)capture->frame.imageData);
2203
        break;
2199 2204
    }
2200

  
2201 2205
  } else
2202 2206
#endif /* HAVE_CAMV4L2 */
2203 2207
  {