Esempio n. 1
0
func webpGetEXIF(data []byte) (metadata []byte, err error) {
	if len(data) == 0 {
		err = errors.New("webpGetEXIF: bad arguments")
		return
	}
	isCBuf := false
	cData := cgoSafePtr(data, isCBuf)
	defer cgoFreePtr(cData, isCBuf)

	rv := C.cgoWebpGetEXIF((*C.uint8_t)(cData), C.size_t(len(data)))
	if rv.ok != 1 {
		err = errors.New("webpGetEXIF: failed")
		return
	}
	metadata = C.GoBytes(unsafe.Pointer(rv.ptr), C.int(rv.size))
	C.webpFree(unsafe.Pointer(rv.ptr))
	return
}
Esempio n. 2
0
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
	}
}