aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2023-10-26 16:32:50 +0200
committerDaniel Eklöf <daniel@ekloef.se>2023-10-26 16:32:50 +0200
commit423f7dc6990b1cb5afde95f8383c44b1a4dce16a (patch)
treece22ea28126d73c68bc290505e8fee6a781a89c5
parent61af8e87661b93cfefe77c083328fef962c4121d (diff)
parent8798bf08c1ae0d8c1334ea914c80ddaf322c9fb3 (diff)
downloadwbg-423f7dc6990b1cb5afde95f8383c44b1a4dce16a.tar.gz
Merge branch 'zoom'
Closes #6
-rw-r--r--CHANGELOG.md6
-rw-r--r--main.c8
2 files changed, 14 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7b1b71c..054403f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,12 @@
### Changed
+
+* Image is now zoomed, rather than stretched ([#6][6]).
+
+[6]: https://codeberg.org/dnkl/wbg/issues/6
+
+
### Deprecated
### Removed
### Fixed
diff --git a/main.c b/main.c
index 6e938f0..19a9711 100644
--- a/main.c
+++ b/main.c
@@ -91,8 +91,16 @@ render(struct output *output)
double sx = (double)img_width / (width * scale);
double sy = (double)img_height / (height * scale);
+ float s = sx > sy ? sy : sx;
+ sx = s;
+ sy = s;
+
+ float tx = (img_width / sx - width) / 2 / sx;
+ float ty = (img_height / sy - height) / 2 / sy;
+
pixman_f_transform_t t;
pixman_transform_t t2;
+ pixman_f_transform_init_translate(&t, tx, ty);
pixman_f_transform_init_scale(&t, sx, sy);
pixman_transform_from_pixman_f_transform(&t2, &t);
pixman_image_set_transform(pix, &t2);