// ImageWxH returns a screenshot at the ts milliseconds, scaled to the specified width and height.
236
func (g *Generator) ImageWxH(ts int64, width, height int) (image.Image, error) {
	frameNum := C.av_rescale(
		C.int64_t(ts),
		C.int64_t(g.streams[g.vStreamIndex].time_base.den),
		C.int64_t(g.streams[g.vStreamIndex].time_base.num),
	) / 1000
	if C.avformat_seek_file(
		g.avfContext,
		C.int(g.vStreamIndex),
		0,
		frameNum,
		frameNum,
		C.AVSEEK_FLAG_FRAME,
	) < 0 {
		if C.avformat_seek_file(
			g.avfContext,
			C.int(g.vStreamIndex),
			0,
			frameNum,
			frameNum,
			C.AVSEEK_FLAG_ANY,
		) < 0 {
			return nil, errors.New("can't seek to timestamp")
		}
	}
	img := image.NewRGBA(image.Rect(0, 0, width, height))
	frame := C.av_frame_alloc()
	defer C.av_frame_free(&frame)
	C.avcodec_flush_buffers(g.avcContext)
	pkt := C.av_packet_alloc()
	for C.av_read_frame(g.avfContext, pkt) == 0 {
		if int(pkt.stream_index) != g.vStreamIndex {
			C.av_packet_unref(pkt)
			continue
		}
		if C.avcodec_send_packet(g.avcContext, pkt) != 0 {
			C.av_packet_unref(pkt)
			return nil, errors.New("avcodec_send_packet failed")
		}
		dts := pkt.dts
		C.av_packet_unref(pkt)
		if ret := C.avcodec_receive_frame(g.avcContext, frame); ret != 0 {
			if ret != C.AVERROR_EAGAIN {
				return nil, errors.New("avcodec_receive_frame failed")
			}
			continue
		}
		if !g.Fast && dts < frameNum {
			continue
		}
		ctx := C.sws_getContext(
			C.int(g.width),
			C.int(g.height),
			g.avcContext.pix_fmt,
			C.int(width),
			C.int(height),
			C.AV_PIX_FMT_RGBA,
			C.SWS_BICUBIC,
			nil,
			nil,
			nil,
		)
		if ctx == nil {
			return nil, errors.New("can't allocate scaling context")
		}
		srcSlice := (**C.uint8_t)(&frame.data[0])
		srcStride := (*C.int)(&frame.linesize[0])
		hdr := (*reflect.SliceHeader)(unsafe.Pointer(&img.Pix))
		dst := (*C.uint8_t)(unsafe.Pointer(hdr.Data))
		dstStride := (*C.int)(unsafe.Pointer(&[1]int{img.Stride}))
		C.sws_scale_wrapper(
			ctx,
			srcSlice,
			srcStride,
			0,
			g.avcContext.height,
			dst,
			dstStride,
		)
		C.sws_freeContext(ctx)
		break
	}
	return img, nil
}
157298
func (_m *APIClient) ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error) {
	ret := _m.Called(ctx, term, options)

	var r0 []registry.SearchResult
	if rf, ok := ret.Get(0).(func(context.Context, string, types.ImageSearchOptions) []registry.SearchResult); ok {
		r0 = rf(ctx, term, options)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]registry.SearchResult)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(context.Context, string, types.ImageSearchOptions) error); ok {
		r1 = rf(ctx, term, options)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
1022684
func (win *Window) Image(img *image.RGBA) {
	s, bounds, fitting := win.widget()
	if fitting != nil {
		fitting(img.Bounds().Dx())
	}
	if !s {
		return
	}
	win.widgets.Add(nstyle.WidgetStateInactive, bounds)
	win.cmds.DrawImage(bounds, img)
}
251950
func IsPCX(src *sdl.RWops) bool {
	_src := (*C.SDL_RWops)(unsafe.Pointer(src))
	return int(C.IMG_isPCX(_src)) > 0
}
1305891
func (w *Window) GetX11Window() C.Window {
	ret := C.glfwGetX11Window(w.data)
	panicError()
	return ret
}
1290875
func (s *SSD1306Driver) ShowImage(img image.Image) (err error) {
	if img.Bounds().Dx() != s.DisplayWidth || img.Bounds().Dy() != s.DisplayHeight {
		return errors.New("Image must match the display width and height")
	}

	s.Clear()
	for y, w, h := 0, img.Bounds().Dx(), img.Bounds().Dy(); y < h; y++ {
		for x := 0; x < w; x++ {
			c := img.At(x, y)
			if r, g, b, _ := c.RGBA(); r > 0 || g > 0 || b > 0 {
				s.Set(x, y, 1)
			}
		}
	}
	return s.Display()
}
1116804
func ShearH(img image.Image, angle float64) *image.RGBA {
	src := clone.AsRGBA(img)
	srcW, srcH := src.Bounds().Dx(), src.Bounds().Dy()

	// Supersample, currently hard set to 2x
	srcW, srcH = srcW*2, srcH*2
	src = Resize(src, srcW, srcH, NearestNeighbor)

	// Calculate shear factor
	kx := math.Tan(angle * (math.Pi / 180))

	dstW, dstH := srcW+int(float64(srcH)*math.Abs(kx)), srcH
	dst := image.NewRGBA(image.Rect(0, 0, dstW, dstH))

	pivotX := float64(dstW) / 2
	pivotY := float64(dstH) / 2

	// Calculate offset since we are resizing the bounds to
	// fit the sheared image.
	dx := (dstW - srcW) / 2
	dy := (dstH - srcH) / 2

	parallel.Line(dstH, func(start, end int) {
		for y := start; y < end; y++ {
			for x := 0; x < dstW; x++ {
				// Move positions to revolve around pivot
				ix := x - int(pivotX) - dx
				iy := y - int(pivotY) - dy

				// Apply linear transformation
				ix = ix + int(float64(iy)*kx)

				// Move positions back to image coordinates
				ix += int(pivotX)
				iy += int(pivotY)

				if ix < 0 || ix >= srcW || iy < 0 || iy >= srcH {
					continue
				}

				srcPos := iy*src.Stride + ix*4
				dstPos := y*dst.Stride + x*4

				dst.Pix[dstPos+0] = src.Pix[srcPos+0]
				dst.Pix[dstPos+1] = src.Pix[srcPos+1]
				dst.Pix[dstPos+2] = src.Pix[srcPos+2]
				dst.Pix[dstPos+3] = src.Pix[srcPos+3]
			}
		}
	})

	// Downsample to original bounds as part of the Supersampling
	dst = Resize(dst, dstW/2, dstH/2, Linear)

	return dst
}
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
}
611406
func copyImage(img *v1alpha.Image) *v1alpha.Image {
	return &v1alpha.Image{
		BaseFormat:      img.BaseFormat,
		Id:              img.Id,
		Name:            img.Name,
		Version:         img.Version,
		ImportTimestamp: img.ImportTimestamp,
		Manifest:        img.Manifest,
		Size:            img.Size,
		Annotations:     img.Annotations,
		Labels:          img.Labels,
	}
}
764275
func Scale(dst draw.Image, src image.Image) error {
	if dst == nil {
		return errors.New("graphics: dst is nil")
	}
	if src == nil {
		return errors.New("graphics: src is nil")
	}

	b := dst.Bounds()
	srcb := src.Bounds()
	if b.Empty() || srcb.Empty() {
		return nil
	}
	sx := float64(b.Dx()) / float64(srcb.Dx())
	sy := float64(b.Dy()) / float64(srcb.Dy())
	return I.Scale(sx, sy).Transform(dst, src, interp.Bilinear)
}
255586
func Sharpen(img image.Image, sigma float64) *image.NRGBA {
	if sigma <= 0 {
		return Clone(img)
	}

	src := newScanner(img)
	dst := image.NewNRGBA(image.Rect(0, 0, src.w, src.h))
	blurred := Blur(img, sigma)

	parallel(0, src.h, func(ys <-chan int) {
		scanLine := make([]uint8, src.w*4)
		for y := range ys {
			src.scan(0, y, src.w, y+1, scanLine)
			j := y * dst.Stride
			for i := 0; i < src.w*4; i++ {
				val := int(scanLine[i])<<1 - int(blurred.Pix[j])
				if val < 0 {
					val = 0
				} else if val > 0xff {
					val = 0xff
				}
				dst.Pix[j] = uint8(val)
				j++
			}
		}
	})

	return dst
}
1326714
func (w *Webcam) SetImageFormat(f PixelFormat, width, height uint32) (PixelFormat, uint32, uint32, error) {

	code := uint32(f)
	cw := width
	ch := height

	err := setImageFormat(w.fd, &code, &width, &height)

	if err != nil {
		return 0, 0, 0, err
	} else {
		return PixelFormat(code), cw, ch, nil
	}
}
1303102
func convolve1dh(dst draw.Image, src image.Image, kernel []float32, options *Options) {
	srcb := src.Bounds()
	dstb := dst.Bounds()
	if srcb.Dx() <= 0 || srcb.Dy() <= 0 {
		return
	}
	if kernel == nil || len(kernel) < 1 {
		copyimage(dst, src, options)
		return
	}
	_, weights := prepareConvolutionWeights1d(kernel)
	pixGetter := newPixelGetter(src)
	pixSetter := newPixelSetter(dst)
	parallelize(options.Parallelization, srcb.Min.Y, srcb.Max.Y, func(start, stop int) {
		srcBuf := make([]pixel, srcb.Dx())
		dstBuf := make([]pixel, srcb.Dx())
		for y := start; y < stop; y++ {
			pixGetter.getPixelRow(y, &srcBuf)
			convolveLine(dstBuf, srcBuf, weights)
			pixSetter.setPixelRow(dstb.Min.Y+y-srcb.Min.Y, dstBuf)
		}
	})
}
338717
func findIconEwmh(X *xgbutil.XUtil, wid xproto.Window,
	width, height int) (*Image, error) {

	icons, err := ewmh.WmIconGet(X, wid)
	if err != nil {
		return nil, err
	}

	icon := FindBestEwmhIcon(width, height, icons)
	if icon == nil {
		return nil, fmt.Errorf("Could not find any _NET_WM_ICON icon.")
	}

	return NewEwmhIcon(X, icon), nil
}
674278
func NewImageWithPlatform(client *Client, i images.Image, platform platforms.MatchComparer) Image {
	return &image{
		client:   client,
		i:        i,
		platform: platform,
	}
}
327006
func (p *BarChart) ScaleXYs(xWidth int, s ScaleFunc) []XYf {

	diff := p.MaxX - p.MinX
	scaleX := float64(diff) / float64(xWidth-1)

	buckets := make([]XYf, xWidth)
	for i := range buckets {
		buckets[i] = XYf{
			X:       float64(i)*scaleX + float64(p.MinX),
			Y:       nil,
			ScaledY: nil,
		}
	}

	miny, maxy := float64(p.xy[0].Y), float64(p.xy[0].Y)

	for _, val := range p.xy {
		minx := float64(p.MinX)
		xdiff := float64(val.X) - minx
		bi := int(xdiff / scaleX)

		slot := buckets[bi]
		if slot.Y == nil {
			slot.Y = new(float64)
			slot.ScaledY = new(float64)
		}
		y := float64(val.Y)
		*slot.Y += y
		miny = math.Min(*slot.Y, miny)
		maxy = math.Max(*slot.Y, maxy)
		buckets[bi] = slot
	}

	for _, val := range buckets {
		if val.Y == nil {
			continue
		}
		*val.ScaledY = s(miny, maxy, *val.Y)
	}

	return buckets
}
114341
func (p *compctx) RelativeImage() string {
	rel, _ := filepath.Rel(p.BuildDir, p.ImageDir)
	return filepath.ToSlash(filepath.Clean(rel))
}