fix zero size images

This commit is contained in:
Alexander 2017-09-17 02:58:01 +03:00
parent 6007e818a9
commit 0054743100
2 changed files with 13 additions and 2 deletions

View File

@ -385,6 +385,12 @@ class TestImage(PillowTestCase):
im = Image.new('L', (0, 0))
self.assertEqual(im.size, (0, 0))
im = Image.new('L', (0, 100))
self.assertEqual(im.size, (0, 100))
im = Image.new('L', (100, 0))
self.assertEqual(im.size, (100, 0))
self.assertTrue(Image.new('RGB', (1, 1)))
# Should pass lists too
i = Image.new('RGB', [1, 1])

View File

@ -278,6 +278,9 @@ _get_block(int requested_size, int dirty)
if ( ! _blocks) {
_blocks = calloc(sizeof(void*), MEMORY_CACHE_BLOCKS);
}
if ( ! requested_size) {
requested_size = 1;
}
if (_blocks_free > 0) {
_blocks_free -= 1;
// printf("get block: %p %d; _blocks_free: %d\n",
@ -341,9 +344,11 @@ ImagingAllocateArray(Imaging im, int dirty)
int linesize, lines_per_block, blocks_count;
linesize = (im->linesize + MEMORY_ALIGN_LINES - 1) & -MEMORY_ALIGN_LINES;
lines_per_block = MEMORY_BLOCK_SIZE / linesize;
if (lines_per_block <= 0)
if ( ! linesize || linesize > MEMORY_BLOCK_SIZE) {
lines_per_block = 1;
} else {
lines_per_block = MEMORY_BLOCK_SIZE / linesize;
}
blocks_count = (im->ysize + lines_per_block - 1) / lines_per_block;
// printf("NEW size: %dx%d, ls: %d, lpb: %d, blocks: %d\n",
// im->xsize, im->ysize, linesize, lines_per_block, blocks_count);