github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/color/utils.go (about)

     1  // Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package color
     6  
     7  import (
     8  	"math"
     9  )
    10  
    11  func f32ToU16(v float32) uint16 {
    12  	switch {
    13  	case v < 0:
    14  		return 0
    15  	case v > math.MaxUint16:
    16  		return math.MaxUint16
    17  	default:
    18  		return uint16(v)
    19  	}
    20  }