From patchwork Thu Sep 20 20:04:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 10608689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5B4315A6 for ; Thu, 20 Sep 2018 20:04:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA4482DFFC for ; Thu, 20 Sep 2018 20:04:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE7032E023; Thu, 20 Sep 2018 20:04:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CE3A2DFFC for ; Thu, 20 Sep 2018 20:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388532AbeIUBtU (ORCPT ); Thu, 20 Sep 2018 21:49:20 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:46732 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388488AbeIUBtT (ORCPT ); Thu, 20 Sep 2018 21:49:19 -0400 Received: by mail-lj1-f196.google.com with SMTP id 203-v6so9531493ljj.13 for ; Thu, 20 Sep 2018 13:04:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=pvqXsm7/PSIni4ozVbffebIeDWTSPIt2iqsLw2NNqYQ=; b=cs3jw2ohDIy79RkUSGms4s6++KU2UFDk/Kg3ksQkV1K8NG/WDbl1vuDENkEQuKIU/g opezmfXmSqjv6db5bHMKQzgJIajUTECtbkdwyT+S2MLAHqVfeckQDmhU/cpl1M0k20Xf Uny5jnUFTDBN3M6we4Xsv5ad2XLivtaaEUJ9cF3kcQql2/ZfU3G1FNuwNxnN4FZZ6883 Cm4VyFZntRQxZ5RvMG+PpK8Xu/QOQ/SzJtKWsSZgby465K0aTmgWXqTjA+j6kCXgBODU weSEYC9Imi7L2/idVmDN4Lh/9rHtZwiSMXBzZi4iK8zg7JbdydfU37OKgaaBhaFPwAwS W55Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=pvqXsm7/PSIni4ozVbffebIeDWTSPIt2iqsLw2NNqYQ=; b=Tmz/0CJ+pvHU2RXqjHLvDAhVIiI3bK9zt13HRNYjBtG2HDtX8ld1kBNON+ABp8fmtB dgUBmy0dGQKYOCruu3bRTO0TC08gjaAc/sawvwbhpiULiT214LJWEOR4T67x81yXcjvP g3WFH8yr8xbxYPgxumshLStFYXZldCkvx+frw+UtLje45+5k/zFxkQYYB/Olz+4I3h3y YtN66Spr0sLBSScRsuHkh0hdp1VbetRyHvzUCLoeTcPW527AerN7QuFFfbOQq7xO5OoI xnvziHrHtrDImQMAwv53Hfw2yk7XAGHLbwtKpziDtgV8Ud8yVeMusN5ClzeflsG+uUnk enkw== X-Gm-Message-State: APzg51AazzG6nWsdAi9rTDrnYiPbAwUyiFSblZfwVqol2iGbWUrxtDoQ L42HKoeyeO23pI1GF1Ul1SE= X-Google-Smtp-Source: ANB0VdYF4vAoT73hCl6JqkflEYngfNUFriEKAH7e5F+1uAg59y6lnBwGFksDw1c5djql9pCe+ZRprQ== X-Received: by 2002:a2e:4557:: with SMTP id s84-v6mr24752938lja.47.1537473849490; Thu, 20 Sep 2018 13:04:09 -0700 (PDT) Received: from piling.lan (80-71-134-83.u.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id f66-v6sm4740900lji.23.2018.09.20.13.04.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 13:04:08 -0700 (PDT) From: Ricardo Ribalda Delgado To: Hans de Goede , linux-media@vger.kernel.org Cc: Ricardo Ribalda Delgado Subject: [PATCH] libv4l: Add support for BAYER10P format conversion Date: Thu, 20 Sep 2018 22:04:06 +0200 Message-Id: <20180920200406.18066-1-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.18.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for 10 bit packet Bayer formats: -V4L2_PIX_FMT_SBGGR10P -V4L2_PIX_FMT_SGBRG10P -V4L2_PIX_FMT_SGRBG10P -V4L2_PIX_FMT_SRGGB10P These formats pack the 2 LSBs for every 4 pixels in an indeppendent byte. Signed-off-by: Ricardo Ribalda Delgado --- lib/libv4lconvert/bayer.c | 15 +++++++++++ lib/libv4lconvert/libv4lconvert-priv.h | 4 +++ lib/libv4lconvert/libv4lconvert.c | 35 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/lib/libv4lconvert/bayer.c b/lib/libv4lconvert/bayer.c index 4b70ddd9..d7d488f9 100644 --- a/lib/libv4lconvert/bayer.c +++ b/lib/libv4lconvert/bayer.c @@ -631,3 +631,18 @@ void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv, v4lconvert_border_bayer_line_to_y(bayer + stride, bayer, ydst, width, !start_with_green, !blue_line); } + +void v4lconvert_bayer10p_to_bayer8(unsigned char *bayer10p, + unsigned char *bayer8, int width, int height) +{ + long i, len = width * height; + uint32_t *src, *dst; + + src = (uint32_t *)bayer10p; + dst = (uint32_t *)bayer8; + for (i = 0; i < len ; i += 4) { + *dst = *src; + dst++; + src = (uint32_t *)(((uint8_t *)src) + 5); + } +} diff --git a/lib/libv4lconvert/libv4lconvert-priv.h b/lib/libv4lconvert/libv4lconvert-priv.h index 9a467e10..3020a39e 100644 --- a/lib/libv4lconvert/libv4lconvert-priv.h +++ b/lib/libv4lconvert/libv4lconvert-priv.h @@ -264,6 +264,10 @@ void v4lconvert_bayer_to_bgr24(const unsigned char *bayer, void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv, int width, int height, const unsigned int stride, unsigned int src_pixfmt, int yvu); + +void v4lconvert_bayer10p_to_bayer8(unsigned char *bayer10p, + unsigned char *bayer8, int width, int height); + void v4lconvert_hm12_to_rgb24(const unsigned char *src, unsigned char *dst, int width, int height); diff --git a/lib/libv4lconvert/libv4lconvert.c b/lib/libv4lconvert/libv4lconvert.c index d666bd97..b3dbf5a0 100644 --- a/lib/libv4lconvert/libv4lconvert.c +++ b/lib/libv4lconvert/libv4lconvert.c @@ -133,6 +133,10 @@ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = { { V4L2_PIX_FMT_SRGGB8, 8, 8, 8, 0 }, { V4L2_PIX_FMT_STV0680, 8, 8, 8, 1 }, { V4L2_PIX_FMT_SGRBG10, 16, 8, 8, 1 }, + { V4L2_PIX_FMT_SBGGR10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SGBRG10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SGRBG10P, 10, 8, 8, 1 }, + { V4L2_PIX_FMT_SRGGB10P, 10, 8, 8, 1 }, /* compressed bayer */ { V4L2_PIX_FMT_SPCA561, 0, 9, 9, 1 }, { V4L2_PIX_FMT_SN9C10X, 0, 9, 9, 1 }, @@ -687,6 +691,10 @@ static int v4lconvert_processing_needs_double_conversion( case V4L2_PIX_FMT_SGBRG8: case V4L2_PIX_FMT_SGRBG8: case V4L2_PIX_FMT_SRGGB8: + case V4L2_PIX_FMT_SBGGR10P: + case V4L2_PIX_FMT_SGBRG10P: + case V4L2_PIX_FMT_SGRBG10P: + case V4L2_PIX_FMT_SRGGB10P: case V4L2_PIX_FMT_STV0680: return 0; } @@ -979,6 +987,33 @@ static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, } /* Raw bayer formats */ + case V4L2_PIX_FMT_SBGGR10P: + case V4L2_PIX_FMT_SGBRG10P: + case V4L2_PIX_FMT_SGRBG10P: + case V4L2_PIX_FMT_SRGGB10P: + if (src_size < ((width * height * 10)/8)) { + V4LCONVERT_ERR("short raw bayer10 data frame\n"); + errno = EPIPE; + result = -1; + } + switch (src_pix_fmt) { + case V4L2_PIX_FMT_SBGGR10P: + src_pix_fmt = V4L2_PIX_FMT_SBGGR8; + break; + case V4L2_PIX_FMT_SGBRG10P: + src_pix_fmt = V4L2_PIX_FMT_SGBRG8; + break; + case V4L2_PIX_FMT_SGRBG10P: + src_pix_fmt = V4L2_PIX_FMT_SGRBG8; + break; + case V4L2_PIX_FMT_SRGGB10P: + src_pix_fmt = V4L2_PIX_FMT_SRGGB8; + break; + } + v4lconvert_bayer10p_to_bayer8(src, src, width, height); + bytesperline = width; + + /* Fall-through*/ case V4L2_PIX_FMT_SBGGR8: case V4L2_PIX_FMT_SGBRG8: case V4L2_PIX_FMT_SGRBG8: