swig: cosmetics

normalize formatting
- update decode prototypes
- match project function name style

Change-Id: Ib481b5602171b72dbb1a5d462e6d5166e9b8566e
(cherry picked from commit 7f5f42bb36e07c4f61fe19617e29fb2b5fed5b5d)
This commit is contained in:
James Zern 2013-05-08 18:00:30 -07:00
parent 498d4dd634
commit b4f5bb6ca3
2 changed files with 62 additions and 59 deletions

View File

@ -28,13 +28,13 @@
// map uint8_t* such that a byte[] is used // map uint8_t* such that a byte[] is used
// this will generate a few spurious warnings in the wrapper code // this will generate a few spurious warnings in the wrapper code
%apply signed char[] { uint8_t * } %apply signed char[] { uint8_t* }
#endif /* SWIGJAVA */ #endif /* SWIGJAVA */
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Decoder specific // Decoder specific
%apply int *OUTPUT { int *width, int *height } %apply int* OUTPUT { int* width, int* height }
// free the buffer returned by these functions after copying into // free the buffer returned by these functions after copying into
// the native type // the native type
@ -47,18 +47,18 @@
int WebPGetDecoderVersion(void); int WebPGetDecoderVersion(void);
int WebPGetInfo(const uint8_t* data, size_t data_size, int WebPGetInfo(const uint8_t* data, size_t data_size,
int *width, int *height); int* width, int* height);
uint8_t* WebPDecodeRGB(const uint8_t* data, size_t data_size, uint8_t* WebPDecodeRGB(const uint8_t* data, size_t data_size,
int *width, int *height); int* width, int* height);
uint8_t* WebPDecodeRGBA(const uint8_t* data, size_t data_size, uint8_t* WebPDecodeRGBA(const uint8_t* data, size_t data_size,
int *width, int *height); int* width, int* height);
uint8_t* WebPDecodeARGB(const uint8_t* data, size_t data_size, uint8_t* WebPDecodeARGB(const uint8_t* data, size_t data_size,
int* width, int* height); int* width, int* height);
uint8_t* WebPDecodeBGR(const uint8_t* data, size_t data_size, uint8_t* WebPDecodeBGR(const uint8_t* data, size_t data_size,
int *width, int *height); int* width, int* height);
uint8_t* WebPDecodeBGRA(const uint8_t* data, size_t data_size, uint8_t* WebPDecodeBGRA(const uint8_t* data, size_t data_size,
int *width, int *height); int* width, int* height);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Encoder specific // Encoder specific
@ -76,12 +76,12 @@ int WebPGetEncoderVersion(void);
#ifdef SWIGJAVA #ifdef SWIGJAVA
%{ %{
#define FillMeInAsSizeCannotBeDeterminedAutomatically \ #define FillMeInAsSizeCannotBeDeterminedAutomatically \
(result ? returned_buffer_size(__FUNCTION__, arg3, arg4) : 0) (result ? ReturnedBufferSize(__FUNCTION__, arg3, arg4) : 0)
static jint returned_buffer_size( static jint ReturnedBufferSize(
const char *function, int *width, int *height) { const char* function, int* width, int* height) {
static const struct sizemap { static const struct sizemap {
const char *function; const char* function;
int size_multiplier; int size_multiplier;
} size_map[] = { } size_map[] = {
{ "Java_com_google_webp_libwebpJNI_WebPDecodeRGB", 3 }, { "Java_com_google_webp_libwebpJNI_WebPDecodeRGB", 3 },
@ -99,7 +99,7 @@ static jint returned_buffer_size(
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessBGRA", 1 }, { "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessBGRA", 1 },
{ NULL, 0 } { NULL, 0 }
}; };
const struct sizemap *p; const struct sizemap* p;
jint size = -1; jint size = -1;
for (p = size_map; p->function; p++) { for (p = size_map; p->function; p++) {
@ -123,29 +123,29 @@ typedef size_t (*WebPEncodeLosslessFunction)(const uint8_t* rgb,
int width, int height, int stride, int width, int height, int stride,
uint8_t** output); uint8_t** output);
static uint8_t* encode(const uint8_t* rgb, static uint8_t* EncodeLossy(const uint8_t* rgb,
int width, int height, int stride, int width, int height, int stride,
float quality_factor, float quality_factor,
WebPEncodeFunction encfn, WebPEncodeFunction encfn,
int* output_size, int* unused) { int* output_size, int* unused) {
uint8_t *output = NULL; uint8_t* output = NULL;
const size_t image_size = const size_t image_size =
encfn(rgb, width, height, stride, quality_factor, &output); encfn(rgb, width, height, stride, quality_factor, &output);
// the values of following two will be interpreted by returned_buffer_size() // the values of following two will be interpreted by ReturnedBufferSize()
// as 'width' and 'height' in the size calculation. // as 'width' and 'height' in the size calculation.
*output_size = image_size; *output_size = image_size;
*unused = 1; *unused = 1;
return image_size ? output : NULL; return image_size ? output : NULL;
} }
static uint8_t* encode_lossless(const uint8_t* rgb, static uint8_t* EncodeLossless(const uint8_t* rgb,
int width, int height, int stride, int width, int height, int stride,
WebPEncodeLosslessFunction encfn, WebPEncodeLosslessFunction encfn,
int* output_size, int* unused) { int* output_size, int* unused) {
uint8_t *output = NULL; uint8_t* output = NULL;
const size_t image_size = encfn(rgb, width, height, stride, &output); const size_t image_size = encfn(rgb, width, height, stride, &output);
// the values of following two will be interpreted by returned_buffer_size() // the values of the following two will be interpreted by
// as 'width' and 'height' in the size calculation. // ReturnedBufferSize() as 'width' and 'height' in the size calculation.
*output_size = image_size; *output_size = image_size;
*unused = 1; *unused = 1;
return image_size ? output : NULL; return image_size ? output : NULL;
@ -155,8 +155,8 @@ static uint8_t* encode_lossless(const uint8_t* rgb,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// libwebp/encode wrapper functions // libwebp/encode wrapper functions
%apply int *INPUT { int *unused1, int *unused2 } %apply int* INPUT { int* unused1, int* unused2 }
%apply int *OUTPUT { int *output_size } %apply int* OUTPUT { int* output_size }
// free the buffer returned by these functions after copying into // free the buffer returned by these functions after copying into
// the native type // the native type
@ -185,14 +185,14 @@ static uint8_t* encode_lossless(const uint8_t* rgb,
// 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 ReturnedBufferSize(),
// unused2 and output_size will be used in this case. // unused2 and output_size will be used in this case.
#define LOSSY_WRAPPER(FUNC) \ #define LOSSY_WRAPPER(FUNC) \
static uint8_t* wrap_##FUNC( \ static uint8_t* wrap_##FUNC( \
const uint8_t* rgb, int* unused1, int* unused2, int* output_size, \ const uint8_t* rgb, int* unused1, int* unused2, int* output_size, \
int width, int height, int stride, float quality_factor) { \ int width, int height, int stride, float quality_factor) { \
return encode(rgb, width, height, stride, quality_factor, \ return EncodeLossy(rgb, width, height, stride, quality_factor, \
FUNC, output_size, unused2); \ FUNC, output_size, unused2); \
} \ } \
LOSSY_WRAPPER(WebPEncodeRGB) LOSSY_WRAPPER(WebPEncodeRGB)
@ -206,8 +206,8 @@ LOSSY_WRAPPER(WebPEncodeBGRA)
static uint8_t* wrap_##FUNC( \ static uint8_t* wrap_##FUNC( \
const uint8_t* rgb, int* unused1, int* unused2, int* output_size, \ const uint8_t* rgb, int* unused1, int* unused2, int* output_size, \
int width, int height, int stride) { \ int width, int height, int stride) { \
return encode_lossless(rgb, width, height, stride, \ return EncodeLossless(rgb, width, height, stride, \
FUNC, output_size, unused2); \ FUNC, output_size, unused2); \
} \ } \
LOSSLESS_WRAPPER(WebPEncodeLosslessRGB) LOSSLESS_WRAPPER(WebPEncodeLosslessRGB)

View File

@ -1,6 +1,6 @@
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org). * This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.40 * Version 2.0.4
* *
* This file is not intended to be easily readable and contains a number of * 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 * coding conventions designed to improve portability and efficiency. Do not make
@ -811,13 +811,14 @@ jdoubleArray SWIG_JavaArrayOutDouble (JNIEnv *jenv, double *result, jsize sz) {
#include "webp/decode.h" #include "webp/decode.h"
#include "webp/encode.h" #include "webp/encode.h"
#define FillMeInAsSizeCannotBeDeterminedAutomatically \
(result ? returned_buffer_size(__FUNCTION__, arg3, arg4) : 0)
static jint returned_buffer_size( #define FillMeInAsSizeCannotBeDeterminedAutomatically \
const char *function, int *width, int *height) { (result ? ReturnedBufferSize(__FUNCTION__, arg3, arg4) : 0)
static jint ReturnedBufferSize(
const char* function, int* width, int* height) {
static const struct sizemap { static const struct sizemap {
const char *function; const char* function;
int size_multiplier; int size_multiplier;
} size_map[] = { } size_map[] = {
{ "Java_com_google_webp_libwebpJNI_WebPDecodeRGB", 3 }, { "Java_com_google_webp_libwebpJNI_WebPDecodeRGB", 3 },
@ -835,7 +836,7 @@ static jint returned_buffer_size(
{ "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessBGRA", 1 }, { "Java_com_google_webp_libwebpJNI_wrap_1WebPEncodeLosslessBGRA", 1 },
{ NULL, 0 } { NULL, 0 }
}; };
const struct sizemap *p; const struct sizemap* p;
jint size = -1; jint size = -1;
for (p = size_map; p->function; p++) { for (p = size_map; p->function; p++) {
@ -848,6 +849,8 @@ static jint returned_buffer_size(
return size; return 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);
@ -855,29 +858,29 @@ typedef size_t (*WebPEncodeLosslessFunction)(const uint8_t* rgb,
int width, int height, int stride, int width, int height, int stride,
uint8_t** output); uint8_t** output);
static uint8_t* encode(const uint8_t* rgb, static uint8_t* EncodeLossy(const uint8_t* rgb,
int width, int height, int stride, int width, int height, int stride,
float quality_factor, float quality_factor,
WebPEncodeFunction encfn, WebPEncodeFunction encfn,
int* output_size, int* unused) { int* output_size, int* unused) {
uint8_t *output = NULL; uint8_t* output = NULL;
const size_t image_size = const size_t image_size =
encfn(rgb, width, height, stride, quality_factor, &output); encfn(rgb, width, height, stride, quality_factor, &output);
// the values of following two will be interpreted by returned_buffer_size() // the values of following two will be interpreted by ReturnedBufferSize()
// as 'width' and 'height' in the size calculation. // as 'width' and 'height' in the size calculation.
*output_size = image_size; *output_size = image_size;
*unused = 1; *unused = 1;
return image_size ? output : NULL; return image_size ? output : NULL;
} }
static uint8_t* encode_lossless(const uint8_t* rgb, static uint8_t* EncodeLossless(const uint8_t* rgb,
int width, int height, int stride, int width, int height, int stride,
WebPEncodeLosslessFunction encfn, WebPEncodeLosslessFunction encfn,
int* output_size, int* unused) { int* output_size, int* unused) {
uint8_t *output = NULL; uint8_t* output = NULL;
const size_t image_size = encfn(rgb, width, height, stride, &output); const size_t image_size = encfn(rgb, width, height, stride, &output);
// the values of following two will be interpreted by returned_buffer_size() // the values of the following two will be interpreted by
// as 'width' and 'height' in the size calculation. // ReturnedBufferSize() as 'width' and 'height' in the size calculation.
*output_size = image_size; *output_size = image_size;
*unused = 1; *unused = 1;
return image_size ? output : NULL; return image_size ? output : NULL;
@ -887,14 +890,14 @@ static uint8_t* encode_lossless(const uint8_t* rgb,
// 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 ReturnedBufferSize(),
// unused2 and output_size will be used in this case. // unused2 and output_size will be used in this case.
#define LOSSY_WRAPPER(FUNC) \ #define LOSSY_WRAPPER(FUNC) \
static uint8_t* wrap_##FUNC( \ static uint8_t* wrap_##FUNC( \
const uint8_t* rgb, int* unused1, int* unused2, int* output_size, \ const uint8_t* rgb, int* unused1, int* unused2, int* output_size, \
int width, int height, int stride, float quality_factor) { \ int width, int height, int stride, float quality_factor) { \
return encode(rgb, width, height, stride, quality_factor, \ return EncodeLossy(rgb, width, height, stride, quality_factor, \
FUNC, output_size, unused2); \ FUNC, output_size, unused2); \
} \ } \
LOSSY_WRAPPER(WebPEncodeRGB) LOSSY_WRAPPER(WebPEncodeRGB)
@ -908,8 +911,8 @@ LOSSY_WRAPPER(WebPEncodeBGRA)
static uint8_t* wrap_##FUNC( \ static uint8_t* wrap_##FUNC( \
const uint8_t* rgb, int* unused1, int* unused2, int* output_size, \ const uint8_t* rgb, int* unused1, int* unused2, int* output_size, \
int width, int height, int stride) { \ int width, int height, int stride) { \
return encode_lossless(rgb, width, height, stride, \ return EncodeLossless(rgb, width, height, stride, \
FUNC, output_size, unused2); \ FUNC, output_size, unused2); \
} \ } \
LOSSLESS_WRAPPER(WebPEncodeLosslessRGB) LOSSLESS_WRAPPER(WebPEncodeLosslessRGB)