diff --git a/src/config.h b/src/config.h index 703b0f23e..e3749c560 100644 --- a/src/config.h +++ b/src/config.h @@ -283,14 +283,21 @@ #define STBI_REQUIRED #endif - #ifndef SUPPORT_FILEFORMAT_BMP + #ifndef SUPPORT_FILEFORMAT_BMP // For clipboard image on Windows #define SUPPORT_FILEFORMAT_BMP 1 #endif + #ifndef SUPPORT_FILEFORMAT_PNG // Wayland uses png for prints, at least it was on 22 LTS ubuntu + #define SUPPORT_FILEFORMAT_PNG 1 + #endif + + #ifndef SUPPORT_FILEFORMAT_JPG + #define SUPPORT_FILEFORMAT_JPG 1 + #endif + #ifndef SUPPORT_MODULE_RTEXTURES #define SUPPORT_MODULE_RTEXTURES 1 #endif - #endif #endif // CONFIG_H diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 5e1a4f0fc..7d931b4b8 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -1086,20 +1086,39 @@ const char *GetClipboardText(void) // Get clipboard image Image GetClipboardImage(void) { - Image image = {0}; + // Let's hope compiler put these arrays in static memory + const char *image_formats[] = { + "image/bmp", + "image/png", + "image/jpg", + "image/tiff", + }; + const char *image_extensions[] = { + ".bmp", + ".png", + ".jpg", + ".tiff", + }; + + Image image = {0}; size_t dataSize = 0; - // NOTE: This pointer should be free with SDL_free() at some point. - // TODO: In case of failure let's try to cycle in to other mime types (formats) - void* fileData = SDL_GetClipboardData("image/bmp", &dataSize); // returns NULL on failure; - if (fileData == NULL) + void *fileData = NULL; + for (int i = 0; i < SDL_arraysize(image_formats); ++i) { - TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data. %s", SDL_GetError()); - } - else - { - image = LoadImageFromMemory(".bmp", fileData, dataSize); + // NOTE: This pointer should be free with SDL_free() at some point. + fileData = SDL_GetClipboardData(image_formats[i], &dataSize); + if (fileData) { + image = LoadImageFromMemory(image_extensions[i], fileData, dataSize); + if (IsImageValid(image)) + { + TRACELOG(LOG_INFO, "Clipboard image: Got image from clipboard as a `%s` successfully", image_extensions[i]); + return image; + } + } } + + TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data. %s", SDL_GetError()); return image; } #endif