mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Merge branch 'master' of github.com:python-imaging/Pillow
This commit is contained in:
commit
46d33257ef
|
@ -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
14
_webp.c
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user