in plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/util/pngj/ImageLineByte.kt [77:150]
override fun readFromPngRaw(raw: ByteArray, len: Int, offset: Int, step: Int) {
filterType = FilterType.getByVal(raw[0].toInt()) // only for non interlaced line the filter is significative
val len1 = len - 1
val step1: Int = (step - 1) * imgInfo.channels
if (imgInfo.bitDepth == 8) {
if (step == 1) { // 8bispp non-interlaced: most important case, should be optimized
arraycopy(raw, 1, scanline, 0, len1)
} else { // 8bispp interlaced
var s = 1
var c = 0
var i: Int = offset * imgInfo.channels
while (s <= len1) {
scanline[i] = raw[s]
c++
if (c == imgInfo.channels) {
c = 0
i += step1
}
s++
i++
}
}
} else if (imgInfo.bitDepth == 16) {
if (step == 1) { // 16bispp non-interlaced
var i = 0
var s = 1
while (i < imgInfo.samplesPerRow) {
scanline[i] = raw[s++] // get the first byte
scanline2!![i] = raw[s++] // get the first byte
i++
}
} else {
var s = 1
var c = 0
var i = if (offset != 0) offset * imgInfo.channels else 0
while (s <= len1) {
scanline[i] = raw[s++]
scanline2!![i] = raw[s++]
c++
if (c == imgInfo.channels) {
c = 0
i += step1
}
i++
}
}
} else { // packed formats
val mask0: Int
var mask: Int
var shi: Int
val bd: Int
bd = imgInfo.bitDepth
mask0 = ImageLineHelper.getMaskForPackedFormats(bd)
var i: Int = offset * imgInfo.channels
var r = 1
var c = 0
while (r < len) {
mask = mask0
shi = 8 - bd
do {
scanline[i] = (raw[r].toInt() and mask shr shi).toByte()
mask = mask shr bd
shi -= bd
i++
c++
if (c == imgInfo.channels) {
c = 0
i += step1
}
} while (mask != 0 && i < size)
r++
}
}
}