Skip to content

Commit 87a1866

Browse files
committed
Removed IMG_Init() and IMG_Quit()
IMG_Init() and IMG_Quit() are no longer necessary. If an image format requires dynamically loading a support library, that will be done automatically.
1 parent 0d418a2 commit 87a1866

27 files changed

+65
-475
lines changed

docs/README-migration.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
# Migrating to SDL_image 3.0
3+
4+
This guide provides useful information for migrating applications from SDL_image 2.0 to SDL_image 3.0.
5+
6+
IMG_Init() and IMG_Quit() are no longer necessary. If an image format requires dynamically loading a support library, that will be done automatically.

include/SDL3_image/SDL_image.h

-101
Original file line numberDiff line numberDiff line change
@@ -67,107 +67,6 @@ extern "C" {
6767
*/
6868
extern SDL_DECLSPEC int SDLCALL IMG_Version(void);
6969

70-
/**
71-
* Initialization flags
72-
*/
73-
typedef Uint32 IMG_InitFlags;
74-
75-
#define IMG_INIT_JPG 0x00000001
76-
#define IMG_INIT_PNG 0x00000002
77-
#define IMG_INIT_TIF 0x00000004
78-
#define IMG_INIT_WEBP 0x00000008
79-
#define IMG_INIT_JXL 0x00000010
80-
#define IMG_INIT_AVIF 0x00000020
81-
82-
/**
83-
* Initialize SDL_image.
84-
*
85-
* This function loads dynamic libraries that SDL_image needs, and prepares
86-
* them for use. This must be the first function you call in SDL_image, and if
87-
* it fails you should not continue with the library.
88-
*
89-
* Flags should be one or more flags from IMG_InitFlags OR'd together. It
90-
* returns the flags successfully initialized, or 0 on failure.
91-
*
92-
* Currently, these flags are:
93-
*
94-
* - `IMG_INIT_JPG`
95-
* - `IMG_INIT_PNG`
96-
* - `IMG_INIT_TIF`
97-
* - `IMG_INIT_WEBP`
98-
* - `IMG_INIT_JXL`
99-
* - `IMG_INIT_AVIF`
100-
*
101-
* More flags may be added in a future SDL_image release.
102-
*
103-
* This function may need to load external shared libraries to support various
104-
* codecs, which means this function can fail to initialize that support on an
105-
* otherwise-reasonable system if the library isn't available; this is not
106-
* just a question of exceptional circumstances like running out of memory at
107-
* startup!
108-
*
109-
* Note that you may call this function more than once to initialize with
110-
* additional flags. The return value will reflect both new flags that
111-
* successfully initialized, and also include flags that had previously been
112-
* initialized as well.
113-
*
114-
* As this will return previously-initialized flags, it's legal to call this
115-
* with zero (no flags set). This is a safe no-op that can be used to query
116-
* the current initialization state without changing it at all.
117-
*
118-
* Since this returns previously-initialized flags as well as new ones, and
119-
* you can call this with zero, you should not check for a zero return value
120-
* to determine an error condition. Instead, you should check to make sure all
121-
* the flags you require are set in the return value. If you have a game with
122-
* data in a specific format, this might be a fatal error. If you're a generic
123-
* image displaying app, perhaps you are fine with only having JPG and PNG
124-
* support and can live without WEBP, even if you request support for
125-
* everything.
126-
*
127-
* Unlike other SDL satellite libraries, calls to IMG_Init do not stack; a
128-
* single call to IMG_Quit() will deinitialize everything and does not have to
129-
* be paired with a matching IMG_Init call. For that reason, it's considered
130-
* best practices to have a single IMG_Init and IMG_Quit call in your program.
131-
* While this isn't required, be aware of the risks of deviating from that
132-
* behavior.
133-
*
134-
* After initializing SDL_image, the app may begin to load images into
135-
* SDL_Surfaces or SDL_Textures.
136-
*
137-
* \param flags initialization flags, OR'd together.
138-
* \returns all currently initialized flags.
139-
*
140-
* \since This function is available since SDL_image 3.0.0.
141-
*
142-
* \sa IMG_Quit
143-
*/
144-
extern SDL_DECLSPEC IMG_InitFlags SDLCALL IMG_Init(IMG_InitFlags flags);
145-
146-
/**
147-
* Deinitialize SDL_image.
148-
*
149-
* This should be the last function you call in SDL_image, after freeing all
150-
* other resources. This will unload any shared libraries it is using for
151-
* various codecs.
152-
*
153-
* After this call, a call to IMG_Init(0) will return 0 (no codecs loaded).
154-
*
155-
* You can safely call IMG_Init() to reload various codec support after this
156-
* call.
157-
*
158-
* Unlike other SDL satellite libraries, calls to IMG_Init do not stack; a
159-
* single call to IMG_Quit() will deinitialize everything and does not have to
160-
* be paired with a matching IMG_Init call. For that reason, it's considered
161-
* best practices to have a single IMG_Init and IMG_Quit call in your program.
162-
* While this isn't required, be aware of the risks of deviating from that
163-
* behavior.
164-
*
165-
* \since This function is available since SDL_image 3.0.0.
166-
*
167-
* \sa IMG_Init
168-
*/
169-
extern SDL_DECLSPEC void SDLCALL IMG_Quit(void);
170-
17170
/**
17271
* Load an image from an SDL data source into a software surface.
17372
*

src/IMG.c

-65
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
/* A simple library to load images of various formats as SDL surfaces */
2323

2424
#include <SDL3_image/SDL_image.h>
25-
#include "IMG.h"
2625

2726
#ifdef __EMSCRIPTEN__
2827
#include <emscripten/emscripten.h>
@@ -89,70 +88,6 @@ int IMG_Version(void)
8988
return SDL_IMAGE_VERSION;
9089
}
9190

92-
static IMG_InitFlags initialized = 0;
93-
94-
IMG_InitFlags IMG_Init(IMG_InitFlags flags)
95-
{
96-
IMG_InitFlags result = 0;
97-
98-
if (flags & IMG_INIT_AVIF) {
99-
if ((initialized & IMG_INIT_AVIF) || IMG_InitAVIF() == 0) {
100-
result |= IMG_INIT_AVIF;
101-
}
102-
}
103-
if (flags & IMG_INIT_JPG) {
104-
if ((initialized & IMG_INIT_JPG) || IMG_InitJPG() == 0) {
105-
result |= IMG_INIT_JPG;
106-
}
107-
}
108-
if (flags & IMG_INIT_JXL) {
109-
if ((initialized & IMG_INIT_JXL) || IMG_InitJXL() == 0) {
110-
result |= IMG_INIT_JXL;
111-
}
112-
}
113-
if (flags & IMG_INIT_PNG) {
114-
if ((initialized & IMG_INIT_PNG) || IMG_InitPNG() == 0) {
115-
result |= IMG_INIT_PNG;
116-
}
117-
}
118-
if (flags & IMG_INIT_TIF) {
119-
if ((initialized & IMG_INIT_TIF) || IMG_InitTIF() == 0) {
120-
result |= IMG_INIT_TIF;
121-
}
122-
}
123-
if (flags & IMG_INIT_WEBP) {
124-
if ((initialized & IMG_INIT_WEBP) || IMG_InitWEBP() == 0) {
125-
result |= IMG_INIT_WEBP;
126-
}
127-
}
128-
initialized |= result;
129-
130-
return initialized;
131-
}
132-
133-
void IMG_Quit(void)
134-
{
135-
if (initialized & IMG_INIT_AVIF) {
136-
IMG_QuitAVIF();
137-
}
138-
if (initialized & IMG_INIT_JPG) {
139-
IMG_QuitJPG();
140-
}
141-
if (initialized & IMG_INIT_JXL) {
142-
IMG_QuitJXL();
143-
}
144-
if (initialized & IMG_INIT_PNG) {
145-
IMG_QuitPNG();
146-
}
147-
if (initialized & IMG_INIT_TIF) {
148-
IMG_QuitTIF();
149-
}
150-
if (initialized & IMG_INIT_WEBP) {
151-
IMG_QuitWEBP();
152-
}
153-
initialized = 0;
154-
}
155-
15691
#if !defined(__APPLE__) || defined(SDL_IMAGE_USE_COMMON_BACKEND)
15792
/* Load an image from a file */
15893
SDL_Surface *IMG_Load(const char *file)

src/IMG.h

-38
This file was deleted.

src/IMG_ImageIO.m

-36
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#if defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND)
1111

1212
#include <SDL3_image/SDL_image.h>
13-
#include "IMG.h"
1413

1514
// Used because CGDataProviderCreate became deprecated in 10.5
1615
#include <AvailabilityMacros.h>
@@ -356,41 +355,6 @@ static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
356355
}
357356

358357

359-
#ifdef JPG_USES_IMAGEIO
360-
361-
int IMG_InitJPG(void)
362-
{
363-
return 0;
364-
}
365-
366-
void IMG_QuitJPG(void)
367-
{
368-
}
369-
370-
#endif /* JPG_USES_IMAGEIO */
371-
372-
#ifdef PNG_USES_IMAGEIO
373-
374-
int IMG_InitPNG(void)
375-
{
376-
return 0;
377-
}
378-
379-
void IMG_QuitPNG(void)
380-
{
381-
}
382-
383-
#endif /* PNG_USES_IMAGEIO */
384-
385-
int IMG_InitTIF(void)
386-
{
387-
return 0;
388-
}
389-
390-
void IMG_QuitTIF(void)
391-
{
392-
}
393-
394358
static bool Internal_isType (SDL_IOStream *rw_ops, CFStringRef uti_string_to_test)
395359
{
396360
bool is_type = false;

src/IMG_WIC.c

+6-35
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
#if defined(SDL_IMAGE_USE_WIC_BACKEND)
2323

2424
#include <SDL3_image/SDL_image.h>
25-
#include "IMG.h"
2625
#define COBJMACROS
2726
#include <initguid.h>
2827
#include <wincodec.h>
2928

3029
static IWICImagingFactory* wicFactory = NULL;
3130

32-
static int WIC_Init(void)
31+
static bool WIC_Init(void)
3332
{
3433
if (wicFactory == NULL) {
3534
HRESULT hr = CoCreateInstance(
@@ -40,49 +39,21 @@ static int WIC_Init(void)
4039
(void**)&wicFactory
4140
);
4241
if (FAILED(hr)) {
43-
return -1;
42+
return false;
4443
}
4544
}
4645

47-
return 0;
46+
return true;
4847
}
4948

49+
#if 0
5050
static void WIC_Quit(void)
5151
{
5252
if (wicFactory) {
5353
IWICImagingFactory_Release(wicFactory);
5454
}
5555
}
56-
57-
int IMG_InitPNG(void)
58-
{
59-
return WIC_Init();
60-
}
61-
62-
void IMG_QuitPNG(void)
63-
{
64-
WIC_Quit();
65-
}
66-
67-
int IMG_InitJPG(void)
68-
{
69-
return WIC_Init();
70-
}
71-
72-
void IMG_QuitJPG(void)
73-
{
74-
WIC_Quit();
75-
}
76-
77-
int IMG_InitTIF(void)
78-
{
79-
return WIC_Init();
80-
}
81-
82-
void IMG_QuitTIF(void)
83-
{
84-
WIC_Quit();
85-
}
56+
#endif // 0
8657

8758
bool IMG_isPNG(SDL_IOStream *src)
8859
{
@@ -214,7 +185,7 @@ static SDL_Surface* WIC_LoadImage(SDL_IOStream *src)
214185
IWICFormatConverter* formatConverter = NULL;
215186
UINT width, height;
216187

217-
if (wicFactory == NULL && (WIC_Init() < 0)) {
188+
if (!WIC_Init()) {
218189
SDL_SetError("WIC failed to initialize!");
219190
return NULL;
220191
}

0 commit comments

Comments
 (0)