0

I am loading large PNG image with stb image library. Following code works with other images, so I'm quite sure the code around is correct.

int width = 0, height = 0, nrChannels = 0;
unsigned char* data = stbi_load(file_name, &width, &height, &nrChannels, 0);
cout << " - Image color channels: " << nrChannels << endl << flush;
if (data) {
...
} else {
    DIE_WITH_ERROR(); <-- Error raised here
}

nrChannels was also 0 after loading. It's RGBA PNG image of size 166800x1029 px - 38.5 MB

other semi-transparent rgba images in same folder work fine.

Is problem the size of the image? What is the largest image I can use?

Some image properties:

properties

Ecto
  • 1,125
  • 1
  • 7
  • 13
  • it seems to work with half-scaled image (82995x512). I will make some more tests – Ecto May 05 '20 at 14:42
  • 1
    Try stepping through the code with a debugger and see where it decides to break. – Botje May 05 '20 at 14:43
  • 1
    I created a blank png using `convert -size 166800x1029 xc:red test.png` and that loaded without problems. Is there anything special about your file? – Botje May 05 '20 at 14:57
  • 2
    Probably this image will exceed the texture size limit. See [`GL_MAX_TEXTURE_SIZE`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGet.xhtml) – Rabbid76 May 05 '20 at 15:09
  • @Botje there is nothing special about my file it's exported from GIMP, I'm having quite hard time debugging the library as I don't understand it and it takes quite long time because of the size of my project – Ecto May 05 '20 at 15:51
  • I got working result with image scaled to 16210x100, the image wouldn't probably work anyways because of openGL, but it's weird on stbi's side – Ecto May 05 '20 at 16:20
  • 1
    @Rabbid76: 4*166800*1029 = 686548800 is well below even 2^30 (1073741824). Address-space fragmentation maybe? – genpfault May 05 '20 at 17:24
  • OP, is this a 32-bit executable? If so, does it have [`IMAGE_FILE_LARGE_ADDRESS_AWARE`](https://stackoverflow.com/a/54305632/44729) set in its PE header? – genpfault May 05 '20 at 17:31
  • it is and it does not – Ecto May 05 '20 at 17:42
  • Welp, I guess try `/LARGEADDRESSAWARE` in the linker & hope for a favorable memory layout or give 64-bit a shot. – genpfault May 05 '20 at 17:44
  • if nothing works you can always try diferent loader like [libpng](http://www.libpng.org/pub/png/libpng.html) – Spektre May 06 '20 at 07:24

0 Answers0