Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
elect86 committed May 27, 2020
2 parents 185ba37 + ac3da81 commit 290b4a7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/kotlin/gli_/misc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,12 +37,20 @@ operator fun Array<dx.Format>.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)
}
}
}

//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"))
//}

0 comments on commit 290b4a7

Please sign in to comment.