mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 17:54:32 +03:00
rename ImagingNewBlock → ImagingAllocateBlock
rename ImagingNewArray → ImagingAllocateArray new utility function with old name ImagingNewBlock call ImagingNewPrologue outside of ImagingAllocateBlock and ImagingAllocateArray
This commit is contained in:
parent
eafa258bd1
commit
d55557152b
|
@ -163,7 +163,6 @@ extern Imaging ImagingNew2(const char* mode, Imaging imOut, Imaging imIn);
|
|||
extern void ImagingDelete(Imaging im);
|
||||
|
||||
extern Imaging ImagingNewBlock(const char* mode, int xsize, int ysize);
|
||||
extern Imaging ImagingNewArray(const char* mode, int xsize, int ysize);
|
||||
extern Imaging ImagingNewMap(const char* filename, int readonly,
|
||||
const char* mode, int xsize, int ysize);
|
||||
|
||||
|
|
|
@ -277,18 +277,13 @@ ImagingDestroyArray(Imaging im)
|
|||
}
|
||||
|
||||
Imaging
|
||||
ImagingNewArray(const char *mode, int xsize, int ysize)
|
||||
ImagingAllocateArray(Imaging im)
|
||||
{
|
||||
Imaging im;
|
||||
ImagingSectionCookie cookie;
|
||||
|
||||
int y;
|
||||
char* p;
|
||||
|
||||
im = ImagingNewPrologue(mode, xsize, ysize);
|
||||
if (!im)
|
||||
return NULL;
|
||||
|
||||
ImagingSectionEnter(&cookie);
|
||||
|
||||
/* Allocate image as an array of lines */
|
||||
|
@ -305,7 +300,6 @@ ImagingNewArray(const char *mode, int xsize, int ysize)
|
|||
ImagingSectionLeave(&cookie);
|
||||
|
||||
if (y != im->ysize) {
|
||||
ImagingDelete(im);
|
||||
return (Imaging) ImagingError_MemoryError();
|
||||
}
|
||||
|
||||
|
@ -327,16 +321,10 @@ ImagingDestroyBlock(Imaging im)
|
|||
}
|
||||
|
||||
Imaging
|
||||
ImagingNewBlock(const char *mode, int xsize, int ysize)
|
||||
ImagingAllocateBlock(Imaging im)
|
||||
{
|
||||
Imaging im;
|
||||
Py_ssize_t y, i;
|
||||
|
||||
im = ImagingNewPrologue(mode, xsize, ysize);
|
||||
if ( ! im) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* We shouldn't overflow, since the threshold defined
|
||||
below says that we're only going to allocate max 4M
|
||||
here before going to the array allocator. Check anyway.
|
||||
|
@ -344,7 +332,6 @@ ImagingNewBlock(const char *mode, int xsize, int ysize)
|
|||
if (im->linesize &&
|
||||
im->ysize > INT_MAX / im->linesize) {
|
||||
/* punt if we're going to overflow */
|
||||
ImagingDelete(im);
|
||||
return (Imaging) ImagingError_MemoryError();
|
||||
}
|
||||
|
||||
|
@ -359,7 +346,6 @@ ImagingNewBlock(const char *mode, int xsize, int ysize)
|
|||
}
|
||||
|
||||
if ( ! im->block) {
|
||||
ImagingDelete(im);
|
||||
return (Imaging) ImagingError_MemoryError();
|
||||
}
|
||||
|
||||
|
@ -400,15 +386,41 @@ ImagingNew(const char* mode, int xsize, int ysize)
|
|||
return (Imaging) ImagingError_ValueError("bad image size");
|
||||
}
|
||||
|
||||
im = ImagingNewPrologue(mode, xsize, ysize);
|
||||
if (!im)
|
||||
return NULL;
|
||||
|
||||
if ((int64_t) xsize * (int64_t) ysize <= THRESHOLD / bytes) {
|
||||
im = ImagingNewBlock(mode, xsize, ysize);
|
||||
if (im)
|
||||
if (ImagingAllocateBlock(im)) {
|
||||
return im;
|
||||
}
|
||||
/* assume memory error; try allocating in array mode instead */
|
||||
ImagingError_Clear();
|
||||
}
|
||||
|
||||
return ImagingNewArray(mode, xsize, ysize);
|
||||
if (ImagingAllocateArray(im)) {
|
||||
return im;
|
||||
}
|
||||
|
||||
ImagingDelete(im);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Imaging
|
||||
ImagingNewBlock(const char* mode, int xsize, int ysize)
|
||||
{
|
||||
Imaging im;
|
||||
|
||||
im = ImagingNewPrologue(mode, xsize, ysize);
|
||||
if ( ! im)
|
||||
return NULL;
|
||||
|
||||
if (ImagingAllocateBlock(im)) {
|
||||
return im;
|
||||
}
|
||||
|
||||
ImagingDelete(im);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Imaging
|
||||
|
|
Loading…
Reference in New Issue
Block a user