2017-01-30 13:33:35 +01:00
|
|
|
// Copyright 2017 Google Inc. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style license
|
|
|
|
// that can be found in the COPYING file in the root of the source
|
|
|
|
// tree. An additional intellectual property rights grant can be found
|
|
|
|
// in the file PATENTS. All contributing project authors may
|
|
|
|
// be found in the AUTHORS file in the root of the source tree.
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Simple SDL-based WebP file viewer.
|
|
|
|
// Does not support animation, just static images.
|
|
|
|
//
|
|
|
|
// Press 'q' to exit.
|
|
|
|
//
|
|
|
|
// Author: James Zern (jzern@google.com)
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2024-05-01 03:18:23 +02:00
|
|
|
#include <stdlib.h>
|
2017-01-30 13:33:35 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "webp/config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(WEBP_HAVE_SDL)
|
|
|
|
|
|
|
|
#include "webp_to_sdl.h"
|
|
|
|
#include "webp/decode.h"
|
2017-10-07 23:15:11 +02:00
|
|
|
#include "imageio/imageio_util.h"
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
#include "../examples/unicode.h"
|
2017-01-30 13:33:35 +01:00
|
|
|
|
|
|
|
#if defined(WEBP_HAVE_JUST_SDL_H)
|
|
|
|
#include <SDL.h>
|
|
|
|
#else
|
2023-09-28 10:18:23 +02:00
|
|
|
#include <SDL2/SDL.h>
|
2017-01-30 13:33:35 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static void ProcessEvents(void) {
|
|
|
|
int done = 0;
|
|
|
|
SDL_Event event;
|
|
|
|
while (!done && SDL_WaitEvent(&event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case SDL_KEYUP:
|
|
|
|
switch (event.key.keysym.sym) {
|
|
|
|
case SDLK_q: done = 1; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-01 03:18:23 +02:00
|
|
|
// Returns EXIT_SUCCESS on success, EXIT_FAILURE on failure.
|
2017-01-30 13:33:35 +01:00
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
int c;
|
|
|
|
int ok = 0;
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
|
|
|
|
INIT_WARGV(argc, argv);
|
|
|
|
|
2024-12-06 22:11:29 +01:00
|
|
|
if (argc == 1) {
|
|
|
|
fprintf(stderr, "Usage: %s [-h] image.webp [more_files.webp...]\n",
|
|
|
|
argv[0]);
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
2017-01-30 13:33:35 +01:00
|
|
|
for (c = 1; c < argc; ++c) {
|
|
|
|
const char* file = NULL;
|
|
|
|
const uint8_t* webp = NULL;
|
|
|
|
size_t webp_size = 0;
|
|
|
|
if (!strcmp(argv[c], "-h")) {
|
|
|
|
printf("Usage: %s [-h] image.webp [more_files.webp...]\n", argv[0]);
|
2024-05-01 03:18:23 +02:00
|
|
|
FREE_WARGV_AND_RETURN(EXIT_SUCCESS);
|
2017-01-30 13:33:35 +01:00
|
|
|
} else {
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
file = (const char*)GET_WARGV(argv, c);
|
2017-01-30 13:33:35 +01:00
|
|
|
}
|
|
|
|
if (file == NULL) continue;
|
|
|
|
if (!ImgIoUtilReadFile(file, &webp, &webp_size)) {
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
WFPRINTF(stderr, "Error opening file: %s\n", (const W_CHAR*)file);
|
2017-01-30 13:33:35 +01:00
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
if (webp_size != (size_t)(int)webp_size) {
|
2018-11-27 11:59:31 +01:00
|
|
|
free((void*)webp);
|
2017-01-30 13:33:35 +01:00
|
|
|
fprintf(stderr, "File too large.\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
2022-12-16 03:11:40 +01:00
|
|
|
ok = WebPToSDL((const char*)webp, (int)webp_size);
|
2017-01-30 13:33:35 +01:00
|
|
|
free((void*)webp);
|
|
|
|
if (!ok) {
|
libwebp: Unicode command tools on Windows
Define macros in examples/unicode.h to use Unicode argv
on Windows. Keep char everywhere on Unix since it handles
UTF-8 without any change.
Impact:
- All fopen () and SHCreateStreamOnFile(),
- All fprintf() printing file paths,
- All strcmp() used with "-",
- File path parsing,
- Gif reading.
Concerned executables from examples/ and extras/:
anim_diff, anim_dump, vwebp, vwebp_sdl,
cwebp, dwebp, gif2webp, img2webp,
webpmux, webpinfo, webp_quality, get_disto
When compiled on Windows with Unicode enabled, webpmux and
img2webp will not work when used with an argument file and
will print "Reading arguments from a file is a feature
unavailable with Unicode binaries."
BUG=webp:398
Change-Id: Ic55d222a3ce1a715f9c4cce57ecbe2705d5ce317
2018-10-16 11:03:18 +02:00
|
|
|
WFPRINTF(stderr, "Error decoding file %s\n", (const W_CHAR*)file);
|
2017-01-30 13:33:35 +01:00
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
ProcessEvents();
|
|
|
|
}
|
|
|
|
ok = 1;
|
|
|
|
|
|
|
|
Error:
|
|
|
|
SDL_Quit();
|
2024-05-01 03:18:23 +02:00
|
|
|
FREE_WARGV_AND_RETURN(ok ? EXIT_SUCCESS : EXIT_FAILURE);
|
2017-01-30 13:33:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#else // !WEBP_HAVE_SDL
|
|
|
|
|
2019-07-26 09:46:40 +02:00
|
|
|
int main(int argc, const char* argv[]) {
|
2017-01-30 13:33:35 +01:00
|
|
|
fprintf(stderr, "SDL support not enabled in %s.\n", argv[0]);
|
|
|
|
(void)argc;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|