From patchwork Wed Dec 8 14:14:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 390662 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oB8EEKIF000632 for ; Wed, 8 Dec 2010 14:14:20 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753991Ab0LHOOS (ORCPT ); Wed, 8 Dec 2010 09:14:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3068 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751588Ab0LHOOR (ORCPT ); Wed, 8 Dec 2010 09:14:17 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oB8EEHWq006373 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 8 Dec 2010 09:14:17 -0500 Received: from [10.3.231.249] (vpn-231-249.phx2.redhat.com [10.3.231.249]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oB8EEFuf010342; Wed, 8 Dec 2010 09:14:16 -0500 Message-ID: <4CFF92B7.4060106@redhat.com> Date: Wed, 08 Dec 2010 12:14:15 -0200 From: Mauro Carvalho Chehab User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100827 Red Hat/3.1.3-1.el6 Lightning/1.0b2 Thunderbird/3.1.3 MIME-Version: 1.0 To: Hans de Goede CC: Linux Media Mailing List Subject: [PATCH] libv4l: Add support for 8-bits grey format (V4L2_PIX_FMT_GREY) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 08 Dec 2010 14:14:21 +0000 (UTC) diff --git a/lib/libv4lconvert/libv4lconvert-priv.h b/lib/libv4lconvert/libv4lconvert-priv.h index 61a8c39..2680ed7 100644 --- a/lib/libv4lconvert/libv4lconvert-priv.h +++ b/lib/libv4lconvert/libv4lconvert-priv.h @@ -127,6 +127,15 @@ void v4lconvert_swap_rgb(const unsigned char *src, unsigned char *dst, void v4lconvert_swap_uv(const unsigned char *src, unsigned char *dst, const struct v4l2_format *src_fmt); +void v4lconvert_grey_to_rgb24(const unsigned char *src, unsigned char *dest, + int width, int height); + +void v4lconvert_grey_to_yuv420(const unsigned char *src, unsigned char *dest, + const struct v4l2_format *src_fmt); + +void v4lconvert_grey_to_rgb24(const unsigned char *src, unsigned char *dest, + int width, int height); + void v4lconvert_rgb565_to_rgb24(const unsigned char *src, unsigned char *dest, int width, int height); diff --git a/lib/libv4lconvert/libv4lconvert.c b/lib/libv4lconvert/libv4lconvert.c index f08996a..26a0978 100644 --- a/lib/libv4lconvert/libv4lconvert.c +++ b/lib/libv4lconvert/libv4lconvert.c @@ -43,6 +43,7 @@ static void v4lconvert_get_framesizes(struct v4lconvert_data *data, v4lconvert_try_format for low resolutions */ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = { SUPPORTED_DST_PIXFMTS, + { V4L2_PIX_FMT_GREY, 0 }, { V4L2_PIX_FMT_YUYV, 0 }, { V4L2_PIX_FMT_YVYU, 0 }, { V4L2_PIX_FMT_UYVY, 0 }, @@ -839,6 +840,23 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, } break; + case V4L2_PIX_FMT_GREY: + switch (dest_pix_fmt) { + case V4L2_PIX_FMT_RGB24: + case V4L2_PIX_FMT_BGR24: + v4lconvert_grey_to_rgb24(src, dest, width, height); + break; + case V4L2_PIX_FMT_YUV420: + case V4L2_PIX_FMT_YVU420: + v4lconvert_grey_to_yuv420(src, dest, fmt); + break; + } + if (src_size < (width * height)) { + V4LCONVERT_ERR("short grey data frame\n"); + errno = EPIPE; + result = -1; + } + break; case V4L2_PIX_FMT_RGB565: switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: diff --git a/lib/libv4lconvert/rgbyuv.c b/lib/libv4lconvert/rgbyuv.c index f205b39..c3b6235 100644 --- a/lib/libv4lconvert/rgbyuv.c +++ b/lib/libv4lconvert/rgbyuv.c @@ -575,3 +575,31 @@ void v4lconvert_rgb565_to_yuv420(const unsigned char *src, unsigned char *dest, src += 2 * src_fmt->fmt.pix.bytesperline - 2 * src_fmt->fmt.pix.width; } } + +void v4lconvert_grey_to_rgb24(const unsigned char *src, unsigned char *dest, + int width, int height) +{ + int j; + while (--height >= 0) { + for (j = 0; j < width; j++) { + *dest++ = *src; + *dest++ = *src; + *dest++ = *src; + src++; + } + } +} + +void v4lconvert_grey_to_yuv420(const unsigned char *src, unsigned char *dest, + const struct v4l2_format *src_fmt) +{ + int x, y; + + /* Y */ + for (y = 0; y < src_fmt->fmt.pix.height; y++) + for (x = 0; x < src_fmt->fmt.pix.width; x++) + *dest++ = *src++; + + /* Clear U/V */ + memset(dest, 0, src_fmt->fmt.pix.width * src_fmt->fmt.pix.height / 2); +}