Skip to content

Instantly share code, notes, and snippets.

@Sciss
Created June 12, 2019 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sciss/5165202d0921ff58a3790994ffbeb8a2 to your computer and use it in GitHub Desktop.
Save Sciss/5165202d0921ff58a3790994ffbeb8a2 to your computer and use it in GitHub Desktop.
val in0 = ImageFileIn("in")
val wIn = in0.width
val hIn = in0.height
val wOut = "width".attr(1920)
val hOut = "height".attr(1080)
val num = "num-frames".attr(100)
val gamma = "gamma".attr(1.0)
val szIn = wIn * hIn
val szOut = wOut * hOut
val in = RepeatWindow(in0, szIn, num)
val zoomEnd = (wOut / wIn) min (hOut / hIn)
val idxOut = ArithmSeq(start = 1, length = num)
//val sx = Line(1.0, zoomEnd, length = num)
val sx = idxOut.linExp(1, num, 1.0, zoomEnd)
//val sx = Line(zoomEnd, zoomEnd, length = num)
val sy = sx
//val sxW = RepeatWindow(sx, 1, szOut)
//val syW = RepeatWindow(sy, 1, szOut)
//val txW = RepeatWindow(tx, 1, szOut)
//val tyW = RepeatWindow(ty, 1, szOut)
//sxW.poll(Metro(szOut), "sx")
//syW.poll(Metro(szOut), "sy")
//txW.poll(Metro(szOut), "tx")
//tyW.poll(Metro(szOut), "ty")
wIn.poll(0, "width-in")
hIn.poll(0, "height-in")
zoomEnd.poll(0, "zoom-end")
val sx1 = sx.sqrt
val sy1 = sy.sqrt
val sx2 = sx1
val sy2 = sy1
val wFull1 = wIn * sx1
val hFull1 = hIn * sy1
val tx1 = 0.0 // (wIn - wFull1) * 0.5
val ty1 = 0.0 // (hIn - hFull1) * 0.5
val wFull2 = wFull1 * sx2
val hFull2 = hFull1 * sy2
val tx2 = (wOut - wFull2) * 0.5
val ty2 = (hOut - hFull2) * 0.5
val sxW1 = RepeatWindow(sx1, 1, szIn)
val syW1 = RepeatWindow(sy1, 1, szIn)
val txW1 = RepeatWindow(tx1, 1, szIn)
val tyW1 = RepeatWindow(ty1, 1, szIn)
val sxW2 = RepeatWindow(sx2, 1, szOut)
val syW2 = RepeatWindow(sy2, 1, szOut)
val txW2 = RepeatWindow(tx2, 1, szOut)
val tyW2 = RepeatWindow(ty2, 1, szOut)
val zoom1 =
AffineTransform2D(in,
widthIn = wIn, heightIn = hIn, widthOut = wIn, heightOut = hIn,
m00 = sxW1, m11 = syW1, m02 = txW1, m12 = tyW1, m01 = 0.0, m10 = 0.0,
zeroCrossings = 0, wrap = 0
)
val zoom = AffineTransform2D(zoom1,
widthIn = wIn, heightIn = hIn, widthOut = wOut, heightOut = hOut,
m00 = sxW2, m11 = syW2, m02 = txW2, m12 = tyW2, m01 = 0.0, m10 = 0.0,
zeroCrossings = 0, wrap = 0
)
val adj = If (gamma sig_== 1.0) Then {
zoom
} Else {
zoom.pow(gamma.reciprocal)
}
val out = adj.clip(0.0, 1.0)
ImageFileSeqOut("out", out, width = wOut, height = hOut,
quality = 95, indices = idxOut)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment