From ac3da8180268b5d121ea83866de5bfe0e8998045 Mon Sep 17 00:00:00 2001 From: Giuseppe Barbieri Date: Thu, 19 Mar 2020 10:07:25 +0100 Subject: [PATCH] fixed BufferedImage.flipY --- src/main/kotlin/gli_/misc.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/gli_/misc.kt b/src/main/kotlin/gli_/misc.kt index 37d538a..6a3d998 100644 --- a/src/main/kotlin/gli_/misc.kt +++ b/src/main/kotlin/gli_/misc.kt @@ -5,10 +5,12 @@ import kool.lib.toByteArray import kool.pos import org.lwjgl.BufferUtils import java.awt.image.BufferedImage +import java.io.File import java.net.URI import java.nio.ByteBuffer import java.nio.file.Path import java.nio.file.Paths +import javax.imageio.ImageIO infix fun Int.has(b: Int) = (this and b) != 0 infix fun Int.hasnt(b: Int) = (this and b) == 0 @@ -35,12 +37,20 @@ operator fun Array.get(index: Format): dx.Format = get(index.i - Format.FIRST.i) fun BufferedImage.flipY() { - lateinit var scanline1: Any - lateinit var scanline2: Any + var scanline1: Any? = null + var scanline2: Any? = null for (i in 0 until height / 2) { scanline1 = raster.getDataElements(0, i, width, 1, scanline1) scanline2 = raster.getDataElements(0, height - i - 1, width, 1, scanline2) raster.setDataElements(0, i, width, 1, scanline2) raster.setDataElements(0, height - i - 1, width, 1, scanline1) } -} \ No newline at end of file +} + +//fun main() { +// val file = File("C:\\Users\\elect\\Pictures\\1.png") +// println(file.exists() && file.canRead()) +// val image = ImageIO.read(file) +// image.flipY() +// ImageIO.write(image, "png", File("flipped.png")) +//} \ No newline at end of file