[rcore]: PLATFORM_SDL: improve clipboard data retrieval
This commit is contained in:
parent
729de10b1e
commit
4d5dfb150c
11
src/config.h
11
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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
void *fileData = NULL;
|
||||
for (int i = 0; i < SDL_arraysize(image_formats); ++i)
|
||||
{
|
||||
// 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)
|
||||
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());
|
||||
}
|
||||
else
|
||||
{
|
||||
image = LoadImageFromMemory(".bmp", fileData, dataSize);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user