Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save bczhc/2ee9eba91bacaaeafe2328c532d8ebb0 to your computer and use it in GitHub Desktop.

Select an option

Save bczhc/2ee9eba91bacaaeafe2328c532d8ebb0 to your computer and use it in GitHub Desktop.
用于修复grim在hyprland下某些缩放值下截图模糊问题的patch
From 2d9d26b81bb1b3eec9c33b52bc9a2a8c7dd6fb8b Mon Sep 17 00:00:00 2001
From: Loukas Agorgianitis <loukas@agorgianitis.com>
Date: Mon, 13 Jan 2025 21:43:56 +0200
Subject: [PATCH] render: make transformations in geometry space
Previously, the rendering process made transformations in logical
geometry space. When using fractional scaling, this process scaled
the transformations to the logical geometry space and back using the
fractional scale, which led to floating point rounding errors. This,
produced non pixel perfect / slightly blurry images.
This patch fixes the above issue, by making the transformations in
geometry (pixel) space, avoiding the unnecessary scaling roundtrip which
caused the rounding errors.
Signed-off-by: Loukas Agorgianitis <loukas@agorgianitis.com>
Co-authored-by: Quantum Cog <thequantumcog@protonmail.com>
---
render.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/render.c b/render.c
index 1f8f929..7a94eea 100644
--- a/render.c
+++ b/render.c
@@ -166,10 +166,8 @@ pixman_image_t *render(struct grim_state *state, struct grim_box *geometry,
return NULL;
}
- int32_t output_x = capture->logical_geometry.x - geometry->x;
- int32_t output_y = capture->logical_geometry.y - geometry->y;
- int32_t output_width = capture->logical_geometry.width;
- int32_t output_height = capture->logical_geometry.height;
+ int32_t raw_output_x = capture->output->fallback_x - geometry->x * scale;
+ int32_t raw_output_y = capture->output->fallback_y - geometry->y * scale;
int32_t raw_output_width = buffer->width;
int32_t raw_output_height = buffer->height;
@@ -194,19 +192,15 @@ pixman_image_t *render(struct grim_state *state, struct grim_box *geometry,
pixman_f_transform_translate(&out2com, NULL,
-(double)buffer->width / 2,
-(double)buffer->height / 2);
- pixman_f_transform_scale(&out2com, NULL,
- (double)output_width / raw_output_width,
- (double)output_height * output_flipped_y / raw_output_height);
+ pixman_f_transform_scale(&out2com, NULL, 1, output_flipped_y);
pixman_f_transform_rotate(&out2com, NULL,
round(cos(get_output_rotation(capture->transform))),
round(sin(get_output_rotation(capture->transform))));
pixman_f_transform_scale(&out2com, NULL, output_flipped_x, 1);
pixman_f_transform_translate(&out2com, NULL,
- (double)output_width / 2,
- (double)output_height / 2);
- pixman_f_transform_translate(&out2com, NULL, output_x, output_y);
- pixman_f_transform_scale(&out2com, NULL, scale, scale);
-
+ (double)capture->output->mode_width / 2,
+ (double)capture->output->mode_height / 2);
+ pixman_f_transform_translate(&out2com, NULL, raw_output_x, raw_output_y);
struct grim_box composite_dest;
bool grid_aligned;
compute_composite_region(&out2com, buffer->width,
--
2.53.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment