[{"id":23933,"web_url":"https://patchwork.libcamera.org/comment/23933/","msgid":"<165788528223.2228597.17535617074926407862@Monstersaurus>","date":"2022-07-15T11:41:22","subject":"Re: [libcamera-devel] [PATCH v3] utils: ipu3-pack: Provide a 10-bit\n\tbayer packing utility","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Umang Jain via libcamera-devel (2022-07-13 13:15:34)\n> Provide a 10-bit bayer packing utility for the unpacked data produced\n> by ipu3-unpack.\n> \n>         Usage: ipu3-unpack input-file output-file\n> \n> The output-file can be \"-\" to pack the data to stdout.\n> \n> The output file generated by ipu3-pack can be directly fed to IMGU\n> for streaming.\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nSeems useful to keep hold of to me.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n> Changes in v3:\n> - Drop fflush() as stdout is per process not global\n> - Use sizeof () directly for bytes to read\n> - consistency of goto\n> ---\n>  utils/ipu3/ipu3-pack.c | 101 +++++++++++++++++++++++++++++++++++++++++\n>  utils/ipu3/meson.build |   1 +\n>  2 files changed, 102 insertions(+)\n>  create mode 100644 utils/ipu3/ipu3-pack.c\n> \n> diff --git a/utils/ipu3/ipu3-pack.c b/utils/ipu3/ipu3-pack.c\n> new file mode 100644\n> index 00000000..decbfc6c\n> --- /dev/null\n> +++ b/utils/ipu3/ipu3-pack.c\n> @@ -0,0 +1,101 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * ipu3-pack - Convert unpacked RAW10 Bayer data to the IPU3 packed Bayer formats\n> + *\n> + * Copyright 2022 Umang Jain <umang.jain@ideasonboard.com>\n> + */\n> +#define _GNU_SOURCE\n> +\n> +#include <errno.h>\n> +#include <fcntl.h>\n> +#include <stdint.h>\n> +#include <stdio.h>\n> +#include <string.h>\n> +#include <sys/stat.h>\n> +#include <sys/types.h>\n> +#include <unistd.h>\n> +\n> +static void usage(const char *argv0)\n> +{\n> +\n> +       printf(\"Usage: %s input-file output-file\\n\", basename(argv0));\n> +       printf(\"Convert unpacked RAW10 Bayer data to the IPU3 packed Bayer formats\\n\");\n> +       printf(\"If the output-file '-', output data will be written to standard output\\n\");\n> +}\n> +\n> +int main(int argc, char *argv[])\n> +{\n> +       int in_fd;\n> +       int out_fd;\n> +       int ret;\n> +\n> +       if (argc != 3) {\n> +               usage(argv[0]);\n> +               return 1;\n> +       }\n> +\n> +       in_fd = open(argv[1], O_RDONLY);\n> +       if (in_fd == -1) {\n> +               fprintf(stderr, \"Failed to open input file '%s': %s\\n\",\n> +                       argv[1], strerror(errno));\n> +               return 1;\n> +       }\n> +\n> +       if (strcmp(argv[2], \"-\") == 0) {\n> +               out_fd = STDOUT_FILENO;\n> +       } else {\n> +               out_fd = open(argv[2], O_WRONLY | O_TRUNC | O_CREAT, 0644);\n> +               if (out_fd == -1) {\n> +                       fprintf(stderr, \"Failed to open output file '%s': %s\\n\",\n> +                               argv[2], strerror(errno));\n> +                       close(in_fd);\n> +                       return 1;\n> +               }\n> +       }\n> +\n> +       while (1) {\n> +               uint16_t in_data[25];\n> +               uint8_t out_data[32];\n> +               unsigned int i;\n> +\n> +               ret = read(in_fd, in_data, sizeof(in_data));\n> +               if (ret < 0) {\n> +                       fprintf(stderr, \"Failed to read input data: %s\\n\",\n> +                               strerror(errno));\n> +                       goto done;\n> +               }\n> +\n> +               if ((unsigned)ret < sizeof(in_data)) {\n> +                       if (ret != 0)\n> +                               fprintf(stderr, \"%u bytes of stray data at end of input\\n\",\n> +                                       ret);\n> +                       goto done;\n> +               }\n> +\n> +               for (i = 0; i < 30; ++i) {\n> +                       unsigned int index = (i * 8) / 10;\n> +                       unsigned int msb_shift = (i * 8) % 10;\n> +                       unsigned int lsb_shift = 10 - msb_shift;\n> +\n> +                       out_data[i] = ((in_data[index] >> msb_shift) & 0xff)\n> +                                   | ((in_data[index+1] << lsb_shift) & 0xff);\n> +               }\n> +\n> +               out_data[30] = (in_data[24] >> 0) & 0xff;\n> +               out_data[31] = (in_data[24] >> 8) & 0x03;\n> +\n> +               ret = write(out_fd, out_data, sizeof(out_data));\n> +               if (ret < 0) {\n> +                       fprintf(stderr, \"Failed to write output data: %s\\n\",\n> +                               strerror(errno));\n> +                       goto done;\n> +               }\n> +       }\n> +\n> +done:\n> +       close(in_fd);\n> +       if (out_fd != STDOUT_FILENO)\n> +               close(out_fd);\n> +\n> +       return ret ? 1 : 0;\n> +}\n> diff --git a/utils/ipu3/meson.build b/utils/ipu3/meson.build\n> index 88049f58..c92cc658 100644\n> --- a/utils/ipu3/meson.build\n> +++ b/utils/ipu3/meson.build\n> @@ -1,3 +1,4 @@\n>  # SPDX-License-Identifier: CC0-1.0\n>  \n> +ipu3_pack = executable('ipu3-pack', 'ipu3-pack.c')\n>  ipu3_unpack = executable('ipu3-unpack', 'ipu3-unpack.c')\n> -- \n> 2.31.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 091BCBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Jul 2022 11:41:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B659A6330E;\n\tFri, 15 Jul 2022 13:41:26 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B14266330A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Jul 2022 13:41:24 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 67B8C993;\n\tFri, 15 Jul 2022 13:41:24 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1657885286;\n\tbh=UOCsp7UUp7js4bUo4FQ5YjV80XhdEPm2/ByoILB+TqE=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=c24QwPXMUT0D8rcaAUOQm2Y/+xD25oi4XPVweUmpM/ctPd7aBR/g9qL9+Rvc0jerZ\n\t28EsOhAemiaeRpMZ53RftyGS3uWq+vqgY8OY78ejSJZxtoN73qcAszYTVqqKm/UaLZ\n\tSgbZgtHxj8HI98/VWk+iolNQZxXpzaHdPfrH16Mb5qrKjlvi7tDuL4APVFejE9obTk\n\tBeQUE8ylpvlW0lrSaNNcbg2sB/JTFjByJdfYfagBjVnN4Ehyt3yn3Eufo07sD0V3TI\n\tTNk/Xg7K3NDnsshs6BaXwMa+6+z8wRnostHVhCl0r6HAWtiwMS9kdiLbFzeWwWnD1P\n\tkhgwRZ8ush4aQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1657885284;\n\tbh=UOCsp7UUp7js4bUo4FQ5YjV80XhdEPm2/ByoILB+TqE=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=abD32FewQ19fTdiiA1sj9vbhPPCs4hBbDZA/4hyPyxrcV/VWakeFC/lgYK13infdW\n\t8MzCJIpFrFFKIyyUKm1b6E3Hb+YM6in8fMnbQDbY9vaMh7vE41UZFYLWpGTEfsJhN5\n\tSBqPJtcBuzSUjoQF4wPoTofHcRxUmAEOKYqAghuI="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"abD32Few\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220713121534.115492-1-umang.jain@ideasonboard.com>","References":"<20220713121534.115492-1-umang.jain@ideasonboard.com>","To":"Umang Jain <umang.jain@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 15 Jul 2022 12:41:22 +0100","Message-ID":"<165788528223.2228597.17535617074926407862@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v3] utils: ipu3-pack: Provide a 10-bit\n\tbayer packing utility","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]