Esempio n. 1
0
// ===== CFData =====
func convertBytesToCFData(data []byte) C.CFDataRef {
	var ptr *C.UInt8
	if len(data) > 0 {
		ptr = (*C.UInt8)((&data[0]))
	}
	return C.CFDataCreate(nil, ptr, C.CFIndex(len(data)))
}
Esempio n. 2
0
func CGImageCreateWithImage(img image.Image) (cgimg C.CGImageRef, err error) {
	var data imageData

	if data, err = extractImageData(img); err != nil {
		return
	}

	memory := C.CFDataCreate(
		nil,
		(*C.UInt8)(unsafe.Pointer(&data.pixels[0])),
		C.CFIndex(len(data.pixels)),
	)

	provider := C.CGDataProviderCreateWithCFData(memory)

	cgimg = C.CGImageCreate(
		C.size_t(data.width),
		C.size_t(data.height),
		C.size_t(data.bpc),
		C.size_t(data.bpp),
		C.size_t(data.stride),
		data.colors,
		data.info,
		provider,
		nil,
		false,
		C.kCGRenderingIntentDefault,
	)

	C.CFRelease(provider)
	C.CFRelease(memory)
	C.CFRelease(data.colors)
	return
}
Esempio n. 3
0
// The returned CFDataRef, if non-nil, must be released via CFRelease.
func bytesToCFData(b []byte) C.CFDataRef {
	var p *C.UInt8
	if len(b) > 0 {
		p = (*C.UInt8)(&b[0])
	}
	return C.CFDataCreate(nil, p, C.CFIndex(len(b)))
}
func CFNetServiceSetTXTData(cns *CFNetService, data []byte) bool {
	p := unsafe.Pointer(nil)
	if data != nil && len(data) > 0 {
		p = unsafe.Pointer(&data[0])
	}
	data_ := C.CFDataCreate(nil, (*C.UInt8)(p), C.CFIndex(len(data)))
	retval := C.CFNetServiceSetTXTData(cns.ref, data_)
	C.CFRelease((C.CFTypeRef)(data_))
	return retval != 0
}
Esempio n. 5
0
// BytesToCFData will return a CFDataRef and if non-nil, must be released with
// Release(ref).
func BytesToCFData(b []byte) (C.CFDataRef, error) {
	if uint64(len(b)) > math.MaxUint32 {
		return nil, errors.New("Data is too large")
	}
	var p *C.UInt8
	if len(b) > 0 {
		p = (*C.UInt8)(&b[0])
	}
	cfData := C.CFDataCreate(nil, p, C.CFIndex(len(b)))
	if cfData == nil {
		return nil, fmt.Errorf("CFDataCreate failed")
	}
	return cfData, nil
}