本文整理匯總了Golang中image.Pt函數的典型用法代碼示例。如果您正苦於以下問題:Golang Pt函數的具體用法?Golang Pt怎麽用?Golang Pt使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Pt函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestFov
func TestFov(t *testing.T) {
mf := space.NewManifold()
mf.SetPortal(space.Loc(10, 11, 1), space.Port(20, 20, 20))
seen := map[image.Point]space.Location{}
// Impassable barrier on every zone at x == 11
blockFn := func(loc space.Location) bool { return loc.X == 11 }
markFn := func(pt image.Point, loc space.Location) {
seen[pt] = loc
}
fov := New(blockFn, markFn, mf)
fov.Run(space.Loc(10, 10, 1), 4)
if _, ok := seen[image.Pt(-2, 0)]; !ok {
t.Fail()
}
if _, ok := seen[image.Pt(2, 0)]; ok {
// Should be stopped by blockFn barrier
t.Fail()
}
if loc, ok := seen[image.Pt(0, 2)]; ok {
// This one should be through the portal.
if loc.Zone != 20 {
t.Fail()
}
} else {
t.Fail()
}
}
示例2: newEanCoordinateConverter
func newEanCoordinateConverter(outerBound image.Rectangle, fm fontMeasurer) (*eanCoordinateConverter, error) {
const rightMargin = digitBarSize
const logicalWidth = 13*digitBarSize + startMarkerSize + endMarkerSize + centerMarkerSize + rightMargin
scale := outerBound.Dx() / logicalWidth
if scale <= 0 {
return nil, errAreaTooSmall
}
xMargin := (outerBound.Dx() % logicalWidth) / 2
fSize, fWidth, fHeight := fm(digitBarSize * scale)
if digitBarSize*scale < fWidth {
return nil, errFontTooBig
}
if outerBound.Dy() < fHeight*2 {
return nil, errAreaTooSmall
}
return &eanCoordinateConverter{
bound: image.Rectangle{
Min: outerBound.Min.Add(image.Pt(xMargin, 0)),
Max: outerBound.Max.Sub(image.Pt(xMargin, 0)),
},
fontDim: image.Rect(0, 0, fWidth, fHeight),
scale: scale,
fontSize: fSize,
}, nil
}
示例3: Parse
func Parse(spec ParseSpec, asciiMap string) (result *Chunk, err error) {
var lines []string
lines, err = preprocess(asciiMap)
if err != nil {
return
}
w, h := len(lines[0]), len(lines)
result = &Chunk{[]Peg{}, map[image.Point]MapCell{}, image.Pt(w, h), &spec}
edges := extractEdges(lines)
for dir, edge := range edges {
var pegs []Peg
pegs, err = collectPegs(corner(Dir4(dir), result.dim), Dir4(dir), spec, edge)
if err != nil {
return
}
for _, peg := range pegs {
result.pegs = append(result.pegs, peg)
}
}
for y, line := range lines {
for x, ch := range line {
if !unicode.IsSpace(ch) {
result.cells[image.Pt(x, y)] = MapCell(ch)
}
}
}
return
}
示例4: addLogo
func addLogo(profilePtr *image.Image, logo string, context appengine.Context) []byte {
profileImage := *profilePtr
destImage := image.NewRGBA(profileImage.Bounds())
draw.Draw(destImage, destImage.Bounds(), profileImage, image.ZP, draw.Src)
if logoImages, ok := THELOGOIMAGES[logo]; ok {
randi := rand.Intn(len(logoImages))
logoImage := logoImages[randi]
offset := image.Pt(5, 5)
if strings.HasPrefix(logo, "NLD-") {
offset = image.Pt(0, 0)
}
start := profileImage.Bounds().Size()
start = start.Sub(offset)
start = start.Sub(logoImage.Bounds().Size())
bounds := image.Rectangle{start, start.Add(logoImage.Bounds().Size())}
draw.Draw(destImage, bounds, logoImage, image.ZP, draw.Over)
} else {
context.Errorf("Cannot load logoimage for %s", logo)
}
buffer := new(bytes.Buffer)
err := png.Encode(buffer, destImage)
check(err, context)
return buffer.Bytes()
}
示例5: CorrBankStrideFFT
// CorrBankStrideFFT computes the strided correlation of
// an image with a bank of filters.
// h_p[u, v] = (f corr g_p)[stride*u, stride*v]
func CorrBankStrideFFT(f *rimg64.Image, g *Bank, stride int) (*rimg64.Multi, error) {
out := ValidSizeStride(f.Size(), g.Size(), stride)
if out.X <= 0 || out.Y <= 0 {
return nil, nil
}
// Compute strided convolution as the sum over
// a stride x stride grid of small convolutions.
grid := image.Pt(stride, stride)
// But do not divide into a larger grid than the size of the filter.
// If the filter is smaller than the stride,
// then some pixels in the image will not affect the output.
grid.X = min(grid.X, g.Width)
grid.Y = min(grid.Y, g.Height)
// Determine the size of the sub-sampled filter.
gsub := image.Pt(ceilDiv(g.Width, grid.X), ceilDiv(g.Height, grid.Y))
// The sub-sampled size of the image should be such that
// the output size is attained.
fsub := image.Pt(out.X+gsub.X-1, out.Y+gsub.Y-1)
// Determine optimal size for FFT.
work, _ := FFT2Size(fsub)
// Cache FFT of image for convolving with multiple filters.
// Re-use plan for multiple convolutions too.
fhat := fftw.NewArray2(work.X, work.Y)
ffwd := fftw.NewPlan2(fhat, fhat, fftw.Forward, fftw.Estimate)
defer ffwd.Destroy()
// FFT for current filter.
ghat := fftw.NewArray2(work.X, work.Y)
gfwd := fftw.NewPlan2(ghat, ghat, fftw.Forward, fftw.Estimate)
defer gfwd.Destroy()
// Allocate one array per output channel.
hhat := make([]*fftw.Array2, len(g.Filters))
for k := range hhat {
hhat[k] = fftw.NewArray2(work.X, work.Y)
}
// Normalization factor.
alpha := complex(1/float64(work.X*work.Y), 0)
// Add the convolutions over channels and strides.
for i := 0; i < grid.X; i++ {
for j := 0; j < grid.Y; j++ {
// Take transform of downsampled image given offset (i, j).
copyStrideTo(fhat, f, stride, image.Pt(i, j))
ffwd.Execute()
// Take transform of each downsampled channel given offset (i, j).
for q := range hhat {
copyStrideTo(ghat, g.Filters[q], stride, image.Pt(i, j))
gfwd.Execute()
addMul(hhat[q], ghat, fhat)
}
}
}
// Take the inverse transform of each channel.
h := rimg64.NewMulti(out.X, out.Y, len(g.Filters))
for q := range hhat {
scale(alpha, hhat[q])
fftw.IFFT2To(hhat[q], hhat[q])
copyRealToChannel(h, q, hhat[q])
}
return h, nil
}
示例6: ImportOverlays
func (jw *JsonWed) ImportOverlays(wed *Wed) error {
jw.Overlays = make([]jsonWedOverlay, 0)
jw.TileIndices = make([]int, len(wed.TileIndices))
for idx, overlay := range wed.Overlays {
if overlay.Name.String() != "" {
ov := jsonWedOverlay{}
ov.Width = int(overlay.Width)
ov.Height = int(overlay.Height)
ov.Name = overlay.Name.String()
ov.Flags = int(overlay.LayerFlags)
ov.Tilemap = make([]jsonWedTilemap, len(wed.Tilemaps[idx]))
for tmIdx, tilemap := range wed.Tilemaps[idx] {
ov.Tilemap[tmIdx].Id = int(tilemap.TileIndexLookupIndex)
ov.Tilemap[tmIdx].Count = int(tilemap.TileIndexLookupCount)
ov.Tilemap[tmIdx].Alt = int(tilemap.AlternateTileIndex)
ov.Tilemap[tmIdx].Flags = int(tilemap.Flags)
ov.Tilemap[tmIdx].AnimSpeed = int(tilemap.AnimSpeed)
ov.Tilemap[tmIdx].WFlags = int(tilemap.WFlags)
}
tisFile, err := os.Open(overlay.Name.String() + ".tis")
if err != nil {
return fmt.Errorf("unable to open overlay: %s %v", overlay.Name.String(), err)
}
defer tisFile.Close()
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("unable to get working directory: %v", err)
}
tis, err := OpenTis(tisFile, overlay.Name.String(), cwd)
if err != nil {
return fmt.Errorf("unable to open tis: %v", err)
}
ov.Tis = tis
img := image.NewRGBA(image.Rect(0, 0, 64*ov.Width, 64*ov.Height))
closedimg := image.NewRGBA(image.Rect(0, 0, 64*ov.Width, 64*ov.Height))
for y := 0; y < int(ov.Height); y++ {
for x := 0; x < int(ov.Width); x++ {
tileNum := y*int(ov.Width) + x
tileImg := tis.SubImage(tileNum)
draw.Draw(img, image.Rect(x*64, y*64, x*64+64, y*64+64), tileImg, image.Pt(0, 0), draw.Src)
if ov.Tilemap[tileNum].Alt != -1 {
tileImg = tis.SubImage(ov.Tilemap[tileNum].Alt)
draw.Draw(closedimg, image.Rect(x*64, y*64, x*64+64, y*64+64), tileImg, image.Pt(0, 0), draw.Src)
}
}
}
ov.BackgroundImg = img
ov.ClosedImage = closedimg
jw.Overlays = append(jw.Overlays, ov)
}
}
for idx, ti := range wed.TileIndices {
jw.TileIndices[idx] = int(ti)
}
return nil
}
示例7: TestFlag
func TestFlag(t *testing.T) {
if flagfn(nil) == nil {
t.Errorf("nil func returned")
}
fs := flag.NewFlagSet("testcmd", flag.ContinueOnError)
var r1, r2 *image.Rectangle
r2 = &image.Rectangle{}
def := image.Rectangle{Min: image.Pt(3, 4), Max: image.Pt(4, 6)} // 1x2+3+4
r1 = defineFlag(fs, nil, "t1", def, "the first test")
if r1 == nil {
t.Errorf("defineFlag returned nil")
}
r2 = defineFlag(fs, r2, "t2", def, "the second test")
if r1 == nil {
t.Errorf("defineFlag returned nil")
}
if r2 != r2 { // pointers should be equal
t.Errorf("defineFlag returned a different pointer")
}
err := fs.Parse([]string{"-t2=1x1+1+1"})
if err != nil {
t.Errorf("parse error: %v", err)
}
if *r1 != def {
t.Errorf("r1: %#v", *r1)
}
if *r2 != image.Rect(1, 1, 2, 2) {
t.Errorf("r2: %#v", r2)
}
}
示例8: ScreenCapture
func ScreenCapture() (*image.NRGBA, error) {
args := captureCommand()
cmd := exec.Command(args[0], args[1:]...)
buf := &bytes.Buffer{}
cmd.Stdout = buf
if err := cmd.Run(); err != nil {
return nil, err
}
data, err := decompressCapture(buf.Bytes())
if err != nil {
return nil, err
}
buf = bytes.NewBuffer(data)
width := int32(0)
height := int32(0)
version := int32(0)
if err := binary.Read(buf, binary.LittleEndian, &width); err != nil {
return nil, err
}
if err := binary.Read(buf, binary.LittleEndian, &height); err != nil {
return nil, err
}
if err := binary.Read(buf, binary.LittleEndian, &version); err != nil {
return nil, err
}
stride := int(width * 4)
rect := image.Rectangle{image.Pt(0, 0), image.Pt(int(width), int(height))}
return &image.NRGBA{Pix: data[12:], Stride: stride, Rect: rect}, nil
}
示例9: Crop
func Crop(img image.Image, width int, height int, padding int) (fimg draw.Image, err error) {
// For now assume top left is bg color
// future maybe avg outer rows of pixels
bgcolor := img.At(img.Bounds().Min.X, img.Bounds().Min.Y)
logoh, logow := height-2*padding, width-2*padding
logorat := float32(logow) / float32(logoh)
interior := findLogo(img, bgcolor)
interior.Max = interior.Max.Add(image.Pt(1, 1))
center := func(rect image.Rectangle) image.Point {
return image.Point{(rect.Max.X - rect.Min.X) / 2, (rect.Max.Y - rect.Min.Y) / 2}
}
fimg = image.NewRGBA(image.Rect(0, 0, width, height))
rc := center(fimg.Bounds())
origrat := float32(interior.Dx()) / float32(interior.Dy())
if logorat > origrat {
logow = int(origrat * float32(logoh))
} else {
logoh = int(float32(logow) / origrat)
}
logoimg := Resize(img, interior, logow, logoh)
logorect := image.Rect(0, 0, logoimg.Bounds().Dx(), logoimg.Bounds().Dy())
logorect = logorect.Add(rc.Sub(image.Pt(logorect.Dx()/2, logorect.Dy()/2)))
draw.Draw(fimg, fimg.Bounds(), &image.Uniform{bgcolor}, image.ZP, draw.Src)
draw.Draw(fimg, logorect, logoimg, image.ZP, draw.Src)
return
}
示例10: drawHealth
func (h *Hud) drawHealth(bounds image.Rectangle) {
heart := app.Cache().GetDrawable(util.SmallIcon(util.Items, 22))
halfHeart := app.Cache().GetDrawable(util.SmallIcon(util.Items, 23))
noHeart := app.Cache().GetDrawable(util.SmallIcon(util.Items, 24))
shield := app.Cache().GetDrawable(util.SmallIcon(util.Items, 25))
halfShield := app.Cache().GetDrawable(util.SmallIcon(util.Items, 26))
pc, _ := h.world.Player.(entity.Stats)
offset := bounds.Min
for i := 0; i < pc.MaxHealth(); i += 2 {
n := pc.Health() - i
if n > 1 {
heart.Draw(offset)
} else if n > 0 {
halfHeart.Draw(offset)
} else {
noHeart.Draw(offset)
}
offset = offset.Add(image.Pt(util.TileW, 0))
}
for i := 0; i < pc.Shield(); i += 2 {
n := pc.Shield() - i
if n > 1 {
shield.Draw(offset)
} else {
halfShield.Draw(offset)
}
offset = offset.Add(image.Pt(util.TileW, 0))
}
}
示例11: TestAssertNotEqual
func TestAssertNotEqual(t *testing.T) {
AssertNotEqual(t, 2, 1)
AssertNotEqual(t, "ABC", strings.ToLower("ABC"))
AssertNotEqual(t, []byte("ABC"), bytes.ToLower([]byte("ABC")))
AssertNotEqual(t, image.Pt(1, 2), image.Pt(2, 2))
AssertNotEqual(t, image.Pt(1, 2), image.Rect(1, 2, 3, 4))
}
示例12: TestSideOverwrite
func TestSideOverwrite(t *testing.T) {
chunks := parseChunks(t, `
###
#..
#.#
#.|
###
###
..#
#|#
#|#
#.#
###
###
|.#
###
`)
// Build an L-shaped room from the first two chunks.
gen := New(chunks[0], '#')
gen.AddChunk(gen.FittingChunks(gen.PegsAt(image.Pt(2, 1))[0], chunks)[0])
// Add a chunk to south peg. The chunk that matches the peg but overwrites
// the other door should be returned.
fits := gen.FittingChunks(gen.PegsAt(image.Pt(2, 3))[0], chunks)
if len(fits) != 1 {
t.Error("Fitting chunks not found")
}
}
示例13: main
func main() {
fmt.Println("ImgNet loading...")
netSize := []int{3, 3}
net := NewImgNet(netSize[0], netSize[1])
imgOrig, err := imaging.Open("lena-colour.png")
if err != nil {
panic(err)
}
imgFiltered, err := imaging.Open("lena-colourdiff.png")
if err != nil {
panic(err)
}
targetImg, err := imaging.Open("lena-colour.png")
if err != nil {
panic(err)
}
fmt.Println("Teaching network.")
for randcount := 0; randcount < 1000000; randcount++ {
x := rand.Intn(imgOrig.Bounds().Dx()-netSize[0]) - netSize[0]/2
y := rand.Intn(imgOrig.Bounds().Dy()-netSize[1]) - netSize[1]/2
net.FF(image.Pt(x, y), &imgOrig)
net.BP(image.Pt(x, y), &imgFiltered)
}
fmt.Println("Filtering image.")
result := net.Filter(targetImg)
imaging.Save(result, "output.png")
}
示例14: Apply
func (phi SumPool) Apply(x *rimg64.Multi) (*rimg64.Multi, error) {
if phi.Field.X <= 0 || phi.Field.Y <= 0 {
err := fmt.Errorf("invalid field size: %v", phi.Field)
return nil, err
}
if phi.Stride <= 0 {
err := fmt.Errorf("invalid stride: %d", phi.Stride)
return nil, err
}
size := image.Pt(
ceilDiv(x.Width-phi.Field.X+1, phi.Stride),
ceilDiv(x.Height-phi.Field.Y+1, phi.Stride),
)
y := rimg64.NewMulti(size.X, size.Y, x.Channels)
for i := 0; i < y.Width; i++ {
for j := 0; j < y.Height; j++ {
for k := 0; k < x.Channels; k++ {
// Position in original image.
p := image.Pt(i, j).Mul(phi.Stride)
var t float64
for u := p.X; u < p.X+phi.Field.X; u++ {
for v := p.Y; v < p.Y+phi.Field.Y; v++ {
t += x.At(u, v, k)
}
}
y.Set(i, j, k, t)
}
}
}
return y, nil
}
示例15: Draw
func (vp *ViewPanel) Draw() {
vp.Clear()
// draw terrain
if vp.g.Map != nil {
for x, row := range vp.g.Map.Locations {
for y, terr := range row {
realpos := vp.cam.Transform(image.Pt(x, y))
if true || vp.cam.ContainsWorldPoint(realpos) {
c := terr.Glyph
vp.SetCell(realpos.X, realpos.Y, c.Ch, c.Fg, c.Bg)
}
}
}
}
for o := range vp.g.Objects.Chan() {
if o.GetTag("visible") {
realpos := vp.cam.Transform(image.Pt(o.GetPos()))
g := o.GetGlyph()
vp.SetCell(realpos.X, realpos.Y, g.Ch, g.Fg, g.Bg)
}
}
vp.Buffered.Draw()
}