From patchwork Fri Jul 8 22:28:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16578 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 8C0ABBD1F1 for ; Fri, 8 Jul 2022 22:28:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4B0B46330F; Sat, 9 Jul 2022 00:28:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657319330; bh=R69h2pZ7E6Y72d0ZUbsK2I205BTIRzi3xMn1VzMIeo4=; 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=fMScDuysSK2IO6MPbSoSXGf7+SQxopW2mpO0Aecy64mPCUeJJmMhIqB/Nydt+eOPV ckxHWukZXg/Rv6e/tLfFS/op+A2+936F9e90CITySGgt44Oahu84l5nQQMnBtGQqpD NaylG4hAxd9TQMxEHQb6uIMSrzpfdq5zzhnws2KLz7c/0hpsG7k/EAv9pnGUgzNVrX Wfl3v4G960dGJAszjFH6L1qzyTs2k/7uJ4tM1RrsSF0kIoEoW5rClnSskxJBLAnSfI /XuEagq9KSK1XvG/h+8BPZc8gIC6a1tkRN/yFoeahR1GZwYPEA15EP+bAulmW03fGE rqUrygZ60ogaA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 56D126330F for ; Sat, 9 Jul 2022 00:28:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JXSLh6z/"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3f:82b9:3739:ca3a:12d7:3721]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 24E8447C; Sat, 9 Jul 2022 00:28:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1657319328; bh=R69h2pZ7E6Y72d0ZUbsK2I205BTIRzi3xMn1VzMIeo4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JXSLh6z/GFqDK30yN4IjeSHuoAPe66FY3zNf98S2YZruNLb4OGxt5M/DsJoMbXtR8 Qxr+16lWUl98CFSnZERMugaYTELRavPoFcoXWSFe8eHdOIptPlP70VmB9zosMJGZVg U/tHmHTpmWdb5BIytBAaxzAGpzWVHBSwxnRrJKzY= To: libcamera-devel@lists.libcamera.org Date: Sat, 9 Jul 2022 03:58:37 +0530 Message-Id: <20220708222838.370187-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220708222838.370187-1-umang.jain@ideasonboard.com> References: <20220708222838.370187-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] utils: ipu3-unpack: Fix error string 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: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- utils/ipu3/ipu3-unpack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/ipu3/ipu3-unpack.c b/utils/ipu3/ipu3-unpack.c index 2dce1038..9d2c1200 100644 --- a/utils/ipu3/ipu3-unpack.c +++ b/utils/ipu3/ipu3-unpack.c @@ -79,7 +79,7 @@ int main(int argc, char *argv[]) ret = write(out_fd, out_data, 50); if (ret < -1) { - fprintf(stderr, "Failed to read input data: %s\n", + fprintf(stderr, "Failed to write output data: %s\n", strerror(errno)); goto done; } From patchwork Fri Jul 8 22:28:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16579 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 0EFD3BD1F1 for ; Fri, 8 Jul 2022 22:28:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BBE1663313; Sat, 9 Jul 2022 00:28:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657319337; bh=oa0MoHQXJ+F67fOjiqepqf8fX5pISTbSEvBJ0vzHlUQ=; 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=mNau+Xr0lVC/pEmTfZeD5CKrsBewmxjwp9unGYLKGUHYwpuTX0VsQwK7NcEW6XPiV sjab2x3HqYEztvNZGU3BsFzc+toX/lXxwvOGE7Sg07z5IO1kF838sRSP9oOcrt+dfC 3Xy7nHfurbZiCa3Ycdt6ovuZLbAKDjT+p7VaQ8Z7TGhFdXNuqPvi8h1Tbfn9X7UD/V IenrEwhNQv6sJpKoTX/8Lt8GsGvcwgks/4IbQ1bpVJtxFRmy+P+wU0BbOFFeEtBB7n RMSpq8L59QeGhcvIkXnby/CJIC1WoFUL3pqqbJq2aEO14pv6ozF7nJhlcidM3lkKZR JG95BjC9vPRKA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5C6A56330E for ; Sat, 9 Jul 2022 00:28:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="CeY2FPUp"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3f:82b9:3739:ca3a:12d7:3721]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 53BE647C; Sat, 9 Jul 2022 00:28:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1657319336; bh=oa0MoHQXJ+F67fOjiqepqf8fX5pISTbSEvBJ0vzHlUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CeY2FPUpOoqF7sS/Z20mYBCEPm3tw5CigPpWF9evSXRBJm/zF3OpzMQO9pxmTY/Vw CmN6/eMOJmLwXf3eYsQfA7RB2Pm4G9HmMz2MdzXMWgAHshSVvffYHDIuKB8hSyKRLN m5gM/gHC+Jt09PCM/nJD37LZagAMBHbjVgO5TTHk= To: libcamera-devel@lists.libcamera.org Date: Sat, 9 Jul 2022 03:58:38 +0530 Message-Id: <20220708222838.370187-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220708222838.370187-1-umang.jain@ideasonboard.com> References: <20220708222838.370187-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] utils: ipu3-pack: Provide a 10-bit bayer packing utility 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: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Provide a 10-bit bayer packing utility for the unpacked data produced by ipu3-unpack. Single or multiple input unpacked files can be packed and concatenated together in a single output file. Use-case where this is useful is streaming IMGU with different test patterns on each frame. The output file generated by ipu3-pack can be directly fed to IMGU. Signed-off-by: Umang Jain --- utils/ipu3/ipu3-pack.c | 129 +++++++++++++++++++++++++++++++++++++++++ utils/ipu3/meson.build | 1 + 2 files changed, 130 insertions(+) create mode 100644 utils/ipu3/ipu3-pack.c diff --git a/utils/ipu3/ipu3-pack.c b/utils/ipu3/ipu3-pack.c new file mode 100644 index 00000000..48193f74 --- /dev/null +++ b/utils/ipu3/ipu3-pack.c @@ -0,0 +1,129 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * ipu3-pack - Pack IPU3 raw Bayer format to 10-bit Bayer + * + * Copyright 2022 Umang Jain + */ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void usage(const char *argv0) +{ + printf("Usage: %s input-file(s) -o output-file\n", basename(argv0)); + printf("Pack the IPU3 raw Bayer format to 10-bit Bayer\n"); +} + +int packInputFile(int in_fd, int out_fd) +{ + int ret = 0; + + while (1) { + uint16_t in_data[25]; + uint8_t out_data[32]; + unsigned int i; + + ret = read(in_fd, in_data, 50); + if (ret == -1) { + fprintf(stderr, "Failed to read input data: %s\n", + strerror(errno)); + break; + } + + if (ret < 50) { + if (ret != 0) + fprintf(stderr, "%u bytes of stray data at end of input\n", + ret); + break; + } + + for (i = 0; i < 32; ++i) { + unsigned int index = (i * 8) / 10; + unsigned int msb_shift = (i * 8) % 10; + unsigned int lsb_shift = 10 - msb_shift; + + out_data[i] = ((in_data[index] >> msb_shift) & 0xff) + | ((in_data[index+1] << lsb_shift) & 0xff); + } + + /* 6 MSB are padding on the 32nd byte. */ + out_data[31] = out_data[31] & 0x03; + + ret = write(out_fd, out_data, 32); + if (ret < -1) { + fprintf(stderr, "Failed to write output data: %s\n", + strerror(errno)); + return ret; + } + } + + return ret; +} +int main(int argc, char *argv[]) +{ + int input_files = argc - 3; + int in_fds[input_files]; + int out_fd = -1; + int j = 1; + int ret; + bool oFlag = false; + + if (argc < 4) { + usage(argv[0]); + return 1; + } + + while (j < argc) { + if (strcmp(argv[j], "-o") == 0) { + oFlag = true; + break; + } + + int fd = open(argv[j], O_RDONLY); + if (fd == -1) { + fprintf(stderr, "Failed to open input file '%s': %s\n", + argv[j], strerror(errno)); + goto done; + } + + in_fds[j - 1] = fd; + j++; + } + + if (!oFlag) { + fprintf(stderr, "Missing option '-o' for output file\n"); + usage(argv[0]); + goto done; + } + + out_fd = open(argv[++j], O_WRONLY | O_TRUNC | O_CREAT, 0644); + if (out_fd == -1) { + fprintf(stderr, "Failed to open output file '%s': %s\n", + argv[j], strerror(errno)); + goto done; + } + + for (j = 0; j < input_files; j++) { + ret = packInputFile(in_fds[j], out_fd); + if (ret < 0) { + fprintf(stderr, "Error packing input file '%s'\n", + argv[j + 1]); + goto done; + } + } + +done: + for (j = 0; j < input_files; j++) + close(in_fds[j]); + close(out_fd); + + return ret ? 1 : 0; +} diff --git a/utils/ipu3/meson.build b/utils/ipu3/meson.build index 88049f58..c92cc658 100644 --- a/utils/ipu3/meson.build +++ b/utils/ipu3/meson.build @@ -1,3 +1,4 @@ # SPDX-License-Identifier: CC0-1.0 +ipu3_pack = executable('ipu3-pack', 'ipu3-pack.c') ipu3_unpack = executable('ipu3-unpack', 'ipu3-unpack.c')