special resizing key to fit within screen

This commit is contained in:
minjaesong
2022-04-07 14:07:33 +09:00
parent 23579b3809
commit 4ec8692e04
2 changed files with 19 additions and 4 deletions

View File

@@ -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...`)

View File

@@ -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
}