示例#1
0
文件: capi.go 项目: bradberger/webp
func webpGetXMP(data []byte) (metadata []byte, err error) {
	if len(data) == 0 {
		err = errors.New("webpGetXMP: bad arguments")
		return
	}
	isCBuf := false
	cData := cgoSafePtr(data, isCBuf)
	defer cgoFreePtr(cData, isCBuf)

	rv := C.cgoWebpGetXMP((*C.uint8_t)(cData), C.size_t(len(data)))
	if rv.ok != 1 {
		err = errors.New("webpGetXMP: failed")
		return
	}
	metadata = C.GoBytes(unsafe.Pointer(rv.ptr), C.int(rv.size))
	C.webpFree(unsafe.Pointer(rv.ptr))
	return
}
示例#2
0
文件: capi.go 项目: bradberger/webp
func webpGetMetadata(data []byte, format string) (metadata []byte, err error) {
	if len(data) == 0 {
		err = errors.New("webpGetMetadata: bad arguments")
		return
	}
	isCBuf := false
	cData := cgoSafePtr(data, isCBuf)
	defer cgoFreePtr(cData, isCBuf)

	switch format {
	case "EXIF":
		rv := C.cgoWebpGetEXIF((*C.uint8_t)(cData), C.size_t(len(data)))
		if rv.ok != 1 {
			err = errors.New("webpGetMetadata: not found")
			return
		}
		metadata = C.GoBytes(unsafe.Pointer(rv.ptr), C.int(rv.size))
		C.webpFree(unsafe.Pointer(rv.ptr))
		return
	case "ICCP":
		rv := C.cgoWebpGetICCP((*C.uint8_t)(cData), C.size_t(len(data)))
		if rv.ok != 1 {
			err = errors.New("webpGetMetadata: not found")
			return
		}
		metadata = C.GoBytes(unsafe.Pointer(rv.ptr), C.int(rv.size))
		C.webpFree(unsafe.Pointer(rv.ptr))
		return
	case "XMP":
		rv := C.cgoWebpGetXMP((*C.uint8_t)(cData), C.size_t(len(data)))
		if rv.ok != 1 {
			err = errors.New("webpGetMetadata: not found")
			return
		}
		metadata = C.GoBytes(unsafe.Pointer(rv.ptr), C.int(rv.size))
		C.webpFree(unsafe.Pointer(rv.ptr))
		return
	default:
		err = errors.New("webpGetMetadata: unknown format")
		return
	}
}