mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-19 20:08:28 +01:00
swig: add basic go bindings
WebPGetDecoderVersion WebPGetInfo Change-Id: Icb66207c2f492c9d20642544c0b31cc92b91cdcc
This commit is contained in:
parent
1939607e7f
commit
e4e7fcd69b
45
swig/libwebp.go
Normal file
45
swig/libwebp.go
Normal file
@ -0,0 +1,45 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* This file was automatically generated by SWIG (http://www.swig.org).
|
||||
* Version 2.0.10
|
||||
*
|
||||
* This file is not intended to be easily readable and contains a number of
|
||||
* coding conventions designed to improve portability and efficiency. Do not make
|
||||
* changes to this file unless you know what you are doing--modify the SWIG
|
||||
* interface file instead.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
package libwebp
|
||||
|
||||
import _ "runtime/cgo"
|
||||
import "unsafe"
|
||||
|
||||
type _ unsafe.Pointer
|
||||
|
||||
type _swig_fnptr *byte
|
||||
type _swig_memberptr *byte
|
||||
|
||||
//extern libwebpSwigCgocall
|
||||
func SwigCgocall()
|
||||
|
||||
//extern libwebpSwigCgocallDone
|
||||
func SwigCgocallDone()
|
||||
|
||||
//extern libwebpSwigCgocallBack
|
||||
func SwigCgocallBack()
|
||||
|
||||
//extern libwebpSwigCgocallBackDone
|
||||
func SwigCgocallBackDone()
|
||||
|
||||
func WebPGetDecoderVersion() int
|
||||
func Wrapped_WebPGetInfo(string, []int, []int) int
|
||||
|
||||
// WebPGetInfo has 2 output parameters, provide a version in the more natural
|
||||
// go idiom:
|
||||
func WebPGetInfo(webp []byte) (ok bool, width int, height int) {
|
||||
w := []int{0}
|
||||
h := []int{0}
|
||||
ok = Wrapped_WebPGetInfo(string(webp), w, h) != 0
|
||||
width = w[0]
|
||||
height = h[0]
|
||||
return
|
||||
}
|
@ -12,6 +12,11 @@
|
||||
// Author: James Zern (jzern@google.com)
|
||||
|
||||
/*
|
||||
Go bindings:
|
||||
$ swig -go \
|
||||
-outdir . \
|
||||
-o libwebp_go_wrap.c libwebp.swig
|
||||
|
||||
Java bindings:
|
||||
$ mkdir -p java/com/google/webp
|
||||
$ swig -java \
|
||||
@ -34,6 +39,13 @@
|
||||
%include "constraints.i"
|
||||
%include "typemaps.i"
|
||||
|
||||
#ifdef SWIGGO
|
||||
%apply (char* STRING, size_t LENGTH) { (const uint8_t* data, size_t data_size) }
|
||||
|
||||
%rename(wrapped_WebPGetInfo) WebPGetInfo(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height);
|
||||
#endif /* SWIGGO */
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
%include "arrays_java.i";
|
||||
%include "enums.swg" /*NB: requires JDK-1.5+
|
||||
@ -96,6 +108,12 @@ DECODE_AUTODOC(WebPDecodeBGRA);
|
||||
|
||||
%apply int* OUTPUT { int* width, int* height }
|
||||
|
||||
int WebPGetDecoderVersion(void);
|
||||
int WebPGetInfo(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height);
|
||||
|
||||
#if defined(SWIGJAVA) || defined(SWIGPYTHON)
|
||||
|
||||
// free the buffer returned by these functions after copying into
|
||||
// the native type
|
||||
%newobject WebPDecodeRGB;
|
||||
@ -105,10 +123,6 @@ DECODE_AUTODOC(WebPDecodeBGRA);
|
||||
%newobject WebPDecodeBGRA;
|
||||
%typemap(newfree) uint8_t* "free($1);"
|
||||
|
||||
int WebPGetDecoderVersion(void);
|
||||
int WebPGetInfo(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height);
|
||||
|
||||
uint8_t* WebPDecodeRGB(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height);
|
||||
uint8_t* WebPDecodeRGBA(const uint8_t* data, size_t data_size,
|
||||
@ -120,11 +134,17 @@ uint8_t* WebPDecodeBGR(const uint8_t* data, size_t data_size,
|
||||
uint8_t* WebPDecodeBGRA(const uint8_t* data, size_t data_size,
|
||||
int* width, int* height);
|
||||
|
||||
#endif /* SWIGJAVA || SWIGPYTHON */
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Encoder specific
|
||||
|
||||
#if defined(SWIGJAVA) || defined(SWIGPYTHON)
|
||||
|
||||
int WebPGetEncoderVersion(void);
|
||||
|
||||
#endif /* SWIGJAVA || SWIGPYTHON */
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Wrapper code additions
|
||||
|
||||
@ -193,7 +213,6 @@ static size_t ReturnedBufferSize(
|
||||
return size;
|
||||
}
|
||||
%}
|
||||
#endif /* SWIGJAVA || SWIGPYTHON */
|
||||
|
||||
%{
|
||||
typedef size_t (*WebPEncodeFunction)(const uint8_t* rgb,
|
||||
@ -232,9 +251,13 @@ static uint8_t* EncodeLossless(const uint8_t* rgb,
|
||||
}
|
||||
%}
|
||||
|
||||
#endif /* SWIGJAVA || SWIGPYTHON */
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// libwebp/encode wrapper functions
|
||||
|
||||
#if defined(SWIGJAVA) || defined(SWIGPYTHON)
|
||||
|
||||
%apply int* INPUT { int* unused1, int* unused2 }
|
||||
%apply int* OUTPUT { int* output_size }
|
||||
|
||||
@ -304,9 +327,28 @@ LOSSLESS_WRAPPER(WebPEncodeLosslessBGRA)
|
||||
|
||||
%}
|
||||
|
||||
#endif /* SWIGJAVA || SWIGPYTHON */
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Language specific
|
||||
|
||||
#ifdef SWIGGO
|
||||
%insert(go_wrapper) %{
|
||||
|
||||
// WebPGetInfo has 2 output parameters, provide a version in the more natural
|
||||
// go idiom:
|
||||
func WebPGetInfo(webp []byte) (ok bool, width int, height int) {
|
||||
w := []int{0}
|
||||
h := []int{0}
|
||||
ok = Wrapped_WebPGetInfo(string(webp), w, h) != 0
|
||||
width = w[0]
|
||||
height = h[0]
|
||||
return
|
||||
}
|
||||
|
||||
%}
|
||||
#endif /* SWIGGO */
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
%{
|
||||
/* Work around broken gcj jni.h */
|
||||
|
52
swig/libwebp_gc.c
Normal file
52
swig/libwebp_gc.c
Normal file
@ -0,0 +1,52 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* This file was automatically generated by SWIG (http://www.swig.org).
|
||||
* Version 2.0.10
|
||||
*
|
||||
* This file is not intended to be easily readable and contains a number of
|
||||
* coding conventions designed to improve portability and efficiency. Do not make
|
||||
* changes to this file unless you know what you are doing--modify the SWIG
|
||||
* interface file instead.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* This file should be compiled with 6c/8c. */
|
||||
#pragma dynimport _ _ "libwebp_go.so"
|
||||
|
||||
#include "runtime.h"
|
||||
#include "cgocall.h"
|
||||
|
||||
#ifdef _64BIT
|
||||
#define SWIG_PARM_SIZE 8
|
||||
#else
|
||||
#define SWIG_PARM_SIZE 4
|
||||
#endif
|
||||
|
||||
#pragma dynimport _wrap_WebPGetDecoderVersion _wrap_WebPGetDecoderVersion ""
|
||||
extern void (*_wrap_WebPGetDecoderVersion)(void*);
|
||||
static void (*x_wrap_WebPGetDecoderVersion)(void*) = _wrap_WebPGetDecoderVersion;
|
||||
|
||||
void
|
||||
·WebPGetDecoderVersion(struct {
|
||||
uint8 x[SWIG_PARM_SIZE];
|
||||
} p)
|
||||
|
||||
{
|
||||
runtime·cgocall(x_wrap_WebPGetDecoderVersion, &p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#pragma dynimport _wrap_wrapped_WebPGetInfo _wrap_wrapped_WebPGetInfo ""
|
||||
extern void (*_wrap_wrapped_WebPGetInfo)(void*);
|
||||
static void (*x_wrap_wrapped_WebPGetInfo)(void*) = _wrap_wrapped_WebPGetInfo;
|
||||
|
||||
void
|
||||
·Wrapped_WebPGetInfo(struct {
|
||||
uint8 x[(2 * SWIG_PARM_SIZE) + (3 * SWIG_PARM_SIZE) + (3 * SWIG_PARM_SIZE) + SWIG_PARM_SIZE];
|
||||
} p)
|
||||
|
||||
{
|
||||
runtime·cgocall(x_wrap_wrapped_WebPGetInfo, &p);
|
||||
}
|
||||
|
||||
|
||||
|
274
swig/libwebp_go_wrap.c
Normal file
274
swig/libwebp_go_wrap.c
Normal file
@ -0,0 +1,274 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* This file was automatically generated by SWIG (http://www.swig.org).
|
||||
* Version 2.0.10
|
||||
*
|
||||
* This file is not intended to be easily readable and contains a number of
|
||||
* coding conventions designed to improve portability and efficiency. Do not make
|
||||
* changes to this file unless you know what you are doing--modify the SWIG
|
||||
* interface file instead.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
#define SWIGMODULE libwebp
|
||||
/* -----------------------------------------------------------------------------
|
||||
* This section contains generic SWIG labels for method/variable
|
||||
* declarations/attributes, and other compiler dependent labels.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* template workaround for compilers that cannot correctly implement the C++ standard */
|
||||
#ifndef SWIGTEMPLATEDISAMBIGUATOR
|
||||
# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
|
||||
# define SWIGTEMPLATEDISAMBIGUATOR template
|
||||
# elif defined(__HP_aCC)
|
||||
/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
|
||||
/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
|
||||
# define SWIGTEMPLATEDISAMBIGUATOR template
|
||||
# else
|
||||
# define SWIGTEMPLATEDISAMBIGUATOR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* inline attribute */
|
||||
#ifndef SWIGINLINE
|
||||
# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
|
||||
# define SWIGINLINE inline
|
||||
# else
|
||||
# define SWIGINLINE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* attribute recognised by some compilers to avoid 'unused' warnings */
|
||||
#ifndef SWIGUNUSED
|
||||
# if defined(__GNUC__)
|
||||
# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
|
||||
# define SWIGUNUSED __attribute__ ((__unused__))
|
||||
# else
|
||||
# define SWIGUNUSED
|
||||
# endif
|
||||
# elif defined(__ICC)
|
||||
# define SWIGUNUSED __attribute__ ((__unused__))
|
||||
# else
|
||||
# define SWIGUNUSED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SWIG_MSC_UNSUPPRESS_4505
|
||||
# if defined(_MSC_VER)
|
||||
# pragma warning(disable : 4505) /* unreferenced local function has been removed */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SWIGUNUSEDPARM
|
||||
# ifdef __cplusplus
|
||||
# define SWIGUNUSEDPARM(p)
|
||||
# else
|
||||
# define SWIGUNUSEDPARM(p) p SWIGUNUSED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* internal SWIG method */
|
||||
#ifndef SWIGINTERN
|
||||
# define SWIGINTERN static SWIGUNUSED
|
||||
#endif
|
||||
|
||||
/* internal inline SWIG method */
|
||||
#ifndef SWIGINTERNINLINE
|
||||
# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
|
||||
#endif
|
||||
|
||||
/* exporting methods */
|
||||
#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
|
||||
# ifndef GCC_HASCLASSVISIBILITY
|
||||
# define GCC_HASCLASSVISIBILITY
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SWIGEXPORT
|
||||
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||
# if defined(STATIC_LINKED)
|
||||
# define SWIGEXPORT
|
||||
# else
|
||||
# define SWIGEXPORT __declspec(dllexport)
|
||||
# endif
|
||||
# else
|
||||
# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
|
||||
# define SWIGEXPORT __attribute__ ((visibility("default")))
|
||||
# else
|
||||
# define SWIGEXPORT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* calling conventions for Windows */
|
||||
#ifndef SWIGSTDCALL
|
||||
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||
# define SWIGSTDCALL __stdcall
|
||||
# else
|
||||
# define SWIGSTDCALL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
|
||||
#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
|
||||
# define _CRT_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
|
||||
/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
|
||||
#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
|
||||
# define _SCL_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
|
||||
typedef long long intgo;
|
||||
typedef unsigned long long uintgo;
|
||||
|
||||
|
||||
|
||||
typedef struct { char *p; intgo n; } _gostring_;
|
||||
typedef struct { void* array; intgo len; intgo cap; } _goslice_;
|
||||
|
||||
|
||||
|
||||
|
||||
#define swiggo_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1];
|
||||
#define swiggo_size_assert(t, n) swiggo_size_assert_eq(sizeof(t), n, swiggo_sizeof_##t##_is_not_##n)
|
||||
|
||||
swiggo_size_assert(char, 1)
|
||||
swiggo_size_assert(short, 2)
|
||||
swiggo_size_assert(int, 4)
|
||||
typedef long long swiggo_long_long;
|
||||
swiggo_size_assert(swiggo_long_long, 8)
|
||||
swiggo_size_assert(float, 4)
|
||||
swiggo_size_assert(double, 8)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern void crosscall2(void (*fn)(void *, int), void *, int);
|
||||
extern void _cgo_allocate(void *, int);
|
||||
extern void _cgo_panic(void *, int);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
static void *_swig_goallocate(size_t len) {
|
||||
struct {
|
||||
size_t len;
|
||||
void *ret;
|
||||
} a;
|
||||
a.len = len;
|
||||
crosscall2(_cgo_allocate, &a, (int) sizeof a);
|
||||
return a.ret;
|
||||
}
|
||||
|
||||
static void _swig_gopanic(const char *p) {
|
||||
struct {
|
||||
const char *p;
|
||||
} a;
|
||||
a.p = p;
|
||||
crosscall2(_cgo_panic, &a, (int) sizeof a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static _gostring_ _swig_makegostring(const char *p, size_t l) {
|
||||
_gostring_ ret;
|
||||
ret.p = (char*)_swig_goallocate(l + 1);
|
||||
memcpy(ret.p, p, l);
|
||||
ret.n = l;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define SWIG_contract_assert(expr, msg) \
|
||||
if (!(expr)) { _swig_gopanic(msg); } else
|
||||
|
||||
|
||||
#define SWIG_exception(code, msg) _swig_gopanic(msg)
|
||||
|
||||
|
||||
#include "webp/decode.h"
|
||||
#include "webp/encode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void
|
||||
_wrap_WebPGetDecoderVersion(void *swig_v)
|
||||
{
|
||||
int result;
|
||||
|
||||
struct swigargs {
|
||||
long : 0;
|
||||
intgo result;
|
||||
} *swig_a = (struct swigargs *) swig_v;
|
||||
|
||||
|
||||
result = (int)WebPGetDecoderVersion();
|
||||
swig_a->result = result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_wrap_wrapped_WebPGetInfo(void *swig_v)
|
||||
{
|
||||
uint8_t *arg1 = (uint8_t *) 0 ;
|
||||
size_t arg2 ;
|
||||
int *arg3 = (int *) 0 ;
|
||||
int *arg4 = (int *) 0 ;
|
||||
int temp3 ;
|
||||
int temp4 ;
|
||||
int result;
|
||||
|
||||
struct swigargs {
|
||||
_gostring_ arg1;
|
||||
_goslice_ arg3;
|
||||
_goslice_ arg4;
|
||||
long : 0;
|
||||
intgo result;
|
||||
} *swig_a = (struct swigargs *) swig_v;
|
||||
|
||||
|
||||
arg1 = (uint8_t *)swig_a->arg1.p;
|
||||
arg2 = (size_t)swig_a->arg1.n;
|
||||
|
||||
{
|
||||
if (swig_a->arg3.len == 0) {
|
||||
_swig_gopanic("array must contain at least 1 element");
|
||||
}
|
||||
arg3 = &temp3;
|
||||
}
|
||||
{
|
||||
if (swig_a->arg4.len == 0) {
|
||||
_swig_gopanic("array must contain at least 1 element");
|
||||
}
|
||||
arg4 = &temp4;
|
||||
}
|
||||
|
||||
result = (int)WebPGetInfo((uint8_t const *)arg1,arg2,arg3,arg4);
|
||||
swig_a->result = result;
|
||||
{
|
||||
int* a = (int *) swig_a->arg3.array;
|
||||
a[0] = temp3;
|
||||
}
|
||||
{
|
||||
int* a = (int *) swig_a->arg4.array;
|
||||
a[0] = temp4;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user