Ejemplo n.º 1
0
// NewPixReadMem creates a new Pix instance from a byte array
func NewPixReadMem(image *[]byte) (*Pix, error) {
	//ptr := (*C.l_uint8)(*C.uchar)(unsafe.Pointer(&(*image)[0]))
	ptr := C.uglycast(unsafe.Pointer(&(*image)[0]))
	CPIX := C.pixReadMem(ptr, C.size_t(len(*image)))
	if CPIX == nil {
		return nil, errors.New("Cannot create PIX from given image data")
	}
	pix := &Pix{
		cPix: CPIX,
	}
	return pix, nil
}
Ejemplo n.º 2
0
// EncodedBytes will return a byte array holding the data from PIX in the given format
func (p *Pix) EncodedBytes(format ImageType) ([]byte, error) {
	var memory []byte
	memPtr := C.uglycast(unsafe.Pointer(&(memory)))
	var i int64
	sizePtr := C.size_t(i)
	cFormat := C.l_int32(format)
	code := C.pixWriteMem(&memPtr, &sizePtr, p.cPix, cFormat)
	if code != 0 {
		return nil, errors.New("Cannot write type to given memory.  WriteMem returned: " + strconv.Itoa(int(code)))
	}
	data := C.GoBytes(unsafe.Pointer(memPtr), C.int(sizePtr))
	C.free(unsafe.Pointer(memPtr))
	return data, nil
}