From patchwork Thu Aug 1 13:04:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 2836976 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 52B769F9C8 for ; Thu, 1 Aug 2013 13:05:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4DBAA20187 for ; Thu, 1 Aug 2013 13:05:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4946520176 for ; Thu, 1 Aug 2013 13:05:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755278Ab3HANFM (ORCPT ); Thu, 1 Aug 2013 09:05:12 -0400 Received: from mail-la0-f50.google.com ([209.85.215.50]:39906 "EHLO mail-la0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755348Ab3HANFJ (ORCPT ); Thu, 1 Aug 2013 09:05:09 -0400 Received: by mail-la0-f50.google.com with SMTP id fn20so1376739lab.23 for ; Thu, 01 Aug 2013 06:05:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=NnCF1r3pGw+4oWVTEFZCPIJmTvL3HnKwqyTT2TUNErE=; b=KO7vO1JqocGEvK3B8mkPH73+SfdMbnu8+23a65rZjaf2Qi6otmgHnk1CtZO+AfN09A 9rhdjlIYJM+GokRdIAVZ+/ssolM2yEn4KQ8NFKe9Y0PeCmMqpuwV4js74xGjfiLuMuCP SoHYq2bUOwXvrT64A/Tc9J918r6GCD0PWkFGz1V1pCrDJbkt2x4ypYwH5M02niPfDB3C OVnXVJr9yEXxbxCkYWx9TdGWjiEcdCS9Z45rew8ljRuEyqyF4feLaUUfBfYoGuL6EYpj xBH0CZMQWhSnr5oXV7i07v3+5NcXyTGZndSxjlB1DR7JWNDjO6kc7Lw6TxJVhyaWY4Pk /EUg== X-Received: by 10.112.72.67 with SMTP id b3mr1389989lbv.35.1375362307184; Thu, 01 Aug 2013 06:05:07 -0700 (PDT) Received: from localhost (0x4dd4aed9.adsl.cybercity.dk. [77.212.174.217]) by mx.google.com with ESMTPSA id rx1sm1244296lbb.0.2013.08.01.06.05.05 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 01 Aug 2013 06:05:06 -0700 (PDT) From: Ricardo Ribalda Delgado To: hans.verkuil@cisco.com, linux-media@vger.kernel.org Cc: Ricardo Ribalda Delgado Subject: [PATCH 2/2] libv4lconvert: Support for RGB32 and BGR32 format Date: Thu, 1 Aug 2013 15:04:54 +0200 Message-Id: <1375362294-30741-3-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1375362294-30741-1-git-send-email-ricardo.ribalda@gmail.com> References: <1375362294-30741-1-git-send-email-ricardo.ribalda@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for V4L2_PIX_FMT_BGR32 and V4L2_PIX_FMT_BGR32 formats. Signed-off-by: Ricardo Ribalda Delgado --- lib/libv4lconvert/libv4lconvert-priv.h | 5 ++- lib/libv4lconvert/libv4lconvert.c | 58 +++++++++++++++++++++++++--- lib/libv4lconvert/rgbyuv.c | 66 ++++++++++++++++++++++++++------ 3 files changed, 111 insertions(+), 18 deletions(-) diff --git a/lib/libv4lconvert/libv4lconvert-priv.h b/lib/libv4lconvert/libv4lconvert-priv.h index 6422fdd..2f411ea 100644 --- a/lib/libv4lconvert/libv4lconvert-priv.h +++ b/lib/libv4lconvert/libv4lconvert-priv.h @@ -108,7 +108,7 @@ unsigned char *v4lconvert_alloc_buffer(int needed, int v4lconvert_oom_error(struct v4lconvert_data *data); void v4lconvert_rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, - const struct v4l2_format *src_fmt, int bgr, int yvu); + const struct v4l2_format *src_fmt, int bgr, int yvu, int rgb32); void v4lconvert_yuv420_to_rgb24(const unsigned char *src, unsigned char *dst, int width, int height, int yvu); @@ -158,6 +158,9 @@ void v4lconvert_y16_to_rgb24(const unsigned char *src, unsigned char *dest, void v4lconvert_y16_to_yuv420(const unsigned char *src, unsigned char *dest, const struct v4l2_format *src_fmt); +void v4lconvert_rgb32_to_rgb24(const unsigned char *src, unsigned char *dest, + int width, int height, int bgr); + int v4lconvert_y10b_to_rgb24(struct v4lconvert_data *data, const unsigned char *src, unsigned char *dest, int width, int height); diff --git a/lib/libv4lconvert/libv4lconvert.c b/lib/libv4lconvert/libv4lconvert.c index bc5e34f..a5ada5b 100644 --- a/lib/libv4lconvert/libv4lconvert.c +++ b/lib/libv4lconvert/libv4lconvert.c @@ -84,6 +84,8 @@ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = { SUPPORTED_DST_PIXFMTS, /* packed rgb formats */ { V4L2_PIX_FMT_RGB565, 16, 4, 6, 0 }, + { V4L2_PIX_FMT_BGR32, 32, 4, 6, 0 }, + { V4L2_PIX_FMT_RGB32, 32, 4, 6, 0 }, /* yuv 4:2:2 formats */ { V4L2_PIX_FMT_YUYV, 16, 5, 4, 0 }, { V4L2_PIX_FMT_YVYU, 16, 5, 4, 0 }, @@ -981,10 +983,10 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, v4lconvert_swap_rgb(d, dest, width, height); break; case V4L2_PIX_FMT_YUV420: - v4lconvert_rgb24_to_yuv420(d, dest, fmt, 0, 0); + v4lconvert_rgb24_to_yuv420(d, dest, fmt, 0, 0, 0); break; case V4L2_PIX_FMT_YVU420: - v4lconvert_rgb24_to_yuv420(d, dest, fmt, 0, 1); + v4lconvert_rgb24_to_yuv420(d, dest, fmt, 0, 1, 0); break; } break; @@ -1079,10 +1081,10 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, v4lconvert_swap_rgb(src, dest, width, height); break; case V4L2_PIX_FMT_YUV420: - v4lconvert_rgb24_to_yuv420(src, dest, fmt, 0, 0); + v4lconvert_rgb24_to_yuv420(src, dest, fmt, 0, 0, 0); break; case V4L2_PIX_FMT_YVU420: - v4lconvert_rgb24_to_yuv420(src, dest, fmt, 0, 1); + v4lconvert_rgb24_to_yuv420(src, dest, fmt, 0, 1, 0); break; } if (src_size < (width * height * 3)) { @@ -1101,10 +1103,10 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, memcpy(dest, src, width * height * 3); break; case V4L2_PIX_FMT_YUV420: - v4lconvert_rgb24_to_yuv420(src, dest, fmt, 1, 0); + v4lconvert_rgb24_to_yuv420(src, dest, fmt, 1, 0, 0); break; case V4L2_PIX_FMT_YVU420: - v4lconvert_rgb24_to_yuv420(src, dest, fmt, 1, 1); + v4lconvert_rgb24_to_yuv420(src, dest, fmt, 1, 1, 0); break; } if (src_size < (width * height * 3)) { @@ -1114,6 +1116,50 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, } break; + case V4L2_PIX_FMT_RGB32: + switch (dest_pix_fmt) { + case V4L2_PIX_FMT_RGB24: + v4lconvert_rgb32_to_rgb24(src, dest, width, height, 0); + break; + case V4L2_PIX_FMT_BGR24: + v4lconvert_rgb32_to_rgb24(src, dest, width, height, 1); + break; + case V4L2_PIX_FMT_YUV420: + v4lconvert_rgb24_to_yuv420(src, dest, fmt, 0, 0, 1); + break; + case V4L2_PIX_FMT_YVU420: + v4lconvert_rgb24_to_yuv420(src, dest, fmt, 0, 1, 1); + break; + } + if (src_size < (width * height * 4)) { + V4LCONVERT_ERR("short rgb32 data frame\n"); + errno = EPIPE; + result = -1; + } + break; + + case V4L2_PIX_FMT_BGR32: + switch (dest_pix_fmt) { + case V4L2_PIX_FMT_RGB24: + v4lconvert_rgb32_to_rgb24(src, dest, width, height, 1); + break; + case V4L2_PIX_FMT_BGR24: + v4lconvert_rgb32_to_rgb24(src, dest, width, height, 0); + break; + case V4L2_PIX_FMT_YUV420: + v4lconvert_rgb24_to_yuv420(src, dest, fmt, 1, 0, 1); + break; + case V4L2_PIX_FMT_YVU420: + v4lconvert_rgb24_to_yuv420(src, dest, fmt, 1, 1, 1); + break; + } + if (src_size < (width * height * 4)) { + V4LCONVERT_ERR("short bgr32 data frame\n"); + errno = EPIPE; + result = -1; + } + break; + case V4L2_PIX_FMT_YUV420: switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: diff --git a/lib/libv4lconvert/rgbyuv.c b/lib/libv4lconvert/rgbyuv.c index bef034f..7d543d6 100644 --- a/lib/libv4lconvert/rgbyuv.c +++ b/lib/libv4lconvert/rgbyuv.c @@ -35,7 +35,7 @@ } while (0) void v4lconvert_rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, - const struct v4l2_format *src_fmt, int bgr, int yvu) + const struct v4l2_format *src_fmt, int bgr, int yvu, int rgb32) { int x, y; unsigned char *udest, *vdest; @@ -47,9 +47,15 @@ void v4lconvert_rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, RGB2Y(src[2], src[1], src[0], *dest++); else RGB2Y(src[0], src[1], src[2], *dest++); - src += 3; + if (rgb32) + src += 4; + else + src += 3; } - src += src_fmt->fmt.pix.bytesperline - 3 * src_fmt->fmt.pix.width; + if (rgb32) + src += src_fmt->fmt.pix.bytesperline - 4 * src_fmt->fmt.pix.width; + else + src += src_fmt->fmt.pix.bytesperline - 3 * src_fmt->fmt.pix.width; } src -= src_fmt->fmt.pix.height * src_fmt->fmt.pix.bytesperline; @@ -66,19 +72,35 @@ void v4lconvert_rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, for (x = 0; x < src_fmt->fmt.pix.width / 2; x++) { int avg_src[3]; - avg_src[0] = (src[0] + src[3] + src[src_fmt->fmt.pix.bytesperline] + - src[src_fmt->fmt.pix.bytesperline + 3]) / 4; - avg_src[1] = (src[1] + src[4] + src[src_fmt->fmt.pix.bytesperline + 1] + - src[src_fmt->fmt.pix.bytesperline + 4]) / 4; - avg_src[2] = (src[2] + src[5] + src[src_fmt->fmt.pix.bytesperline + 2] + - src[src_fmt->fmt.pix.bytesperline + 5]) / 4; + if (rgb32) { + avg_src[0] = (src[0] + src[3] + src[src_fmt->fmt.pix.bytesperline] + + src[src_fmt->fmt.pix.bytesperline + 3]) / 4; + avg_src[1] = (src[1] + src[4] + src[src_fmt->fmt.pix.bytesperline + 1] + + src[src_fmt->fmt.pix.bytesperline + 4]) / 4; + avg_src[2] = (src[2] + src[5] + src[src_fmt->fmt.pix.bytesperline + 2] + + src[src_fmt->fmt.pix.bytesperline + 5]) / 4; + } + else{ + avg_src[0] = (src[0] + src[4] + src[src_fmt->fmt.pix.bytesperline] + + src[src_fmt->fmt.pix.bytesperline + 4]) / 4; + avg_src[1] = (src[1] + src[5] + src[src_fmt->fmt.pix.bytesperline + 1] + + src[src_fmt->fmt.pix.bytesperline + 5]) / 4; + avg_src[2] = (src[2] + src[6] + src[src_fmt->fmt.pix.bytesperline + 2] + + src[src_fmt->fmt.pix.bytesperline + 6]) / 4; + } if (bgr) RGB2UV(avg_src[2], avg_src[1], avg_src[0], *udest++, *vdest++); else RGB2UV(avg_src[0], avg_src[1], avg_src[2], *udest++, *vdest++); - src += 6; + if (rgb32) + src += 8; + else + src += 6; } - src += 2 * src_fmt->fmt.pix.bytesperline - 3 * src_fmt->fmt.pix.width; + if (rgb32) + src += 2 * src_fmt->fmt.pix.bytesperline - 4 * src_fmt->fmt.pix.width; + else + src += 2 * src_fmt->fmt.pix.bytesperline - 3 * src_fmt->fmt.pix.width; } } @@ -725,3 +747,25 @@ int v4lconvert_y10b_to_yuv420(struct v4lconvert_data *data, return 0; } + +void v4lconvert_rgb32_to_rgb24(const unsigned char *src, unsigned char *dest, + int width, int height,int bgr) +{ + int j; + while (--height >= 0) { + for (j = 0; j < width; j++) { + if (bgr){ + *dest++ = src[2]; + *dest++ = src[1]; + *dest++ = src[0]; + src+=4; + } + else{ + *dest++ = *src++; + *dest++ = *src++; + *dest++ = *src++; + src+=1; + } + } + } +}