mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-16 05:49:51 +02:00
swig/java: basic encode support
Wrap WebPEncode???* to provide an interface similar to decode. As only WebPGetEncoderVersion is wrapped directly from encode.h avoid including it in the swig file to reduce %ignore's. This change also removes unnecessary incremental decoding related enums. Change-Id: I0b5424026aa6ae012c6a29ad2f2301c2681ca301
This commit is contained in:
123
swig/libwebp.i
123
swig/libwebp.i
@ -21,6 +21,9 @@
|
||||
%include "constraints.i"
|
||||
%include "typemaps.i"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Decoder specific
|
||||
|
||||
%ignore WEBP_WEBP_DECODE_H_;
|
||||
// FIXME for these to be available returned_buffer_size() would need to be
|
||||
// made more intelligent.
|
||||
@ -32,6 +35,8 @@
|
||||
%ignore WebPDecodeYUVInto;
|
||||
|
||||
// incremental decoding
|
||||
%ignore WEBP_CSP_MODE;
|
||||
%ignore VP8StatusCode;
|
||||
%ignore WebPIDecGetYUV;
|
||||
%ignore WebPINew;
|
||||
%ignore WebPIDecoder;
|
||||
@ -56,6 +61,11 @@
|
||||
%newobject WebPDecodeBGRA;
|
||||
%typemap(newfree) uint8_t* "free($1);"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Encoder specific
|
||||
|
||||
int WebPGetEncoderVersion(void);
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
%include "arrays_java.i";
|
||||
%include "enums.swg" /*NB: requires JDK-1.5+
|
||||
@ -81,6 +91,7 @@
|
||||
*/
|
||||
%{
|
||||
#include "webp/decode.h"
|
||||
#include "webp/encode.h"
|
||||
|
||||
#define FillMeInAsSizeCannotBeDeterminedAutomatically \
|
||||
(result ? returned_buffer_size(__FUNCTION__, arg3, arg4) : 0)
|
||||
@ -95,6 +106,10 @@ static jint returned_buffer_size(
|
||||
{ "Java_com_google_webp_libwebpJNI_WebPDecodeRGBA", 4 },
|
||||
{ "Java_com_google_webp_libwebpJNI_WebPDecodeBGR", 3 },
|
||||
{ "Java_com_google_webp_libwebpJNI_WebPDecodeBGRA", 4 },
|
||||
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeRGB", 1 },
|
||||
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeBGR", 1 },
|
||||
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeRGBA", 1 },
|
||||
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeBGRA", 1 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
const struct sizemap *p;
|
||||
@ -109,7 +124,115 @@ static jint returned_buffer_size(
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
typedef size_t (*WebPEncodeFunction)(const uint8_t* rgb,
|
||||
int width, int height, int stride,
|
||||
float quality_factor, uint8_t** output);
|
||||
|
||||
static uint8_t* encode(const uint8_t* rgb,
|
||||
int width, int height, int stride,
|
||||
float quality_factor,
|
||||
WebPEncodeFunction encfn,
|
||||
int* output_size, int* unused) {
|
||||
uint8_t *output = NULL;
|
||||
const size_t image_size =
|
||||
encfn(rgb, width, height, stride, quality_factor, &output);
|
||||
// the values of following two will be interpreted by returned_buffer_size()
|
||||
// as 'width' and 'height' in the size calculation.
|
||||
*output_size = image_size;
|
||||
*unused = 1;
|
||||
return image_size ? output : NULL;
|
||||
}
|
||||
%}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// libwebp/encode wrapper functions
|
||||
|
||||
%apply int *INPUT { int *unused1, int *unused2 }
|
||||
%apply int *OUTPUT { int *output_size }
|
||||
|
||||
// free the buffer returned by these functions after copying into
|
||||
// the native type
|
||||
%newobject wrap_WebPEncodeRGB;
|
||||
%newobject wrap_WebPEncodeBGR;
|
||||
%newobject wrap_WebPEncodeRGBA;
|
||||
%newobject wrap_WebPEncodeBGRA;
|
||||
|
||||
%inline %{
|
||||
// Changes the return type of WebPEncode* to more closely match Decode*.
|
||||
// This also makes it easier to wrap the output buffer in a native type rather
|
||||
// than dealing with the return pointer.
|
||||
// The additional parameters are to allow reuse of returned_buffer_size(),
|
||||
// unused2 and output_size will be used in this case.
|
||||
static uint8_t* wrap_WebPEncodeRGB(
|
||||
const uint8_t* rgb, int* unused1, int* unused2, int* output_size,
|
||||
int width, int height, int stride, float quality_factor) {
|
||||
return encode(rgb, width, height, stride, quality_factor,
|
||||
WebPEncodeRGB, output_size, unused2);
|
||||
}
|
||||
|
||||
static uint8_t* wrap_WebPEncodeBGR(
|
||||
const uint8_t* bgr, int* unused1, int* unused2, int* output_size,
|
||||
int width, int height, int stride, float quality_factor) {
|
||||
return encode(bgr, width, height, stride, quality_factor,
|
||||
WebPEncodeBGR, output_size, unused2);
|
||||
}
|
||||
|
||||
static uint8_t* wrap_WebPEncodeRGBA(
|
||||
const uint8_t* rgba, int* unused1, int* unused2, int* output_size,
|
||||
int width, int height, int stride, float quality_factor) {
|
||||
return encode(rgba, width, height, stride, quality_factor,
|
||||
WebPEncodeRGBA, output_size, unused2);
|
||||
}
|
||||
|
||||
static uint8_t* wrap_WebPEncodeBGRA(
|
||||
const uint8_t* bgra, int* unused1, int* unused2, int* output_size,
|
||||
int width, int height, int stride, float quality_factor) {
|
||||
return encode(bgra, width, height, stride, quality_factor,
|
||||
WebPEncodeBGRA, output_size, unused2);
|
||||
}
|
||||
%}
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
// There's no reason to call these directly
|
||||
%javamethodmodifiers wrap_WebPEncodeRGB "private";
|
||||
%javamethodmodifiers wrap_WebPEncodeBGR "private";
|
||||
%javamethodmodifiers wrap_WebPEncodeRGBA "private";
|
||||
%javamethodmodifiers wrap_WebPEncodeBGRA "private";
|
||||
|
||||
%pragma(java) modulecode=%{
|
||||
private static final int UNUSED = 1;
|
||||
private static int outputSize[] = { 0 };
|
||||
|
||||
public static byte[] WebPEncodeRGB(byte[] rgb,
|
||||
int width, int height, int stride,
|
||||
float quality_factor) {
|
||||
return wrap_WebPEncodeRGB(
|
||||
rgb, UNUSED, UNUSED, outputSize, width, height, stride, quality_factor);
|
||||
}
|
||||
|
||||
public static byte[] WebPEncodeBGR(byte[] bgr,
|
||||
int width, int height, int stride,
|
||||
float quality_factor) {
|
||||
return wrap_WebPEncodeBGR(
|
||||
bgr, UNUSED, UNUSED, outputSize, width, height, stride, quality_factor);
|
||||
}
|
||||
|
||||
public static byte[] WebPEncodeRGBA(byte[] rgba,
|
||||
int width, int height, int stride,
|
||||
float quality_factor) {
|
||||
return wrap_WebPEncodeRGBA(
|
||||
rgba, UNUSED, UNUSED, outputSize, width, height, stride, quality_factor);
|
||||
}
|
||||
|
||||
public static byte[] WebPEncodeBGRA(byte[] bgra,
|
||||
int width, int height, int stride,
|
||||
float quality_factor) {
|
||||
return wrap_WebPEncodeBGRA(
|
||||
bgra, UNUSED, UNUSED, outputSize, width, height, stride, quality_factor);
|
||||
}
|
||||
%}
|
||||
#endif /* SWIGJAVA */
|
||||
|
||||
// All functions, constants, etc. not named above in %ignore will be wrapped
|
||||
%include "webp/decode.h"
|
||||
|
Reference in New Issue
Block a user