--- src/highgui/cvcap_v4l.cpp.org 2010-03-13 01:30:47.000000000 +0100 +++ src/highgui/cvcap_v4l.cpp 2010-03-13 02:16:20.000000000 +0100 @@ -269,17 +269,17 @@ #define V4L2_PIX_FMT_SGBRG v4l2_fourcc('G','B','R','G') /* bayer GBRG GBGB.. RGRG.. */ #endif -#endif /* HAVE_CAMV4L2 */ +#define PALETTE_BGR24 1 +#define PALETTE_YVU420 2 +#define PALETTE_YUV411P 3 +#define PALETTE_YUYV 4 +#define PALETTE_UYVY 5 +#define PALETTE_SBGGR8 6 +#define PALETTE_SN9C10X 7 +#define PALETTE_MJPEG 8 +#define PALETTE_SGBRG 9 -int PALETTE_BGR24 = 0, - PALETTE_YVU420 = 0, - PALETTE_YUV411P = 0, - PALETTE_YUYV = 0, - PALETTE_UYVY= 0, - PALETTE_SBGGR8 = 0, - PALETTE_SN9C10X = 0, - PALETTE_MJPEG = 0, - PALETTE_SGBRG = 0; +#endif /* HAVE_CAMV4L2 */ typedef struct CvCaptureCAM_V4L { @@ -317,6 +317,8 @@ int v4l2_gain, v4l2_gain_min, v4l2_gain_max; int v4l2_exposure, v4l2_exposure_min, v4l2_exposure_max; + int v4l2_palette; + #endif /* HAVE_CAMV4L2 */ } @@ -529,17 +531,17 @@ { if (try_palette_v4l2(capture, V4L2_PIX_FMT_BGR24) == 0) { - PALETTE_BGR24 = 1; + capture->v4l2_palette = PALETTE_BGR24; } else if (try_palette_v4l2(capture, V4L2_PIX_FMT_YVU420) == 0) { - PALETTE_YVU420 = 1; + capture->v4l2_palette = PALETTE_YVU420; } else if (try_palette_v4l2(capture, V4L2_PIX_FMT_YUV411P) == 0) { - PALETTE_YUV411P = 1; + capture->v4l2_palette = PALETTE_YUV411P; } else @@ -551,7 +553,7 @@ if (try_palette_v4l2(capture, V4L2_PIX_FMT_MJPEG) == 0 || try_palette_v4l2(capture, V4L2_PIX_FMT_JPEG) == 0) { - PALETTE_MJPEG = 1; + capture->v4l2_palette = PALETTE_MJPEG; } else #endif @@ -559,24 +561,24 @@ if (try_palette_v4l2(capture, V4L2_PIX_FMT_YUYV) == 0) { - PALETTE_YUYV = 1; + capture->v4l2_palette = PALETTE_YUYV; } else if (try_palette_v4l2(capture, V4L2_PIX_FMT_UYVY) == 0) { - PALETTE_UYVY = 1; + capture->v4l2_palette = PALETTE_UYVY; } else if (try_palette_v4l2(capture, V4L2_PIX_FMT_SN9C10X) == 0) { - PALETTE_SN9C10X = 1; + capture->v4l2_palette = PALETTE_SN9C10X; } else if (try_palette_v4l2(capture, V4L2_PIX_FMT_SBGGR8) == 0) { - PALETTE_SBGGR8 = 1; + capture->v4l2_palette = PALETTE_SBGGR8; } else if (try_palette_v4l2(capture, V4L2_PIX_FMT_SGBRG) == 0) { - PALETTE_SGBRG = 1; + capture->v4l2_palette = PALETTE_SGBRG; } else { @@ -2122,82 +2124,84 @@ if (V4L2_SUPPORT == 1) { - if (PALETTE_BGR24 == 1) - memcpy((char *)capture->frame.imageData, - (char *)capture->buffers[capture->bufferIndex].start, - capture->frame.imageSize); - - if (PALETTE_YVU420 == 1) - yuv420p_to_rgb24(capture->form.fmt.pix.width, - capture->form.fmt.pix.height, - (unsigned char*)(capture->buffers[capture->bufferIndex].start), - (unsigned char*)capture->frame.imageData); - - if (PALETTE_YUV411P == 1) - yuv411p_to_rgb24(capture->form.fmt.pix.width, - capture->form.fmt.pix.height, - (unsigned char*)(capture->buffers[capture->bufferIndex].start), - (unsigned char*)capture->frame.imageData); + switch( capture->v4l2_palette) { + case PALETTE_BGR24: + memcpy((char *)capture->frame.imageData, + (char *)capture->buffers[capture->bufferIndex].start, + capture->frame.imageSize); + break; + case PALETTE_YVU420: + yuv420p_to_rgb24(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)(capture->buffers[capture->bufferIndex].start), + (unsigned char*)capture->frame.imageData); + break; + case PALETTE_YUV411P: + yuv411p_to_rgb24(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)(capture->buffers[capture->bufferIndex].start), + (unsigned char*)capture->frame.imageData); + break; #ifdef HAVE_JPEG #ifdef __USE_GNU /* support for MJPEG is only available with libjpeg and gcc, because it's use libjepg and fmemopen() */ - if (PALETTE_MJPEG == 1) - if (!mjpeg_to_rgb24(capture->form.fmt.pix.width, - capture->form.fmt.pix.height, - (unsigned char*)(capture->buffers[capture->bufferIndex] - .start), - capture->buffers[capture->bufferIndex].length, - (unsigned char*)capture->frame.imageData)) - return 0; + case PALETTE_MJPEG: + if (!mjpeg_to_rgb24(capture->form.fmt.pix.width, + capture->form.fmt.pix.height, + (unsigned char*)(capture->buffers[capture->bufferIndex] + .start), + capture->buffers[capture->bufferIndex].length, + (unsigned char*)capture->frame.imageData)) + return 0; + break; #endif #endif - if (PALETTE_YUYV == 1) + case PALETTE_YUYV: yuyv_to_rgb24(capture->form.fmt.pix.width, capture->form.fmt.pix.height, (unsigned char*)(capture->buffers[capture->bufferIndex].start), (unsigned char*)capture->frame.imageData); + break; - if (PALETTE_UYVY == 1) + case PALETTE_UYVY: uyvy_to_rgb24(capture->form.fmt.pix.width, capture->form.fmt.pix.height, (unsigned char*)(capture->buffers[capture->bufferIndex].start), (unsigned char*)capture->frame.imageData); + break; - if (PALETTE_SBGGR8 == 1) - { - bayer2rgb24(capture->form.fmt.pix.width, + case PALETTE_SBGGR8: + bayer2rgb24(capture->form.fmt.pix.width, capture->form.fmt.pix.height, (unsigned char*)capture->buffers[capture->bufferIndex].start, (unsigned char*)capture->frame.imageData); - } + break; - if (PALETTE_SN9C10X == 1) - { - sonix_decompress_init(); + case PALETTE_SN9C10X: + sonix_decompress_init(); - sonix_decompress(capture->form.fmt.pix.width, + sonix_decompress(capture->form.fmt.pix.width, capture->form.fmt.pix.height, (unsigned char*)capture->buffers[capture->bufferIndex].start, (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start); - bayer2rgb24(capture->form.fmt.pix.width, + bayer2rgb24(capture->form.fmt.pix.width, capture->form.fmt.pix.height, (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start, (unsigned char*)capture->frame.imageData); - } + break; - if (PALETTE_SGBRG == 1) - { - sgbrg2rgb24(capture->form.fmt.pix.width, + case PALETTE_SGBRG: + sgbrg2rgb24(capture->form.fmt.pix.width, capture->form.fmt.pix.height, (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start, (unsigned char*)capture->frame.imageData); + break; } - } else #endif /* HAVE_CAMV4L2 */ {