From e5e0ee40b43eea10897468154a3f460f3a5a8111 Mon Sep 17 00:00:00 2001 From: Vishesh Yadav Date: Mon, 8 Jun 2015 17:40:09 -0400 Subject: [PATCH] Implement overlay/offset and underlay/offset functions in image --- whalesong/image/private/js-impl.js | 33 +++++++++++++++++++++++++ whalesong/image/private/main.rkt | 2 ++ whalesong/image/private/racket-impl.rkt | 4 +++ 3 files changed, 39 insertions(+) diff --git a/whalesong/image/private/js-impl.js b/whalesong/image/private/js-impl.js index ac1c00d..473243b 100644 --- a/whalesong/image/private/js-impl.js +++ b/whalesong/image/private/js-impl.js @@ -474,6 +474,22 @@ EXPORTS['overlay/xy'] = jsnums.toFixnum(deltaY)); }); +EXPORTS['overlay/offset'] = + makePrimitiveProcedure( + 'overlay/offset', + 4, + function(MACHINE) { + var img1 = checkImage(MACHINE, "overlay/offset", 0); + var deltaX = checkReal(MACHINE, "overlay/offset", 1); + var deltaY = checkReal(MACHINE, "overlay/offset", 2); + var img2 = checkImage(MACHINE, "overlay/offset", 3); + var middleX = (img1.getWidth() - img2.getWidth()) / 2; + var middleY = (img1.getHeight() - img2.getHeight()) / 2; + return makeOverlayImage(img1, + img2, + jsnums.toFixnum(middleX + deltaX), + jsnums.toFixnum(middleY + deltaY)); + }); EXPORTS['overlay/align'] = @@ -540,6 +556,23 @@ EXPORTS['underlay/xy'] = -(jsnums.toFixnum(deltaY))); }); +EXPORTS['underlay/offset'] = + makePrimitiveProcedure( + 'underlay/offset', + 4, + function(MACHINE) { + var img1 = checkImage(MACHINE, "underlay/offset", 0); + var deltaX = checkReal(MACHINE, "underlay/offset", 1); + var deltaY = checkReal(MACHINE, "underlay/offset", 2); + var img2 = checkImage(MACHINE, "underlay/offset", 3); + var middleX = (img1.getWidth() - img2.getWidth()) / 2; + var middleY = (img1.getHeight() - img2.getHeight()) / 2; + return makeOverlayImage(img2, + img1, + -jsnums.toFixnum(middleX + deltaX), + -jsnums.toFixnum(middleY + deltaY)); + }); + EXPORTS['underlay/align'] = makePrimitiveProcedure( 'underlay/align', diff --git a/whalesong/image/private/main.rkt b/whalesong/image/private/main.rkt index 0e71a16..d78e851 100644 --- a/whalesong/image/private/main.rkt +++ b/whalesong/image/private/main.rkt @@ -19,9 +19,11 @@ video/url play-sound overlay + overlay/offset overlay/xy overlay/align underlay + underlay/offset underlay/xy underlay/align beside diff --git a/whalesong/image/private/racket-impl.rkt b/whalesong/image/private/racket-impl.rkt index e3e57b8..362556a 100644 --- a/whalesong/image/private/racket-impl.rkt +++ b/whalesong/image/private/racket-impl.rkt @@ -5,9 +5,11 @@ (provide text text/font overlay + overlay/offset overlay/xy overlay/align underlay + underlay/offset underlay/xy underlay/align beside @@ -101,9 +103,11 @@ text text/font overlay + overlay/offset overlay/xy overlay/align underlay + underlay/offset underlay/xy underlay/align beside