use accurate im->linesize instead of strlen(mode) approximation

This commit is contained in:
Alexander 2017-08-06 01:31:31 +03:00
parent d55557152b
commit 0990dadd6d

View File

@ -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;
} }