Remove bitmap

This commit is contained in:
vcaesar 2017-08-05 00:45:54 +08:00
parent a262c68f42
commit 1a6054612a
6 changed files with 187 additions and 209 deletions

View File

@ -36,29 +36,22 @@ This is a work in progress.
## Requirements: ## Requirements:
Now, Please make sure Golang, GCC, zlib and libpng is installed correctly before installing RobotGo. Now, Please make sure Golang, GCC is installed correctly before installing RobotGo.
### ALL: ### ALL:
``` ```
Golang Golang
GCC GCC
zlib & libpng (bitmap)
``` ```
#### For Mac OS X: #### For Mac OS X:
Xcode Command Line Tools
``` ```
brew install libpng Xcode Command Line Tools
brew install homebrew/dupes/zlib
``` ```
#### For Windows: #### For Windows:
``` ```
MinGW or other GCC MinGW or other GCC
zlib & libpng (bitmap need it.)
``` ```
##### [Zlib & libpng Windows32 GCC's Course](https://github.com/go-vgo/Mingw32)
##### [Download include zlib & libpng Windows64 GCC](https://github.com/go-vgo/Mingw)
#### For everything else: #### For everything else:
``` ```
@ -76,8 +69,7 @@ xcb, xkb, libxkbcommon
sudo apt-get install gcc libc6-dev sudo apt-get install gcc libc6-dev
sudo apt-get install libx11-dev sudo apt-get install libx11-dev
sudo apt-get install xorg-dev sudo apt-get install xorg-dev
sudo apt-get install libxtst-dev libpng++-dev
sudo apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev sudo apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev
sudo apt-get install libxkbcommon-dev sudo apt-get install libxkbcommon-dev
@ -91,8 +83,6 @@ sudo apt-get install xclip
```yml ```yml
sudo dnf install libxkbcommon-devel libXtst-devel libxkbcommon-x11-devel xorg-x11-xkb-utils-devel sudo dnf install libxkbcommon-devel libXtst-devel libxkbcommon-x11-devel xorg-x11-xkb-utils-devel
sudo dnf install libpng-devel
sudo dnf install xsel sudo dnf install xsel
sudo dnf install xclip sudo dnf install xclip
``` ```
@ -103,8 +93,6 @@ go get github.com/go-vgo/robotgo
``` ```
It's that easy! It's that easy!
png.h: No such file or directory? Please see [issues/47](https://github.com/go-vgo/robotgo/issues/47).
## Update: ## Update:
``` ```
go get -u github.com/go-vgo/robotgo go get -u github.com/go-vgo/robotgo
@ -174,7 +162,7 @@ func main() {
} }
``` ```
#### [Bitmap](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/mian.go) <!-- #### [Bitmap](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/mian.go)
```Go ```Go
package main package main
@ -194,7 +182,7 @@ func main() {
robotgo.SaveBitmap(bitmap, "test.png") robotgo.SaveBitmap(bitmap, "test.png")
} }
``` ``` -->
#### [Event](https://github.com/go-vgo/robotgo/blob/master/examples/event/main.go) #### [Event](https://github.com/go-vgo/robotgo/blob/master/examples/event/main.go)

View File

@ -34,28 +34,21 @@ QQ 群: 595877611
## Requirements: ## Requirements:
环境要求: 环境要求:
在安装 RobotGo 之前, 请确保 Golang、GCC、zlib 和 libpng 被正确安装 在安装 RobotGo 之前, 请确保 Golang、GCC 被正确安装
### ALL: ### ALL:
``` ```
Golang Golang
GCC GCC
zlib & libpng (bitmap)
``` ```
#### For Mac OS X: #### For Mac OS X:
Xcode Command Line Tools
``` ```
brew install libpng Xcode Command Line Tools
brew install homebrew/dupes/zlib
``` ```
#### For Windows: #### For Windows:
``` ```
MinGW or other GCC MinGW or other GCC
zlib & libpng (bitmap 依赖)
``` ```
##### [Zlib & libpng Windows32 GCC 教程](https://github.com/go-vgo/Mingw32)
##### [下载包含 zlib 和 libpng 的 64位 MinGW](https://github.com/go-vgo/Mingw)
#### For everything else (Linux 等其他系统): #### For everything else (Linux 等其他系统):
``` ```
@ -73,9 +66,7 @@ xcb, xkb, libxkbcommon
sudo apt-get install gcc libc6-dev sudo apt-get install gcc libc6-dev
sudo apt-get install libx11-dev sudo apt-get install libx11-dev
sudo apt-get install xorg-dev sudo apt-get install xorg-dev
sudo apt-get install libxtst-dev libpng++-dev
sudo apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev sudo apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev
sudo apt-get install libxkbcommon-dev sudo apt-get install libxkbcommon-dev
@ -90,8 +81,6 @@ sudo apt-get install xclip
```yml ```yml
sudo dnf install libxkbcommon-devel libXtst-devel libxkbcommon-x11-devel xorg-x11-xkb-utils-devel sudo dnf install libxkbcommon-devel libXtst-devel libxkbcommon-x11-devel xorg-x11-xkb-utils-devel
sudo dnf install libpng-devel
sudo dnf install xsel sudo dnf install xsel
sudo dnf install xclip sudo dnf install xclip
``` ```
@ -99,9 +88,7 @@ sudo dnf install xclip
``` ```
go get github.com/go-vgo/robotgo go get github.com/go-vgo/robotgo
``` ```
It's that easy! It's that easy!
png.h: No such file or directory? Please see [issues/47](https://github.com/go-vgo/robotgo/issues/47).
## Update: ## Update:
``` ```
@ -172,7 +159,7 @@ func main() {
} }
``` ```
#### [位图](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/mian.go) <!-- #### [位图](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/mian.go)
```Go ```Go
package main package main
@ -192,7 +179,7 @@ func main() {
robotgo.SaveBitmap(bitmap, "test.png") robotgo.SaveBitmap(bitmap, "test.png")
} }
``` ``` -->
#### [事件](https://github.com/go-vgo/robotgo/blob/master/examples/event/main.go) #### [事件](https://github.com/go-vgo/robotgo/blob/master/examples/event/main.go)

View File

@ -12,7 +12,7 @@ dependencies:
# - sudo apt-get install libghc6-x11-dev # - sudo apt-get install libghc6-x11-dev
# - sudo apt-get install libgl1-mesa-swx11-dev # - sudo apt-get install libgl1-mesa-swx11-dev
- sudo apt-get install xorg-dev - sudo apt-get install xorg-dev
- sudo apt-get install libxtst-dev libpng++-dev # - sudo apt-get install libxtst-dev libpng++-dev
# Event: # Event:
- sudo apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev - sudo apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev
- sudo apt-get install libxkbcommon-dev - sudo apt-get install libxkbcommon-dev

View File

@ -30,29 +30,29 @@ func main() {
bitmap := robotgo.CaptureScreen(100, 200, 30, 40) bitmap := robotgo.CaptureScreen(100, 200, 30, 40)
fmt.Println("CaptureScreen...", bitmap) fmt.Println("CaptureScreen...", bitmap)
// searches for needle in bitmap // // searches for needle in bitmap
fx, fy := robotgo.FindBitmap(bitmap) // fx, fy := robotgo.FindBitmap(bitmap)
fmt.Println("FindBitmap------", fx, fy) // fmt.Println("FindBitmap------", fx, fy)
// returns new bitmap object created from a portion of another // // returns new bitmap object created from a portion of another
bitpos := robotgo.GetPortion(bitmap, 10, 10, 11, 10) // bitpos := robotgo.GetPortion(bitmap, 10, 10, 11, 10)
fmt.Println(bitpos) // fmt.Println(bitpos)
// creates bitmap from string by bitmap // // creates bitmap from string by bitmap
bitstr := robotgo.TostringBitmap(bitmap) // bitstr := robotgo.TostringBitmap(bitmap)
fmt.Println("bitstr...", bitstr) // fmt.Println("bitstr...", bitstr)
// sbitmap := robotgo.BitmapFromstring(bitstr, 2) // // sbitmap := robotgo.BitmapFromstring(bitstr, 2)
// fmt.Println("...", sbitmap) // // fmt.Println("...", sbitmap)
// saves image to absolute filepath in the given format // // saves image to absolute filepath in the given format
robotgo.SaveBitmap(bitmap, "test.png") // robotgo.SaveBitmap(bitmap, "test.png")
robotgo.SaveBitmap(bitmap, "test31.tif", 1) // robotgo.SaveBitmap(bitmap, "test31.tif", 1)
// convert image // // convert image
robotgo.Convert("test.png", "test.tif") // robotgo.Convert("test.png", "test.tif")
// open image bitmap // // open image bitmap
openbit := robotgo.OpenBitmap("test.tif") // openbit := robotgo.OpenBitmap("test.tif")
fmt.Println("openBitmap...", openbit) // fmt.Println("openBitmap...", openbit)
} }

View File

@ -124,45 +124,45 @@ func screen() {
} }
func bitmap() { // func bitmap() {
//////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////
// Bitmap // // Bitmap
//////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////
// gets all of the screen // // gets all of the screen
abitMap := robotgo.CaptureScreen() // abitMap := robotgo.CaptureScreen()
fmt.Println("abitMap...", abitMap) // fmt.Println("abitMap...", abitMap)
// gets part of the screen // // gets part of the screen
bitmap := robotgo.CaptureScreen(100, 200, 30, 40) // bitmap := robotgo.CaptureScreen(100, 200, 30, 40)
fmt.Println("CaptureScreen...", bitmap) // fmt.Println("CaptureScreen...", bitmap)
// searches for needle in bitmap // // searches for needle in bitmap
fx, fy := robotgo.FindBitmap(bitmap) // fx, fy := robotgo.FindBitmap(bitmap)
fmt.Println("FindBitmap------", fx, fy) // fmt.Println("FindBitmap------", fx, fy)
// returns new bitmap object created from a portion of another // // returns new bitmap object created from a portion of another
bitpos := robotgo.GetPortion(bitmap, 10, 10, 11, 10) // bitpos := robotgo.GetPortion(bitmap, 10, 10, 11, 10)
fmt.Println(bitpos) // fmt.Println(bitpos)
// creates bitmap from string by bitmap // // creates bitmap from string by bitmap
bitstr := robotgo.TostringBitmap(bitmap) // bitstr := robotgo.TostringBitmap(bitmap)
fmt.Println("bitstr...", bitstr) // fmt.Println("bitstr...", bitstr)
// sbitmap := robotgo.BitmapFromstring(bitstr, 2) // // sbitmap := robotgo.BitmapFromstring(bitstr, 2)
// fmt.Println("...", sbitmap) // // fmt.Println("...", sbitmap)
// saves image to absolute filepath in the given format // // saves image to absolute filepath in the given format
robotgo.SaveBitmap(bitmap, "test.png") // robotgo.SaveBitmap(bitmap, "test.png")
robotgo.SaveBitmap(bitmap, "test31.tif", 1) // robotgo.SaveBitmap(bitmap, "test31.tif", 1)
// convert image // // convert image
robotgo.Convert("test.png", "test.tif") // robotgo.Convert("test.png", "test.tif")
// open image bitmap // // open image bitmap
openbit := robotgo.OpenBitmap("test.tif") // openbit := robotgo.OpenBitmap("test.tif")
fmt.Println("openBitmap...", openbit) // fmt.Println("openBitmap...", openbit)
} // }
func event() { func event() {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -285,7 +285,7 @@ func main() {
// Read the screen // Read the screen
screen() screen()
// Bitmap and image processing // Bitmap and image processing
bitmap() // bitmap()
// Global event listener // Global event listener
event() event()
// Window Handle and progress // Window Handle and progress

View File

@ -25,18 +25,21 @@ package robotgo
/* /*
//#if defined(IS_MACOSX) //#if defined(IS_MACOSX)
#cgo darwin CFLAGS: -x objective-c -Wno-deprecated-declarations -I/usr/local/opt/libpng/include -I/usr/local/opt/zlib/include #cgo darwin CFLAGS: -x objective-c -Wno-deprecated-declarations -I/usr/local/opt/libpng/include -I/usr/local/opt/zlib/include
#cgo darwin LDFLAGS: -framework Cocoa -framework OpenGL -framework IOKit -framework Carbon -framework CoreFoundation -L/usr/local/opt/libpng/lib -lpng -L/usr/local/opt/zlib/lib -lz #cgo darwin LDFLAGS: -framework Cocoa -framework OpenGL -framework IOKit -framework Carbon -framework CoreFoundation
// -L/usr/local/opt/libpng/lib -lpng -L/usr/local/opt/zlib/lib -lz
//#elif defined(USE_X11) //#elif defined(USE_X11)
// drop -std=c11 // drop -std=c11
#cgo linux CFLAGS:-I/usr/src #cgo linux CFLAGS:-I/usr/src
#cgo linux LDFLAGS:-L/usr/src -lpng -lz -lX11 -lXtst -lX11-xcb -lxcb -lxcb-xkb -lxkbcommon -lxkbcommon-x11 -lm #cgo linux LDFLAGS:-L/usr/src -lX11 -lXtst -lX11-xcb -lxcb -lxcb-xkb -lxkbcommon -lxkbcommon-x11 -lm
// -lpng -lz
//#endif //#endif
#cgo windows LDFLAGS: -lgdi32 -luser32 -lpng -lz #cgo windows LDFLAGS: -lgdi32 -luser32
// -lpng -lz
//#include <AppKit/NSEvent.h> //#include <AppKit/NSEvent.h>
#include "screen/goScreen.h" #include "screen/goScreen.h"
#include "mouse/goMouse.h" #include "mouse/goMouse.h"
#include "key/goKey.h" #include "key/goKey.h"
#include "bitmap/goBitmap.h" // #include "bitmap/goBitmap.h"
#include "event/goEvent.h" #include "event/goEvent.h"
#include "window/goWindow.h" #include "window/goWindow.h"
*/ */
@ -573,137 +576,137 @@ func SetKeyboardDelay(x int) {
|______/ |__| |__| |__| |__| /__/ \__\ | _| |______/ |__| |__| |__| |__| /__/ \__\ | _|
*/ */
// FindBitmap find the bitmap // // FindBitmap find the bitmap
func FindBitmap(args ...interface{}) (int, int) { // func FindBitmap(args ...interface{}) (int, int) {
var bit C.MMBitmapRef // var bit C.MMBitmapRef
bit = args[0].(C.MMBitmapRef) // bit = args[0].(C.MMBitmapRef)
var rect C.MMRect // var rect C.MMRect
Try(func() { // Try(func() {
rect.origin.x = C.size_t(args[1].(int)) // rect.origin.x = C.size_t(args[1].(int))
rect.origin.y = C.size_t(args[2].(int)) // rect.origin.y = C.size_t(args[2].(int))
rect.size.width = C.size_t(args[3].(int)) // rect.size.width = C.size_t(args[3].(int))
rect.size.height = C.size_t(args[4].(int)) // rect.size.height = C.size_t(args[4].(int))
}, func(e interface{}) { // }, func(e interface{}) {
// fmt.Println("err:::", e) // // fmt.Println("err:::", e)
// rect.origin.x = x // // rect.origin.x = x
// rect.origin.y = y // // rect.origin.y = y
// rect.size.width = w // // rect.size.width = w
// rect.size.height = h // // rect.size.height = h
}) // })
pos := C.aFindBitmap(bit, rect) // pos := C.aFindBitmap(bit, rect)
// fmt.Println("pos----", pos) // // fmt.Println("pos----", pos)
return int(pos.x), int(pos.y) // return int(pos.x), int(pos.y)
} // }
// OpenBitmap open the bitmap // // OpenBitmap open the bitmap
func OpenBitmap(args ...interface{}) C.MMBitmapRef { // func OpenBitmap(args ...interface{}) C.MMBitmapRef {
path := C.CString(args[0].(string)) // path := C.CString(args[0].(string))
var mtype C.uint16_t // var mtype C.uint16_t
Try(func() { // Try(func() {
mtype = C.uint16_t(args[1].(int)) // mtype = C.uint16_t(args[1].(int))
}, func(e interface{}) { // }, func(e interface{}) {
// fmt.Println("err:::", e) // // fmt.Println("err:::", e)
mtype = 1 // mtype = 1
}) // })
bit := C.bitmap_open(path, mtype) // bit := C.bitmap_open(path, mtype)
defer C.free(unsafe.Pointer(path)) // defer C.free(unsafe.Pointer(path))
// fmt.Println("opening...", bit) // // fmt.Println("opening...", bit)
return bit // return bit
// defer C.free(unsafe.Pointer(path))
}
// SaveBitmap save the bitmap
func SaveBitmap(args ...interface{}) string {
var mtype C.uint16_t
Try(func() {
mtype = C.uint16_t(args[2].(int))
}, func(e interface{}) {
// fmt.Println("err:::", e)
mtype = 1
})
path := C.CString(args[1].(string))
savebit := C.bitmap_save(args[0].(C.MMBitmapRef), path, mtype)
// fmt.Println("saved...", savebit)
// return bit
defer C.free(unsafe.Pointer(path))
return C.GoString(savebit)
}
// func SaveBitmap(bit C.MMBitmapRef, gpath string, mtype C.MMImageType) {
// path := C.CString(gpath)
// savebit := C.aSaveBitmap(bit, path, mtype)
// fmt.Println("saving...", savebit)
// // return bit
// // defer C.free(unsafe.Pointer(path)) // // defer C.free(unsafe.Pointer(path))
// } // }
// TostringBitmap tostring bitmap // // SaveBitmap save the bitmap
func TostringBitmap(bit C.MMBitmapRef) *C.char { // func SaveBitmap(args ...interface{}) string {
// str_bit := C.aTostringBitmap(bit) // var mtype C.uint16_t
strBit := C.aTostringBitmap(bit) // Try(func() {
// fmt.Println("...", str_bit) // mtype = C.uint16_t(args[2].(int))
// return str_bit // }, func(e interface{}) {
return strBit // // fmt.Println("err:::", e)
} // mtype = 1
// })
// GetPortion get portion // path := C.CString(args[1].(string))
func GetPortion(bit C.MMBitmapRef, x, y, w, h C.size_t) C.MMBitmapRef { // savebit := C.bitmap_save(args[0].(C.MMBitmapRef), path, mtype)
var rect C.MMRect // // fmt.Println("saved...", savebit)
rect.origin.x = x // // return bit
rect.origin.y = y // defer C.free(unsafe.Pointer(path))
rect.size.width = w
rect.size.height = h
pos := C.aGetPortion(bit, rect) // return C.GoString(savebit)
return pos // }
}
// Convert convert bitmap // // func SaveBitmap(bit C.MMBitmapRef, gpath string, mtype C.MMImageType) {
func Convert(args ...interface{}) { // // path := C.CString(gpath)
var mtype int // // savebit := C.aSaveBitmap(bit, path, mtype)
Try(func() { // // fmt.Println("saving...", savebit)
mtype = args[2].(int) // // // return bit
}, func(e interface{}) { // // // defer C.free(unsafe.Pointer(path))
// fmt.Println("err:::", e) // // }
mtype = 1
})
//C.CString()
opath := args[0].(string)
spath := args[1].(string)
bitmap := OpenBitmap(opath)
// fmt.Println("a----", bit_map)
SaveBitmap(bitmap, spath, mtype)
}
// FreeBitmap free and dealloc bitmap // // TostringBitmap tostring bitmap
func FreeBitmap(bitmap C.MMBitmapRef) { // func TostringBitmap(bit C.MMBitmapRef) *C.char {
// C.destroyMMBitmap(bitmap) // // str_bit := C.aTostringBitmap(bit)
C.bitmap_dealloc(bitmap) // strBit := C.aTostringBitmap(bit)
} // // fmt.Println("...", str_bit)
// // return str_bit
// return strBit
// }
// ReadBitmap returns false and sets error if |bitmap| is NULL // // GetPortion get portion
func ReadBitmap(bitmap C.MMBitmapRef) bool { // func GetPortion(bit C.MMBitmapRef, x, y, w, h C.size_t) C.MMBitmapRef {
abool := C.bitmap_ready(bitmap) // var rect C.MMRect
gbool := bool(abool) // rect.origin.x = x
return gbool // rect.origin.y = y
} // rect.size.width = w
// rect.size.height = h
// CopyBitpb copy bitmap to pasteboard // pos := C.aGetPortion(bit, rect)
func CopyBitpb(bitmap C.MMBitmapRef) bool { // return pos
abool := C.bitmap_copy_to_pboard(bitmap) // }
gbool := bool(abool)
return gbool
}
// DeepCopyBit deep copy bitmap // // Convert convert bitmap
func DeepCopyBit(bitmap C.MMBitmapRef) C.MMBitmapRef { // func Convert(args ...interface{}) {
bit := C.bitmap_deepcopy(bitmap) // var mtype int
return bit // Try(func() {
} // mtype = args[2].(int)
// }, func(e interface{}) {
// // fmt.Println("err:::", e)
// mtype = 1
// })
// //C.CString()
// opath := args[0].(string)
// spath := args[1].(string)
// bitmap := OpenBitmap(opath)
// // fmt.Println("a----", bit_map)
// SaveBitmap(bitmap, spath, mtype)
// }
// // FreeBitmap free and dealloc bitmap
// func FreeBitmap(bitmap C.MMBitmapRef) {
// // C.destroyMMBitmap(bitmap)
// C.bitmap_dealloc(bitmap)
// }
// // ReadBitmap returns false and sets error if |bitmap| is NULL
// func ReadBitmap(bitmap C.MMBitmapRef) bool {
// abool := C.bitmap_ready(bitmap)
// gbool := bool(abool)
// return gbool
// }
// // CopyBitpb copy bitmap to pasteboard
// func CopyBitpb(bitmap C.MMBitmapRef) bool {
// abool := C.bitmap_copy_to_pboard(bitmap)
// gbool := bool(abool)
// return gbool
// }
// // DeepCopyBit deep copy bitmap
// func DeepCopyBit(bitmap C.MMBitmapRef) C.MMBitmapRef {
// bit := C.bitmap_deepcopy(bitmap)
// return bit
// }
/* /*
___________ ____ _______ .__ __. .___________. ___________ ____ _______ .__ __. .___________.