diff options
author | Manuel Reimer <manuel.reimer@gmx.de> | 2014-11-09 10:57:12 +0100 |
---|---|---|
committer | Manuel Reimer <manuel.reimer@gmx.de> | 2014-11-09 10:57:12 +0100 |
commit | 0d5773cb7f1748b5cf2f338ac41c1a9b8f99b664 (patch) | |
tree | 5544d59102e6efb52bf5ee64baa7fc9afb0696b7 /libcore | |
parent | 28413f7f2cd6299d3418a43a81b643ac04cdc67e (diff) | |
download | vdr-plugin-skindesigner-0d5773cb7f1748b5cf2f338ac41c1a9b8f99b664.tar.gz vdr-plugin-skindesigner-0d5773cb7f1748b5cf2f338ac41c1a9b8f99b664.tar.bz2 |
Center scaled image in the available target space when preserving aspect
Diffstat (limited to 'libcore')
-rw-r--r-- | libcore/imageloader.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/libcore/imageloader.c b/libcore/imageloader.c index a0247ac..d3f02fe 100644 --- a/libcore/imageloader.c +++ b/libcore/imageloader.c @@ -33,10 +33,17 @@ cImage *cImageLoader::CreateImage(int width, int height, bool preserveAspect) { double sx = width / (double)w; double sy = height / (double)h; if (preserveAspect) { - if (sx < sy) + double tx = 0; + double ty = 0; + if (sx < sy) { sy = sx; - if (sy < sx) + ty = (height - h * sy) / 2; + } + if (sy < sx) { sx = sy; + tx = (width - w * sx) / 2; + } + cairo_translate(cr, tx, ty); } cairo_scale(cr, sx, sy); |