From 73c5010e4e85e593f2057653d1dd9c5c8cd3c816 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Thu, 11 Jul 2024 20:43:47 +0200 Subject: [PATCH] render: fix sampling of transformed buffers with crop --- src/gfx_api.rs | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/gfx_api.rs b/src/gfx_api.rs index a36c9a4e..8611a357 100644 --- a/src/gfx_api.rs +++ b/src/gfx_api.rs @@ -72,13 +72,43 @@ impl SampleRect { let y2 = self.y2; match self.buffer_transform { None => [[x2, y1], [x1, y1], [x2, y2], [x1, y2]], - Rotate90 => [[y1, x1], [y1, x2], [y2, x1], [y2, x2]], - Rotate180 => [[x1, y2], [x2, y2], [x1, y1], [x2, y1]], - Rotate270 => [[y2, x2], [y2, x1], [y1, x2], [y1, x1]], - Flip => [[x1, y1], [x2, y1], [x1, y2], [x2, y2]], + Rotate90 => [ + [y1, 1.0 - x2], + [y1, 1.0 - x1], + [y2, 1.0 - x2], + [y2, 1.0 - x1], + ], + Rotate180 => [ + [1.0 - x2, 1.0 - y1], + [1.0 - x1, 1.0 - y1], + [1.0 - x2, 1.0 - y2], + [1.0 - x1, 1.0 - y2], + ], + Rotate270 => [ + [1.0 - y1, x2], + [1.0 - y1, x1], + [1.0 - y2, x2], + [1.0 - y2, x1], + ], + Flip => [ + [1.0 - x2, y1], + [1.0 - x1, y1], + [1.0 - x2, y2], + [1.0 - x1, y2], + ], FlipRotate90 => [[y1, x2], [y1, x1], [y2, x2], [y2, x1]], - FlipRotate180 => [[x2, y2], [x1, y2], [x2, y1], [x1, y1]], - FlipRotate270 => [[y2, x1], [y2, x2], [y1, x1], [y1, x2]], + FlipRotate180 => [ + [x2, 1.0 - y1], + [x1, 1.0 - y1], + [x2, 1.0 - y2], + [x1, 1.0 - y2], + ], + FlipRotate270 => [ + [1.0 - y1, 1.0 - x2], + [1.0 - y1, 1.0 - x1], + [1.0 - y2, 1.0 - x2], + [1.0 - y2, 1.0 - x1], + ], } } }