From patchwork Fri Jun 28 21:35:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20486 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 A7CE9BD87C for ; Fri, 28 Jun 2024 21:36:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C1FBB62C9F; Fri, 28 Jun 2024 23:36:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="G9zpe3dR"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0055662C95 for ; Fri, 28 Jun 2024 23:35:58 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 10A862C5 for ; Fri, 28 Jun 2024 23:35:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1719610533; bh=j7YXVIhlBpY9+vSh/yt9XreDl5UBpm+4n4rSTlqjKsw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=G9zpe3dRHR3v6IuVu7nRo5fLOE3n/WRuk1XfEIAMqBrM6hOKJNRq1/h2gPuVcjrrk leVStOiI8YTeFUwC3DL3g2O+bLQyDYGwuMDt8jzxt0DFWDVeSWlxnmAq1EI0OK2bYM i1DdFNy0quu4nLafbzygq17YNYHO0ifRU23AL0BI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 1/2] apps: common: dng_writer: Fix thumbnail generation on BE machines Date: Sat, 29 Jun 2024 00:35:34 +0300 Message-ID: <20240628213535.6906-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240628213535.6906-1-laurent.pinchart@ideasonboard.com> References: <20240628213535.6906-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The 16-bit padded raw 10 and raw 12 formats are stored in memory in little endian order, regardless of the machine's endianness. Swap the 16-bit values on big-endian machines when reading pixels from memory to generate thumbnails. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Signed-off-by: Stefan Klug Reviewed-by: Stefan Klug --- src/apps/common/dng_writer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp index 9241f23fb806..50db5eb33c83 100644 --- a/src/apps/common/dng_writer.cpp +++ b/src/apps/common/dng_writer.cpp @@ -8,6 +8,7 @@ #include "dng_writer.h" #include +#include #include #include @@ -185,7 +186,8 @@ void thumbScanlineRaw(const FormatInfo &info, void *output, const void *input, /* Simple averaging that produces greyscale RGB values. */ for (unsigned int x = 0; x < width; x++) { - uint16_t value = (in[0] + in[1] + in2[0] + in2[1]) >> 2; + uint16_t value = (le16toh(in[0]) + le16toh(in[1]) + + le16toh(in2[0]) + le16toh(in2[1])) >> 2; value = value >> shift; *out++ = value; *out++ = value; From patchwork Fri Jun 28 21:35:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20487 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 73CD0BD87C for ; Fri, 28 Jun 2024 21:36:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C9DAD62CA0; Fri, 28 Jun 2024 23:36:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Fv4lQhdm"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 73CC662C97 for ; Fri, 28 Jun 2024 23:35:59 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7F9E32C5 for ; Fri, 28 Jun 2024 23:35:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1719610534; bh=Fyt7eCbzpiE8cFJAPdaB6xFkpcdfQ+CgQcgioJGOLew=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Fv4lQhdmoK5o2Ydtbes4Blm8YHrlJqTwVZ1cvkOjFGQla8f/xk7MArJ6b+3I/Hl3e Edp5ben65f/cOopozmU6Ip+3VFqR0mNs0GdbmbXae7RDjDAvpwqk19wNB5lCyRQ+pL wd2dBW01Ec0jtXpyw4qfX7KgzUgEnKTkKLhAAdmo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 2/2] apps: common: dng_writer: Fix RAW10 and RAW12 packing on BE machines Date: Sat, 29 Jun 2024 00:35:35 +0300 Message-ID: <20240628213535.6906-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240628213535.6906-1-laurent.pinchart@ideasonboard.com> References: <20240628213535.6906-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The 16-bit padded raw 10 and raw 12 formats are stored in memory in little endian order, regardless of the machine's endianness. Read pixel data as uint8_t values and hardcode bit shifting to little endian to fix scanline packing. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Reviewed-by: Stefan Klug --- src/apps/common/dng_writer.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp index 50db5eb33c83..355433b08d68 100644 --- a/src/apps/common/dng_writer.cpp +++ b/src/apps/common/dng_writer.cpp @@ -139,29 +139,29 @@ void packScanlineRaw8(void *output, const void *input, unsigned int width) void packScanlineRaw10(void *output, const void *input, unsigned int width) { - const uint16_t *in = static_cast(input); + const uint8_t *in = static_cast(input); uint8_t *out = static_cast(output); for (unsigned int i = 0; i < width; i += 4) { - *out++ = (in[0] & 0x3fc) >> 2; - *out++ = (in[0] & 0x003) << 6 | (in[1] & 0x3f0) >> 4; - *out++ = (in[1] & 0x00f) << 4 | (in[2] & 0x3c0) >> 6; - *out++ = (in[2] & 0x03f) << 2 | (in[3] & 0x300) >> 8; - *out++ = (in[3] & 0x0ff); - in += 4; + *out++ = in[1] << 6 | in[0] >> 2; + *out++ = in[0] << 6 | (in[3] & 0x03) << 4 | in[2] >> 4; + *out++ = in[2] << 4 | (in[5] & 0x03) << 2 | in[4] >> 6; + *out++ = in[4] << 2 | (in[7] & 0x03) << 0; + *out++ = in[6]; + in += 8; } } void packScanlineRaw12(void *output, const void *input, unsigned int width) { - const uint16_t *in = static_cast(input); + const uint8_t *in = static_cast(input); uint8_t *out = static_cast(output); for (unsigned int i = 0; i < width; i += 2) { - *out++ = (in[0] & 0xff0) >> 4; - *out++ = (in[0] & 0x00f) << 4 | (in[1] & 0xf00) >> 8; - *out++ = (in[1] & 0x0ff); - in += 2; + *out++ = in[1] << 4 | in[0] >> 4; + *out++ = in[0] << 4 | (in[3] & 0x0f); + *out++ = in[2]; + in += 4; } }