@@ -30,6 +30,11 @@ fun F64Array.Companion.fromImage(img: BufferedImage): F64ImageArray {
3030 val h = img.height
3131 val hasAlpha = img.alphaRaster != null
3232 val pxData = (img.raster.dataBuffer as DataBufferByte ).data
33+ val (r, g, b) = when (img.type) {
34+ BufferedImage .TYPE_INT_RGB , BufferedImage .TYPE_INT_ARGB -> Triple (0 , 1 , 2 )
35+ BufferedImage .TYPE_INT_BGR , BufferedImage .TYPE_3BYTE_BGR , BufferedImage .TYPE_4BYTE_ABGR -> Triple (2 , 1 , 0 )
36+ else -> throw UnsupportedOperationException (" Unknown image type ${img.type} , please open an issue!" )
37+ }
3338 val arr = F64Array (w, h, 4 ).image
3439 val pxSize = if (hasAlpha) 4 else 3
3540
@@ -38,14 +43,14 @@ fun F64Array.Companion.fromImage(img: BufferedImage): F64ImageArray {
3843 val idx = (x + y * w) * pxSize
3944 if (hasAlpha) {
4045 arr[x, y, 3 ] = pxData[idx].toInt().asColorDouble()
41- arr[x, y, 0 ] = pxData[idx + 1 ].toInt().asColorDouble()
42- arr[x, y, 1 ] = pxData[idx + 2 ].toInt().asColorDouble()
43- arr[x, y, 2 ] = pxData[idx + 3 ].toInt().asColorDouble()
46+ arr[x, y, r ] = pxData[idx + 1 ].toInt().asColorDouble()
47+ arr[x, y, g ] = pxData[idx + 2 ].toInt().asColorDouble()
48+ arr[x, y, b ] = pxData[idx + 3 ].toInt().asColorDouble()
4449 } else {
4550 arr[x, y, 3 ] = 1.0
46- arr[x, y, 0 ] = pxData[idx].toInt().asColorDouble()
47- arr[x, y, 1 ] = pxData[idx + 1 ].toInt().asColorDouble()
48- arr[x, y, 2 ] = pxData[idx + 2 ].toInt().asColorDouble()
51+ arr[x, y, r ] = pxData[idx].toInt().asColorDouble()
52+ arr[x, y, g ] = pxData[idx + 1 ].toInt().asColorDouble()
53+ arr[x, y, b ] = pxData[idx + 2 ].toInt().asColorDouble()
4954 }
5055 }
5156 }
0 commit comments