[PATCH i-g-t 4/6] tools: Add new sharpness tool
Swati Sharma
swati2.sharma at intel.com
Mon Sep 23 07:10:21 UTC 2024
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, 3 images are used (HD, FHD, 4K).
All the images are stocked images.
Tool has following options:
-h value: incr/decr factor for setting strength for hd res
-f value: incr/decr factor for setting strength for fhd res
-k value: incr/decr factor for setting strength for 4k res
-H value: user defined strength (1-255) for hd res
-F value: user defined strength (1-255) for fhd res
-K value: user defined strength (1-255) for 4k res
-p: prints this message
Signed-off-by: Swati Sharma <swati2.sharma at intel.com>
Signed-off-by: Mohammed Thasleem <mohammed.thasleem at intel.com>
Signed-off-by: Nemesa Garg <nemesa.garg at intel.com>
---
tools/intel_sharpness_tool.c | 342 +++++++++++++++++++++++++++++++++++
1 file changed, 342 insertions(+)
create mode 100644 tools/intel_sharpness_tool.c
diff --git a/tools/intel_sharpness_tool.c b/tools/intel_sharpness_tool.c
new file mode 100644
index 000000000..3040bb802
--- /dev/null
+++ b/tools/intel_sharpness_tool.c
@@ -0,0 +1,342 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2024 Intel Corporation
+ */
+
+#include "igt.h"
+#include "igt_kms.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,
+ USAGE_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, data->format, data->modifier, &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)
+{
+ igt_output_t *output = data->output;
+ drmModeModeInfo *mode = data->mode;
+ int ret;
+
+ igt_display_reset(&data->display);
+ igt_output_set_pipe(output, data->pipe_id);
+
+ data->plane = igt_pipe_get_plane_type(data->pipe, DRM_PLANE_TYPE_PRIMARY);
+ igt_skip_on_f(!igt_plane_has_format_mod(data->plane, data->format, data->modifier),
+ "No requested format/modifier on pipe %s\n", kmstest_pipe_name(data->pipe_id));
+
+ setup_fb(data);
+ igt_plane_set_fb(data->plane, &data->fb);
+ igt_plane_set_size(data->plane, mode->hdisplay, 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);
+
+ if (!intel_pipe_output_combo_valid(display)) {
+ igt_output_set_pipe(output, PIPE_NONE);
+ continue;
+ }
+ }
+}
+
+/* Handles incrementing or decrementing the sharpness filter strength based on arrow key inputs. */
+static void do_sharpness_incr(data_t *data)
+{
+ char arrow;
+
+ data->modifier = DRM_FORMAT_MOD_LINEAR;
+ data->format = DRM_FORMAT_XRGB8888;
+
+ /* Run with sharpness filter disable */
+ set_output(data);
+ test_sharpness_filter(data);
+
+ /*
+ * Press up-arrow to increase & down-arrow to decrease strength value
+ * and 'q' to escape. Strength value is incremented/decremented by
+ * incr/decr value provide by user if its within range (0-255).
+ */
+
+ /* Read the 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)
+{
+ data->modifier = DRM_FORMAT_MOD_LINEAR;
+ data->format = DRM_FORMAT_XRGB8888;
+
+ /* Run with sharpness filter disable */
+ set_output(data);
+ test_sharpness_filter(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"
+" -h value: incr/decr factor for setting strength value for hd resolution. use up/down \n"
+" arrow keys to increase/decrease strength by this factor and q to quit.\n"
+" -f value: incr/decr factor for setting strength value for fhd resolution. use up/down \n"
+" arrow keys to increase/decrease strength by this factor and q to quit.\n"
+" -k value: incr/decr factor for setting strength value for 4k resolution. use up/down \n"
+" arrow keys to increase/decrease strength by this factor and q to quit.\n"
+" -H value: user defined strength value (1-255) for hd resolution.\n"
+" -F value: user defined strength value (1-255) for fhd resolution.\n"
+" -K value: user defined strength value (1-255) for 4k resolution.\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;
+ const char *files[] = {"640x480.png", "1920x1080.png", "3840x2160.png"};
+
+ option selected_option = NONE_SELECTED;
+
+ 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:f:k:H:F:K:p")) != -1) {
+ switch (opt) {
+ case 'h':
+ case 'f':
+ case 'k':
+ if (selected_option != NONE_SELECTED) {
+ igt_warn("Error: Only one option can be selected.\n");
+ ret = EXIT_FAILURE;
+ goto exit;
+ }
+ data.incr_value = atoi(optarg);
+ if (data.incr_value < 1 || data.incr_value > 255) {
+ igt_warn("Invalid input for -%c option. Value should be between 1 and 255.\n", opt);
+ ret = EXIT_FAILURE;
+ goto exit;
+ }
+ selected_option = SHARP_INCR_SELECTED;
+
+ data.png = (opt == 'h') ? files[0] : ((opt == 'f') ? files[1] : files[2]);
+ data.width = (opt == 'h') ? 640 : ((opt == 'f') ? 1920 : 3840);
+ data.height = (opt == 'h') ? 480 : ((opt == 'f') ? 1080 : 2160);
+
+ // Check if the file exists and can be opened
+ file = igt_fopen_data(data.png);
+ if (file == NULL) {
+ igt_warn("Error: Unable to open file '%s'\n", data.png);
+ ret = EXIT_FAILURE;
+ goto exit;
+ }
+
+ fclose(file);
+ break;
+ case 'H':
+ case 'F':
+ case 'K':
+ if (selected_option != NONE_SELECTED) {
+ igt_warn("Error: Only one option can be selected.\n");
+ ret = EXIT_FAILURE;
+ goto exit;
+ }
+ data.filter_strength = atoi(optarg);
+ if (data.filter_strength < 1 || data.filter_strength > 255) {
+ igt_warn("Invalid input for -%c option. Value should be between 1 and 255.\n", opt);
+ ret = EXIT_FAILURE;
+ goto exit;
+ }
+ selected_option = SHARP_USR_SELECTED;
+
+ data.png = (opt == 'H') ? files[0] : ((opt == 'F') ? files[1] : files[2]);
+ data.width = (opt == 'H') ? 640 : ((opt == 'F') ? 1920 : 3840);
+ data.height = (opt == 'H') ? 480 : ((opt == 'F') ? 1080 : 2160);
+
+ // Check if the file exists and can be opened
+ file = igt_fopen_data(data.png);
+ if (file == NULL) {
+ igt_warn("Error: Unable to open file '%s'\n", data.png);
+ ret = EXIT_FAILURE;
+ goto exit;
+ }
+
+ fclose(file);
+ break;
+ case 'p':
+ if (selected_option != NONE_SELECTED) {
+ igt_warn("Error: Only one option can be selected.\n");
+ print_usage();
+ ret = EXIT_FAILURE;
+ goto exit;
+ }
+ selected_option = USAGE_SELECTED;
+ break;
+ default:
+ igt_warn("Error: Unknown option -%c.\n", opt);
+ print_usage();
+ ret = EXIT_FAILURE;
+ goto exit;
+ }
+ }
+
+ // Check if the selected_option that requires a file was selected
+ if ((selected_option == SHARP_INCR_SELECTED || selected_option == SHARP_USR_SELECTED) && data.png == NULL) {
+ igt_warn("Error: No file specified for sharpness adjustment.\n");
+ ret = EXIT_FAILURE;
+ goto exit;
+ }
+
+ // Handle the case where no valid option was processed
+ if (selected_option == NONE_SELECTED) {
+ igt_warn("Error: No valid option selected.\n");
+ ret = EXIT_FAILURE;
+ goto exit;
+ }
+
+ // Perform actions based on the selected option
+ if (selected_option == SHARP_INCR_SELECTED) {
+ do_sharpness_incr(&data);
+ } else if (selected_option == SHARP_USR_SELECTED) {
+ do_sharpness_usr(&data);
+ } else if (selected_option == USAGE_SELECTED) {
+ print_usage();
+ }
+exit:
+ igt_display_fini(&data.display);
+ close(data.drm_fd);
+
+ return ret;
+}
--
2.25.1
More information about the igt-dev
mailing list