當前位置: 首頁>>代碼示例>>Golang>>正文


Golang image.Rectangle類代碼示例

本文整理匯總了Golang中image.Rectangle的典型用法代碼示例。如果您正苦於以下問題:Golang Rectangle類的具體用法?Golang Rectangle怎麽用?Golang Rectangle使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Rectangle類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: traverseTiles

func traverseTiles(Style style, Area area) (image.Image, error) {
	m := image.NewRGBA(image.Rect(-Margins, -Margins, Area.TileRange.Dx()*TileSize+Margins, Area.TileRange.Dy()*TileSize+Margins))

	whiteColor := color.RGBA{255, 255, 255, 255}
	draw.Draw(m, m.Bounds(), &image.Uniform{whiteColor}, image.ZP, draw.Src)

	frameColor := color.RGBA{50, 50, 50, 255}
	draw.Draw(m, image.Rect(-Frame, -Frame, Area.TileRange.Dx()*TileSize+Frame, Area.TileRange.Dy()*TileSize+Frame), &image.Uniform{frameColor}, image.ZP, draw.Src)

	position := image.Rectangle{image.ZP, image.Point{X: TileSize, Y: TileSize}}
	for y := Area.TileRange.Min.Y; y < Area.TileRange.Max.Y; y++ {
		for x := Area.TileRange.Min.X; x < Area.TileRange.Max.X; x++ {
			img, err := readTile(Style.Mapid, Area.Z, uint(x), uint(y))
			if err != nil {
				fmt.Printf("no luck reading this tile: z:%v, %vx %v \n", Area.Z, x, y)
				fmt.Println(err)
				break
			}
			fmt.Printf("...adding %vx%v \n", x, y)
			draw.Draw(m, position, img, image.ZP, draw.Src)
			position = position.Add(image.Point{X: TileSize, Y: 0})
		}
		position = image.Rectangle{image.Point{X: 0, Y: (y - Area.TileRange.Min.Y + 1) * TileSize}, image.Point{X: TileSize, Y: (y - Area.TileRange.Min.Y + 2) * TileSize}}
	}
	fmt.Println("Great success!")
	return m, nil
}
開發者ID:mapposters,項目名稱:tilepirate,代碼行數:27,代碼來源:traverse_tiles.go

示例2: SubImage

// SubImage returns an image representing the portion of the image p visible
// through r. The returned value shares pixels with the original image.
func (p *Image) SubImage(r image.Rectangle) image.Image {
	// TODO: share code with image.NewYCbCr when this type moves into the
	// standard image package.
	r = r.Intersect(p.Rect)
	// If r1 and r2 are Rectangles, r1.Intersect(r2) is not guaranteed to be inside
	// either r1 or r2 if the intersection is empty. Without explicitly checking for
	// this, the Pix[i:] expression below can panic.
	if r.Empty() {
		return &Image{
			YCbCr: image.YCbCr{
				SubsampleRatio: p.SubsampleRatio,
			},
		}
	}
	yi := p.YOffset(r.Min.X, r.Min.Y)
	ci := p.COffset(r.Min.X, r.Min.Y)
	ai := p.AOffset(r.Min.X, r.Min.Y)
	return &Image{
		YCbCr: image.YCbCr{
			Y:              p.Y[yi:],
			Cb:             p.Cb[ci:],
			Cr:             p.Cr[ci:],
			SubsampleRatio: p.SubsampleRatio,
			YStride:        p.YStride,
			CStride:        p.CStride,
			Rect:           r,
		},
		A:       p.A[ai:],
		AStride: p.AStride,
	}
}
開發者ID:2722,項目名稱:lantern,代碼行數:33,代碼來源:nycbcra.go

示例3: New

// New returns a new Image with the given bounds and subsample ratio.
func New(r image.Rectangle, subsampleRatio image.YCbCrSubsampleRatio) *Image {
	// TODO: share code with image.NewYCbCr when this type moves into the
	// standard image package.
	w, h, cw, ch := r.Dx(), r.Dy(), 0, 0
	switch subsampleRatio {
	case image.YCbCrSubsampleRatio422:
		cw = (r.Max.X+1)/2 - r.Min.X/2
		ch = h
	case image.YCbCrSubsampleRatio420:
		cw = (r.Max.X+1)/2 - r.Min.X/2
		ch = (r.Max.Y+1)/2 - r.Min.Y/2
	case image.YCbCrSubsampleRatio440:
		cw = w
		ch = (r.Max.Y+1)/2 - r.Min.Y/2
	default:
		// Default to 4:4:4 subsampling.
		cw = w
		ch = h
	}
	b := make([]byte, 2*w*h+2*cw*ch)
	// TODO: use s[i:j:k] notation to set the cap.
	return &Image{
		YCbCr: image.YCbCr{
			Y:              b[:w*h],
			Cb:             b[w*h+0*cw*ch : w*h+1*cw*ch],
			Cr:             b[w*h+1*cw*ch : w*h+2*cw*ch],
			SubsampleRatio: subsampleRatio,
			YStride:        w,
			CStride:        cw,
			Rect:           r,
		},
		A:       b[w*h+2*cw*ch:],
		AStride: w,
	}
}
開發者ID:2722,項目名稱:lantern,代碼行數:36,代碼來源:nycbcra.go

示例4: wantRescale

func (opts *DecodeOpts) wantRescale(b image.Rectangle, swapDimensions bool) bool {
	if opts == nil {
		return false
	}

	// In rescale Scale* trumps Max* so we assume the same relationship here.

	// Floating point compares probably only allow this to work if the values
	// were specified as the literal 1 or 1.0, computed values will likely be
	// off.  If Scale{Width,Height} end up being 1.0-epsilon we'll rescale
	// when it probably wouldn't even be noticible but that's okay.
	if opts.ScaleWidth == 1.0 && opts.ScaleHeight == 1.0 {
		return false
	}
	if opts.ScaleWidth > 0 && opts.ScaleWidth < 1.0 ||
		opts.ScaleHeight > 0 && opts.ScaleHeight < 1.0 {
		return true
	}

	w, h := b.Dx(), b.Dy()
	if swapDimensions {
		w, h = h, w
	}

	// Same size, don't rescale.
	if opts.MaxWidth == w && opts.MaxHeight == h {
		return false
	}
	return opts.MaxWidth > 0 && opts.MaxWidth < w ||
		opts.MaxHeight > 0 && opts.MaxHeight < h
}
開發者ID:kdevroede,項目名稱:camlistore,代碼行數:31,代碼來源:images.go

示例5: Trimmed

// Trimmed ...
func (t *Tree) Trimmed() *Tree {
	var leafs []image.Rectangle
	t.Visit(func(other *Tree) {
		if len(other.points) == 0 {
			return
		}
		leafs = append(leafs, image.Rectangle{
			Min: other.Extents.Min,
			Max: other.Extents.Max,
		})
	})

	var r *image.Rectangle
	for _, b := range leafs {
		if r == nil {
			r = new(image.Rectangle)
			*r = b
			continue
		}
		*r = r.Union(b)
	}

	tr := New(*r, t.capacity)

	t.Visit(func(other *Tree) {
		for p := range other.points {
			tr.Insert(p)
		}
	})

	return tr
}
開發者ID:marcusolsson,項目名稱:exp,代碼行數:33,代碼來源:quadtree.go

示例6: Thumbnail

// Thumbnail scales and crops src so it fits in dst.
func Thumbnail(dst draw.Image, src image.Image) error {
	// Scale down src in the dimension that is closer to dst.
	sb := src.Bounds()
	db := dst.Bounds()
	rx := float64(sb.Dx()) / float64(db.Dx())
	ry := float64(sb.Dy()) / float64(db.Dy())
	var b image.Rectangle
	if rx < ry {
		b = image.Rect(0, 0, db.Dx(), int(float64(sb.Dy())/rx))
	} else {
		b = image.Rect(0, 0, int(float64(sb.Dx())/ry), db.Dy())
	}

	buf := image.NewRGBA(b)
	if err := Scale(buf, src); err != nil {
		return err
	}

	// Crop.
	// TODO(crawshaw): improve on center-alignment.
	var pt image.Point
	if rx < ry {
		pt.Y = (b.Dy() - db.Dy()) / 2
	} else {
		pt.X = (b.Dx() - db.Dx()) / 2
	}
	draw.Draw(dst, db, buf, pt, draw.Src)
	return nil
}
開發者ID:sandbreaker,項目名稱:graphics-go,代碼行數:30,代碼來源:thumbnail.go

示例7: PackHorizontal

// PackHorzontal finds the Pos for a horizontally packed sprite
func (l *Sprite) PackHorizontal(pos int) Pos {
	if pos == -1 || pos == 0 {
		return Pos{0, 0}
	}
	var x, y int
	var rect image.Rectangle
	l.optsMu.RLock()
	padding := l.opts.Padding
	l.optsMu.RUnlock()

	// there are n-1 paddings in an image list
	x = padding * pos
	// No padding on the outside of the image
	numimages := l.Len()
	if pos == numimages {
		x -= padding
	}
	for i := 1; i <= pos; i++ {
		l.goImagesMu.RLock()
		rect = l.imgs[i-1].Bounds()
		l.goImagesMu.RUnlock()
		x += rect.Dx()
		if pos == numimages {
			y = int(math.Max(float64(y), float64(rect.Dy())))
		}
	}

	return Pos{
		x, y,
	}
}
開發者ID:xarem,項目名稱:wellington,代碼行數:32,代碼來源:sprite.go

示例8: checkPsnrs

func checkPsnrs(t *testing.T, ref, img image.Image, sub image.Rectangle, min []float64) {
	var a, b image.Image
	a, b = ref, img
	if !sub.Empty() {
		switch a.(type) {
		case *image.RGBA:
			a = a.(*image.RGBA).SubImage(sub)
			b = b.(*image.RGBA).SubImage(sub)
		case *image.NRGBA:
			a = a.(*image.NRGBA).SubImage(sub)
			b = b.(*image.NRGBA).SubImage(sub)
		case *image.YCbCr:
			a = a.(*image.YCbCr).SubImage(sub)
			b = b.(*image.YCbCr).SubImage(sub)
		case *image.Gray:
			a = a.(*image.Gray).SubImage(sub)
			b = b.(*image.Gray).SubImage(sub)
		}
	}
	psnrs, err := Psnr(a, b)
	expect(t, err, nil)
	for i, v := range psnrs {
		if v < min[i] {
			t.Fatalf("invalid psnr %v < %v\n", v, min[i])
		}
	}
}
開發者ID:donlzx,項目名稱:rez,代碼行數:27,代碼來源:resize_test.go

示例9: Make

func Make(r image.Rectangle) *Image {
	return &Image{
		Pix:    make([]byte, r.Dx()*r.Dy()*3),
		Stride: r.Dx() * 3,
		Rect:   image.Rect(0, 0, r.Dx(), r.Dy()),
	}
}
開發者ID:runningwild,項目名稱:argus,代碼行數:7,代碼來源:rgb.go

示例10: Repaint

func (a *area) Repaint(r image.Rectangle) {
	r = image.Rect(0, 0, a.width, a.height).Intersect(r)
	if r.Empty() {
		return
	}
	C.gtk_widget_queue_draw_area(a.widget, C.gint(r.Min.X), C.gint(r.Min.Y), C.gint(r.Dx()), C.gint(r.Dy()))
}
開發者ID:sjn1978,項目名稱:ui,代碼行數:7,代碼來源:area_unix.go

示例11: Bounds

func (p *resizeToFitFilter) Bounds(srcBounds image.Rectangle) image.Rectangle {
	w, h := p.width, p.height
	srcw, srch := srcBounds.Dx(), srcBounds.Dy()

	if w <= 0 || h <= 0 || srcw <= 0 || srch <= 0 {
		return image.Rect(0, 0, 0, 0)
	}

	if srcw <= w && srch <= h {
		return image.Rect(0, 0, srcw, srch)
	}

	wratio := float64(srcw) / float64(w)
	hratio := float64(srch) / float64(h)

	var dstw, dsth int
	if wratio > hratio {
		dstw = w
		dsth = minint(int(float64(srch)/wratio+0.5), h)
	} else {
		dsth = h
		dstw = minint(int(float64(srcw)/hratio+0.5), w)
	}

	return image.Rect(0, 0, dstw, dsth)
}
開發者ID:eliquious,項目名稱:gift,代碼行數:26,代碼來源:resize.go

示例12: imfilter

func imfilter(filter [][]float32, rect image.Rectangle, rgbFunc func(xpos, ypos int) (r0, g0, b0, a0 uint8), mergFunc func(a, b float32) float32) *image.RGBA {
	wg := sync.WaitGroup{}
	size := rect.Size()
	imgGrey := image.NewRGBA(rect)
	fX := len(filter)
	fY := len(filter[0])
	xoffset := fX / 2
	yoffset := fY / 2
	threadCount := (fX + fY) / 2
	sizeoffset := (size.X - fX) / threadCount

	timeStart := time.Now()

	wg.Add(threadCount)
	for i := 0; i < threadCount; i++ {
		go func(i int) {
			for x := xoffset + i*sizeoffset; x < xoffset+(i+1)*sizeoffset; x++ {
				for y := yoffset; y < size.Y-yoffset; y++ {
					newColor := imfilterMerg(filter, fX, fY, x, y, xoffset, yoffset, rgbFunc, mergFunc)
					imgGrey.SetRGBA(x, y, newColor)
				}
			}
			wg.Done()
		}(i)
	}
	wg.Wait()
	fmt.Println("Filt Time", time.Now().Sub(timeStart))
	return imgGrey
}
開發者ID:GargouillePao,項目名稱:gosfml2ex,代碼行數:29,代碼來源:preTreatmen.go

示例13: NewPicture

func NewPicture(bounds image.Rectangle) *Picture {
	return &Picture{
		Data:  make([]float64, bounds.Dx()*bounds.Dy()),
		Gamma: 1.0, //2.2,
		Rect:  bounds,
	}
}
開發者ID:kreshikhin,項目名稱:refoc,代碼行數:7,代碼來源:picture.go

示例14: drawScene

func (v *platformView) drawScene(r image.Rectangle) {
	//log.Printf("platformView.drawScene %v\n", r)
	x, y, w, h := r.Min.X, r.Min.Y, r.Size().X, r.Size().Y
	v.area.QueueDrawArea(v.parent.ScaleCoord(x, false), v.parent.ScaleCoord(y, false),
		v.parent.ScaleCoord(w, true)+1, v.parent.ScaleCoord(h, true)+1)
	return
}
開發者ID:axel-freesp,項目名稱:sge,代碼行數:7,代碼來源:platformview.go

示例15: NewYCbCrAligned

// NewYCbCrAligned Allocates YCbCr image with padding.
// Because LibJPEG needs extra padding to decoding buffer, This func add an
// extra alignSize (16) padding to cover overflow from any such modes.
func NewYCbCrAligned(r image.Rectangle, subsampleRatio image.YCbCrSubsampleRatio) *image.YCbCr {
	w, h, cw, ch := r.Dx(), r.Dy(), 0, 0
	switch subsampleRatio {
	case image.YCbCrSubsampleRatio422:
		cw = (r.Max.X+1)/2 - r.Min.X/2
		ch = h
	case image.YCbCrSubsampleRatio420:
		cw = (r.Max.X+1)/2 - r.Min.X/2
		ch = (r.Max.Y+1)/2 - r.Min.Y/2
	case image.YCbCrSubsampleRatio440:
		cw = w
		ch = (r.Max.Y+1)/2 - r.Min.Y/2
	default:
		cw = w
		ch = h
	}

	// TODO: check the padding size to minimize memory allocation.
	yStride := pad(w, alignSize) + alignSize
	cStride := pad(cw, alignSize) + alignSize
	yHeight := pad(h, alignSize) + alignSize
	cHeight := pad(ch, alignSize) + alignSize

	b := make([]byte, yStride*yHeight+2*cStride*cHeight)
	return &image.YCbCr{
		Y:              b[:yStride*yHeight],
		Cb:             b[yStride*yHeight+0*cStride*cHeight : yStride*yHeight+1*cStride*cHeight],
		Cr:             b[yStride*yHeight+1*cStride*cHeight : yStride*yHeight+2*cStride*cHeight],
		SubsampleRatio: subsampleRatio,
		YStride:        yStride,
		CStride:        cStride,
		Rect:           r,
	}
}
開發者ID:ieee0824,項目名稱:go-libjpeg,代碼行數:37,代碼來源:decompress.go


注:本文中的image.Rectangle類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。