From patchwork Mon Jul 25 19:23:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16771 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 1FEB6BE173 for ; Mon, 25 Jul 2022 19:23:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D788263319; Mon, 25 Jul 2022 21:23:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658777016; bh=yXczEyAmHVtLaX0+gd1hlgvfbGWE9Ruf9KDIPNWdFbw=; 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=P5BJi6PE80lFfhsqOI6IdfYkr+FMmVrxmftsk6QOKCiDJo5Ff3GHS7sdws27LuYBa Qw49SQ8wtHUmY9czDVT3hhIL6XrRQ7MI5R0G474ICdgAoYCZmiYrds8yfz2NnlzBtl e1JR95KXM326yQGBCyTHgIeh35yCyHHmryGELJGKzhuNnZc95J7wUn/xosW7PtXitN CSaS2fE2SkrbKrtXk9D9zd+84/JF+vhnkOiv10nJvlSmDYR6K0kFyjSKUgrlO2fy40 OEE09c7NeMFz1T0LHtFvtdKAlgqnh3Oku7qB2Rjt1capgKzgMqaD5FtxUynajP3dL7 7cOXnNDmFX0Bg== 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 823D96330A for ; Mon, 25 Jul 2022 21:23:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NF5b7Qi5"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3e:f7a:bc8f:12ed:b45f:c35d]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7C5DF6D1; Mon, 25 Jul 2022 21:23:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1658777013; bh=yXczEyAmHVtLaX0+gd1hlgvfbGWE9Ruf9KDIPNWdFbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NF5b7Qi5HRObIgqpEcpjp7Ags4BiRNmZfRRN8EbFK9GUJmASm+ieMoyYyt65M0F7C LfVwWh9f/A5pltFVqO0gZAwZbvFxaO7ISlW6xv0mKOKl3rTsYPOwJdC2ON9+D4W2k3 5vtup9wqZRg+erk7GUgW1t+ckj7n1MYNZsqQOk/E= To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Jul 2022 00:53:16 +0530 Message-Id: <20220725192317.99026-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220725192317.99026-1-umang.jain@ideasonboard.com> References: <20220725192317.99026-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 2/3] utils: ipu3: Executable helper to read statistics 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" Usage: ipu3-read-stats input-file output-file [Currently only reads R,G,B averages out of AWB] To be extended to dump more meaningful stats. Signed-off-by: Umang Jain --- utils/ipu3/ipu3-read-stats.c | 110 +++++++++++++++++++++++++++++++++++ utils/ipu3/meson.build | 2 + 2 files changed, 112 insertions(+) create mode 100644 utils/ipu3/ipu3-read-stats.c diff --git a/utils/ipu3/ipu3-read-stats.c b/utils/ipu3/ipu3-read-stats.c new file mode 100644 index 00000000..c400d294 --- /dev/null +++ b/utils/ipu3/ipu3-read-stats.c @@ -0,0 +1,110 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * ipu3-read-stats - Dump IPU3 statistics + * + * Copyright 2022 Umang Jain + */ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include + +#include "../../include/linux/intel-ipu3.h" + +static void usage(const char *argv0) +{ + printf("Usage: %s input-file output-file\n", basename(argv0)); + printf("Dump IPU3 statistics\n"); + printf("If the output-file '-', output data will be written to standard output\n"); +} + +int main(int argc, char *argv[]) +{ + int in_fd; + FILE *fout; + 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 statistics file '%s': %s\n", + argv[1], strerror(errno)); + return 1; + } + + if (strcmp(argv[2], "-") == 0) { + fout = stdout; + } else { + fout = fopen(argv[2], "w"); + if (!fout) { + fprintf(stderr, "Failed to open output file '%s': %s\n", + argv[2], strerror(errno)); + close(in_fd); + return 1; + } + } + + int frame = 0; + struct ipu3_uapi_stats_3a *stats = (struct ipu3_uapi_stats_3a *) malloc(sizeof(struct ipu3_uapi_stats_3a)); + + while (1) { + ret = read(in_fd, stats, sizeof(struct ipu3_uapi_stats_3a)); + if (ret < 0) { + fprintf(stderr, "Failed to read stats data: %s\n", + strerror(errno)); + goto done; + } + + if ((unsigned)ret < sizeof(struct ipu3_uapi_stats_3a)) { + if (ret != 0) + fprintf(stderr, "%u bytes of stray data at end of input\n", + ret); + goto done; + } + + /* ================ Dump AE stats ================ */ + + + /* ================ Dump AWB stats ================ */ + + /* Sum the per-channel averages */ + unsigned int stride_ = 56; /* \todo find dynamic way to calculate grid stride */ + double redSum = 0, greenSum = 0, blueSum = 0; + struct ipu3_uapi_grid_config grid = stats->stats_4a_config.awb_config.grid; + for (unsigned int cellY = 0; cellY < grid.height; cellY++) { + for (unsigned int cellX = 0; cellX < grid.width; cellX++) { + uint32_t cellPosition = cellY * stride_ + cellX; + + const struct ipu3_uapi_awb_set_item *cell = + (const struct ipu3_uapi_awb_set_item *)( + &stats->awb_raw_buffer.meta_data[cellPosition] + ); + const uint8_t G_avg = (cell->Gr_avg + cell->Gb_avg) / 2; + + redSum += cell->R_avg; + greenSum += G_avg; + blueSum += cell->B_avg; + } + } + + fprintf(fout, "Frame: %d, redSum: %.1f, greenSum: %.1f, blueSum: %.1f\n", + frame, redSum, greenSum, blueSum); + frame++; + } + +done: + free(stats); + close(in_fd); + fclose(fout); + + return ret ? 1 : 0; +} diff --git a/utils/ipu3/meson.build b/utils/ipu3/meson.build index c92cc658..88fc2a1b 100644 --- a/utils/ipu3/meson.build +++ b/utils/ipu3/meson.build @@ -2,3 +2,5 @@ ipu3_pack = executable('ipu3-pack', 'ipu3-pack.c') ipu3_unpack = executable('ipu3-unpack', 'ipu3-unpack.c') + +ipu3_read_stats = executable('ipu3-read-stats', 'ipu3-read-stats.c')