Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Can't Save Large Images  (Read 2088 times)

0 Members and 1 Guest are viewing this topic.

Zakkle

  • Newbie
  • *
  • Posts: 10
    • View Profile
Can't Save Large Images
« on: May 06, 2020, 02:04:08 pm »
Aight, so I am having an issue with a large image not saving.  Here is my test code:

Code: [Select]
sf::Image test;
test.create(32*16*52,32*12*60);
sf::Image mpone;
mpone.loadFromFile("map_image1.png");

test.copy(mpone,0,0);

test.saveToFile("test.png");

I keep getting the generic [Failed to save image "test.png"] error.

The thing is, I can load over 12,000 textures from small 32*32 .bmp files and assemble a 224*53,852px image then save it to file.  But then I can't load even a single small image into a (roughly) 25k*25k image.  My graphics card shouldn't be an issue, at all.

I have loaded over 20,000 textures, both big and small, into the graphics card.  But then I have also created a test project without all of those and just tried creating the blank image and adding one thing to it.  This results in failure, every time.

Even if we go with the GPU's limitations, it can produce/handle textures up to 32k*32k.  Besides, and this may sound a bit ignorant, but I am thinking that 12GB of GPU RAM should mean that it's not a GPU limitation (since the texture limitations are 32k*32k).

All this to say, can we get some sort of verbose debugging?  Can we get a bool return for the copy() command to see if that's it, at least?  I am kind of lost in the sauce and it's been bugging me for weeks because each test I conduct on this code takes no less than fifteen minutes to run my converter.  So what are my options for narrowing down why, exactly, this image save fails, since nothing I am doing is getting me anywhere close to an answer?[/code]

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can't Save Large Images
« Reply #1 on: May 06, 2020, 03:21:07 pm »
Tested this.

I got both:
"Failed to load image "*.png". Reason: Image too large to decode"
and
"Failed to save image "test.png""

Notably, this means that it's not possible to load (or save) an image that large.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Zakkle

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Can't Save Large Images
« Reply #2 on: May 06, 2020, 03:46:56 pm »
Can we confirm this is an SFML limitation, though?

If you got both errors in the same test, then that means there's an issue with the image that was fed to the program, making it not load, and also resulting in the API not wanting to save a blank sf::Image object to file.  If you have an image, of whatever size, that would successfully load into the program before trying the save the image of that size, then it would be more accurate to the test.

All of my "map_image*.png" files are 32*16x32*12.  I have 10,000 images that are tiled with the images of this size, and out of all of those clusters of images, there is only one (the 25kx25k image) that is giving me issues.

What's really killing me is that I have been analyzing the code and I have implemented checks within my code to ensure I do not exceed the limits of the data types SFML uses for the sf::Image objects.

So why is this happening?

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can't Save Large Images
« Reply #3 on: May 06, 2020, 04:02:45 pm »
It could be a limitation of the STB library that SFML uses to load and save image files.


It's worth noting that I had trouble with running with this size of image when building in 32-bit mode. It seems to only be able to deal with it in 64-bit mode.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Zakkle

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Can't Save Large Images
« Reply #4 on: May 06, 2020, 04:05:18 pm »
Ohhhh, wait.  I was under the impression I was building in 64-bit mode.  Is this a compiler flag issue?

[Edit]
I have tried 64-bit compiler tags, no dice.
« Last Edit: May 06, 2020, 04:12:05 pm by Zakkle »

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can't Save Large Images
« Reply #5 on: May 06, 2020, 04:20:37 pm »
Just checked around STB (see here and here) and it seems that maximum size (actual memory size, not compressed file size) for 32-bit is 1GB and for 64-bit is 2GB.

Your image is 2,453,667,840 bytes. or approx. 2.3 GB (technically, GiB but whatever ;D)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Zakkle

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Can't Save Large Images
« Reply #6 on: May 06, 2020, 04:35:38 pm »
Omfg...  this is killing me.  I wanted to use SFML to not have to reinvent the wheel (no stabs at SFML-- I plan to still use it for regular projects for years to begin).

Help me wrap my tiny mind around this.  If this is a known issue, why isn't SFML checking against this, having knowingly used STB?  (Again, not taking a stab against SFML, I'm just trying to understand things.)

I really need to make images this size, and I have many graphics editing programs that do this if I manually paste all 3,500 images into it.  The problem being, the entire point of this program was automation.

Am I doomed to be unable to any of this in SFML?  I keep doing research on OpenGL but I have a, uh... special problem that prevents me from remembering things from long enough to learn all the research I need to do.

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can't Save Large Images
« Reply #7 on: May 06, 2020, 04:46:19 pm »
The limitation is a limitation of PNG, apparently:
Quote
PNG has an explicit threshold of max 1GB output
But STB "weaken" that limitation to 2GB for 64-bit.

Note that the limitation is based on maximum integer values.

That said, you could simply cut it into quarters and piece it together inside SFML. And, to save it, cut it into quarters and save each quarter separately.


Doomed, I would say not necessarily. You could look for other libraries that load PNG files (that ignore its rules) and then load that into an sf::Image.


On top of this, I would say that images this size are not pleasant, even for image manipulation programs. My Photoshop didn't enjoy trying to make a PNG of that size.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Zakkle

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Can't Save Large Images
« Reply #8 on: May 06, 2020, 05:05:44 pm »
I built a system with a large amount of RAM and GPU RAM specifically for manually creating these images.  Except, now I have resorted to trying to generate these images using a script, rather than dealing with all of the analog nature of this project.  My Photoshop, GIMP, Krita, etc. have been dealing with these image sizes just fine.  They have also been saving this exact image to files of about 125MB.  In RAM and GPU RAM is a different story, only because of all of the layers this project has generated, but nevertheless it's nowhere near a 1GB~2GB file output.

For large image files, I am willing to compromise and use a different file format, it's just baffling that SFML allows images of this size but will not save imges of this size without more specific error messages.

I mean, SFML creates an image that size, without error, and will .copy() thousands of files into that image, without error, but when it comes to saving images of that size, it throws a generic error.

I'm not particularly looking to ignore .png's rules, because none of the image editing programs have generated an output of much larger than 125MB.  I mean, I only mentioned my 25k*25k image problem but I have images that are 4~10 times larger than that which will save to .png in other image manipulators without an issue.

Just how in the world do I do this without splitting the image?  The entire purpose of this project is to piece it together into a single image from a bunch of other iamges.

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can't Save Large Images
« Reply #9 on: May 06, 2020, 09:57:16 pm »
PNG definition states that this is a limitation of PNG for compatibility purposes:
http://www.libpng.org/pub/png/spec/iso/index-object.html#7Integers-and-byte-order
Quote
PNG four-byte unsigned integers are limited to the range 0 to 231-1 to accommodate languages that have difficulty with unsigned four-byte values. Similarly PNG four-byte signed integers are limited to the range -(231-1) to 231-1 to accommodate languages that have difficulty with the value -231.

This isn't really an SFML issue. It's using a library that follows PNG's rules.

You could try a different format. I'm sure there will be others that don't have these rules.
It was said that JPEG doesn't have these restrictions but, I imagine, that is not acceptable for non-lossy data compression format.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything