Is IMG_Init() necessary? |
Is IMG_Init() necessary? |
Bob Rubbens
Guest
|
If you look at the source you'll see that a lot of stuff happens in the Init() call, as well as the separate init calls for various file formats. If I were you I'd just call it to avoid subtle bugs. Is there a reason to avoid calling it? Op 17 jan. 2016 6:09 p.m. schreef "dandago":
|
|||||||||||||
|
Is IMG_Init() necessary? |
Jonny D
|
It's not strictly necessary. You can ignore it if you don't think you need it. Things get initialized if they are used, which is already one good reason to have control over when that happens.
You can also use IMG_Init() to enforce image format support and treat failure as an error. Jonny D On Sun, Jan 17, 2016 at 1:01 PM, Bob Rubbens wrote:
|
|||||||||||||||
|
dandago
|
Let me give you some scenarios so that you can better understand why I'm asking.
Scenario 1: I know I need to load a PNG. No problem. Just use IMG_Init(IMG_INIT_PNG) and be on your way. Scenario 2: I know I need to load a GIF. IMG_Init(IMG_INIT_... what? There's no init flag for this type (and for many others). So how should I initialize SDL_image exactly? Scenario 3: I don't know what type I need to load. A filename is provided by the user so loading happens dynamically at runtime. I think there's no point in initializing every known type if it "things get initialized if they are used", i.e. lazy initialization. I'd just call IMG_Load() without calling IMG_Init(), and then clean up with IMG_Quit(). |
|||||||||||
|
Is IMG_Init() necessary? |
MrOzBarry
|
Are you after an animated GIF? That might be out of scope of SDL_image.
Otherwise, you're going to want to look at the mime type of the file, which usually ends up being a guessing game based on the file extension. I'd recommend saying you only support PNG, TIF, and JPEG, and do some guess work when examining the file, something like (pseudo): if (filename.extension in ['jpg', 'jpeg']) then IMG_Init(IMG_INIT_JPG); if (filename.extension in ['png']) then IMG_Init(IMG_INIT_PNG); // etc. If you really need a lot of image types to be supported, there might be some other image libraries that do some of this guess work for you, and provide raw buffer access so you can import it into an SDL_Surface pointer. On Mon, Jan 18, 2016 at 3:40 PM, dandago wrote:
|
|||||||||||||
|
Is IMG_Init() necessary? |
Sam Lantinga
|
It's totally safe to load your images without calling IMG_Init() and then just call IMG_Quit() when you're done. Each loader will automatically initialize itself if necessary at image load time.
On Sun, Jan 17, 2016 at 9:08 AM, dandago wrote:
|
|||||||||||||
|
Is IMG_Init() necessary? |
Bob Rubbens
Guest
|
On 19 January 2016 at 06:08, Sam Lantinga wrote:
It's even in the docs: "Note: If the image format loader requires initialization, it will attempt to do that the first time it is needed if you have not already called IMG_Init to load support for your image format." Didn't know that, pretty neat. |
|||||||||||||||
|