fix fallback texture reading when alpha is in raster

This commit is contained in:
Moritz Zwerger 2023-11-05 18:25:22 +01:00
parent deeb997541
commit 06a98fedfe
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -57,17 +57,25 @@ object TextureUtil {
val byteOutput = ByteArrayOutputStream() val byteOutput = ByteArrayOutputStream()
val dataOutput = DataOutputStream(byteOutput) val dataOutput = DataOutputStream(byteOutput)
val samples = if (image.raster.numBands == 3) intArrayOf(0, 1, 2) else intArrayOf(0, 0, 0) val samples = when (image.raster.numBands) {
4 -> intArrayOf(0, 1, 2, 3)
3 -> intArrayOf(0, 1, 2)
else -> intArrayOf(0, 0, 0)
}
for (y in 0 until image.height) { for (y in 0 until image.height) {
for (x in 0 until image.width) { for (x in 0 until image.width) {
dataOutput.writeByte(image.raster.getSample(x, y, samples[0])) dataOutput.writeByte(image.raster.getSample(x, y, samples[0]))
dataOutput.writeByte(image.raster.getSample(x, y, samples[1])) dataOutput.writeByte(image.raster.getSample(x, y, samples[1]))
dataOutput.writeByte(image.raster.getSample(x, y, samples[2])) dataOutput.writeByte(image.raster.getSample(x, y, samples[2]))
if (samples.size > 3) {
dataOutput.writeByte(image.raster.getSample(x, y, samples[3]))
} else {
val alpha = image.alphaRaster?.getSample(x, y, 0) ?: 0xFF val alpha = image.alphaRaster?.getSample(x, y, 0) ?: 0xFF
dataOutput.writeByte(alpha) dataOutput.writeByte(alpha)
} }
} }
}
val buffer = MemoryUtil.memAlloc(byteOutput.size()) val buffer = MemoryUtil.memAlloc(byteOutput.size())
buffer.put(byteOutput.toByteArray()) buffer.put(byteOutput.toByteArray())