mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-09 16:45:46 -07:00
true nn upscale
This commit is contained in:
parent
341d6758c1
commit
c5ba4ecc94
1 changed files with 21 additions and 24 deletions
|
|
@ -43,6 +43,8 @@ import rt4.client.mainLoadState
|
||||||
import java.awt.*
|
import java.awt.*
|
||||||
import java.awt.Font
|
import java.awt.Font
|
||||||
import java.awt.event.*
|
import java.awt.event.*
|
||||||
|
import java.awt.geom.AffineTransform
|
||||||
|
import java.awt.image.AffineTransformOp
|
||||||
import java.awt.image.BufferedImage
|
import java.awt.image.BufferedImage
|
||||||
import java.awt.image.VolatileImage
|
import java.awt.image.VolatileImage
|
||||||
import javax.swing.*
|
import javax.swing.*
|
||||||
|
|
@ -153,12 +155,7 @@ class plugin : Plugin() {
|
||||||
|
|
||||||
class AltCanvas : Canvas() {
|
class AltCanvas : Canvas() {
|
||||||
private var gameImage: VolatileImage? = null
|
private var gameImage: VolatileImage? = null
|
||||||
private var flippedPixels = IntArray(FIXED_WIDTH * FIXED_HEIGHT)
|
|
||||||
private var bufferImage = BufferedImage(FIXED_WIDTH, FIXED_HEIGHT, BufferedImage.TYPE_INT_BGR)
|
private var bufferImage = BufferedImage(FIXED_WIDTH, FIXED_HEIGHT, BufferedImage.TYPE_INT_BGR)
|
||||||
private var scaleX = 1.0
|
|
||||||
private var scaleY = 1.0
|
|
||||||
private var offsetX = 0
|
|
||||||
private var offsetY = 0
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
isFocusable = true
|
isFocusable = true
|
||||||
|
|
@ -220,13 +217,10 @@ class plugin : Plugin() {
|
||||||
g2d.fillRect(0, 0, width, height)
|
g2d.fillRect(0, 0, width, height)
|
||||||
|
|
||||||
gameImage?.let { image ->
|
gameImage?.let { image ->
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)
|
val scale = minOf(width.toDouble() / image.width, height.toDouble() / image.height)
|
||||||
val (drawWidth, drawHeight) = calculateDrawDimensions(image)
|
val x = ((width - image.width * scale) / 2).toInt()
|
||||||
scaleX = drawWidth.toDouble() / image.width
|
val y = ((height - image.height * scale) / 2).toInt()
|
||||||
scaleY = drawHeight.toDouble() / image.height
|
g2d.drawImage(image, x, y, (image.width * scale).toInt(), (image.height * scale).toInt(), null)
|
||||||
offsetX = (width - drawWidth) / 2
|
|
||||||
offsetY = (height - drawHeight) / 2
|
|
||||||
g2d.drawImage(image, offsetX, offsetY, drawWidth, drawHeight, null)
|
|
||||||
Toolkit.getDefaultToolkit().sync()
|
Toolkit.getDefaultToolkit().sync()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -243,9 +237,14 @@ class plugin : Plugin() {
|
||||||
|
|
||||||
private fun relayMouseEvent(e: MouseEvent) {
|
private fun relayMouseEvent(e: MouseEvent) {
|
||||||
requestFocusInWindow()
|
requestFocusInWindow()
|
||||||
val adjustedX = ((e.x - offsetX) / scaleX).toInt().coerceIn(0, gameImage!!.width - 1)
|
val scale = minOf(width.toDouble() / gameImage!!.width, height.toDouble() / gameImage!!.height)
|
||||||
val adjustedY = ((e.y - offsetY) / scaleY).toInt().coerceIn(0, gameImage!!.height - 1)
|
val xOffset = ((width - gameImage!!.width * scale) / 2)
|
||||||
canvas.dispatchEvent(MouseEvent(canvas, e.id, e.`when`, e.modifiersEx, adjustedX, adjustedY, e.clickCount, e.isPopupTrigger, e.button))
|
val yOffset = ((height - gameImage!!.height * scale) / 2)
|
||||||
|
|
||||||
|
val adjustedX = ((e.x - xOffset) / scale).toInt().coerceIn(0, gameImage!!.width - 1)
|
||||||
|
val adjustedY = ((e.y - yOffset) / scale).toInt().coerceIn(0, gameImage!!.height - 1)
|
||||||
|
|
||||||
|
canvas.dispatchEvent(MouseEvent(this, e.id, e.`when`, e.modifiersEx, adjustedX, adjustedY, e.clickCount, e.isPopupTrigger, e.button))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun relayKeyEvent(e: KeyEvent, action: (KeyListener) -> Unit) {
|
private fun relayKeyEvent(e: KeyEvent, action: (KeyListener) -> Unit) {
|
||||||
|
|
@ -262,22 +261,20 @@ class plugin : Plugin() {
|
||||||
val height = gameImage!!.height
|
val height = gameImage!!.height
|
||||||
val pixelData = GlRenderer.pixelData
|
val pixelData = GlRenderer.pixelData
|
||||||
|
|
||||||
// Flip and copy pixels in one pass using a single loop
|
bufferImage.setRGB(0, 0, width, height, pixelData, 0, width)
|
||||||
for (y in 0 until height) {
|
|
||||||
val srcOffset = (height - 1 - y) * width
|
|
||||||
val destOffset = y * width
|
|
||||||
System.arraycopy(pixelData, srcOffset, flippedPixels, destOffset, width)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw flipped pixels directly to bufferImage
|
val transform = AffineTransform.getScaleInstance(1.0, -1.0)
|
||||||
bufferImage.setRGB(0, 0, width, height, flippedPixels, 0, width)
|
transform.translate(0.0, -height.toDouble())
|
||||||
|
val op = AffineTransformOp(transform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR)
|
||||||
|
val flippedImage = op.filter(bufferImage, null)
|
||||||
|
|
||||||
gameImage?.createGraphics()?.apply {
|
gameImage?.createGraphics()?.apply {
|
||||||
drawImage(bufferImage, 0, 0, null)
|
drawImage(flippedImage, 0, 0, null)
|
||||||
dispose()
|
dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun renderSoftwareRaster() {
|
private fun renderSoftwareRaster() {
|
||||||
gameImage?.createGraphics()?.apply {
|
gameImage?.createGraphics()?.apply {
|
||||||
SoftwareRaster.frameBuffer.draw(this)
|
SoftwareRaster.frameBuffer.draw(this)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue