adbbot

package
v0.0.0-...-7cc33da Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2019 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OP_CLICK = iota
	OP_SWIPE

	OP_TOUCH
	OP_KEY
	OP_TEXT

	OP_CAP
	OP_PULL

	OP_CMD   // no return data
	OP_SHELL // pipe
)

Variables

View Source
var (
	ErrNotImpl    = errors.New("not implemented")
	ErrNotSupport = errors.New("not supported")

	ErrTriggerFirst = errors.New("need trigger screencap first")
)
View Source
var ErrLengthOutOfRange = errors.New("Length Out of Range")
View Source
var (
	ErrUnsupportedFormat = errors.New("imaging: unsupported image format")
)
View Source
var RectAll = image.ZR
View Source
var VTagMaxSize uint64 = 128 * 1024 * 1024 // 128MB, should enough for 4k raw image
View Source
var Verbosity = 3

Functions

func Clone

func Clone(img image.Image) *image.NRGBA

Clone returns a copy of the given image.

func Cmd

func Cmd(cmd string) ([]byte, error)

func CmdArg

func CmdArg(cmd ...string) ([]byte, error)

func Cmds

func Cmds(x []string)

func CmpAt

func CmpAt(img *image.NRGBA, subimg *image.NRGBA, offX int, offY int, limit int64) int64

func Decode

func Decode(r io.Reader) (image.Image, error)

Decode reads an image from r.

func Encode

func Encode(w io.Writer, img image.Image, format Format) error

Encode writes the image img to w in the specified format (JPEG, PNG, GIF, TIFF or BMP).

func Find

func Find(img image.Image, subimg image.Image) (x int, y int, val float64)

func FindCachedReg

func FindCachedReg(b Bot, tmpl *Tmpl, delay int) (x int, y int, val float64)

func FindExistImg

func FindExistImg(b Bot, subimg image.Image, times int, delay int) (x int, y int, val float64)

func FindExistReg

func FindExistReg(b Bot, tmpl *Tmpl, times int, delay int) (x int, y int, val float64)

func FindInTmpl

func FindInTmpl(img image.Image, tmpl *Tmpl) (x int, y int, val float64)

func FindP

func FindP(img image.Image, subimg image.Image) (x int, y int, val float64)

func Fit

func Fit(img image.Image, width, height int, filter ResampleFilter) *image.NRGBA

Fit scales down the image using the specified resample filter to fit the specified maximum width and height and returns the transformed image.

Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali, CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.

Usage example:

dstImage := imaging.Fit(srcImage, 800, 600, imaging.Lanczos)

func OpenImage

func OpenImage(filename string) (image.Image, error)

Open loads an image from file

func ReadTagByte

func ReadTagByte(conn io.Reader) ([]byte, error)

func ReadTagStr

func ReadTagStr(conn io.Reader) (string, error)

func ReadVLen

func ReadVLen(conn io.Reader) (int64, error)

func ReadVTagByte

func ReadVTagByte(conn io.Reader) ([]byte, error)

func Rect

func Rect(x, y, xp, yp int) image.Rectangle

func RectAbs

func RectAbs(x, y, x2, y2 int) image.Rectangle

func Resize

func Resize(img image.Image, width, height int, filter ResampleFilter) *image.NRGBA

Resize resizes the image to the specified width and height using the specified resampling filter and returns the transformed image. If one of width or height is 0, the image aspect ratio is preserved.

Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali, CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.

Usage example:

dstImage := imaging.Resize(srcImage, 800, 600, imaging.Lanczos)

func SaveImage

func SaveImage(img image.Image, filename string) (err error)

Save saves the image to file with the specified filename. The format is determined from the filename extension: "jpg" (or "jpeg"), "png", "gif" are supported.

func V

func V(level int, v ...interface{})

func Vf

func Vf(level int, format string, v ...interface{})

func Vln

func Vln(level int, v ...interface{})

func WriteTagByte

func WriteTagByte(conn io.Writer, tag []byte) (err error)

func WriteTagStr

func WriteTagStr(conn io.Writer, tag string) (err error)

func WriteVLen

func WriteVLen(conn io.Writer, n int64) (err error)

func WriteVTagByte

func WriteVTagByte(conn io.Writer, tag []byte) (err error)

Types

type Bot

type Bot interface {
	Adb(parts string) ([]byte, error)
	Shell(parts string) ([]byte, error)

	// will block untill sh exit
	ShellPipe(p1 io.ReadWriteCloser, cmds string, blocking bool) (*exec.Cmd, error)

	TriggerScreencap() (err error)
	GetLastScreencap() image.Image // cached image
	Screencap() (img image.Image, err error)
	PullScreenByte() ([]byte, error) // raw byte (png or RGBA), may not cached

	SaveScreen(imagefile string) (err error)

	//	ScreenBounds()           (image.Rectangle)
	Remap(loc image.Point) image.Point

	ImgCompLv(lv int)

	// input
	Input

	StartApp(app string) (err error)
	KillApp(app string) (err error)
}
| on computer | on devices

localBot | adb | shell remoteBot | adb+daemon | shell+daemon all with/without monkey

type CmdInput

type CmdInput struct {
	// contains filtered or unexported fields
}

input by cmd command

func NewCmdInput

func NewCmdInput(b Bot) *CmdInput

func (*CmdInput) Click

func (i *CmdInput) Click(loc image.Point) (err error)

func (*CmdInput) Key

func (i *CmdInput) Key(in string, ty KeyAction) (err error)

func (*CmdInput) KeyBack

func (i *CmdInput) KeyBack() error

func (*CmdInput) KeyHome

func (i *CmdInput) KeyHome() error

func (*CmdInput) KeyPower

func (i *CmdInput) KeyPower() error

func (*CmdInput) KeySwitch

func (i *CmdInput) KeySwitch() error

func (*CmdInput) Keyevent

func (i *CmdInput) Keyevent(in string) (err error)

func (*CmdInput) SwipeT

func (i *CmdInput) SwipeT(p0, p1 image.Point, time int) (err error)

func (*CmdInput) Text

func (i *CmdInput) Text(in string) (err error)

func (*CmdInput) Touch

func (i *CmdInput) Touch(loc image.Point, ty KeyAction) (err error)

type CompStream

type CompStream struct {
	Conn net.Conn
	// contains filtered or unexported fields
}

func NewCompStream

func NewCompStream(conn net.Conn, level int) *CompStream

func (*CompStream) Close

func (c *CompStream) Close() error

func (*CompStream) LocalAddr

func (c *CompStream) LocalAddr() net.Addr

LocalAddr satisfies net.Conn interface

func (*CompStream) Read

func (c *CompStream) Read(p []byte) (n int, err error)

func (*CompStream) RemoteAddr

func (c *CompStream) RemoteAddr() net.Addr

RemoteAddr satisfies net.Conn interface

func (*CompStream) SetDeadline

func (c *CompStream) SetDeadline(t time.Time) error

func (*CompStream) SetReadDeadline

func (c *CompStream) SetReadDeadline(t time.Time) error

func (*CompStream) SetWriteDeadline

func (c *CompStream) SetWriteDeadline(t time.Time) error

func (*CompStream) Write

func (c *CompStream) Write(p []byte) (n int, err error)

type Daemon

type Daemon struct {
	Reflash time.Duration
	// contains filtered or unexported fields
}

func NewDaemon

func NewDaemon(ln net.Listener, bot Bot, comp bool) (*Daemon, error)

func (*Daemon) Close

func (d *Daemon) Close() error

func (*Daemon) ImgCompLv

func (d *Daemon) ImgCompLv(lv int)

func (*Daemon) Listen

func (d *Daemon) Listen()

type DiffImgComp

type DiffImgComp struct {
	N int
	// contains filtered or unexported fields
}

func NewDiffImgComp

func NewDiffImgComp(buf *bytes.Buffer, n int) *DiffImgComp

func (*DiffImgComp) Encode

func (o *DiffImgComp) Encode(img image.Image, foreIframe bool) ([]byte, error)

func (*DiffImgComp) Encode2

func (o *DiffImgComp) Encode2(img image.Image, foreIframe bool) ([]byte, error)

type DiffImgDeComp

type DiffImgDeComp struct {
	// contains filtered or unexported fields
}

func NewDiffImgDeComp

func NewDiffImgDeComp() *DiffImgDeComp

func (*DiffImgDeComp) Decode

func (o *DiffImgDeComp) Decode(imgByte []byte) (image.Image, error)

func (*DiffImgDeComp) Decode2

func (o *DiffImgDeComp) Decode2(imgByte []byte) (image.Image, error)

type FlateStream

type FlateStream struct {
	Conn net.Conn
	// contains filtered or unexported fields
}

func NewFlateStream

func NewFlateStream(conn net.Conn, level int) *FlateStream

func (*FlateStream) Close

func (c *FlateStream) Close() error

func (*FlateStream) LocalAddr

func (c *FlateStream) LocalAddr() net.Addr

LocalAddr satisfies net.Conn interface

func (*FlateStream) Read

func (c *FlateStream) Read(p []byte) (n int, err error)

func (*FlateStream) RemoteAddr

func (c *FlateStream) RemoteAddr() net.Addr

RemoteAddr satisfies net.Conn interface

func (*FlateStream) SetDeadline

func (c *FlateStream) SetDeadline(t time.Time) error

func (*FlateStream) SetReadDeadline

func (c *FlateStream) SetReadDeadline(t time.Time) error

func (*FlateStream) SetWriteDeadline

func (c *FlateStream) SetWriteDeadline(t time.Time) error

func (*FlateStream) Write

func (c *FlateStream) Write(p []byte) (n int, err error)

type Format

type Format int

belows are copy and modify form Grigory Dryapak's Imaging https://github.com/disintegration/imaging

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

const (
	JPEG Format = iota
	PNG
	GIF
)

type Input

type Input interface {
	Click(loc image.Point) (err error)
	SwipeT(p0, p1 image.Point, time int) (err error)

	Touch(loc image.Point, ty KeyAction) (err error)
	Key(in string, ty KeyAction) (err error)

	Text(in string) (err error)

	Keyevent(in string) (err error)
	KeyHome() error
	KeyBack() error
	KeySwitch() error
	KeyPower() error
}

type KeyAction

type KeyAction int
const (
	KEY_UP   KeyAction = -1
	KEY_MV   KeyAction = 0
	KEY_DOWN KeyAction = 1
)

type LocalBot

type LocalBot struct {
	Dev        string
	Exec       string
	UseSU      bool
	UsePipe    bool
	IsOnDevice bool

	Local_tmp_path string
	Adb_tmp_path   string

	//	Screen          *image.Rectangle
	TargetScreen *image.Rectangle

	ScreenBounds image.Rectangle

	Input
	// contains filtered or unexported fields
}

func NewLocalBot

func NewLocalBot(device, exec string) *LocalBot

func NewLocalBotOnDevice

func NewLocalBotOnDevice() *LocalBot

func (*LocalBot) Adb

func (b *LocalBot) Adb(parts string) ([]byte, error)

func (*LocalBot) GetLastScreencap

func (b *LocalBot) GetLastScreencap() image.Image

func (*LocalBot) ImgCompLv

func (b *LocalBot) ImgCompLv(lv int)

func (*LocalBot) KillApp

func (b *LocalBot) KillApp(app string) (err error)

func (*LocalBot) Pipe

func (b *LocalBot) Pipe(parts string) ([]byte, error)

func (*LocalBot) PullScreenByte

func (b *LocalBot) PullScreenByte() ([]byte, error)

func (*LocalBot) Remap

func (b *LocalBot) Remap(loc image.Point) image.Point

func (*LocalBot) SaveScreen

func (b *LocalBot) SaveScreen(imagefile string) (err error)

func (*LocalBot) Screencap

func (b *LocalBot) Screencap() (img image.Image, err error)

func (*LocalBot) ScriptScreen

func (b *LocalBot) ScriptScreen(x0, y0, dx, dy int)

func (*LocalBot) SetScale

func (b *LocalBot) SetScale(scale float64)

func (*LocalBot) Shell

func (b *LocalBot) Shell(parts string) ([]byte, error)

func (*LocalBot) ShellPipe

func (b *LocalBot) ShellPipe(p1 io.ReadWriteCloser, cmds string, blocking bool) (*exec.Cmd, error)

func (*LocalBot) StartApp

func (b *LocalBot) StartApp(app string) (err error)

func (*LocalBot) TriggerScreencap

func (b *LocalBot) TriggerScreencap() (err error)

type Monkey

type Monkey struct {
	Port     int
	KeyDelta time.Duration
	// contains filtered or unexported fields
}

input by monkey NOTE: "Accounts" in "Settings" will disappear!! You can NOT setup your accounts!! And can NOT set keyboard app!!

func NewMonkey

func NewMonkey(b *LocalBot, port int) *Monkey

func (*Monkey) Click

func (m *Monkey) Click(loc image.Point) (err error)

func (*Monkey) Close

func (m *Monkey) Close() (err error)

func (*Monkey) Key

func (m *Monkey) Key(in string, ty KeyAction) (err error)

func (*Monkey) KeyBack

func (m *Monkey) KeyBack() error

func (*Monkey) KeyHome

func (m *Monkey) KeyHome() error

func (*Monkey) KeyPower

func (m *Monkey) KeyPower() error

func (*Monkey) KeySwitch

func (m *Monkey) KeySwitch() error

func (*Monkey) Keyevent

func (m *Monkey) Keyevent(in string) (err error)

blocking

func (*Monkey) Press

func (m *Monkey) Press(in string) (err error)

func (*Monkey) SwipeT

func (m *Monkey) SwipeT(p0, p1 image.Point, dtime int) (err error)

blocking

func (*Monkey) Tap

func (m *Monkey) Tap(loc image.Point) (err error)

func (*Monkey) Text

func (m *Monkey) Text(in string) (err error)

func (*Monkey) Touch

func (m *Monkey) Touch(loc image.Point, ty KeyAction) (err error)

type RemoteBot

type RemoteBot struct {
	ScreenBounds image.Rectangle

	FindOnDaemon bool // TODO

	KeyDelta time.Duration

	Input
	// contains filtered or unexported fields
}

func NewRemoteBot

func NewRemoteBot(conn net.Conn, comp bool) (*RemoteBot, error)

func (*RemoteBot) Adb

func (b *RemoteBot) Adb(parts string) ([]byte, error)

func (*RemoteBot) Click

func (b *RemoteBot) Click(loc image.Point) (err error)

func (*RemoteBot) GetLastScreencap

func (b *RemoteBot) GetLastScreencap() image.Image

func (*RemoteBot) ImgCompLv

func (b *RemoteBot) ImgCompLv(lv int)

func (*RemoteBot) Key

func (b *RemoteBot) Key(in string, ty KeyAction) (err error)

func (*RemoteBot) KeyBack

func (b *RemoteBot) KeyBack() error

func (*RemoteBot) KeyHome

func (b *RemoteBot) KeyHome() error

func (*RemoteBot) KeyPower

func (b *RemoteBot) KeyPower() error

func (*RemoteBot) KeySwitch

func (b *RemoteBot) KeySwitch() error

func (*RemoteBot) Keyevent

func (b *RemoteBot) Keyevent(in string) (err error)

func (*RemoteBot) KillApp

func (b *RemoteBot) KillApp(app string) (err error)

func (*RemoteBot) Press

func (b *RemoteBot) Press(in string) (err error)

func (*RemoteBot) PullScreenByte

func (b *RemoteBot) PullScreenByte() ([]byte, error)

func (*RemoteBot) Remap

func (b *RemoteBot) Remap(loc image.Point) image.Point

func (*RemoteBot) SaveScreen

func (b *RemoteBot) SaveScreen(imagefile string) (err error)

func (*RemoteBot) Screencap

func (b *RemoteBot) Screencap() (img image.Image, err error)

func (*RemoteBot) Shell

func (b *RemoteBot) Shell(parts string) ([]byte, error)

func (*RemoteBot) ShellPipe

func (b *RemoteBot) ShellPipe(p1 io.ReadWriteCloser, cmds string, blocking bool) (*exec.Cmd, error)

func (*RemoteBot) StartApp

func (b *RemoteBot) StartApp(app string) (err error)

func (*RemoteBot) SwipeT

func (b *RemoteBot) SwipeT(p0, p1 image.Point, dtime int) (err error)

func (*RemoteBot) Tap

func (b *RemoteBot) Tap(loc image.Point) (err error)

inputs

func (*RemoteBot) Text

func (b *RemoteBot) Text(in string) (err error)

func (*RemoteBot) Touch

func (b *RemoteBot) Touch(loc image.Point, ty KeyAction) (err error)

func (*RemoteBot) TriggerScreencap

func (b *RemoteBot) TriggerScreencap() (err error)

type ResampleFilter

type ResampleFilter struct {
	Support float64
	Kernel  func(float64) float64
}

ResampleFilter is a resampling filter struct. It can be used to define custom filters.

Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali, CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.

General filter recommendations:

- Lanczos
	High-quality resampling filter for photographic images yielding sharp results.
	It's slower than cubic filters (see below).

- CatmullRom
	A sharp cubic filter. It's a good filter for both upscaling and downscaling if sharp results are needed.

- MitchellNetravali
	A high quality cubic filter that produces smoother results with less ringing artifacts than CatmullRom.

- BSpline
	A good filter if a very smooth output is needed.

- Linear
	Bilinear interpolation filter, produces reasonably good, smooth output.
	It's faster than cubic filters.

- Box
	Simple and fast averaging filter appropriate for downscaling.
	When upscaling it's similar to NearestNeighbor.

- NearestNeighbor
	Fastest resampling filter, no antialiasing.
var BSpline ResampleFilter

BSpline is a smooth cubic filter (BC-spline; B=1; C=0).

var Bartlett ResampleFilter

Bartlett is a Bartlett-windowed sinc filter (3 lobes).

var Blackman ResampleFilter

Blackman is a Blackman-windowed sinc filter (3 lobes).

var Box ResampleFilter

Box filter (averaging pixels).

var CatmullRom ResampleFilter

CatmullRom is a Catmull-Rom - sharp cubic filter (BC-spline; B=0; C=0.5).

var Cosine ResampleFilter

Cosine is a Cosine-windowed sinc filter (3 lobes).

var Gaussian ResampleFilter

Gaussian is a Gaussian blurring Filter.

var Hamming ResampleFilter

Hamming is a Hamming-windowed sinc filter (3 lobes).

var Hann ResampleFilter

Hann is a Hann-windowed sinc filter (3 lobes).

var Hermite ResampleFilter

Hermite cubic spline filter (BC-spline; B=0; C=0).

var Lanczos ResampleFilter

Lanczos filter (3 lobes).

var Linear ResampleFilter

Linear filter.

var MitchellNetravali ResampleFilter

MitchellNetravali is Mitchell-Netravali cubic filter (BC-spline; B=1/3; C=1/3).

var NearestNeighbor ResampleFilter

NearestNeighbor is a nearest-neighbor filter (no anti-aliasing).

var Welch ResampleFilter

Welch is a Welch-windowed sinc filter (parabolic window, 3 lobes).

type Tmpl

type Tmpl struct {
	Image     image.Image
	Region    image.Rectangle
	ImagePath string
}

func LoadTmpl

func LoadTmpl(filename string, reg image.Rectangle) *Tmpl

func NewTmpl

func NewTmpl(filename string, reg image.Rectangle) (*Tmpl, error)

func (*Tmpl) Center

func (t *Tmpl) Center(x, y int) image.Point

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL