diff --git a/kitty/graphics.c b/kitty/graphics.c index 43d23acf5..4db4f8174 100644 --- a/kitty/graphics.c +++ b/kitty/graphics.c @@ -830,8 +830,9 @@ update_src_rect(ImageRef *ref, Image *img) { static void update_dest_rect(ImageRef *ref, uint32_t num_cols, uint32_t num_rows, CellPixelSize cell) { uint32_t t; - if (num_cols == 0) { - if (num_rows == 0) { + const bool auto_cols = num_cols == 0, auto_rows = num_rows == 0; + if (auto_cols) { + if (auto_rows) { t = (uint32_t)(ref->src_width + ref->cell_x_offset); num_cols = t / cell.width; if (t > num_cols * cell.width) num_cols += 1; @@ -841,8 +842,8 @@ update_dest_rect(ImageRef *ref, uint32_t num_cols, uint32_t num_rows, CellPixelS num_cols = (uint32_t)ceil(width_px / cell.width); } } - if (num_rows == 0) { - if (num_cols == 0) { + if (auto_rows) { + if (auto_cols) { t = (uint32_t)(ref->src_height + ref->cell_y_offset); num_rows = t / cell.height; if (t > num_rows * cell.height) num_rows += 1; diff --git a/kitty_tests/graphics.py b/kitty_tests/graphics.py index ec6a0444d..24cbfb5b7 100644 --- a/kitty_tests/graphics.py +++ b/kitty_tests/graphics.py @@ -647,6 +647,13 @@ class TestGraphics(BaseTest): self.ae((s.cursor.x, s.cursor.y), (3, 2)) rect_eq(layers(s)[0]['dest_rect'], -1, 1, -1 + 3 * dx, 1 - 3*dy) + def test_graphics_put_with_pixel_offsets(self): + cw, ch = 10, 20 + # Image 10x20 placed with 5px X and Y pixel offsets + s, dx, dy, put_image, put_ref, layers, rect_eq = put_helpers(self, cw, ch) + self.ae(put_image(s, 10, 20, cell_x_off=5, cell_y_off=5)[1], 'OK') + self.ae((s.cursor.x, s.cursor.y), (2, 1)) + def test_image_layer_grouping(self): cw, ch = 10, 20 s, dx, dy, put_image, put_ref, layers, rect_eq = put_helpers(self, cw, ch)