/* Generated from "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod" by precompile.pike running Pike v8.0 release 1089
 *
 * Do NOT edit this file.
 */

#undef PRECOMPILE_API_VERSION
#define PRECOMPILE_API_VERSION 6

#undef PRECOMPILE_SUB_PIKEVARS
#define PRECOMPILE_SUB_PIKEVARS 1

#undef PRECOMPILE_DYNAMIC_TYPES
#define PRECOMPILE_DYNAMIC_TYPES 1



#undef cmod___CMOD__
#define cmod___CMOD__ 1
#line 1 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
#line 1 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
#line 1 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
#line 3003 "/Users/hww3/devel/pike/lib/modules/Tools.pmod/Standalone.pmod/precompile.pike"







#line 3010 "/Users/hww3/devel/pike/lib/modules/Tools.pmod/Standalone.pmod/precompile.pike"
#line 1 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
#line 1 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
#include "pike_macros.h"
#include "object.h"
#include "constants.h"
#include "interpret.h"
#include "svalue.h"
#include "threads.h"
#include "array.h"
#include "builtin_functions.h"
#include "mapping.h"
#include "pike_error.h"
#include "threads.h"
#include "operators.h"
#include "module_support.h"
#include "modules/Image/image.h"
#include "config.h"

#ifdef HAVE_LIBWEBP


#ifndef PIKE_UNUSED_ATTRIBUTE
#define PIKE_UNUSED_ATTRIBUTE
#endif
#define CMOD_MAP_PROGRAM_IDS_DEFINED 1
static int ___cmod_map_program_ids(int id) PIKE_UNUSED_ATTRIBUTE;
#ifndef TYPEOF
/* Compat with older Pikes. */
#define TYPEOF(SVAL)	((SVAL).type)
#define SUBTYPEOF(SVAL)	((SVAL).subtype)
#define SET_SVAL_TYPE(SVAL, TYPE)	(TYPEOF(SVAL) = TYPE)
#define SET_SVAL_SUBTYPE(SVAL, TYPE)	(SUBTYPEOF(SVAL) = TYPE)
#define SET_SVAL(SVAL, TYPE, SUBTYPE, FIELD, EXPR) do {	\
    /* Set the type afterwards to avoid a clobbered	\
     * svalue in case EXPR throws. */			\
    (SVAL).u.FIELD = (EXPR);				\
    SET_SVAL_TYPE((SVAL), (TYPE));			\
    SET_SVAL_SUBTYPE((SVAL), (SUBTYPE));		\
  } while(0)
#endif /* !TYPEOF */
#ifndef PIKE_UNUSED
/* Compat with Pike 7.8 and earlier. */
/* NB: Not strictly correct; PIKE_UNUSED was added the
 *     day after set_program_id_to_id(), but good enough.
 */
#ifndef UNUSED
#define UNUSED(X)	X
#endif
#ifndef set_program_id_to_id
/* NB: Recent Pike 7.8 has a #define that conflicts with
 *     the following declaration.
 */
static void set_program_id_to_id(void*UNUSED(id)){}
#endif
#else /* */
PMOD_EXPORT void set_program_id_to_id( int (*to)(int) );
#endif /* !PIKE_UNUSED */


#ifndef DEFAULT_CMOD_STORAGE
#define CMOD_COND_USED
#define DEFAULT_CMOD_STORAGE static
#endif
#define module_strings_declared
static struct pike_string *module_strings[1] = {
  NULL,
};
static struct { INT32 from;INT32 to; } ___cmod_ext_used[1];
#ifndef CMOD_COND_USED
# define f_cq__Image_WebP_decode_fun_num_used 1
#else
#undef f_cq__Image_WebP_decode_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_cq__Image_WebP_encode_fun_num_used 1
#else
#undef f_cq__Image_WebP_encode_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_cq__Image_WebP_cq__decode_fun_num_used 1
#else
#undef f_cq__Image_WebP_cq__decode_fun_num_used
#endif
#line 20 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
/* #define DEFAULT_CMOD_STORAGE static*/
#define true 1
#define false 0

#include <webp/encode.h>
#include <webp/decode.h>

#if WEBP_ENCODER_ABI_VERSION < 0x0201
typedef struct WebPMemoryWriter
{
uint8_t* mem; /* final buffer (of size 'max_size', larger than 'size'). */
size_t size; /* final size */
size_t max_size; /* total capacity */
uint32_t pad[1]; /* padding for later use */
} WebPMemoryWriter;

/* This is from LIBWEBP 0.3.1+ */
void WebPMemoryWriterInit(WebPMemoryWriter* writer)
{
writer->mem = NULL;
writer->size = 0;
writer->max_size = 0;
}

int WebPMemoryWrite(const uint8_t* data, size_t data_size,
const WebPPicture* picture)
{
WebPMemoryWriter* const w = (WebPMemoryWriter*)picture->custom_ptr;
uint64_t next_size;
if (w == NULL)
{
return 1;
}

next_size = (uint64_t)w->size + data_size;

if (next_size > w->max_size)
{
uint8_t* new_mem;
size_t next_max_size = 2ULL * w->max_size;
if (next_max_size < next_size) next_max_size = next_size;
if (next_max_size < 8192ULL) next_max_size = 8192ULL;
new_mem = xalloc(next_max_size);
if (w->size > 0) {
memcpy(new_mem, w->mem, w->size);
}
free(w->mem);
w->mem = new_mem;
w->max_size = (size_t)next_max_size;
}
if (data_size > 0) {
memcpy(w->mem + w->size, data, data_size);
w->size += data_size;
}
return 1;
}
#endif


typedef int (*Importer)(WebPPicture* const, const uint8_t* const, int);


typedef struct object object;
typedef struct program program;

static program *img_program;

static program *image_program()
{
if( !img_program )
{
push_text("Image.Image");
SAFE_APPLY_MASTER("resolv",1);
img_program = Pike_sp[-1].u.program;
Pike_sp--;
}
return img_program;
}

static object *allocate_image(int w, int h )
{
push_int(w);
push_int(h);
return clone_object(image_program(),2);
}

static inline int image_width( object *img )
{
char *x;
if( !img ) return 0;
x = get_storage( img, image_program() );
if( !x ) return 0;
return ((struct image *)x)->xsize;
}

static inline int image_height( object *img )
{
char *x;
if( !img ) return 0;
x = get_storage( img, image_program() );
if( !x ) return 0;
return ((struct image *)x)->ysize;
}

static inline unsigned char *image_ptr( object *img )
{
char *x;
if( !img ) return 0;
x = get_storage( img, image_program() );
if( !x ) return 0;
return (unsigned char *)(((struct image *)x)->img);
}


static size_t Encode(const uint8_t* rgba, int width, int height, int stride,
Importer import, WebPConfig *config, uint8_t** output)
{
WebPPicture pic;
WebPMemoryWriter wrt;
int ok;

if( !WebPPictureInit(&pic) )
return 0;

#if WEBP_ENCODER_ABI_VERSION > 0x0200
 pic.use_argb = !!config->lossless;
#endif
 pic.width = width;
pic.height = height;
pic.writer = WebPMemoryWrite;
pic.custom_ptr = &wrt;
WebPMemoryWriterInit(&wrt);

ok = import(&pic, rgba, stride) && WebPEncode(config, &pic);
WebPPictureFree(&pic);

if (!ok)
{
free(wrt.mem);
*output = NULL;
switch( pic.error_code )
{
case VP8_ENC_ERROR_OUT_OF_MEMORY:
*output = (uint8_t*)"Out of memory\n";
break;
case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY:
*output = (uint8_t*)"Out of memory while writing\n";
break;
case VP8_ENC_ERROR_NULL_PARAMETER:
*output =(uint8_t*) "Pointer parameter is NULL\n";
break;
case VP8_ENC_ERROR_INVALID_CONFIGURATION:
*output = (uint8_t*)"Invalid parameters\n";
break;
case VP8_ENC_ERROR_BAD_DIMENSION:
*output = (uint8_t*)"Invalid image size\n";
break;
case VP8_ENC_ERROR_PARTITION0_OVERFLOW:
*output = (uint8_t*)"Invalid partition0 size\n";
break;
case VP8_ENC_ERROR_PARTITION_OVERFLOW:
*output = (uint8_t*)"Invalid partition size\n";
break;
case VP8_ENC_ERROR_FILE_TOO_BIG:
*output = (uint8_t*)"File too big, >4G\n";
break;
#ifdef VP8_ENC_ERROR_USER_ABORT
 case VP8_ENC_ERROR_USER_ABORT:
*output = (uint8_t*)"User aborted\n";
break;
#endif
 default:
*output = (uint8_t*)"Unknown error\n";
break;
}
return 0;
}
*output = wrt.mem;
return wrt.size;
}


/*! @module Image
 *!
 *! @module WebP
 *!
 *! WebP is a truecolor image format with alpha channel support
 *! currently developed by Google.
 *!
 *! This module supports decoding and encoding of lossy and lossless
 *! WebP images with and without alpha channels using the libwebp library.
 *!
 *! WebP images are generally smaller than the same quality JPEG or
 *! PNG image, but takes longer to encode and decode, and support in
 *! various applications is less common.
 *!
 */

/*! @decl mapping _decode( string data )
 *!
 *! Decode a WebP image.
 *!
 *! @returns
 *! @mapping
 *! @member Image.Image "alpha"
 *! @member Image.Image "image"
 *! @member string "format"
 *! @member int(1..16384) "width"
 *! @member int(1..16384) "height"
 *! @endmapping
 */

/*! @decl Image.Image decode( string data )
 *!
 *! Decode a WebP image, like @[_decode].
 *! @returns
 *! The decoded image or an error
 */

#define f_cq__Image_WebP_cq__decode_defined

#ifdef f_cq__Image_WebP_cq__decode_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_cq__Image_WebP_cq__decode_fun_num = 0;

#endif /* f_cq__Image_WebP_cq__decode_fun_num_used */
DEFAULT_CMOD_STORAGE void f_cq__Image_WebP_cq__decode(INT32 args) {
#line 239 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
struct pike_string * data;
#line 239 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
if(args != 1) wrong_number_of_args_error("_decode",args,1);
#line 239 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("_decode",1,"string");
#line 239 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
debug_malloc_pass(data=Pike_sp[0-1].u.string);
{
int width, height, npix;
uint8_t *ip, *rp, *ap;
object *i = NULL, *a = NULL;
WebPBitstreamFeatures features;
uint8_t *res = WebPDecodeRGBA( (uint8_t*)data->str, data->len,
&width, &height );
WebPGetFeatures( (uint8_t*)data->str, data->len, &features );

if( !res )
Pike_error("Failed to decode image\n");

ip = ap = NULL;
rp = res;
npix = width * height;

if( features.has_alpha )
{
a = allocate_image( width, height );
ap = image_ptr( a );
}
i = allocate_image( width, height );
ip = image_ptr( i );

while( npix-- )
{
uint8_t av;
*(ip++) = *(rp++); /* R */
*(ip++) = *(rp++); /* G */
*(ip++) = *(rp++); /* B */
av = *(rp++);

if( ap )
{
*(ap++) = av; /* A */
*(ap++) = av;
*(ap++) = av;
}
}
free( res );

pop_n_elems(args);

push_text( "image" ); push_object( i );
push_text( "img" ); ref_push_object( i );
push_text( "alpha" );
if( a ) 
push_object( a );
else 
push_undefined( );
push_text("format"); push_text("image/webp");
push_text( "xsize" ); push_int( width );
push_text( "ysize" ); push_int( height );
f_aggregate_mapping( 12 );
}

}
#define f_cq__Image_WebP_decode_defined

#ifdef f_cq__Image_WebP_decode_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_cq__Image_WebP_decode_fun_num = 0;

#endif /* f_cq__Image_WebP_decode_fun_num_used */
DEFAULT_CMOD_STORAGE void f_cq__Image_WebP_decode(INT32 args) {
#line 296 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
struct pike_string * data;
#line 296 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
if(args != 1) wrong_number_of_args_error("decode",args,1);
#line 296 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("decode",1,"string");
#line 296 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
debug_malloc_pass(data=Pike_sp[0-1].u.string);
{
struct mapping *m;
struct svalue *p;

apply(Pike_fp->current_object, "_decode", args);

m = Pike_sp[-1].u.mapping;

if( TYPEOF(Pike_sp[-1]) != PIKE_T_MAPPING )
Pike_error("Decoding failed\n");

p = simple_mapping_string_lookup(m,"image");

if( !p || TYPEOF(*p) != PIKE_T_OBJECT )
Pike_error("Decoding failed\n");

ref_push_object( p->u.object );
stack_unlink(1);
}

}
#line 317 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
static int parameter_int(struct mapping *map, const char *what, int def )
{
struct svalue *v = simple_mapping_string_lookup(map,what);
if (v && TYPEOF(*v) == PIKE_T_INT) return v->u.integer;
return def;
}

static double parameter_float(struct mapping *map, const char *what,
double def )
{
struct svalue *v = simple_mapping_string_lookup(map,what);
if (!v) return def;
if( TYPEOF(*v) == PIKE_T_INT )
return (float)v->u.integer;
if( TYPEOF(*v) == PIKE_T_FLOAT )
return (float)v->u.float_number;
return def;
}

static object *parameter_obj(struct mapping *map, const char *what )
{
struct svalue *v = simple_mapping_string_lookup(map,what);
if( v && TYPEOF(*v) == PIKE_T_OBJECT )
return v->u.object;
return NULL;
}


/*! @decl string encode( Image.Image image, mapping(string:int|float|Image.Image)|void options )
 *!
 *! Encode an image using the WebP format.
 *!
 *! The image to encode has to be at most 16384 pixels in any direction.
 *!
 *! Commonly used options:
 *!
 *! @mapping
 *! @member Image.Image "alpha"
 *!  If present, the alpha channel for the image will be the green
 *!  component of this image. Has to be the same size as the @[image]
 *! @member int "preset"
 *!  Initialization for the encoding options.
 *!  One of PRESET_DEFAULT, PRESET_PICTURE, PRESET_PHOTO
 *!  PRESET_DRAWING, PRESET_ICON and PRESET_TEXT
 *! @member bool "lossless"
 *!  If set, do lossless encoding.
 *! @member float "quality"
 *!  Between 0 and 99. If quality is 100+, lossless encoding with
 *!  quality 70 will be used.
 *! @endmapping
 *!
 *!  Additionally these advanced options are also supported:
 *!
 *! @mapping
 *! @member int "image_hint"
 *!   One of HINT_DEFAULT, HINT_PICTURE, HINT_PHOTO and HINT_GRAPH.
 *!   Only used in lossless mode
 *! @member int "target_size"
 *!  If non zero, sets the desired filesize, in bytes. Takes
 *!  precedence over quality.
 *! @member int "target_PSNR"
 *!  if non-zero, specifies the minimal distortion to try to
 *!  achieve. Takes precedence over target_size.
 *! @member int(1..4) "segments"
 *!  maximum number of segments to use.
 *! @member int(0..100) "sns_strength"
 *!   Spatial Noise Shaping. 0=off, 100=maximum.
 *! @member int(0..100) "filter_strength"
 *!  0=off
 *! @member int(0..7) "filter_sharpness"
 *!  0=off
 *! @member int(0..1) "filter_type"
 *!   For the type, 0=simple, 1=strong.
 *! @member bool autofilter
 *!   If true, automatically adjust the filter strengths
 *! @member int(0..1) "alpha_compression"
 *!  Select alpha channel encoding format. Currently supported are 0: No alpha and 1: WebP lossless
 *! @member int(0..2) "alpha_filtering"
 *!  Select alpha filtering method. 0: none, 1: fast, 2: best. Default if 1.
 *! @member int(0..100) "alpha_quality"
 *!  Select the base image quality for the alpha channel.
 *! @member int(1..10) "pass"
 *!   The number of entropy analysis passes. Defaults to 1.
 *! @member bool "show_compressed"
 *!
 *! @member bool "preprocessing"
 *!  If true, do preprocessing (segment-smooth)
 *! @member int(0..3) "partitions"
 *!  log2(number of token partitions). Default is set to 0 for easier
 *!  progressive decoding.
 *! @member int(0..100) "partition_limit"
 *!  quality degradation allowed to fit the 512k limit on prediction
 *!  modes coding (0: no degradation, 100: maximum possible
 *!  degradation).
 *! @member bool "emulate_jpeg_size"
 *!  If true, try to map the quality setting to generate similar sizes
 *!  when compared to jpeg.
 *! @member int "thread_level"
 *!   The maximum number of extra threads to use. Defaults to 0
 *! @member bool "low_memory"
 *!   Decrease memory usage at the cost of encoding speed
 *! @endmapping
 *!
 *! @returns
 *! Always returns the encoded image as a string or throws an error.
 *!
 */
#define f_cq__Image_WebP_encode_defined

#ifdef f_cq__Image_WebP_encode_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_cq__Image_WebP_encode_fun_num = 0;

#endif /* f_cq__Image_WebP_encode_fun_num_used */
DEFAULT_CMOD_STORAGE void f_cq__Image_WebP_encode(INT32 args) {
#line 424 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
struct object * i;
struct mapping * options;
#line 424 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
if(args < 1) wrong_number_of_args_error("encode",args,1);
#line 424 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
if(args > 2) wrong_number_of_args_error("encode",args,2);
#line 424 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_OBJECT) SIMPLE_ARG_TYPE_ERROR("encode",1,"Image.Image");
#line 424 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
debug_malloc_pass(i=Pike_sp[0-args].u.object);
if (args > 1 &&
    (TYPEOF(Pike_sp[1-args]) != PIKE_T_INT ||
     Pike_sp[1-args].u.integer)) {
#line 425 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
if(TYPEOF(Pike_sp[1-args]) != PIKE_T_MAPPING) SIMPLE_ARG_TYPE_ERROR("encode",2,"mapping(string:int|float|Image.Image)|void");
#line 425 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
debug_malloc_pass(options=Pike_sp[1-args].u.mapping);
#line 425 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
} else options = NULL;
{
unsigned char *result = NULL;
size_t size;
object *a;
int width = image_width( i );
int height = image_height( i );
unsigned char *iptr = image_ptr( i );
unsigned char *rgba = NULL;
Importer importer = WebPPictureImportRGB;
WebPConfig config;
WebPPreset preset;
if( !iptr || !width || !height )
{
Pike_error("Image argument is not a valid image.");
}

if( options )
{
if( (preset = (WebPPreset)parameter_int( options, "preset", 0 )) )
{
if( !WebPConfigPreset(&config, preset, 75.0) )
Pike_error("Failed to initialize config.\n");
}
else
{
if( !WebPConfigInit( &config ) )
Pike_error("Failed to initialize config.\n");
}

a = parameter_obj( options, "alpha" );

#define GET_ENUM(Y,X) (config.X = (Y)parameter_int( options, #X, config.X ));
#define GET_INT(X) (config.X = parameter_int( options, #X, config.X ));
#define GET_FLT(X) (config.X = parameter_float( options, #X, config.X ));
#define GET_BOL(X) (config.X = !!parameter_int( options, #X, config.X ));

#if WEBP_ENCODER_ABI_VERSION > 0x0200
 GET_BOL(lossless);
#else
 if( parameter_int( options, "lossless", 0 ) )
Pike_error("Your libwebp is too old to support lossless encoding.\n");
#endif
 GET_FLT(quality);
GET_INT(method);
#if WEBP_ENCODER_ABI_VERSION > 0x0200
 GET_ENUM(WebPImageHint,image_hint);
#endif
 GET_INT(target_size);
GET_FLT(target_PSNR);
GET_INT(segments);
GET_INT(sns_strength);
GET_INT(filter_strength);
GET_INT(filter_sharpness);
GET_INT(filter_type);
GET_INT(autofilter);

#if WEBP_ENCODER_ABI_VERSION > 0x0200
 GET_INT(alpha_compression);
GET_INT(alpha_filtering);
GET_INT(alpha_quality);
#endif
 GET_INT(pass);
GET_INT(show_compressed);
GET_INT(preprocessing);
GET_INT(partitions);
GET_INT(partition_limit);
#if WEBP_ENCODER_ABI_VERSION > 0x0200
 GET_BOL(emulate_jpeg_size);
GET_BOL(thread_level);
GET_BOL(low_memory);
#endif
#undef GET_BOL
#undef GET_FLT
#undef GET_INT
#undef GET_ENUM

#if WEBP_ENCODER_ABI_VERSION > 0x0200
 if( config.quality >= 100 )
{
config.quality = 70;
config.lossless = true;
}
#endif
 }
else
{
a = 0;
WebPConfigInit( &config );
}

if( a )
{
unsigned char *aptr = image_ptr( a );
int num = width*height;
unsigned char *dst;
importer = WebPPictureImportRGBA;

if( !aptr )
Pike_error("Alpha channels is not an image object\n");
#if WEBP_ENCODER_ABI_VERSION < 0x0201
 else 
Pike_error("Alpha channels are not supported by your libwebp.\n");
#endif
 if( image_width( a ) != width || image_height( a ) != height )
Pike_error("The alpha channel does not have the same size as the image\n");

dst = rgba = xalloc( num * 4 );

while( num-- )
{
*(dst++) = *(iptr++); /* r */
*(dst++) = *(iptr++); /* g */
*(dst++) = *(iptr++); /* b */
*(dst++) = *(aptr); /* a */
aptr += 3;
}
}

size = Encode( rgba ? rgba : iptr, width, height, width*(rgba?4:3), 
importer, &config, &result );

if( rgba ) free( rgba );

if( size == 0 )
Pike_error( (const char *)result );

push_string( make_shared_binary_string( (const char *)result, size ) );
free( result );
}

}

#undef cq__Image_WebP_gc_live_obj
#define cq__Image_WebP_gc_live_obj

#undef internal_exit_cq__Image_WebP_defined
#define internal_exit_cq__Image_WebP_defined

#undef cq__Image_WebP_event_handler_defined
#define cq__Image_WebP_event_handler_defined
static void exit_cq__Image_WebP_struct(void)
#line 556 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
{
if (img_program) {
free_program(img_program);
img_program = NULL;
}
}

/*
*! @decl constant PRESET_DEFAULT
*! @decl constant PRESET_PICTURE
*! @decl constant PRESET_PHOTO
*! @decl constant PRESET_DRAWING
*! @decl constant PRESET_ICON
*! @decl constant PRESET_TREXT
*!  Constants used to select the default values for the various encoding options in @[encode].
*!
*! @decl constant HINT_DEFAULT
*! @decl constant HINT_PICTURE
*! @decl constant HINT_PHOTO
*! @decl constant HINT_GRAPH
*!  Constants used to give hints to the lossless encoder when using @[encode].
*!  (selected automatically when using a hint.)
*/


#undef extra_cq__Image_WebP_defined
#define extra_cq__Image_WebP_defined
#line 597 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
#endif /* HAVE_LIBVPX */

/*! @endmodule
 *!
 *! @endmodule
 */


#ifdef cq__Image_WebP_event_handler_defined
static void cq__Image_WebP_event_handler(int ev) {
  switch(ev) {

#ifdef internal_exit_cq__Image_WebP_defined
  case PROG_EVENT_EXIT: exit_cq__Image_WebP_struct(); break;

#endif /* internal_exit_cq__Image_WebP_defined */
  default: break; 
  }
}

#endif /* cq__Image_WebP_event_handler_defined */

#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED
static int ___cmod_map_program_ids(int id)
{
  int i = 0;
  if( (id&0x7f000000) != 0x7f000000 ) return id;
  id = id&0x00ffffff;
  while(___cmod_ext_used[i].from ) {
   if( ___cmod_ext_used[i].from == id ) return ___cmod_ext_used[i].to;
   i++;
  }
  return 0;
}
#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */
PIKE_MODULE_INIT {

#ifdef module_strings_declared
module_strings[0] = 
  make_shared_binary_string("Image.Image",
                            CONSTANT_STRLEN("Image.Image"));
#endif

#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED
{ int i=0;
#ifndef tObjImpl_IMAGE_IMAGE
# define tObjImpl_IMAGE_IMAGE "\3\0\177\0\0\2"
{
   struct program *tmp = resolve_program(module_strings[0] /* "Image.Image" */);
   if( tmp ) {
      ___cmod_ext_used[i].from = 2;
      ___cmod_ext_used[i].to = tmp->id;
      i++;
   }
}
#endif /* tObjImpl_IMAGE_IMAGE */
}
set_program_id_to_id( ___cmod_map_program_ids );

#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */

#ifdef extra_cq__Image_WebP_defined
#line 580 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
{
#define CONST(X)  add_integer_constant( #X, WEBP_##X, 0 );
 CONST(PRESET_DEFAULT);
CONST(PRESET_PICTURE);
CONST(PRESET_PHOTO);
CONST(PRESET_DRAWING);
CONST(PRESET_ICON);
CONST(PRESET_TEXT);

#if WEBP_ENCODER_ABI_VERSION > 0x0200
 CONST(HINT_DEFAULT);
CONST(HINT_PICTURE);
CONST(HINT_PHOTO);
CONST(HINT_GRAPH);
#endif
#undef CONST
}

#endif /* extra_cq__Image_WebP_defined */

#ifdef cq__Image_WebP_event_handler_defined
  pike_set_prog_event_callback(cq__Image_WebP_event_handler);

#ifndef cq__Image_WebP_gc_live_obj
  Pike_compiler->new_program->flags &= ~PROGRAM_LIVE_OBJ;

#endif /* cq__Image_WebP_gc_live_obj */

#endif /* cq__Image_WebP_event_handler_defined */

#ifdef f_cq__Image_WebP_cq__decode_defined

#ifdef f_cq__Image_WebP_cq__decode_fun_num_used
  f_cq__Image_WebP_cq__decode_fun_num =
#endif /* f_cq__Image_WebP_cq__decode_fun_num_used */
#line 239 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
    ADD_FUNCTION2("_decode", f_cq__Image_WebP_cq__decode, tFunc(tStr,tMap(tStr,tOr(tName("Image.Image", tObjImpl_IMAGE_IMAGE),tStr))), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_cq__Image_WebP_cq__decode_defined */

#ifdef f_cq__Image_WebP_decode_defined

#ifdef f_cq__Image_WebP_decode_fun_num_used
  f_cq__Image_WebP_decode_fun_num =
#endif /* f_cq__Image_WebP_decode_fun_num_used */
#line 296 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
    ADD_FUNCTION2("decode", f_cq__Image_WebP_decode, tFunc(tStr,tName("Image.Image", tObjImpl_IMAGE_IMAGE)), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_cq__Image_WebP_decode_defined */

#ifdef f_cq__Image_WebP_encode_defined

#ifdef f_cq__Image_WebP_encode_fun_num_used
  f_cq__Image_WebP_encode_fun_num =
#endif /* f_cq__Image_WebP_encode_fun_num_used */
#line 424 "/Users/hww3/devel/pike/src/post_modules/_Image_WebP/image_webp.cmod"
    ADD_FUNCTION2("encode", f_cq__Image_WebP_encode, tFunc(tName("Image.Image", tObjImpl_IMAGE_IMAGE) tOr(tMap(tStr,tOr3("\10\200\0\0\0\177\377\377\377",tFloat,tName("Image.Image", tObjImpl_IMAGE_IMAGE))),tVoid),tStr8), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_cq__Image_WebP_encode_defined */

#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED
set_program_id_to_id( 0 );
#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */
}
PIKE_MODULE_EXIT {

#ifdef module_strings_declared
{
  int i;
  for(i=0; i < 1; i++) {
    if (module_strings[i]) free_string(module_strings[i]);
    module_strings[i] = NULL;
  }
}
#endif
}
