mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 10:56:18 +03:00
use accurate im->linesize instead of strlen(mode) approximation
This commit is contained in:
parent
d55557152b
commit
0990dadd6d
|
@ -371,17 +371,8 @@ ImagingAllocateBlock(Imaging im)
|
||||||
Imaging
|
Imaging
|
||||||
ImagingNew(const char* mode, int xsize, int ysize)
|
ImagingNew(const char* mode, int xsize, int ysize)
|
||||||
{
|
{
|
||||||
int bytes;
|
|
||||||
Imaging im;
|
Imaging im;
|
||||||
|
|
||||||
if (strlen(mode) == 1) {
|
|
||||||
if (mode[0] == 'F' || mode[0] == 'I')
|
|
||||||
bytes = 4;
|
|
||||||
else
|
|
||||||
bytes = 1;
|
|
||||||
} else
|
|
||||||
bytes = strlen(mode) || 1; /* close enough */
|
|
||||||
|
|
||||||
if (xsize < 0 || ysize < 0) {
|
if (xsize < 0 || ysize < 0) {
|
||||||
return (Imaging) ImagingError_ValueError("bad image size");
|
return (Imaging) ImagingError_ValueError("bad image size");
|
||||||
}
|
}
|
||||||
|
@ -390,7 +381,7 @@ ImagingNew(const char* mode, int xsize, int ysize)
|
||||||
if ( ! im)
|
if ( ! im)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((int64_t) xsize * (int64_t) ysize <= THRESHOLD / bytes) {
|
if (im->ysize && im->linesize <= THRESHOLD / im->ysize) {
|
||||||
if (ImagingAllocateBlock(im)) {
|
if (ImagingAllocateBlock(im)) {
|
||||||
return im;
|
return im;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user