Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed IMG_Init() and IMG_Quit() #482

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions cmake/test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,15 @@
#include <SDL3/SDL_main.h>
#include <SDL3_image/SDL_image.h>

#define TEST_INIT_FLAG(FLAG) do { \
if ((IMG_Init(FLAG) & FLAG) == FLAG) { \
SDL_Log("IMG_Init("#FLAG") succeeded"); \
} else { \
SDL_Log("IMG_Init("#FLAG") failed"); \
} \
} while (0);

#define FOREACH_INIT_FLAGS(X) \
X(IMG_INIT_JPG) \
X(IMG_INIT_PNG) \
X(IMG_INIT_TIF) \
X(IMG_INIT_WEBP) \
X(IMG_INIT_JXL) \
X(IMG_INIT_AVIF) \

int main(int argc, char *argv[])
{
if (!SDL_Init(0)) {
SDL_Log("SDL_Init(0) failed: %s\n", SDL_GetError());
return 1;
}

FOREACH_INIT_FLAGS(TEST_INIT_FLAG)
IMG_Version();

IMG_Quit();
SDL_Quit();
return 0;
}
6 changes: 6 additions & 0 deletions docs/README-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# Migrating to SDL_image 3.0

This guide provides useful information for migrating applications from SDL_image 2.0 to SDL_image 3.0.

IMG_Init() and IMG_Quit() are no longer necessary. If an image format requires dynamically loading a support library, that will be done automatically.
101 changes: 0 additions & 101 deletions include/SDL3_image/SDL_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,107 +67,6 @@ extern "C" {
*/
extern SDL_DECLSPEC int SDLCALL IMG_Version(void);

/**
* Initialization flags
*/
typedef Uint32 IMG_InitFlags;

#define IMG_INIT_JPG 0x00000001
#define IMG_INIT_PNG 0x00000002
#define IMG_INIT_TIF 0x00000004
#define IMG_INIT_WEBP 0x00000008
#define IMG_INIT_JXL 0x00000010
#define IMG_INIT_AVIF 0x00000020

/**
* Initialize SDL_image.
*
* This function loads dynamic libraries that SDL_image needs, and prepares
* them for use. This must be the first function you call in SDL_image, and if
* it fails you should not continue with the library.
*
* Flags should be one or more flags from IMG_InitFlags OR'd together. It
* returns the flags successfully initialized, or 0 on failure.
*
* Currently, these flags are:
*
* - `IMG_INIT_JPG`
* - `IMG_INIT_PNG`
* - `IMG_INIT_TIF`
* - `IMG_INIT_WEBP`
* - `IMG_INIT_JXL`
* - `IMG_INIT_AVIF`
*
* More flags may be added in a future SDL_image release.
*
* This function may need to load external shared libraries to support various
* codecs, which means this function can fail to initialize that support on an
* otherwise-reasonable system if the library isn't available; this is not
* just a question of exceptional circumstances like running out of memory at
* startup!
*
* Note that you may call this function more than once to initialize with
* additional flags. The return value will reflect both new flags that
* successfully initialized, and also include flags that had previously been
* initialized as well.
*
* As this will return previously-initialized flags, it's legal to call this
* with zero (no flags set). This is a safe no-op that can be used to query
* the current initialization state without changing it at all.
*
* Since this returns previously-initialized flags as well as new ones, and
* you can call this with zero, you should not check for a zero return value
* to determine an error condition. Instead, you should check to make sure all
* the flags you require are set in the return value. If you have a game with
* data in a specific format, this might be a fatal error. If you're a generic
* image displaying app, perhaps you are fine with only having JPG and PNG
* support and can live without WEBP, even if you request support for
* everything.
*
* Unlike other SDL satellite libraries, calls to IMG_Init do not stack; a
* single call to IMG_Quit() will deinitialize everything and does not have to
* be paired with a matching IMG_Init call. For that reason, it's considered
* best practices to have a single IMG_Init and IMG_Quit call in your program.
* While this isn't required, be aware of the risks of deviating from that
* behavior.
*
* After initializing SDL_image, the app may begin to load images into
* SDL_Surfaces or SDL_Textures.
*
* \param flags initialization flags, OR'd together.
* \returns all currently initialized flags.
*
* \since This function is available since SDL_image 3.0.0.
*
* \sa IMG_Quit
*/
extern SDL_DECLSPEC IMG_InitFlags SDLCALL IMG_Init(IMG_InitFlags flags);

/**
* Deinitialize SDL_image.
*
* This should be the last function you call in SDL_image, after freeing all
* other resources. This will unload any shared libraries it is using for
* various codecs.
*
* After this call, a call to IMG_Init(0) will return 0 (no codecs loaded).
*
* You can safely call IMG_Init() to reload various codec support after this
* call.
*
* Unlike other SDL satellite libraries, calls to IMG_Init do not stack; a
* single call to IMG_Quit() will deinitialize everything and does not have to
* be paired with a matching IMG_Init call. For that reason, it's considered
* best practices to have a single IMG_Init and IMG_Quit call in your program.
* While this isn't required, be aware of the risks of deviating from that
* behavior.
*
* \since This function is available since SDL_image 3.0.0.
*
* \sa IMG_Init
*/
extern SDL_DECLSPEC void SDLCALL IMG_Quit(void);

/**
* Load an image from an SDL data source into a software surface.
*
Expand Down
65 changes: 0 additions & 65 deletions src/IMG.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
/* A simple library to load images of various formats as SDL surfaces */

#include <SDL3_image/SDL_image.h>
#include "IMG.h"

#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
Expand Down Expand Up @@ -89,70 +88,6 @@ int IMG_Version(void)
return SDL_IMAGE_VERSION;
}

static IMG_InitFlags initialized = 0;

IMG_InitFlags IMG_Init(IMG_InitFlags flags)
{
IMG_InitFlags result = 0;

if (flags & IMG_INIT_AVIF) {
if ((initialized & IMG_INIT_AVIF) || IMG_InitAVIF() == 0) {
result |= IMG_INIT_AVIF;
}
}
if (flags & IMG_INIT_JPG) {
if ((initialized & IMG_INIT_JPG) || IMG_InitJPG() == 0) {
result |= IMG_INIT_JPG;
}
}
if (flags & IMG_INIT_JXL) {
if ((initialized & IMG_INIT_JXL) || IMG_InitJXL() == 0) {
result |= IMG_INIT_JXL;
}
}
if (flags & IMG_INIT_PNG) {
if ((initialized & IMG_INIT_PNG) || IMG_InitPNG() == 0) {
result |= IMG_INIT_PNG;
}
}
if (flags & IMG_INIT_TIF) {
if ((initialized & IMG_INIT_TIF) || IMG_InitTIF() == 0) {
result |= IMG_INIT_TIF;
}
}
if (flags & IMG_INIT_WEBP) {
if ((initialized & IMG_INIT_WEBP) || IMG_InitWEBP() == 0) {
result |= IMG_INIT_WEBP;
}
}
initialized |= result;

return initialized;
}

void IMG_Quit(void)
{
if (initialized & IMG_INIT_AVIF) {
IMG_QuitAVIF();
}
if (initialized & IMG_INIT_JPG) {
IMG_QuitJPG();
}
if (initialized & IMG_INIT_JXL) {
IMG_QuitJXL();
}
if (initialized & IMG_INIT_PNG) {
IMG_QuitPNG();
}
if (initialized & IMG_INIT_TIF) {
IMG_QuitTIF();
}
if (initialized & IMG_INIT_WEBP) {
IMG_QuitWEBP();
}
initialized = 0;
}

#if !defined(__APPLE__) || defined(SDL_IMAGE_USE_COMMON_BACKEND)
/* Load an image from a file */
SDL_Surface *IMG_Load(const char *file)
Expand Down
38 changes: 0 additions & 38 deletions src/IMG.h

This file was deleted.

38 changes: 1 addition & 37 deletions src/IMG_ImageIO.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#if defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND)

#include <SDL3_image/SDL_image.h>
#include "IMG.h"

// Used because CGDataProviderCreate became deprecated in 10.5
#include <AvailabilityMacros.h>
Expand Down Expand Up @@ -324,7 +323,7 @@ static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
if (num_entries > (size_t)palette->ncolors) {
num_entries = (size_t)palette->ncolors;
}
palette->ncolors = num_entries;
palette->ncolors = (int)num_entries;
for (i = 0, entry = entries; i < num_entries; ++i) {
palette->colors[i].r = entry[0];
palette->colors[i].g = entry[1];
Expand Down Expand Up @@ -356,41 +355,6 @@ static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
}


#ifdef JPG_USES_IMAGEIO

int IMG_InitJPG(void)
{
return 0;
}

void IMG_QuitJPG(void)
{
}

#endif /* JPG_USES_IMAGEIO */

#ifdef PNG_USES_IMAGEIO

int IMG_InitPNG(void)
{
return 0;
}

void IMG_QuitPNG(void)
{
}

#endif /* PNG_USES_IMAGEIO */

int IMG_InitTIF(void)
{
return 0;
}

void IMG_QuitTIF(void)
{
}

static bool Internal_isType (SDL_IOStream *rw_ops, CFStringRef uti_string_to_test)
{
bool is_type = false;
Expand Down
Loading
Loading