Merge branch 'master' of github.com:python-imaging/Pillow

This commit is contained in:
Alex Clark 2013-10-24 06:02:29 -04:00
commit 46d33257ef
2 changed files with 29 additions and 19 deletions

View File

@ -48,6 +48,7 @@ def _save(im, fp, filename):
if im.mode not in _VALID_WEBP_MODES:
raise IOError("cannot write mode %s as WEBP" % image_mode)
lossless = im.encoderinfo.get("lossless", False)
quality = im.encoderinfo.get("quality", 80)
icc_profile = im.encoderinfo.get("icc_profile", "")
exif = im.encoderinfo.get("exif", "")
@ -56,6 +57,7 @@ def _save(im, fp, filename):
im.tobytes(),
im.size[0],
im.size[1],
lossless,
float(quality),
im.mode,
icc_profile,

14
_webp.c
View File

@ -13,6 +13,7 @@ PyObject* WebPEncode_wrapper(PyObject* self, PyObject* args)
{
int width;
int height;
int lossless;
float quality_factor;
uint8_t *rgb;
uint8_t *icc_bytes;
@ -24,22 +25,29 @@ PyObject* WebPEncode_wrapper(PyObject* self, PyObject* args)
Py_ssize_t exif_size;
size_t ret_size;
if (!PyArg_ParseTuple(args, "s#iifss#s#",
(char**)&rgb, &size, &width, &height, &quality_factor, &mode,
if (!PyArg_ParseTuple(args, "s#iiOfss#s#",
(char**)&rgb, &size, &width, &height, &lossless, &quality_factor, &mode,
&icc_bytes, &icc_size, &exif_bytes, &exif_size)) {
Py_RETURN_NONE;
}
if (strcmp(mode, "RGBA")==0){
if (size < width * height * 4){
Py_RETURN_NONE;
}
if (PyObject_IsTrue(lossless)) {
ret_size = WebPEncodeLosslessRGBA(rgb, width, height, 4* width, &output);
} else {
ret_size = WebPEncodeRGBA(rgb, width, height, 4* width, quality_factor, &output);
}
} else if (strcmp(mode, "RGB")==0){
if (size < width * height * 3){
Py_RETURN_NONE;
}
if (PyObject_IsTrue(lossless)) {
ret_size = WebPEncodeLosslessRGB(rgb, width, height, 3* width, &output);
} else {
ret_size = WebPEncodeRGB(rgb, width, height, 3* width, quality_factor, &output);
}
} else {
Py_RETURN_NONE;
}