From patchwork Mon Jul 11 10:58:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16585 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 14CB4BE173 for ; Mon, 11 Jul 2022 10:58:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D354263315; Mon, 11 Jul 2022 12:58:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657537130; bh=jyujHf/RJ0uOUc7UDNNQASNZY6r1PBBnjMztMrilQAA=; 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=pK/LgbYWwI4L/XEFUBqATYCyx+6n2xDscRezV++cJpcMw0qo0Jz2cT1ZUbqlQHOfn 4BsUUGBkBtWmjDU8vLDv1vQLU91dSv8neRK6Wjc8s2lMwgzAL0AsHW78bN9H0iJj+b dc48x1pvkY2/vGiymqw1/jbLpwY9ejcRhCRdG2b2aCasFB/9dUnjSTvb2XuwYA2iXr uO57VYKt7gnMLjMqwS/1vdq+ORLqOzFeVIGcZ7pIInPpMZUPaej+nJLSOMFu/m/UuX 7zOHyzTlWvm++bgvNvMAq4L4w7EfTpYwQTLW6QC/HNOTn035oKuBIUsWoQfLK4X+ua YypBEmtzPyzdw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 59BB360401 for ; Mon, 11 Jul 2022 12:58:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BYlBltF2"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3f:b3fb:3712:29bf:7855:376e]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7DF86326; Mon, 11 Jul 2022 12:58:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1657537129; bh=jyujHf/RJ0uOUc7UDNNQASNZY6r1PBBnjMztMrilQAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BYlBltF297BhOLab62DCcxPGywZvuFNcODT86E/HySxVRvEJmqAA/2JCbXPlIdHmW xIbI7xpF1r4+XSjzniQQfcyarAVgqK94vDqUNePljTiByFlI4EMRqXB64Uu+muYPPz EG8yEsC6d8OQJwiuJnK1ts4Xqq+8r5mFjgwGBj0U= To: libcamera-devel@lists.libcamera.org Date: Mon, 11 Jul 2022 16:28:34 +0530 Message-Id: <20220711105835.48254-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220711105835.48254-1-umang.jain@ideasonboard.com> References: <20220711105835.48254-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 Reviewed-by: Kieran Bingham --- 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 Mon Jul 11 10:58:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16586 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 AD402BE173 for ; Mon, 11 Jul 2022 10:58:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 779E363314; Mon, 11 Jul 2022 12:58:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657537133; bh=MqTr0ZT2yko0/5UDDKB70+gs3nrXDoHwhy3adKqsLKU=; 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=JhB04gJCBn9KGsp3lM17UhBuxxotvq/RbaBmDPV6+6MwhUVktCeItFDCaOvmQvrRi yKfpduAoaXWUSRxIhsimn6GRM9auLJTo8W97D54QilyrrKL410cc6fYq7bMuzu3t4b 5v4p6iZpVWQbuMwk5v8sZwhexNVcEKY/ft+Jqylg8jS68j9U/K/UVg88NAAyv18P53 ob63k0JSmF2SKnjbaSf1krqi7uVKtyCZc6XbGweJbRIEQKxiYwR1J76HVpMBWeFUaW y5i06r4jQVlkLlllxTbfqq/Z24IuAAlCjXF06VAmqsAr3CVH3yMn/6iVy6PVsIuogZ g9QV2iwsBTipw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D7C1860401 for ; Mon, 11 Jul 2022 12:58:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bcq8ZABa"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3f:b3fb:3712:29bf:7855:376e]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 73B5D326; Mon, 11 Jul 2022 12:58:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1657537131; bh=MqTr0ZT2yko0/5UDDKB70+gs3nrXDoHwhy3adKqsLKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bcq8ZABay/6jAtJOxqL9ErSpeUQoa7qAEKBqEc7ROgaANH2mZSWB/+XJSxOOSYCU1 MsNBlgP2t7vHrV4EbqXQ9uSv5FFaFcHGJG9KNwp9UCm7/Jke6o8rf0DbELixTV2SYA g0H+k1Dq6XqVW5lIFBpS9T6Ucjb06YbdW2UimdEo= To: libcamera-devel@lists.libcamera.org Date: Mon, 11 Jul 2022 16:28:35 +0530 Message-Id: <20220711105835.48254-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220711105835.48254-1-umang.jain@ideasonboard.com> References: <20220711105835.48254-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. Usage: ipu3-unpack input-file output-file The output-file can be "-" to unpack the data to stdout. The output file generated by ipu3-pack can be directly fed to IMGU for streaming. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- utils/ipu3/ipu3-pack.c | 100 +++++++++++++++++++++++++++++++++++++++++ utils/ipu3/meson.build | 1 + 2 files changed, 101 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..328e3cd6 --- /dev/null +++ b/utils/ipu3/ipu3-pack.c @@ -0,0 +1,100 @@ +/* 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 + +static void usage(const char *argv0) +{ + printf("Usage:%s input-file output-file('-' to use stdout)\n", basename(argv0)); + printf("Convert unpacked RAW10 Bayer data to the IPU3 packed Bayer formats\n"); +} + +int main(int argc, char *argv[]) +{ + int in_fd; + int out_fd; + int ret; + + if (argc != 3) { + usage(argv[0]); + return 1; + } + + in_fd = open(argv[1], O_RDONLY); + if (in_fd == -1) { + fprintf(stderr, "Failed to open input file '%s': %s\n", + argv[1], strerror(errno)); + return 1; + } + + if (strcmp(argv[2], "-") == 0) { + out_fd = STDOUT_FILENO; + fflush(stdout); + } else { + out_fd = open(argv[2], O_WRONLY | O_TRUNC | O_CREAT, 0644); + if (out_fd == -1) { + fprintf(stderr, "Failed to open output file '%s': %s\n", + argv[2], strerror(errno)); + return 1; + } + } + + while (1) { + uint16_t in_data[25]; + uint8_t out_data[32]; + unsigned int i; + + int bytes_to_read = sizeof(in_data); + ret = read(in_fd, in_data, bytes_to_read); + if (ret == -1) { + fprintf(stderr, "Failed to read input data: %s\n", + strerror(errno)); + goto done; + } + + if (ret < bytes_to_read) { + if (ret != 0) + fprintf(stderr, "%u bytes of stray data at end of input\n", + ret); + break; + } + + for (i = 0; i < 30; ++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); + } + + out_data[30] = (in_data[24] >> 0) & 0xff; + out_data[31] = (in_data[24] >> 8) & 0x03; + + ret = write(out_fd, out_data, sizeof(out_data)); + if (ret < 0) { + fprintf(stderr, "Failed to write output data: %s\n", + strerror(errno)); + goto done; + } + } + +done: + close(in_fd); + if (out_fd != STDOUT_FILENO) + 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')