/*
 * Module code.
 *
 * Generated by SIP 6.15.3
 */

#include "sipAPIimageops.h"

#line 33 "/usr/lib/python3.14/site-packages/PyQt6/bindings/QtGui/qimage.sip"
#include <qimage.h>
#line 12 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"
#line 26 "/usr/lib/python3.14/site-packages/PyQt6/bindings/QtGui/qcolor.sip"
#include <qcolor.h>
#line 15 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"
#line 890 "/usr/lib/python3.14/site-packages/PyQt6/bindings/QtCore/qpycore_qlist.sip"
#include <qlist.h>
#line 18 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

/* Define the strings used by this module. */
const char sipStrings_imageops[] = {
    'l', 'o', 'a', 'd', '_', 'f', 'r', 'o', 'm', '_', 'd', 'a', 't', 'a', '_', 'w', 'i', 't', 'h', 'o', 'u', 't', '_', 'g', 'i', 'l', 0,
    'h', 'a', 's', '_', 't', 'r', 'a', 'n', 's', 'p', 'a', 'r', 'e', 'n', 't', '_', 'p', 'i', 'x', 'e', 'l', 's', 0,
    'g', 'a', 'u', 's', 's', 'i', 'a', 'n', '_', 's', 'h', 'a', 'r', 'p', 'e', 'n', 0,
    'd', 'o', 'm', 'i', 'n', 'a', 'n', 't', '_', 'c', 'o', 'l', 'o', 'r', 0,
    'o', 'r', 'd', 'e', 'r', 'e', 'd', '_', 'd', 'i', 't', 'h', 'e', 'r', 0,
    'r', 'e', 'm', 'o', 'v', 'e', '_', 'b', 'o', 'r', 'd', 'e', 'r', 's', 0,
    'g', 'a', 'u', 's', 's', 'i', 'a', 'n', '_', 'b', 'l', 'u', 'r', 0,
    't', 'e', 'x', 't', 'u', 'r', 'e', '_', 'i', 'm', 'a', 'g', 'e', 0,
    's', 'e', 't', '_', 'o', 'p', 'a', 'c', 'i', 't', 'y', 0,
    'd', 'e', 's', 'p', 'e', 'c', 'k', 'l', 'e', 0,
    'g', 'r', 'a', 'y', 's', 'c', 'a', 'l', 'e', 0,
    'n', 'o', 'r', 'm', 'a', 'l', 'i', 'z', 'e', 0,
    'o', 'i', 'l', '_', 'p', 'a', 'i', 'n', 't', 0,
    'i', 'm', 'a', 'g', 'e', 'o', 'p', 's', 0,
    'q', 'u', 'a', 'n', 't', 'i', 'z', 'e', 0,
    'o', 'v', 'e', 'r', 'l', 'a', 'y', 0,
};
#line 9 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
#include <imageops.h>
#include <stdexcept>
#define IMAGEOPS_PREFIX \
            if (a0->isNull()) { PyErr_SetString(PyExc_ValueError, "Cannot operate on null QImage"); return NULL; } \
            try {
#define IMAGEOPS_SUFFIX \
        } catch (std::out_of_range &exc) { PyErr_SetString(PyExc_ValueError, exc.what()); return NULL; \
        } catch (std::bad_alloc &) { PyErr_NoMemory(); return NULL; \
        } catch (std::exception &exc) { PyErr_SetString(PyExc_Exception, exc.what()); return NULL; \
        } catch (...) { PyErr_SetString(PyExc_RuntimeError, "unknown error"); return NULL;}
#line 50 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"


PyDoc_STRVAR(doc_ordered_dither, "ordered_dither(image: QImage) -> QImage");

extern "C" {static PyObject *func_ordered_dither(PyObject *, PyObject *);}
static PyObject *func_ordered_dither(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9", sipType_QImage, &a0))
        {
            ::QImage*sipRes = 0;

#line 111 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
			sipRes = new QImage(ordered_dither(*a0));
        IMAGEOPS_SUFFIX
#line 71 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

            return sipConvertFromNewType(sipRes, sipType_QImage, SIP_NULLPTR);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_ordered_dither, doc_ordered_dither);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_texture_image, "texture_image(image: QImage, texturei: QImage) -> QImage");

extern "C" {static PyObject *func_texture_image(PyObject *, PyObject *);}
static PyObject *func_texture_image(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;
        const ::QImage* a1;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9J9", sipType_QImage, &a0, sipType_QImage, &a1))
        {
            ::QImage*sipRes = 0;

#line 104 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
			sipRes = new QImage(texture_image(*a0, *a1));
        IMAGEOPS_SUFFIX
#line 103 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

            return sipConvertFromNewType(sipRes, sipType_QImage, SIP_NULLPTR);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_texture_image, doc_texture_image);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_set_opacity, "set_opacity(image: QImage, alpha: float) -> QImage");

extern "C" {static PyObject *func_set_opacity(PyObject *, PyObject *);}
static PyObject *func_set_opacity(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;
        double a1;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9d", sipType_QImage, &a0, &a1))
        {
            ::QImage*sipRes = 0;

#line 97 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
			sipRes = new QImage(set_opacity(*a0, a1));
        IMAGEOPS_SUFFIX
#line 135 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

            return sipConvertFromNewType(sipRes, sipType_QImage, SIP_NULLPTR);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_set_opacity, doc_set_opacity);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_has_transparent_pixels, "has_transparent_pixels(image: QImage) -> bool");

extern "C" {static PyObject *func_has_transparent_pixels(PyObject *, PyObject *);}
static PyObject *func_has_transparent_pixels(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9", sipType_QImage, &a0))
        {
            bool sipRes = 0;

#line 90 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
			sipRes = has_transparent_pixels(*a0);
        IMAGEOPS_SUFFIX
#line 166 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

            return PyBool_FromLong(sipRes);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_has_transparent_pixels, doc_has_transparent_pixels);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_quantize, "quantize(image: QImage, maximum_colors: int, dither: bool, palette: Iterable[int]) -> QImage");

extern "C" {static PyObject *func_quantize(PyObject *, PyObject *);}
static PyObject *func_quantize(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;
        uint a1;
        bool a2;
        const ::QList< ::QRgb>* a3;
        int a3State = 0;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9ubJ1", sipType_QImage, &a0, &a1, &a2, sipType_QList_1900, &a3, &a3State))
        {
            ::QImage*sipRes = 0;

#line 83 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
			sipRes = new QImage(quantize(*a0, a1, a2, *a3));
        IMAGEOPS_SUFFIX
#line 201 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"
            sipReleaseType(const_cast< ::QList< ::QRgb> *>(a3), sipType_QList_1900, a3State);

            return sipConvertFromNewType(sipRes, sipType_QImage, SIP_NULLPTR);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_quantize, doc_quantize);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_dominant_color, "dominant_color(image: QImage) -> QColor");

extern "C" {static PyObject *func_dominant_color(PyObject *, PyObject *);}
static PyObject *func_dominant_color(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9", sipType_QImage, &a0))
        {
            ::QColor*sipRes;

            Py_BEGIN_ALLOW_THREADS
            try
            {
            sipRes = new ::QColor(dominant_color(*a0));
            }
            catch (...)
            {
                Py_BLOCK_THREADS

                void *sipExcState = SIP_NULLPTR;
                sipExceptionHandler sipExcHandler;
                std::exception_ptr sipExcPtr = std::current_exception();

                while ((sipExcHandler = sipNextExceptionHandler(&sipExcState)) != SIP_NULLPTR)
                    if (sipExcHandler(sipExcPtr))
                        return SIP_NULLPTR;

                sipRaiseUnknownException();
                return SIP_NULLPTR;
            }
            Py_END_ALLOW_THREADS

            return sipConvertFromNewType(sipRes, sipType_QColor, SIP_NULLPTR);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_dominant_color, doc_dominant_color);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_oil_paint, "oil_paint(image: QImage, radius: float = -1, high_quality: bool = True) -> QImage");

extern "C" {static PyObject *func_oil_paint(PyObject *, PyObject *);}
static PyObject *func_oil_paint(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;
        float a1 = -1;
        bool a2 = 1;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9|fb", sipType_QImage, &a0, &a1, &a2))
        {
            ::QImage*sipRes = 0;

#line 74 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
			sipRes = new QImage(oil_paint(*a0, a1, a2));
        IMAGEOPS_SUFFIX
#line 282 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

            return sipConvertFromNewType(sipRes, sipType_QImage, SIP_NULLPTR);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_oil_paint, doc_oil_paint);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_normalize, "normalize(image: QImage) -> QImage");

extern "C" {static PyObject *func_normalize(PyObject *, PyObject *);}
static PyObject *func_normalize(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9", sipType_QImage, &a0))
        {
            ::QImage*sipRes = 0;

#line 67 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
			sipRes = new QImage(normalize(*a0));
        IMAGEOPS_SUFFIX
#line 313 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

            return sipConvertFromNewType(sipRes, sipType_QImage, SIP_NULLPTR);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_normalize, doc_normalize);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_overlay, "overlay(image: QImage, canvas: QImage, left: int, top: int)");

extern "C" {static PyObject *func_overlay(PyObject *, PyObject *);}
static PyObject *func_overlay(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;
        ::QImage* a1;
        uint a2;
        uint a3;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9J9uu", sipType_QImage, &a0, sipType_QImage, &a1, &a2, &a3))
        {
#line 60 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
            overlay(*a0, *a1, a2, a3);
        IMAGEOPS_SUFFIX
#line 345 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_overlay, doc_overlay);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_despeckle, "despeckle(image: QImage) -> QImage");

extern "C" {static PyObject *func_despeckle(PyObject *, PyObject *);}
static PyObject *func_despeckle(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9", sipType_QImage, &a0))
        {
            ::QImage*sipRes = 0;

#line 53 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
			sipRes = new QImage(despeckle(*a0));
        IMAGEOPS_SUFFIX
#line 377 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

            return sipConvertFromNewType(sipRes, sipType_QImage, SIP_NULLPTR);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_despeckle, doc_despeckle);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_gaussian_blur, "gaussian_blur(img: QImage, radius: float, sigma: float) -> QImage");

extern "C" {static PyObject *func_gaussian_blur(PyObject *, PyObject *);}
static PyObject *func_gaussian_blur(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;
        float a1;
        float a2;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9ff", sipType_QImage, &a0, &a1, &a2))
        {
            ::QImage*sipRes = 0;

#line 46 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
			sipRes = new QImage(gaussian_blur(*a0, a1, a2));
        IMAGEOPS_SUFFIX
#line 410 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

            return sipConvertFromNewType(sipRes, sipType_QImage, SIP_NULLPTR);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_gaussian_blur, doc_gaussian_blur);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_gaussian_sharpen, "gaussian_sharpen(img: QImage, radius: float, sigma: float, high_quality: bool = True) -> QImage");

extern "C" {static PyObject *func_gaussian_sharpen(PyObject *, PyObject *);}
static PyObject *func_gaussian_sharpen(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;
        float a1;
        float a2;
        bool a3 = 1;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9ff|b", sipType_QImage, &a0, &a1, &a2, &a3))
        {
            ::QImage*sipRes = 0;

#line 39 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
			sipRes = new QImage(gaussian_sharpen(*a0, a1, a2, a3));
        IMAGEOPS_SUFFIX
#line 444 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

            return sipConvertFromNewType(sipRes, sipType_QImage, SIP_NULLPTR);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_gaussian_sharpen, doc_gaussian_sharpen);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_grayscale, "grayscale(image: QImage) -> QImage|None");

extern "C" {static PyObject *func_grayscale(PyObject *, PyObject *);}
static PyObject *func_grayscale(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9", sipType_QImage, &a0))
        {
            ::QImage*sipRes = 0;

#line 32 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
			sipRes = new QImage(grayscale(*a0));
        IMAGEOPS_SUFFIX
#line 475 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

            return sipConvertFromType(sipRes, sipType_QImage, SIP_NULLPTR);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_grayscale, doc_grayscale);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_remove_borders, "remove_borders(image: QImage, fuzz: float) -> QImage|None");

extern "C" {static PyObject *func_remove_borders(PyObject *, PyObject *);}
static PyObject *func_remove_borders(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        const ::QImage* a0;
        double a1;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9d", sipType_QImage, &a0, &a1))
        {
            ::QImage*sipRes = 0;

#line 25 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/imageops.sip"
        IMAGEOPS_PREFIX
			sipRes = new QImage(remove_borders(*a0, a1));
        IMAGEOPS_SUFFIX
#line 507 "/build/calibre/src/calibre-9.11.0/build/pyqt/imageops/build/imageops/sipimageopscmodule.cpp"

            return sipConvertFromType(sipRes, sipType_QImage, SIP_NULLPTR);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_remove_borders, doc_remove_borders);

    return SIP_NULLPTR;
}


PyDoc_STRVAR(doc_load_from_data_without_gil, "load_from_data_without_gil(image: QImage, data: PyQt6.sip.array[bytes]) -> bool");

extern "C" {static PyObject *func_load_from_data_without_gil(PyObject *, PyObject *);}
static PyObject *func_load_from_data_without_gil(PyObject *, PyObject *sipArgs)
{
    PyObject *sipParseErr = SIP_NULLPTR;

    {
        ::QImage* a0;
        const char* a1;
        Py_ssize_t a2;

        if (sipParseArgs(&sipParseErr, sipArgs, "J9k", sipType_QImage, &a0, &a1, &a2))
        {
            bool sipRes;

            Py_BEGIN_ALLOW_THREADS
            try
            {
            sipRes = load_from_data_without_gil(*a0, a1, (size_t)a2);
            }
            catch (...)
            {
                Py_BLOCK_THREADS

                void *sipExcState = SIP_NULLPTR;
                sipExceptionHandler sipExcHandler;
                std::exception_ptr sipExcPtr = std::current_exception();

                while ((sipExcHandler = sipNextExceptionHandler(&sipExcState)) != SIP_NULLPTR)
                    if (sipExcHandler(sipExcPtr))
                        return SIP_NULLPTR;

                sipRaiseUnknownException();
                return SIP_NULLPTR;
            }
            Py_END_ALLOW_THREADS

            return PyBool_FromLong(sipRes);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoFunction(sipParseErr, sipName_load_from_data_without_gil, doc_load_from_data_without_gil);

    return SIP_NULLPTR;
}


/* This defines the types that this module needs to import from QtCore. */
sipImportedTypeDef sipImportedTypes_imageops_QtCore[] = {
    {"QList<uint>"},
    {SIP_NULLPTR}
};


/* This defines the types that this module needs to import from QtGui. */
sipImportedTypeDef sipImportedTypes_imageops_QtGui[] = {
    {"QColor"},
    {"QImage"},
    {SIP_NULLPTR}
};


/* This defines the modules that this module needs to import. */
static sipImportedModuleDef importsTable[] = {
    {"PyQt6.QtCore", sipImportedTypes_imageops_QtCore, SIP_NULLPTR, SIP_NULLPTR},
    {"PyQt6.QtGui", sipImportedTypes_imageops_QtGui, SIP_NULLPTR, SIP_NULLPTR},
    {SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR}
};


/* This defines this module. */
sipExportedModuleDef sipModuleAPI_imageops = {
    SIP_NULLPTR,
    8,
    sipNameNr_imageops,
    0,
    sipStrings_imageops,
    importsTable,
    0,
    SIP_NULLPTR,
    SIP_NULLPTR,
    0,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    {SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR},
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
    SIP_NULLPTR,
};


/* The SIP API and the APIs of any imported modules. */
const sipAPIDef *sipAPI_imageops;

sip_qt_metaobject_func sip_imageops_qt_metaobject;
sip_qt_metacall_func sip_imageops_qt_metacall;
sip_qt_metacast_func sip_imageops_qt_metacast;


/* The Python module initialisation function. */
#if defined(SIP_STATIC_MODULE)
extern "C" PyObject *PyInit_imageops()
#else
PyMODINIT_FUNC PyInit_imageops()
#endif
{
    static PyMethodDef sip_methods[] = {
        {sipName_ordered_dither, func_ordered_dither, METH_VARARGS, doc_ordered_dither},
        {sipName_texture_image, func_texture_image, METH_VARARGS, doc_texture_image},
        {sipName_set_opacity, func_set_opacity, METH_VARARGS, doc_set_opacity},
        {sipName_has_transparent_pixels, func_has_transparent_pixels, METH_VARARGS, doc_has_transparent_pixels},
        {sipName_quantize, func_quantize, METH_VARARGS, doc_quantize},
        {sipName_dominant_color, func_dominant_color, METH_VARARGS, doc_dominant_color},
        {sipName_oil_paint, func_oil_paint, METH_VARARGS, doc_oil_paint},
        {sipName_normalize, func_normalize, METH_VARARGS, doc_normalize},
        {sipName_overlay, func_overlay, METH_VARARGS, doc_overlay},
        {sipName_despeckle, func_despeckle, METH_VARARGS, doc_despeckle},
        {sipName_gaussian_blur, func_gaussian_blur, METH_VARARGS, doc_gaussian_blur},
        {sipName_gaussian_sharpen, func_gaussian_sharpen, METH_VARARGS, doc_gaussian_sharpen},
        {sipName_grayscale, func_grayscale, METH_VARARGS, doc_grayscale},
        {sipName_remove_borders, func_remove_borders, METH_VARARGS, doc_remove_borders},
        {sipName_load_from_data_without_gil, func_load_from_data_without_gil, METH_VARARGS, doc_load_from_data_without_gil},
        {SIP_NULLPTR, SIP_NULLPTR, 0, SIP_NULLPTR}
    };
    static PyModuleDef sip_module_def = {
        PyModuleDef_HEAD_INIT,
        "imageops",
        SIP_NULLPTR,
        -1,
        sip_methods,
        SIP_NULLPTR,
        SIP_NULLPTR,
        SIP_NULLPTR,
        SIP_NULLPTR
    };

    PyObject *sipModule, *sipModuleDict;
    PyObject *sip_sipmod, *sip_capiobj;

    /* Initialise the module and get it's dictionary. */
    if ((sipModule = PyModule_Create(&sip_module_def)) == SIP_NULLPTR)
        return SIP_NULLPTR;

    sipModuleDict = PyModule_GetDict(sipModule);

    /* Get the SIP module's API. */
    if ((sip_sipmod = PyImport_ImportModule("PyQt6.sip")) == SIP_NULLPTR)
    {
        Py_DECREF(sipModule);
        return SIP_NULLPTR;
    }

    sip_capiobj = PyDict_GetItemString(PyModule_GetDict(sip_sipmod), "_C_API");
    Py_DECREF(sip_sipmod);

    if (sip_capiobj == SIP_NULLPTR || !PyCapsule_CheckExact(sip_capiobj))
    {
        PyErr_SetString(PyExc_AttributeError, "PyQt6.sip._C_API is missing or has the wrong type");
        Py_DECREF(sipModule);
        return SIP_NULLPTR;
    }

    sipAPI_imageops = reinterpret_cast<const sipAPIDef *>(PyCapsule_GetPointer(sip_capiobj, "PyQt6.sip._C_API"));

    if (sipAPI_imageops == SIP_NULLPTR)
    {
        Py_DECREF(sipModule);
        return SIP_NULLPTR;
    }

    /* Export the module and publish it's API. */
    if (sipExportModule(&sipModuleAPI_imageops, 13, 8, 0) < 0)
    {
        Py_DECREF(sipModule);
        return SIP_NULLPTR;
    }


    sip_imageops_qt_metaobject = (sip_qt_metaobject_func)sipImportSymbol("qtcore_qt_metaobject");
    sip_imageops_qt_metacall = (sip_qt_metacall_func)sipImportSymbol("qtcore_qt_metacall");
    sip_imageops_qt_metacast = (sip_qt_metacast_func)sipImportSymbol("qtcore_qt_metacast");

    if (!sip_imageops_qt_metacast)
        Py_FatalError("Unable to import qtcore_qt_metacast");

    /* Initialise the module now all its dependencies have been set up. */
    if (sipInitModule(&sipModuleAPI_imageops, sipModuleDict) < 0)
    {
        Py_DECREF(sipModule);
        return SIP_NULLPTR;
    }

    return sipModule;
}
