I’m using IMG_Load to load a 4096x4096 jpg. This SDL function works fine on Windows (and my own OpenGL code can handle that image size on iOS too) but when I run the same SDL function on the emulator on Android Studio IMG_Load fails with the error “That Operation Is Not Supported”.
If I reduce the jpg all the way down to 1024x1024 it starts to work. Is there any way to increase the image size that IMG_Load can load on Android? 1024x1024 seems a bit small nowadays!
Are you sure the limitation isn’t in the emulator? I’d recommend testing with a genuine Android device connected by a USB cable. If you do continue to have a problem with
You may be right! My only Android device is an old Huawei P7-L10 running 4.4.2 and when I ran the same code on that it all seems to work. I guess I can assume it’ll work on all actual Android devices then?
It’s a bit of a pain that I won’t be able to use the emulator though. Is it maybe a memory issue on the emulator I’ve selected rather than a problem with SDL?
I wouldn’t say that. I test my app on at least four different Android devices and four different iOS devices, and that still only covers a limited set of possibilities in terms of CPU, OS version, screen resolution, pixel format etc.
Is it maybe a memory issue on the emulator I’ve selected rather than a problem with SDL?
Memory issue would’ve been my guess as well - an uncompressed 32bit 4096x4096 bitmap is about 64MB, I can imagine that allocating that much memory might fail on low-end devices (maybe the Android emulator emulates a very low end device to make sure it works everywhere? No idea, I have no experience with Android development)
The maximum texture size depends on the GPU in the device. See the old but good answer Mobile Max Texture Size - Unity Answers
So, if you want to cover the maximum number of devices, you should use textures 2048x2048.
SDL_GetRendererInfo() returns the maximum texture size in the max_texture_width and max_texture_height fields. On my One Plus 10 Pro it is 16384 x 16384, on a much older Android device it’s 4096 x 4096, and also 4096 x 4096 on the iOS devices I’ve tried.
Note that the OP said it was the
IMG_Load() function that was failing.
IMG_Load returns a surface, not a texture, so I don’t think the maximum texture dimensions can be the cause of the failure.
Of course had
SDL_CreateTextureFromSurface() might have failed subsequently, so the maximum texture size is still a consideration. But I’d be surprised if that was smaller than 4096 x 4096.
I’m gonna cross my fingers and hope that if my ancient Huawei P7-L10 can load a 4096x4096 jpg then anything more modern ought to as well. I’ll let you know how that pans out!
Note that the OP said it was the
IMG_Load() function that was failing
Yes, it was IMG_Load() failing on the emulator on anything above 1024x1024 and the error I got from IMG_GetError() was “That Operation Is Not Supported”.
I wonder where “That Operation Is Not Supported” comes from, because I can’t find that string in the SDL_Image 2.0.5 source.
Also, you could still try SDL_stbimage.h, as @rtrussell suggested earlier.
I’ve been using lodePNG with no issues on Android
Looks like you guys were right, and it was a mistake for me to assume modern phones could handle a 4096x4096 image just cos my ancient Huawei phone could, so I’ve gone back to breaking it up into 16 1024x1024 tiled images. The devices I had reports of it failing on were:
Samsung Galaxy S20
Samsung Galaxy S21 ultra
Samsung Galaxy S9 Plus
Samsung S20 FE
So it looks like it might be a Samsung thing!
My Nokia 8 reports a texture pixel limit of 16384 x 16384. Use my handy app to get video hardware capabilities https://play.google.com/store/apps/details?id=uk.co.powgames.gamecondiag
This doesn’t seem to be about texture limit though, but about loading the file to RAM with IMG_Load() as SDL_Surface. One would think that this would have fewer limits than the GPU but… for some reason it fails anyway.
Of course we don’t know what exactly goes wrong here (one or two allocations of 64MB? the image decoding itself? if so, who’s to blame, libjpeg or does SDL_Image use some system lib on Android? …)