作者:monadbob
项目:agent_leveld
func (option *Options) Set_create_if_exists(flag bool) {
if flag {
C.leveldb_options_set_error_if_exists(option.options, C.uchar(1))
} else {
C.leveldb_options_set_error_if_exists(option.options, C.uchar(0))
}
}
作者:cayleyd
项目:dgrap
func boolToUchar(b bool) C.uchar {
uc := C.uchar(0)
if b {
uc = C.uchar(1)
}
return uc
}
作者:jimmyfrasch
项目:cair
//FromImage copies an image into a surface.
//
//The created image surface will have the same size as img,
//the optimal stride for img's width, and FormatARGB32.
//
//Originally cairo_image_surface_create_for_data and
//cairo_format_stride_for_width.
func FromImage(img image.Image) (ImageSurface, error) {
f := FormatARGB32.c()
b := img.Bounds()
w, h := b.Dx(), b.Dy()
s := int(C.cairo_format_stride_for_width(f, C.int(w)))
n := s * h
data := (*C.uchar)(C.calloc(C.size_t(uintptr(n)), 1))
pseudoslice := (*[1 << 30]C.uchar)(unsafe.Pointer(data))[:n:n]
i := 0
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
r, g, b, a := img.At(x, y).RGBA()
pseudoslice[i+oA] = C.uchar(a)
pseudoslice[i+oR] = C.uchar(r)
pseudoslice[i+oG] = C.uchar(g)
pseudoslice[i+oB] = C.uchar(b)
i += 4
}
i += 4 * (s/4 - w)
}
is := C.cairo_image_surface_create_for_data(data, f, C.int(w), C.int(h), C.int(s))
C.cairo_surface_set_user_data(is, imgKey, unsafe.Pointer(data), free)
return newImg(is, FormatARGB32, w, h, s)
}
作者:CaptainSoOm
项目:Un
func ctrl1(c Controller, lauter bool) {
//
switch c {
case Left:
if lauter {
if volume_left < MaxVol {
volume_left++
}
} else {
if volume_left > 0 {
volume_left--
}
}
case Right:
if lauter {
if volume_right < MaxVol {
volume_right++
}
} else {
if volume_right > 0 {
volume_right--
}
}
case Balance:
if lauter {
if volume_left < MaxVol {
volume_left++
}
if volume_right > 0 {
volume_right--
}
} else {
if volume_right < MaxVol {
volume_right++
}
if volume_left > 0 {
volume_left--
}
}
case All:
if lauter {
if volume_left < MaxVol {
volume_left++
}
if volume_right < MaxVol {
volume_right++
}
} else {
if volume_left > 0 {
volume_left--
}
if volume_right > 0 {
volume_right--
}
}
}
C.volCtrl(C.int(cdd), C.uchar(volume_left), C.uchar(volume_right))
balance = Volume(Balance)
}
作者:veandc
项目:go-sdl
func ImageFilterClipToRange(src1, dest []byte, tmin, tmax byte) bool {
_src1 := (*C.uchar)(unsafe.Pointer(&src1[0]))
_dest := (*C.uchar)(unsafe.Pointer(&dest[0]))
_len := C.uint(min(len(src1), len(dest)))
_tmin := C.uchar(tmin)
_tmax := C.uchar(tmax)
return C.SDL_imageFilterClipToRange(_src1, _dest, _len, _tmin, _tmax) == 0
}
作者:veandc
项目:go-sdl
func ImageFilterShiftRightAndMultByByte(src1, dest []byte, n, c byte) bool {
_src1 := (*C.uchar)(unsafe.Pointer(&src1[0]))
_dest := (*C.uchar)(unsafe.Pointer(&dest[0]))
_len := C.uint(min(len(src1), len(dest)))
_n := C.uchar(n)
_c := C.uchar(c)
return C.SDL_imageFilterShiftRightAndMultByByte(_src1, _dest, _len, _n, _c) == 0
}
作者:monadbob
项目:agent_leveld
func (option *Options) Set_create_if_missing(flag bool) {
if flag {
C.leveldb_options_set_create_if_missing(option.options, C.uchar(1))
} else {
C.leveldb_options_set_create_if_missing(option.options, C.uchar(0))
}
}
作者:acseller
项目:Go51
func SetColor(clr color.Color) {
command_buffer := [4]C.uchar{0x05, 0x00, 0x00, 0x00}
r, g, b, _ := clr.RGBA()
command_buffer[1] = C.uchar(uint8(r))
command_buffer[2] = C.uchar(uint8(g))
command_buffer[3] = C.uchar(uint8(b))
C.libusb_control_transfer(keyboardHandle, 33, 9, 0x305, 1, &command_buffer[0], 0x4, 1000)
}
作者:acseller
项目:Go51
func ColorChange(handle *C.struct_libusb_device_handle, color chan byte) {
command_buffer := [4]C.uchar{0x05, 0x00, 0x00, 0x00}
for {
command_buffer[1] = C.uchar(<-color)
command_buffer[2] = C.uchar(<-color)
command_buffer[3] = C.uchar(<-color)
r := C.libusb_control_transfer(handle, 33, 9, 0x305, 1, &command_buffer[0], 0x4, 1000)
log.Printf("Color Change Response %d\n", r)
}
}
作者:henrylee2c
项目:trayhos
func create_image(image Image) (C.struct_image, func()) {
var img C.struct_image
if image.Kind == "" || len(image.Bytes) == 0 {
return img, func() {}
}
// Copy the image data into unmanaged memory.
cImageKind := C.CString(string(image.Kind))
cImageData := C.malloc(C.size_t(len(image.Bytes)))
freeImg := func() {
C.free(unsafe.Pointer(cImageKind))
C.free(cImageData)
}
var cImageDataSlice []C.uchar
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&cImageDataSlice))
sliceHeader.Cap = len(image.Bytes)
sliceHeader.Len = len(image.Bytes)
sliceHeader.Data = uintptr(cImageData)
for i, b := range image.Bytes {
cImageDataSlice[i] = C.uchar(b)
}
img.kind = cImageKind
img.bytes = unsafe.Pointer(&cImageDataSlice[0])
img.length = C.int(len(image.Bytes))
return img, freeImg
}
作者:str4
项目:i2p-tool
func bytesToUchar(data []byte) (d []C.uchar) {
d = make([]C.uchar, len(data))
for i, c := range data {
d[i] = C.uchar(c)
}
return
}
作者:acseller
项目:Go51
func SpecialKeyMonitor(handle *C.struct_libusb_device_handle, output chan guinput.KeyEvent) {
data_buffer := make([]C.uchar, 512)
key_endpoint := C.uchar(0x82)
transferred_bytes := C.int(0)
pressed_duos := uint8(0)
for {
e := C.libusb_interrupt_transfer(handle, key_endpoint, &data_buffer[0], 512, &transferred_bytes, 10)
switch e {
case 0:
//we did it
log.Print("Special Key data received")
//the media buttons and dials in the top uh right
//THey transfer 2 bytes and the first byte is 2, so duos
if transferred_bytes == 2 && data_buffer[0] == 0x02 {
ParseDuos(uint8(data_buffer[1]), pressed_duos, output)
pressed_duos = uint8(data_buffer[1])
}
for i := 0; i < int(transferred_bytes); i++ {
fmt.Printf("%02x\n", data_buffer[i])
}
case -7:
//nothing happened
default:
//augh, panic
fmt.Println("Augh panic")
}
}
}
作者:nzlo
项目:wxg
func (w *window) SetTransparent(alpha uint8) bool {
p := ptr(w)
if p == nil {
return false
}
return goBool(C.wxWindow_SetTransparent(p, C.uchar(alpha)))
}
作者:jeffalle
项目:mini
func Write(m message.Message) ([]byte, error) {
var b C.buf_t
m2 := C.messageNew()
switch m1 := m.(type) {
case *message.Setup:
m2.mtype = C.Setup
s := (*C.struct_Setup)(unsafe.Pointer(ptr(m2.u[:])))
s.ver_min = C.uint32_t(m1.Versions.Min)
s.ver_max = C.uint32_t(m1.Versions.Max)
for i, x := range m1.PeerNaClPublicKey {
s.PeerNaClPublicKey[i] = C.uchar(x)
}
s.mtu = C.uint64_t(m1.Mtu)
s.sharedTokens = C.uint64_t(m1.SharedTokens)
default:
panic("not impl yet")
}
err := C.messageAppend(m2, &b)
if err != C.ERR_OK {
return nil, GoError(err)
}
out := C.GoBytes(unsafe.Pointer(b.buf), C.int(b.len))
C.bufDealloc(&b)
return out, nil
}
作者:Comde
项目:trayhos
// Run the host system's event loop
func EnterLoop(title string, imageData []byte) {
defer C.free(urlPtr)
cTitle := C.CString(title)
defer C.free(unsafe.Pointer(cTitle))
// Copy the image data into unmanaged memory
cImageData := C.malloc(C.size_t(len(imageData)))
defer C.free(cImageData)
var cImageDataSlice []C.uchar
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&cImageDataSlice))
sliceHeader.Cap = len(imageData)
sliceHeader.Len = len(imageData)
sliceHeader.Data = uintptr(cImageData)
for i, v := range imageData {
cImageDataSlice[i] = C.uchar(v)
}
// Enter the loop
C.native_loop(cTitle, &cImageDataSlice[0], C.uint(len(imageData)))
// If reached, user clicked Exit
isExiting = true
}
作者:veandc
项目:go-sdl
func ImageFilterBinarizeUsingThreshold(src1, dest []byte, t byte) bool {
_src1 := (*C.uchar)(unsafe.Pointer(&src1[0]))
_dest := (*C.uchar)(unsafe.Pointer(&dest[0]))
_len := C.uint(min(len(src1), len(dest)))
_t := C.uchar(t)
return C.SDL_imageFilterBinarizeUsingThreshold(_src1, _dest, _len, _t) == 0
}
作者:peacekeepe
项目:golang-github-presbrey-goraptor-de
func (l *Literal) raptor_term() (term *C.raptor_term) {
value := (*C.uchar)(unsafe.Pointer(C.CString(l.Value)))
llen := len(l.Value)
var lang *C.uchar
langlen := len(l.Lang)
if langlen != 0 {
lang = (*C.uchar)(unsafe.Pointer(C.CString(l.Lang)))
}
var datatype *C.raptor_uri
if len(l.Datatype) != 0 {
dtstr := (*C.uchar)(unsafe.Pointer(C.CString(l.Datatype)))
datatype = C.raptor_new_uri(global_world, dtstr)
C.free(unsafe.Pointer(dtstr))
}
term = C.raptor_new_term_from_counted_literal(global_world,
value, C.size_t(llen), datatype, lang, C.uchar(langlen))
if datatype != nil {
C.raptor_free_uri(datatype)
}
if lang != nil {
C.free(unsafe.Pointer(lang))
}
C.free(unsafe.Pointer(value))
return
}
作者:veandc
项目:go-sdl
func ImageFilterShiftLeft(src1, dest []byte, n byte) bool {
_src1 := (*C.uchar)(unsafe.Pointer(&src1[0]))
_dest := (*C.uchar)(unsafe.Pointer(&dest[0]))
_len := C.uint(min(len(src1), len(dest)))
_n := C.uchar(n)
return C.SDL_imageFilterShiftLeft(_src1, _dest, _len, _n) == 0
}
作者:skyview05
项目:v
func (w *win) showCursor(r *nrefs, show bool) {
tf1 := 0
if show {
tf1 = 1
}
C.gs_show_cursor(C.long(r.display), C.uchar(tf1))
}
作者:skyview05
项目:v
func (o *osx) showCursor(r *nrefs, show bool) {
tf1 := 0
if show {
tf1 = 1
}
C.gs_show_cursor(C.uchar(tf1))
}