aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.cpp
diff options
context:
space:
mode:
authorTadao Tanikawa <tanikawa.tadao@jp.panasonic.com>2018-05-16 09:48:31 +0000
committerTadao Tanikawa <tanikawa.tadao@jp.panasonic.com>2018-05-16 09:48:31 +0000
commitdcdcfe175174a0a94997fc3d3d34102b0912b00e (patch)
tree55f01242217cda946344c9a0248271e50e62bfee /src/util.cpp
parent33ee7d8a99c540749dd9691362f109c5b884e588 (diff)
Enable scaling
Fit screen, keep aspect rate. Change-Id: Id11a07560fe254712aaab42018bfb4d1d87ad1df Signed-off-by: Tadao Tanikawa <tanikawa.tadao@jp.panasonic.com>
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 2ae856f..068e7b8 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -37,3 +37,30 @@ unique_fd::~unique_fd() {
close(this->fd);
}
}
+
+void rectangle::scale(int to_w, int to_h, bool keep_aspect)
+{
+ if (!keep_aspect) {
+ w = to_w;
+ h = to_h;
+ return;
+ }
+
+ int64_t resized_w = int64_t(to_h) * int64_t(w) / int64_t(h);
+
+ if (resized_w <= to_w) {
+ /* use aspect by height */
+ w = resized_w;
+ h = to_h;
+ } else {
+ /* use aspect by width */
+ w = to_h;
+ h = int64_t(to_h) * int64_t(h) / int64_t(w);
+ }
+}
+
+void rectangle::center(int outer_w, int outer_h)
+{
+ x = (outer_w - w) / 2;
+ y = (outer_h - h) / 2;
+}