Skip to contentSkip to conversation

New sharpness tool

PATCH In review Swati Sharma 3 participants 11 messages Jan 10, 2025 – Apr 8, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover New sharpness tool

New sharpness tool is introduced to validate basic functionality of content adaptive sharpness filter supported with intel LNL platform.

Tool has following 2 main functions:
1. input user defined strength value (1-255)
2. input incr/decr factor for setting strength and use up/down arrow keys to increase/decrease strength during run time

Naladala Ramanaidu (5):
data: Move PNG images to new data directory runner/settings: Constify absolute_path parameter runner/settings: Add function to set IGT_RUNNER_DATA environment
variable
lib/igt_core: Enhance __igt_fopen_data to support additional
directories
meson: Add sharpness tool

Swati Sharma (3):
lib/igt_kms: Add "sharpness strength" as crtc property
tools: Add new sharpness tool
data: Add image

 {tests => data}/1080p-left.png  | Bin
 {tests => data}/1080p-right.png | Bin
 data/default_hd_image.png       | Bin 0 -> 657520 bytes
 data/meson.build                |  12 ++
 {tests => data}/pass.png        | Bin
 lib/igt_core.c                  |  31 ++-
 lib/igt_core.h                  |   6 +-
 lib/igt_kms.c                   |   4 +
 lib/igt_kms.h                   |   1 +
 lib/meson.build                 |   1 +
 meson.build                     |   2 +
 runner/runner.c                 |   8 +
 runner/settings.c               |  11 +-
 runner/settings.h               |   3 +-
 tests/meson.build               |   6 -
 tools/intel_sharpness_tool.c    | 370 ++++++++++++++++++++++++++++++++
 tools/meson.build               |  11 +
 17 files changed, 439 insertions(+), 27 deletions(-)
 rename {tests => data}/1080p-left.png (100%)
 rename {tests => data}/1080p-right.png (100%)
 create mode 100644 data/default_hd_image.png
 create mode 100644 data/meson.build
 rename {tests => data}/pass.png (100%)
 create mode 100644 tools/intel_sharpness_tool.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/8 data: Move PNG images to new data directory

From: Naladala Ramanaidu <[email protected]>

Placing png images inside "tests/" directory seems wrong, as these are not source files. These images should ideally be in a directory with other non-exec files, so creating a new "data/" directory to store such non-exec files.

v2: Update commit message subject (Kamil)

---
 {tests => data}/1080p-left.png  | Bin
 {tests => data}/1080p-right.png | Bin
 data/meson.build                |  11 +++++++++++
 {tests => data}/pass.png        | Bin
 lib/meson.build                 |   1 +
 meson.build                     |   2 ++
 tests/meson.build               |   6 ------
 7 files changed, 14 insertions(+), 6 deletions(-)
 rename {tests => data}/1080p-left.png (100%)
 rename {tests => data}/1080p-right.png (100%)
 create mode 100644 data/meson.build
 rename {tests => data}/pass.png (100%)
data/1080p-left.png renamed from tests/1080p-left.png +0 -0
similarity index 100%
rename from tests/1080p-left.png
rename to data/1080p-left.png
data/1080p-right.png renamed from tests/1080p-right.png +0 -0
similarity index 100%
rename from tests/1080p-right.png
rename to data/1080p-right.png
data/meson.build new file +11 -0
new file mode 100644
index 000000000..9490d20ac
@@ -0,0 +1,11 @@
+image_files = [
+  '1080p-left.png',
+  '1080p-right.png',
+  'pass.png',
+]
+
+foreach img : image_files
+      configure_file(output:img, input:img, copy:true)
+endforeach
+
+install_data(sources : image_files, install_dir : datadir)
data/pass.png renamed from tests/pass.png +0 -0
similarity index 100%
rename from tests/pass.png
rename to data/pass.png
lib/meson.build +1 -0
index 1704ed1e1..afa09ae02 100644
@@ -240,6 +240,7 @@ foreach f: lib_sources
 	    '-DIGT_DATADIR="@0@"'.format(join_paths(prefix, datadir)),
 	    '-DIGT_SRCDIR="@0@"'.format(srcdir),
 	    '-DIGT_LOG_DOMAIN="@0@"'.format(f.split('.')[0]),
+	    '-DIGT_IMGDIR="@0@"'.format(imgdir),
 	])
 
     lib_intermediates += lib
meson.build +2 -0
index 5eda2d582..2c2c304b1 100644
@@ -293,6 +293,7 @@ vmwgfxdir = join_paths(libexecdir, 'vmwgfx')
 mandir = get_option('mandir')
 pkgconfigdir = join_paths(libdir, 'pkgconfig')
 python3 = find_program('python3', required : true)
+imgdir = join_paths(build_root, 'data')
 
 if get_option('use_rpath')
 	# Set up runpath for the test executables towards libigt.so.
@@ -388,6 +389,7 @@ endif
 subdir('overlay')
 subdir('man')
 subdir('docs')
+subdir('data')
 
 message('Build options')
 message('=============')
tests/meson.build +0 -6
index 89bba6454..a8d875d36 100644
@@ -510,11 +510,5 @@ if not meson.is_cross_build()
 			output : 'gem_stress.testlist')
 endif
 
-image_files = [
-  '1080p-left.png',
-  '1080p-right.png',
-  'pass.png',
-]
-install_data(sources : image_files, install_dir : datadir)
 
 subdir('intel-ci')
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/8 runner/settings: Constify absolute_path parameter

In reply to Swati Sharma

From: Naladala Ramanaidu <[email protected]>

Modified absolute_path to use const char* for input, updating the corresponding declaration. This ensures the input path remains unmodified, enhancing code safety and clarity.

v2: Update commit subject. (kmail)

---
 runner/settings.c | 2 +-
 runner/settings.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
runner/settings.c +1 -1
index 92fd42ea6..bea0c3059 100644
@@ -567,7 +567,7 @@ static char *_basename(const char *path)
 	return tmpname;
 }
 
-char *absolute_path(char *path)
+char *absolute_path(const char *path)
 {
 	char *result = NULL;
 	char *base, *dir;
runner/settings.h +1 -1
index f69f09778..7e6cd11e2 100644
@@ -136,7 +136,7 @@ bool parse_options(int argc, char **argv,
 bool validate_settings(struct settings *settings);
 
 /* TODO: Better place for this */
-char *absolute_path(char *path);
+char *absolute_path(const char *path);
 
 /**
  * serialize_settings:
Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/8 runner/settings: Add function to set IGT_RUNNER_DATA environment variable

In reply to Swati Sharma

From: Naladala Ramanaidu <[email protected]>

Introduced set_runner_datadir() to set the IGT_RUNNER_DATA environment variable. This function uses absolute_path() to convert the relative path "../share/igt-gpu-tools" to an absolute path. Update the runner/runner code to call set_runner_datadir() and handle errors appropriately.

v2: Fix review comments. (Kamil)

---
 runner/runner.c   | 8 ++++++++
 runner/settings.c | 9 +++++++++
 runner/settings.h | 1 +
 3 files changed, 18 insertions(+)
runner/runner.c +8 -0
index 4855ad641..950eb5662 100644
@@ -12,8 +12,13 @@ int main(int argc, char **argv)
 	struct job_list job_list;
 	struct execute_state state;
 	int exitcode = 0;
+	int data_flag = 0;
 
 	init_settings(&settings);
+	data_flag = set_runner_datadir();
+	if (data_flag)
+		fprintf(stderr, "Data dir path not set\n");
+
 	init_job_list(&job_list);
 
 	if (!parse_options(argc, argv, &settings)) {
@@ -49,6 +54,9 @@ int main(int argc, char **argv)
 		exitcode = 1;
 	}
 
+	if (!data_flag)
+		unsetenv("IGT_RUNNER_DATA");
+
 	printf("Done.\n");
 	return exitcode;
 }
runner/settings.c +9 -0
index bea0c3059..c8220be32 100644
@@ -589,6 +589,15 @@ char *absolute_path(const char *path)
 	return result;
 }
 
+int set_runner_datadir(void)
+{
+	const char *datapath = "../share/igt-gpu-tools";
+	char *abpath;
+
+	abpath = absolute_path(datapath);
+	return setenv("IGT_RUNNER_DATA", abpath, 1);
+}
+
 static char *bin_path(char *fname)
 {
 	char *path, *p;
runner/settings.h +1 -0
index 7e6cd11e2..5926817b6 100644
@@ -150,5 +150,6 @@ bool serialize_settings(struct settings *settings);
 
 bool read_settings_from_file(struct settings *settings, FILE* f);
 bool read_settings_from_dir(struct settings *settings, int dirfd);
+int set_runner_datadir(void);
 
 #endif
Signature · 1 line
2.25.1
#4 lore raw

PATCH 4/8 lib/igt_core: Enhance __igt_fopen_data to support additional directories

In reply to Swati Sharma

From: Naladala Ramanaidu <[email protected]>

Add an additional parameter for the image directory. Refactor the function to use an array of directories to iterate through, reducing redundancy. Include a check for the "IGT_RUNNER_DATA" environment variable.

v2: Fix review comments. (Santhosh, Kamil)

---
 lib/igt_core.c | 31 +++++++++++++++----------------
 lib/igt_core.h |  6 +++---
 2 files changed, 18 insertions(+), 19 deletions(-)
lib/igt_core.c +15 -16
index 407f7b551..cd43d276a 100644
@@ -3305,27 +3305,26 @@ void igt_reset_timeout(void)
 	igt_set_timeout(0, NULL);
 }
 
-FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
-		       const char* filename)
+FILE *__igt_fopen_data(const char *igt_srcdir, const char *igt_datadir,
+		       const char *igt_imgdir, const char *filename)
 {
 	char path[PATH_MAX];
 	FILE *fp;
-
-	snprintf(path, sizeof(path), "%s/%s", igt_datadir, filename);
-	fp = fopen(path, "r");
-	if (!fp) {
-		snprintf(path, sizeof(path), "%s/%s", igt_srcdir, filename);
-		fp = fopen(path, "r");
-	}
-	if (!fp) {
-		snprintf(path, sizeof(path), "./%s", filename);
-		fp = fopen(path, "r");
+	size_t i;
+	const char *dirs[] = {igt_datadir, igt_srcdir, igt_imgdir,
+				     getenv("IGT_RUNNER_DATA"), "./data"};
+
+	for (i = 0; i < ARRAY_SIZE(dirs); i++) {
+		if (dirs[i]) {
+			snprintf(path, sizeof(path), "%s/%s", dirs[i], filename);
+			fp = fopen(path, "r");
+			if (fp)
+				return fp;
+		}
 	}
 
-	if (!fp)
-		igt_critical("Could not open data file \"%s\": %m\n", filename);
-
-	return fp;
+	igt_critical("Could not open data file \"%s\": %m\n", filename);
+	return NULL;
 }
 
 static void log_output(int *fd, enum igt_log_level level)
lib/igt_core.h +3 -3
index f0ba1a381..05134a104 100644
@@ -1456,8 +1456,8 @@ static inline uint32_t igt_seconds_elapsed(struct timespec *start)
 
 void igt_reset_timeout(void);
 
-FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
-		       const char* filename);
+FILE *__igt_fopen_data(const char *igt_srcdir, const char *igt_datadir,
+		       const char *igt_imgdir, const char *filename);
 /**
  * igt_fopen_data:
  * @filename: filename to open.
@@ -1466,7 +1466,7 @@ FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
  * then from build directory, and finally from current directory.
  */
 #define igt_fopen_data(filename) \
-	__igt_fopen_data(IGT_SRCDIR, IGT_DATADIR, filename)
+	__igt_fopen_data(IGT_SRCDIR, IGT_DATADIR, IGT_IMGDIR, filename)
 
 int igt_system(const char *command);
 int igt_system_quiet(const char *command);
Signature · 1 line
2.25.1
#5 lore raw

PATCH 5/8 lib/igt_kms: Add "sharpness strength" as crtc property

In reply to Swati Sharma

Add "sharpness strength" as crtc property.

v2: Replace SHARPENESS_STRENGTH with SHARPNESS_STRENGTH. (Nemesa)
v3: Rebase
v4: Rebase

---
 lib/igt_kms.c | 4 ++++
 lib/igt_kms.h | 1 +
 2 files changed, 5 insertions(+)
lib/igt_kms.c +4 -0
index 95e3059f7..d2f8bd16d 100644
@@ -717,6 +717,7 @@ const char * const igt_crtc_prop_names[IGT_NUM_CRTC_PROPS] = {
 	[IGT_CRTC_HISTOGRAM] = "HISTOGRAM_ENABLE",
 	[IGT_CRTC_GLOBAL_HISTOGRAM] = "HISTOGRAM_DATA",
 	[IGT_CRTC_GLOBAL_HIST_PIXEL_FACTOR] = "HISTOGRAM_IET",
+	[IGT_CRTC_SHARPNESS_STRENGTH] = "SHARPNESS_STRENGTH",
 };
 
 const char * const igt_connector_prop_names[IGT_NUM_CONNECTOR_PROPS] = {
@@ -2621,6 +2622,9 @@ static void igt_pipe_reset(igt_pipe_t *pipe)
 	if (igt_pipe_obj_has_prop(pipe, IGT_CRTC_HISTOGRAM))
 		igt_pipe_obj_set_prop_value(pipe, IGT_CRTC_HISTOGRAM, 0);
 
+	if (igt_pipe_obj_has_prop(pipe, IGT_CRTC_SHARPNESS_STRENGTH))
+		igt_pipe_obj_set_prop_value(pipe, IGT_CRTC_SHARPNESS_STRENGTH, 0);
+
 	pipe->out_fence_fd = -1;
 }
 
lib/igt_kms.h +1 -0
index 1e2a927ab..bfd297a93 100644
@@ -168,6 +168,7 @@ enum igt_atomic_crtc_properties {
        IGT_CRTC_HISTOGRAM,
        IGT_CRTC_GLOBAL_HISTOGRAM,
        IGT_CRTC_GLOBAL_HIST_PIXEL_FACTOR,
+       IGT_CRTC_SHARPNESS_STRENGTH,
        IGT_NUM_CRTC_PROPS
 };
 
Signature · 1 line
2.25.1
#6 lore raw

PATCH 6/8 tools: Add new sharpness tool

In reply to Swati Sharma

New sharpness tool is introduced to validate basic functionality of content adaptive sharpness filter supported with intel LNL platform.

Tool has following 2 main functions:
1. input user defined strength value (1-255)
2. input incr/decr factor for setting strength and use up/down arrow keys to increase/decrease strength during run time

To experiment with sharpness, HD 640x480 default image is used. Option is given to user to provide HD, FHD, 4K images as an input.
NOTE: Image used as default is a stocked image.

Tool has following options:
-d <incr/decr_factor>: increment/decrement factor for
sharpness strength for HD resolution. Default image will be used.
-D <strength>: sharpness strength value for HD
resolution. Default image will be used.
-h <image> <incr/decr_factor>: image file for HD resolution (640x480) and
increment/decrement factor for sharpness strength.
-H <image> <strength>: image file for HD resolution

				(640x480) and sharpness strength value.
-f <image> <incr/decr_factor>:	image file for Full HD resolution
				(1920x1080) and increment/decrement factor for sharpness strength.
-F <image> <strength>:		image file for Full HD resolution
				(1920x1080) and sharpness strength value.
-k <image> <incr/decr_factor>:	image file for 4K resolution
				(3840x2160) and increment/decrement factor for sharpness strength.
-K <image> <strength>:		image file for 4K resolution
				(3840x2160) and sharpness strength value.

-p: prints this message

---
 tools/intel_sharpness_tool.c | 370 +++++++++++++++++++++++++++++++++++
 1 file changed, 370 insertions(+)
 create mode 100644 tools/intel_sharpness_tool.c
tools/intel_sharpness_tool.c new file +370 -0
new file mode 100644
index 000000000..89d307e32
@@ -0,0 +1,370 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2024 Intel Corporation
+ */
+
+#include "igt.h"
+#include "igt_kms.h"
+#include <unistd.h>
+
+#define DISABLE_FILTER 0
+#define MIN_VALUE 1
+#define MAX_VALUE 255
+#define UP_ARROW 65
+#define DOWN_ARROW 66
+
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+
+typedef struct {
+	int drm_fd;
+	enum pipe pipe_id;
+	struct igt_fb fb;
+	igt_pipe_t *pipe;
+	igt_display_t display;
+	igt_output_t *output;
+	igt_plane_t *plane;
+	drmModeModeInfo *mode;
+	int filter_strength;
+	uint64_t modifier;
+	uint32_t format;
+	const char *png;
+	int incr_value;
+	int width;
+	int height;
+} data_t;
+
+typedef enum {
+	NONE_SELECTED,
+	SHARP_INCR_SELECTED,
+	SHARP_USR_SELECTED,
+} option;
+
+/* Sets the sharpness filter strength on the display pipe. */
+static void set_filter_strength_on_pipe(data_t *data)
+{
+	igt_pipe_set_prop_value(&data->display, data->pipe_id,
+				IGT_CRTC_SHARPNESS_STRENGTH,
+				data->filter_strength);
+}
+
+static void paint_image(data_t *data)
+{
+	cairo_t *cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
+	int img_x, img_y, img_w, img_h;
+
+	img_x = img_y = 0;
+	img_w = data->fb.width;
+	img_h = data->fb.height;
+
+	igt_paint_image(cr, data->png, img_x, img_y, img_w, img_h);
+
+	igt_put_cairo_ctx(cr);
+}
+
+static void setup_fb(data_t *data)
+{
+	int fb_id;
+
+	fb_id = igt_create_fb(data->drm_fd, data->width, data->height,
+			      DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_LINEAR, &data->fb);
+	igt_assert(fb_id);
+
+	paint_image(data);
+}
+
+static void cleanup(data_t *data)
+{
+	igt_remove_fb(data->drm_fd, &data->fb);
+
+	igt_output_set_pipe(data->output, PIPE_NONE);
+	igt_display_commit2(&data->display, COMMIT_ATOMIC);
+}
+
+/* Tests the sharpness filter by applying the filter strength and committing the changes. */
+static void test_sharpness_filter(data_t *data)
+{
+	int ret;
+
+	igt_display_reset(&data->display);
+	igt_output_set_pipe(data->output, data->pipe_id);
+
+	data->plane = igt_pipe_get_plane_type(data->pipe, DRM_PLANE_TYPE_PRIMARY);
+
+	setup_fb(data);
+	igt_plane_set_fb(data->plane, &data->fb);
+	igt_plane_set_size(data->plane, data->mode->hdisplay, data->mode->vdisplay);
+
+	/* Set filter strength property */
+	set_filter_strength_on_pipe(data);
+	igt_debug("Sharpened image should be observed for filter strength > 0\n");
+
+	ret = igt_display_try_commit2(&data->display, COMMIT_ATOMIC);
+	igt_assert_eq(ret, 0);
+}
+
+/* Checks if the sharpness filter property is available on a given pipe. */
+static bool has_sharpness_filter(igt_pipe_t *pipe)
+{
+	return igt_pipe_obj_has_prop(pipe, IGT_CRTC_SHARPNESS_STRENGTH);
+}
+
+static void set_output(data_t *data)
+{
+	igt_display_t *display = &data->display;
+	igt_output_t *output;
+	enum pipe pipe;
+
+	for_each_pipe_with_valid_output(display, pipe, output) {
+		/* Restricting to pipe A */
+		if (pipe != PIPE_A)
+			continue;
+
+		data->output = output;
+		data->pipe_id = pipe;
+		data->pipe = &display->pipes[data->pipe_id];
+		data->mode = igt_output_get_mode(data->output);
+
+		if (!has_sharpness_filter(data->pipe))
+			continue;
+
+		igt_output_set_pipe(output, pipe);
+	}
+}
+
+/* Handles incrementing or decrementing the sharpness filter strength based on factor. */
+static void do_sharpness_incr(data_t *data)
+{
+	char arrow;
+	data->filter_strength = 0;
+
+	set_output(data);
+
+	/* Handle incrementing or decrementing based on arrow key input */
+	while ((arrow = getchar()) != 'q') {
+		if (arrow != UP_ARROW && arrow != DOWN_ARROW)
+			continue;
+
+		if (arrow == UP_ARROW) {
+			data->filter_strength = MIN(MAX_VALUE, data->filter_strength + data->incr_value);
+		} else if (arrow == DOWN_ARROW) {
+			data->filter_strength = MAX(MIN_VALUE, data->filter_strength - data->incr_value);
+		}
+
+		igt_info("pipe-%s-%s-strength-%d \n", kmstest_pipe_name(data->pipe_id), data->output->name, data->filter_strength);
+		test_sharpness_filter(data);
+	}
+
+	/* Clear the input buffer */
+	while (getchar() != '\n');
+	cleanup(data);
+}
+
+/* Allows the user to specify a sharpness filter strength value directly. */
+static void do_sharpness_usr(data_t *data)
+{
+	// Check if the strength value is within the valid range
+	if (data->filter_strength < MIN_VALUE || data->filter_strength > MAX_VALUE) {
+		igt_warn("Invalid strength value. Please provide a value between %d and %d.\n", MIN_VALUE, MAX_VALUE);
+		cleanup(data);
+		return;
+	}
+
+	set_output(data);
+	igt_info("pipe-%s-%s-strength-%d \n", kmstest_pipe_name(data->pipe_id), data->output->name, data->filter_strength);
+	test_sharpness_filter(data);
+
+	cleanup(data);
+}
+
+static void print_usage(void)
+{
+	printf("Options:\n"
+	       "  -d <incr/decr_factor>:          increment/decrement factor for sharpness strength for HD resolution. Default image will be used.\n"
+	       "  -D <strength>:                  sharpness strength value for HD resolution. Default image will be used.\n"
+
+	       "  -h <image> <incr/decr_factor>:  image file for HD resolution (640x480) and increment/decrement factor for sharpness strength.\n"
+	       "  -H <image> <strength>:          image file for HD resolution (640x480) and sharpness strength value.\n"
+	       "  -d <incr/decr_factor>:          increment/decrement factor for sharpness strength for HD resolution. Default image will be used.\n"
+	       "  -D <strength>:                  sharpness strength value for HD resolution. Default image will be used.\n"
+	       "  -f <image> <incr/decr_factor>:  image file for Full HD resolution (1920x1080) and increment/decrement factor for sharpness strength.\n"
+	       "  -F <image> <strength>:          image file for Full HD resolution (1920x1080) and sharpness strength value.\n"
+	       "  -k <image> <incr/decr_factor>:  image file for 4K resolution (3840x2160) and increment/decrement factor for sharpness strength.\n"
+	       "  -K <image> <strength>:          image file for 4K resolution (3840x2160) and sharpness strength value.\n"
+	       "  -p:                             prints this message\n");
+}
+
+int main(int argc, char *argv[])
+{
+	int opt;
+	data_t data = {0};
+	int ret = EXIT_SUCCESS;
+	FILE *file = NULL;
+
+	option selected_option = NONE_SELECTED;
+
+	// Default image for -d and -D options
+	const char *default_image = "default_hd_image.png";
+
+	if (argc <= 1) {
+		print_usage();
+		return EXIT_SUCCESS;
+	}
+
+	data.drm_fd = drm_open_driver_master(DRIVER_XE);
+	igt_require(data.drm_fd >= 0);
+
+	kmstest_set_vt_graphics_mode();
+
+	igt_display_require(&data.display, data.drm_fd);
+	igt_require(data.display.is_atomic);
+	igt_display_require_output(&data.display);
+
+	while ((opt = getopt(argc, argv, "h:H:d:D:f:k:F:K:p")) != -1) {
+		switch (opt) {
+		case 'p':
+			print_usage();
+			return EXIT_SUCCESS;
+		case 'd':
+			data.incr_value = atoi(optarg);
+			data.png = default_image;
+			data.width = 640;
+			data.height = 480;
+			selected_option = SHARP_INCR_SELECTED;
+			break;
+		case 'D':
+			data.filter_strength = atoi(optarg);
+			if (data.filter_strength < MIN_VALUE || data.filter_strength > MAX_VALUE) {
+				igt_warn("Invalid strength value.\n");
+				return EXIT_FAILURE;
+			}
+			data.png = default_image;
+			data.width = 640;
+			data.height = 480;
+			selected_option = SHARP_USR_SELECTED;
+			break;
+		case 'h':
+			if (optind < argc) {
+				data.png = optarg;
+				data.incr_value = atoi(argv[optind]);
+				optind++;
+			} else {
+				igt_warn("Error: Option -h requires two arguments.\n");
+				return EXIT_FAILURE;
+			}
+			data.width = 640;
+			data.height = 480;
+			selected_option = SHARP_INCR_SELECTED;
+			break;
+		case 'H':
+			if (optind < argc) {
+				data.png = optarg;
+				data.filter_strength = atoi(argv[optind]);
+				if (data.filter_strength < MIN_VALUE || data.filter_strength > MAX_VALUE) {
+					igt_warn("Invalid strength value.\n");
+					return EXIT_FAILURE;
+				}
+				optind++;
+			} else {
+				igt_warn("Error: Option -H requires two arguments.\n");
+				return EXIT_FAILURE;
+			}
+			data.width = 640;
+			data.height = 480;
+			selected_option = SHARP_USR_SELECTED;
+			break;
+		case 'f':
+			if (optind < argc) {
+				data.png = optarg;
+				data.incr_value = atoi(argv[optind]);
+				optind++;
+			} else {
+				igt_warn("Error: Option -f requires two arguments.\n");
+				return EXIT_FAILURE;
+			}
+			data.width = 1920;
+			data.height = 1080;
+			selected_option = SHARP_INCR_SELECTED;
+			break;
+		case 'F':
+			if (optind < argc) {
+				data.png = optarg;
+				data.filter_strength = atoi(argv[optind]);
+				if (data.filter_strength < MIN_VALUE || data.filter_strength > MAX_VALUE) {
+					igt_warn("Invalid strength value.\n");
+					return EXIT_FAILURE;
+				}
+				optind++;
+			} else {
+				igt_warn("Error: Option -F requires two arguments.\n");
+				return EXIT_FAILURE;
+			}
+			data.width = 1920;
+			data.height = 1080;
+			selected_option = SHARP_USR_SELECTED;
+			break;
+		case 'k':
+			if (optind < argc) {
+				data.png = optarg;
+				data.incr_value = atoi(argv[optind]);
+				optind++;
+			} else {
+				igt_warn("Error: Option -k requires two arguments.\n");
+				return EXIT_FAILURE;
+			}
+			data.width = 3840;
+			data.height = 2160;
+			selected_option = SHARP_INCR_SELECTED;
+			break;
+		case 'K':
+			if (optind < argc) {
+				data.png = optarg;
+				data.filter_strength = atoi(argv[optind]);
+				if (data.filter_strength < MIN_VALUE || data.filter_strength > MAX_VALUE) {
+					igt_warn("Invalid strength value.\n");
+					return EXIT_FAILURE;
+				}
+				optind++;
+			} else {
+				igt_warn("Error: Option -K requires two arguments.\n");
+				return EXIT_FAILURE;
+			}
+			data.width = 3840;
+			data.height = 2160;
+			selected_option = SHARP_USR_SELECTED;
+			break;
+		default:
+			igt_warn("Unknown option.\n");
+			print_usage();
+			return EXIT_FAILURE;
+		}
+	}
+
+	if (data.png) {
+		file = igt_fopen_data(data.png);
+		if (file == NULL) {
+			igt_warn("Could not open data file \"%s\": No such file or directory\n", data.png);
+			return EXIT_FAILURE;
+		}
+	}
+
+	// Ensure valid arguments
+	if (!data.png && data.filter_strength <= 0 && selected_option != NONE_SELECTED) {
+		igt_warn("Error: No image file or strength value specified.\n");
+		return EXIT_FAILURE;
+	}
+
+	// Handle different options
+	if (selected_option == SHARP_INCR_SELECTED) {
+		do_sharpness_incr(&data);
+	} else if (selected_option == SHARP_USR_SELECTED) {
+		do_sharpness_usr(&data);
+	}
+
+	fclose(file);
+	igt_display_fini(&data.display);
+	close(data.drm_fd);
+
+	return ret;
+}
+
Signature · 1 line
2.25.1
#7 lore raw

Re: [PATCH i-g-t 6/8] tools: Add new sharpness tool

Hi,

Patch has style problems, Please check.

Quoted 232 lines · Swati Sharma

New sharpness tool is introduced to validate basic functionality of content adaptive sharpness filter supported with intel LNL platform.

Tool has following 2 main functions:
1. input user defined strength value (1-255)
2. input incr/decr factor for setting strength and use up/down arrow keys to increase/decrease strength during run time

To experiment with sharpness, HD 640x480 default image is used. Option is given to user to provide HD, FHD, 4K images as an input.
NOTE: Image used as default is a stocked image.

Tool has following options:
-d <incr/decr_factor>: increment/decrement factor for
sharpness strength for HD resolution. Default image will be used.
-D <strength>: sharpness strength value for HD
resolution. Default image will be used.
-h <image> <incr/decr_factor>: image file for HD resolution (640x480) and
increment/decrement factor for sharpness strength.
-H <image> <strength>: image file for HD resolution

				(640x480) and sharpness strength value.
-f <image> <incr/decr_factor>:	image file for Full HD resolution
				(1920x1080) and increment/decrement factor for sharpness strength.
-F <image> <strength>:		image file for Full HD resolution
				(1920x1080) and sharpness strength value.
-k <image> <incr/decr_factor>:	image file for 4K resolution
				(3840x2160) and increment/decrement factor for sharpness strength.
-K <image> <strength>:		image file for 4K resolution
				(3840x2160) and sharpness strength value.

-p: prints this message

---
  tools/intel_sharpness_tool.c | 370 +++++++++++++++++++++++++++++++++++
  1 file changed, 370 insertions(+)

create mode 100644 tools/intel_sharpness_tool.c

tools/intel_sharpness_tool.c new file +185 -0
new file mode 100644
index 000000000..89d307e32
@@ -0,0 +1,370 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2024 Intel Corporation
+ */
+
+#include "igt.h"
+#include "igt_kms.h"
+#include <unistd.h>
+
+#define DISABLE_FILTER 0
+#define MIN_VALUE 1
+#define MAX_VALUE 255
+#define UP_ARROW 65
+#define DOWN_ARROW 66
+
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+
+typedef struct {
+	int drm_fd;
+	enum pipe pipe_id;
+	struct igt_fb fb;
+	igt_pipe_t *pipe;
+	igt_display_t display;
+	igt_output_t *output;
+	igt_plane_t *plane;
+	drmModeModeInfo *mode;
+	int filter_strength;
+	uint64_t modifier;
+	uint32_t format;
+	const char *png;
+	int incr_value;
+	int width;
+	int height;
+} data_t;
+
+typedef enum {
+	NONE_SELECTED,
+	SHARP_INCR_SELECTED,
+	SHARP_USR_SELECTED,
+} option;
+
+/* Sets the sharpness filter strength on the display pipe. */
+static void set_filter_strength_on_pipe(data_t *data)
+{
+	igt_pipe_set_prop_value(&data->display, data->pipe_id,
+				IGT_CRTC_SHARPNESS_STRENGTH,
+				data->filter_strength);
+}
+
+static void paint_image(data_t *data)
+{
+	cairo_t *cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
+	int img_x, img_y, img_w, img_h;
+
+	img_x = img_y = 0;
+	img_w = data->fb.width;
+	img_h = data->fb.height;
+
+	igt_paint_image(cr, data->png, img_x, img_y, img_w, img_h);
+
+	igt_put_cairo_ctx(cr);
+}
+
+static void setup_fb(data_t *data)
+{
+	int fb_id;
+
+	fb_id = igt_create_fb(data->drm_fd, data->width, data->height,
+			      DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_LINEAR, &data->fb);
+	igt_assert(fb_id);
+
+	paint_image(data);
+}
+
+static void cleanup(data_t *data)
+{
+	igt_remove_fb(data->drm_fd, &data->fb);
+
+	igt_output_set_pipe(data->output, PIPE_NONE);
+	igt_display_commit2(&data->display, COMMIT_ATOMIC);
+}
+
+/* Tests the sharpness filter by applying the filter strength and committing the changes. */
+static void test_sharpness_filter(data_t *data)
+{
+	int ret;
+
+	igt_display_reset(&data->display);
+	igt_output_set_pipe(data->output, data->pipe_id);
+
+	data->plane = igt_pipe_get_plane_type(data->pipe, DRM_PLANE_TYPE_PRIMARY);
+
+	setup_fb(data);
+	igt_plane_set_fb(data->plane, &data->fb);
+	igt_plane_set_size(data->plane, data->mode->hdisplay, data->mode->vdisplay);
+
+	/* Set filter strength property */
+	set_filter_strength_on_pipe(data);
+	igt_debug("Sharpened image should be observed for filter strength > 0\n");
+
+	ret = igt_display_try_commit2(&data->display, COMMIT_ATOMIC);
+	igt_assert_eq(ret, 0);
+}
+
+/* Checks if the sharpness filter property is available on a given pipe. */
+static bool has_sharpness_filter(igt_pipe_t *pipe)
+{
+	return igt_pipe_obj_has_prop(pipe, IGT_CRTC_SHARPNESS_STRENGTH);
+}
+
+static void set_output(data_t *data)
+{
+	igt_display_t *display = &data->display;
+	igt_output_t *output;
+	enum pipe pipe;
+
+	for_each_pipe_with_valid_output(display, pipe, output) {
+		/* Restricting to pipe A */
+		if (pipe != PIPE_A)
+			continue;
+
+		data->output = output;
+		data->pipe_id = pipe;
+		data->pipe = &display->pipes[data->pipe_id];
+		data->mode = igt_output_get_mode(data->output);
+
+		if (!has_sharpness_filter(data->pipe))
+			continue;
+
+		igt_output_set_pipe(output, pipe);
+	}
+}
+
+/* Handles incrementing or decrementing the sharpness filter strength based on factor. */
+static void do_sharpness_incr(data_t *data)
+{
+	char arrow;
+	data->filter_strength = 0;
+
+	set_output(data);
+
+	/* Handle incrementing or decrementing based on arrow key input */
+	while ((arrow = getchar()) != 'q') {
+		if (arrow != UP_ARROW && arrow != DOWN_ARROW)
+			continue;
+
+		if (arrow == UP_ARROW) {
+			data->filter_strength = MIN(MAX_VALUE, data->filter_strength + data->incr_value);
+		} else if (arrow == DOWN_ARROW) {
+			data->filter_strength = MAX(MIN_VALUE, data->filter_strength - data->incr_value);
+		}
+
+		igt_info("pipe-%s-%s-strength-%d \n", kmstest_pipe_name(data->pipe_id), data->output->name, data->filter_strength);
+		test_sharpness_filter(data);
+	}
+
+	/* Clear the input buffer */
+	while (getchar() != '\n');
+	cleanup(data);
+}
+
+/* Allows the user to specify a sharpness filter strength value directly. */
+static void do_sharpness_usr(data_t *data)
+{
+	// Check if the strength value is within the valid range
+	if (data->filter_strength < MIN_VALUE || data->filter_strength > MAX_VALUE) {
+		igt_warn("Invalid strength value. Please provide a value between %d and %d.\n", MIN_VALUE, MAX_VALUE);
+		cleanup(data);
+		return;
+	}
+
+	set_output(data);
+	igt_info("pipe-%s-%s-strength-%d \n", kmstest_pipe_name(data->pipe_id), data->output->name, data->filter_strength);
+	test_sharpness_filter(data);
+
+	cleanup(data);
+}
+
+static void print_usage(void)
+{
+	printf("Options:\n"
+	       "  -d <incr/decr_factor>:          increment/decrement factor for sharpness strength for HD resolution. Default image will be used.\n"
+	       "  -D <strength>:                  sharpness strength value for HD resolution. Default image will be used.\n"
+

tools/intel_sharpness_tool.c line 195

Quoted 10 lines
tools/intel_sharpness_tool.c new file +10 -0
+	       "  -h <image> <incr/decr_factor>:  image file for HD resolution (640x480) and increment/decrement factor for sharpness strength.\n"
+	       "  -H <image> <strength>:          image file for HD resolution (640x480) and sharpness strength value.\n"
+	       "  -d <incr/decr_factor>:          increment/decrement factor for sharpness strength for HD resolution. Default image will be used.\n"
+	       "  -D <strength>:                  sharpness strength value for HD resolution. Default image will be used.\n"
+	       "  -f <image> <incr/decr_factor>:  image file for Full HD resolution (1920x1080) and increment/decrement factor for sharpness strength.\n"
+	       "  -F <image> <strength>:          image file for Full HD resolution (1920x1080) and sharpness strength value.\n"
+	       "  -k <image> <incr/decr_factor>:  image file for 4K resolution (3840x2160) and increment/decrement factor for sharpness strength.\n"
+	       "  -K <image> <strength>:          image file for 4K resolution (3840x2160) and sharpness strength value.\n"
+	       "  -p:                             prints this message\n");
+}

Add one more option to select the output for multi display config.

Quoted 144 lines
tools/intel_sharpness_tool.c new file +144 -0
+
+int main(int argc, char *argv[])
+{
+	int opt;
+	data_t data = {0};
+	int ret = EXIT_SUCCESS;
+	FILE *file = NULL;
+
+	option selected_option = NONE_SELECTED;
+
+	// Default image for -d and -D options
+	const char *default_image = "default_hd_image.png";
+
+	if (argc <= 1) {
+		print_usage();
+		return EXIT_SUCCESS;
+	}
+
+	data.drm_fd = drm_open_driver_master(DRIVER_XE);
+	igt_require(data.drm_fd >= 0);
+
+	kmstest_set_vt_graphics_mode();
+
+	igt_display_require(&data.display, data.drm_fd);
+	igt_require(data.display.is_atomic);
+	igt_display_require_output(&data.display);
+
+	while ((opt = getopt(argc, argv, "h:H:d:D:f:k:F:K:p")) != -1) {
+		switch (opt) {
+		case 'p':
+			print_usage();
+			return EXIT_SUCCESS;
+		case 'd':
+			data.incr_value = atoi(optarg);
+			data.png = default_image;
+			data.width = 640;
+			data.height = 480;
+			selected_option = SHARP_INCR_SELECTED;
+			break;
+		case 'D':
+			data.filter_strength = atoi(optarg);
+			if (data.filter_strength < MIN_VALUE || data.filter_strength > MAX_VALUE) {
+				igt_warn("Invalid strength value.\n");
+				return EXIT_FAILURE;
+			}
+			data.png = default_image;
+			data.width = 640;
+			data.height = 480;
+			selected_option = SHARP_USR_SELECTED;
+			break;
+		case 'h':
+			if (optind < argc) {
+				data.png = optarg;
+				data.incr_value = atoi(argv[optind]);
+				optind++;
+			} else {
+				igt_warn("Error: Option -h requires two arguments.\n");
+				return EXIT_FAILURE;
+			}
+			data.width = 640;
+			data.height = 480;
+			selected_option = SHARP_INCR_SELECTED;
+			break;
+		case 'H':
+			if (optind < argc) {
+				data.png = optarg;
+				data.filter_strength = atoi(argv[optind]);
+				if (data.filter_strength < MIN_VALUE || data.filter_strength > MAX_VALUE) {
+					igt_warn("Invalid strength value.\n");
+					return EXIT_FAILURE;
+				}
+				optind++;
+			} else {
+				igt_warn("Error: Option -H requires two arguments.\n");
+				return EXIT_FAILURE;
+			}
+			data.width = 640;
+			data.height = 480;
+			selected_option = SHARP_USR_SELECTED;
+			break;
+		case 'f':
+			if (optind < argc) {
+				data.png = optarg;
+				data.incr_value = atoi(argv[optind]);
+				optind++;
+			} else {
+				igt_warn("Error: Option -f requires two arguments.\n");
+				return EXIT_FAILURE;
+			}
+			data.width = 1920;
+			data.height = 1080;
+			selected_option = SHARP_INCR_SELECTED;
+			break;
+		case 'F':
+			if (optind < argc) {
+				data.png = optarg;
+				data.filter_strength = atoi(argv[optind]);
+				if (data.filter_strength < MIN_VALUE || data.filter_strength > MAX_VALUE) {
+					igt_warn("Invalid strength value.\n");
+					return EXIT_FAILURE;
+				}
+				optind++;
+			} else {
+				igt_warn("Error: Option -F requires two arguments.\n");
+				return EXIT_FAILURE;
+			}
+			data.width = 1920;
+			data.height = 1080;
+			selected_option = SHARP_USR_SELECTED;
+			break;
+		case 'k':
+			if (optind < argc) {
+				data.png = optarg;
+				data.incr_value = atoi(argv[optind]);
+				optind++;
+			} else {
+				igt_warn("Error: Option -k requires two arguments.\n");
+				return EXIT_FAILURE;
+			}
+			data.width = 3840;
+			data.height = 2160;
+			selected_option = SHARP_INCR_SELECTED;
+			break;
+		case 'K':
+			if (optind < argc) {
+				data.png = optarg;
+				data.filter_strength = atoi(argv[optind]);
+				if (data.filter_strength < MIN_VALUE || data.filter_strength > MAX_VALUE) {
+					igt_warn("Invalid strength value.\n");
+					return EXIT_FAILURE;
+				}
+				optind++;
+			} else {
+				igt_warn("Error: Option -K requires two arguments.\n");
+				return EXIT_FAILURE;
+			}
+			data.width = 3840;
+			data.height = 2160;
+			selected_option = SHARP_USR_SELECTED;
+			break;
+		default:
+			igt_warn("Unknown option.\n");
+			print_usage();
+			return EXIT_FAILURE;

tools/intel_sharpness_tool.c line 349

Quoted 10 lines
tools/intel_sharpness_tool.c new file +10 -0
+		}
+	}
+
+	if (data.png) {
+		file = igt_fopen_data(data.png);
+		if (file == NULL) {
+			igt_warn("Could not open data file \"%s\": No such file or directory\n", data.png);
+			return EXIT_FAILURE;
+		}
+	}

We are exporting png data location using igt_runner. But for tool we need to find other way.

Quoted 21 lines
tools/intel_sharpness_tool.c new file +21 -0
+
+	// Ensure valid arguments
+	if (!data.png && data.filter_strength <= 0 && selected_option != NONE_SELECTED) {
+		igt_warn("Error: No image file or strength value specified.\n");
+		return EXIT_FAILURE;
+	}
+
+	// Handle different options
+	if (selected_option == SHARP_INCR_SELECTED) {
+		do_sharpness_incr(&data);
+	} else if (selected_option == SHARP_USR_SELECTED) {
+		do_sharpness_usr(&data);
+	}
+
+	fclose(file);
+	igt_display_fini(&data.display);
+	close(data.drm_fd);
+
+	return ret;
+}
+
#8 lore raw

PATCH 7/8 data: Add image

In reply to Swati Sharma

Add hd image for user to experiment with sharpness tool.

---
 data/default_hd_image.png | Bin 0 -> 657520 bytes
 data/meson.build          |   1 +
 2 files changed, 1 insertion(+)
 create mode 100644 data/default_hd_image.png
data/default_hd_image.png new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..57f1f2297dbb4abee9eea3fc388fcea3f21ad913
GIT binary patch
data/meson.build +1 -0
index 9490d20ac..df2be7ecc 100644
@@ -1,6 +1,7 @@
 image_files = [
   '1080p-left.png',
   '1080p-right.png',
+  'default_hd_image.png',
   'pass.png',
 ]
 
Signature · 1 line
2.25.1
#9 lore raw

PATCH 8/8 meson: Add sharpness tool

In reply to Swati Sharma

From: Naladala Ramanaidu <[email protected]>

Make changes in tools/meson.build to build sharpness tool.

---
 tools/meson.build | 11 +++++++++++
 1 file changed, 11 insertions(+)
tools/meson.build +11 -0
index 511aec69e..dcd931cc1 100644
@@ -68,6 +68,17 @@ if libudev.found()
 		   install : true)
 endif
 
+executable('intel_sharpness_tool', 'intel_sharpness_tool.c',
+           dependencies : tool_deps,
+           c_args : [
+	      '-DIGT_DATADIR="@0@"'.format(join_paths(prefix, datadir)),
+	      '-DIGT_SRCDIR="@0@"'.format(srcdir),
+	      '-DIGT_IMGDIR="@0@"'.format(imgdir),
+	      '-DIGT_LOG_DOMAIN="@0@"'.format(f.split('.')[0])
+            ],
+          install_rpath : bindir_rpathdir,
+          install : true)
+
 executable('gputop', 'gputop.c',
            install : true,
            install_rpath : bindir_rpathdir,
Signature · 1 line
2.25.1
#10 lore raw

✗ Fi.CI.BUILD: failure for New sharpness tool (rev2)

In reply to Swati Sharma
== Series Details ==

== Series Details ==

Series: New sharpness tool (rev2)
URL : https://patchwork.freedesktop.org/series/138966/
State : failure

== Summary ==

Applying: data: Move PNG images to new data directory
Applying: runner/settings: Constify absolute_path parameter
Applying: runner/settings: Add function to set IGT_RUNNER_DATA environment variable
Applying: lib/igt_core: Enhance __igt_fopen_data to support additional directories
Applying: lib/igt_kms: Add "sharpness strength" as crtc property
Using index info to reconstruct a base tree...
M lib/igt_kms.c
M lib/igt_kms.h
Falling back to patching base and 3-way merge...
Auto-merging lib/igt_kms.h
CONFLICT (content): Merge conflict in lib/igt_kms.h
Auto-merging lib/igt_kms.c
CONFLICT (content): Merge conflict in lib/igt_kms.c
Patch failed at 0005 lib/igt_kms: Add "sharpness strength" as crtc property When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".