liuxiaolong
2019-08-22 f4e8f206a6760bdc31734dfcb1c65916b5b76311
extend/util/util.go
@@ -7,6 +7,7 @@
   "errors"
   "github.com/gin-gonic/gin"
   "github.com/golang/glog"
   "github.com/pierrec/lz4"
   "gocv.io/x/gocv"
   "image"
   "net"
@@ -192,6 +193,37 @@
}
func ParseScore(compareScore float32) float32 {
   f, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", compareScore*100), 32)
   if compareScore < 1 {
      compareScore = compareScore * 100
   }
   f, _ := strconv.ParseFloat(fmt.Sprintf("%2.2f", compareScore), 32)
   return float32(f)
}
}
// UnCompress uncompress
func UnCompress(in []byte) ([]byte, error) {
   out := make([]byte, 10*len(in))
   n, err := lz4.UncompressBlock(in, out)
   if err != nil {
      fmt.Println(err)
      return nil, err
   }
   out = out[:n] // uncompressed data
   return out, nil
}
// Compress compress
func Compress(in []byte) ([]byte, error) {
   out := make([]byte, len(in))
   ht := make([]int, 64<<10) // buffer for the compression table
   n, err := lz4.CompressBlock(in, out, ht)
   if err != nil {
      fmt.Println(err)
      return nil, err
   }
   if n >= len(in) {
      fmt.Println("image is not compressible")
   }
   out = out[:n] // compressed data
   return out, nil
}