diff --git a/assets/disk0/home/jpdectest.js b/assets/disk0/home/jpdectest.js index d151991..2d79535 100644 --- a/assets/disk0/home/jpdectest.js +++ b/assets/disk0/home/jpdectest.js @@ -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...`) diff --git a/tsvm_core/src/net/torvald/tsvm/GraphicsJSR223Delegate.kt b/tsvm_core/src/net/torvald/tsvm/GraphicsJSR223Delegate.kt index 11c2ad5..8b6d5ee 100644 --- a/tsvm_core/src/net/torvald/tsvm/GraphicsJSR223Delegate.kt +++ b/tsvm_core/src/net/torvald/tsvm/GraphicsJSR223Delegate.kt @@ -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 }