/* Generated by Cython 0.11.2 on Sat Nov  7 00:13:43 2009 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
#endif
#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
#endif
#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)

  typedef struct {
       void *buf;
       PyObject *obj;
       Py_ssize_t len;
       Py_ssize_t itemsize;
       int readonly;
       int ndim;
       char *format;
       Py_ssize_t *shape;
       Py_ssize_t *strides;
       Py_ssize_t *suboffsets;
       void *internal;
  } Py_buffer;

  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)

#endif
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif
#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyString_Type                PyBytes_Type
  #define PyString_CheckExact          PyBytes_CheckExact
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define PyBytes_Type                 PyString_Type
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func)
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#else
  #define _USE_MATH_DEFINES
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#include <math.h>
#define __PYX_HAVE_API___renpy
#include "renpy.h"
#define __PYX_USE_C99_COMPLEX defined(_Complex_I)


#ifdef __GNUC__
#define INLINE __inline__
#elif _WIN32
#define INLINE __inline
#else
#define INLINE 
#endif

typedef struct {PyObject **p; char *s; long n; char is_unicode; char intern; char is_identifier;} __Pyx_StringTabEntry; /*proto*/



static int __pyx_skip_dispatch = 0;


/* Type Conversion Predeclarations */

#if PY_MAJOR_VERSION < 3
#define __Pyx_PyBytes_FromString          PyString_FromString
#define __Pyx_PyBytes_FromStringAndSize   PyString_FromStringAndSize
#define __Pyx_PyBytes_AsString            PyString_AsString
#else
#define __Pyx_PyBytes_FromString          PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize   PyBytes_FromStringAndSize
#define __Pyx_PyBytes_AsString            PyBytes_AsString
#endif

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);

#if !defined(T_PYSSIZET)
#if PY_VERSION_HEX < 0x02050000
#define T_PYSSIZET T_INT
#elif !defined(T_LONGLONG)
#define T_PYSSIZET \
        ((sizeof(Py_ssize_t) == sizeof(int))  ? T_INT  : \
        ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : -1))
#else
#define T_PYSSIZET \
        ((sizeof(Py_ssize_t) == sizeof(int))          ? T_INT      : \
        ((sizeof(Py_ssize_t) == sizeof(long))         ? T_LONG     : \
        ((sizeof(Py_ssize_t) == sizeof(PY_LONG_LONG)) ? T_LONGLONG : -1)))
#endif
#endif

#if !defined(T_SIZET)
#if !defined(T_ULONGLONG)
#define T_SIZET \
        ((sizeof(size_t) == sizeof(unsigned int))  ? T_UINT  : \
        ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : -1))
#else
#define T_SIZET \
        ((sizeof(size_t) == sizeof(unsigned int))          ? T_UINT      : \
        ((sizeof(size_t) == sizeof(unsigned long))         ? T_ULONG     : \
        ((sizeof(size_t) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1)))
#endif
#endif

static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))


#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 ||               (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) 
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
    
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;
static const char **__pyx_f;


#ifdef CYTHON_REFNANNY
typedef struct {
  void (*INCREF)(void*, PyObject*, int);
  void (*DECREF)(void*, PyObject*, int);
  void (*GOTREF)(void*, PyObject*, int);
  void (*GIVEREF)(void*, PyObject*, int);
  void* (*NewContext)(const char*, int, const char*);
  void (*FinishContext)(void**);
} __Pyx_RefnannyAPIStruct;
static __Pyx_RefnannyAPIStruct *__Pyx_Refnanny = NULL;
#define __Pyx_ImportRefcountAPI(name)   (__Pyx_RefnannyAPIStruct *) PyCObject_Import((char *)name, (char *)"RefnannyAPI")
#define __Pyx_INCREF(r) __Pyx_Refnanny->INCREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_DECREF(r) __Pyx_Refnanny->DECREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_GOTREF(r) __Pyx_Refnanny->GOTREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (PyObject *)(r), __LINE__)
#define __Pyx_XDECREF(r) if((r) == NULL) ; else __Pyx_DECREF(r)
#define __Pyx_SetupRefcountContext(name)   void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__, __FILE__)
#define __Pyx_FinishRefcountContext()   __Pyx_Refnanny->FinishContext(&__pyx_refchk)
#else
#define __Pyx_INCREF(r) Py_INCREF(r)
#define __Pyx_DECREF(r) Py_DECREF(r)
#define __Pyx_GOTREF(r)
#define __Pyx_GIVEREF(r)
#define __Pyx_XDECREF(r) Py_XDECREF(r)
#define __Pyx_SetupRefcountContext(name)
#define __Pyx_FinishRefcountContext()
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) if((r) == NULL) ; else __Pyx_GIVEREF(r)
#define __Pyx_XGOTREF(r) if((r) == NULL) ; else __Pyx_GOTREF(r)

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name, PyObject* kw_name); /*proto*/

static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],     PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,     const char* function_name); /*proto*/


static INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}


#define __Pyx_GetItemInt_List(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_List_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
}

#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
}


#define __Pyx_GetItemInt(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    PyObject *r;
    if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) {
        r = PySequence_GetItem(o, i);
    }
    else {
        r = __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
    }
    return r;
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

static INLINE void __Pyx_RaiseTooManyValuesError(void);

static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/
static int __Pyx_EndUnpack(PyObject *); /*proto*/

static INLINE int __Pyx_StrEq(const char *, const char *); /*proto*/

static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static INLINE char __Pyx_PyInt_AsChar(PyObject *);

static INLINE short __Pyx_PyInt_AsShort(PyObject *);

static INLINE int __Pyx_PyInt_AsInt(PyObject *);

static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static INLINE long __Pyx_PyInt_AsLong(PyObject *);

static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

static void __Pyx_AddTraceback(const char *funcname); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/

/* Type declarations */
/* Module declarations from _renpy */

static PyObject *__pyx_k_20 = 0;
static PyObject *__pyx_k_21 = 0;
static PyObject *__pyx_k_22 = 0;
static PyObject *__pyx_k_23 = 0;
static PyObject *__pyx_k_24 = 0;
#define __Pyx_MODULE_NAME "_renpy"
int __pyx_module_is_main__renpy = 0;

/* Implementation of _renpy */
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_int_6;
static PyObject *__pyx_int_10;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_24;
static PyObject *__pyx_int_32;
static PyObject *__pyx_int_3;
static PyObject *__pyx_int_4;
static char __pyx_k___main__[] = "__main__";
static PyObject *__pyx_kp___main__;
static char __pyx_k_surf[] = "surf";
static PyObject *__pyx_kp_surf;
static char __pyx_k_file[] = "file";
static PyObject *__pyx_kp_file;
static char __pyx_k_compress[] = "compress";
static PyObject *__pyx_kp_compress;
static char __pyx_k_pysrc[] = "pysrc";
static PyObject *__pyx_kp_pysrc;
static char __pyx_k_pydst[] = "pydst";
static PyObject *__pyx_kp_pydst;
static char __pyx_k_avgwidth[] = "avgwidth";
static PyObject *__pyx_kp_avgwidth;
static char __pyx_k_avgheight[] = "avgheight";
static PyObject *__pyx_kp_avgheight;
static char __pyx_k_outwidth[] = "outwidth";
static PyObject *__pyx_kp_outwidth;
static char __pyx_k_outheight[] = "outheight";
static PyObject *__pyx_kp_outheight;
static char __pyx_k_r[] = "r";
static PyObject *__pyx_kp_r;
static char __pyx_k_g[] = "g";
static PyObject *__pyx_kp_g;
static char __pyx_k_b[] = "b";
static PyObject *__pyx_kp_b;
static char __pyx_k_a[] = "a";
static PyObject *__pyx_kp_a;
static char __pyx_k_srcchan[] = "srcchan";
static PyObject *__pyx_kp_srcchan;
static char __pyx_k_dstchan[] = "dstchan";
static PyObject *__pyx_kp_dstchan;
static char __pyx_k_amap[] = "amap";
static PyObject *__pyx_kp_amap;
static char __pyx_k_source_xoff[] = "source_xoff";
static PyObject *__pyx_kp_source_xoff;
static char __pyx_k_source_yoff[] = "source_yoff";
static PyObject *__pyx_kp_source_yoff;
static char __pyx_k_source_width[] = "source_width";
static PyObject *__pyx_kp_source_width;
static char __pyx_k_source_height[] = "source_height";
static PyObject *__pyx_kp_source_height;
static char __pyx_k_dest_xoff[] = "dest_xoff";
static PyObject *__pyx_kp_dest_xoff;
static char __pyx_k_dest_yoff[] = "dest_yoff";
static PyObject *__pyx_kp_dest_yoff;
static char __pyx_k_dest_width[] = "dest_width";
static PyObject *__pyx_kp_dest_width;
static char __pyx_k_dest_height[] = "dest_height";
static PyObject *__pyx_kp_dest_height;
static char __pyx_k_corner_x[] = "corner_x";
static PyObject *__pyx_kp_corner_x;
static char __pyx_k_corner_y[] = "corner_y";
static PyObject *__pyx_kp_corner_y;
static char __pyx_k_xdx[] = "xdx";
static PyObject *__pyx_kp_xdx;
static char __pyx_k_ydx[] = "ydx";
static PyObject *__pyx_kp_ydx;
static char __pyx_k_xdy[] = "xdy";
static PyObject *__pyx_kp_xdy;
static char __pyx_k_ydy[] = "ydy";
static PyObject *__pyx_kp_ydy;
static char __pyx_k_pysrca[] = "pysrca";
static PyObject *__pyx_kp_pysrca;
static char __pyx_k_pysrcb[] = "pysrcb";
static PyObject *__pyx_kp_pysrcb;
static char __pyx_k_alpha[] = "alpha";
static PyObject *__pyx_kp_alpha;
static char __pyx_k_pyimg[] = "pyimg";
static PyObject *__pyx_kp_pyimg;
static char __pyx_k_aoff[] = "aoff";
static PyObject *__pyx_kp_aoff;
static char __pyx_k_c00[] = "c00";
static PyObject *__pyx_kp_c00;
static char __pyx_k_1[] = "c01";
static PyObject *__pyx_kp_1;
static char __pyx_k_2[] = "c02";
static PyObject *__pyx_kp_2;
static char __pyx_k_3[] = "c03";
static PyObject *__pyx_kp_3;
static char __pyx_k_4[] = "c04";
static PyObject *__pyx_kp_4;
static char __pyx_k_5[] = "c10";
static PyObject *__pyx_kp_5;
static char __pyx_k_6[] = "c11";
static PyObject *__pyx_kp_6;
static char __pyx_k_7[] = "c12";
static PyObject *__pyx_kp_7;
static char __pyx_k_8[] = "c13";
static PyObject *__pyx_kp_8;
static char __pyx_k_9[] = "c14";
static PyObject *__pyx_kp_9;
static char __pyx_k_10[] = "c20";
static PyObject *__pyx_kp_10;
static char __pyx_k_11[] = "c21";
static PyObject *__pyx_kp_11;
static char __pyx_k_12[] = "c22";
static PyObject *__pyx_kp_12;
static char __pyx_k_13[] = "c23";
static PyObject *__pyx_kp_13;
static char __pyx_k_14[] = "c24";
static PyObject *__pyx_kp_14;
static char __pyx_k_15[] = "c30";
static PyObject *__pyx_kp_15;
static char __pyx_k_16[] = "c31";
static PyObject *__pyx_kp_16;
static char __pyx_k_17[] = "c32";
static PyObject *__pyx_kp_17;
static char __pyx_k_18[] = "c33";
static PyObject *__pyx_kp_18;
static char __pyx_k_19[] = "c34";
static PyObject *__pyx_kp_19;
static char __pyx_k_rmul[] = "rmul";
static PyObject *__pyx_kp_rmul;
static char __pyx_k_gmul[] = "gmul";
static PyObject *__pyx_kp_gmul;
static char __pyx_k_bmul[] = "bmul";
static PyObject *__pyx_kp_bmul;
static char __pyx_k_amul[] = "amul";
static PyObject *__pyx_kp_amul;
static char __pyx_k_shift[] = "shift";
static PyObject *__pyx_kp_shift;
static char __pyx_k_vmap[] = "vmap";
static PyObject *__pyx_kp_vmap;
static char __pyx_k_xoffset[] = "xoffset";
static PyObject *__pyx_kp_xoffset;
static char __pyx_k_yoffset[] = "yoffset";
static PyObject *__pyx_kp_yoffset;
static char __pyx_k_pygame[] = "pygame";
static PyObject *__pyx_kp_pygame;
static char __pyx_k_Surface[] = "Surface";
static PyObject *__pyx_kp_Surface;
static char __pyx_k_PygameSurface[] = "PygameSurface";
static PyObject *__pyx_kp_PygameSurface;
static char __pyx_k_Exception[] = "Exception";
static PyObject *__pyx_kp_Exception;
static char __pyx_k_get_bitsize[] = "get_bitsize";
static PyObject *__pyx_kp_get_bitsize;
static char __pyx_k_get_size[] = "get_size";
static PyObject *__pyx_kp_get_size;
static char __pyx_k_check[] = "check";
static PyObject *__pyx_kp_check;
static char __pyx_k_get_shifts[] = "get_shifts";
static PyObject *__pyx_kp_get_shifts;
static char __pyx_k_blit[] = "blit";
static PyObject *__pyx_kp_blit;
static PyObject *__pyx_builtin_Exception;
static PyObject *__pyx_kp_25;
static char __pyx_k_25[] = "save_png requires a pygame Surface as its first argument.";
static PyObject *__pyx_kp_26;
static PyObject *__pyx_kp_27;
static PyObject *__pyx_kp_28;
static PyObject *__pyx_kp_29;
static char __pyx_k_26[] = "pixellate requires a pygame Surface as its first argument.";
static char __pyx_k_27[] = "pixellate requires a pygame Surface as its second argument.";
static char __pyx_k_28[] = "pixellate requires a 24 or 32 bit surface.";
static char __pyx_k_29[] = "pixellate requires both surfaces have the same bitsize.";
static PyObject *__pyx_kp_30;
static PyObject *__pyx_kp_31;
static PyObject *__pyx_kp_32;
static PyObject *__pyx_kp_33;
static PyObject *__pyx_kp_34;
static char __pyx_k_30[] = "map requires a pygame Surface as its first argument.";
static char __pyx_k_31[] = "map requires a pygame Surface as its second argument.";
static char __pyx_k_32[] = "map requires a 24 or 32 bit surface.";
static char __pyx_k_33[] = "map requires both surfaces have the same bitsize.";
static char __pyx_k_34[] = "map requires both surfaces have the same size.";
static PyObject *__pyx_kp_35;
static PyObject *__pyx_kp_36;
static PyObject *__pyx_kp_37;
static PyObject *__pyx_kp_38;
static PyObject *__pyx_kp_39;
static char __pyx_k_35[] = "map requires a pygame Surface as its first argument.";
static char __pyx_k_36[] = "map requires a pygame Surface as its second argument.";
static char __pyx_k_37[] = "map requires a 24 or 32 bit surface.";
static char __pyx_k_38[] = "map requires both surfaces have the same bitsize.";
static char __pyx_k_39[] = "map requires both surfaces have the same size.";
static PyObject *__pyx_kp_40;
static PyObject *__pyx_kp_41;
static PyObject *__pyx_kp_42;
static PyObject *__pyx_kp_43;
static PyObject *__pyx_kp_44;
static char __pyx_k_40[] = "alpha_munge requires a pygame Surface as its first argument.";
static char __pyx_k_41[] = "alpha_munge requires a pygame Surface as its second argument.";
static char __pyx_k_42[] = "alpha_munge requires a 24 or 32 bit surface.";
static char __pyx_k_43[] = "alpha_munge requires both surfaces have the same bitsize.";
static char __pyx_k_44[] = "alpha_munge requires both surfaces have the same size.";
static PyObject *__pyx_kp_45;
static PyObject *__pyx_kp_46;
static PyObject *__pyx_kp_47;
static PyObject *__pyx_kp_48;
static char __pyx_k_45[] = "bilinear requires a pygame Surface as its first argument.";
static char __pyx_k_46[] = "bilinear requires a pygame Surface as its second argument.";
static char __pyx_k_47[] = "bilinear requires a 24 or 32 bit surface.";
static char __pyx_k_48[] = "bilinear requires both surfaces have the same bitsize.";
static PyObject *__pyx_kp_49;
static PyObject *__pyx_kp_50;
static char __pyx_k_49[] = "Surface must be a pygame surface.";
static char __pyx_k_50[] = "Surface must be 32-bit.";

/* "/home/tom/ab/renpy/module/_renpy.pyx":97
 * PygameSurface = pygame.Surface
 * 
 * def version():             # <<<<<<<<<<<<<<
 *     return (6, 10, 0)
 * 
 */

static PyObject *__pyx_pf_6_renpy_version(PyObject *__pyx_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6_renpy_version(PyObject *__pyx_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  __Pyx_SetupRefcountContext("version");
  __pyx_self = __pyx_self;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":98
 * 
 * def version():
 *     return (6, 10, 0)             # <<<<<<<<<<<<<<
 * 
 * def save_png(surf, file, compress=-1):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_int_6);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_6);
  __Pyx_GIVEREF(__pyx_int_6);
  __Pyx_INCREF(__pyx_int_10);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_10);
  __Pyx_GIVEREF(__pyx_int_10);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_renpy.version");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":100
 *     return (6, 10, 0)
 * 
 * def save_png(surf, file, compress=-1):             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(surf, PygameSurface):
 */

static PyObject *__pyx_pf_6_renpy_save_png(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6_renpy_save_png(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_surf = 0;
  PyObject *__pyx_v_file = 0;
  PyObject *__pyx_v_compress = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_surf,&__pyx_kp_file,&__pyx_kp_compress,0};
  __Pyx_SetupRefcountContext("save_png");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[2] = __pyx_int_neg_1;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_surf);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_file);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("save_png", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_compress);
        if (unlikely(value)) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "save_png") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_surf = values[0];
    __pyx_v_file = values[1];
    __pyx_v_compress = values[2];
  } else {
    __pyx_v_compress = __pyx_int_neg_1;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3:
      __pyx_v_compress = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2:
      __pyx_v_file = PyTuple_GET_ITEM(__pyx_args, 1);
      __pyx_v_surf = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("save_png", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy.save_png");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":102
 * def save_png(surf, file, compress=-1):
 * 
 *     if not isinstance(surf, PygameSurface):             # <<<<<<<<<<<<<<
 *         raise Exception("save_png requires a pygame Surface as its first argument.")
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_PygameSurface); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyObject_IsInstance(__pyx_v_surf, __pyx_1); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":103
 * 
 *     if not isinstance(surf, PygameSurface):
 *         raise Exception("save_png requires a pygame Surface as its first argument.")             # <<<<<<<<<<<<<<
 * 
 *     save_png_core(surf, RWopsFromPython(file), compress)
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_25);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_25);
    __Pyx_GIVEREF(__pyx_kp_25);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":105
 *         raise Exception("save_png requires a pygame Surface as its first argument.")
 * 
 *     save_png_core(surf, RWopsFromPython(file), compress)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_v_compress); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  save_png_core(__pyx_v_surf, RWopsFromPython(__pyx_v_file), __pyx_t_5);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("_renpy.save_png");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":108
 * 
 * 
 * def pixellate(pysrc, pydst, avgwidth, avgheight, outwidth, outheight):             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(pysrc, PygameSurface):
 */

static PyObject *__pyx_pf_6_renpy_pixellate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6_renpy_pixellate(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysrc = 0;
  PyObject *__pyx_v_pydst = 0;
  PyObject *__pyx_v_avgwidth = 0;
  PyObject *__pyx_v_avgheight = 0;
  PyObject *__pyx_v_outwidth = 0;
  PyObject *__pyx_v_outheight = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_pysrc,&__pyx_kp_pydst,&__pyx_kp_avgwidth,&__pyx_kp_avgheight,&__pyx_kp_outwidth,&__pyx_kp_outheight,0};
  __Pyx_SetupRefcountContext("pixellate");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[6] = {0,0,0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrc);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pydst);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("pixellate", 1, 6, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_kp_avgwidth);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("pixellate", 1, 6, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_kp_avgheight);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("pixellate", 1, 6, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  4:
      values[4] = PyDict_GetItem(__pyx_kwds, __pyx_kp_outwidth);
      if (likely(values[4])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("pixellate", 1, 6, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  5:
      values[5] = PyDict_GetItem(__pyx_kwds, __pyx_kp_outheight);
      if (likely(values[5])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("pixellate", 1, 6, 6, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pixellate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysrc = values[0];
    __pyx_v_pydst = values[1];
    __pyx_v_avgwidth = values[2];
    __pyx_v_avgheight = values[3];
    __pyx_v_outwidth = values[4];
    __pyx_v_outheight = values[5];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 6) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_pysrc = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_pydst = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_avgwidth = PyTuple_GET_ITEM(__pyx_args, 2);
    __pyx_v_avgheight = PyTuple_GET_ITEM(__pyx_args, 3);
    __pyx_v_outwidth = PyTuple_GET_ITEM(__pyx_args, 4);
    __pyx_v_outheight = PyTuple_GET_ITEM(__pyx_args, 5);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("pixellate", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy.pixellate");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":110
 * def pixellate(pysrc, pydst, avgwidth, avgheight, outwidth, outheight):
 * 
 *     if not isinstance(pysrc, PygameSurface):             # <<<<<<<<<<<<<<
 *         raise Exception("pixellate requires a pygame Surface as its first argument.")
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_PygameSurface); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyObject_IsInstance(__pyx_v_pysrc, __pyx_1); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":111
 * 
 *     if not isinstance(pysrc, PygameSurface):
 *         raise Exception("pixellate requires a pygame Surface as its first argument.")             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(pydst, PygameSurface):
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_26);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_26);
    __Pyx_GIVEREF(__pyx_kp_26);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":113
 *         raise Exception("pixellate requires a pygame Surface as its first argument.")
 * 
 *     if not isinstance(pydst, PygameSurface):             # <<<<<<<<<<<<<<
 *         raise Exception("pixellate requires a pygame Surface as its second argument.")
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_PygameSurface); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_2 = PyObject_IsInstance(__pyx_v_pydst, __pyx_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_1 = (!__pyx_t_2);
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":114
 * 
 *     if not isinstance(pydst, PygameSurface):
 *         raise Exception("pixellate requires a pygame Surface as its second argument.")             # <<<<<<<<<<<<<<
 * 
 *     if pysrc.get_bitsize() not in (24, 32):
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_27);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_27);
    __Pyx_GIVEREF(__pyx_kp_27);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":116
 *         raise Exception("pixellate requires a pygame Surface as its second argument.")
 * 
 *     if pysrc.get_bitsize() not in (24, 32):             # <<<<<<<<<<<<<<
 *         raise Exception("pixellate requires a 24 or 32 bit surface.")
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_int_24, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (((int)__pyx_t_1)) {
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_int_32, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = ((int)__pyx_t_2);
  } else {
    __pyx_t_5 = ((int)__pyx_t_1);
  }
  __pyx_t_1 = __pyx_t_5;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":117
 * 
 *     if pysrc.get_bitsize() not in (24, 32):
 *         raise Exception("pixellate requires a 24 or 32 bit surface.")             # <<<<<<<<<<<<<<
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_28);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_28);
    __Pyx_GIVEREF(__pyx_kp_28);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":119
 *         raise Exception("pixellate requires a 24 or 32 bit surface.")
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():             # <<<<<<<<<<<<<<
 *         raise Exception("pixellate requires both surfaces have the same bitsize.")
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pydst, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":120
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():
 *         raise Exception("pixellate requires both surfaces have the same bitsize.")             # <<<<<<<<<<<<<<
 * 
 *     # pysrc.lock()
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_29);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_29);
    __Pyx_GIVEREF(__pyx_kp_29);
    __pyx_t_6 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_6, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":125
 *     # pydst.lock()
 * 
 *     if pysrc.get_bitsize() == 32:             # <<<<<<<<<<<<<<
 *         pixellate32_core(pysrc, pydst, avgwidth, avgheight, outwidth, outheight)
 *     else:
 */
  __pyx_t_6 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_3, __pyx_int_32, Py_EQ); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":126
 * 
 *     if pysrc.get_bitsize() == 32:
 *         pixellate32_core(pysrc, pydst, avgwidth, avgheight, outwidth, outheight)             # <<<<<<<<<<<<<<
 *     else:
 *         pixellate24_core(pysrc, pydst, avgwidth, avgheight, outwidth, outheight)
 */
    __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_v_avgwidth); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_v_avgheight); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_v_outwidth); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_v_outheight); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    pixellate32_core(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_7, __pyx_t_8, __pyx_t_9, __pyx_t_10);
    goto __pyx_L10;
  }
  /*else*/ {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":128
 *         pixellate32_core(pysrc, pydst, avgwidth, avgheight, outwidth, outheight)
 *     else:
 *         pixellate24_core(pysrc, pydst, avgwidth, avgheight, outwidth, outheight)             # <<<<<<<<<<<<<<
 * 
 *     # pydst.unlock()
 */
    __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_v_avgwidth); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_v_avgheight); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_v_outwidth); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_v_outheight); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    pixellate24_core(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_10, __pyx_t_9, __pyx_t_8, __pyx_t_7);
  }
  __pyx_L10:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_renpy.pixellate");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":138
 * # The mapping between byte and color/alpha varies from system to
 * # system, and needs to be determined at a higher level.
 * def map(pysrc, pydst, r, g, b, a):             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(pysrc, PygameSurface):
 */

static PyObject *__pyx_pf_6_renpy_map(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6_renpy_map(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysrc = 0;
  PyObject *__pyx_v_pydst = 0;
  PyObject *__pyx_v_r = 0;
  PyObject *__pyx_v_g = 0;
  PyObject *__pyx_v_b = 0;
  PyObject *__pyx_v_a = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  char *__pyx_t_7;
  char *__pyx_t_8;
  char *__pyx_t_9;
  char *__pyx_t_10;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_pysrc,&__pyx_kp_pydst,&__pyx_kp_r,&__pyx_kp_g,&__pyx_kp_b,&__pyx_kp_a,0};
  __Pyx_SetupRefcountContext("map");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[6] = {0,0,0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrc);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pydst);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("map", 1, 6, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_kp_r);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("map", 1, 6, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_kp_g);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("map", 1, 6, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  4:
      values[4] = PyDict_GetItem(__pyx_kwds, __pyx_kp_b);
      if (likely(values[4])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("map", 1, 6, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  5:
      values[5] = PyDict_GetItem(__pyx_kwds, __pyx_kp_a);
      if (likely(values[5])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("map", 1, 6, 6, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "map") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysrc = values[0];
    __pyx_v_pydst = values[1];
    __pyx_v_r = values[2];
    __pyx_v_g = values[3];
    __pyx_v_b = values[4];
    __pyx_v_a = values[5];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 6) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_pysrc = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_pydst = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_r = PyTuple_GET_ITEM(__pyx_args, 2);
    __pyx_v_g = PyTuple_GET_ITEM(__pyx_args, 3);
    __pyx_v_b = PyTuple_GET_ITEM(__pyx_args, 4);
    __pyx_v_a = PyTuple_GET_ITEM(__pyx_args, 5);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("map", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy.map");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":140
 * def map(pysrc, pydst, r, g, b, a):
 * 
 *     if not isinstance(pysrc, PygameSurface):             # <<<<<<<<<<<<<<
 *         raise Exception("map requires a pygame Surface as its first argument.")
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_PygameSurface); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyObject_IsInstance(__pyx_v_pysrc, __pyx_1); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":141
 * 
 *     if not isinstance(pysrc, PygameSurface):
 *         raise Exception("map requires a pygame Surface as its first argument.")             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(pydst, PygameSurface):
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_30);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_30);
    __Pyx_GIVEREF(__pyx_kp_30);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":143
 *         raise Exception("map requires a pygame Surface as its first argument.")
 * 
 *     if not isinstance(pydst, PygameSurface):             # <<<<<<<<<<<<<<
 *         raise Exception("map requires a pygame Surface as its second argument.")
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_PygameSurface); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_2 = PyObject_IsInstance(__pyx_v_pydst, __pyx_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_1 = (!__pyx_t_2);
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":144
 * 
 *     if not isinstance(pydst, PygameSurface):
 *         raise Exception("map requires a pygame Surface as its second argument.")             # <<<<<<<<<<<<<<
 * 
 *     if pysrc.get_bitsize() not in (24, 32):
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_31);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_31);
    __Pyx_GIVEREF(__pyx_kp_31);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":146
 *         raise Exception("map requires a pygame Surface as its second argument.")
 * 
 *     if pysrc.get_bitsize() not in (24, 32):             # <<<<<<<<<<<<<<
 *         raise Exception("map requires a 24 or 32 bit surface.")
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_int_24, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (((int)__pyx_t_1)) {
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_int_32, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = ((int)__pyx_t_2);
  } else {
    __pyx_t_5 = ((int)__pyx_t_1);
  }
  __pyx_t_1 = __pyx_t_5;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":147
 * 
 *     if pysrc.get_bitsize() not in (24, 32):
 *         raise Exception("map requires a 24 or 32 bit surface.")             # <<<<<<<<<<<<<<
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_32);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_32);
    __Pyx_GIVEREF(__pyx_kp_32);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":149
 *         raise Exception("map requires a 24 or 32 bit surface.")
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():             # <<<<<<<<<<<<<<
 *         raise Exception("map requires both surfaces have the same bitsize.")
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pydst, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":150
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():
 *         raise Exception("map requires both surfaces have the same bitsize.")             # <<<<<<<<<<<<<<
 * 
 *     if pydst.get_size() != pysrc.get_size():
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_33);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_33);
    __Pyx_GIVEREF(__pyx_kp_33);
    __pyx_t_6 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_6, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":152
 *         raise Exception("map requires both surfaces have the same bitsize.")
 * 
 *     if pydst.get_size() != pysrc.get_size():             # <<<<<<<<<<<<<<
 *         raise Exception("map requires both surfaces have the same size.")
 * 
 */
  __pyx_t_6 = PyObject_GetAttr(__pyx_v_pydst, __pyx_kp_get_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_NE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":153
 * 
 *     if pydst.get_size() != pysrc.get_size():
 *         raise Exception("map requires both surfaces have the same size.")             # <<<<<<<<<<<<<<
 * 
 *     # pysrc.lock()
 */
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
    __Pyx_INCREF(__pyx_kp_34);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_kp_34);
    __Pyx_GIVEREF(__pyx_kp_34);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":158
 *     # pydst.lock()
 * 
 *     if pysrc.get_bitsize() == 32:             # <<<<<<<<<<<<<<
 *         map32_core(pysrc, pydst, r, g, b, a)
 *     else:
 */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_int_32, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":159
 * 
 *     if pysrc.get_bitsize() == 32:
 *         map32_core(pysrc, pydst, r, g, b, a)             # <<<<<<<<<<<<<<
 *     else:
 *         map24_core(pysrc, pydst, r, g, b)
 */
    __pyx_t_7 = __Pyx_PyBytes_AsString(__pyx_v_r); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = __Pyx_PyBytes_AsString(__pyx_v_g); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = __Pyx_PyBytes_AsString(__pyx_v_b); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_10 = __Pyx_PyBytes_AsString(__pyx_v_a); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    map32_core(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_7, __pyx_t_8, __pyx_t_9, __pyx_t_10);
    goto __pyx_L11;
  }
  /*else*/ {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":161
 *         map32_core(pysrc, pydst, r, g, b, a)
 *     else:
 *         map24_core(pysrc, pydst, r, g, b)             # <<<<<<<<<<<<<<
 * 
 *     # pydst.unlock()
 */
    __pyx_t_10 = __Pyx_PyBytes_AsString(__pyx_v_r); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = __Pyx_PyBytes_AsString(__pyx_v_g); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = __Pyx_PyBytes_AsString(__pyx_v_b); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    map24_core(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_10, __pyx_t_9, __pyx_t_8);
  }
  __pyx_L11:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_renpy.map");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":170
 * # The mapping between byte and color/alpha varies from system to
 * # system, and needs to be determined at a higher level.
 * def linmap(pysrc, pydst, r, g, b, a):             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(pysrc, PygameSurface):
 */

static PyObject *__pyx_pf_6_renpy_linmap(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6_renpy_linmap(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysrc = 0;
  PyObject *__pyx_v_pydst = 0;
  PyObject *__pyx_v_r = 0;
  PyObject *__pyx_v_g = 0;
  PyObject *__pyx_v_b = 0;
  PyObject *__pyx_v_a = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_pysrc,&__pyx_kp_pydst,&__pyx_kp_r,&__pyx_kp_g,&__pyx_kp_b,&__pyx_kp_a,0};
  __Pyx_SetupRefcountContext("linmap");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[6] = {0,0,0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrc);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pydst);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("linmap", 1, 6, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_kp_r);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("linmap", 1, 6, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_kp_g);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("linmap", 1, 6, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  4:
      values[4] = PyDict_GetItem(__pyx_kwds, __pyx_kp_b);
      if (likely(values[4])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("linmap", 1, 6, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  5:
      values[5] = PyDict_GetItem(__pyx_kwds, __pyx_kp_a);
      if (likely(values[5])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("linmap", 1, 6, 6, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "linmap") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysrc = values[0];
    __pyx_v_pydst = values[1];
    __pyx_v_r = values[2];
    __pyx_v_g = values[3];
    __pyx_v_b = values[4];
    __pyx_v_a = values[5];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 6) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_pysrc = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_pydst = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_r = PyTuple_GET_ITEM(__pyx_args, 2);
    __pyx_v_g = PyTuple_GET_ITEM(__pyx_args, 3);
    __pyx_v_b = PyTuple_GET_ITEM(__pyx_args, 4);
    __pyx_v_a = PyTuple_GET_ITEM(__pyx_args, 5);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("linmap", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy.linmap");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":172
 * def linmap(pysrc, pydst, r, g, b, a):
 * 
 *     if not isinstance(pysrc, PygameSurface):             # <<<<<<<<<<<<<<
 *         raise Exception("map requires a pygame Surface as its first argument.")
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_PygameSurface); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyObject_IsInstance(__pyx_v_pysrc, __pyx_1); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":173
 * 
 *     if not isinstance(pysrc, PygameSurface):
 *         raise Exception("map requires a pygame Surface as its first argument.")             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(pydst, PygameSurface):
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_35);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_35);
    __Pyx_GIVEREF(__pyx_kp_35);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":175
 *         raise Exception("map requires a pygame Surface as its first argument.")
 * 
 *     if not isinstance(pydst, PygameSurface):             # <<<<<<<<<<<<<<
 *         raise Exception("map requires a pygame Surface as its second argument.")
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_PygameSurface); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_2 = PyObject_IsInstance(__pyx_v_pydst, __pyx_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_1 = (!__pyx_t_2);
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":176
 * 
 *     if not isinstance(pydst, PygameSurface):
 *         raise Exception("map requires a pygame Surface as its second argument.")             # <<<<<<<<<<<<<<
 * 
 *     if pysrc.get_bitsize() not in (24, 32):
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_36);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_36);
    __Pyx_GIVEREF(__pyx_kp_36);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":178
 *         raise Exception("map requires a pygame Surface as its second argument.")
 * 
 *     if pysrc.get_bitsize() not in (24, 32):             # <<<<<<<<<<<<<<
 *         raise Exception("map requires a 24 or 32 bit surface.")
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_int_24, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (((int)__pyx_t_1)) {
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_int_32, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = ((int)__pyx_t_2);
  } else {
    __pyx_t_5 = ((int)__pyx_t_1);
  }
  __pyx_t_1 = __pyx_t_5;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":179
 * 
 *     if pysrc.get_bitsize() not in (24, 32):
 *         raise Exception("map requires a 24 or 32 bit surface.")             # <<<<<<<<<<<<<<
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_37);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_37);
    __Pyx_GIVEREF(__pyx_kp_37);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":181
 *         raise Exception("map requires a 24 or 32 bit surface.")
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():             # <<<<<<<<<<<<<<
 *         raise Exception("map requires both surfaces have the same bitsize.")
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pydst, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":182
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():
 *         raise Exception("map requires both surfaces have the same bitsize.")             # <<<<<<<<<<<<<<
 * 
 *     if pydst.get_size() != pysrc.get_size():
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_38);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_38);
    __Pyx_GIVEREF(__pyx_kp_38);
    __pyx_t_6 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_6, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":184
 *         raise Exception("map requires both surfaces have the same bitsize.")
 * 
 *     if pydst.get_size() != pysrc.get_size():             # <<<<<<<<<<<<<<
 *         raise Exception("map requires both surfaces have the same size.")
 * 
 */
  __pyx_t_6 = PyObject_GetAttr(__pyx_v_pydst, __pyx_kp_get_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_NE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":185
 * 
 *     if pydst.get_size() != pysrc.get_size():
 *         raise Exception("map requires both surfaces have the same size.")             # <<<<<<<<<<<<<<
 * 
 *     # pysrc.lock()
 */
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
    __Pyx_INCREF(__pyx_kp_39);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_kp_39);
    __Pyx_GIVEREF(__pyx_kp_39);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":190
 *     # pydst.lock()
 * 
 *     if pysrc.get_bitsize() == 32:             # <<<<<<<<<<<<<<
 *         linmap32_core(pysrc, pydst, r, g, b, a)
 *     else:
 */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_int_32, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":191
 * 
 *     if pysrc.get_bitsize() == 32:
 *         linmap32_core(pysrc, pydst, r, g, b, a)             # <<<<<<<<<<<<<<
 *     else:
 *         linmap24_core(pysrc, pydst, r, g, b)
 */
    __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_v_r); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_v_g); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_v_b); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_v_a); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    linmap32_core(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_7, __pyx_t_8, __pyx_t_9, __pyx_t_10);
    goto __pyx_L11;
  }
  /*else*/ {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":193
 *         linmap32_core(pysrc, pydst, r, g, b, a)
 *     else:
 *         linmap24_core(pysrc, pydst, r, g, b)             # <<<<<<<<<<<<<<
 * 
 *     # pydst.unlock()
 */
    __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_v_r); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_v_g); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_v_b); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    linmap24_core(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_10, __pyx_t_9, __pyx_t_8);
  }
  __pyx_L11:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_renpy.linmap");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":199
 * 
 * 
 * def alpha_munge(pysrc, pydst, srcchan, dstchan, amap):             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(pysrc, PygameSurface):
 */

static PyObject *__pyx_pf_6_renpy_alpha_munge(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6_renpy_alpha_munge(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysrc = 0;
  PyObject *__pyx_v_pydst = 0;
  PyObject *__pyx_v_srcchan = 0;
  PyObject *__pyx_v_dstchan = 0;
  PyObject *__pyx_v_amap = 0;
  PyObject *__pyx_v_bytes;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  char *__pyx_t_10;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_pysrc,&__pyx_kp_pydst,&__pyx_kp_srcchan,&__pyx_kp_dstchan,&__pyx_kp_amap,0};
  __Pyx_SetupRefcountContext("alpha_munge");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[5] = {0,0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrc);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pydst);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("alpha_munge", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_kp_srcchan);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("alpha_munge", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_kp_dstchan);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("alpha_munge", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  4:
      values[4] = PyDict_GetItem(__pyx_kwds, __pyx_kp_amap);
      if (likely(values[4])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("alpha_munge", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "alpha_munge") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysrc = values[0];
    __pyx_v_pydst = values[1];
    __pyx_v_srcchan = values[2];
    __pyx_v_dstchan = values[3];
    __pyx_v_amap = values[4];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_pysrc = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_pydst = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_srcchan = PyTuple_GET_ITEM(__pyx_args, 2);
    __pyx_v_dstchan = PyTuple_GET_ITEM(__pyx_args, 3);
    __pyx_v_amap = PyTuple_GET_ITEM(__pyx_args, 4);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("alpha_munge", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy.alpha_munge");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_bytes = Py_None; __Pyx_INCREF(Py_None);

  /* "/home/tom/ab/renpy/module/_renpy.pyx":201
 * def alpha_munge(pysrc, pydst, srcchan, dstchan, amap):
 * 
 *     if not isinstance(pysrc, PygameSurface):             # <<<<<<<<<<<<<<
 *         raise Exception("alpha_munge requires a pygame Surface as its first argument.")
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_PygameSurface); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyObject_IsInstance(__pyx_v_pysrc, __pyx_1); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":202
 * 
 *     if not isinstance(pysrc, PygameSurface):
 *         raise Exception("alpha_munge requires a pygame Surface as its first argument.")             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(pydst, PygameSurface):
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_40);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_40);
    __Pyx_GIVEREF(__pyx_kp_40);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":204
 *         raise Exception("alpha_munge requires a pygame Surface as its first argument.")
 * 
 *     if not isinstance(pydst, PygameSurface):             # <<<<<<<<<<<<<<
 *         raise Exception("alpha_munge requires a pygame Surface as its second argument.")
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_PygameSurface); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_2 = PyObject_IsInstance(__pyx_v_pydst, __pyx_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_1 = (!__pyx_t_2);
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":205
 * 
 *     if not isinstance(pydst, PygameSurface):
 *         raise Exception("alpha_munge requires a pygame Surface as its second argument.")             # <<<<<<<<<<<<<<
 * 
 *     if pysrc.get_bitsize() not in (24, 32):
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_41);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_41);
    __Pyx_GIVEREF(__pyx_kp_41);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":207
 *         raise Exception("alpha_munge requires a pygame Surface as its second argument.")
 * 
 *     if pysrc.get_bitsize() not in (24, 32):             # <<<<<<<<<<<<<<
 *         raise Exception("alpha_munge requires a 24 or 32 bit surface.")
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_int_24, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (((int)__pyx_t_1)) {
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_int_32, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = ((int)__pyx_t_2);
  } else {
    __pyx_t_5 = ((int)__pyx_t_1);
  }
  __pyx_t_1 = __pyx_t_5;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":208
 * 
 *     if pysrc.get_bitsize() not in (24, 32):
 *         raise Exception("alpha_munge requires a 24 or 32 bit surface.")             # <<<<<<<<<<<<<<
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_42);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_42);
    __Pyx_GIVEREF(__pyx_kp_42);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":210
 *         raise Exception("alpha_munge requires a 24 or 32 bit surface.")
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():             # <<<<<<<<<<<<<<
 *         raise Exception("alpha_munge requires both surfaces have the same bitsize.")
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pydst, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":211
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():
 *         raise Exception("alpha_munge requires both surfaces have the same bitsize.")             # <<<<<<<<<<<<<<
 * 
 *     if pydst.get_size() != pysrc.get_size():
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_43);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_43);
    __Pyx_GIVEREF(__pyx_kp_43);
    __pyx_t_6 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_6, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":213
 *         raise Exception("alpha_munge requires both surfaces have the same bitsize.")
 * 
 *     if pydst.get_size() != pysrc.get_size():             # <<<<<<<<<<<<<<
 *         raise Exception("alpha_munge requires both surfaces have the same size.")
 * 
 */
  __pyx_t_6 = PyObject_GetAttr(__pyx_v_pydst, __pyx_kp_get_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_NE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":214
 * 
 *     if pydst.get_size() != pysrc.get_size():
 *         raise Exception("alpha_munge requires both surfaces have the same size.")             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
    __Pyx_INCREF(__pyx_kp_44);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_kp_44);
    __Pyx_GIVEREF(__pyx_kp_44);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":217
 * 
 * 
 *     if pysrc.get_bitsize() == 24:             # <<<<<<<<<<<<<<
 *         bytes = 3
 *     else:
 */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_int_24, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":218
 * 
 *     if pysrc.get_bitsize() == 24:
 *         bytes = 3             # <<<<<<<<<<<<<<
 *     else:
 *         bytes = 4
 */
    __Pyx_INCREF(__pyx_int_3);
    __Pyx_DECREF(__pyx_v_bytes);
    __pyx_v_bytes = __pyx_int_3;
    goto __pyx_L11;
  }
  /*else*/ {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":220
 *         bytes = 3
 *     else:
 *         bytes = 4             # <<<<<<<<<<<<<<
 * 
 *     # pysrc.lock()
 */
    __Pyx_INCREF(__pyx_int_4);
    __Pyx_DECREF(__pyx_v_bytes);
    __pyx_v_bytes = __pyx_int_4;
  }
  __pyx_L11:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":225
 *     # pydst.lock()
 * 
 *     alphamunge_core(pysrc, pydst, bytes, srcchan, dstchan, amap)             # <<<<<<<<<<<<<<
 * 
 *     # pydst.unlock()
 */
  __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_v_bytes); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_v_srcchan); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_v_dstchan); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_10 = __Pyx_PyBytes_AsString(__pyx_v_amap); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  alphamunge_core(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_7, __pyx_t_8, __pyx_t_9, __pyx_t_10);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_renpy.alpha_munge");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_bytes);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":284
 * 
 * 
 * def bilinear(pysrc, pydst,             # <<<<<<<<<<<<<<
 *              source_xoff=0.0, source_yoff=0.0, source_width=None, source_height=None,
 *              dest_xoff=0.0, dest_yoff=0.0, dest_width=None, dest_height=None):
 */

static PyObject *__pyx_pf_6_renpy_bilinear(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6_renpy_bilinear(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysrc = 0;
  PyObject *__pyx_v_pydst = 0;
  PyObject *__pyx_v_source_xoff = 0;
  PyObject *__pyx_v_source_yoff = 0;
  PyObject *__pyx_v_source_width = 0;
  PyObject *__pyx_v_source_height = 0;
  PyObject *__pyx_v_dest_xoff = 0;
  PyObject *__pyx_v_dest_yoff = 0;
  PyObject *__pyx_v_dest_width = 0;
  PyObject *__pyx_v_dest_height = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  float __pyx_t_7;
  float __pyx_t_8;
  float __pyx_t_9;
  float __pyx_t_10;
  float __pyx_t_11;
  float __pyx_t_12;
  float __pyx_t_13;
  float __pyx_t_14;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_pysrc,&__pyx_kp_pydst,&__pyx_kp_source_xoff,&__pyx_kp_source_yoff,&__pyx_kp_source_width,&__pyx_kp_source_height,&__pyx_kp_dest_xoff,&__pyx_kp_dest_yoff,&__pyx_kp_dest_width,&__pyx_kp_dest_height,0};
  __Pyx_SetupRefcountContext("bilinear");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[10] = {0,0,0,0,0,0,0,0,0,0};
    values[2] = __pyx_k_20;
    values[3] = __pyx_k_21;
    values[4] = Py_None;
    values[5] = Py_None;
    values[6] = __pyx_k_22;
    values[7] = __pyx_k_23;
    values[8] = Py_None;
    values[9] = Py_None;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
      case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
      case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
      case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrc);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pydst);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("bilinear", 0, 2, 10, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_source_xoff);
        if (unlikely(value)) { values[2] = value; kw_args--; }
      }
      case  3:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_source_yoff);
        if (unlikely(value)) { values[3] = value; kw_args--; }
      }
      case  4:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_source_width);
        if (unlikely(value)) { values[4] = value; kw_args--; }
      }
      case  5:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_source_height);
        if (unlikely(value)) { values[5] = value; kw_args--; }
      }
      case  6:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_dest_xoff);
        if (unlikely(value)) { values[6] = value; kw_args--; }
      }
      case  7:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_dest_yoff);
        if (unlikely(value)) { values[7] = value; kw_args--; }
      }
      case  8:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_dest_width);
        if (unlikely(value)) { values[8] = value; kw_args--; }
      }
      case  9:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_dest_height);
        if (unlikely(value)) { values[9] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "bilinear") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysrc = values[0];
    __pyx_v_pydst = values[1];
    __pyx_v_source_xoff = values[2];
    __pyx_v_source_yoff = values[3];
    __pyx_v_source_width = values[4];
    __pyx_v_source_height = values[5];
    __pyx_v_dest_xoff = values[6];
    __pyx_v_dest_yoff = values[7];
    __pyx_v_dest_width = values[8];
    __pyx_v_dest_height = values[9];
  } else {
    __pyx_v_source_xoff = __pyx_k_20;
    __pyx_v_source_yoff = __pyx_k_21;
    __pyx_v_source_width = Py_None;
    __pyx_v_source_height = Py_None;
    __pyx_v_dest_xoff = __pyx_k_22;
    __pyx_v_dest_yoff = __pyx_k_23;
    __pyx_v_dest_width = Py_None;
    __pyx_v_dest_height = Py_None;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case 10:
      __pyx_v_dest_height = PyTuple_GET_ITEM(__pyx_args, 9);
      case  9:
      __pyx_v_dest_width = PyTuple_GET_ITEM(__pyx_args, 8);
      case  8:
      __pyx_v_dest_yoff = PyTuple_GET_ITEM(__pyx_args, 7);
      case  7:
      __pyx_v_dest_xoff = PyTuple_GET_ITEM(__pyx_args, 6);
      case  6:
      __pyx_v_source_height = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5:
      __pyx_v_source_width = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4:
      __pyx_v_source_yoff = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3:
      __pyx_v_source_xoff = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2:
      __pyx_v_pydst = PyTuple_GET_ITEM(__pyx_args, 1);
      __pyx_v_pysrc = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("bilinear", 0, 2, 10, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy.bilinear");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_source_width);
  __Pyx_INCREF(__pyx_v_source_height);
  __Pyx_INCREF(__pyx_v_dest_width);
  __Pyx_INCREF(__pyx_v_dest_height);

  /* "/home/tom/ab/renpy/module/_renpy.pyx":288
 *              dest_xoff=0.0, dest_yoff=0.0, dest_width=None, dest_height=None):
 * 
 *     if not isinstance(pysrc, PygameSurface):             # <<<<<<<<<<<<<<
 *         raise Exception("bilinear requires a pygame Surface as its first argument.")
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_PygameSurface); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyObject_IsInstance(__pyx_v_pysrc, __pyx_1); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":289
 * 
 *     if not isinstance(pysrc, PygameSurface):
 *         raise Exception("bilinear requires a pygame Surface as its first argument.")             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(pydst, PygameSurface):
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_45);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_45);
    __Pyx_GIVEREF(__pyx_kp_45);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":291
 *         raise Exception("bilinear requires a pygame Surface as its first argument.")
 * 
 *     if not isinstance(pydst, PygameSurface):             # <<<<<<<<<<<<<<
 *         raise Exception("bilinear requires a pygame Surface as its second argument.")
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_PygameSurface); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_2 = PyObject_IsInstance(__pyx_v_pydst, __pyx_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_1 = (!__pyx_t_2);
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":292
 * 
 *     if not isinstance(pydst, PygameSurface):
 *         raise Exception("bilinear requires a pygame Surface as its second argument.")             # <<<<<<<<<<<<<<
 * 
 *     if pysrc.get_bitsize() not in (24, 32):
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_46);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_46);
    __Pyx_GIVEREF(__pyx_kp_46);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":294
 *         raise Exception("bilinear requires a pygame Surface as its second argument.")
 * 
 *     if pysrc.get_bitsize() not in (24, 32):             # <<<<<<<<<<<<<<
 *         raise Exception("bilinear requires a 24 or 32 bit surface.")
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_int_24, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (((int)__pyx_t_1)) {
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_int_32, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 == (int)-1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = ((int)__pyx_t_2);
  } else {
    __pyx_t_5 = ((int)__pyx_t_1);
  }
  __pyx_t_1 = __pyx_t_5;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":295
 * 
 *     if pysrc.get_bitsize() not in (24, 32):
 *         raise Exception("bilinear requires a 24 or 32 bit surface.")             # <<<<<<<<<<<<<<
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_47);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_47);
    __Pyx_GIVEREF(__pyx_kp_47);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":297
 *         raise Exception("bilinear requires a 24 or 32 bit surface.")
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():             # <<<<<<<<<<<<<<
 *         raise Exception("bilinear requires both surfaces have the same bitsize.")
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pydst, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_1) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":298
 * 
 *     if pydst.get_bitsize() != pysrc.get_bitsize():
 *         raise Exception("bilinear requires both surfaces have the same bitsize.")             # <<<<<<<<<<<<<<
 * 
 *     if source_width is None or source_height is None:
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_48);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_48);
    __Pyx_GIVEREF(__pyx_kp_48);
    __pyx_t_6 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_6, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":300
 *         raise Exception("bilinear requires both surfaces have the same bitsize.")
 * 
 *     if source_width is None or source_height is None:             # <<<<<<<<<<<<<<
 *         source_width, source_height = pysrc.get_size()
 * 
 */
  __pyx_t_1 = (__pyx_v_source_width == Py_None);
  if (!__pyx_t_1) {
    __pyx_t_5 = (__pyx_v_source_height == Py_None);
    __pyx_t_2 = __pyx_t_5;
  } else {
    __pyx_t_2 = __pyx_t_1;
  }
  if (__pyx_t_2) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":301
 * 
 *     if source_width is None or source_height is None:
 *         source_width, source_height = pysrc.get_size()             # <<<<<<<<<<<<<<
 * 
 *     if dest_width is None or dest_height is None:
 */
    __pyx_t_6 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (PyTuple_CheckExact(__pyx_t_3) && likely(PyTuple_GET_SIZE(__pyx_t_3) == 2)) {
      PyObject* tuple = __pyx_t_3;
      __pyx_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_2);
      __pyx_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_3);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_v_source_width);
      __pyx_v_source_width = __pyx_2;
      __pyx_2 = 0;
      __Pyx_DECREF(__pyx_v_source_height);
      __pyx_v_source_height = __pyx_3;
      __pyx_3 = 0;
    } else {
      __pyx_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_2 = __Pyx_UnpackItem(__pyx_1, 0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_2);
      __pyx_3 = __Pyx_UnpackItem(__pyx_1, 1); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_3);
      if (__Pyx_EndUnpack(__pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
      __Pyx_DECREF(__pyx_v_source_width);
      __pyx_v_source_width = __pyx_2;
      __pyx_2 = 0;
      __Pyx_DECREF(__pyx_v_source_height);
      __pyx_v_source_height = __pyx_3;
      __pyx_3 = 0;
    }
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":303
 *         source_width, source_height = pysrc.get_size()
 * 
 *     if dest_width is None or dest_height is None:             # <<<<<<<<<<<<<<
 *         dest_width, dest_height = pydst.get_size()
 * 
 */
  __pyx_t_2 = (__pyx_v_dest_width == Py_None);
  if (!__pyx_t_2) {
    __pyx_t_1 = (__pyx_v_dest_height == Py_None);
    __pyx_t_5 = __pyx_t_1;
  } else {
    __pyx_t_5 = __pyx_t_2;
  }
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":304
 * 
 *     if dest_width is None or dest_height is None:
 *         dest_width, dest_height = pydst.get_size()             # <<<<<<<<<<<<<<
 * 
 *     # pysrc.lock()
 */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_pydst, __pyx_kp_get_size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyTuple_CheckExact(__pyx_t_6) && likely(PyTuple_GET_SIZE(__pyx_t_6) == 2)) {
      PyObject* tuple = __pyx_t_6;
      __pyx_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_2);
      __pyx_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_v_dest_width);
      __pyx_v_dest_width = __pyx_2;
      __pyx_2 = 0;
      __Pyx_DECREF(__pyx_v_dest_height);
      __pyx_v_dest_height = __pyx_3;
      __pyx_3 = 0;
    } else {
      __pyx_1 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_2 = __Pyx_UnpackItem(__pyx_1, 0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_2);
      __pyx_3 = __Pyx_UnpackItem(__pyx_1, 1); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_3);
      if (__Pyx_EndUnpack(__pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
      __Pyx_DECREF(__pyx_v_dest_width);
      __pyx_v_dest_width = __pyx_2;
      __pyx_2 = 0;
      __Pyx_DECREF(__pyx_v_dest_height);
      __pyx_v_dest_height = __pyx_3;
      __pyx_3 = 0;
    }
    goto __pyx_L11;
  }
  __pyx_L11:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":309
 *     # pydst.lock()
 * 
 *     if pysrc.get_bitsize() == 32:             # <<<<<<<<<<<<<<
 *         scale32_core(pysrc, pydst,
 *                      source_xoff, source_yoff, source_width, source_height,
 */
  __pyx_t_6 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyObject_RichCompare(__pyx_t_3, __pyx_int_32, Py_EQ); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__pyx_t_5) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":311
 *     if pysrc.get_bitsize() == 32:
 *         scale32_core(pysrc, pydst,
 *                      source_xoff, source_yoff, source_width, source_height,             # <<<<<<<<<<<<<<
 *                      dest_xoff, dest_yoff, dest_width, dest_height)
 * 
 */
    __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_v_source_xoff); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_v_source_yoff); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_v_source_width); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_v_source_height); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "/home/tom/ab/renpy/module/_renpy.pyx":312
 *         scale32_core(pysrc, pydst,
 *                      source_xoff, source_yoff, source_width, source_height,
 *                      dest_xoff, dest_yoff, dest_width, dest_height)             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
    __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_v_dest_xoff); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_v_dest_yoff); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = __pyx_PyFloat_AsDouble(__pyx_v_dest_width); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_14 = __pyx_PyFloat_AsDouble(__pyx_v_dest_height); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    scale32_core(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_7, __pyx_t_8, __pyx_t_9, __pyx_t_10, __pyx_t_11, __pyx_t_12, __pyx_t_13, __pyx_t_14);
    goto __pyx_L12;
  }
  /*else*/ {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":316
 *     else:
 *         scale24_core(pysrc, pydst,
 *                      source_xoff, source_yoff, source_width, source_height,             # <<<<<<<<<<<<<<
 *                      dest_xoff, dest_yoff, dest_width, dest_height)
 * 
 */
    __pyx_t_14 = __pyx_PyFloat_AsDouble(__pyx_v_source_xoff); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = __pyx_PyFloat_AsDouble(__pyx_v_source_yoff); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_v_source_width); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_v_source_height); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "/home/tom/ab/renpy/module/_renpy.pyx":317
 *         scale24_core(pysrc, pydst,
 *                      source_xoff, source_yoff, source_width, source_height,
 *                      dest_xoff, dest_yoff, dest_width, dest_height)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_v_dest_xoff); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_v_dest_yoff); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_v_dest_width); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_v_dest_height); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    scale24_core(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_14, __pyx_t_13, __pyx_t_12, __pyx_t_11, __pyx_t_10, __pyx_t_9, __pyx_t_8, __pyx_t_7);
  }
  __pyx_L12:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_2);
  __Pyx_XDECREF(__pyx_3);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_renpy.bilinear");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_source_width);
  __Pyx_DECREF(__pyx_v_source_height);
  __Pyx_DECREF(__pyx_v_dest_width);
  __Pyx_DECREF(__pyx_v_dest_height);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":324
 * 
 * 
 * def check(surf):             # <<<<<<<<<<<<<<
 *     if not isinstance(surf, PygameSurface):
 *         raise Exception("Surface must be a pygame surface.")
 */

static PyObject *__pyx_pf_6_renpy_check(PyObject *__pyx_self, PyObject *__pyx_v_surf); /*proto*/
static PyObject *__pyx_pf_6_renpy_check(PyObject *__pyx_self, PyObject *__pyx_v_surf) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_SetupRefcountContext("check");
  __pyx_self = __pyx_self;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":325
 * 
 * def check(surf):
 *     if not isinstance(surf, PygameSurface):             # <<<<<<<<<<<<<<
 *         raise Exception("Surface must be a pygame surface.")
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_PygameSurface); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyObject_IsInstance(__pyx_v_surf, __pyx_1); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":326
 * def check(surf):
 *     if not isinstance(surf, PygameSurface):
 *         raise Exception("Surface must be a pygame surface.")             # <<<<<<<<<<<<<<
 * 
 *     if surf.get_bitsize() != 32:
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_kp_49);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_49);
    __Pyx_GIVEREF(__pyx_kp_49);
    __pyx_t_4 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":328
 *         raise Exception("Surface must be a pygame surface.")
 * 
 *     if surf.get_bitsize() != 32:             # <<<<<<<<<<<<<<
 *         raise Exception("Surface must be 32-bit.")
 * 
 */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_surf, __pyx_kp_get_bitsize); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_int_32, Py_NE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_2) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":329
 * 
 *     if surf.get_bitsize() != 32:
 *         raise Exception("Surface must be 32-bit.")             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(__pyx_kp_50);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_50);
    __Pyx_GIVEREF(__pyx_kp_50);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("_renpy.check");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":332
 * 
 * 
 * def transform(pysrc, pydst,             # <<<<<<<<<<<<<<
 *               corner_x, corner_y,
 *               xdx, ydx, xdy, ydy, a=1.0):
 */

static PyObject *__pyx_pf_6_renpy_transform(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6_renpy_transform(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysrc = 0;
  PyObject *__pyx_v_pydst = 0;
  PyObject *__pyx_v_corner_x = 0;
  PyObject *__pyx_v_corner_y = 0;
  PyObject *__pyx_v_xdx = 0;
  PyObject *__pyx_v_ydx = 0;
  PyObject *__pyx_v_xdy = 0;
  PyObject *__pyx_v_ydy = 0;
  PyObject *__pyx_v_a = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  float __pyx_t_3;
  float __pyx_t_4;
  float __pyx_t_5;
  float __pyx_t_6;
  float __pyx_t_7;
  float __pyx_t_8;
  int __pyx_t_9;
  float __pyx_t_10;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_pysrc,&__pyx_kp_pydst,&__pyx_kp_corner_x,&__pyx_kp_corner_y,&__pyx_kp_xdx,&__pyx_kp_ydx,&__pyx_kp_xdy,&__pyx_kp_ydy,&__pyx_kp_a,0};
  __Pyx_SetupRefcountContext("transform");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[9] = {0,0,0,0,0,0,0,0,0};
    values[8] = __pyx_k_24;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
      case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
      case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrc);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pydst);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("transform", 0, 8, 9, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_kp_corner_x);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("transform", 0, 8, 9, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_kp_corner_y);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("transform", 0, 8, 9, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  4:
      values[4] = PyDict_GetItem(__pyx_kwds, __pyx_kp_xdx);
      if (likely(values[4])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("transform", 0, 8, 9, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  5:
      values[5] = PyDict_GetItem(__pyx_kwds, __pyx_kp_ydx);
      if (likely(values[5])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("transform", 0, 8, 9, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  6:
      values[6] = PyDict_GetItem(__pyx_kwds, __pyx_kp_xdy);
      if (likely(values[6])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("transform", 0, 8, 9, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  7:
      values[7] = PyDict_GetItem(__pyx_kwds, __pyx_kp_ydy);
      if (likely(values[7])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("transform", 0, 8, 9, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  8:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_a);
        if (unlikely(value)) { values[8] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "transform") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysrc = values[0];
    __pyx_v_pydst = values[1];
    __pyx_v_corner_x = values[2];
    __pyx_v_corner_y = values[3];
    __pyx_v_xdx = values[4];
    __pyx_v_ydx = values[5];
    __pyx_v_xdy = values[6];
    __pyx_v_ydy = values[7];
    __pyx_v_a = values[8];
  } else {
    __pyx_v_a = __pyx_k_24;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  9:
      __pyx_v_a = PyTuple_GET_ITEM(__pyx_args, 8);
      case  8:
      __pyx_v_ydy = PyTuple_GET_ITEM(__pyx_args, 7);
      __pyx_v_xdy = PyTuple_GET_ITEM(__pyx_args, 6);
      __pyx_v_ydx = PyTuple_GET_ITEM(__pyx_args, 5);
      __pyx_v_xdx = PyTuple_GET_ITEM(__pyx_args, 4);
      __pyx_v_corner_y = PyTuple_GET_ITEM(__pyx_args, 3);
      __pyx_v_corner_x = PyTuple_GET_ITEM(__pyx_args, 2);
      __pyx_v_pydst = PyTuple_GET_ITEM(__pyx_args, 1);
      __pyx_v_pysrc = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("transform", 0, 8, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy.transform");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":336
 *               xdx, ydx, xdy, ydy, a=1.0):
 * 
 *     check(pysrc)             # <<<<<<<<<<<<<<
 *     check(pydst)
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_check); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_pysrc);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_pysrc);
  __Pyx_GIVEREF(__pyx_v_pysrc);
  __pyx_t_2 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":337
 * 
 *     check(pysrc)
 *     check(pydst)             # <<<<<<<<<<<<<<
 * 
 *     # pysrc.lock()
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_check); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(__pyx_v_pydst);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_pydst);
  __Pyx_GIVEREF(__pyx_v_pydst);
  __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":343
 * 
 *     transform32_core(pysrc, pydst,
 *                      corner_x, corner_y,             # <<<<<<<<<<<<<<
 *                      xdx, ydx,
 *                      xdy, ydy,
 */
  __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_corner_x); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_v_corner_y); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/tom/ab/renpy/module/_renpy.pyx":344
 *     transform32_core(pysrc, pydst,
 *                      corner_x, corner_y,
 *                      xdx, ydx,             # <<<<<<<<<<<<<<
 *                      xdy, ydy,
 *                      pysrc.get_shifts()[3], a)
 */
  __pyx_t_5 = __pyx_PyFloat_AsDouble(__pyx_v_xdx); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_v_ydx); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/tom/ab/renpy/module/_renpy.pyx":345
 *                      corner_x, corner_y,
 *                      xdx, ydx,
 *                      xdy, ydy,             # <<<<<<<<<<<<<<
 *                      pysrc.get_shifts()[3], a)
 * 
 */
  __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_v_xdy); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_v_ydy); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/tom/ab/renpy/module/_renpy.pyx":346
 *                      xdx, ydx,
 *                      xdy, ydy,
 *                      pysrc.get_shifts()[3], a)             # <<<<<<<<<<<<<<
 * 
 *     # pydst.unlock()
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_pysrc, __pyx_kp_get_shifts); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_1 = __Pyx_GetItemInt(__pyx_t_2, 3, sizeof(long), PyInt_FromLong); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_1); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_v_a); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  transform32_core(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_3, __pyx_t_4, __pyx_t_5, __pyx_t_6, __pyx_t_7, __pyx_t_8, __pyx_t_9, __pyx_t_10);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_renpy.transform");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":352
 * 
 * 
 * def blend(pysrca, pysrcb, pydst, alpha):             # <<<<<<<<<<<<<<
 * 
 *     check(pysrca)
 */

static PyObject *__pyx_pf_6_renpy_blend(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6_renpy_blend(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysrca = 0;
  PyObject *__pyx_v_pysrcb = 0;
  PyObject *__pyx_v_pydst = 0;
  PyObject *__pyx_v_alpha = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_pysrca,&__pyx_kp_pysrcb,&__pyx_kp_pydst,&__pyx_kp_alpha,0};
  __Pyx_SetupRefcountContext("blend");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[4] = {0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrca);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrcb);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("blend", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pydst);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("blend", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_kp_alpha);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("blend", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "blend") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysrca = values[0];
    __pyx_v_pysrcb = values[1];
    __pyx_v_pydst = values[2];
    __pyx_v_alpha = values[3];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_pysrca = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_pysrcb = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_pydst = PyTuple_GET_ITEM(__pyx_args, 2);
    __pyx_v_alpha = PyTuple_GET_ITEM(__pyx_args, 3);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("blend", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy.blend");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":354
 * def blend(pysrca, pysrcb, pydst, alpha):
 * 
 *     check(pysrca)             # <<<<<<<<<<<<<<
 *     check(pysrcb)
 *     check(pydst)
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_check); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_pysrca);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_pysrca);
  __Pyx_GIVEREF(__pyx_v_pysrca);
  __pyx_t_2 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":355
 * 
 *     check(pysrca)
 *     check(pysrcb)             # <<<<<<<<<<<<<<
 *     check(pydst)
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_check); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(__pyx_v_pysrcb);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_pysrcb);
  __Pyx_GIVEREF(__pyx_v_pysrcb);
  __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":356
 *     check(pysrca)
 *     check(pysrcb)
 *     check(pydst)             # <<<<<<<<<<<<<<
 * 
 *     # pysrca.lock()
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_check); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_pydst);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_pydst);
  __Pyx_GIVEREF(__pyx_v_pydst);
  __pyx_t_2 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":362
 *     # pydst.lock()
 * 
 *     blend32_core(pysrca, pysrcb, pydst, alpha)             # <<<<<<<<<<<<<<
 * 
 *     # pydst.unlock()
 */
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_alpha); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  blend32_core(__pyx_v_pysrca, __pyx_v_pysrcb, __pyx_v_pydst, __pyx_t_3);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_renpy.blend");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":368
 *     # pysrca.unlock()
 * 
 * def imageblend(pysrca, pysrcb, pydst, pyimg, aoff, amap):             # <<<<<<<<<<<<<<
 *     check(pysrca)
 *     check(pysrcb)
 */

static PyObject *__pyx_pf_6_renpy_imageblend(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6_renpy_imageblend(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysrca = 0;
  PyObject *__pyx_v_pysrcb = 0;
  PyObject *__pyx_v_pydst = 0;
  PyObject *__pyx_v_pyimg = 0;
  PyObject *__pyx_v_aoff = 0;
  PyObject *__pyx_v_amap = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  char *__pyx_t_4;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_pysrca,&__pyx_kp_pysrcb,&__pyx_kp_pydst,&__pyx_kp_pyimg,&__pyx_kp_aoff,&__pyx_kp_amap,0};
  __Pyx_SetupRefcountContext("imageblend");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[6] = {0,0,0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrca);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrcb);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("imageblend", 1, 6, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pydst);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("imageblend", 1, 6, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pyimg);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("imageblend", 1, 6, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  4:
      values[4] = PyDict_GetItem(__pyx_kwds, __pyx_kp_aoff);
      if (likely(values[4])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("imageblend", 1, 6, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  5:
      values[5] = PyDict_GetItem(__pyx_kwds, __pyx_kp_amap);
      if (likely(values[5])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("imageblend", 1, 6, 6, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "imageblend") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysrca = values[0];
    __pyx_v_pysrcb = values[1];
    __pyx_v_pydst = values[2];
    __pyx_v_pyimg = values[3];
    __pyx_v_aoff = values[4];
    __pyx_v_amap = values[5];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 6) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_pysrca = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_pysrcb = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_pydst = PyTuple_GET_ITEM(__pyx_args, 2);
    __pyx_v_pyimg = PyTuple_GET_ITEM(__pyx_args, 3);
    __pyx_v_aoff = PyTuple_GET_ITEM(__pyx_args, 4);
    __pyx_v_amap = PyTuple_GET_ITEM(__pyx_args, 5);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("imageblend", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy.imageblend");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":369
 * 
 * def imageblend(pysrca, pysrcb, pydst, pyimg, aoff, amap):
 *     check(pysrca)             # <<<<<<<<<<<<<<
 *     check(pysrcb)
 *     check(pydst)
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_check); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_pysrca);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_pysrca);
  __Pyx_GIVEREF(__pyx_v_pysrca);
  __pyx_t_2 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":370
 * def imageblend(pysrca, pysrcb, pydst, pyimg, aoff, amap):
 *     check(pysrca)
 *     check(pysrcb)             # <<<<<<<<<<<<<<
 *     check(pydst)
 *     check(pyimg)
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_check); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(__pyx_v_pysrcb);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_pysrcb);
  __Pyx_GIVEREF(__pyx_v_pysrcb);
  __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":371
 *     check(pysrca)
 *     check(pysrcb)
 *     check(pydst)             # <<<<<<<<<<<<<<
 *     check(pyimg)
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_check); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_pydst);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_pydst);
  __Pyx_GIVEREF(__pyx_v_pydst);
  __pyx_t_2 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":372
 *     check(pysrcb)
 *     check(pydst)
 *     check(pyimg)             # <<<<<<<<<<<<<<
 * 
 *     # pysrca.lock()
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_check); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(__pyx_v_pyimg);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_pyimg);
  __Pyx_GIVEREF(__pyx_v_pyimg);
  __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":379
 *     # pyimg.lock()
 * 
 *     imageblend32_core(pysrca, pysrcb, pydst, pyimg, aoff, amap)             # <<<<<<<<<<<<<<
 * 
 *     # pyimg.unlock()
 */
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_aoff); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_amap); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  imageblend32_core(__pyx_v_pysrca, __pyx_v_pysrcb, __pyx_v_pydst, __pyx_v_pyimg, __pyx_t_3, __pyx_t_4);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_renpy.imageblend");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":386
 *     # pysrca.unlock()
 * 
 * def colormatrix(pysrc, pydst,             # <<<<<<<<<<<<<<
 *                 c00, c01, c02, c03, c04,
 *                 c10, c11, c12, c13, c14,
 */

static PyObject *__pyx_pf_6_renpy_colormatrix(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6_renpy_colormatrix(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysrc = 0;
  PyObject *__pyx_v_pydst = 0;
  PyObject *__pyx_v_c00 = 0;
  PyObject *__pyx_v_c01 = 0;
  PyObject *__pyx_v_c02 = 0;
  PyObject *__pyx_v_c03 = 0;
  PyObject *__pyx_v_c04 = 0;
  PyObject *__pyx_v_c10 = 0;
  PyObject *__pyx_v_c11 = 0;
  PyObject *__pyx_v_c12 = 0;
  PyObject *__pyx_v_c13 = 0;
  PyObject *__pyx_v_c14 = 0;
  PyObject *__pyx_v_c20 = 0;
  PyObject *__pyx_v_c21 = 0;
  PyObject *__pyx_v_c22 = 0;
  PyObject *__pyx_v_c23 = 0;
  PyObject *__pyx_v_c24 = 0;
  PyObject *__pyx_v_c30 = 0;
  PyObject *__pyx_v_c31 = 0;
  PyObject *__pyx_v_c32 = 0;
  PyObject *__pyx_v_c33 = 0;
  PyObject *__pyx_v_c34 = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  float __pyx_t_3;
  float __pyx_t_4;
  float __pyx_t_5;
  float __pyx_t_6;
  float __pyx_t_7;
  float __pyx_t_8;
  float __pyx_t_9;
  float __pyx_t_10;
  float __pyx_t_11;
  float __pyx_t_12;
  float __pyx_t_13;
  float __pyx_t_14;
  float __pyx_t_15;
  float __pyx_t_16;
  float __pyx_t_17;
  float __pyx_t_18;
  float __pyx_t_19;
  float __pyx_t_20;
  float __pyx_t_21;
  float __pyx_t_22;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_pysrc,&__pyx_kp_pydst,&__pyx_kp_c00,&__pyx_kp_1,&__pyx_kp_2,&__pyx_kp_3,&__pyx_kp_4,&__pyx_kp_5,&__pyx_kp_6,&__pyx_kp_7,&__pyx_kp_8,&__pyx_kp_9,&__pyx_kp_10,&__pyx_kp_11,&__pyx_kp_12,&__pyx_kp_13,&__pyx_kp_14,&__pyx_kp_15,&__pyx_kp_16,&__pyx_kp_17,&__pyx_kp_18,&__pyx_kp_19,0};
  __Pyx_SetupRefcountContext("colormatrix");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case 22: values[21] = PyTuple_GET_ITEM(__pyx_args, 21);
      case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20);
      case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19);
      case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18);
      case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17);
      case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16);
      case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15);
      case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14);
      case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13);
      case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
      case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
      case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
      case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
      case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
      case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
      case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrc);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pydst);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_kp_c00);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_kp_1);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  4:
      values[4] = PyDict_GetItem(__pyx_kwds, __pyx_kp_2);
      if (likely(values[4])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  5:
      values[5] = PyDict_GetItem(__pyx_kwds, __pyx_kp_3);
      if (likely(values[5])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  6:
      values[6] = PyDict_GetItem(__pyx_kwds, __pyx_kp_4);
      if (likely(values[6])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  7:
      values[7] = PyDict_GetItem(__pyx_kwds, __pyx_kp_5);
      if (likely(values[7])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  8:
      values[8] = PyDict_GetItem(__pyx_kwds, __pyx_kp_6);
      if (likely(values[8])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 8); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  9:
      values[9] = PyDict_GetItem(__pyx_kwds, __pyx_kp_7);
      if (likely(values[9])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 9); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 10:
      values[10] = PyDict_GetItem(__pyx_kwds, __pyx_kp_8);
      if (likely(values[10])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 10); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 11:
      values[11] = PyDict_GetItem(__pyx_kwds, __pyx_kp_9);
      if (likely(values[11])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 11); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 12:
      values[12] = PyDict_GetItem(__pyx_kwds, __pyx_kp_10);
      if (likely(values[12])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 12); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 13:
      values[13] = PyDict_GetItem(__pyx_kwds, __pyx_kp_11);
      if (likely(values[13])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 13); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 14:
      values[14] = PyDict_GetItem(__pyx_kwds, __pyx_kp_12);
      if (likely(values[14])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 14); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 15:
      values[15] = PyDict_GetItem(__pyx_kwds, __pyx_kp_13);
      if (likely(values[15])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 15); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 16:
      values[16] = PyDict_GetItem(__pyx_kwds, __pyx_kp_14);
      if (likely(values[16])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 16); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 17:
      values[17] = PyDict_GetItem(__pyx_kwds, __pyx_kp_15);
      if (likely(values[17])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 17); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 18:
      values[18] = PyDict_GetItem(__pyx_kwds, __pyx_kp_16);
      if (likely(values[18])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 18); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 19:
      values[19] = PyDict_GetItem(__pyx_kwds, __pyx_kp_17);
      if (likely(values[19])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 19); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 20:
      values[20] = PyDict_GetItem(__pyx_kwds, __pyx_kp_18);
      if (likely(values[20])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 20); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case 21:
      values[21] = PyDict_GetItem(__pyx_kwds, __pyx_kp_19);
      if (likely(values[21])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, 21); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "colormatrix") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysrc = values[0];
    __pyx_v_pydst = values[1];
    __pyx_v_c00 = values[2];
    __pyx_v_c01 = values[3];
    __pyx_v_c02 = values[4];
    __pyx_v_c03 = values[5];
    __pyx_v_c04 = values[6];
    __pyx_v_c10 = values[7];
    __pyx_v_c11 = values[8];
    __pyx_v_c12 = values[9];
    __pyx_v_c13 = values[10];
    __pyx_v_c14 = values[11];
    __pyx_v_c20 = values[12];
    __pyx_v_c21 = values[13];
    __pyx_v_c22 = values[14];
    __pyx_v_c23 = values[15];
    __pyx_v_c24 = values[16];
    __pyx_v_c30 = values[17];
    __pyx_v_c31 = values[18];
    __pyx_v_c32 = values[19];
    __pyx_v_c33 = values[20];
    __pyx_v_c34 = values[21];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 22) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_pysrc = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_pydst = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_c00 = PyTuple_GET_ITEM(__pyx_args, 2);
    __pyx_v_c01 = PyTuple_GET_ITEM(__pyx_args, 3);
    __pyx_v_c02 = PyTuple_GET_ITEM(__pyx_args, 4);
    __pyx_v_c03 = PyTuple_GET_ITEM(__pyx_args, 5);
    __pyx_v_c04 = PyTuple_GET_ITEM(__pyx_args, 6);
    __pyx_v_c10 = PyTuple_GET_ITEM(__pyx_args, 7);
    __pyx_v_c11 = PyTuple_GET_ITEM(__pyx_args, 8);
    __pyx_v_c12 = PyTuple_GET_ITEM(__pyx_args, 9);
    __pyx_v_c13 = PyTuple_GET_ITEM(__pyx_args, 10);
    __pyx_v_c14 = PyTuple_GET_ITEM(__pyx_args, 11);
    __pyx_v_c20 = PyTuple_GET_ITEM(__pyx_args, 12);
    __pyx_v_c21 = PyTuple_GET_ITEM(__pyx_args, 13);
    __pyx_v_c22 = PyTuple_GET_ITEM(__pyx_args, 14);
    __pyx_v_c23 = PyTuple_GET_ITEM(__pyx_args, 15);
    __pyx_v_c24 = PyTuple_GET_ITEM(__pyx_args, 16);
    __pyx_v_c30 = PyTuple_GET_ITEM(__pyx_args, 17);
    __pyx_v_c31 = PyTuple_GET_ITEM(__pyx_args, 18);
    __pyx_v_c32 = PyTuple_GET_ITEM(__pyx_args, 19);
    __pyx_v_c33 = PyTuple_GET_ITEM(__pyx_args, 20);
    __pyx_v_c34 = PyTuple_GET_ITEM(__pyx_args, 21);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("colormatrix", 1, 22, 22, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy.colormatrix");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":392
 *                 c30, c31, c32, c33, c34):
 * 
 *     check(pysrc)             # <<<<<<<<<<<<<<
 *     check(pydst)
 * 
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_check); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_pysrc);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_pysrc);
  __Pyx_GIVEREF(__pyx_v_pysrc);
  __pyx_t_2 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":393
 * 
 *     check(pysrc)
 *     check(pydst)             # <<<<<<<<<<<<<<
 * 
 *     # pysrc.lock()
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_check); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(__pyx_v_pydst);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_pydst);
  __Pyx_GIVEREF(__pyx_v_pydst);
  __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":399
 * 
 *     colormatrix32_core(pysrc, pydst,
 *                        c00, c01, c02, c03, c04,             # <<<<<<<<<<<<<<
 *                        c10, c11, c12, c13, c14,
 *                        c20, c21, c22, c23, c24,
 */
  __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_c00); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_v_c01); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = __pyx_PyFloat_AsDouble(__pyx_v_c02); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_v_c03); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_v_c04); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/tom/ab/renpy/module/_renpy.pyx":400
 *     colormatrix32_core(pysrc, pydst,
 *                        c00, c01, c02, c03, c04,
 *                        c10, c11, c12, c13, c14,             # <<<<<<<<<<<<<<
 *                        c20, c21, c22, c23, c24,
 *                        c30, c31, c32, c33, c34)
 */
  __pyx_t_8 = __pyx_PyFloat_AsDouble(__pyx_v_c10); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_9 = __pyx_PyFloat_AsDouble(__pyx_v_c11); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_10 = __pyx_PyFloat_AsDouble(__pyx_v_c12); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_v_c13); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_v_c14); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/tom/ab/renpy/module/_renpy.pyx":401
 *                        c00, c01, c02, c03, c04,
 *                        c10, c11, c12, c13, c14,
 *                        c20, c21, c22, c23, c24,             # <<<<<<<<<<<<<<
 *                        c30, c31, c32, c33, c34)
 * 
 */
  __pyx_t_13 = __pyx_PyFloat_AsDouble(__pyx_v_c20); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_14 = __pyx_PyFloat_AsDouble(__pyx_v_c21); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_v_c22); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_16 = __pyx_PyFloat_AsDouble(__pyx_v_c23); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_17 = __pyx_PyFloat_AsDouble(__pyx_v_c24); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "/home/tom/ab/renpy/module/_renpy.pyx":402
 *                        c10, c11, c12, c13, c14,
 *                        c20, c21, c22, c23, c24,
 *                        c30, c31, c32, c33, c34)             # <<<<<<<<<<<<<<
 * 
 *     # pydst.unlock()
 */
  __pyx_t_18 = __pyx_PyFloat_AsDouble(__pyx_v_c30); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_v_c31); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_20 = __pyx_PyFloat_AsDouble(__pyx_v_c32); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_21 = __pyx_PyFloat_AsDouble(__pyx_v_c33); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_22 = __pyx_PyFloat_AsDouble(__pyx_v_c34); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  colormatrix32_core(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_3, __pyx_t_4, __pyx_t_5, __pyx_t_6, __pyx_t_7, __pyx_t_8, __pyx_t_9, __pyx_t_10, __pyx_t_11, __pyx_t_12, __pyx_t_13, __pyx_t_14, __pyx_t_15, __pyx_t_16, __pyx_t_17, __pyx_t_18, __pyx_t_19, __pyx_t_20, __pyx_t_21, __pyx_t_22);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("_renpy.colormatrix");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":408
 * 
 * 
 * def staticgray(pysrc, pydst, rmul, gmul, bmul, amul, shift, vmap):             # <<<<<<<<<<<<<<
 *     PyErr_Clear()
 *     staticgray_core(pysrc, pydst, rmul, gmul, bmul, amul, shift, vmap)
 */

static PyObject *__pyx_pf_6_renpy_staticgray(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6_renpy_staticgray(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysrc = 0;
  PyObject *__pyx_v_pydst = 0;
  PyObject *__pyx_v_rmul = 0;
  PyObject *__pyx_v_gmul = 0;
  PyObject *__pyx_v_bmul = 0;
  PyObject *__pyx_v_amul = 0;
  PyObject *__pyx_v_shift = 0;
  PyObject *__pyx_v_vmap = 0;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  char *__pyx_t_6;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_pysrc,&__pyx_kp_pydst,&__pyx_kp_rmul,&__pyx_kp_gmul,&__pyx_kp_bmul,&__pyx_kp_amul,&__pyx_kp_shift,&__pyx_kp_vmap,0};
  __Pyx_SetupRefcountContext("staticgray");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[8] = {0,0,0,0,0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
      case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrc);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pydst);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("staticgray", 1, 8, 8, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_kp_rmul);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("staticgray", 1, 8, 8, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_kp_gmul);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("staticgray", 1, 8, 8, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  4:
      values[4] = PyDict_GetItem(__pyx_kwds, __pyx_kp_bmul);
      if (likely(values[4])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("staticgray", 1, 8, 8, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  5:
      values[5] = PyDict_GetItem(__pyx_kwds, __pyx_kp_amul);
      if (likely(values[5])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("staticgray", 1, 8, 8, 5); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  6:
      values[6] = PyDict_GetItem(__pyx_kwds, __pyx_kp_shift);
      if (likely(values[6])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("staticgray", 1, 8, 8, 6); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  7:
      values[7] = PyDict_GetItem(__pyx_kwds, __pyx_kp_vmap);
      if (likely(values[7])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("staticgray", 1, 8, 8, 7); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "staticgray") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysrc = values[0];
    __pyx_v_pydst = values[1];
    __pyx_v_rmul = values[2];
    __pyx_v_gmul = values[3];
    __pyx_v_bmul = values[4];
    __pyx_v_amul = values[5];
    __pyx_v_shift = values[6];
    __pyx_v_vmap = values[7];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 8) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_pysrc = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_pydst = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_rmul = PyTuple_GET_ITEM(__pyx_args, 2);
    __pyx_v_gmul = PyTuple_GET_ITEM(__pyx_args, 3);
    __pyx_v_bmul = PyTuple_GET_ITEM(__pyx_args, 4);
    __pyx_v_amul = PyTuple_GET_ITEM(__pyx_args, 5);
    __pyx_v_shift = PyTuple_GET_ITEM(__pyx_args, 6);
    __pyx_v_vmap = PyTuple_GET_ITEM(__pyx_args, 7);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("staticgray", 1, 8, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy.staticgray");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":409
 * 
 * def staticgray(pysrc, pydst, rmul, gmul, bmul, amul, shift, vmap):
 *     PyErr_Clear()             # <<<<<<<<<<<<<<
 *     staticgray_core(pysrc, pydst, rmul, gmul, bmul, amul, shift, vmap)
 * 
 */
  PyErr_Clear();

  /* "/home/tom/ab/renpy/module/_renpy.pyx":410
 * def staticgray(pysrc, pydst, rmul, gmul, bmul, amul, shift, vmap):
 *     PyErr_Clear()
 *     staticgray_core(pysrc, pydst, rmul, gmul, bmul, amul, shift, vmap)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_rmul); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_v_gmul); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_bmul); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_amul); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_v_shift); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = __Pyx_PyBytes_AsString(__pyx_v_vmap); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  staticgray_core(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_1, __pyx_t_2, __pyx_t_3, __pyx_t_4, __pyx_t_5, __pyx_t_6);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("_renpy.staticgray");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

/* "/home/tom/ab/renpy/module/_renpy.pyx":413
 * 
 * 
 * def subpixel(pysrc, pydst, xoffset, yoffset, shift):             # <<<<<<<<<<<<<<
 * 
 *     if subpixel32(pysrc, pydst, xoffset, yoffset, shift):
 */

static PyObject *__pyx_pf_6_renpy_subpixel(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_6_renpy_subpixel(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pysrc = 0;
  PyObject *__pyx_v_pydst = 0;
  PyObject *__pyx_v_xoffset = 0;
  PyObject *__pyx_v_yoffset = 0;
  PyObject *__pyx_v_shift = 0;
  PyObject *__pyx_r = NULL;
  float __pyx_t_1;
  float __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_kp_pysrc,&__pyx_kp_pydst,&__pyx_kp_xoffset,&__pyx_kp_yoffset,&__pyx_kp_shift,0};
  __Pyx_SetupRefcountContext("subpixel");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[5] = {0,0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pysrc);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_pydst);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("subpixel", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_kp_xoffset);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("subpixel", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_kp_yoffset);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("subpixel", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  4:
      values[4] = PyDict_GetItem(__pyx_kwds, __pyx_kp_shift);
      if (likely(values[4])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("subpixel", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "subpixel") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_pysrc = values[0];
    __pyx_v_pydst = values[1];
    __pyx_v_xoffset = values[2];
    __pyx_v_yoffset = values[3];
    __pyx_v_shift = values[4];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_pysrc = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_pydst = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_xoffset = PyTuple_GET_ITEM(__pyx_args, 2);
    __pyx_v_yoffset = PyTuple_GET_ITEM(__pyx_args, 3);
    __pyx_v_shift = PyTuple_GET_ITEM(__pyx_args, 4);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("subpixel", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("_renpy.subpixel");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":415
 * def subpixel(pysrc, pydst, xoffset, yoffset, shift):
 * 
 *     if subpixel32(pysrc, pydst, xoffset, yoffset, shift):             # <<<<<<<<<<<<<<
 *         return
 * 
 */
  __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_xoffset); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_yoffset); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_shift); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = subpixel32(__pyx_v_pysrc, __pyx_v_pydst, __pyx_t_1, __pyx_t_2, __pyx_t_3);
  if (__pyx_t_4) {

    /* "/home/tom/ab/renpy/module/_renpy.pyx":416
 * 
 *     if subpixel32(pysrc, pydst, xoffset, yoffset, shift):
 *         return             # <<<<<<<<<<<<<<
 * 
 *     pydst.blit(pysrc, (int(xoffset), int(yoffset)))
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":418
 *         return
 * 
 *     pydst.blit(pysrc, (int(xoffset), int(yoffset)))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = PyObject_GetAttr(__pyx_v_pydst, __pyx_kp_blit); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_6));
  __Pyx_INCREF(__pyx_v_xoffset);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_xoffset);
  __Pyx_GIVEREF(__pyx_v_xoffset);
  __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)&PyInt_Type)), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_6));
  __Pyx_INCREF(__pyx_v_yoffset);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_yoffset);
  __Pyx_GIVEREF(__pyx_v_yoffset);
  __pyx_t_8 = PyObject_Call(((PyObject *)((PyObject*)&PyInt_Type)), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_6));
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_8));
  __Pyx_INCREF(__pyx_v_pysrc);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_pysrc);
  __Pyx_GIVEREF(__pyx_v_pysrc);
  PyTuple_SET_ITEM(__pyx_t_8, 1, ((PyObject *)__pyx_t_6));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
  __pyx_t_6 = 0;
  __pyx_t_6 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("_renpy.subpixel");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_FinishRefcountContext();
  return __pyx_r;
}

static struct PyMethodDef __pyx_methods[] = {
  {__Pyx_NAMESTR("version"), (PyCFunction)__pyx_pf_6_renpy_version, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("save_png"), (PyCFunction)__pyx_pf_6_renpy_save_png, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("pixellate"), (PyCFunction)__pyx_pf_6_renpy_pixellate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("map"), (PyCFunction)__pyx_pf_6_renpy_map, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("linmap"), (PyCFunction)__pyx_pf_6_renpy_linmap, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("alpha_munge"), (PyCFunction)__pyx_pf_6_renpy_alpha_munge, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("bilinear"), (PyCFunction)__pyx_pf_6_renpy_bilinear, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("check"), (PyCFunction)__pyx_pf_6_renpy_check, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("transform"), (PyCFunction)__pyx_pf_6_renpy_transform, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("blend"), (PyCFunction)__pyx_pf_6_renpy_blend, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("imageblend"), (PyCFunction)__pyx_pf_6_renpy_imageblend, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("colormatrix"), (PyCFunction)__pyx_pf_6_renpy_colormatrix, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("staticgray"), (PyCFunction)__pyx_pf_6_renpy_staticgray, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("subpixel"), (PyCFunction)__pyx_pf_6_renpy_subpixel, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static void __pyx_init_filenames(void); /*proto*/

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("_renpy"),
    0, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp___main__, __pyx_k___main__, sizeof(__pyx_k___main__), 1, 1, 1},
  {&__pyx_kp_surf, __pyx_k_surf, sizeof(__pyx_k_surf), 1, 1, 1},
  {&__pyx_kp_file, __pyx_k_file, sizeof(__pyx_k_file), 1, 1, 1},
  {&__pyx_kp_compress, __pyx_k_compress, sizeof(__pyx_k_compress), 1, 1, 1},
  {&__pyx_kp_pysrc, __pyx_k_pysrc, sizeof(__pyx_k_pysrc), 1, 1, 1},
  {&__pyx_kp_pydst, __pyx_k_pydst, sizeof(__pyx_k_pydst), 1, 1, 1},
  {&__pyx_kp_avgwidth, __pyx_k_avgwidth, sizeof(__pyx_k_avgwidth), 1, 1, 1},
  {&__pyx_kp_avgheight, __pyx_k_avgheight, sizeof(__pyx_k_avgheight), 1, 1, 1},
  {&__pyx_kp_outwidth, __pyx_k_outwidth, sizeof(__pyx_k_outwidth), 1, 1, 1},
  {&__pyx_kp_outheight, __pyx_k_outheight, sizeof(__pyx_k_outheight), 1, 1, 1},
  {&__pyx_kp_r, __pyx_k_r, sizeof(__pyx_k_r), 1, 1, 1},
  {&__pyx_kp_g, __pyx_k_g, sizeof(__pyx_k_g), 1, 1, 1},
  {&__pyx_kp_b, __pyx_k_b, sizeof(__pyx_k_b), 1, 1, 1},
  {&__pyx_kp_a, __pyx_k_a, sizeof(__pyx_k_a), 1, 1, 1},
  {&__pyx_kp_srcchan, __pyx_k_srcchan, sizeof(__pyx_k_srcchan), 1, 1, 1},
  {&__pyx_kp_dstchan, __pyx_k_dstchan, sizeof(__pyx_k_dstchan), 1, 1, 1},
  {&__pyx_kp_amap, __pyx_k_amap, sizeof(__pyx_k_amap), 1, 1, 1},
  {&__pyx_kp_source_xoff, __pyx_k_source_xoff, sizeof(__pyx_k_source_xoff), 1, 1, 1},
  {&__pyx_kp_source_yoff, __pyx_k_source_yoff, sizeof(__pyx_k_source_yoff), 1, 1, 1},
  {&__pyx_kp_source_width, __pyx_k_source_width, sizeof(__pyx_k_source_width), 1, 1, 1},
  {&__pyx_kp_source_height, __pyx_k_source_height, sizeof(__pyx_k_source_height), 1, 1, 1},
  {&__pyx_kp_dest_xoff, __pyx_k_dest_xoff, sizeof(__pyx_k_dest_xoff), 1, 1, 1},
  {&__pyx_kp_dest_yoff, __pyx_k_dest_yoff, sizeof(__pyx_k_dest_yoff), 1, 1, 1},
  {&__pyx_kp_dest_width, __pyx_k_dest_width, sizeof(__pyx_k_dest_width), 1, 1, 1},
  {&__pyx_kp_dest_height, __pyx_k_dest_height, sizeof(__pyx_k_dest_height), 1, 1, 1},
  {&__pyx_kp_corner_x, __pyx_k_corner_x, sizeof(__pyx_k_corner_x), 1, 1, 1},
  {&__pyx_kp_corner_y, __pyx_k_corner_y, sizeof(__pyx_k_corner_y), 1, 1, 1},
  {&__pyx_kp_xdx, __pyx_k_xdx, sizeof(__pyx_k_xdx), 1, 1, 1},
  {&__pyx_kp_ydx, __pyx_k_ydx, sizeof(__pyx_k_ydx), 1, 1, 1},
  {&__pyx_kp_xdy, __pyx_k_xdy, sizeof(__pyx_k_xdy), 1, 1, 1},
  {&__pyx_kp_ydy, __pyx_k_ydy, sizeof(__pyx_k_ydy), 1, 1, 1},
  {&__pyx_kp_pysrca, __pyx_k_pysrca, sizeof(__pyx_k_pysrca), 1, 1, 1},
  {&__pyx_kp_pysrcb, __pyx_k_pysrcb, sizeof(__pyx_k_pysrcb), 1, 1, 1},
  {&__pyx_kp_alpha, __pyx_k_alpha, sizeof(__pyx_k_alpha), 1, 1, 1},
  {&__pyx_kp_pyimg, __pyx_k_pyimg, sizeof(__pyx_k_pyimg), 1, 1, 1},
  {&__pyx_kp_aoff, __pyx_k_aoff, sizeof(__pyx_k_aoff), 1, 1, 1},
  {&__pyx_kp_c00, __pyx_k_c00, sizeof(__pyx_k_c00), 1, 1, 1},
  {&__pyx_kp_1, __pyx_k_1, sizeof(__pyx_k_1), 1, 1, 1},
  {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 1, 1, 1},
  {&__pyx_kp_3, __pyx_k_3, sizeof(__pyx_k_3), 1, 1, 1},
  {&__pyx_kp_4, __pyx_k_4, sizeof(__pyx_k_4), 1, 1, 1},
  {&__pyx_kp_5, __pyx_k_5, sizeof(__pyx_k_5), 1, 1, 1},
  {&__pyx_kp_6, __pyx_k_6, sizeof(__pyx_k_6), 1, 1, 1},
  {&__pyx_kp_7, __pyx_k_7, sizeof(__pyx_k_7), 1, 1, 1},
  {&__pyx_kp_8, __pyx_k_8, sizeof(__pyx_k_8), 1, 1, 1},
  {&__pyx_kp_9, __pyx_k_9, sizeof(__pyx_k_9), 1, 1, 1},
  {&__pyx_kp_10, __pyx_k_10, sizeof(__pyx_k_10), 1, 1, 1},
  {&__pyx_kp_11, __pyx_k_11, sizeof(__pyx_k_11), 1, 1, 1},
  {&__pyx_kp_12, __pyx_k_12, sizeof(__pyx_k_12), 1, 1, 1},
  {&__pyx_kp_13, __pyx_k_13, sizeof(__pyx_k_13), 1, 1, 1},
  {&__pyx_kp_14, __pyx_k_14, sizeof(__pyx_k_14), 1, 1, 1},
  {&__pyx_kp_15, __pyx_k_15, sizeof(__pyx_k_15), 1, 1, 1},
  {&__pyx_kp_16, __pyx_k_16, sizeof(__pyx_k_16), 1, 1, 1},
  {&__pyx_kp_17, __pyx_k_17, sizeof(__pyx_k_17), 1, 1, 1},
  {&__pyx_kp_18, __pyx_k_18, sizeof(__pyx_k_18), 1, 1, 1},
  {&__pyx_kp_19, __pyx_k_19, sizeof(__pyx_k_19), 1, 1, 1},
  {&__pyx_kp_rmul, __pyx_k_rmul, sizeof(__pyx_k_rmul), 1, 1, 1},
  {&__pyx_kp_gmul, __pyx_k_gmul, sizeof(__pyx_k_gmul), 1, 1, 1},
  {&__pyx_kp_bmul, __pyx_k_bmul, sizeof(__pyx_k_bmul), 1, 1, 1},
  {&__pyx_kp_amul, __pyx_k_amul, sizeof(__pyx_k_amul), 1, 1, 1},
  {&__pyx_kp_shift, __pyx_k_shift, sizeof(__pyx_k_shift), 1, 1, 1},
  {&__pyx_kp_vmap, __pyx_k_vmap, sizeof(__pyx_k_vmap), 1, 1, 1},
  {&__pyx_kp_xoffset, __pyx_k_xoffset, sizeof(__pyx_k_xoffset), 1, 1, 1},
  {&__pyx_kp_yoffset, __pyx_k_yoffset, sizeof(__pyx_k_yoffset), 1, 1, 1},
  {&__pyx_kp_pygame, __pyx_k_pygame, sizeof(__pyx_k_pygame), 1, 1, 1},
  {&__pyx_kp_Surface, __pyx_k_Surface, sizeof(__pyx_k_Surface), 1, 1, 1},
  {&__pyx_kp_PygameSurface, __pyx_k_PygameSurface, sizeof(__pyx_k_PygameSurface), 1, 1, 1},
  {&__pyx_kp_Exception, __pyx_k_Exception, sizeof(__pyx_k_Exception), 1, 1, 1},
  {&__pyx_kp_get_bitsize, __pyx_k_get_bitsize, sizeof(__pyx_k_get_bitsize), 1, 1, 1},
  {&__pyx_kp_get_size, __pyx_k_get_size, sizeof(__pyx_k_get_size), 1, 1, 1},
  {&__pyx_kp_check, __pyx_k_check, sizeof(__pyx_k_check), 1, 1, 1},
  {&__pyx_kp_get_shifts, __pyx_k_get_shifts, sizeof(__pyx_k_get_shifts), 1, 1, 1},
  {&__pyx_kp_blit, __pyx_k_blit, sizeof(__pyx_k_blit), 1, 1, 1},
  {&__pyx_kp_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 0},
  {&__pyx_kp_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 0},
  {&__pyx_kp_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 0},
  {&__pyx_kp_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 0},
  {&__pyx_kp_29, __pyx_k_29, sizeof(__pyx_k_29), 0, 0, 0},
  {&__pyx_kp_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 0, 0},
  {&__pyx_kp_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 0},
  {&__pyx_kp_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 0},
  {&__pyx_kp_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 0, 0},
  {&__pyx_kp_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 0},
  {&__pyx_kp_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 0},
  {&__pyx_kp_36, __pyx_k_36, sizeof(__pyx_k_36), 0, 0, 0},
  {&__pyx_kp_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 0},
  {&__pyx_kp_38, __pyx_k_38, sizeof(__pyx_k_38), 0, 0, 0},
  {&__pyx_kp_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 0},
  {&__pyx_kp_40, __pyx_k_40, sizeof(__pyx_k_40), 0, 0, 0},
  {&__pyx_kp_41, __pyx_k_41, sizeof(__pyx_k_41), 0, 0, 0},
  {&__pyx_kp_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 0, 0},
  {&__pyx_kp_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 0},
  {&__pyx_kp_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 0},
  {&__pyx_kp_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 0},
  {&__pyx_kp_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 0},
  {&__pyx_kp_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 0},
  {&__pyx_kp_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 0},
  {&__pyx_kp_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 0},
  {&__pyx_kp_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 0},
  {0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_Exception = __Pyx_GetName(__pyx_b, __pyx_kp_Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitGlobals(void) {
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_6 = PyInt_FromLong(6); if (unlikely(!__pyx_int_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_10 = PyInt_FromLong(10); if (unlikely(!__pyx_int_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_24 = PyInt_FromLong(24); if (unlikely(!__pyx_int_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_32 = PyInt_FromLong(32); if (unlikely(!__pyx_int_32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC init_renpy(void); /*proto*/
PyMODINIT_FUNC init_renpy(void)
#else
PyMODINIT_FUNC PyInit__renpy(void); /*proto*/
PyMODINIT_FUNC PyInit__renpy(void)
#endif
{
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_t_1 = NULL;
  #ifdef CYTHON_REFNANNY
  void* __pyx_refchk = NULL;
  __Pyx_Refnanny = __Pyx_ImportRefcountAPI("refnanny");
  if (!__Pyx_Refnanny) {
      PyErr_Clear();
      __Pyx_Refnanny = __Pyx_ImportRefcountAPI("Cython.Runtime.refnanny");
      if (!__Pyx_Refnanny)
          Py_FatalError("failed to import refnanny module");
  }
  __pyx_refchk = __Pyx_Refnanny->NewContext("PyMODINIT_FUNC PyInit__renpy(void)", __LINE__, __FILE__);
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Library function declarations ---*/
  __pyx_init_filenames();
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_renpy"), __pyx_methods, 0, 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__pyx_module_is_main__renpy) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_kp___main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_skip_dispatch = 0;
  /*--- Global init code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "/home/tom/ab/renpy/module/_renpy.pyx":93
 * 
 * 
 * import pygame             # <<<<<<<<<<<<<<
 * 
 * PygameSurface = pygame.Surface
 */
  __pyx_1 = __Pyx_Import(__pyx_kp_pygame, 0); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_pygame, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":95
 * import pygame
 * 
 * PygameSurface = pygame.Surface             # <<<<<<<<<<<<<<
 * 
 * def version():
 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_pygame); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_1);
  __pyx_t_1 = PyObject_GetAttr(__pyx_1, __pyx_kp_Surface); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_1); __pyx_1 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_kp_PygameSurface, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "/home/tom/ab/renpy/module/_renpy.pyx":285
 * 
 * def bilinear(pysrc, pydst,
 *              source_xoff=0.0, source_yoff=0.0, source_width=None, source_height=None,             # <<<<<<<<<<<<<<
 *              dest_xoff=0.0, dest_yoff=0.0, dest_width=None, dest_height=None):
 * 
 */
  __pyx_t_1 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_20 = __pyx_t_1;
  __pyx_t_1 = 0;
  __Pyx_GIVEREF(__pyx_k_20);
  __pyx_t_1 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_21 = __pyx_t_1;
  __pyx_t_1 = 0;
  __Pyx_GIVEREF(__pyx_k_21);

  /* "/home/tom/ab/renpy/module/_renpy.pyx":286
 * def bilinear(pysrc, pydst,
 *              source_xoff=0.0, source_yoff=0.0, source_width=None, source_height=None,
 *              dest_xoff=0.0, dest_yoff=0.0, dest_width=None, dest_height=None):             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(pysrc, PygameSurface):
 */
  __pyx_t_1 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_22 = __pyx_t_1;
  __pyx_t_1 = 0;
  __Pyx_GIVEREF(__pyx_k_22);
  __pyx_t_1 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_23 = __pyx_t_1;
  __pyx_t_1 = 0;
  __Pyx_GIVEREF(__pyx_k_23);

  /* "/home/tom/ab/renpy/module/_renpy.pyx":334
 * def transform(pysrc, pydst,
 *               corner_x, corner_y,
 *               xdx, ydx, xdy, ydy, a=1.0):             # <<<<<<<<<<<<<<
 * 
 *     check(pysrc)
 */
  __pyx_t_1 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_24 = __pyx_t_1;
  __pyx_t_1 = 0;
  __Pyx_GIVEREF(__pyx_k_24);

  /* "/home/tom/ab/renpy/module/_renpy.pyx":423
 * # Be sure to update scale.py when adding something new here!
 * 
 * core_init()             # <<<<<<<<<<<<<<
 */
  core_init();
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_1);
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("_renpy");
  Py_DECREF(__pyx_m); __pyx_m = 0;
  __pyx_L0:;
  __Pyx_FinishRefcountContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

static const char *__pyx_filenames[] = {
  "_renpy.pyx",
};

/* Runtime support code */

static void __pyx_init_filenames(void) {
  __pyx_f = __pyx_filenames;
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AS_STRING(kw_name));
        #endif
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *number, *more_or_less;

    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    number = (num_expected == 1) ? "" : "s";
    PyErr_Format(PyExc_TypeError,
        #if PY_VERSION_HEX < 0x02050000
            "%s() takes %s %d positional argument%s (%d given)",
        #else
            "%s() takes %s %zd positional argument%s (%zd given)",
        #endif
        func_name, more_or_less, num_expected, number, num_found);
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;

    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
        } else {
            #if PY_MAJOR_VERSION < 3
            if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
            #else
            if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
            #endif
                goto invalid_keyword_type;
            } else {
                for (name = first_kw_arg; *name; name++) {
                    #if PY_MAJOR_VERSION >= 3
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                        PyUnicode_Compare(**name, key) == 0) break;
                    #else
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                        _PyString_Eq(**name, key)) break;
                    #endif
                }
                if (*name) {
                    values[name-argnames] = value;
                } else {
                    /* unexpected keyword found */
                    for (name=argnames; name != first_kw_arg; name++) {
                        if (**name == key) goto arg_passed_twice;
                        #if PY_MAJOR_VERSION >= 3
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
                        #else
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                            _PyString_Eq(**name, key)) goto arg_passed_twice;
                        #endif
                    }
                    if (kwds2) {
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
                    } else {
                        goto invalid_keyword;
                    }
                }
            }
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}


static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *__import__ = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    __import__ = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!__import__)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    module = PyObject_CallFunctionObjArgs(__import__,
        name, global_dict, empty_dict, list, NULL);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(__import__);
    Py_XDECREF(empty_dict);
    return module;
}

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    /* First, check the traceback argument, replacing None with NULL. */
    if (tb == Py_None) {
        Py_DECREF(tb);
        tb = 0;
    }
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto raise_error;
    }
    /* Next, replace a missing value with None */
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        /* Raising an instance.  The value should be a dummy. */
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        /* Normalize to raise <class>, <instance> */
        Py_DECREF(value);
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                type = 0;
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) Py_TYPE(type);
            Py_INCREF(type);
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception class must be a subclass of BaseException");
                goto raise_error;
            }
        #endif
    }
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

#if PY_MAJOR_VERSION >= 3
    /* Note: this is a temporary work-around to prevent crashes in Python 3.0 */
    if ((tstate->exc_type != NULL) & (tstate->exc_type != Py_None)) {
        tmp_type = tstate->exc_type;
        tmp_value = tstate->exc_value;
        tmp_tb = tstate->exc_traceback;
        PyErr_NormalizeException(&type, &value, &tb);
        PyErr_NormalizeException(&tmp_type, &tmp_value, &tmp_tb);
        tstate->exc_type = 0;
        tstate->exc_value = 0;
        tstate->exc_traceback = 0;
        PyException_SetContext(value, tmp_value);
        Py_DECREF(tmp_type);
        Py_XDECREF(tmp_tb);
    }
#endif

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;

    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}


static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
        #if PY_VERSION_HEX < 0x02050000
                 "need more than %d value%s to unpack", (int)index,
        #else
                 "need more than %zd value%s to unpack", index,
        #endif
                 (index == 1) ? "" : "s");
}

static INLINE void __Pyx_RaiseTooManyValuesError(void) {
    PyErr_SetString(PyExc_ValueError, "too many values to unpack");
}

static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
    PyObject *item;
    if (!(item = PyIter_Next(iter))) {
        if (!PyErr_Occurred()) {
            __Pyx_RaiseNeedMoreValuesError(index);
        }
    }
    return item;
}

static int __Pyx_EndUnpack(PyObject *iter) {
    PyObject *item;
    if ((item = PyIter_Next(iter))) {
        Py_DECREF(item);
        __Pyx_RaiseTooManyValuesError();
        return -1;
    }
    else if (!PyErr_Occurred())
        return 0;
    else
        return -1;
}

static INLINE int __Pyx_StrEq(const char *s1, const char *s2) {
     while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
     return *s1 == *s2;
}

static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (unsigned char)-1;
            if (unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned char");
                return (unsigned char)-1;
            }
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to unsigned char");
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (unsigned short)-1;
            if (unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned short");
                return (unsigned short)-1;
            }
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to unsigned short");
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (unsigned int)-1;
            if (unlikely(val < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned int");
                return (unsigned int)-1;
            }
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to unsigned int");
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (char)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to char");
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (short)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to short");
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (int)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to int");
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (signed char)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to signed char");
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (signed short)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to signed short");
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (unlikely(val == -1 && PyErr_Occurred()))
                return (signed int)-1;
            PyErr_SetString(PyExc_OverflowError,
                           "value too large to convert to signed int");
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        if (unlikely(Py_SIZE(x) < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return PyLong_AsUnsignedLong(x);
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        if (unlikely(Py_SIZE(x) < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return PyLong_AsUnsignedLongLong(x);
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        return (long)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        return PyLong_AsLong(x);
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        return PyLong_AsLongLong(x);
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        return PyLong_AsLong(x);
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
        return PyLong_AsLongLong(x);
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(const char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyObject *empty_string = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;

    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(__pyx_filename);
    #else
    py_srcfile = PyUnicode_FromString(__pyx_filename);
    #endif
    if (!py_srcfile) goto bad;
    if (__pyx_clineno) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    #if PY_MAJOR_VERSION < 3
    empty_string = PyString_FromStringAndSize("", 0);
    #else
    empty_string = PyBytes_FromStringAndSize("", 0);
    #endif
    if (!empty_string) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,            /*int kwonlyargcount,*/
        #endif
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        empty_string, /*PyObject *code,*/
        __pyx_empty_tuple,  /*PyObject *consts,*/
        __pyx_empty_tuple,  /*PyObject *names,*/
        __pyx_empty_tuple,  /*PyObject *varnames,*/
        __pyx_empty_tuple,  /*PyObject *freevars,*/
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        empty_string  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(empty_string);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode && (!t->is_identifier)) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_identifier || (t->is_unicode && t->intern)) {
            *t->p = PyUnicode_InternFromString(t->s);
        } else if (t->is_unicode) {
            *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

/* Type Conversion Functions */

static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   if (x == Py_True) return 1;
   else if ((x == Py_False) | (x == Py_None)) return 0;
   else return PyObject_IsTrue(x);
}

static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


