2012-05-12 01:00:57 +02:00
|
|
|
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
|
|
//
|
2013-06-07 08:05:58 +02:00
|
|
|
// 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.
|
2012-05-12 01:00:57 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Utility functions used by the example programs.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "./example_util.h"
|
2014-08-30 04:07:17 +02:00
|
|
|
|
2018-02-08 08:09:14 +01:00
|
|
|
#include <assert.h>
|
2012-05-12 01:00:57 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
add a "-duration duration,start,end" option to webpmux
this will force a constant duration for an interval of frames
in an animation.
Notes:
a) '-duration [...]' can be repeated as many times as needed.
b) intervals are taken into account in option order. If they overlap, values will be overwritten.
c) 'start' and 'end' can be omitted, but not the duration value.
d) 'end' can be equal to '0', in which case it means 'last frame'
e) single-image files are untouched (ie. not turned into an animation file).
Some example usage:
webpmux -duration 150 in.webp -o out.webp
webpmux -duration 33,10,0 in.webp -o out.webp
webpmux -duration 200,2 -duration 150,0,50 in.webp -o out.webp
Change-Id: I9b595dafa77f9221bacd080be7858b1457f54636
2016-10-21 15:14:45 +02:00
|
|
|
#include <string.h>
|
2014-04-23 04:33:22 +02:00
|
|
|
|
2018-02-08 08:09:14 +01:00
|
|
|
#include "webp/mux_types.h"
|
|
|
|
#include "../imageio/imageio_util.h"
|
|
|
|
|
2014-09-11 08:35:48 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// String parsing
|
|
|
|
|
|
|
|
uint32_t ExUtilGetUInt(const char* const v, int base, int* const error) {
|
|
|
|
char* end = NULL;
|
|
|
|
const uint32_t n = (v != NULL) ? (uint32_t)strtoul(v, &end, base) : 0u;
|
|
|
|
if (end == v && error != NULL && !*error) {
|
|
|
|
*error = 1;
|
|
|
|
fprintf(stderr, "Error! '%s' is not an integer.\n",
|
|
|
|
(v != NULL) ? v : "(null)");
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ExUtilGetInt(const char* const v, int base, int* const error) {
|
|
|
|
return (int)ExUtilGetUInt(v, base, error);
|
|
|
|
}
|
|
|
|
|
add a "-duration duration,start,end" option to webpmux
this will force a constant duration for an interval of frames
in an animation.
Notes:
a) '-duration [...]' can be repeated as many times as needed.
b) intervals are taken into account in option order. If they overlap, values will be overwritten.
c) 'start' and 'end' can be omitted, but not the duration value.
d) 'end' can be equal to '0', in which case it means 'last frame'
e) single-image files are untouched (ie. not turned into an animation file).
Some example usage:
webpmux -duration 150 in.webp -o out.webp
webpmux -duration 33,10,0 in.webp -o out.webp
webpmux -duration 200,2 -duration 150,0,50 in.webp -o out.webp
Change-Id: I9b595dafa77f9221bacd080be7858b1457f54636
2016-10-21 15:14:45 +02:00
|
|
|
int ExUtilGetInts(const char* v, int base, int max_output, int output[]) {
|
|
|
|
int n, error = 0;
|
|
|
|
for (n = 0; v != NULL && n < max_output; ++n) {
|
|
|
|
const int value = ExUtilGetInt(v, base, &error);
|
|
|
|
if (error) return -1;
|
|
|
|
output[n] = value;
|
|
|
|
v = strchr(v, ',');
|
|
|
|
if (v != NULL) ++v; // skip over the trailing ','
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2014-09-11 08:35:48 +02:00
|
|
|
float ExUtilGetFloat(const char* const v, int* const error) {
|
|
|
|
char* end = NULL;
|
|
|
|
const float f = (v != NULL) ? (float)strtod(v, &end) : 0.f;
|
|
|
|
if (end == v && error != NULL && !*error) {
|
|
|
|
*error = 1;
|
|
|
|
fprintf(stderr, "Error! '%s' is not a floating point number.\n",
|
|
|
|
(v != NULL) ? v : "(null)");
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
2018-02-08 08:09:14 +01:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static void ResetCommandLineArguments(int argc, const char* argv[],
|
|
|
|
CommandLineArguments* const args) {
|
|
|
|
assert(args != NULL);
|
|
|
|
args->argc_ = argc;
|
|
|
|
args->argv_ = argv;
|
|
|
|
args->own_argv_ = 0;
|
|
|
|
WebPDataInit(&args->argv_data_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExUtilDeleteCommandLineArguments(CommandLineArguments* const args) {
|
|
|
|
if (args != NULL) {
|
|
|
|
if (args->own_argv_) {
|
2019-10-15 23:16:51 +02:00
|
|
|
WebPFree((void*)args->argv_);
|
2018-02-08 08:09:14 +01:00
|
|
|
WebPDataClear(&args->argv_data_);
|
|
|
|
}
|
|
|
|
ResetCommandLineArguments(0, NULL, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_ARGC 16384
|
|
|
|
int ExUtilInitCommandLineArguments(int argc, const char* argv[],
|
|
|
|
CommandLineArguments* const args) {
|
|
|
|
if (args == NULL || argv == NULL) return 0;
|
|
|
|
ResetCommandLineArguments(argc, argv, args);
|
|
|
|
if (argc == 1 && argv[0][0] != '-') {
|
|
|
|
char* cur;
|
|
|
|
const char sep[] = " \t\r\n\f\v";
|
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
|
|
|
|
|
|
|
#if defined(_WIN32) && defined(_UNICODE)
|
|
|
|
fprintf(stderr,
|
|
|
|
"Error: Reading arguments from a file is a feature unavailable "
|
|
|
|
"with Unicode binaries.\n");
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
2018-02-08 08:09:14 +01:00
|
|
|
if (!ExUtilReadFileToWebPData(argv[0], &args->argv_data_)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
args->own_argv_ = 1;
|
2019-10-15 23:16:51 +02:00
|
|
|
args->argv_ = (const char**)WebPMalloc(MAX_ARGC * sizeof(*args->argv_));
|
2022-04-04 19:51:13 +02:00
|
|
|
if (args->argv_ == NULL) {
|
|
|
|
ExUtilDeleteCommandLineArguments(args);
|
|
|
|
return 0;
|
|
|
|
}
|
2018-02-08 08:09:14 +01:00
|
|
|
|
|
|
|
argc = 0;
|
|
|
|
for (cur = strtok((char*)args->argv_data_.bytes, sep);
|
|
|
|
cur != NULL;
|
|
|
|
cur = strtok(NULL, sep)) {
|
|
|
|
if (argc == MAX_ARGC) {
|
|
|
|
fprintf(stderr, "ERROR: Arguments limit %d reached\n", MAX_ARGC);
|
2022-04-04 19:51:13 +02:00
|
|
|
ExUtilDeleteCommandLineArguments(args);
|
2018-02-08 08:09:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
assert(strlen(cur) != 0);
|
|
|
|
args->argv_[argc++] = cur;
|
|
|
|
}
|
|
|
|
args->argc_ = argc;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int ExUtilReadFileToWebPData(const char* const filename,
|
|
|
|
WebPData* const webp_data) {
|
|
|
|
const uint8_t* data;
|
|
|
|
size_t size;
|
|
|
|
if (webp_data == NULL) return 0;
|
|
|
|
if (!ImgIoUtilReadFile(filename, &data, &size)) return 0;
|
|
|
|
webp_data->bytes = data;
|
|
|
|
webp_data->size = size;
|
|
|
|
return 1;
|
|
|
|
}
|