I've been using LodePNG's lodepng_encode24_file
to encode some 24-bit RGB image files, and it has worked wonderfully so far. However, I noticed that it appears to crash when I feed it a dataset larger than 15360*15360 pixels in size (14336*14336 pixel images get encoded fine).
A minimal example of this behavior for the 32-bit case (where the maximum size before crashing is slightly lower) can be obtained by simply replacing the line
unsigned width = 512, height = 512;
with
unsigned width = 1024*14, height = 1024*14;
in LodePNG's example_encode.c file, and executing it.
I previously had issues with C code crashing because I was allocating large arrays to stack memory (whose maximum size is generally somewhere around 2MB) instead of heap memory, so as a new user of C, my first instinct was to see if there is an upper limit on heap memory size.
However, according to this answer, there is no limit on heap memory, so something else must be going wrong.
My second guess was that the crash was due to an inherent limitation on the maximum image dimensions supported by the PNG format itself. However, according to this answer and the comment below it, the maximum file size supported by PNG is on the order of 4,000,000,000 * 4,000,000,000 pixels, so this is also not the culprit.
Does anyone have a guess as to what might be going wrong? Is anyone else able to reproduce this error when they try it?
EDIT: As far as RAM consumption is concerned, I have 8GB RAM, and subtracting the hardware-reserved, in-use, modified and standby memory (terms used by Windows Resource Monitor utility) I have about 4GB RAM free when doing the computation. For a 32-bit image of 15000*15000 size, less than 1GB would be needed. Likewise, when I successfully encode 14000*14000 24-bit images, my free RAM never drops below 3GB at any point of the encoding process, so I don't think RAM running out is the problem.