mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +09:00
special resizing key to fit within screen
This commit is contained in:
@@ -14,7 +14,7 @@ dma.comToRam(0, 0, infile, fileLen)
|
||||
println("decoding")
|
||||
|
||||
// decode
|
||||
const [imgw, imgh, imageData] = graphics.decodeImageResample(infile, fileLen, 0, 448)
|
||||
const [imgw, imgh, imageData] = graphics.decodeImageResample(infile, fileLen, -1, -1)
|
||||
|
||||
println(`dim: ${imgw}x${imgh}`)
|
||||
println(`converting to displayable format...`)
|
||||
|
||||
@@ -202,8 +202,10 @@ class GraphicsJSR223Delegate(val vm: VM) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param width0 new image width. If either width or height is zero, the resulting image will be proportionally scaled using the other value. If both are zero, original image dimension will be used.
|
||||
* @param height0 new image height. If either width or height is zero, the resulting image will be proportionally scaled using the other value. If both are zero, original image dimension will be used.
|
||||
* Special number for width and height:
|
||||
* - If either width or height is zero, the resulting image will be proportionally scaled using the other value
|
||||
* - If both are zero, original image dimension will be used.
|
||||
* - If both are -1, image will be resized so that the entire picture fits into the screen.
|
||||
*
|
||||
* Will always return 4-channel image data
|
||||
*/
|
||||
@@ -216,8 +218,21 @@ class GraphicsJSR223Delegate(val vm: VM) {
|
||||
UnsafeHelper.memcpyRaw(null, vm.usermem.ptr + srcFilePtr, data, UnsafeHelper.getArrayOffset(data), srcFileLen.toLong())
|
||||
|
||||
val inPixmap = Pixmap(data, 0, data.size)
|
||||
val gpu = getFirstGPU()
|
||||
|
||||
if (width <= 0 && height <= 0) {
|
||||
if (width <= -1.0 && height <= -1.0 && gpu != null) {
|
||||
if (inPixmap.width > inPixmap.height) {
|
||||
val scale = inPixmap.height.toFloat() / inPixmap.width.toFloat()
|
||||
width = gpu.config.width
|
||||
height = (width * scale).roundToInt()
|
||||
}
|
||||
else {
|
||||
val scale = inPixmap.width.toFloat() / inPixmap.height.toFloat()
|
||||
height = gpu.config.height
|
||||
width = (height * scale).roundToInt()
|
||||
}
|
||||
}
|
||||
else if (width == 0 && height == 0) {
|
||||
width = inPixmap.width
|
||||
height = inPixmap.height
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user