mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-12 22:14:29 +02:00
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
This commit is contained in:
@ -26,6 +26,7 @@
|
||||
#include "webp/encode.h"
|
||||
#include "imageio/image_dec.h"
|
||||
#include "imageio/imageio_util.h"
|
||||
#include "../examples/unicode.h"
|
||||
|
||||
static size_t ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
int keep_alpha) {
|
||||
@ -48,7 +49,8 @@ static size_t ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
|
||||
End:
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error! Could not process file %s\n", filename);
|
||||
WFPRINTF(stderr, "Error! Could not process file %s\n",
|
||||
(const W_CHAR*)filename);
|
||||
}
|
||||
free((void*)data);
|
||||
return ok ? data_size : 0;
|
||||
@ -239,9 +241,11 @@ int main(int argc, const char *argv[]) {
|
||||
const char* name2 = NULL;
|
||||
const char* output = NULL;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
if (!WebPPictureInit(&pic1) || !WebPPictureInit(&pic2)) {
|
||||
fprintf(stderr, "Can't init pictures\n");
|
||||
return 1;
|
||||
FREE_WARGV_AND_RETURN(1);
|
||||
}
|
||||
|
||||
for (c = 1; c < argc; ++c) {
|
||||
@ -263,11 +267,11 @@ int main(int argc, const char *argv[]) {
|
||||
fprintf(stderr, "missing file name after %s option.\n", argv[c - 1]);
|
||||
goto End;
|
||||
}
|
||||
output = argv[c];
|
||||
output = (const char*)GET_WARGV(argv, c);
|
||||
} else if (name1 == NULL) {
|
||||
name1 = argv[c];
|
||||
name1 = (const char*)GET_WARGV(argv, c);
|
||||
} else {
|
||||
name2 = argv[c];
|
||||
name2 = (const char*)GET_WARGV(argv, c);
|
||||
}
|
||||
}
|
||||
if (help || name1 == NULL || name2 == NULL) {
|
||||
@ -347,5 +351,5 @@ int main(int argc, const char *argv[]) {
|
||||
End:
|
||||
WebPPictureFree(&pic1);
|
||||
WebPPictureFree(&pic2);
|
||||
return ret;
|
||||
FREE_WARGV_AND_RETURN(ret);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "webp_to_sdl.h"
|
||||
#include "webp/decode.h"
|
||||
#include "imageio/imageio_util.h"
|
||||
#include "../examples/unicode.h"
|
||||
|
||||
#if defined(WEBP_HAVE_JUST_SDL_H)
|
||||
#include <SDL.h>
|
||||
@ -51,19 +52,22 @@ static void ProcessEvents(void) {
|
||||
int main(int argc, char* argv[]) {
|
||||
int c;
|
||||
int ok = 0;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
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]);
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else {
|
||||
file = argv[c];
|
||||
file = (const char*)GET_WARGV(argv, c);
|
||||
}
|
||||
if (file == NULL) continue;
|
||||
if (!ImgIoUtilReadFile(file, &webp, &webp_size)) {
|
||||
fprintf(stderr, "Error opening file: %s\n", file);
|
||||
WFPRINTF(stderr, "Error opening file: %s\n", (const W_CHAR*)file);
|
||||
goto Error;
|
||||
}
|
||||
if (webp_size != (size_t)(int)webp_size) {
|
||||
@ -73,7 +77,7 @@ int main(int argc, char* argv[]) {
|
||||
ok = WebpToSDL((const char*)webp, (int)webp_size);
|
||||
free((void*)webp);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error decoding file %s\n", file);
|
||||
WFPRINTF(stderr, "Error decoding file %s\n", (const W_CHAR*)file);
|
||||
goto Error;
|
||||
}
|
||||
ProcessEvents();
|
||||
@ -82,7 +86,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
Error:
|
||||
SDL_Quit();
|
||||
return ok ? 0 : 1;
|
||||
FREE_WARGV_AND_RETURN(ok ? 0 : 1);
|
||||
}
|
||||
|
||||
#else // !WEBP_HAVE_SDL
|
||||
|
@ -13,26 +13,30 @@
|
||||
|
||||
#include "extras/extras.h"
|
||||
#include "imageio/imageio_util.h"
|
||||
#include "../examples/unicode.h"
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int c;
|
||||
int quiet = 0;
|
||||
int ok = 1;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
for (c = 1; ok && c < argc; ++c) {
|
||||
if (!strcmp(argv[c], "-quiet")) {
|
||||
quiet = 1;
|
||||
} else if (!strcmp(argv[c], "-help") || !strcmp(argv[c], "-h")) {
|
||||
printf("webp_quality [-h][-quiet] webp_files...\n");
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else {
|
||||
const char* const filename = argv[c];
|
||||
const char* const filename = (const char*)GET_WARGV(argv, c);
|
||||
const uint8_t* data = NULL;
|
||||
size_t data_size = 0;
|
||||
int q;
|
||||
ok = ImgIoUtilReadFile(filename, &data, &data_size);
|
||||
if (!ok) break;
|
||||
q = VP8EstimateQuality(data, data_size);
|
||||
if (!quiet) printf("[%s] ", filename);
|
||||
if (!quiet) WPRINTF("[%s] ", (const W_CHAR*)filename);
|
||||
if (q < 0) {
|
||||
fprintf(stderr, "Not a WebP file, or not a lossy WebP file.\n");
|
||||
ok = 0;
|
||||
@ -46,5 +50,5 @@ int main(int argc, const char *argv[]) {
|
||||
free((void*)data);
|
||||
}
|
||||
}
|
||||
return ok ? 0 : 1;
|
||||
FREE_WARGV_AND_RETURN(ok ? 0 : 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user