Atlas - testdlopennote.c
Home / ext / SDL / test Lines: 1 | Size: 1977 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1#include <SDL3/SDL.h> 2#include <SDL3/SDL_main.h> 3 4#ifdef SDL_PLATFORM_WINDOWS 5#define PNG_SHARED_LIBRARY "libpng16-16.dll" 6#elif defined(SDL_PLATFORM_APPLE) 7#define PNG_SHARED_LIBRARY "libpng16.16.dylib" 8#else 9#define PNG_SHARED_LIBRARY "libpng16.so.16" 10#endif 11 12SDL_ELF_NOTE_DLOPEN( 13 "png", 14 "Support for loading PNG images using libpng", 15 SDL_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, 16 PNG_SHARED_LIBRARY 17) 18 19typedef int png_sig_cmp_fn(const unsigned char *sig, size_t start, size_t num_to_check); 20 21static struct { 22 SDL_SharedObject *library; 23 png_sig_cmp_fn *png_sig_cmp; 24} libpng16; 25 26static bool libpng_init(void) 27{ 28 libpng16.library = SDL_LoadObject(PNG_SHARED_LIBRARY); 29 if (!libpng16.library) { 30 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to load libpng library \"" PNG_SHARED_LIBRARY "\""); 31 return false; 32 } 33 libpng16.png_sig_cmp = (png_sig_cmp_fn *)SDL_LoadFunction(libpng16.library, "png_sig_cmp"); 34 return libpng16.png_sig_cmp != NULL; 35} 36 37static void libpng_quit(void) 38{ 39 SDL_UnloadObject(libpng16.library); 40 SDL_zero(libpng16); 41} 42 43static bool is_png(const char *path) 44{ 45 unsigned char header[8]; 46 size_t count; 47 bool result; 48 SDL_IOStream *io = SDL_IOFromFile(path, "rb"); 49 if (io == NULL) { 50 return false; 51 } 52 count = SDL_ReadIO(io, header, sizeof(header)); 53 result = libpng16.png_sig_cmp(header, 0, count) == 0; 54 SDL_CloseIO(io); 55 return result; 56} 57 58int main(int argc, char *argv[]) 59{ 60 int i; 61 62 /* Enable standard application logging */ 63 SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); 64 65 if (argc < 2) { 66 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Usage: %s IMAGE [IMAGE [IMAGE ... ]]", argv[0]); 67 return 1; 68 } 69 if (!libpng_init()) { 70 return 1; 71 } 72 for (i = 1; i < argc; i++) { 73 SDL_Log("\"%s\" is a png: %s", argv[i], is_png(argv[i]) ? "YES" : "NO"); 74 } 75 libpng_quit(); 76 return 0; 77} 78[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.