Пример #1
0
func webpSetMetadata(data, metadata []byte, format string) (newData []byte, err error) {
	if len(data) == 0 || len(metadata) == 0 {
		err = errors.New("webpSetMetadata: bad arguments")
		return
	}
	isCBuf := false
	cData := cgoSafePtr(data, isCBuf)
	defer cgoFreePtr(cData, isCBuf)
	cMetadata := cgoSafePtr(metadata, isCBuf)
	defer cgoFreePtr(cMetadata, isCBuf)

	switch format {
	case "EXIF":
		rv := C.cgoWebpSetEXIF(
			(*C.uint8_t)(cData), C.size_t(len(data)),
			(*C.char)(cMetadata), C.size_t(len(metadata)),
		)
		if rv.ok != 1 {
			err = errors.New("webpSetMetadata: failed")
			return
		}
		newData = C.GoBytes(unsafe.Pointer(rv.ptr), C.int(rv.size))
		C.webpFree(unsafe.Pointer(rv.ptr))
		return
	case "ICCP":
		rv := C.cgoWebpSetICCP(
			(*C.uint8_t)(cData), C.size_t(len(data)),
			(*C.char)(cMetadata), C.size_t(len(metadata)),
		)
		if rv.ok != 1 {
			err = errors.New("webpSetMetadata: failed")
			return
		}
		newData = C.GoBytes(unsafe.Pointer(rv.ptr), C.int(rv.size))
		C.webpFree(unsafe.Pointer(rv.ptr))
		return
	case "XMP":
		rv := C.cgoWebpSetXMP(
			(*C.uint8_t)(cData), C.size_t(len(data)),
			(*C.char)(cMetadata), C.size_t(len(metadata)),
		)
		if rv.ok != 1 {
			err = errors.New("webpSetMetadata: failed")
			return
		}
		newData = C.GoBytes(unsafe.Pointer(rv.ptr), C.int(rv.size))
		C.webpFree(unsafe.Pointer(rv.ptr))
		return
	default:
		err = errors.New("webpSetMetadata: unknown format")
		return
	}
}
Пример #2
0
func webpSetXMP(data, metadata []byte) (newData []byte, err error) {
	if len(data) == 0 || len(metadata) == 0 {
		err = errors.New("webpSetXMP: bad arguments")
		return
	}
	isCBuf := false
	cData := cgoSafePtr(data, isCBuf)
	defer cgoFreePtr(cData, isCBuf)
	cMetadata := cgoSafePtr(metadata, isCBuf)
	defer cgoFreePtr(cMetadata, isCBuf)

	rv := C.cgoWebpSetXMP(
		(*C.uint8_t)(cData), C.size_t(len(data)),
		(*C.char)(cMetadata), C.size_t(len(metadata)),
	)
	if rv.ok != 1 {
		err = errors.New("webpSetXMP: failed")
		return
	}
	newData = C.GoBytes(unsafe.Pointer(rv.ptr), C.int(rv.size))
	C.webpFree(unsafe.Pointer(rv.ptr))
	return
}