Example #1
0
// Blend a new pixel over an old pixel - heeding their alpha chan values
//
// algorithm NOT according to http://en.wikipedia.org/wiki/Alpha_compositing
//   but by my own trial and error
func blendPixelOverPixel(ic_old, ic_new uint8, al_new float64) (c_res uint8) {

	al_old := float64(1)
	_ = al_old
	c_old := float64(ic_old)
	c_new := float64(ic_new)

	algo1 := c_old*(1-al_new) + c_new*al_new
	c_res = uint8(util.Min(util.Round(algo1), 255))
	//log.Printf("\t\t %3.1f +  %3.1f  = %3.1f", c_old*(1-al_new),c_new*al_new, algo1)

	return
}
Example #2
0
func logRetrieve(w http.ResponseWriter, r *http.Request) {

	cgiRes := makeRequest(w, r, path_get_log)

	sl := []string{cgiRes.Log0, cgiRes.Log1, cgiRes.Log2, cgiRes.Log3, cgiRes.Log4,
		cgiRes.Log5, cgiRes.Log6, cgiRes.Log7, cgiRes.Log8, cgiRes.Log9}

	for _, v := range sl {
		sl1 := strings.Split(v, "%2B")
		if len(sl1) < 4 {
			continue
		}

		// 		 time+user+ip+logID
		unixTS := sl1[0]
		usr := sl1[1]
		ip := sl1[2]
		eventId := sl1[3]
		eventDesc := ""
		switch eventId {
		case "0":
			eventDesc = "Power On"
		case "1":
			eventDesc = "Motion Alarm"
		case "3":
			eventDesc = "Login"
		case "4":
			eventDesc = "Logout"
		case "5":
			eventDesc = "Offline"
		default:
			eventDesc = "unkown event id: " + eventId
		}
		_, _, _ = eventDesc, usr, ip

		ts := util.TimeFromUnix(unixTS)
		tsf := ts.Format("2.1.2006 15:04:05")

		tn := time.Now()
		since := tn.Sub(ts)
		iHours := int(math.Floor(since.Hours()))
		iMinutes := util.Round(since.Minutes()) - iHours*60

		if eventId == "1" {
			wpf(w, "Last Alarm <b>%3vhrs %2vmin</b> ago (%v)<br>\n", iHours, iMinutes, tsf)
			break
		}
	}

}
Example #3
0
// returns a format string with as few as needed
//   post-decimal digits ;  1000 => 1000 , but 0.0400 => 0.04
func practicalFormat(mv float64) (floatFormat string, exponent int) {

	//Log x    =    Ln x / Ln 10
	fExponent := math.Log(mv) / math.Log(10)
	//exponent  = int(fExponent)
	exponent = util.Round(fExponent)

	sExponent := fmt.Sprint(util.Abs(exponent) + 2)
	floatFormat = "%12.0f"
	if mv < 10 {
		floatFormat = "%12.1f"
	}
	if mv < 1 {
		floatFormat = "%12." + sExponent + "f"
	}

	return
}