[libcamera-devel,5/5] utils: ipu3: dump lens shading params
diff mbox series

Message ID 20220630101702.45781-6-jeanmichel.hautbois@ideasonboard.com
State New
Headers show
Series
  • [libcamera-devel,1/5] utils: ipu3: Introduce a parameters dump tool
Related show

Commit Message

Jean-Michel Hautbois June 30, 2022, 10:17 a.m. UTC
The sensor lens shading can be corrected, and this is controlled with
the ipu3_uapi_shd_config structure. Display the configuration followed
by the look-up tables for each of the 4 channels.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
---
 utils/ipu3/ipu3-dump-params.c | 98 +++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)

Patch
diff mbox series

diff --git a/utils/ipu3/ipu3-dump-params.c b/utils/ipu3/ipu3-dump-params.c
index e34a7e53..c8a4ae2f 100644
--- a/utils/ipu3/ipu3-dump-params.c
+++ b/utils/ipu3/ipu3-dump-params.c
@@ -75,6 +75,90 @@  static void displayGD(struct ipu3_uapi_bnr_static_config_green_disparity *gd)
 		gd->gd_central_weight);
 }
 
+static void displayShdGrid(struct ipu3_uapi_shd_grid_config *grid, const char *gridName)
+{
+	fprintf(stderr, "Configured %s grid [%d,%d]x[%d,%d] starting at (%d, %d)\n",
+		gridName,
+		grid->width,
+		grid->block_width_log2,
+		grid->height,
+		grid->block_height_log2,
+		grid->x_start,
+		grid->y_start & ~IPU3_UAPI_GRID_Y_START_EN);
+	fprintf(stderr, "Grid size is (%d x %d)\n",
+		grid->width << grid->block_width_log2,
+		grid->height << grid->block_height_log2);
+}
+
+static void displayShdConfig(struct ipu3_uapi_params *params)
+{
+	struct ipu3_uapi_shd_general_config shdConfig = params->acc_param.shd.shd.general;
+	fprintf(stderr, "Shading general config\n");
+	fprintf(stderr, "Vertical offset (init_set_vrt_offst_ul): %u\n", shdConfig.init_set_vrt_offst_ul);
+	fprintf(stderr, "Shd flag (shd_enable): %s\n", shdConfig.shd_enable ? "enabled" : "disabled");
+	fprintf(stderr, "Gain factor (gain_factor): %u\n", shdConfig.gain_factor);
+}
+
+static void displayShdLutGr(struct ipu3_uapi_params *params)
+{
+	struct ipu3_uapi_shd_lut shdLut = params->acc_param.shd.shd_lut;
+	for (unsigned int height = 0; height < params->acc_param.shd.shd.grid.height / 2; height++) {
+		fprintf(stderr, "\n");
+		for (unsigned int width = 0; width < params->acc_param.shd.shd.grid.width; width++) {
+			fprintf(stderr, "%d,", shdLut.sets[height].r_and_gr[width].gr);
+		}
+		fprintf(stderr, "\n");
+		for (unsigned int width = 0; width < params->acc_param.shd.shd.grid.width; width++) {
+			fprintf(stderr, "%d,", shdLut.sets[height].r_and_gr[params->acc_param.shd.shd.grid.width + width].gr);
+		}
+	}
+}
+
+static void displayShdLutR(struct ipu3_uapi_params *params)
+{
+	struct ipu3_uapi_shd_lut shdLut = params->acc_param.shd.shd_lut;
+	for (unsigned int height = 0; height < params->acc_param.shd.shd.grid.height / 2; height++) {
+		fprintf(stderr, "\n");
+		for (unsigned int width = 0; width < params->acc_param.shd.shd.grid.width; width++) {
+			fprintf(stderr, "%d,", shdLut.sets[height].r_and_gr[width].r);
+		}
+		fprintf(stderr, "\n");
+		for (unsigned int width = 0; width < params->acc_param.shd.shd.grid.width; width++) {
+			fprintf(stderr, "%d,", shdLut.sets[height].r_and_gr[params->acc_param.shd.shd.grid.width + width].r);
+		}
+	}
+}
+
+static void displayShdLutGb(struct ipu3_uapi_params *params)
+{
+	struct ipu3_uapi_shd_lut shdLut = params->acc_param.shd.shd_lut;
+	for (unsigned int height = 0; height < params->acc_param.shd.shd.grid.height / 2; height++) {
+		fprintf(stderr, "\n");
+		for (unsigned int width = 0; width < params->acc_param.shd.shd.grid.width; width++) {
+			fprintf(stderr, "%d,", shdLut.sets[height].gb_and_b[width].gb);
+		}
+		fprintf(stderr, "\n");
+		for (unsigned int width = 0; width < params->acc_param.shd.shd.grid.width; width++) {
+			fprintf(stderr, "%d,", shdLut.sets[height].gb_and_b[params->acc_param.shd.shd.grid.width + width].gb);
+		}
+	}
+}
+
+static void displayShdLutB(struct ipu3_uapi_params *params)
+{
+	struct ipu3_uapi_shd_lut shdLut = params->acc_param.shd.shd_lut;
+	for (unsigned int height = 0; height < params->acc_param.shd.shd.grid.height / 2; height++) {
+		fprintf(stderr, "\n");
+		for (unsigned int width = 0; width < params->acc_param.shd.shd.grid.width; width++) {
+			fprintf(stderr, "%d,", shdLut.sets[height].gb_and_b[width].b);
+		}
+		fprintf(stderr, "\n");
+		for (unsigned int width = 0; width < params->acc_param.shd.shd.grid.width; width++) {
+			fprintf(stderr, "%d,", shdLut.sets[height].gb_and_b[params->acc_param.shd.shd.grid.width + width].b);
+		}
+	}
+}
+
 int main(int argc, char *argv[])
 {
 	int in_fd;
@@ -118,6 +202,20 @@  start:
 		displayGD(&params.acc_param.green_disparity);
 	}
 
+	if (params.use.acc_shd) {
+		fprintf(stderr, "\n**** Lens shading parameters ****\n");
+		displayShdGrid(&params.acc_param.shd.shd.grid, "shd");
+		displayShdConfig(&params);
+		fprintf(stderr, "\n** Lens shading LUT for Gr **");
+		displayShdLutGr(&params);
+		fprintf(stderr, "\n** Lens shading LUT for R **");
+		displayShdLutR(&params);
+		fprintf(stderr, "\n** Lens shading LUT for Gb **");
+		displayShdLutGb(&params);
+		fprintf(stderr, "\n** Lens shading LUT for B **");
+		displayShdLutB(&params);
+	}
+
 	close(in_fd);
 
 	return ret ? 1 : 0;