// Resample returns a resampled copy of the image slice r of m.
// The returned image has width w and height h.
341130
func Resample(m image.Image, r image.Rectangle, w, h int) image.Image {
	if w < 0 || h < 0 {
		return nil
	}
	if w == 0 || h == 0 || r.Dx() <= 0 || r.Dy() <= 0 {
		return image.NewRGBA64(image.Rect(0, 0, w, h))
	}
	img := image.NewRGBA(image.Rect(0, 0, w, h))
	xStep := float64(r.Dx()) / float64(w)
	yStep := float64(r.Dy()) / float64(h)
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			xSrc := int(float64(r.Min.X) + float64(x)*xStep)
			ySrc := int(float64(r.Min.Y) + float64(y)*yStep)
			r, g, b, a := m.At(xSrc, ySrc).RGBA()
			img.SetRGBA(x, y, color.RGBA{
				R: uint8(r >> 8),
				G: uint8(g >> 8),
				B: uint8(b >> 8),
				A: uint8(a >> 8),
			})
		}
	}
	return img
}
568970
func (s *UniformSample) Mean() float64 {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	return SampleMean(s.values)
}
525652
func Grayscale(img image.Image) *image.NRGBA {
	src := newScanner(img)
	dst := image.NewNRGBA(image.Rect(0, 0, src.w, src.h))
	parallel(0, src.h, func(ys <-chan int) {
		for y := range ys {
			i := y * dst.Stride
			src.scan(0, y, src.w, y+1, dst.Pix[i:i+src.w*4])
			for x := 0; x < src.w; x++ {
				d := dst.Pix[i : i+3 : i+3]
				r := d[0]
				g := d[1]
				b := d[2]
				f := 0.299*float64(r) + 0.587*float64(g) + 0.114*float64(b)
				y := uint8(f + 0.5)
				d[0] = y
				d[1] = y
				d[2] = y
				i += 4
			}
		}
	})
	return dst
}
23667
func Crop(img image.Image, rect image.Rectangle) *image.NRGBA {
	r := rect.Intersect(img.Bounds()).Sub(img.Bounds().Min)
	if r.Empty() {
		return &image.NRGBA{}
	}
	src := newScanner(img)
	dst := image.NewNRGBA(image.Rect(0, 0, r.Dx(), r.Dy()))
	rowSize := r.Dx() * 4
	parallel(r.Min.Y, r.Max.Y, func(ys <-chan int) {
		for y := range ys {
			i := (y - r.Min.Y) * dst.Stride
			src.scan(r.Min.X, y, r.Max.X, y+1, dst.Pix[i:i+rowSize])
		}
	})
	return dst
}
52812
func StringSample(stringList ...string) string {
	str := ""
	if len(stringList) > 0 {
		str = stringList[Number(0, len(stringList))]
	}
	return str
}
794363
func (s *Static) GetSampleRate(key string) int {
	if rate, found := s.Rates[key]; found {
		return rate
	}
	return s.Default
}
1325483
func (t *TotalThroughput) GetSampleRate(key string) int {
	t.lock.Lock()
	defer t.lock.Unlock()
	t.currentCounts[key]++
	if rate, found := t.savedSampleRates[key]; found {
		return rate
	}
	return 1
}
534413
func resize(bs []byte, size int) []byte {
	if cap(bs) < size {
		return make([]byte, size)
	}
	return bs[:size]
}
1208029
func (orig *SampleFJSON) Convert() (*SampleF, error) {
	ret := &SampleF{}

	b := NewSampleFJSONBuilder().AddAll()
	for _, info := range b._properties {
		if err := info.Decoder(orig, ret); err != nil {
			return nil, err
		}
	}

	return ret, nil
}
385623
func Rescale(input, fromMin, fromMax, toMin, toMax float64) float64 {
	return (input-fromMin)*(toMax-toMin)/(fromMax-fromMin) + toMin
}
1127078
func (other *Surface) CreateSimilarImage(format Format, width, height int) *Surface {
	ret := wrapSurface(C.cairo_surface_create_similar_image(other.Ptr, C.cairo_format_t(format), C.int(width), C.int(height)))
	if err := other.status(); err != nil {
		panic(err)
	}
	return ret
}
1324923
func (s *RemotelyControlledSampler) IsSampled(id TraceID, operation string) (bool, []Tag) {
	s.RLock()
	defer s.RUnlock()
	return s.sampler.IsSampled(id, operation)
}
573215
func (w *Wav) ReadSamples(n int) (interface{}, error) {
	var data interface{}
	switch w.AudioFormat {
	case wavFormatPCM:
		switch w.BitsPerSample {
		case 8:
			data = make([]uint8, n)
		case 16:
			data = make([]int16, n)
		default:
			return nil, fmt.Errorf("wav: unknown bits per sample: %v", w.BitsPerSample)
		}
	case wavFormatIEEEFloat:
		data = make([]float32, n)
	default:
		return nil, fmt.Errorf("wav: unknown audio format")
	}
	if err := binary.Read(w.r, binary.LittleEndian, data); err != nil {
		return nil, err
	}
	return data, nil
}
768865
func parseHeapSample(line string, rate int64, sampling string) (value []int64, blocksize int64, addrs []uint64, err error) {
	sampleData := heapSampleRE.FindStringSubmatch(line)
	if len(sampleData) != 6 {
		return value, blocksize, addrs, fmt.Errorf("unexpected number of sample values: got %d, want 6", len(sampleData))
	}

	// Use first two values by default; tcmalloc sampling generates the
	// same value for both, only the older heap-profile collect separate
	// stats for in-use and allocated objects.
	valueIndex := 1
	if LegacyHeapAllocated {
		valueIndex = 3
	}

	var v1, v2 int64
	if v1, err = strconv.ParseInt(sampleData[valueIndex], 10, 64); err != nil {
		return value, blocksize, addrs, fmt.Errorf("malformed sample: %s: %v", line, err)
	}
	if v2, err = strconv.ParseInt(sampleData[valueIndex+1], 10, 64); err != nil {
		return value, blocksize, addrs, fmt.Errorf("malformed sample: %s: %v", line, err)
	}

	if v1 == 0 {
		if v2 != 0 {
			return value, blocksize, addrs, fmt.Errorf("allocation count was 0 but allocation bytes was %d", v2)
		}
	} else {
		blocksize = v2 / v1
		if sampling == "v2" {
			v1, v2 = scaleHeapSample(v1, v2, rate)
		}
	}

	value = []int64{v1, v2}
	addrs = parseHexAddresses(sampleData[5])

	return value, blocksize, addrs, nil
}
744916
func (s *AacSettings) SetSampleRate(v float64) *AacSettings {
	s.SampleRate = &v
	return s
}
121719
func (s *BasicSampler) Sample(lvl Level) bool {
	c := atomic.AddUint32(&s.counter, 1)
	return c%s.N == s.N-1
}
77210
func (w *Writer) WriteSample(sample []byte) error {
	if len(sample)*8 != int(w.options.SignificantBits) {
		return fmt.Errorf("incorrect Sample Length %d", len(sample))
	}

	n, err := w.sampleBuf.Write(sample)
	if err != nil {
		return err
	}

	w.bytesWritten += n

	return nil
}