2017-08-28 16:03:40 +02: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.
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Decodes an animated WebP file and dumps the decoded frames as PNG or TIFF.
|
|
|
|
//
|
|
|
|
// Author: Skal (pascal.massimino@gmail.com)
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h> // for 'strcmp'.
|
|
|
|
|
|
|
|
#include "./anim_util.h"
|
|
|
|
#include "webp/decode.h"
|
|
|
|
#include "../imageio/image_enc.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 "./unicode.h"
|
2017-08-28 16:03:40 +02:00
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1900
|
|
|
|
#define snprintf _snprintf
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void Help(void) {
|
|
|
|
printf("Usage: anim_dump [options] files...\n");
|
|
|
|
printf("\nOptions:\n");
|
|
|
|
printf(" -folder <string> .... dump folder (default: '.')\n");
|
|
|
|
printf(" -prefix <string> .... prefix for dumped frames "
|
|
|
|
"(default: 'dump_')\n");
|
|
|
|
printf(" -tiff ............... save frames as TIFF\n");
|
|
|
|
printf(" -pam ................ save frames as PAM\n");
|
2018-04-03 14:50:58 +02:00
|
|
|
printf(" -h .................. this help\n");
|
|
|
|
printf(" -version ............ print version number and exit\n");
|
2017-08-28 16:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char* argv[]) {
|
|
|
|
int error = 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
|
|
|
const W_CHAR* dump_folder = TO_W_CHAR(".");
|
|
|
|
const W_CHAR* prefix = TO_W_CHAR("dump_");
|
|
|
|
const W_CHAR* suffix = TO_W_CHAR("png");
|
2017-08-28 16:03:40 +02:00
|
|
|
WebPOutputFileFormat format = PNG;
|
|
|
|
int c;
|
|
|
|
|
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);
|
|
|
|
|
2017-08-28 16:03:40 +02:00
|
|
|
if (argc < 2) {
|
|
|
|
Help();
|
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
|
|
|
FREE_WARGV_AND_RETURN(-1);
|
2017-08-28 16:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (c = 1; !error && c < argc; ++c) {
|
|
|
|
if (!strcmp(argv[c], "-folder")) {
|
|
|
|
if (c + 1 == argc) {
|
|
|
|
fprintf(stderr, "missing argument after option '%s'\n", argv[c]);
|
|
|
|
error = 1;
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
dump_folder = GET_WARGV(argv, ++c);
|
2017-08-28 16:03:40 +02:00
|
|
|
} else if (!strcmp(argv[c], "-prefix")) {
|
|
|
|
if (c + 1 == argc) {
|
|
|
|
fprintf(stderr, "missing argument after option '%s'\n", argv[c]);
|
|
|
|
error = 1;
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
prefix = GET_WARGV(argv, ++c);
|
2017-08-28 16:03:40 +02:00
|
|
|
} else if (!strcmp(argv[c], "-tiff")) {
|
|
|
|
format = TIFF;
|
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
|
|
|
suffix = TO_W_CHAR("tiff");
|
2017-08-28 16:03:40 +02:00
|
|
|
} else if (!strcmp(argv[c], "-pam")) {
|
|
|
|
format = PAM;
|
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
|
|
|
suffix = TO_W_CHAR("pam");
|
2018-04-03 14:50:58 +02:00
|
|
|
} else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
|
|
|
|
Help();
|
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
|
|
|
FREE_WARGV_AND_RETURN(0);
|
2018-04-03 14:50:58 +02:00
|
|
|
} else if (!strcmp(argv[c], "-version")) {
|
|
|
|
int dec_version, demux_version;
|
|
|
|
GetAnimatedImageVersions(&dec_version, &demux_version);
|
|
|
|
printf("WebP Decoder version: %d.%d.%d\nWebP Demux version: %d.%d.%d\n",
|
|
|
|
(dec_version >> 16) & 0xff, (dec_version >> 8) & 0xff,
|
|
|
|
(dec_version >> 0) & 0xff,
|
|
|
|
(demux_version >> 16) & 0xff, (demux_version >> 8) & 0xff,
|
|
|
|
(demux_version >> 0) & 0xff);
|
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
|
|
|
FREE_WARGV_AND_RETURN(0);
|
2017-08-28 16:03:40 +02:00
|
|
|
} else {
|
|
|
|
uint32_t i;
|
|
|
|
AnimatedImage image;
|
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
|
|
|
const W_CHAR* const file = GET_WARGV(argv, c);
|
2017-08-28 16:03:40 +02:00
|
|
|
memset(&image, 0, sizeof(image));
|
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
|
|
|
WPRINTF("Decoding file: %s as %s/%sxxxx.%s\n",
|
|
|
|
file, dump_folder, prefix, suffix);
|
|
|
|
if (!ReadAnimatedImage((const char*)file, &image, 0, NULL)) {
|
|
|
|
WFPRINTF(stderr, "Error decoding file: %s\n Aborting.\n", file);
|
2017-08-28 16:03:40 +02:00
|
|
|
error = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (i = 0; !error && i < image.num_frames; ++i) {
|
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
|
|
|
W_CHAR out_file[1024];
|
2017-08-28 16:03:40 +02:00
|
|
|
WebPDecBuffer buffer;
|
2023-11-10 13:57:07 +01:00
|
|
|
if (!WebPInitDecBuffer(&buffer)) {
|
|
|
|
fprintf(stderr, "Cannot init dec buffer\n");
|
|
|
|
error = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-28 16:03:40 +02:00
|
|
|
buffer.colorspace = MODE_RGBA;
|
|
|
|
buffer.is_external_memory = 1;
|
|
|
|
buffer.width = image.canvas_width;
|
|
|
|
buffer.height = image.canvas_height;
|
|
|
|
buffer.u.RGBA.rgba = image.frames[i].rgba;
|
|
|
|
buffer.u.RGBA.stride = buffer.width * sizeof(uint32_t);
|
|
|
|
buffer.u.RGBA.size = buffer.u.RGBA.stride * buffer.height;
|
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
|
|
|
WSNPRINTF(out_file, sizeof(out_file), "%s/%s%.4d.%s",
|
|
|
|
dump_folder, prefix, i, suffix);
|
|
|
|
if (!WebPSaveImage(&buffer, format, (const char*)out_file)) {
|
|
|
|
WFPRINTF(stderr, "Error while saving image '%s'\n", out_file);
|
2017-08-28 16:03:40 +02:00
|
|
|
error = 1;
|
|
|
|
}
|
|
|
|
WebPFreeDecBuffer(&buffer);
|
|
|
|
}
|
|
|
|
ClearAnimatedImage(&image);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
FREE_WARGV_AND_RETURN(error ? 1 : 0);
|
2017-08-28 16:03:40 +02:00
|
|
|
}
|