mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-29 20:57:59 +08:00
testclipboard: load any image format supported by SDL
This commit is contained in:
+1
-10
@@ -128,9 +128,6 @@ static float PrintPrimarySelectionText(float x, float y)
|
|||||||
static float PrintClipboardImage(float x, float y, const char *mime_type)
|
static float PrintClipboardImage(float x, float y, const char *mime_type)
|
||||||
{
|
{
|
||||||
/* We don't actually need to read this data each frame, but this is a simple example */
|
/* We don't actually need to read this data each frame, but this is a simple example */
|
||||||
bool isBMP = (SDL_strcmp(mime_type, "image/bmp") == 0);
|
|
||||||
bool isPNG = (SDL_strcmp(mime_type, "image/png") == 0);
|
|
||||||
if (isBMP || isPNG) {
|
|
||||||
size_t size;
|
size_t size;
|
||||||
void *data = SDL_GetClipboardData(mime_type, &size);
|
void *data = SDL_GetClipboardData(mime_type, &size);
|
||||||
if (data) {
|
if (data) {
|
||||||
@@ -138,12 +135,7 @@ static float PrintClipboardImage(float x, float y, const char *mime_type)
|
|||||||
bool rendered = false;
|
bool rendered = false;
|
||||||
SDL_IOStream *stream = SDL_IOFromConstMem(data, size);
|
SDL_IOStream *stream = SDL_IOFromConstMem(data, size);
|
||||||
if (stream) {
|
if (stream) {
|
||||||
SDL_Surface *surface;
|
SDL_Surface *surface = SDL_LoadSurface_IO(stream, false);
|
||||||
if (isBMP) {
|
|
||||||
surface = SDL_LoadBMP_IO(stream, false);
|
|
||||||
} else {
|
|
||||||
surface = SDL_LoadPNG_IO(stream, false);
|
|
||||||
}
|
|
||||||
if (surface) {
|
if (surface) {
|
||||||
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
|
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||||
if (texture) {
|
if (texture) {
|
||||||
@@ -163,7 +155,6 @@ static float PrintClipboardImage(float x, float y, const char *mime_type)
|
|||||||
SDL_free(data);
|
SDL_free(data);
|
||||||
return h + 2.0f;
|
return h + 2.0f;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user