作者:georgebash
项目:pugholde
func (img *Image) Resize(width int, height int) {
wand := img.wand
cur_width := float64(C.MagickGetImageWidth(wand))
cur_height := float64(C.MagickGetImageHeight(wand))
r_width := cur_width / float64(width)
r_height := cur_height / float64(height)
ratio := r_height
if r_width < r_height {
ratio = r_width
}
dest_width := cur_width / ratio
dest_height := cur_height / ratio
crop_x := int((dest_width - float64(width)) / 2)
crop_y := int((dest_height - float64(height)) / 2)
if r_width > 5 && r_height > 5 {
C.MagickSampleImage(wand, C.size_t(dest_width*5), C.size_t(dest_height*5))
}
C.MagickResizeImage(wand, C.size_t(dest_width), C.size_t(dest_height), C.LanczosFilter, 1)
C.MagickCropImage(wand, C.size_t(width), C.size_t(height), C.ssize_t(crop_x), C.ssize_t(crop_y))
}
作者:rli-dirary
项目:pain
/* Extracts a region of the image. */
func (w *MagickWand) CropImage(width, height uint, x, y int) error {
if C.MagickCropImage(w.wand, C.size_t(width), C.size_t(height), C.ssize_t(x), C.ssize_t(y)) == C.MagickFalse {
eStr, eCode := w.Exception()
return fmt.Errorf("CropImage() failed : [%d] %s", eStr, eCode)
}
return nil
}
作者:kilny
项目:magic
func (im *Image) setPixels(r *Rect, src *C.PixelPacket, ex *C.ExceptionInfo) bool {
dst := C.GetAuthenticPixels(im.image, C.ssize_t(r.X), C.ssize_t(r.Y), C.size_t(r.Width), C.size_t(r.Height), ex)
if dst == nil {
return false
}
C.copy_pixel_packets(src, dst, C.int(r.Width*r.Height))
if C.SyncAuthenticPixels(im.image, ex) != C.MagickTrue {
return false
}
return true
}
作者:dqmin
项目:mag
// Private: center the current wand on top of the new wand, after that, we only
// keep the new wand.
//
// Params:
// - newWand: new wand, probably going to be result of blankWand
// - x: x position on the current wand that is the center of the new wand
// - y: y position on the current wand that is the center of the new wand
//
// Example:
// newWand := blankWand("jpg", width, height)
// done := m.compositeCenter(newWand, 10, 10)
//
// Return boolean result of the composition
func (m *Mage) compositeCenter(newWand *C.MagickWand, x, y int) bool {
success := C.MagickCompositeImage(
newWand,
m.wand,
C.OverCompositeOp,
C.ssize_t(x),
C.ssize_t(y))
C.DestroyMagickWand(m.wand)
m.wand = newWand
return mBoolean(success)
}
作者:ahu
项目:
func (br *BodyReader) Read(p []byte) (n int, err error) {
m := len(p)
var rlen C.ssize_t = C.ssize_t(0)
c_body := C.uwsgi_request_body_read(br.wsgi_req, C.ssize_t(m), &rlen)
if c_body == C.uwsgi.empty {
err = io.EOF
return 0, err
} else if c_body != nil {
C.memcpy(unsafe.Pointer(&p[0]), unsafe.Pointer(c_body), C.size_t(rlen))
return int(rlen), err
}
err = io.ErrUnexpectedEOF
rlen = 0
return int(rlen), err
}
作者:coolbry9
项目:magicmachin
func (e *Enchant) Replace(word, wordNew string) {
// does the dictionary need to be loaded here?
cWord := C.CString(word)
defer C.free(unsafe.Pointer(cWord))
cWordNew := C.CString(wordNew)
defer C.free(unsafe.Pointer(cWordNew))
cWordLen := uintptr(len(word))
s := C.ssize_t(cWordLen)
cWordLenNew := uintptr(len(wordNew))
sNew := C.ssize_t(cWordLenNew)
C.enchant_dict_store_replacement(e.dict, cWord, s, cWordNew, sNew)
}
作者:mishudar
项目:gosex
// Puts a canvas on top of the current one.
func (cv Canvas) AppendCanvas(source Canvas, x int, y int) bool {
status := C.MagickCompositeImage(cv.wand, source.wand, C.OverCompositeOp, C.ssize_t(x), C.ssize_t(y))
if status == C.MagickFalse {
return false
}
return true
}
作者:mishudar
项目:gosex
// 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.size_t(width), C.size_t(height), C.ssize_t(x), C.ssize_t(y))
if status == C.MagickFalse {
return false
}
return true
}
作者:rli-dirary
项目:pain
/* Composite one image onto another at the specified offset. */
func (w *MagickWand) CompositeImage(srcWand *MagickWand, compose, x, y int) error {
if C.MagickCompositeImage(w.wand, srcWand.wand, C.CompositeOperator(compose), C.ssize_t(x), C.ssize_t(y)) == C.MagickFalse {
eStr, eCode := w.Exception()
return fmt.Errorf("CompositeImage() failed : [%d] %s", eStr, eCode)
}
return nil
}
作者:phacop
项目:canva
// 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.size_t(width), C.size_t(height), C.ssize_t(x), C.ssize_t(y))
if success == C.MagickFalse {
return fmt.Errorf("Could not crop: %s", self.Error())
}
return nil
}
作者:naegelej
项目:go-ac
func (acl *ACL) CopyExt(buffer []byte) (int64, error) {
p := unsafe.Pointer(&buffer[0])
l := C.ssize_t(len(buffer))
i, err := C.acl_copy_ext(p, acl.a, l)
if i < 0 {
return int64(i), err
}
return int64(i), nil
}
作者:phacop
项目:canva
// Puts a canvas on top of the current one.
func (self *Canvas) AppendCanvas(source *Canvas, x int, y int) error {
success := C.MagickCompositeImage(self.wand, source.wand, C.OverCompositeOp, C.ssize_t(x), C.ssize_t(y))
if success == C.MagickFalse {
return fmt.Errorf("Could not append image: %s", self.Error())
}
return nil
}
作者:tarut
项目:enchan
// Check whether a given word is in the currently loaded dictionary.
// This wraps enchant_dict_check.
// It returns a boolean value: true if the word is in the dictionary,
// false otherwise.
func (d Dict) Check(word string) bool {
if len(word) == 0 {
return true
}
cWord := (*C.char)(unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&word)).Data))
size := C.ssize_t(uintptr(len(word)))
return C.enchant_dict_check(d.dict, cWord, size) == 0
}
作者:kshl
项目:gogfap
// Write writes len(b) bytes from b into the Fd
//
// Returns number of bytes written on success and error on failure
func (fd *Fd) Write(b []byte) (int, error) {
n, err := C.glfs_write(fd.fd, unsafe.Pointer(&b[0]), C.size_t(len(b)), 0)
if n == C.ssize_t(len(b)) {
// FIXME: errno is set to EINVAL even though write is successful. This
// is probably a bug. Remove this workaround when that gets fixed.
err = nil
}
return int(n), err
}
作者:str4
项目:i2p-tool
// write to a file descriptor
func fdWrite(fd C.int, d []byte) (n int, err error) {
buff := make([]C.uchar, len(d))
for i, b := range d {
buff[i] = C.uchar(b)
}
res := C.uchar_write(fd, &buff[0], C.size_t(len(d)))
if res == C.ssize_t(-1) {
err = errors.New("write returned -1")
} else {
n = int(res)
}
return
}
作者:proglotti
项目:gpgm
//export gogpgme_writefunc
func gogpgme_writefunc(handle, buffer unsafe.Pointer, size C.size_t) C.ssize_t {
d := callbackLookup(uintptr(handle)).(*Data)
if len(d.buf) < int(size) {
d.buf = make([]byte, size)
}
C.memcpy(unsafe.Pointer(&d.buf[0]), buffer, C.size_t(size))
n, err := d.w.Write(d.buf[:size])
if err != nil && err != io.EOF {
C.gpgme_err_set_errno(C.EIO)
return -1
}
return C.ssize_t(n)
}
作者:str4
项目:i2p-tool
// read from a file descriptor
func fdRead(fd C.int, d []byte) (n int, err error) {
buff := make([]C.uchar, len(d))
res := C.uchar_read(fd, &buff[0], C.size_t(len(d)))
if res == C.ssize_t(-1) {
err = errors.New("read returned -1")
} else {
n = int(res)
for i, b := range buff[:n] {
d[i] = byte(b)
}
}
return
}
作者:XenServerBestPractic
项目:nov
func readdelattr(filepath string) (bool, error) {
val := C.char(0)
err := C.getxattr(
C.CString(filepath),
C.CString("novm-deleted"),
unsafe.Pointer(&val),
C.size_t(1))
if err != C.ssize_t(1) {
var stat syscall.Stat_t
err := syscall.Stat(
path.Join(filepath, ".deleted"),
&stat)
if err != nil {
return false, err
}
return true, nil
}
return val == C.char(1), nil
}
作者:surma-dum
项目:gol
// Takes a serialized OSC packet and deserializes it into a
// message. Parameters with an unsupported type will
// be deserialized as ErrUnknown.
func Deserialize(data []byte) (*Message, error) {
cdata := unsafe.Pointer(&data[0])
cdatalen := C.size_t(len(data))
msg := C.lo_message_deserialise(cdata, cdatalen, (*C.int)(unsafe.Pointer(nil)))
if msg == nil {
// TODO: Obtain and parse actual error?
return nil, errors.New("Deserialization failed")
}
result := &Message{
Path: C.GoString(C.lo_get_path(cdata, C.ssize_t(cdatalen))),
Params: make([]interface{}, 0, 10),
}
argc := int(C.lo_message_get_argc(msg))
for i := 0; i < argc; i++ {
result.Params = append(result.Params, extractArgument(msg, i))
}
return result, nil
}
作者:kilny
项目:magic
func (im *Image) pixels(r *Rect, ex *C.ExceptionInfo) *C.PixelPacket {
return C.GetVirtualPixels(im.image, C.ssize_t(r.X), C.ssize_t(r.Y), C.size_t(r.Width), C.size_t(r.Height), ex)
}