From patchwork Sat Mar 12 00:45:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8570571 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 95B92C0553 for ; Sat, 12 Mar 2016 00:46:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A9F3E20361 for ; Sat, 12 Mar 2016 00:46:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A55F32035D for ; Sat, 12 Mar 2016 00:46:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751756AbcCLAqk (ORCPT ); Fri, 11 Mar 2016 19:46:40 -0500 Received: from smtp-4.sys.kth.se ([130.237.48.193]:47110 "EHLO smtp-4.sys.kth.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750980AbcCLAqk (ORCPT ); Fri, 11 Mar 2016 19:46:40 -0500 Received: from smtp-4.sys.kth.se (localhost.localdomain [127.0.0.1]) by smtp-4.sys.kth.se (Postfix) with ESMTP id EFF1223F4; Sat, 12 Mar 2016 01:46:36 +0100 (CET) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-4.sys.kth.se ([127.0.0.1]) by smtp-4.sys.kth.se (smtp-4.sys.kth.se [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 0qpy-miuCPp8; Sat, 12 Mar 2016 01:46:35 +0100 (CET) X-KTH-Auth: niso [89.233.230.99] X-KTH-mail-from: niklas.soderlund+renesas@ragnatech.se Received: from bismarck.berto.se (dynamic.0.6.79d1f80.14cc20ac3a53.cust.bredband2.com [89.233.230.99]) by smtp-4.sys.kth.se (Postfix) with ESMTPSA id 046B22C1; Sat, 12 Mar 2016 01:46:34 +0100 (CET) From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= To: hverkuil@xs4all.nl, linux-media@vger.kernel.org Cc: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [v4l-utils PATCHv2] libv4lconvert: Add support for V4L2_PIX_FMT_{NV16, NV61} Date: Sat, 12 Mar 2016 01:45:05 +0100 Message-Id: <1457743505-7161-1-git-send-email-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.7.2 In-Reply-To: <56E332A8.2080004@xs4all.nl> References: <56E332A8.2080004@xs4all.nl> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 NV16 and NV61 are two-plane versions of the YUV 4:2:2 formats YUYV and YVYU. Support both formats by merging the two planes into a one and falling through to the V4L2_PIX_FMT_{YUYV,YVYU} code path. Signed-off-by: Niklas Söderlund Acked-by: Hans de Goede --- I'm sorry this is a bit of a hack. The support for NV16 are scarce and this allowed me use it in qv4l2 so I thought it might help someone else. I'm not to sure about the entry in supported_src_pixfmts[] is it correct to set 'needs conversion' for my use case? Changes since v1 - Add NV61 support - Fixed s/YUVU/YUYV/g in commit message lib/libv4lconvert/libv4lconvert-priv.h | 3 +++ lib/libv4lconvert/libv4lconvert.c | 31 +++++++++++++++++++++++++++++++ lib/libv4lconvert/rgbyuv.c | 15 +++++++++++++++ 3 files changed, 49 insertions(+) -- 2.7.2 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/lib/libv4lconvert/libv4lconvert-priv.h b/lib/libv4lconvert/libv4lconvert-priv.h index b77e3d3..1740efc 100644 --- a/lib/libv4lconvert/libv4lconvert-priv.h +++ b/lib/libv4lconvert/libv4lconvert-priv.h @@ -129,6 +129,9 @@ void v4lconvert_yuyv_to_bgr24(const unsigned char *src, unsigned char *dst, void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dst, int width, int height, int stride, int yvu); +void v4lconvert_nv16_to_yuyv(const unsigned char *src, unsigned char *dest, + int width, int height); + void v4lconvert_yvyu_to_rgb24(const unsigned char *src, unsigned char *dst, int width, int height, int stride); diff --git a/lib/libv4lconvert/libv4lconvert.c b/lib/libv4lconvert/libv4lconvert.c index f62aea1..d3d8936 100644 --- a/lib/libv4lconvert/libv4lconvert.c +++ b/lib/libv4lconvert/libv4lconvert.c @@ -98,6 +98,8 @@ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = { { V4L2_PIX_FMT_YUYV, 16, 5, 4, 0 }, { V4L2_PIX_FMT_YVYU, 16, 5, 4, 0 }, { V4L2_PIX_FMT_UYVY, 16, 5, 4, 0 }, + { V4L2_PIX_FMT_NV16, 16, 5, 4, 1 }, + { V4L2_PIX_FMT_NV61, 16, 5, 4, 1 }, /* yuv 4:2:0 formats */ { V4L2_PIX_FMT_SPCA501, 12, 6, 3, 1 }, { V4L2_PIX_FMT_SPCA505, 12, 6, 3, 1 }, @@ -1229,6 +1231,20 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, } break; + case V4L2_PIX_FMT_NV16: { + unsigned char *tmpbuf; + + tmpbuf = v4lconvert_alloc_buffer(width * height * 2, + &data->convert_pixfmt_buf, &data->convert_pixfmt_buf_size); + if (!tmpbuf) + return v4lconvert_oom_error(data); + + v4lconvert_nv16_to_yuyv(src, tmpbuf, width, height); + src_pix_fmt = V4L2_PIX_FMT_YUYV; + src = tmpbuf; + bytesperline = bytesperline * 2; + /* fall through */ + } case V4L2_PIX_FMT_YUYV: if (src_size < (width * height * 2)) { V4LCONVERT_ERR("short yuyv data frame\n"); @@ -1251,6 +1267,21 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, } break; + case V4L2_PIX_FMT_NV61: { + unsigned char *tmpbuf; + + tmpbuf = v4lconvert_alloc_buffer(width * height * 2, + &data->convert_pixfmt_buf, &data->convert_pixfmt_buf_size); + if (!tmpbuf) + return v4lconvert_oom_error(data); + + /* Note NV61 is NV16 with U and V swapped so this becomes yvyu. */ + v4lconvert_nv16_to_yuyv(src, tmpbuf, width, height); + src_pix_fmt = V4L2_PIX_FMT_YVYU; + src = tmpbuf; + bytesperline = bytesperline * 2; + /* fall through */ + } case V4L2_PIX_FMT_YVYU: if (src_size < (width * height * 2)) { V4LCONVERT_ERR("short yvyu data frame\n"); diff --git a/lib/libv4lconvert/rgbyuv.c b/lib/libv4lconvert/rgbyuv.c index 695255a..a0f8256 100644 --- a/lib/libv4lconvert/rgbyuv.c +++ b/lib/libv4lconvert/rgbyuv.c @@ -295,6 +295,21 @@ void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dest, } } +void v4lconvert_nv16_to_yuyv(const unsigned char *src, unsigned char *dest, + int width, int height) +{ + const unsigned char *y, *cbcr; + int count = 0; + + y = src; + cbcr = src + width*height; + + while (count++ < width*height) { + *dest++ = *y++; + *dest++ = *cbcr++; + } +} + void v4lconvert_yvyu_to_bgr24(const unsigned char *src, unsigned char *dest, int width, int height, int stride) {