[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Re: Out of memory loading very large image



On Thu, Sep 29, 2016 at 9:06 PM, shortcipher <short.jones.cipher@xxxxxxxxx> wrote:
Some experiments point to overflowing 16-bit integers rather than memory
resource issues:-

1. My script can load a 16383 x 1321 image but gets "Out of memory" on a a
16384 x 1321 image.
​PyGame is layered over SDL 1.2. It seems that, in SDL 1.2, the pitch (sizeof scanline) is a uint16. So 16384 pixels * 4 bytes/pixel causes the overflow.​
 
2. A workaround to load the image in PIL and transfer it to pygame as a
string works as long as the width is less than 21846 and the height is less
than 32768, otherwise the image is totally garbled. (Note that 21845 x 3 =
0xFFFF.)
​Based on the above, I'd say 16383 is an upper limit on width. The pixel pitch is important for various things, although it may not be immediately critical. That's why loading might appear to work.

Width and height are stored as ints, but I still wouldn't make them larger than 16383 (who makes an image higher than wide?).

N.B. JPEG itself supports up to 65535 square.

Ian​