swig: add WebPEncodeLossless* wrappers

Change-Id: If373a5d2953ec53b856900666422fb2b4f9939a4
This commit is contained in:
James Zern 2012-07-17 13:42:15 -07:00
parent c2416c9b61
commit 4972302d24
3 changed files with 318 additions and 48 deletions

View File

@ -90,6 +90,10 @@ static jint returned_buffer_size(
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeBGR", 1 }, { "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeBGR", 1 },
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeRGBA", 1 }, { "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeRGBA", 1 },
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeBGRA", 1 }, { "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeBGRA", 1 },
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessRGB", 1 },
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessBGR", 1 },
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessRGBA", 1 },
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessBGRA", 1 },
{ NULL, 0 } { NULL, 0 }
}; };
const struct sizemap *p; const struct sizemap *p;
@ -108,6 +112,9 @@ static jint returned_buffer_size(
typedef size_t (*WebPEncodeFunction)(const uint8_t* rgb, typedef size_t (*WebPEncodeFunction)(const uint8_t* rgb,
int width, int height, int stride, int width, int height, int stride,
float quality_factor, uint8_t** output); float quality_factor, uint8_t** output);
typedef size_t (*WebPEncodeLosslessFunction)(const uint8_t* rgb,
int width, int height, int stride,
uint8_t** output);
static uint8_t* encode(const uint8_t* rgb, static uint8_t* encode(const uint8_t* rgb,
int width, int height, int stride, int width, int height, int stride,
@ -123,6 +130,19 @@ static uint8_t* encode(const uint8_t* rgb,
*unused = 1; *unused = 1;
return image_size ? output : NULL; return image_size ? output : NULL;
} }
static uint8_t* encode_lossless(const uint8_t* rgb,
int width, int height, int stride,
WebPEncodeLosslessFunction encfn,
int* output_size, int* unused) {
uint8_t *output = NULL;
const size_t image_size = encfn(rgb, width, height, stride, &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;
}
%} %}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -137,6 +157,10 @@ static uint8_t* encode(const uint8_t* rgb,
%newobject wrap_WebPEncodeBGR; %newobject wrap_WebPEncodeBGR;
%newobject wrap_WebPEncodeRGBA; %newobject wrap_WebPEncodeRGBA;
%newobject wrap_WebPEncodeBGRA; %newobject wrap_WebPEncodeBGRA;
%newobject wrap_WebPEncodeLosslessRGB;
%newobject wrap_WebPEncodeLosslessBGR;
%newobject wrap_WebPEncodeLosslessRGBA;
%newobject wrap_WebPEncodeLosslessBGRA;
#ifdef SWIGJAVA #ifdef SWIGJAVA
// There's no reason to call these directly // There's no reason to call these directly
@ -144,6 +168,10 @@ static uint8_t* encode(const uint8_t* rgb,
%javamethodmodifiers wrap_WebPEncodeBGR "private"; %javamethodmodifiers wrap_WebPEncodeBGR "private";
%javamethodmodifiers wrap_WebPEncodeRGBA "private"; %javamethodmodifiers wrap_WebPEncodeRGBA "private";
%javamethodmodifiers wrap_WebPEncodeBGRA "private"; %javamethodmodifiers wrap_WebPEncodeBGRA "private";
%javamethodmodifiers wrap_WebPEncodeLosslessRGB "private";
%javamethodmodifiers wrap_WebPEncodeLosslessBGR "private";
%javamethodmodifiers wrap_WebPEncodeLosslessRGBA "private";
%javamethodmodifiers wrap_WebPEncodeLosslessBGRA "private";
#endif /* SWIGJAVA */ #endif /* SWIGJAVA */
%inline %{ %inline %{
@ -152,33 +180,36 @@ static uint8_t* encode(const uint8_t* rgb,
// than dealing with the return pointer. // than dealing with the return pointer.
// The additional parameters are to allow reuse of returned_buffer_size(), // The additional parameters are to allow reuse of returned_buffer_size(),
// unused2 and output_size will be used in this case. // unused2 and output_size will be used in this case.
static uint8_t* wrap_WebPEncodeRGB( #define LOSSY_WRAPPER(FUNC) \
const uint8_t* rgb, int* unused1, int* unused2, int* output_size, static uint8_t* wrap_##FUNC( \
int width, int height, int stride, float quality_factor) { const uint8_t* rgb, int* unused1, int* unused2, int* output_size, \
return encode(rgb, width, height, stride, quality_factor, int width, int height, int stride, float quality_factor) { \
WebPEncodeRGB, output_size, unused2); return encode(rgb, width, height, stride, quality_factor, \
} FUNC, output_size, unused2); \
} \
static uint8_t* wrap_WebPEncodeBGR( LOSSY_WRAPPER(WebPEncodeRGB)
const uint8_t* bgr, int* unused1, int* unused2, int* output_size, LOSSY_WRAPPER(WebPEncodeBGR)
int width, int height, int stride, float quality_factor) { LOSSY_WRAPPER(WebPEncodeRGBA)
return encode(bgr, width, height, stride, quality_factor, LOSSY_WRAPPER(WebPEncodeBGRA)
WebPEncodeBGR, output_size, unused2);
}
static uint8_t* wrap_WebPEncodeRGBA( #undef LOSSY_WRAPPER
const uint8_t* rgba, int* unused1, int* unused2, int* output_size,
int width, int height, int stride, float quality_factor) { #define LOSSLESS_WRAPPER(FUNC) \
return encode(rgba, width, height, stride, quality_factor, static uint8_t* wrap_##FUNC( \
WebPEncodeRGBA, output_size, unused2); const uint8_t* rgb, int* unused1, int* unused2, int* output_size, \
} int width, int height, int stride) { \
return encode_lossless(rgb, width, height, stride, \
FUNC, output_size, unused2); \
} \
LOSSLESS_WRAPPER(WebPEncodeLosslessRGB)
LOSSLESS_WRAPPER(WebPEncodeLosslessBGR)
LOSSLESS_WRAPPER(WebPEncodeLosslessRGBA)
LOSSLESS_WRAPPER(WebPEncodeLosslessBGRA)
#undef LOSSLESS_WRAPPER
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);
}
%} %}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -226,5 +257,29 @@ static uint8_t* wrap_WebPEncodeBGRA(
return wrap_WebPEncodeBGRA( return wrap_WebPEncodeBGRA(
bgra, UNUSED, UNUSED, outputSize, width, height, stride, quality_factor); bgra, UNUSED, UNUSED, outputSize, width, height, stride, quality_factor);
} }
public static byte[] WebPEncodeLosslessRGB(
byte[] rgb, int width, int height, int stride) {
return wrap_WebPEncodeLosslessRGB(
rgb, UNUSED, UNUSED, outputSize, width, height, stride);
}
public static byte[] WebPEncodeLosslessBGR(
byte[] bgr, int width, int height, int stride) {
return wrap_WebPEncodeLosslessBGR(
bgr, UNUSED, UNUSED, outputSize, width, height, stride);
}
public static byte[] WebPEncodeLosslessRGBA(
byte[] rgba, int width, int height, int stride) {
return wrap_WebPEncodeLosslessRGBA(
rgba, UNUSED, UNUSED, outputSize, width, height, stride);
}
public static byte[] WebPEncodeLosslessBGRA(
byte[] bgra, int width, int height, int stride) {
return wrap_WebPEncodeLosslessBGRA(
bgra, UNUSED, UNUSED, outputSize, width, height, stride);
}
%} %}
#endif /* SWIGJAVA */ #endif /* SWIGJAVA */

Binary file not shown.

View File

@ -829,6 +829,10 @@ static jint returned_buffer_size(
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeBGR", 1 }, { "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeBGR", 1 },
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeRGBA", 1 }, { "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeRGBA", 1 },
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeBGRA", 1 }, { "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeBGRA", 1 },
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessRGB", 1 },
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessBGR", 1 },
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessRGBA", 1 },
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessBGRA", 1 },
{ NULL, 0 } { NULL, 0 }
}; };
const struct sizemap *p; const struct sizemap *p;
@ -847,6 +851,9 @@ static jint returned_buffer_size(
typedef size_t (*WebPEncodeFunction)(const uint8_t* rgb, typedef size_t (*WebPEncodeFunction)(const uint8_t* rgb,
int width, int height, int stride, int width, int height, int stride,
float quality_factor, uint8_t** output); float quality_factor, uint8_t** output);
typedef size_t (*WebPEncodeLosslessFunction)(const uint8_t* rgb,
int width, int height, int stride,
uint8_t** output);
static uint8_t* encode(const uint8_t* rgb, static uint8_t* encode(const uint8_t* rgb,
int width, int height, int stride, int width, int height, int stride,
@ -863,39 +870,55 @@ static uint8_t* encode(const uint8_t* rgb,
return image_size ? output : NULL; return image_size ? output : NULL;
} }
static uint8_t* encode_lossless(const uint8_t* rgb,
int width, int height, int stride,
WebPEncodeLosslessFunction encfn,
int* output_size, int* unused) {
uint8_t *output = NULL;
const size_t image_size = encfn(rgb, width, height, stride, &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;
}
// Changes the return type of WebPEncode* to more closely match Decode*. // 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 // This also makes it easier to wrap the output buffer in a native type rather
// than dealing with the return pointer. // than dealing with the return pointer.
// The additional parameters are to allow reuse of returned_buffer_size(), // The additional parameters are to allow reuse of returned_buffer_size(),
// unused2 and output_size will be used in this case. // unused2 and output_size will be used in this case.
static uint8_t* wrap_WebPEncodeRGB( #define LOSSY_WRAPPER(FUNC) \
const uint8_t* rgb, int* unused1, int* unused2, int* output_size, static uint8_t* wrap_##FUNC( \
int width, int height, int stride, float quality_factor) { const uint8_t* rgb, int* unused1, int* unused2, int* output_size, \
return encode(rgb, width, height, stride, quality_factor, int width, int height, int stride, float quality_factor) { \
WebPEncodeRGB, output_size, unused2); return encode(rgb, width, height, stride, quality_factor, \
} FUNC, output_size, unused2); \
} \
static uint8_t* wrap_WebPEncodeBGR( LOSSY_WRAPPER(WebPEncodeRGB)
const uint8_t* bgr, int* unused1, int* unused2, int* output_size, LOSSY_WRAPPER(WebPEncodeBGR)
int width, int height, int stride, float quality_factor) { LOSSY_WRAPPER(WebPEncodeRGBA)
return encode(bgr, width, height, stride, quality_factor, LOSSY_WRAPPER(WebPEncodeBGRA)
WebPEncodeBGR, output_size, unused2);
}
static uint8_t* wrap_WebPEncodeRGBA( #undef LOSSY_WRAPPER
const uint8_t* rgba, int* unused1, int* unused2, int* output_size,
int width, int height, int stride, float quality_factor) { #define LOSSLESS_WRAPPER(FUNC) \
return encode(rgba, width, height, stride, quality_factor, static uint8_t* wrap_##FUNC( \
WebPEncodeRGBA, output_size, unused2); const uint8_t* rgb, int* unused1, int* unused2, int* output_size, \
} int width, int height, int stride) { \
return encode_lossless(rgb, width, height, stride, \
FUNC, output_size, unused2); \
} \
LOSSLESS_WRAPPER(WebPEncodeLosslessRGB)
LOSSLESS_WRAPPER(WebPEncodeLosslessBGR)
LOSSLESS_WRAPPER(WebPEncodeLosslessRGBA)
LOSSLESS_WRAPPER(WebPEncodeLosslessBGRA)
#undef LOSSLESS_WRAPPER
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);
}
/* Work around broken gcj jni.h */ /* Work around broken gcj jni.h */
@ -1470,6 +1493,198 @@ SWIGEXPORT jbyteArray JNICALL Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeBG
} }
SWIGEXPORT jbyteArray JNICALL Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessRGB(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jint jarg2, jint jarg3, jintArray jarg4, jint jarg5, jint jarg6, jint jarg7) {
jbyteArray jresult = 0 ;
uint8_t *arg1 = (uint8_t *) 0 ;
int *arg2 = (int *) 0 ;
int *arg3 = (int *) 0 ;
int *arg4 = (int *) 0 ;
int arg5 ;
int arg6 ;
int arg7 ;
jbyte *jarr1 ;
int temp4 ;
uint8_t *result = 0 ;
(void)jenv;
(void)jcls;
if (!SWIG_JavaArrayInSchar(jenv, &jarr1, &arg1, jarg1)) return 0;
arg2 = (int *)&jarg2;
arg3 = (int *)&jarg3;
{
if (!jarg4) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
return 0;
}
if ((*jenv)->GetArrayLength(jenv, jarg4) == 0) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
return 0;
}
arg4 = &temp4;
}
arg5 = (int)jarg5;
arg6 = (int)jarg6;
arg7 = (int)jarg7;
result = (uint8_t *)wrap_WebPEncodeLosslessRGB((uint8_t const *)arg1,arg2,arg3,arg4,arg5,arg6,arg7);
jresult = SWIG_JavaArrayOutSchar(jenv, result, FillMeInAsSizeCannotBeDeterminedAutomatically);
SWIG_JavaArrayArgoutSchar(jenv, jarr1, arg1, jarg1);
{
jint jvalue = (jint)temp4;
(*jenv)->SetIntArrayRegion(jenv, jarg4, 0, 1, &jvalue);
}
free(arg1);
free(result);
return jresult;
}
SWIGEXPORT jbyteArray JNICALL Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessBGR(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jint jarg2, jint jarg3, jintArray jarg4, jint jarg5, jint jarg6, jint jarg7) {
jbyteArray jresult = 0 ;
uint8_t *arg1 = (uint8_t *) 0 ;
int *arg2 = (int *) 0 ;
int *arg3 = (int *) 0 ;
int *arg4 = (int *) 0 ;
int arg5 ;
int arg6 ;
int arg7 ;
jbyte *jarr1 ;
int temp4 ;
uint8_t *result = 0 ;
(void)jenv;
(void)jcls;
if (!SWIG_JavaArrayInSchar(jenv, &jarr1, &arg1, jarg1)) return 0;
arg2 = (int *)&jarg2;
arg3 = (int *)&jarg3;
{
if (!jarg4) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
return 0;
}
if ((*jenv)->GetArrayLength(jenv, jarg4) == 0) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
return 0;
}
arg4 = &temp4;
}
arg5 = (int)jarg5;
arg6 = (int)jarg6;
arg7 = (int)jarg7;
result = (uint8_t *)wrap_WebPEncodeLosslessBGR((uint8_t const *)arg1,arg2,arg3,arg4,arg5,arg6,arg7);
jresult = SWIG_JavaArrayOutSchar(jenv, result, FillMeInAsSizeCannotBeDeterminedAutomatically);
SWIG_JavaArrayArgoutSchar(jenv, jarr1, arg1, jarg1);
{
jint jvalue = (jint)temp4;
(*jenv)->SetIntArrayRegion(jenv, jarg4, 0, 1, &jvalue);
}
free(arg1);
free(result);
return jresult;
}
SWIGEXPORT jbyteArray JNICALL Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessRGBA(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jint jarg2, jint jarg3, jintArray jarg4, jint jarg5, jint jarg6, jint jarg7) {
jbyteArray jresult = 0 ;
uint8_t *arg1 = (uint8_t *) 0 ;
int *arg2 = (int *) 0 ;
int *arg3 = (int *) 0 ;
int *arg4 = (int *) 0 ;
int arg5 ;
int arg6 ;
int arg7 ;
jbyte *jarr1 ;
int temp4 ;
uint8_t *result = 0 ;
(void)jenv;
(void)jcls;
if (!SWIG_JavaArrayInSchar(jenv, &jarr1, &arg1, jarg1)) return 0;
arg2 = (int *)&jarg2;
arg3 = (int *)&jarg3;
{
if (!jarg4) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
return 0;
}
if ((*jenv)->GetArrayLength(jenv, jarg4) == 0) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
return 0;
}
arg4 = &temp4;
}
arg5 = (int)jarg5;
arg6 = (int)jarg6;
arg7 = (int)jarg7;
result = (uint8_t *)wrap_WebPEncodeLosslessRGBA((uint8_t const *)arg1,arg2,arg3,arg4,arg5,arg6,arg7);
jresult = SWIG_JavaArrayOutSchar(jenv, result, FillMeInAsSizeCannotBeDeterminedAutomatically);
SWIG_JavaArrayArgoutSchar(jenv, jarr1, arg1, jarg1);
{
jint jvalue = (jint)temp4;
(*jenv)->SetIntArrayRegion(jenv, jarg4, 0, 1, &jvalue);
}
free(arg1);
free(result);
return jresult;
}
SWIGEXPORT jbyteArray JNICALL Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessBGRA(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jint jarg2, jint jarg3, jintArray jarg4, jint jarg5, jint jarg6, jint jarg7) {
jbyteArray jresult = 0 ;
uint8_t *arg1 = (uint8_t *) 0 ;
int *arg2 = (int *) 0 ;
int *arg3 = (int *) 0 ;
int *arg4 = (int *) 0 ;
int arg5 ;
int arg6 ;
int arg7 ;
jbyte *jarr1 ;
int temp4 ;
uint8_t *result = 0 ;
(void)jenv;
(void)jcls;
if (!SWIG_JavaArrayInSchar(jenv, &jarr1, &arg1, jarg1)) return 0;
arg2 = (int *)&jarg2;
arg3 = (int *)&jarg3;
{
if (!jarg4) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
return 0;
}
if ((*jenv)->GetArrayLength(jenv, jarg4) == 0) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
return 0;
}
arg4 = &temp4;
}
arg5 = (int)jarg5;
arg6 = (int)jarg6;
arg7 = (int)jarg7;
result = (uint8_t *)wrap_WebPEncodeLosslessBGRA((uint8_t const *)arg1,arg2,arg3,arg4,arg5,arg6,arg7);
jresult = SWIG_JavaArrayOutSchar(jenv, result, FillMeInAsSizeCannotBeDeterminedAutomatically);
SWIG_JavaArrayArgoutSchar(jenv, jarr1, arg1, jarg1);
{
jint jvalue = (jint)temp4;
(*jenv)->SetIntArrayRegion(jenv, jarg4, 0, 1, &jvalue);
}
free(arg1);
free(result);
return jresult;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif