mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +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:
|
if im.mode not in _VALID_WEBP_MODES:
|
||||||
raise IOError("cannot write mode %s as WEBP" % image_mode)
|
raise IOError("cannot write mode %s as WEBP" % image_mode)
|
||||||
|
|
||||||
|
lossless = im.encoderinfo.get("lossless", False)
|
||||||
quality = im.encoderinfo.get("quality", 80)
|
quality = im.encoderinfo.get("quality", 80)
|
||||||
icc_profile = im.encoderinfo.get("icc_profile", "")
|
icc_profile = im.encoderinfo.get("icc_profile", "")
|
||||||
exif = im.encoderinfo.get("exif", "")
|
exif = im.encoderinfo.get("exif", "")
|
||||||
|
@ -56,6 +57,7 @@ def _save(im, fp, filename):
|
||||||
im.tobytes(),
|
im.tobytes(),
|
||||||
im.size[0],
|
im.size[0],
|
||||||
im.size[1],
|
im.size[1],
|
||||||
|
lossless,
|
||||||
float(quality),
|
float(quality),
|
||||||
im.mode,
|
im.mode,
|
||||||
icc_profile,
|
icc_profile,
|
||||||
|
|
14
_webp.c
14
_webp.c
|
@ -13,6 +13,7 @@ PyObject* WebPEncode_wrapper(PyObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
|
int lossless;
|
||||||
float quality_factor;
|
float quality_factor;
|
||||||
uint8_t *rgb;
|
uint8_t *rgb;
|
||||||
uint8_t *icc_bytes;
|
uint8_t *icc_bytes;
|
||||||
|
@ -24,22 +25,29 @@ PyObject* WebPEncode_wrapper(PyObject* self, PyObject* args)
|
||||||
Py_ssize_t exif_size;
|
Py_ssize_t exif_size;
|
||||||
size_t ret_size;
|
size_t ret_size;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s#iifss#s#",
|
if (!PyArg_ParseTuple(args, "s#iiOfss#s#",
|
||||||
(char**)&rgb, &size, &width, &height, &quality_factor, &mode,
|
(char**)&rgb, &size, &width, &height, &lossless, &quality_factor, &mode,
|
||||||
&icc_bytes, &icc_size, &exif_bytes, &exif_size)) {
|
&icc_bytes, &icc_size, &exif_bytes, &exif_size)) {
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(mode, "RGBA")==0){
|
if (strcmp(mode, "RGBA")==0){
|
||||||
if (size < width * height * 4){
|
if (size < width * height * 4){
|
||||||
Py_RETURN_NONE;
|
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);
|
ret_size = WebPEncodeRGBA(rgb, width, height, 4* width, quality_factor, &output);
|
||||||
|
}
|
||||||
} else if (strcmp(mode, "RGB")==0){
|
} else if (strcmp(mode, "RGB")==0){
|
||||||
if (size < width * height * 3){
|
if (size < width * height * 3){
|
||||||
Py_RETURN_NONE;
|
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);
|
ret_size = WebPEncodeRGB(rgb, width, height, 3* width, quality_factor, &output);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user