fun computeHistogramForFilter()

in plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/util/pngj/pixels/FiltersPerformance.kt [104:176]


    fun computeHistogramForFilter(filterType: FilterType, rowb: ByteArray?, rowbprev: ByteArray?) {
        fill(histog, 0)
        var i: Int
        var j: Int
        val imax: Int = iminfo.bytesPerRow
        when (filterType) {
            FilterType.FILTER_NONE -> {
                i = 1
                while (i <= imax) {
                    histog[rowb!![i].toInt() and 0xFF]++
                    i++
                }
            }

            FilterType.FILTER_PAETH -> {
                i = 1
                while (i <= imax) {
                    histog[PngHelperInternal.filterRowPaeth(rowb!![i].toInt(), 0, rowbprev!![i].toInt() and 0xFF, 0)]++
                    i++
                }
                j = 1
                i = iminfo.bytesPixel + 1
                while (i <= imax) {
                    histog[PngHelperInternal.filterRowPaeth(
                        rowb!![i].toInt(), rowb[j].toInt() and 0xFF, rowbprev!![i].toInt() and 0xFF,
                        rowbprev[j].toInt() and 0xFF
                    )]++
                    i++
                    j++
                }
            }

            FilterType.FILTER_SUB -> {
                i = 1
                while (i <= iminfo.bytesPixel) {
                    histog[rowb!![i].toInt() and 0xFF]++
                    i++
                }
                j = 1
                i = iminfo.bytesPixel + 1
                while (i <= imax) {
                    histog[rowb!![i] - rowb[j] and 0xFF]++
                    i++
                    j++
                }
            }

            FilterType.FILTER_UP -> {
                i = 1
                while (i <= iminfo.bytesPerRow) {
                    histog[rowb!![i] - rowbprev!![i] and 0xFF]++
                    i++
                }
            }

            FilterType.FILTER_AVERAGE -> {
                i = 1
                while (i <= iminfo.bytesPixel) {
                    histog[(rowb!![i].toInt() and 0xFF) - (rowbprev!![i].toInt() and 0xFF) / 2 and 0xFF]++
                    i++
                }
                j = 1
                i = iminfo.bytesPixel + 1
                while (i <= imax) {
                    histog[(rowb!![i].toInt() and 0xFF) - ((rowbprev!![i].toInt() and 0xFF) + (rowb[j].toInt() and 0xFF)) / 2 and 0xFF]++
                    i++
                    j++
                }
            }

            else -> throw PngjExceptionInternal("Bad filter:$filterType")
        }
    }