mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Partial work to add a wrapper for WebPGetFeatures to correctly support #204
This commit is contained in:
parent
1344610a52
commit
5a0308cc19
36
_webp.c
36
_webp.c
|
@ -2,6 +2,41 @@
|
||||||
#include "py3.h"
|
#include "py3.h"
|
||||||
#include <webp/encode.h>
|
#include <webp/encode.h>
|
||||||
#include <webp/decode.h>
|
#include <webp/decode.h>
|
||||||
|
#include <webp/types.h>
|
||||||
|
|
||||||
|
|
||||||
|
PyObject* WebPGetFeatures_wrapper(PyObject* self, PyObject* args)
|
||||||
|
{
|
||||||
|
PyBytesObject *webp_string;
|
||||||
|
const uint8_t* webp = NULL;
|
||||||
|
VP8StatusCode vp8_status_code = VP8_STATUS_OK;
|
||||||
|
Py_ssize_t size;
|
||||||
|
WebPBitstreamFeatures* const features;
|
||||||
|
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "S", &webp_string)) {
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyBytes_AsStringAndSize((PyObject *) webp_string, (char**)&webp, &size);
|
||||||
|
|
||||||
|
vp8_status_code = WebPGetFeatures(webp, size, features);
|
||||||
|
|
||||||
|
if (vp8_status_code == VP8_STATUS_OK) {
|
||||||
|
printf("%i", features->has_alpha);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// TODO: raise some sort of error
|
||||||
|
printf("Error occured checking webp file with code: %d\n", vp8_status_code);
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
|
}
|
||||||
|
|
||||||
|
free((void*)webp);
|
||||||
|
return Py_BuildValue("b", features->has_alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PyObject* WebPEncodeRGB_wrapper(PyObject* self, PyObject* args)
|
PyObject* WebPEncodeRGB_wrapper(PyObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
|
@ -127,6 +162,7 @@ PyObject* WebPDecodeRGBA_wrapper(PyObject* self, PyObject* args)
|
||||||
|
|
||||||
static PyMethodDef webpMethods[] =
|
static PyMethodDef webpMethods[] =
|
||||||
{
|
{
|
||||||
|
{"WebPGetFeatures", WebPGetFeatures_wrapper, METH_VARARGS, "WebPGetFeatures"},
|
||||||
{"WebPEncodeRGB", WebPEncodeRGB_wrapper, METH_VARARGS, "WebPEncodeRGB"},
|
{"WebPEncodeRGB", WebPEncodeRGB_wrapper, METH_VARARGS, "WebPEncodeRGB"},
|
||||||
{"WebPEncodeRGBA", WebPEncodeRGBA_wrapper, METH_VARARGS, "WebPEncodeRGBA"},
|
{"WebPEncodeRGBA", WebPEncodeRGBA_wrapper, METH_VARARGS, "WebPEncodeRGBA"},
|
||||||
{"WebPDecodeRGB", WebPDecodeRGB_wrapper, METH_VARARGS, "WebPDecodeRGB"},
|
{"WebPDecodeRGB", WebPDecodeRGB_wrapper, METH_VARARGS, "WebPDecodeRGB"},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user