| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include <stdio.h> |
| 18 |
|
| 19 |
#ifdef HAVE_CONFIG_H |
| 20 |
#include "webp/config.h" |
| 21 |
#endif |
| 22 |
|
| 23 |
#if defined(WEBP_HAVE_SDL) |
| 24 |
|
| 25 |
#include "webp_to_sdl.h" |
| 26 |
#include "webp/decode.h" |
| 27 |
#include "imageio/imageio_util.h" |
| 28 |
#include "../examples/unicode.h" |
| 29 |
|
| 30 |
#if defined(WEBP_HAVE_JUST_SDL_H) |
| 31 |
#include <SDL.h> |
| 32 |
#else |
| 33 |
#include <SDL2/SDL.h> |
| 34 |
#endif |
| 35 |
|
| 36 |
static void ProcessEvents(void) { |
| 37 |
int done = 0; |
| 38 |
SDL_Event event; |
| 39 |
while (!done && SDL_WaitEvent(&event)) { |
| 40 |
switch (event.type) { |
| 41 |
case SDL_KEYUP: |
| 42 |
switch (event.key.keysym.sym) { |
| 43 |
case SDLK_q: done = 1; break; |
| 44 |
default: break; |
| 45 |
} |
| 46 |
break; |
| 47 |
default: break; |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
int main(int argc, char* argv[]) { |
| 53 |
int c; |
| 54 |
int ok = 0; |
| 55 |
|
| 56 |
INIT_WARGV(argc, argv); |
| 57 |
|
| 58 |
for (c = 1; c < argc; ++c) { |
| 59 |
const char* file = NULL; |
| 60 |
const uint8_t* webp = NULL; |
| 61 |
size_t webp_size = 0; |
| 62 |
if (!strcmp(argv[c], "-h")) { |
| 63 |
printf("Usage: %s [-h] image.webp [more_files.webp...]\n", argv[0]); |
| 64 |
FREE_WARGV_AND_RETURN(0); |
| 65 |
} else { |
| 66 |
file = (const char*)GET_WARGV(argv, c); |
| 67 |
} |
| 68 |
if (file == NULL) continue; |
| 69 |
if (!ImgIoUtilReadFile(file, &webp, &webp_size)) { |
| 70 |
WFPRINTF(stderr, "Error opening file: %s\n", (const W_CHAR*)file); |
| 71 |
goto Error; |
| 72 |
} |
| 73 |
if (webp_size != (size_t)(int)webp_size) { |
| 74 |
free((void*)webp); |
| 75 |
fprintf(stderr, "File too large.\n"); |
| 76 |
goto Error; |
| 77 |
} |
| 78 |
ok = WebPToSDL((const char*)webp, (int)webp_size); |
| 79 |
free((void*)webp); |
| 80 |
if (!ok) { |
| 81 |
WFPRINTF(stderr, "Error decoding file %s\n", (const W_CHAR*)file); |
| 82 |
goto Error; |
| 83 |
} |
| 84 |
ProcessEvents(); |
| 85 |
} |
| 86 |
ok = 1; |
| 87 |
|
| 88 |
Error: |
| 89 |
SDL_Quit(); |
| 90 |
FREE_WARGV_AND_RETURN(ok ? 0 : 1); |
| 91 |
} |
| 92 |
|
| 93 |
#else |
| 94 |
|
| 95 |
int main(int argc, const char* argv[]) { |
| 96 |
fprintf(stderr, "SDL support not enabled in %s.\n", argv[0]); |
| 97 |
(void)argc; |
| 98 |
return 0; |
| 99 |
} |
| 100 |
|
| 101 |
#endif |