in plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/util/pngj/ChunkSeqReader.kt [187:218]
protected open fun startNewChunk(len: Int, id: String, offset: Long) {
println("New chunk: $id $len off:$offset")
// check id an length
if (id.length != 4 || id.all { it !in 'a'..'z' && it !in 'A'..'Z' }) throw PngjInputException("Bad chunk id: $id")
if (len < 0) throw PngjInputException("Bad chunk len: $len")
if (id == ChunkHelper.IDAT) idatBytes += len.toLong()
val checkCrc = shouldCheckCrc(len, id)
val skip = shouldSkipContent(len, id)
val isIdatType = isIdatKind(id)
// PngHelperInternal.debug("start new chunk id=" + id + " off=" + offset + "
// skip=" + skip + " idat=" +
// isIdatType);
// first see if we should terminate an active curReaderDeflatedSet
var forCurrentIdatSet = false
if (curDeflatedSet != null && !curDeflatedSet!!.isClosed) forCurrentIdatSet = curDeflatedSet!!.ackNextChunkId(id)
if (isIdatType && !skip) { // IDAT non skipped: create a DeflatedChunkReader owned by a idatSet
if (!forCurrentIdatSet) {
if (curDeflatedSet != null && !curDeflatedSet!!.isDone) throw PngjInputException("new IDAT-like chunk when previous was not done")
curDeflatedSet = createIdatSet(id)
}
curChunkReader = object : DeflatedChunkReader(len, id, checkCrc, offset, curDeflatedSet!!) {
override fun chunkDone() {
super.chunkDone()
postProcessChunk(this)
}
}
} else { // for non-idat chunks (or skipped idat like)
curChunkReader = createChunkReaderForNewChunk(id, len, offset, skip)
}
if (curChunkReader != null && !checkCrc) curChunkReader!!.setCrcCheck(false)
}