// Adaptively changes the size of the canvas, returns true on success. func (cv Canvas) AdaptiveResize(width uint, height uint) bool { status := C.MagickAdaptiveResizeImage(cv.wand, C.ulong(width), C.ulong(height)) if status == C.MagickFalse { return false } return true }
// ResizeBlur returns a new image resized to the given dimensions using the provided // filter and blur factor (where > 1 is blurry, < 1 is sharp). If width or height is // < 0, it's calculated proportionally to the other dimension. If both of them are < 0, // an error is returned. func (im *Image) ResizeBlur(width, height int, filter Filter, blur float64) (*Image, error) { var data C.ResizeData if width < 0 { if height < 0 { return nil, fmt.Errorf("invalid resize %dx%d", width, height) } h := float64(im.Height()) var ratio float64 if h != 0 { ratio = float64(im.Width()) / h } width = int(float64(height) * ratio) } if height < 0 { if width < 0 { return nil, fmt.Errorf("invalid resize %dx%d", width, height) } var ratio float64 w := float64(im.Width()) if w != 0 { ratio = float64(im.Height()) / w } height = int(float64(width) * ratio) } data.columns = C.ulong(width) data.rows = C.ulong(height) data.filter = C.FilterTypes(filter) data.blur = C.double(blur) return im.applyDataFunc("resizing", C.ImageDataFunc(C.resizeImage), &data) }
// Extract runs the extractor and returns a slice of Entities found in the // given tokens. func (ext *Extractor) Extract(tokens []string) ([]Entity, error) { ctokens := C.ner_arr_make(C.int(len(tokens)) + 1) // NULL termination defer C.ner_arr_free(ctokens, C.int(len(tokens))+1) for i, t := range tokens { cs := C.CString(t) // released by ner_arr_free C.ner_arr_set(ctokens, cs, C.int(i)) } dets := C.mitie_extract_entities(ext.ner, ctokens) defer C.mitie_free(unsafe.Pointer(dets)) if dets == nil { return nil, ErrMemory } n := int(C.mitie_ner_get_num_detections(dets)) entities := make([]Entity, n, n) for i := 0; i < n; i++ { pos := int(C.mitie_ner_get_detection_position(dets, C.ulong(i))) len := int(C.mitie_ner_get_detection_length(dets, C.ulong(i))) entities[i] = Entity{ Tag: int(C.mitie_ner_get_detection_tag(dets, C.ulong(i))), Score: float64(C.mitie_ner_get_detection_score(dets, C.ulong(i))), Name: strings.Join(tokens[pos:pos+len], " "), Range: Range{pos, pos + len}, } } return entities, nil }
// Extracts a region from the canvas. func (cv Canvas) Crop(x int, y int, width uint, height uint) bool { status := C.MagickCropImage(cv.wand, C.ulong(width), C.ulong(height), C.long(x), C.long(y)) if status == C.MagickFalse { return false } return true }
// Creates an empty canvas of the given dimensions. func (cv Canvas) Blank(width uint, height uint) bool { status := C.MagickNewImage(cv.wand, C.ulong(width), C.ulong(height), cv.bg) if status == C.MagickFalse { return false } return true }
// Changes the size of the canvas using specified filter and blur, returns true on success. func (self *Canvas) ResizeWithFilter(width uint, height uint, filter uint, blur float32) error { if width == 0 && height == 0 { return fmt.Errorf("Please specify at least one of dimensions") } if width == 0 || height == 0 { origHeight := uint(C.MagickGetImageHeight(self.wand)) origWidth := uint(C.MagickGetImageWidth(self.wand)) if width == 0 { ratio := float32(origHeight) / float32(height) width = uint(float32(origWidth) / ratio) } if height == 0 { ratio := float32(origWidth) / float32(width) height = uint(float32(origHeight) / ratio) } } success := C.MagickResizeImage(self.wand, C.ulong(width), C.ulong(height), C.FilterTypes(filter), C.double(blur)) if success == C.MagickFalse { return fmt.Errorf("Could not resize: %s", self.Error()) } return nil }
// Changes the size of the canvas, returns true on success. func (cv Canvas) Resize(width uint, height uint) bool { status := C.MagickResizeImage(cv.wand, C.ulong(width), C.ulong(height), C.GaussianFilter, C.double(1.0)) if status == C.MagickFalse { return false } return true }
// ResizeBlur returns a new image resized to the given dimensions using the provided // filter and blur factor (where > 1 is blurry, < 1 is sharp). func (im *Image) ResizeBlur(width, height int, filter Filter, blur float64) (*Image, error) { var data C.ResizeData data.columns = C.ulong(width) data.rows = C.ulong(height) data.filter = C.FilterTypes(filter) data.blur = C.double(blur) return im.applyDataFunc("resizing", C.ImageDataFunc(C.resizeImage), &data) }
func Call(p, a1, a2, a3 uintptr) uintptr { ret := C.dlcall( C.ulong(p), C.ulong(a1), C.ulong(a2), C.ulong(a3)) return uintptr(ret) }
// Adaptively changes the size of the canvas, returns true on success. func (self Canvas) AdaptiveResize(width uint, height uint) error { success := C.MagickAdaptiveResizeImage(self.wand, C.ulong(width), C.ulong(height)) if success == C.MagickFalse { return fmt.Errorf("Could not resize: %s", self.Error()) } return nil }
// Creates an empty canvas of the given dimensions. func (self Canvas) Blank(width uint, height uint) error { success := C.MagickNewImage(self.wand, C.ulong(width), C.ulong(height), self.bg) if success == C.MagickFalse { return fmt.Errorf("Could not create image: %s", self.Error()) } return nil }
// Extracts a region from the canvas. func (self Canvas) Crop(x int, y int, width uint, height uint) error { success := C.MagickCropImage(self.wand, C.ulong(width), C.ulong(height), C.long(x), C.long(y)) if success == C.MagickFalse { return fmt.Errorf("Could not crop: %s", self.Error()) } return nil }
func fastHMAC(msg, key []byte) []byte { toret := make([]byte, 512/8) thing := C.ulong(512 / 8) C.hmac_memory(sha512idx, unsafe_bytes(key), C.ulong(len(key)), unsafe_bytes(msg), C.ulong(len(msg)), unsafe_bytes(toret), (&thing)) return toret }
// Changes the size of the canvas, returns true on success. func (self Canvas) Resize(width uint, height uint) error { success := C.MagickResizeImage(self.wand, C.ulong(width), C.ulong(height), C.GaussianFilter, C.double(1.0)) if success == C.MagickFalse { return fmt.Errorf("Could not resize: %s", self.Error()) } return nil }
// SetBit sets z to x, with x's i'th bit set to b (0 or 1). // That is, if b is 1 SetBit sets z = x | (1 << i); // if b is 0 SetBit sets z = x &^ (1 << i). If b is not 0 or 1, // SetBit will panic. func (z *Int) SetBit(x *Int, i int, b uint) *Int { if z != x { z.Set(x) } if b == 0 { C._mpz_clrbit(&z.i[0], C.ulong(i)) } else { C._mpz_setbit(&z.i[0], C.ulong(i)) } return z }
func Resize(img *C.Image, x, y int) (*C.Image, error) { newImg := C.ResizeImage(img, C.ulong(x), C.ulong(y), C.LanczosFilter, 1.0, &exceptionInfo) if newImg == nil { C.CatchException(&exceptionInfo) return nil, fmt.Errorf(C.GoString(exceptionInfo.reason)) } C.DestroyImage(img) return newImg, nil }
func (im *Image) setPixels(r *Rect, src *C.PixelPacket, ex *C.ExceptionInfo) bool { dst := C.SetImagePixelsEx(im.image, C.long(r.X), C.long(r.Y), C.ulong(r.Width), C.ulong(r.Height), ex) if dst == nil { return false } C.copy_pixel_packets(src, dst, C.int(r.Width*r.Height)) if C.SyncImagePixelsEx(im.image, ex) != C.MagickPass { return false } return true }
func (client *Client) PortRegister(portName, portType string, flags, bufferSize uint64) *Port { cname := C.CString(portName) defer C.free(unsafe.Pointer(cname)) ctype := C.CString(portType) defer C.free(unsafe.Pointer(ctype)) cport := C.jack_port_register(client.handler, cname, ctype, C.ulong(flags), C.ulong(bufferSize)) if cport != nil { return &Port{cport} } return nil }
func (s *StatVfs) toCStat(o *C.struct_statvfs) { o.f_bsize = C.ulong(s.BlockSize) o.f_blocks = C.fsblkcnt_t(s.Blocks) o.f_bfree = C.fsblkcnt_t(s.BlocksFree) o.f_files = C.fsfilcnt_t(s.Files) o.f_ffree = C.fsfilcnt_t(s.FilesFree) o.f_fsid = C.ulong(s.Fsid) o.f_flag = C.ulong(s.Flags) o.f_namemax = C.ulong(s.NameMax) }
/* Scale() scales the size of this image to the given dimensions. columns: The number of columns in the scaled image. rows: The number of rows in the scaled image */ func (this *Image) Scale(columns int64, rows int64) error { if this.magickWand == nil { return errors.New("error scale image:magickwand is nil") } status := C.MagickScaleImage(this.magickWand, C.ulong(columns), C.ulong(rows)) if status == 0 { var etype int descr := C.MagickGetException(this.magickWand, (*C.ExceptionType)(unsafe.Pointer(&etype))) defer C.MagickRelinquishMemory(unsafe.Pointer(descr)) return errors.New(fmt.Sprintf("error scale image: %s (ExceptionType = %d)", C.GoString(descr), etype)) } return nil }
func (this *Image) Resize(width int64, height int64) error { if this.magickWand == nil { return errors.New("error resizing image:magickwand is nil") } status := C.MagickResizeImage(this.magickWand, C.ulong(width), C.ulong(height), C.CubicFilter, 0.5) if status == 0 { var etype int descr := C.MagickGetException(this.magickWand, (*C.ExceptionType)(unsafe.Pointer(&etype))) defer C.MagickRelinquishMemory(unsafe.Pointer(descr)) return errors.New(fmt.Sprintf("error resizing image: %s (ExceptionType = %d)", C.GoString(descr), etype)) } return nil }
func (state fastGCMState) Seal(dst, nonce, plaintext, data []byte) []byte { rawenc := make([]byte, len(plaintext)) sched := (*_Ctype_gcm_state)(unsafe.Pointer(&state[0])) FASSERT(C.gcm_reset(sched) == C.CRYPT_OK) FASSERT(C.gcm_add_iv(sched, unsafe_bytes(nonce), 12) == C.CRYPT_OK) C.gcm_add_aad(sched, nil, 0) FASSERT(C.gcm_process(sched, unsafe_bytes(plaintext), C.ulong(len(plaintext)), unsafe_bytes(rawenc), C.GCM_ENCRYPT) == C.CRYPT_OK) tag := buf.Alloc() thing := C.ulong(16) FASSERT(C.gcm_done(sched, unsafe_bytes(tag), &thing) == C.CRYPT_OK) rawenc = append(rawenc, tag[:int(thing)]...) buf.Free(tag) return append(dst, rawenc...) }
// SendCommand sends a raw command to the MySQL server. func (conn *Connection) SendCommand(command uint32, data []byte) error { ret := C.vt_simple_command(&conn.c, command, (*C.uchar)(unsafe.Pointer(&data[0])), C.ulong(len(data)), 1) if ret != 0 { return fmt.Errorf("error sending raw MySQL command: %v", conn.lastError("")) } return nil }
// ExecuteFetch executes the query on the connection func (conn *Connection) ExecuteFetch(query string, maxrows int, wantfields bool) (qr *sqltypes.Result, err error) { if conn.IsClosed() { return nil, sqldb.NewSQLError(2006, "Connection is closed") } if C.vt_execute(&conn.c, (*C.char)(hack.StringPointer(query)), C.ulong(len(query)), 0) != 0 { return nil, conn.lastError(query) } defer conn.CloseResult() qr = &sqltypes.Result{} qr.RowsAffected = uint64(conn.c.affected_rows) qr.InsertID = uint64(conn.c.insert_id) if conn.c.num_fields == 0 { return qr, nil } if qr.RowsAffected > uint64(maxrows) { return nil, &sqldb.SQLError{ Num: 0, Message: fmt.Sprintf("Row count exceeded %d", maxrows), Query: string(query), } } if wantfields { qr.Fields = conn.Fields() } qr.Rows, err = conn.fetchAll() return qr, err }
// Connect uses the connection parameters to connect and returns the connection func Connect(params sqldb.ConnParams) (sqldb.Conn, error) { var err error defer handleError(&err) host := C.CString(params.Host) defer cfree(host) port := C.uint(params.Port) uname := C.CString(params.Uname) defer cfree(uname) pass := C.CString(params.Pass) defer cfree(pass) dbname := C.CString(params.DbName) defer cfree(dbname) unixSocket := C.CString(params.UnixSocket) defer cfree(unixSocket) charset := C.CString(params.Charset) defer cfree(charset) flags := C.ulong(params.Flags) conn := &Connection{} if C.vt_connect(&conn.c, host, uname, pass, dbname, port, unixSocket, charset, flags) != 0 { defer conn.Close() return nil, conn.lastError("") } return conn, nil }
func (conn Connection) Prepare(query string) (dbs db.Statement, e os.Error) { s := Statement{}; s.conn = &conn; conn.Lock(); s.stmt = C.mysql_stmt_init(conn.handle); conn.Unlock(); if s.stmt == nil { e = MysqlError("Prepare: Couldn't init statement (out of memory?)"); return; } conn.Lock(); cquery := strings.Bytes(query); if r := C.mysql_stmt_prepare( s.stmt, (*C.char)(unsafe.Pointer(&cquery[0])), C.ulong(len(query))); r != 0 { e = conn.lastError() } else { dbs = s } conn.Unlock(); return; }
func (d *Domain) SetMemory(memory uint64) error { result := C.virDomainSetMemory(d.cptr, C.ulong(memory)) if result == -1 { return GetLastError() } return nil }
func (self *Connection) ExecuteFetch(query []byte, maxrows int) (qr *QueryResult, err error) { defer handleError(&err) self.validate() if C.mysql_real_query(self.handle, (*C.char)(unsafe.Pointer(&query[0])), C.ulong(len(query))) != 0 { return nil, self.lastError(query) } result := C.mysql_store_result(self.handle) if result == nil { if int(C.mysql_field_count(self.handle)) != 0 { // Query was supposed to return data, but it didn't return nil, self.lastError(query) } qr = &QueryResult{} qr.RowsAffected = uint64(C.mysql_affected_rows(self.handle)) qr.InsertId = uint64(C.mysql_insert_id(self.handle)) return qr, nil } defer C.mysql_free_result(result) qr = &QueryResult{} qr.RowsAffected = uint64(C.mysql_affected_rows(self.handle)) if qr.RowsAffected > uint64(maxrows) { return nil, &SqlError{0, fmt.Sprintf("Row count exceeded %d", maxrows), string(query)} } qr.Fields = self.buildFields(result) qr.Rows = self.fetchAll(result) return qr, nil }
func (this *MITIE) Process(body string) *list.List { tokens := C.mitie_tokenize(C.CString(body)) defer C.mitie_free(unsafe.Pointer(tokens)) dets := C.mitie_extract_entities(this.ner, tokens) defer C.mitie_free(unsafe.Pointer(dets)) num_dets := C.mitie_ner_get_num_detections(dets) duplicates := set.New() entites := list.New() for i := 0; i < int(num_dets); i++ { centity := C.get_entity(tokens, dets, C.ulong(i)) model := C.GoString(centity.model) score := float64(centity.score) value := C.GoString(centity.value) key := fmt.Sprintf("%s:%s", value, model) if duplicates.Has(key) { continue } duplicates.Add(key) if score > 0.5 { entity := models.NewEntity(model, score, value) entites.PushBack(entity) } } return entites }
func (d *VirDomain) SetMemoryFlags(memory uint64, flags uint32) error { result := C.virDomainSetMemoryFlags(d.ptr, C.ulong(memory), C.uint(flags)) if result == -1 { return GetLastError() } return nil }