3
#include <webp/encode.h>
4
#include <webp/decode.h>
6
PyObject* WebPEncodeRGB_wrapper(PyObject* self, PyObject* args)
8
PyBytesObject *rgb_string;
18
if (!PyArg_ParseTuple(args, "Siiif", &rgb_string, &width, &height, &stride, &quality_factor)) {
23
PyBytes_AsStringAndSize((PyObject *) rgb_string, &rgb, &size);
25
if (stride * height > size) {
30
ret_size = WebPEncodeRGB(rgb, width, height, stride, quality_factor, &output);
32
PyObject *ret = PyBytes_FromStringAndSize(output, ret_size);
41
PyObject* WebPDecodeRGB_wrapper(PyObject* self, PyObject* args)
43
PyBytesObject *webp_string;
52
if (!PyArg_ParseTuple(args, "S", &webp_string)) {
57
PyBytes_AsStringAndSize((PyObject *) webp_string, &webp, &size);
59
output = WebPDecodeRGB(webp, size, &width, &height);
61
ret = PyBytes_FromStringAndSize(output, width * height * 3);
63
return Py_BuildValue("Sii", ret, width, height);
66
static PyMethodDef webpMethods[] =
68
{"WebPEncodeRGB", WebPEncodeRGB_wrapper, METH_VARARGS, "WebPEncodeRGB"},
69
{"WebPDecodeRGB", WebPDecodeRGB_wrapper, METH_VARARGS, "WebPEncodeRGB"},
73
#if PY_VERSION_HEX >= 0x03000000
78
static PyModuleDef module_def = {
79
PyModuleDef_HEAD_INIT,
83
webpMethods, /* m_methods */
86
m = PyModule_Create(&module_def);
94
m = Py_InitModule("_webp", webpMethods);