30 lines
673 B
Go
30 lines
673 B
Go
package main
|
|
|
|
import (
|
|
"gonum.org/v1/gonum/mat"
|
|
"math"
|
|
)
|
|
|
|
func LumaToFull16(l float64) uint16 {
|
|
return uint16(min(math.MaxUint16, max(0, int(math.Round(l*math.MaxUint16)))))
|
|
}
|
|
|
|
func ChromaToFull16(c float64) uint16 {
|
|
return uint16(min(math.MaxUint16, max(0, int(math.Round(c*math.MaxUint16+math.MaxInt16+1)))))
|
|
}
|
|
|
|
// RoundMatToPrecision Applies rounding to each Matrix entry to limit precision
|
|
func RoundMatToPrecision(m *mat.Dense, decimals int) *mat.Dense {
|
|
var o mat.Dense
|
|
if decimals <= 0 {
|
|
o.CloneFrom(m)
|
|
return &o
|
|
}
|
|
factor := 10. * float64(decimals)
|
|
|
|
o.Apply(func(i, j int, v float64) float64 {
|
|
return math.Round(v*factor) / factor
|
|
}, m)
|
|
return &o
|
|
}
|