コード例 #1
0
ファイル: options.go プロジェクト: monadbobo/agent_leveldb
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))
	}
}
コード例 #2
0
ファイル: conv.go プロジェクト: cayleydb/dgraph
func boolToUchar(b bool) C.uchar {
	uc := C.uchar(0)
	if b {
		uc = C.uchar(1)
	}
	return uc
}
コード例 #3
0
ファイル: image.go プロジェクト: jimmyfrasche/cairo
//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)
}
コード例 #4
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
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)
}
コード例 #5
0
ファイル: sdl_gfx.go プロジェクト: veandco/go-sdl2
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
}
コード例 #6
0
ファイル: sdl_gfx.go プロジェクト: veandco/go-sdl2
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
}
コード例 #7
0
ファイル: options.go プロジェクト: monadbobo/agent_leveldb
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))
	}

}
コード例 #8
0
ファイル: new.go プロジェクト: acsellers/Go510
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)
}
コード例 #9
0
ファイル: golibusb.go プロジェクト: acsellers/Go510
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)
	}
}
コード例 #10
0
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
}
コード例 #11
0
ファイル: eth_linux.go プロジェクト: str4d/i2p-tools
func bytesToUchar(data []byte) (d []C.uchar) {
	d = make([]C.uchar, len(data))
	for i, c := range data {
		d[i] = C.uchar(c)
	}
	return
}
コード例 #12
0
ファイル: golibusb.go プロジェクト: acsellers/Go510
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")
		}
	}

}
コード例 #13
0
ファイル: window.go プロジェクト: nzlov/wxgo
func (w *window) SetTransparent(alpha uint8) bool {
	p := ptr(w)
	if p == nil {
		return false
	}
	return goBool(C.wxWindow_SetTransparent(p, C.uchar(alpha)))
}
コード例 #14
0
ファイル: message.go プロジェクト: jeffallen/miniv
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
}
コード例 #15
0
ファイル: trayhost.go プロジェクト: Comdex/trayhost
// 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
}
コード例 #16
0
ファイル: sdl_gfx.go プロジェクト: veandco/go-sdl2
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
}
コード例 #17
0
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
}
コード例 #18
0
ファイル: sdl_gfx.go プロジェクト: veandco/go-sdl2
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
}
コード例 #19
0
ファイル: os_windows.go プロジェクト: skyview059/vu
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))
}
コード例 #20
0
ファイル: os_darwin.go プロジェクト: skyview059/vu
func (o *osx) showCursor(r *nrefs, show bool) {
	tf1 := 0
	if show {
		tf1 = 1
	}
	C.gs_show_cursor(C.uchar(tf1))
}
コード例 #21
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func ctrl(c Controller, i uint8) {
	//
	l, r, j := uint(volume_left), uint(volume_right), uint(i)
	sum := l + r
	mid := sum / 2
	switch c {
	case Left:
		l = j
	case Right:
		r = j
	case Balance:
		if i == 0 {
			l, r = sum, 0
		} else if j == MaxVol {
			l, r = 0, sum
		} else {
			r = (sum * j) / MaxVol
			l = sum - r
		}
	case All:
		if l == r {
			l, r = j, j
		} else {
			l += j
			if l >= mid {
				l -= mid
			} else {
				l = 0
			}
			r += j
			if r >= mid {
				r -= mid
			} else {
				r = 0
			}
		}
	}
	if l > MaxVol {
		l = MaxVol
	}
	if r > MaxVol {
		r = MaxVol
	}
	volume_left, volume_right = uint8(l), uint8(r)
	C.volCtrl(C.int(cdd), C.uchar(volume_left), C.uchar(volume_right))
	balance = Volume(Balance)
}
コード例 #22
0
ファイル: ed25519.go プロジェクト: majestrate/go-i2p
func (k Ed25519PublicKey) NewVerifier() (v Verifier, err error) {
	ev := new(Ed25519Verifier)
	for i, b := range k {
		ev.k[i] = C.uchar(b)
	}
	v = ev
	return
}
コード例 #23
0
ファイル: tray_darwin.go プロジェクト: tnhu/systray
func (p *_Systray) addItemToNativeMenu(info CallbackInfo, index int) {
	cItemName := C.CString(info.ItemName)
	defer C.free(unsafe.Pointer(cItemName))
	cIndex := C.uint(index)
	var cEnabled C.uchar
	if info.Disabled || info.Callback == nil {
		cEnabled = C.uchar(0)
	} else {
		cEnabled = C.uchar(1)
	}
	var cChecked C.uchar
	if info.Checked {
		cChecked = C.uchar(1)
	} else {
		cChecked = C.uchar(0)
	}
	C.addSystrayMenuItem(cItemName, unsafe.Pointer(p), cIndex, cEnabled, cChecked)
}
コード例 #24
0
ファイル: gomilter.go プロジェクト: rayyang2000/gomilter
// See also: http://bit.ly/1HVWA9I
func SetPriv(ctx uintptr, privatedata interface{}) int {
	// privatedata seems to work for any data type
	// Structs must have exported fields

	// Serialize Go privatedata into a byte slice
	bytedata, _ := GobEncode(privatedata)

	// length and size
	// length is a uint32 (usually 4 bytes)
	// the length will be stored in front of the byte sequence
	length := uint32(len(bytedata))
	lengthsize := C.size_t(unsafe.Sizeof(length))
	buf := new(bytes.Buffer)
	err := binary.Write(buf, binary.BigEndian, length)
	if err != nil {
		return -1
	}
	lengthbytes := buf.Bytes()

	// Allocate memory for the length and byte sequence
	CArray := (*C.uchar)(C.malloc(lengthsize + C.size_t(length)))

	var lenStart, seqStart uintptr
	lenStart = uintptr(unsafe.Pointer(CArray))
	seqStart = lenStart + uintptr(lengthsize)

	CArray = (*C.uchar)(unsafe.Pointer(lenStart))

	for i := uintptr(0); i < uintptr(lengthsize); i++ {
		CArray = (*C.uchar)(unsafe.Pointer(lenStart + i))
		*CArray = C.uchar(lengthbytes[i])
	}

	// Now copy the data bytes to the position after the length
	for i := uintptr(0); i < uintptr(length); i++ {
		CArray = (*C.uchar)(unsafe.Pointer(seqStart + i))
		*CArray = C.uchar(bytedata[i])
	}

	// Call libmilter smfi_setpriv
	type CtxPtr *C.struct_smfi_str
	return int(C.smfi_setpriv(int2ctx(ctx), unsafe.Pointer(lenStart)))
}
コード例 #25
0
// SetCacheIndexAndFilterBlock indicates if we'd put index/filter blocks to
// the block cache. If not specified, each "table reader" object will pre-load
// index/filter block during table initialization.
// Default: false
func (o *BlockBasedTableOptions) SetCacheIndexAndFilterBlocks(val bool) {
	var value uint8
	if val {
		value = 1
	}
	C.rocksdb_block_based_options_set_cache_index_and_filter_blocks(
		o.c,
		C.uchar(value),
	)
}
コード例 #26
0
ファイル: wkb.go プロジェクト: helmi03/gogeos
func (d *wkbDecoder) decode(wkb []byte) (*Geometry, error) {
	var cwkb []C.uchar
	for i := range wkb {
		cwkb = append(cwkb, C.uchar(wkb[i]))
	}
	g := cGEOSWKBReader_read(d.r, &cwkb[0], C.size_t(len(wkb)))
	if g == nil {
		return nil, Error()
	}
	return geomFromPtr(g), nil
}
コード例 #27
0
ファイル: usb.go プロジェクト: hanwen/usb
func (h *DeviceHandle) InterruptTransfer(endpoint byte, data []byte, timeout int) (actual int, err error) {
	var ptr *byte
	if len(data) > 0 {
		ptr = &data[0]
	}

	var n C.int
	e := C.libusb_bulk_transfer(h.me(), C.uchar(endpoint), (*C.uchar)(ptr),
		C.int(len(data)), &n, C.uint(timeout))
	return int(n), toErr(e)
}
コード例 #28
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func soundfile() *os.File {
	//
	dev := env.Par(1)
	if dev == "" {
		dev = "cdrom"
	}
	var e error
	cdfile, e = os.OpenFile("/dev/"+dev, syscall.O_RDONLY|syscall.O_NONBLOCK, 0440)
	if e != nil {
		return nil
	}
	cdd = int(cdfile.Fd())
	C.closeTray(C.int(cdd))
	counter := 0
	for { // anfangs dauert's manchmal 'ne Weile ...
		counter++
		if counter > 30 {
			return nil
		}
		_, status = cstatus(cdd)
		if status == invalid {
			ker.Msleep(250 * 1000)
		} else {
			break
		}
	}
	nTracks = uint8(C.nTracks(C.int(cdd)))
	n1 := nTracks + 1
	startFrame = make([]uint, n1)
	StartTime = make([]*clk.Imp, nTracks)
	Length = make([]*clk.Imp, nTracks)
	for t := uint8(0); t <= nTracks; t++ {
		startFrame[t] = uint(C.startFrame(C.int(cdd), C.uchar(t)))
		if t < nTracks {
			StartTime[t] = clk.New()
			Length[t] = clk.New()
			m, s := ms(startFrame[t] - offset)
			StartTime[t].Set(m/60, m%60, s)
		}
		if t > 0 {
			m, s := ms(startFrame[t] - startFrame[t-1] - offset)
			Length[t-1].Set(m/60, m%60, s)
		}
	}
	m, s := ms(startFrame[nTracks] - 2*offset)
	TotalTime.Set(m/60, m%60, s)
	var l, r C.uchar
	C.volRead(C.int(cdd), &l, &r)
	volume_left, volume_right = uint8(l), uint8(r)
	//  C.lockDoor (C.int(cdd))
	Ctrl(All, MaxVol/3)
	return cdfile
}
コード例 #29
0
ファイル: new.go プロジェクト: acsellers/Go510
func SetLCD(pix *image.Gray) {
	if !Connected {
		if err := StartLibUsb(); err != nil {
			return
		}
		defer EndLibUsb()
	}
	var img [992]C.uchar
	imgOffset := 32
	var curr, row uint8

	for offset := 0; offset < 5; offset++ {
		for col := 0; col < 160; col++ {
			curr = 0
			for row = 0; row < 8; row++ {
				if pix.Pix[(offset*8+int(row)-pix.Rect.Min.Y)*pix.Stride+(col-pix.Rect.Min.X)]>>4 > 0 {
					curr += 1 << row
				}
			}
			img[imgOffset] = C.uchar(curr)
			imgOffset++
		}
	}
	for col := 0; col < 160; col++ {
		curr = 0
		for row = 0; row < 3; row++ {
			if pix.Pix[(40+int(row)-pix.Rect.Min.Y)*pix.Stride+(col-pix.Rect.Min.X)]>>4 > 0 {
				curr += 1 << row
			}
		}
		img[imgOffset] = C.uchar(curr)
		imgOffset++
	}

	//magic byte from libg15 and USBTrace
	img[0] = 0x03

	transferred := C.int(0)
	C.libusb_interrupt_transfer(keyboardHandle, 0x3, &img[0], 992, &transferred, 1000)
}
コード例 #30
0
ファイル: eeprom.go プロジェクト: sstallion/go
func (d *Device) transferN(endpoint uint8, data []byte, n int) error {
	if m := int(C.libusb_get_max_packet_size(d.dev, C.uchar(endpoint))); n == 0 {
		n = m
	} else if n > m {
		return errors.New("invalid packet size")
	}

	for len, off := len(data), 0; len > 0; {
		var transferred int

		if n > len {
			n = len
		}
		if err := C.libusb_bulk_transfer(d.handle, C.uchar(endpoint), (*C.uchar)(&data[off]), C.int(n),
			(*C.int)(unsafe.Pointer(&transferred)), 2500); err != C.LIBUSB_SUCCESS {
			return &libusbError{err}
		}
		len -= transferred
		off += transferred
	}
	return nil
}