All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sksamuel.scrimage.format.png.PaethPredictor.kt Maven / Gradle / Ivy

package com.sksamuel.scrimage.format.png

import kotlin.math.abs

object PaethPredictor {
   fun predict(left: Int, up: Int, upleft: Int): Int {
      val p = left + up - upleft   // initial estimate
      val pa = abs(p - left) // distances to a, b, c
      val pb = abs(p - up)
      val pc = abs(p - upleft)
      // return nearest of a, b, c
      // breaking ties in order a, b, c
      return when {
         pa <= pb && pa <= pc -> left
         pb <= pc -> up
         else -> upleft
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy