예제 #1
0
// GetDimensions returns the dimensions in Width, Height, Depth, Error format
func (p *Pix) GetDimensions() (int32, int32, int32, error) {
	p.lock.Lock()
	defer p.lock.Unlock()
	var w, h, d int32
	cW := C.l_int32(w)
	cH := C.l_int32(h)
	cD := C.l_int32(d)
	if !p.closed {
		code := C.pixGetDimensions(p.cPix, &cW, &cH, &cD)
		if code != 0 {
			return 0, 0, 0, errors.New("could not get dimensions")
		}

	}
	return int32(cW), int32(cH), int32(cD), nil
}
예제 #2
0
// WriteFile saves to disk the current pix in the given format
func (p *Pix) WriteFile(filename string, format ImageType) error {
	cFilename := C.CString(filename)
	defer C.free(unsafe.Pointer(cFilename))
	cFormat := C.l_int32(format)

	// create new PIX
	code := C.pixWrite(cFilename, p.cPix, cFormat)
	if code != 0 {
		return errors.New("could not write PIX to given filename: " + filename + " (format: " + strconv.Itoa(int(format)) + ")")
	}

	return nil
}
예제 #3
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
}