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; } }