Skip to content

Commit c879123

Browse files
authored
jvm: update internal 'readPixmap' to use stbimage instead of ImageIO (#281)
1 parent 1ddde4f commit c879123

File tree

2 files changed

+4
-210
lines changed

2 files changed

+4
-210
lines changed

core/src/jvmMain/kotlin/com/littlekt/file/ImageUtils.kt

Lines changed: 0 additions & 198 deletions
This file was deleted.

core/src/jvmMain/kotlin/com/littlekt/file/vfs/VfsLoaders.jvm.kt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,25 @@ import com.littlekt.audio.AudioStream
66
import com.littlekt.audio.OpenALAudioClip
77
import com.littlekt.audio.OpenALAudioStream
88
import com.littlekt.file.ByteBufferImpl
9-
import com.littlekt.file.ImageUtils
109
import com.littlekt.file.JvmByteSequenceStream
1110
import com.littlekt.graphics.Pixmap
1211
import com.littlekt.graphics.PixmapTexture
1312
import com.littlekt.graphics.Texture
1413
import com.littlekt.graphics.webgpu.TextureFormat
1514
import com.littlekt.log.Logger
16-
import fr.delthas.javamp3.Sound
15+
import fr.delthas.javamp3.Soundgit
1716
import java.io.ByteArrayInputStream
1817
import java.nio.ByteBuffer
1918
import java.nio.IntBuffer
20-
import javax.imageio.ImageIO
2119
import javax.sound.sampled.AudioSystem
2220
import org.lwjgl.stb.STBImage.*
2321
import org.lwjgl.system.MemoryStack
2422
import org.lwjgl.system.MemoryUtil
2523

2624
private val logger = Logger("VfsLoaders")
27-
private val imageIoLock = Any()
2825

2926
/** Reads Base64 encoded ByteArray for embedded images. */
30-
internal actual suspend fun ByteArray.readPixmap(): Pixmap {
31-
// ImageIO.read is not thread safe!
32-
val img = synchronized(imageIoLock) { ImageIO.read(ByteArrayInputStream(this)) }
33-
val result = ImageUtils.bufferedImageToBuffer(img, "RGBA", img.width, img.height)
34-
return Pixmap(img.width, img.height, result.buffer)
35-
}
27+
internal actual suspend fun ByteArray.readPixmap(): Pixmap = readPixmap(this)
3628

3729
/**
3830
* Loads an image from the path as a [Pixmap].
@@ -128,7 +120,7 @@ private suspend fun VfsFile.createAudioStreamMp3(): OpenALAudioStream {
128120
read,
129121
reset,
130122
channels,
131-
decoder.samplingFrequency
123+
decoder.samplingFrequency,
132124
)
133125
}
134126

@@ -153,6 +145,6 @@ private suspend fun VfsFile.createAudioStreamWav(): OpenALAudioStream {
153145
read,
154146
reset,
155147
clip.format.channels,
156-
clip.format.sampleRate.toInt()
148+
clip.format.sampleRate.toInt(),
157149
)
158150
}

0 commit comments

Comments
 (0)