From patchwork Sat Mar 18 23:40:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 18418 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0F7C7C3264 for ; Sat, 18 Mar 2023 23:40:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A5400626E4; Sun, 19 Mar 2023 00:40:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1679182841; bh=C37Hro6tCy34wIVwFypxMDCtp37LTHZR+pvMjoVAx+I=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=JsudmhWNe5KEgYP4tfbNUjju6m1Yob6MwEB8fCTU2GGkfFMFzS00Bhrq83WSSmGr9 1hlyuB6QiDQxt6JqsmcxplwZfhmcPgn2SK6m8E0WAyr0FBmfz9Gwql8w3dwp4plcpr 5qCAdA8ZzgupXjeFi6zcAUu4Q3zIsWMaQVbBiiNb+IJPErAla6iAp+8T1e8eGjyyqX UJkjZfxbA2J//YTNiVZWyBQmxu2KQ9oXWoNCy/5twPWTF1DcfkhYZ6pZmRtC1nWg9L EfJVeOboCPRDPZU7cHige0u1uUTXYRf/so/H2z3ezsXAZM2qWvWa2Tc2sIZmgFg5xj qanlwinnffxrw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ABA6D626F3 for ; Sun, 19 Mar 2023 00:40:34 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nnmxLe98"; dkim-atps=neutral Received: from mail.ideasonboard.com (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4B35DB6C; Sun, 19 Mar 2023 00:40:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1679182834; bh=C37Hro6tCy34wIVwFypxMDCtp37LTHZR+pvMjoVAx+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nnmxLe98vM8MyrdGmtIk4vMjwM9VSmIJe6ZiJtIzjlIDTHZcnG5qGX4NwW3YqULlz 2qmdh6fqj0hv+Pd+rAo/nj+fsA56crrxrQvu4QmxCue9ybUgnEDIXtLUimf53IFfqY xS/f1kJcq8J+CSevtHkm1tUkwHu47mjce5sUiMhU= To: libcamera-devel@lists.libcamera.org Date: Sat, 18 Mar 2023 23:40:12 +0000 Message-Id: <20230318234014.29506-10-dan.scally@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230318234014.29506-1-dan.scally@ideasonboard.com> References: <20230318234014.29506-1-dan.scally@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 09/11] apps: qcam: Add support for IPU3_Y10 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Daniel Scally via libcamera-devel From: Dan Scally Reply-To: Daniel Scally Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add support for the IPU3_Y10 format to the FormatConverter. Signed-off-by: Daniel Scally --- src/apps/qcam/format_converter.cpp | 50 ++++++++++++++++++++++++++++++ src/apps/qcam/format_converter.h | 2 ++ 2 files changed, 52 insertions(+) diff --git a/src/apps/qcam/format_converter.cpp b/src/apps/qcam/format_converter.cpp index de76b32c..7f5648f3 100644 --- a/src/apps/qcam/format_converter.cpp +++ b/src/apps/qcam/format_converter.cpp @@ -169,6 +169,10 @@ int FormatConverter::configure(const libcamera::PixelFormat &format, formatFamily_ = MJPEG; break; + case libcamera::formats::Y10_IPU3: + formatFamily_ = IPU3Packed; + break; + default: return -EINVAL; }; @@ -199,6 +203,9 @@ void FormatConverter::convert(const Image *src, size_t size, QImage *dst) case YUVPlanar: convertYUVPlanar(src, dst->bits()); break; + case IPU3Packed: + convertIPU3Packed(src, dst->bits(), size); + break; }; } @@ -357,3 +364,46 @@ void FormatConverter::convertYUVSemiPlanar(const Image *srcImage, unsigned char } } } + +void FormatConverter::convertIPU3Packed(const Image *srcImage, unsigned char *dst, size_t size) +{ + const unsigned char *src = srcImage->data(0).data(); + unsigned int bytesprocessed = 0; + unsigned int lsb_shift; + unsigned int msb_shift; + unsigned int index; + unsigned int x = 0; + uint16_t pixel; + + while (bytesprocessed < size) { + for (unsigned int i = 0; i < 25; ++i) { + index = (i * 10) / 8; + lsb_shift = (i * 10) % 8; + msb_shift = 8 - lsb_shift; + + /* + * The IPU3-packed format can result in padding at the + * end of a 32-byte block if the last pixel in a row is + * within that block. Check whether we're on the line's + * last pixel and skip the rest of the block if so. + */ + if (x == width_) { + x = 0; + dst += width_ * 4; + break; + } + + pixel = (((src + bytesprocessed)[index+1] << msb_shift) & 0x3ff) + | (((src + bytesprocessed)[index+0] >> lsb_shift) & 0x3ff); + + dst[4 * x + 0] = (pixel >> 2) & 0xff; + dst[4 * x + 1] = (pixel >> 2) & 0xff; + dst[4 * x + 2] = (pixel >> 2) & 0xff; + dst[4 * x + 3] = 0xff; + + x++; + } + + bytesprocessed += 32; + } +} diff --git a/src/apps/qcam/format_converter.h b/src/apps/qcam/format_converter.h index 37dbfae2..940f8b6b 100644 --- a/src/apps/qcam/format_converter.h +++ b/src/apps/qcam/format_converter.h @@ -31,12 +31,14 @@ private: YUVPacked, YUVPlanar, YUVSemiPlanar, + IPU3Packed, }; void convertRGB(const Image *src, unsigned char *dst); void convertYUVPacked(const Image *src, unsigned char *dst); void convertYUVPlanar(const Image *src, unsigned char *dst); void convertYUVSemiPlanar(const Image *src, unsigned char *dst); + void convertIPU3Packed(const Image *src, unsigned char *dst, size_t size); libcamera::PixelFormat format_; unsigned int width_;