2012-01-06 23:49:06 +01:00
|
|
|
// Copyright 2011 Google Inc. All Rights Reserved.
|
2011-02-19 08:33:46 +01:00
|
|
|
//
|
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.
|
2011-02-19 08:33:46 +01:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// simple command line calling the WebPEncode function.
|
|
|
|
// Encodes a raw .YUV into WebP bitstream
|
|
|
|
//
|
|
|
|
// Author: Skal (pascal.massimino@gmail.com)
|
|
|
|
|
2020-08-12 11:40:08 +02:00
|
|
|
#include <assert.h>
|
2011-02-19 08:33:46 +01:00
|
|
|
#include <stdio.h>
|
2011-03-26 17:27:45 +01:00
|
|
|
#include <stdlib.h>
|
2011-02-19 08:33:46 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2011-06-07 02:56:50 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2014-06-11 02:53:44 +02:00
|
|
|
#include "webp/config.h"
|
2011-06-07 02:56:50 +02:00
|
|
|
#endif
|
|
|
|
|
2016-07-22 01:10:05 +02:00
|
|
|
#include "../examples/example_util.h"
|
2016-07-20 01:02:55 +02:00
|
|
|
#include "../imageio/image_dec.h"
|
2016-07-21 03:25:00 +02:00
|
|
|
#include "../imageio/imageio_util.h"
|
2020-08-12 11:40:08 +02:00
|
|
|
#include "../imageio/webpdec.h"
|
2012-05-15 22:48:11 +02:00
|
|
|
#include "./stopwatch.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"
|
2022-10-25 04:24:44 +02:00
|
|
|
#include "sharpyuv/sharpyuv.h"
|
2016-05-31 06:45:38 +02:00
|
|
|
#include "webp/encode.h"
|
2012-12-11 11:02:39 +01:00
|
|
|
|
2011-07-15 23:53:03 +02:00
|
|
|
#ifndef WEBP_DLL
|
2013-11-25 23:43:12 +01:00
|
|
|
#ifdef __cplusplus
|
2011-11-04 23:20:08 +01:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-09-02 23:30:08 +02:00
|
|
|
extern void* VP8GetCPUInfo; // opaque forward declaration.
|
2011-11-04 23:20:08 +01:00
|
|
|
|
2013-11-25 23:43:12 +01:00
|
|
|
#ifdef __cplusplus
|
2011-11-04 23:20:08 +01:00
|
|
|
} // extern "C"
|
2011-07-15 23:53:03 +02:00
|
|
|
#endif
|
2011-11-04 23:20:08 +01:00
|
|
|
#endif // WEBP_DLL
|
2011-04-22 21:14:45 +02:00
|
|
|
|
2011-08-25 23:22:32 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2011-02-19 08:33:46 +01:00
|
|
|
|
|
|
|
static int verbose = 0;
|
|
|
|
|
2015-12-08 08:22:41 +01:00
|
|
|
static int ReadYUV(const uint8_t* const data, size_t data_size,
|
|
|
|
WebPPicture* const pic) {
|
2012-07-18 23:58:53 +02:00
|
|
|
const int use_argb = pic->use_argb;
|
2011-02-19 08:33:46 +01:00
|
|
|
const int uv_width = (pic->width + 1) / 2;
|
|
|
|
const int uv_height = (pic->height + 1) / 2;
|
2016-05-25 07:54:57 +02:00
|
|
|
const int y_plane_size = pic->width * pic->height;
|
2015-11-13 00:05:02 +01:00
|
|
|
const int uv_plane_size = uv_width * uv_height;
|
2016-05-25 07:54:57 +02:00
|
|
|
const size_t expected_data_size = y_plane_size + 2 * uv_plane_size;
|
2015-11-13 00:05:02 +01:00
|
|
|
|
|
|
|
if (data_size != expected_data_size) {
|
|
|
|
fprintf(stderr,
|
2015-12-08 08:22:41 +01:00
|
|
|
"input data doesn't have the expected size (%d instead of %d)\n",
|
|
|
|
(int)data_size, (int)expected_data_size);
|
|
|
|
return 0;
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
|
2015-12-08 08:22:41 +01:00
|
|
|
pic->use_argb = 0;
|
|
|
|
if (!WebPPictureAlloc(pic)) return 0;
|
2016-07-22 00:36:29 +02:00
|
|
|
ImgIoUtilCopyPlane(data, pic->width, pic->y, pic->y_stride,
|
|
|
|
pic->width, pic->height);
|
|
|
|
ImgIoUtilCopyPlane(data + y_plane_size, uv_width,
|
|
|
|
pic->u, pic->uv_stride, uv_width, uv_height);
|
|
|
|
ImgIoUtilCopyPlane(data + y_plane_size + uv_plane_size, uv_width,
|
|
|
|
pic->v, pic->uv_stride, uv_width, uv_height);
|
2015-12-08 08:22:41 +01:00
|
|
|
return use_argb ? WebPPictureYUVAToARGB(pic) : 1;
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
|
2011-06-07 02:56:50 +02:00
|
|
|
#ifdef HAVE_WINCODEC_H
|
2011-02-19 08:33:46 +01:00
|
|
|
|
EXPERIMENTAL: add support for alpha channel
This is a (minor) bitstream change: if the 'color_space' bit is set to '1'
(which is normally an undefined/invalid behaviour), we add extra data at the
end of partition #0 (so-called 'extensions')
Namely, we add the size of the extension data as 3 bytes (little-endian),
followed by a set of bits telling which extensions we're incorporating.
The data then _preceeds_ this trailing tags.
This is all experimental, and you'll need to have
'#define WEBP_EXPERIMENTAL_FEATURES' in webp/types.h to enable this code
(at your own risk! :))
Still, this hack produces almost-valid WebP file for decoders that don't
check this color_space bit. In particular, previous 'dwebp' (and for instance
Chrome) will recognize this files and decode them, but without the alpha
of course. Other decoder will just see random extra stuff at the end of
partition #0.
To experiment with the alpha-channel, you need to compile on Unix platform
and use PNGs for input/output.
If 'alpha.png' is a source with alpha channel, then you can try (on Unix):
cwebp alpha.png -o alpha.webp
dwebp alpha.webp -o test.png
cwebp now has a '-noalpha' flag to ignore any alpha information from the
source, if present.
More hacking and experimenting welcome!
Change-Id: I3c7b1fd8411c9e7a9f77690e898479ad85c52f3e
2011-04-26 01:58:04 +02:00
|
|
|
static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
2012-12-04 03:20:00 +01:00
|
|
|
int keep_alpha, Metadata* const metadata) {
|
2015-12-08 08:22:41 +01:00
|
|
|
int ok = 0;
|
|
|
|
const uint8_t* data = NULL;
|
|
|
|
size_t data_size = 0;
|
2011-02-19 08:33:46 +01:00
|
|
|
if (pic->width != 0 && pic->height != 0) {
|
2016-07-22 00:36:29 +02:00
|
|
|
ok = ImgIoUtilReadFile(filename, &data, &data_size);
|
2015-12-08 08:22:41 +01:00
|
|
|
ok = ok && ReadYUV(data, data_size, pic);
|
2011-02-19 08:33:46 +01:00
|
|
|
} else {
|
|
|
|
// If no size specified, try to decode it using WIC.
|
2013-01-25 00:37:49 +01:00
|
|
|
ok = ReadPictureWithWIC(filename, pic, keep_alpha, metadata);
|
2014-05-25 03:30:33 +02:00
|
|
|
if (!ok) {
|
2016-07-22 00:36:29 +02:00
|
|
|
ok = ImgIoUtilReadFile(filename, &data, &data_size);
|
2015-12-08 08:22:41 +01:00
|
|
|
ok = ok && ReadWebP(data, data_size, pic, keep_alpha, metadata);
|
2014-05-25 03:30:33 +02:00
|
|
|
}
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
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! Could not process file %s\n",
|
|
|
|
(const W_CHAR*)filename);
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
2020-10-16 15:37:26 +02:00
|
|
|
WebPFree((void*)data);
|
2011-02-19 08:33:46 +01:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2011-06-07 02:56:50 +02:00
|
|
|
#else // !HAVE_WINCODEC_H
|
2011-02-19 08:33:46 +01:00
|
|
|
|
EXPERIMENTAL: add support for alpha channel
This is a (minor) bitstream change: if the 'color_space' bit is set to '1'
(which is normally an undefined/invalid behaviour), we add extra data at the
end of partition #0 (so-called 'extensions')
Namely, we add the size of the extension data as 3 bytes (little-endian),
followed by a set of bits telling which extensions we're incorporating.
The data then _preceeds_ this trailing tags.
This is all experimental, and you'll need to have
'#define WEBP_EXPERIMENTAL_FEATURES' in webp/types.h to enable this code
(at your own risk! :))
Still, this hack produces almost-valid WebP file for decoders that don't
check this color_space bit. In particular, previous 'dwebp' (and for instance
Chrome) will recognize this files and decode them, but without the alpha
of course. Other decoder will just see random extra stuff at the end of
partition #0.
To experiment with the alpha-channel, you need to compile on Unix platform
and use PNGs for input/output.
If 'alpha.png' is a source with alpha channel, then you can try (on Unix):
cwebp alpha.png -o alpha.webp
dwebp alpha.webp -o test.png
cwebp now has a '-noalpha' flag to ignore any alpha information from the
source, if present.
More hacking and experimenting welcome!
Change-Id: I3c7b1fd8411c9e7a9f77690e898479ad85c52f3e
2011-04-26 01:58:04 +02:00
|
|
|
static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
2012-12-04 03:20:00 +01:00
|
|
|
int keep_alpha, Metadata* const metadata) {
|
2015-12-08 08:22:41 +01:00
|
|
|
const uint8_t* data = NULL;
|
|
|
|
size_t data_size = 0;
|
2011-02-19 08:33:46 +01:00
|
|
|
int ok = 0;
|
2015-12-08 08:22:41 +01:00
|
|
|
|
2016-07-22 00:36:29 +02:00
|
|
|
ok = ImgIoUtilReadFile(filename, &data, &data_size);
|
2015-12-08 08:22:41 +01:00
|
|
|
if (!ok) goto End;
|
|
|
|
|
2011-02-19 08:33:46 +01:00
|
|
|
if (pic->width == 0 || pic->height == 0) {
|
2016-06-01 20:55:29 +02:00
|
|
|
WebPImageReader reader = WebPGuessImageReader(data, data_size);
|
2016-10-08 20:57:13 +02:00
|
|
|
ok = reader(data, data_size, pic, keep_alpha, metadata);
|
2011-02-19 08:33:46 +01:00
|
|
|
} else {
|
|
|
|
// If image size is specified, infer it as YUV format.
|
2015-12-08 08:22:41 +01:00
|
|
|
ok = ReadYUV(data, data_size, pic);
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
2015-12-08 08:22:41 +01:00
|
|
|
End:
|
2011-02-19 08:33:46 +01:00
|
|
|
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! Could not process file %s\n",
|
|
|
|
(const W_CHAR*)filename);
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
2020-10-16 15:37:26 +02:00
|
|
|
WebPFree((void*)data);
|
2011-02-19 08:33:46 +01:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2011-06-07 02:56:50 +02:00
|
|
|
#endif // !HAVE_WINCODEC_H
|
2011-02-19 08:33:46 +01:00
|
|
|
|
|
|
|
static void AllocExtraInfo(WebPPicture* const pic) {
|
|
|
|
const int mb_w = (pic->width + 15) / 16;
|
|
|
|
const int mb_h = (pic->height + 15) / 16;
|
2019-10-15 23:16:51 +02:00
|
|
|
pic->extra_info =
|
|
|
|
(uint8_t*)WebPMalloc(mb_w * mb_h * sizeof(*pic->extra_info));
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintByteCount(const int bytes[4], int total_size,
|
|
|
|
int* const totals) {
|
|
|
|
int s;
|
|
|
|
int total = 0;
|
|
|
|
for (s = 0; s < 4; ++s) {
|
|
|
|
fprintf(stderr, "| %7d ", bytes[s]);
|
|
|
|
total += bytes[s];
|
|
|
|
if (totals) totals[s] += bytes[s];
|
|
|
|
}
|
2011-11-04 23:20:08 +01:00
|
|
|
fprintf(stderr, "| %7d (%.1f%%)\n", total, 100.f * total / total_size);
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
|
2017-12-27 17:10:39 +01:00
|
|
|
static void PrintPercents(const int counts[4]) {
|
2011-02-19 08:33:46 +01:00
|
|
|
int s;
|
2017-12-27 17:10:39 +01:00
|
|
|
const int total = counts[0] + counts[1] + counts[2] + counts[3];
|
2011-02-19 08:33:46 +01:00
|
|
|
for (s = 0; s < 4; ++s) {
|
2020-08-12 11:40:08 +02:00
|
|
|
fprintf(stderr, "| %3d%%", (int)(100. * counts[s] / total + .5));
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
2011-11-04 23:20:08 +01:00
|
|
|
fprintf(stderr, "| %7d\n", total);
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintValues(const int values[4]) {
|
|
|
|
int s;
|
|
|
|
for (s = 0; s < 4; ++s) {
|
|
|
|
fprintf(stderr, "| %7d ", values[s]);
|
|
|
|
}
|
2011-11-04 23:20:08 +01:00
|
|
|
fprintf(stderr, "|\n");
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
|
2012-07-25 01:15:36 +02:00
|
|
|
static void PrintFullLosslessInfo(const WebPAuxStats* const stats,
|
|
|
|
const char* const description) {
|
|
|
|
fprintf(stderr, "Lossless-%s compressed size: %d bytes\n",
|
|
|
|
description, stats->lossless_size);
|
2014-09-17 23:11:52 +02:00
|
|
|
fprintf(stderr, " * Header size: %d bytes, image data size: %d\n",
|
|
|
|
stats->lossless_hdr_size, stats->lossless_data_size);
|
2012-07-25 01:15:36 +02:00
|
|
|
if (stats->lossless_features) {
|
|
|
|
fprintf(stderr, " * Lossless features used:");
|
|
|
|
if (stats->lossless_features & 1) fprintf(stderr, " PREDICTION");
|
|
|
|
if (stats->lossless_features & 2) fprintf(stderr, " CROSS-COLOR-TRANSFORM");
|
|
|
|
if (stats->lossless_features & 4) fprintf(stderr, " SUBTRACT-GREEN");
|
|
|
|
if (stats->lossless_features & 8) fprintf(stderr, " PALETTE");
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
fprintf(stderr, " * Precision Bits: histogram=%d transform=%d cache=%d\n",
|
|
|
|
stats->histogram_bits, stats->transform_bits, stats->cache_bits);
|
|
|
|
if (stats->palette_size > 0) {
|
|
|
|
fprintf(stderr, " * Palette size: %d\n", stats->palette_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-09 07:57:46 +02:00
|
|
|
static void PrintExtraInfoLossless(const WebPPicture* const pic,
|
|
|
|
int short_output,
|
|
|
|
const char* const file_name) {
|
|
|
|
const WebPAuxStats* const stats = pic->stats;
|
|
|
|
if (short_output) {
|
|
|
|
fprintf(stderr, "%7d %2.2f\n", stats->coded_size, stats->PSNR[3]);
|
|
|
|
} 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
|
|
|
WFPRINTF(stderr, "File: %s\n", (const W_CHAR*)file_name);
|
2012-05-09 07:57:46 +02:00
|
|
|
fprintf(stderr, "Dimension: %d x %d\n", pic->width, pic->height);
|
2018-02-19 22:33:45 +01:00
|
|
|
fprintf(stderr, "Output: %d bytes (%.2f bpp)\n", stats->coded_size,
|
2018-04-11 00:51:23 +02:00
|
|
|
8.f * stats->coded_size / pic->width / pic->height);
|
2012-07-25 01:15:36 +02:00
|
|
|
PrintFullLosslessInfo(stats, "ARGB");
|
2012-05-09 07:57:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintExtraInfoLossy(const WebPPicture* const pic, int short_output,
|
2013-03-12 00:37:42 +01:00
|
|
|
int full_details,
|
2012-05-09 07:57:46 +02:00
|
|
|
const char* const file_name) {
|
2011-02-19 08:33:46 +01:00
|
|
|
const WebPAuxStats* const stats = pic->stats;
|
|
|
|
if (short_output) {
|
|
|
|
fprintf(stderr, "%7d %2.2f\n", stats->coded_size, stats->PSNR[3]);
|
2011-11-04 23:20:08 +01:00
|
|
|
} else {
|
2011-02-19 08:33:46 +01:00
|
|
|
const int num_i4 = stats->block_count[0];
|
|
|
|
const int num_i16 = stats->block_count[1];
|
|
|
|
const int num_skip = stats->block_count[2];
|
|
|
|
const int total = num_i4 + num_i16;
|
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, "File: %s\n", (const W_CHAR*)file_name);
|
2012-01-20 16:20:56 +01:00
|
|
|
fprintf(stderr, "Dimension: %d x %d%s\n",
|
2012-06-08 02:32:29 +02:00
|
|
|
pic->width, pic->height,
|
|
|
|
stats->alpha_data_size ? " (with alpha)" : "");
|
2012-01-20 16:20:56 +01:00
|
|
|
fprintf(stderr, "Output: "
|
2018-02-19 22:33:45 +01:00
|
|
|
"%d bytes Y-U-V-All-PSNR %2.2f %2.2f %2.2f %2.2f dB\n"
|
|
|
|
" (%.2f bpp)\n",
|
2011-02-19 08:33:46 +01:00
|
|
|
stats->coded_size,
|
2018-02-19 22:33:45 +01:00
|
|
|
stats->PSNR[0], stats->PSNR[1], stats->PSNR[2], stats->PSNR[3],
|
2018-04-11 00:51:23 +02:00
|
|
|
8.f * stats->coded_size / pic->width / pic->height);
|
2011-02-19 08:33:46 +01:00
|
|
|
if (total > 0) {
|
|
|
|
int totals[4] = { 0, 0, 0, 0 };
|
2017-12-27 17:10:39 +01:00
|
|
|
fprintf(stderr, "block count: intra4: %6d (%.2f%%)\n"
|
|
|
|
" intra16: %6d (%.2f%%)\n"
|
|
|
|
" skipped: %6d (%.2f%%)\n",
|
|
|
|
num_i4, 100.f * num_i4 / total,
|
|
|
|
num_i16, 100.f * num_i16 / total,
|
2011-02-19 08:33:46 +01:00
|
|
|
num_skip, 100.f * num_skip / total);
|
|
|
|
fprintf(stderr, "bytes used: header: %6d (%.1f%%)\n"
|
|
|
|
" mode-partition: %6d (%.1f%%)\n",
|
|
|
|
stats->header_bytes[0],
|
|
|
|
100.f * stats->header_bytes[0] / stats->coded_size,
|
|
|
|
stats->header_bytes[1],
|
|
|
|
100.f * stats->header_bytes[1] / stats->coded_size);
|
2012-07-25 01:15:36 +02:00
|
|
|
if (stats->alpha_data_size > 0) {
|
|
|
|
fprintf(stderr, " transparency: %6d (%.1f dB)\n",
|
|
|
|
stats->alpha_data_size, stats->PSNR[4]);
|
EXPERIMENTAL: add support for alpha channel
This is a (minor) bitstream change: if the 'color_space' bit is set to '1'
(which is normally an undefined/invalid behaviour), we add extra data at the
end of partition #0 (so-called 'extensions')
Namely, we add the size of the extension data as 3 bytes (little-endian),
followed by a set of bits telling which extensions we're incorporating.
The data then _preceeds_ this trailing tags.
This is all experimental, and you'll need to have
'#define WEBP_EXPERIMENTAL_FEATURES' in webp/types.h to enable this code
(at your own risk! :))
Still, this hack produces almost-valid WebP file for decoders that don't
check this color_space bit. In particular, previous 'dwebp' (and for instance
Chrome) will recognize this files and decode them, but without the alpha
of course. Other decoder will just see random extra stuff at the end of
partition #0.
To experiment with the alpha-channel, you need to compile on Unix platform
and use PNGs for input/output.
If 'alpha.png' is a source with alpha channel, then you can try (on Unix):
cwebp alpha.png -o alpha.webp
dwebp alpha.webp -o test.png
cwebp now has a '-noalpha' flag to ignore any alpha information from the
source, if present.
More hacking and experimenting welcome!
Change-Id: I3c7b1fd8411c9e7a9f77690e898479ad85c52f3e
2011-04-26 01:58:04 +02:00
|
|
|
}
|
2011-02-19 08:33:46 +01:00
|
|
|
fprintf(stderr, " Residuals bytes "
|
|
|
|
"|segment 1|segment 2|segment 3"
|
|
|
|
"|segment 4| total\n");
|
2013-03-12 00:37:42 +01:00
|
|
|
if (full_details) {
|
|
|
|
fprintf(stderr, " intra4-coeffs: ");
|
|
|
|
PrintByteCount(stats->residual_bytes[0], stats->coded_size, totals);
|
|
|
|
fprintf(stderr, " intra16-coeffs: ");
|
|
|
|
PrintByteCount(stats->residual_bytes[1], stats->coded_size, totals);
|
|
|
|
fprintf(stderr, " chroma coeffs: ");
|
|
|
|
PrintByteCount(stats->residual_bytes[2], stats->coded_size, totals);
|
|
|
|
}
|
2011-02-19 08:33:46 +01:00
|
|
|
fprintf(stderr, " macroblocks: ");
|
2017-12-27 17:10:39 +01:00
|
|
|
PrintPercents(stats->segment_size);
|
2011-02-19 08:33:46 +01:00
|
|
|
fprintf(stderr, " quantizer: ");
|
|
|
|
PrintValues(stats->segment_quant);
|
|
|
|
fprintf(stderr, " filter level: ");
|
|
|
|
PrintValues(stats->segment_level);
|
2013-03-12 00:37:42 +01:00
|
|
|
if (full_details) {
|
|
|
|
fprintf(stderr, "------------------+---------");
|
|
|
|
fprintf(stderr, "+---------+---------+---------+-----------------\n");
|
|
|
|
fprintf(stderr, " segments total: ");
|
|
|
|
PrintByteCount(totals, stats->coded_size, NULL);
|
|
|
|
}
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
2012-07-25 01:15:36 +02:00
|
|
|
if (stats->lossless_size > 0) {
|
|
|
|
PrintFullLosslessInfo(stats, "alpha");
|
|
|
|
}
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
2013-12-23 12:03:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintMapInfo(const WebPPicture* const pic) {
|
2012-07-25 01:15:36 +02:00
|
|
|
if (pic->extra_info != NULL) {
|
2011-02-19 08:33:46 +01:00
|
|
|
const int mb_w = (pic->width + 15) / 16;
|
|
|
|
const int mb_h = (pic->height + 15) / 16;
|
|
|
|
const int type = pic->extra_info_type;
|
|
|
|
int x, y;
|
|
|
|
for (y = 0; y < mb_h; ++y) {
|
|
|
|
for (x = 0; x < mb_w; ++x) {
|
|
|
|
const int c = pic->extra_info[x + y * mb_w];
|
|
|
|
if (type == 1) { // intra4/intra16
|
2014-03-12 19:48:00 +01:00
|
|
|
fprintf(stderr, "%c", "+."[c]);
|
2011-02-19 08:33:46 +01:00
|
|
|
} else if (type == 2) { // segments
|
2014-03-12 19:48:00 +01:00
|
|
|
fprintf(stderr, "%c", ".-*X"[c]);
|
2011-02-19 08:33:46 +01:00
|
|
|
} else if (type == 3) { // quantizers
|
2014-03-12 19:48:00 +01:00
|
|
|
fprintf(stderr, "%.2d ", c);
|
2011-02-19 08:33:46 +01:00
|
|
|
} else if (type == 6 || type == 7) {
|
2014-03-12 19:48:00 +01:00
|
|
|
fprintf(stderr, "%3d ", c);
|
2011-02-19 08:33:46 +01:00
|
|
|
} else {
|
2014-03-12 19:48:00 +01:00
|
|
|
fprintf(stderr, "0x%.2x ", c);
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-12 19:48:00 +01:00
|
|
|
fprintf(stderr, "\n");
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-25 23:22:32 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2011-02-19 08:33:46 +01:00
|
|
|
|
|
|
|
static int MyWriter(const uint8_t* data, size_t data_size,
|
|
|
|
const WebPPicture* const pic) {
|
|
|
|
FILE* const out = (FILE*)pic->custom_ptr;
|
|
|
|
return data_size ? (fwrite(data, data_size, 1, out) == 1) : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dumps a picture as a PGM file using the IMC4 layout.
|
|
|
|
static int DumpPicture(const WebPPicture* const picture, const char* PGM_name) {
|
|
|
|
int y;
|
|
|
|
const int uv_width = (picture->width + 1) / 2;
|
|
|
|
const int uv_height = (picture->height + 1) / 2;
|
|
|
|
const int stride = (picture->width + 1) & ~1;
|
2017-01-04 09:54:23 +01:00
|
|
|
const uint8_t* src_y = picture->y;
|
|
|
|
const uint8_t* src_u = picture->u;
|
|
|
|
const uint8_t* src_v = picture->v;
|
|
|
|
const uint8_t* src_a = picture->a;
|
2012-06-05 00:50:05 +02:00
|
|
|
const int alpha_height =
|
|
|
|
WebPPictureHasTransparency(picture) ? picture->height : 0;
|
2011-07-08 01:08:15 +02:00
|
|
|
const int height = picture->height + uv_height + alpha_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
|
|
|
FILE* const f = WFOPEN(PGM_name, "wb");
|
2012-01-20 16:20:56 +01:00
|
|
|
if (f == NULL) return 0;
|
2011-02-19 08:33:46 +01:00
|
|
|
fprintf(f, "P5\n%d %d\n255\n", stride, height);
|
|
|
|
for (y = 0; y < picture->height; ++y) {
|
2017-01-04 09:54:23 +01:00
|
|
|
if (fwrite(src_y, picture->width, 1, f) != 1) return 0;
|
2011-02-19 08:33:46 +01:00
|
|
|
if (picture->width & 1) fputc(0, f); // pad
|
2017-01-04 09:54:23 +01:00
|
|
|
src_y += picture->y_stride;
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
for (y = 0; y < uv_height; ++y) {
|
2017-01-04 09:54:23 +01:00
|
|
|
if (fwrite(src_u, uv_width, 1, f) != 1) return 0;
|
|
|
|
if (fwrite(src_v, uv_width, 1, f) != 1) return 0;
|
|
|
|
src_u += picture->uv_stride;
|
|
|
|
src_v += picture->uv_stride;
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
2011-07-08 01:08:15 +02:00
|
|
|
for (y = 0; y < alpha_height; ++y) {
|
2017-01-04 09:54:23 +01:00
|
|
|
if (fwrite(src_a, picture->width, 1, f) != 1) return 0;
|
2011-07-08 01:08:15 +02:00
|
|
|
if (picture->width & 1) fputc(0, f); // pad
|
2017-01-04 09:54:23 +01:00
|
|
|
src_a += picture->a_stride;
|
2011-07-08 01:08:15 +02:00
|
|
|
}
|
2011-02-19 08:33:46 +01:00
|
|
|
fclose(f);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-01-11 21:25:36 +01:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Metadata writing.
|
|
|
|
|
|
|
|
enum {
|
|
|
|
METADATA_EXIF = (1 << 0),
|
2013-03-13 22:04:20 +01:00
|
|
|
METADATA_ICC = (1 << 1),
|
2013-01-11 21:25:36 +01:00
|
|
|
METADATA_XMP = (1 << 2),
|
2013-03-13 22:04:20 +01:00
|
|
|
METADATA_ALL = METADATA_EXIF | METADATA_ICC | METADATA_XMP
|
2013-01-11 21:25:36 +01:00
|
|
|
};
|
|
|
|
|
2013-01-15 03:32:44 +01:00
|
|
|
static const int kChunkHeaderSize = 8;
|
|
|
|
static const int kTagSize = 4;
|
|
|
|
|
2013-03-13 22:41:38 +01:00
|
|
|
static void PrintMetadataInfo(const Metadata* const metadata,
|
|
|
|
int metadata_written) {
|
|
|
|
if (metadata == NULL || metadata_written == 0) return;
|
|
|
|
|
|
|
|
fprintf(stderr, "Metadata:\n");
|
2013-03-16 00:42:58 +01:00
|
|
|
if (metadata_written & METADATA_ICC) {
|
2013-03-21 00:59:35 +01:00
|
|
|
fprintf(stderr, " * ICC profile: %6d bytes\n", (int)metadata->iccp.size);
|
2013-03-13 22:41:38 +01:00
|
|
|
}
|
|
|
|
if (metadata_written & METADATA_EXIF) {
|
2013-03-21 00:59:35 +01:00
|
|
|
fprintf(stderr, " * EXIF data: %6d bytes\n", (int)metadata->exif.size);
|
2013-03-13 22:41:38 +01:00
|
|
|
}
|
|
|
|
if (metadata_written & METADATA_XMP) {
|
2013-03-21 00:59:35 +01:00
|
|
|
fprintf(stderr, " * XMP data: %6d bytes\n", (int)metadata->xmp.size);
|
2013-03-13 22:41:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-15 03:32:44 +01:00
|
|
|
// Outputs, in little endian, 'num' bytes from 'val' to 'out'.
|
|
|
|
static int WriteLE(FILE* const out, uint32_t val, int num) {
|
|
|
|
uint8_t buf[4];
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < num; ++i) {
|
|
|
|
buf[i] = (uint8_t)(val & 0xff);
|
|
|
|
val >>= 8;
|
|
|
|
}
|
|
|
|
return (fwrite(buf, num, 1, out) == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int WriteLE24(FILE* const out, uint32_t val) {
|
|
|
|
return WriteLE(out, val, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int WriteLE32(FILE* const out, uint32_t val) {
|
|
|
|
return WriteLE(out, val, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int WriteMetadataChunk(FILE* const out, const char fourcc[4],
|
|
|
|
const MetadataPayload* const payload) {
|
|
|
|
const uint8_t zero = 0;
|
|
|
|
const size_t need_padding = payload->size & 1;
|
|
|
|
int ok = (fwrite(fourcc, kTagSize, 1, out) == 1);
|
|
|
|
ok = ok && WriteLE32(out, (uint32_t)payload->size);
|
|
|
|
ok = ok && (fwrite(payload->bytes, payload->size, 1, out) == 1);
|
|
|
|
return ok && (fwrite(&zero, need_padding, need_padding, out) == need_padding);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets 'flag' in 'vp8x_flags' and updates 'metadata_size' with the size of the
|
|
|
|
// chunk if there is metadata and 'keep' is true.
|
|
|
|
static int UpdateFlagsAndSize(const MetadataPayload* const payload,
|
|
|
|
int keep, int flag,
|
|
|
|
uint32_t* vp8x_flags, uint64_t* metadata_size) {
|
|
|
|
if (keep && payload->bytes != NULL && payload->size > 0) {
|
|
|
|
*vp8x_flags |= flag;
|
|
|
|
*metadata_size += kChunkHeaderSize + payload->size + (payload->size & 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Writes a WebP file using the image contained in 'memory_writer' and the
|
|
|
|
// metadata from 'metadata'. Metadata is controlled by 'keep_metadata' and the
|
|
|
|
// availability in 'metadata'. Returns true on success.
|
|
|
|
// For details see doc/webp-container-spec.txt#extended-file-format.
|
|
|
|
static int WriteWebPWithMetadata(FILE* const out,
|
|
|
|
const WebPPicture* const picture,
|
|
|
|
const WebPMemoryWriter* const memory_writer,
|
|
|
|
const Metadata* const metadata,
|
2013-03-13 22:41:38 +01:00
|
|
|
int keep_metadata,
|
|
|
|
int* const metadata_written) {
|
2013-01-15 03:32:44 +01:00
|
|
|
const char kVP8XHeader[] = "VP8X\x0a\x00\x00\x00";
|
|
|
|
const int kAlphaFlag = 0x10;
|
|
|
|
const int kEXIFFlag = 0x08;
|
|
|
|
const int kICCPFlag = 0x20;
|
|
|
|
const int kXMPFlag = 0x04;
|
|
|
|
const size_t kRiffHeaderSize = 12;
|
|
|
|
const size_t kMaxChunkPayload = ~0 - kChunkHeaderSize - 1;
|
|
|
|
const size_t kMinSize = kRiffHeaderSize + kChunkHeaderSize;
|
|
|
|
uint32_t flags = 0;
|
|
|
|
uint64_t metadata_size = 0;
|
|
|
|
const int write_exif = UpdateFlagsAndSize(&metadata->exif,
|
|
|
|
!!(keep_metadata & METADATA_EXIF),
|
|
|
|
kEXIFFlag, &flags, &metadata_size);
|
|
|
|
const int write_iccp = UpdateFlagsAndSize(&metadata->iccp,
|
2013-03-13 22:04:20 +01:00
|
|
|
!!(keep_metadata & METADATA_ICC),
|
2013-01-15 03:32:44 +01:00
|
|
|
kICCPFlag, &flags, &metadata_size);
|
|
|
|
const int write_xmp = UpdateFlagsAndSize(&metadata->xmp,
|
|
|
|
!!(keep_metadata & METADATA_XMP),
|
|
|
|
kXMPFlag, &flags, &metadata_size);
|
|
|
|
uint8_t* webp = memory_writer->mem;
|
|
|
|
size_t webp_size = memory_writer->size;
|
2013-03-13 22:41:38 +01:00
|
|
|
|
|
|
|
*metadata_written = 0;
|
|
|
|
|
2013-01-15 03:32:44 +01:00
|
|
|
if (webp_size < kMinSize) return 0;
|
|
|
|
if (webp_size - kChunkHeaderSize + metadata_size > kMaxChunkPayload) {
|
|
|
|
fprintf(stderr, "Error! Addition of metadata would exceed "
|
|
|
|
"container size limit.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (metadata_size > 0) {
|
|
|
|
const int kVP8XChunkSize = 18;
|
|
|
|
const int has_vp8x = !memcmp(webp + kRiffHeaderSize, "VP8X", kTagSize);
|
|
|
|
const uint32_t riff_size = (uint32_t)(webp_size - kChunkHeaderSize +
|
|
|
|
(has_vp8x ? 0 : kVP8XChunkSize) +
|
|
|
|
metadata_size);
|
|
|
|
// RIFF
|
|
|
|
int ok = (fwrite(webp, kTagSize, 1, out) == 1);
|
|
|
|
// RIFF size (file header size is not recorded)
|
|
|
|
ok = ok && WriteLE32(out, riff_size);
|
|
|
|
webp += kChunkHeaderSize;
|
|
|
|
webp_size -= kChunkHeaderSize;
|
|
|
|
// WEBP
|
|
|
|
ok = ok && (fwrite(webp, kTagSize, 1, out) == 1);
|
|
|
|
webp += kTagSize;
|
|
|
|
webp_size -= kTagSize;
|
|
|
|
if (has_vp8x) { // update the existing VP8X flags
|
|
|
|
webp[kChunkHeaderSize] |= (uint8_t)(flags & 0xff);
|
|
|
|
ok = ok && (fwrite(webp, kVP8XChunkSize, 1, out) == 1);
|
2013-12-19 19:17:08 +01:00
|
|
|
webp += kVP8XChunkSize;
|
2013-01-15 03:32:44 +01:00
|
|
|
webp_size -= kVP8XChunkSize;
|
|
|
|
} else {
|
|
|
|
const int is_lossless = !memcmp(webp, "VP8L", kTagSize);
|
2013-07-19 20:55:09 +02:00
|
|
|
if (is_lossless) {
|
2017-10-18 21:33:30 +02:00
|
|
|
// Presence of alpha is stored in the 37th bit (29th after the
|
|
|
|
// signature) of VP8L data.
|
|
|
|
if (webp[kChunkHeaderSize + 4] & (1 << 4)) flags |= kAlphaFlag;
|
2013-07-19 20:55:09 +02:00
|
|
|
}
|
2013-01-15 03:32:44 +01:00
|
|
|
ok = ok && (fwrite(kVP8XHeader, kChunkHeaderSize, 1, out) == 1);
|
|
|
|
ok = ok && WriteLE32(out, flags);
|
|
|
|
ok = ok && WriteLE24(out, picture->width - 1);
|
|
|
|
ok = ok && WriteLE24(out, picture->height - 1);
|
|
|
|
}
|
2013-03-13 22:41:38 +01:00
|
|
|
if (write_iccp) {
|
|
|
|
ok = ok && WriteMetadataChunk(out, "ICCP", &metadata->iccp);
|
2013-03-16 00:42:58 +01:00
|
|
|
*metadata_written |= METADATA_ICC;
|
2013-03-13 22:41:38 +01:00
|
|
|
}
|
2013-01-15 03:32:44 +01:00
|
|
|
// Image
|
|
|
|
ok = ok && (fwrite(webp, webp_size, 1, out) == 1);
|
2013-03-13 22:41:38 +01:00
|
|
|
if (write_exif) {
|
|
|
|
ok = ok && WriteMetadataChunk(out, "EXIF", &metadata->exif);
|
|
|
|
*metadata_written |= METADATA_EXIF;
|
|
|
|
}
|
|
|
|
if (write_xmp) {
|
|
|
|
ok = ok && WriteMetadataChunk(out, "XMP ", &metadata->xmp);
|
|
|
|
*metadata_written |= METADATA_XMP;
|
|
|
|
}
|
2013-01-15 03:32:44 +01:00
|
|
|
return ok;
|
|
|
|
}
|
2017-08-26 23:20:51 +02:00
|
|
|
|
|
|
|
// No metadata, just write the original image file.
|
|
|
|
return (fwrite(webp, webp_size, 1, out) == 1);
|
2013-01-15 03:32:44 +01:00
|
|
|
}
|
|
|
|
|
2011-08-25 23:22:32 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2011-02-19 08:33:46 +01:00
|
|
|
|
2011-12-01 11:24:50 +01:00
|
|
|
static int ProgressReport(int percent, const WebPPicture* const picture) {
|
2014-03-12 19:48:00 +01:00
|
|
|
fprintf(stderr, "[%s]: %3d %% \r",
|
|
|
|
(char*)picture->user_data, percent);
|
2011-12-01 11:24:50 +01:00
|
|
|
return 1; // all ok
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2011-03-25 23:04:11 +01:00
|
|
|
static void HelpShort(void) {
|
2011-02-19 08:33:46 +01:00
|
|
|
printf("Usage:\n\n");
|
|
|
|
printf(" cwebp [options] -q quality input.png -o output.webp\n\n");
|
|
|
|
printf("where quality is between 0 (poor) to 100 (very good).\n");
|
|
|
|
printf("Typical value is around 80.\n\n");
|
|
|
|
printf("Try -longhelp for an exhaustive list of advanced options.\n");
|
|
|
|
}
|
|
|
|
|
2011-03-25 23:04:11 +01:00
|
|
|
static void HelpLong(void) {
|
2011-02-19 08:33:46 +01:00
|
|
|
printf("Usage:\n");
|
|
|
|
printf(" cwebp [-preset <...>] [options] in_file [-o out_file]\n\n");
|
2014-06-18 16:45:34 +02:00
|
|
|
printf("If input size (-s) for an image is not specified, it is\n"
|
|
|
|
"assumed to be a PNG, JPEG, TIFF or WebP file.\n");
|
2020-11-20 04:15:57 +01:00
|
|
|
printf("Note: Animated PNG and WebP files are not supported.\n");
|
2011-06-07 02:56:50 +02:00
|
|
|
#ifdef HAVE_WINCODEC_H
|
2014-06-18 16:45:34 +02:00
|
|
|
printf("Windows builds can take as input any of the files handled by WIC.\n");
|
2011-02-19 08:33:46 +01:00
|
|
|
#endif
|
2014-06-18 16:45:34 +02:00
|
|
|
printf("\nOptions:\n");
|
2016-06-25 04:25:11 +02:00
|
|
|
printf(" -h / -help ............. short help\n");
|
|
|
|
printf(" -H / -longhelp ......... long help\n");
|
2016-08-09 19:03:55 +02:00
|
|
|
printf(" -q <float> ............. quality factor (0:small..100:big), "
|
|
|
|
"default=75\n");
|
|
|
|
printf(" -alpha_q <int> ......... transparency-compression quality (0..100),"
|
|
|
|
"\n default=100\n");
|
2014-06-18 16:45:34 +02:00
|
|
|
printf(" -preset <string> ....... preset setting, one of:\n");
|
2011-02-19 08:33:46 +01:00
|
|
|
printf(" default, photo, picture,\n");
|
|
|
|
printf(" drawing, icon, text\n");
|
2014-06-18 16:45:34 +02:00
|
|
|
printf(" -preset must come first, as it overwrites other parameters\n");
|
|
|
|
printf(" -z <int> ............... activates lossless preset with given\n"
|
2014-03-11 23:25:35 +01:00
|
|
|
" level in [0:fast, ..., 9:slowest]\n");
|
2011-02-19 08:33:46 +01:00
|
|
|
printf("\n");
|
2016-08-09 19:03:55 +02:00
|
|
|
printf(" -m <int> ............... compression method (0=fast, 6=slowest), "
|
|
|
|
"default=4\n");
|
|
|
|
printf(" -segments <int> ........ number of segments to use (1..4), "
|
|
|
|
"default=4\n");
|
2014-06-18 16:45:34 +02:00
|
|
|
printf(" -size <int> ............ target size (in bytes)\n");
|
|
|
|
printf(" -psnr <float> .......... target PSNR (in dB. typically: 42)\n");
|
2011-02-19 08:33:46 +01:00
|
|
|
printf("\n");
|
2014-06-18 16:45:34 +02:00
|
|
|
printf(" -s <int> <int> ......... input size (width x height) for YUV\n");
|
2016-08-09 19:03:55 +02:00
|
|
|
printf(" -sns <int> ............. spatial noise shaping (0:off, 100:max), "
|
|
|
|
"default=50\n");
|
|
|
|
printf(" -f <int> ............... filter strength (0=off..100), "
|
|
|
|
"default=60\n");
|
2011-02-19 08:33:46 +01:00
|
|
|
printf(" -sharpness <int> ....... "
|
2016-08-09 19:03:55 +02:00
|
|
|
"filter sharpness (0:most .. 7:least sharp), default=0\n");
|
2013-02-15 10:08:52 +01:00
|
|
|
printf(" -strong ................ use strong filter instead "
|
2014-06-18 16:45:34 +02:00
|
|
|
"of simple (default)\n");
|
|
|
|
printf(" -nostrong .............. use simple filter instead of strong\n");
|
2017-01-20 16:53:58 +01:00
|
|
|
printf(" -sharp_yuv ............. use sharper (and slower) RGB->YUV "
|
|
|
|
"conversion\n");
|
2011-08-24 00:58:22 +02:00
|
|
|
printf(" -partition_limit <int> . limit quality to fit the 512k limit on\n");
|
|
|
|
printf(" "
|
|
|
|
"the first partition (0=no degradation ... 100=full)\n");
|
2011-02-19 08:33:46 +01:00
|
|
|
printf(" -pass <int> ............ analysis pass number (1..10)\n");
|
2020-01-29 09:34:26 +01:00
|
|
|
printf(" -qrange <min> <max> .... specifies the permissible quality range\n"
|
|
|
|
" (default: 0 100)\n");
|
2011-02-19 08:33:46 +01:00
|
|
|
printf(" -crop <x> <y> <w> <h> .. crop picture with the given rectangle\n");
|
2022-03-17 18:29:02 +01:00
|
|
|
printf(" -resize <w> <h> ........ resize picture (*after* any cropping)\n");
|
2013-03-01 01:21:34 +01:00
|
|
|
printf(" -mt .................... use multi-threading if available\n");
|
2013-03-12 00:37:42 +01:00
|
|
|
printf(" -low_memory ............ reduce memory usage (slower encoding)\n");
|
2014-06-18 16:45:34 +02:00
|
|
|
printf(" -map <int> ............. print map of extra info\n");
|
|
|
|
printf(" -print_psnr ............ prints averaged PSNR distortion\n");
|
|
|
|
printf(" -print_ssim ............ prints averaged SSIM distortion\n");
|
|
|
|
printf(" -print_lsim ............ prints local-similarity distortion\n");
|
|
|
|
printf(" -d <file.pgm> .......... dump the compressed output (PGM file)\n");
|
2016-08-09 19:03:55 +02:00
|
|
|
printf(" -alpha_method <int> .... transparency-compression method (0..1), "
|
|
|
|
"default=1\n");
|
2014-06-18 16:45:34 +02:00
|
|
|
printf(" -alpha_filter <string> . predictive filtering for alpha plane,\n");
|
|
|
|
printf(" one of: none, fast (default) or best\n");
|
2016-08-09 19:03:55 +02:00
|
|
|
printf(" -exact ................. preserve RGB values in transparent area, "
|
|
|
|
"default=off\n");
|
2014-06-18 16:45:34 +02:00
|
|
|
printf(" -blend_alpha <hex> ..... blend colors against background color\n"
|
2013-04-03 04:14:14 +02:00
|
|
|
" expressed as RGB values written in\n"
|
|
|
|
" hexadecimal, e.g. 0xc0e0d0 for red=0xc0\n"
|
2014-06-18 16:45:34 +02:00
|
|
|
" green=0xe0 and blue=0xd0\n");
|
|
|
|
printf(" -noalpha ............... discard any transparency information\n");
|
2016-08-09 19:03:55 +02:00
|
|
|
printf(" -lossless .............. encode image losslessly, default=off\n");
|
2023-03-17 23:17:31 +01:00
|
|
|
printf(" -near_lossless <int> ... use near-lossless image preprocessing\n"
|
|
|
|
" (0..100=off), default=100\n");
|
2014-06-18 16:45:34 +02:00
|
|
|
printf(" -hint <string> ......... specify image characteristics hint,\n");
|
|
|
|
printf(" one of: photo, picture or graph\n");
|
2011-05-03 02:19:00 +02:00
|
|
|
|
2013-01-11 21:25:36 +01:00
|
|
|
printf("\n");
|
|
|
|
printf(" -metadata <string> ..... comma separated list of metadata to\n");
|
|
|
|
printf(" ");
|
|
|
|
printf("copy from the input to the output if present.\n");
|
|
|
|
printf(" "
|
2013-03-13 22:04:20 +01:00
|
|
|
"Valid values: all, none (default), exif, icc, xmp\n");
|
2013-01-11 21:25:36 +01:00
|
|
|
|
2011-02-19 08:33:46 +01:00
|
|
|
printf("\n");
|
|
|
|
printf(" -short ................. condense printed message\n");
|
2014-06-18 16:45:34 +02:00
|
|
|
printf(" -quiet ................. don't print anything\n");
|
|
|
|
printf(" -version ............... print version number and exit\n");
|
2011-07-15 23:53:03 +02:00
|
|
|
#ifndef WEBP_DLL
|
2014-06-18 16:45:34 +02:00
|
|
|
printf(" -noasm ................. disable all assembly optimizations\n");
|
2011-07-15 23:53:03 +02:00
|
|
|
#endif
|
2011-02-19 08:33:46 +01:00
|
|
|
printf(" -v ..................... verbose, e.g. print encoding/decoding "
|
|
|
|
"times\n");
|
2011-12-01 11:24:50 +01:00
|
|
|
printf(" -progress .............. report encoding progress\n");
|
2011-02-19 08:33:46 +01:00
|
|
|
printf("\n");
|
|
|
|
printf("Experimental Options:\n");
|
2014-06-18 16:45:34 +02:00
|
|
|
printf(" -jpeg_like ............. roughly match expected JPEG size\n");
|
|
|
|
printf(" -af .................... auto-adjust filter strength\n");
|
2011-02-19 08:33:46 +01:00
|
|
|
printf(" -pre <int> ............. pre-processing filter\n");
|
|
|
|
printf("\n");
|
2022-03-26 23:17:58 +01:00
|
|
|
printf("Supported input formats:\n %s\n", WebPGetEnabledInputFileFormats());
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
|
2011-08-25 23:22:32 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2011-06-02 15:55:03 +02:00
|
|
|
// Error messages
|
|
|
|
|
2014-07-21 15:44:43 +02:00
|
|
|
static const char* const kErrorMessages[VP8_ENC_ERROR_LAST] = {
|
2011-06-02 15:55:03 +02:00
|
|
|
"OK",
|
|
|
|
"OUT_OF_MEMORY: Out of memory allocating objects",
|
|
|
|
"BITSTREAM_OUT_OF_MEMORY: Out of memory re-allocating byte buffer",
|
|
|
|
"NULL_PARAMETER: NULL parameter passed to function",
|
|
|
|
"INVALID_CONFIGURATION: configuration is invalid",
|
2011-08-24 00:58:22 +02:00
|
|
|
"BAD_DIMENSION: Bad picture dimension. Maximum width and height "
|
|
|
|
"allowed is 16383 pixels.",
|
|
|
|
"PARTITION0_OVERFLOW: Partition #0 is too big to fit 512k.\n"
|
|
|
|
"To reduce the size of this partition, try using less segments "
|
|
|
|
"with the -segments option, and eventually reduce the number of "
|
|
|
|
"header bits using -partition_limit. More details are available "
|
|
|
|
"in the manual (`man cwebp`)",
|
|
|
|
"PARTITION_OVERFLOW: Partition is too big to fit 16M",
|
2011-12-01 12:34:22 +01:00
|
|
|
"BAD_WRITE: Picture writer returned an I/O error",
|
2011-12-01 11:24:50 +01:00
|
|
|
"FILE_TOO_BIG: File would be too big to fit in 4G",
|
|
|
|
"USER_ABORT: encoding abort requested by user"
|
2011-06-02 15:55:03 +02:00
|
|
|
};
|
|
|
|
|
2011-08-25 23:22:32 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2011-02-19 08:33:46 +01:00
|
|
|
|
2019-07-26 09:46:40 +02:00
|
|
|
int main(int argc, const char* argv[]) {
|
2012-05-09 09:32:20 +02:00
|
|
|
int return_value = -1;
|
2019-07-26 09:46:40 +02:00
|
|
|
const char* in_file = NULL, *out_file = NULL, *dump_file = NULL;
|
|
|
|
FILE* out = NULL;
|
2011-02-19 08:33:46 +01:00
|
|
|
int c;
|
|
|
|
int short_output = 0;
|
|
|
|
int quiet = 0;
|
2011-12-01 10:41:34 +01:00
|
|
|
int keep_alpha = 1;
|
2013-04-03 04:14:14 +02:00
|
|
|
int blend_alpha = 0;
|
|
|
|
uint32_t background_color = 0xffffffu;
|
2011-02-19 08:33:46 +01:00
|
|
|
int crop = 0, crop_x = 0, crop_y = 0, crop_w = 0, crop_h = 0;
|
2011-05-03 02:19:00 +02:00
|
|
|
int resize_w = 0, resize_h = 0;
|
2014-03-11 23:25:35 +01:00
|
|
|
int lossless_preset = 6;
|
|
|
|
int use_lossless_preset = -1; // -1=unset, 0=don't use, 1=use it
|
2011-12-01 11:24:50 +01:00
|
|
|
int show_progress = 0;
|
2013-01-11 21:25:36 +01:00
|
|
|
int keep_metadata = 0;
|
2013-03-13 22:41:38 +01:00
|
|
|
int metadata_written = 0;
|
2011-02-19 08:33:46 +01:00
|
|
|
WebPPicture picture;
|
2012-10-18 17:26:40 +02:00
|
|
|
int print_distortion = -1; // -1=off, 0=PSNR, 1=SSIM, 2=LSIM
|
2012-01-20 16:20:56 +01:00
|
|
|
WebPPicture original_picture; // when PSNR or SSIM is requested
|
2011-02-19 08:33:46 +01:00
|
|
|
WebPConfig config;
|
|
|
|
WebPAuxStats stats;
|
2013-01-15 03:32:44 +01:00
|
|
|
WebPMemoryWriter memory_writer;
|
2020-08-12 11:40:08 +02:00
|
|
|
int use_memory_writer;
|
2012-12-04 03:20:00 +01:00
|
|
|
Metadata metadata;
|
2011-02-19 08:33:46 +01:00
|
|
|
Stopwatch stop_watch;
|
2011-05-03 02:19:00 +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
2018-10-16 11:03:18 +02:00
|
|
|
INIT_WARGV(argc, argv);
|
|
|
|
|
2012-12-04 03:20:00 +01:00
|
|
|
MetadataInit(&metadata);
|
2013-02-02 04:17:26 +01:00
|
|
|
WebPMemoryWriterInit(&memory_writer);
|
2012-01-20 16:20:56 +01:00
|
|
|
if (!WebPPictureInit(&picture) ||
|
|
|
|
!WebPPictureInit(&original_picture) ||
|
|
|
|
!WebPConfigInit(&config)) {
|
2011-02-19 08:33:46 +01:00
|
|
|
fprintf(stderr, "Error! Version mismatch!\n");
|
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);
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
HelpShort();
|
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);
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (c = 1; c < argc; ++c) {
|
2014-09-11 08:35:48 +02:00
|
|
|
int parse_error = 0;
|
2011-02-19 08:33:46 +01:00
|
|
|
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
|
|
|
|
HelpShort();
|
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);
|
2011-02-19 08:33:46 +01:00
|
|
|
} else if (!strcmp(argv[c], "-H") || !strcmp(argv[c], "-longhelp")) {
|
|
|
|
HelpLong();
|
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);
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-o") && c + 1 < argc) {
|
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
|
|
|
out_file = (const char*)GET_WARGV(argv, ++c);
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-d") && c + 1 < argc) {
|
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_file = (const char*)GET_WARGV(argv, ++c);
|
2011-02-19 08:33:46 +01:00
|
|
|
config.show_compressed = 1;
|
2012-01-20 16:20:56 +01:00
|
|
|
} else if (!strcmp(argv[c], "-print_psnr")) {
|
2012-10-18 17:26:40 +02:00
|
|
|
config.show_compressed = 1;
|
|
|
|
print_distortion = 0;
|
|
|
|
} else if (!strcmp(argv[c], "-print_ssim")) {
|
2012-01-20 16:20:56 +01:00
|
|
|
config.show_compressed = 1;
|
|
|
|
print_distortion = 1;
|
2012-10-18 17:26:40 +02:00
|
|
|
} else if (!strcmp(argv[c], "-print_lsim")) {
|
|
|
|
config.show_compressed = 1;
|
|
|
|
print_distortion = 2;
|
2011-02-19 08:33:46 +01:00
|
|
|
} else if (!strcmp(argv[c], "-short")) {
|
2013-12-23 12:03:00 +01:00
|
|
|
++short_output;
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-s") && c + 2 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
picture.width = ExUtilGetInt(argv[++c], 0, &parse_error);
|
|
|
|
picture.height = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2015-11-13 00:05:02 +01:00
|
|
|
if (picture.width > WEBP_MAX_DIMENSION || picture.width < 0 ||
|
|
|
|
picture.height > WEBP_MAX_DIMENSION || picture.height < 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Specified dimension (%d x %d) is out of range.\n",
|
|
|
|
picture.width, picture.height);
|
|
|
|
goto Error;
|
|
|
|
}
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-m") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.method = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2014-03-11 23:25:35 +01:00
|
|
|
use_lossless_preset = 0; // disable -z option
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-q") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.quality = ExUtilGetFloat(argv[++c], &parse_error);
|
2014-03-11 23:25:35 +01:00
|
|
|
use_lossless_preset = 0; // disable -z option
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-z") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
lossless_preset = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2014-03-11 23:25:35 +01:00
|
|
|
if (use_lossless_preset != 0) use_lossless_preset = 1;
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-alpha_q") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.alpha_quality = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-alpha_method") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.alpha_compression = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2012-01-17 09:18:22 +01:00
|
|
|
} else if (!strcmp(argv[c], "-alpha_cleanup")) {
|
2015-11-16 14:14:57 +01:00
|
|
|
// This flag is obsolete, does opposite of -exact.
|
|
|
|
config.exact = 0;
|
|
|
|
} else if (!strcmp(argv[c], "-exact")) {
|
|
|
|
config.exact = 1;
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-blend_alpha") && c + 1 < argc) {
|
2013-04-03 04:14:14 +02:00
|
|
|
blend_alpha = 1;
|
2014-09-11 08:35:48 +02:00
|
|
|
// background color is given in hex with an optional '0x' prefix
|
|
|
|
background_color = ExUtilGetInt(argv[++c], 16, &parse_error);
|
2013-04-03 04:14:14 +02:00
|
|
|
background_color = background_color & 0x00ffffffu;
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-alpha_filter") && c + 1 < argc) {
|
2012-01-09 04:27:21 +01:00
|
|
|
++c;
|
|
|
|
if (!strcmp(argv[c], "none")) {
|
|
|
|
config.alpha_filtering = 0;
|
|
|
|
} else if (!strcmp(argv[c], "fast")) {
|
|
|
|
config.alpha_filtering = 1;
|
|
|
|
} else if (!strcmp(argv[c], "best")) {
|
|
|
|
config.alpha_filtering = 2;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Error! Unrecognized alpha filter: %s\n", argv[c]);
|
|
|
|
goto Error;
|
|
|
|
}
|
2011-12-01 10:41:34 +01:00
|
|
|
} else if (!strcmp(argv[c], "-noalpha")) {
|
|
|
|
keep_alpha = 0;
|
2012-04-24 12:59:08 +02:00
|
|
|
} else if (!strcmp(argv[c], "-lossless")) {
|
|
|
|
config.lossless = 1;
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-near_lossless") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.near_lossless = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2014-08-05 19:14:57 +02:00
|
|
|
config.lossless = 1; // use near-lossless only with lossless
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-hint") && c + 1 < argc) {
|
2012-06-22 08:44:48 +02:00
|
|
|
++c;
|
|
|
|
if (!strcmp(argv[c], "photo")) {
|
|
|
|
config.image_hint = WEBP_HINT_PHOTO;
|
|
|
|
} else if (!strcmp(argv[c], "picture")) {
|
|
|
|
config.image_hint = WEBP_HINT_PICTURE;
|
2012-08-01 08:07:52 +02:00
|
|
|
} else if (!strcmp(argv[c], "graph")) {
|
|
|
|
config.image_hint = WEBP_HINT_GRAPH;
|
2012-06-22 08:44:48 +02:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Error! Unrecognized image hint: %s\n", argv[c]);
|
|
|
|
goto Error;
|
|
|
|
}
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-size") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.target_size = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-psnr") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.target_PSNR = ExUtilGetFloat(argv[++c], &parse_error);
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-sns") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.sns_strength = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-f") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.filter_strength = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2011-02-19 08:33:46 +01:00
|
|
|
} else if (!strcmp(argv[c], "-af")) {
|
|
|
|
config.autofilter = 1;
|
2013-02-05 19:40:18 +01:00
|
|
|
} else if (!strcmp(argv[c], "-jpeg_like")) {
|
|
|
|
config.emulate_jpeg_size = 1;
|
2013-03-01 01:21:34 +01:00
|
|
|
} else if (!strcmp(argv[c], "-mt")) {
|
|
|
|
++config.thread_level; // increase thread level
|
2013-03-12 00:37:42 +01:00
|
|
|
} else if (!strcmp(argv[c], "-low_memory")) {
|
|
|
|
config.low_memory = 1;
|
2011-05-06 03:10:08 +02:00
|
|
|
} else if (!strcmp(argv[c], "-strong")) {
|
2011-02-19 08:33:46 +01:00
|
|
|
config.filter_type = 1;
|
2013-02-15 10:08:52 +01:00
|
|
|
} else if (!strcmp(argv[c], "-nostrong")) {
|
|
|
|
config.filter_type = 0;
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-sharpness") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.filter_sharpness = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2017-01-20 16:53:58 +01:00
|
|
|
} else if (!strcmp(argv[c], "-sharp_yuv")) {
|
|
|
|
config.use_sharp_yuv = 1;
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-pass") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.pass = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-qrange") && c + 2 < argc) {
|
|
|
|
config.qmin = ExUtilGetInt(argv[++c], 0, &parse_error);
|
|
|
|
config.qmax = ExUtilGetInt(argv[++c], 0, &parse_error);
|
|
|
|
if (config.qmin < 0) config.qmin = 0;
|
|
|
|
if (config.qmax > 100) config.qmax = 100;
|
|
|
|
} else if (!strcmp(argv[c], "-pre") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.preprocessing = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-segments") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.segments = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-partition_limit") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
config.partition_limit = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-map") && c + 1 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
picture.extra_info_type = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-crop") && c + 4 < argc) {
|
2011-02-19 08:33:46 +01:00
|
|
|
crop = 1;
|
2014-09-11 08:35:48 +02:00
|
|
|
crop_x = ExUtilGetInt(argv[++c], 0, &parse_error);
|
|
|
|
crop_y = ExUtilGetInt(argv[++c], 0, &parse_error);
|
|
|
|
crop_w = ExUtilGetInt(argv[++c], 0, &parse_error);
|
|
|
|
crop_h = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-resize") && c + 2 < argc) {
|
2014-09-11 08:35:48 +02:00
|
|
|
resize_w = ExUtilGetInt(argv[++c], 0, &parse_error);
|
|
|
|
resize_h = ExUtilGetInt(argv[++c], 0, &parse_error);
|
2011-07-15 23:53:03 +02:00
|
|
|
#ifndef WEBP_DLL
|
2011-04-22 21:14:45 +02:00
|
|
|
} else if (!strcmp(argv[c], "-noasm")) {
|
2011-09-02 23:30:08 +02:00
|
|
|
VP8GetCPUInfo = NULL;
|
2011-07-15 23:53:03 +02:00
|
|
|
#endif
|
2011-03-25 00:17:10 +01:00
|
|
|
} else if (!strcmp(argv[c], "-version")) {
|
|
|
|
const int version = WebPGetEncoderVersion();
|
2022-10-25 04:24:44 +02:00
|
|
|
const int sharpyuv_version = SharpYuvGetVersion();
|
2011-03-25 00:17:10 +01:00
|
|
|
printf("%d.%d.%d\n",
|
2015-12-12 01:40:23 +01:00
|
|
|
(version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff);
|
2022-10-25 04:24:44 +02:00
|
|
|
printf("libsharpyuv: %d.%d.%d\n",
|
|
|
|
(sharpyuv_version >> 24) & 0xff, (sharpyuv_version >> 16) & 0xffff,
|
|
|
|
sharpyuv_version & 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);
|
2011-12-01 11:24:50 +01:00
|
|
|
} else if (!strcmp(argv[c], "-progress")) {
|
|
|
|
show_progress = 1;
|
2011-02-19 08:33:46 +01:00
|
|
|
} else if (!strcmp(argv[c], "-quiet")) {
|
|
|
|
quiet = 1;
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-preset") && c + 1 < argc) {
|
2011-02-19 08:33:46 +01:00
|
|
|
WebPPreset preset;
|
|
|
|
++c;
|
|
|
|
if (!strcmp(argv[c], "default")) {
|
|
|
|
preset = WEBP_PRESET_DEFAULT;
|
|
|
|
} else if (!strcmp(argv[c], "photo")) {
|
|
|
|
preset = WEBP_PRESET_PHOTO;
|
|
|
|
} else if (!strcmp(argv[c], "picture")) {
|
|
|
|
preset = WEBP_PRESET_PICTURE;
|
|
|
|
} else if (!strcmp(argv[c], "drawing")) {
|
|
|
|
preset = WEBP_PRESET_DRAWING;
|
|
|
|
} else if (!strcmp(argv[c], "icon")) {
|
|
|
|
preset = WEBP_PRESET_ICON;
|
|
|
|
} else if (!strcmp(argv[c], "text")) {
|
|
|
|
preset = WEBP_PRESET_TEXT;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Error! Unrecognized preset: %s\n", argv[c]);
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
if (!WebPConfigPreset(&config, preset, config.quality)) {
|
2011-03-17 22:49:19 +01:00
|
|
|
fprintf(stderr, "Error! Could initialize configuration with preset.\n");
|
2011-02-19 08:33:46 +01:00
|
|
|
goto Error;
|
|
|
|
}
|
2020-01-29 09:34:26 +01:00
|
|
|
} else if (!strcmp(argv[c], "-metadata") && c + 1 < argc) {
|
2013-01-11 21:25:36 +01:00
|
|
|
static const struct {
|
|
|
|
const char* option;
|
|
|
|
int flag;
|
|
|
|
} kTokens[] = {
|
|
|
|
{ "all", METADATA_ALL },
|
|
|
|
{ "none", 0 },
|
|
|
|
{ "exif", METADATA_EXIF },
|
2013-03-13 22:04:20 +01:00
|
|
|
{ "icc", METADATA_ICC },
|
2013-01-11 21:25:36 +01:00
|
|
|
{ "xmp", METADATA_XMP },
|
|
|
|
};
|
|
|
|
const size_t kNumTokens = sizeof(kTokens) / sizeof(kTokens[0]);
|
|
|
|
const char* start = argv[++c];
|
|
|
|
const char* const end = start + strlen(start);
|
|
|
|
|
|
|
|
while (start < end) {
|
|
|
|
size_t i;
|
|
|
|
const char* token = strchr(start, ',');
|
|
|
|
if (token == NULL) token = end;
|
|
|
|
|
|
|
|
for (i = 0; i < kNumTokens; ++i) {
|
|
|
|
if ((size_t)(token - start) == strlen(kTokens[i].option) &&
|
|
|
|
!strncmp(start, kTokens[i].option, strlen(kTokens[i].option))) {
|
|
|
|
if (kTokens[i].flag != 0) {
|
|
|
|
keep_metadata |= kTokens[i].flag;
|
|
|
|
} else {
|
|
|
|
keep_metadata = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == kNumTokens) {
|
|
|
|
fprintf(stderr, "Error! Unknown metadata type '%.*s'\n",
|
|
|
|
(int)(token - start), start);
|
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);
|
2013-01-11 21:25:36 +01:00
|
|
|
}
|
|
|
|
start = token + 1;
|
|
|
|
}
|
2013-01-15 03:32:44 +01:00
|
|
|
#ifdef HAVE_WINCODEC_H
|
2013-03-13 22:04:20 +01:00
|
|
|
if (keep_metadata != 0 && keep_metadata != METADATA_ICC) {
|
2013-01-11 21:25:36 +01:00
|
|
|
// TODO(jzern): remove when -metadata is supported on all platforms.
|
2013-01-25 00:37:49 +01:00
|
|
|
fprintf(stderr, "Warning: only ICC profile extraction is currently"
|
|
|
|
" supported on this platform!\n");
|
2013-01-11 21:25:36 +01:00
|
|
|
}
|
2013-01-15 03:32:44 +01:00
|
|
|
#endif
|
2011-02-19 08:33:46 +01:00
|
|
|
} else if (!strcmp(argv[c], "-v")) {
|
|
|
|
verbose = 1;
|
2013-12-13 05:20:08 +01:00
|
|
|
} else if (!strcmp(argv[c], "--")) {
|
2020-01-29 09:34:26 +01:00
|
|
|
if (c + 1 < argc) in_file = (const char*)GET_WARGV(argv, ++c);
|
2013-12-13 05:20:08 +01:00
|
|
|
break;
|
2011-02-19 08:33:46 +01:00
|
|
|
} else if (argv[c][0] == '-') {
|
|
|
|
fprintf(stderr, "Error! Unknown option '%s'\n", argv[c]);
|
|
|
|
HelpLong();
|
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);
|
2011-02-19 08:33:46 +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
|
|
|
in_file = (const char*)GET_WARGV(argv, c);
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
2014-09-11 08:35:48 +02:00
|
|
|
|
|
|
|
if (parse_error) {
|
|
|
|
HelpLong();
|
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);
|
2014-09-11 08:35:48 +02:00
|
|
|
}
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
2012-05-09 09:32:20 +02:00
|
|
|
if (in_file == NULL) {
|
|
|
|
fprintf(stderr, "No input file specified!\n");
|
|
|
|
HelpShort();
|
|
|
|
goto Error;
|
|
|
|
}
|
2011-02-19 08:33:46 +01:00
|
|
|
|
2014-03-11 23:25:35 +01:00
|
|
|
if (use_lossless_preset == 1) {
|
|
|
|
if (!WebPConfigLosslessPreset(&config, lossless_preset)) {
|
|
|
|
fprintf(stderr, "Invalid lossless preset (-z %d)\n", lossless_preset);
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-20 05:32:25 +02:00
|
|
|
// Check for unsupported command line options for lossless mode and log
|
|
|
|
// warning for such options.
|
2012-06-20 11:20:34 +02:00
|
|
|
if (!quiet && config.lossless == 1) {
|
2012-06-20 05:32:25 +02:00
|
|
|
if (config.target_size > 0 || config.target_PSNR > 0) {
|
|
|
|
fprintf(stderr, "Encoding for specified size or PSNR is not supported"
|
|
|
|
" for lossless encoding. Ignoring such option(s)!\n");
|
|
|
|
}
|
|
|
|
if (config.partition_limit > 0) {
|
|
|
|
fprintf(stderr, "Partition limit option is not required for lossless"
|
|
|
|
" encoding. Ignoring this option!\n");
|
|
|
|
}
|
|
|
|
}
|
2016-02-13 10:22:32 +01:00
|
|
|
// If a target size or PSNR was given, but somehow the -pass option was
|
|
|
|
// omitted, force a reasonable value.
|
|
|
|
if (config.target_size > 0 || config.target_PSNR > 0) {
|
|
|
|
if (config.pass == 1) config.pass = 6;
|
|
|
|
}
|
2012-06-20 05:32:25 +02:00
|
|
|
|
2011-02-19 08:33:46 +01:00
|
|
|
if (!WebPValidateConfig(&config)) {
|
|
|
|
fprintf(stderr, "Error! Invalid configuration.\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
2015-10-27 22:54:11 +01:00
|
|
|
// Read the input. We need to decide if we prefer ARGB or YUVA
|
|
|
|
// samples, depending on the expected compression mode (this saves
|
|
|
|
// some conversion steps).
|
2017-01-20 16:53:58 +01:00
|
|
|
picture.use_argb = (config.lossless || config.use_sharp_yuv ||
|
|
|
|
config.preprocessing > 0 ||
|
2015-10-27 22:54:11 +01:00
|
|
|
crop || (resize_w | resize_h) > 0);
|
2011-05-05 07:59:51 +02:00
|
|
|
if (verbose) {
|
2013-09-12 09:32:28 +02:00
|
|
|
StopwatchReset(&stop_watch);
|
2011-05-05 07:59:51 +02:00
|
|
|
}
|
2013-01-11 21:25:36 +01:00
|
|
|
if (!ReadPicture(in_file, &picture, keep_alpha,
|
|
|
|
(keep_metadata == 0) ? NULL : &metadata)) {
|
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! Cannot read input picture file '%s'\n",
|
|
|
|
(const W_CHAR*)in_file);
|
2011-03-17 22:49:19 +01:00
|
|
|
goto Error;
|
|
|
|
}
|
2011-12-01 11:24:50 +01:00
|
|
|
picture.progress_hook = (show_progress && !quiet) ? ProgressReport : NULL;
|
2013-04-03 04:14:14 +02:00
|
|
|
|
|
|
|
if (blend_alpha) {
|
|
|
|
WebPBlendAlpha(&picture, background_color);
|
|
|
|
}
|
|
|
|
|
2011-02-25 21:03:27 +01:00
|
|
|
if (verbose) {
|
2013-01-25 09:44:16 +01:00
|
|
|
const double read_time = StopwatchReadAndReset(&stop_watch);
|
|
|
|
fprintf(stderr, "Time to read input: %.3fs\n", read_time);
|
2011-02-25 21:03:27 +01:00
|
|
|
}
|
2020-08-12 11:40:08 +02:00
|
|
|
// The bitstream should be kept in memory when metadata must be appended
|
|
|
|
// before writing it to a file/stream, and/or when the near-losslessly encoded
|
|
|
|
// bitstream must be decoded for distortion computation (lossy will modify the
|
|
|
|
// 'picture' but not the lossless pipeline).
|
|
|
|
// Otherwise directly write the bitstream to a file.
|
|
|
|
use_memory_writer = (out_file != NULL && keep_metadata) ||
|
|
|
|
(!quiet && print_distortion >= 0 && config.lossless &&
|
|
|
|
config.near_lossless < 100);
|
2011-02-25 21:03:27 +01:00
|
|
|
|
|
|
|
// Open the output
|
2014-03-12 19:48:00 +01:00
|
|
|
if (out_file != NULL) {
|
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 int use_stdout = !WSTRCMP(out_file, "-");
|
|
|
|
out = use_stdout ? ImgIoUtilSetBinaryMode(stdout) : WFOPEN(out_file, "wb");
|
2012-01-20 16:20:56 +01:00
|
|
|
if (out == NULL) {
|
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! Cannot open output file '%s'\n",
|
|
|
|
(const W_CHAR*)out_file);
|
2011-02-19 08:33:46 +01:00
|
|
|
goto Error;
|
|
|
|
} else {
|
|
|
|
if (!short_output && !quiet) {
|
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, "Saving file '%s'\n", (const W_CHAR*)out_file);
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
}
|
2020-08-12 11:40:08 +02:00
|
|
|
if (use_memory_writer) {
|
2013-01-15 03:32:44 +01:00
|
|
|
picture.writer = WebPMemoryWrite;
|
|
|
|
picture.custom_ptr = (void*)&memory_writer;
|
2020-08-12 11:40:08 +02:00
|
|
|
} else {
|
|
|
|
picture.writer = MyWriter;
|
|
|
|
picture.custom_ptr = (void*)out;
|
2013-01-15 03:32:44 +01:00
|
|
|
}
|
2011-02-19 08:33:46 +01:00
|
|
|
} else {
|
|
|
|
out = NULL;
|
2020-08-12 11:40:08 +02:00
|
|
|
if (use_memory_writer) {
|
|
|
|
picture.writer = WebPMemoryWrite;
|
|
|
|
picture.custom_ptr = (void*)&memory_writer;
|
|
|
|
}
|
2011-02-19 08:33:46 +01:00
|
|
|
if (!quiet && !short_output) {
|
|
|
|
fprintf(stderr, "No output file specified (no -o flag). Encoding will\n");
|
|
|
|
fprintf(stderr, "be performed, but its results discarded.\n\n");
|
|
|
|
}
|
|
|
|
}
|
2012-07-25 01:15:36 +02:00
|
|
|
if (!quiet) {
|
|
|
|
picture.stats = &stats;
|
2012-07-28 04:53:16 +02:00
|
|
|
picture.user_data = (void*)in_file;
|
2012-07-25 01:15:36 +02:00
|
|
|
}
|
2011-02-19 08:33:46 +01:00
|
|
|
|
2014-07-29 01:04:54 +02:00
|
|
|
// Crop & resize.
|
2011-05-05 07:59:51 +02:00
|
|
|
if (verbose) {
|
2013-09-12 09:32:28 +02:00
|
|
|
StopwatchReset(&stop_watch);
|
2011-05-05 07:59:51 +02:00
|
|
|
}
|
2012-06-21 09:30:43 +02:00
|
|
|
if (crop != 0) {
|
|
|
|
// We use self-cropping using a view.
|
|
|
|
if (!WebPPictureView(&picture, crop_x, crop_y, crop_w, crop_h, &picture)) {
|
|
|
|
fprintf(stderr, "Error! Cannot crop picture\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
2011-03-17 22:49:19 +01:00
|
|
|
}
|
2011-05-03 02:19:00 +02:00
|
|
|
if ((resize_w | resize_h) > 0) {
|
2018-09-25 13:02:30 +02:00
|
|
|
WebPPicture picture_no_alpha;
|
|
|
|
if (config.exact) {
|
|
|
|
// If -exact, we can't premultiply RGB by A otherwise RGB is lost if A=0.
|
|
|
|
// We rescale an opaque copy and assemble scaled A and non-premultiplied
|
|
|
|
// RGB channels. This is slower but it's a very uncommon use case. Color
|
|
|
|
// leak at sharp alpha edges is possible.
|
|
|
|
if (!WebPPictureCopy(&picture, &picture_no_alpha)) {
|
|
|
|
fprintf(stderr, "Error! Cannot copy temporary picture\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We enforced picture.use_argb = 1 above. Now, remove the alpha values.
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
uint32_t* argb_no_alpha = picture_no_alpha.argb;
|
|
|
|
for (y = 0; y < picture_no_alpha.height; ++y) {
|
|
|
|
for (x = 0; x < picture_no_alpha.width; ++x) {
|
|
|
|
argb_no_alpha[x] |= 0xff000000; // Opaque copy.
|
|
|
|
}
|
|
|
|
argb_no_alpha += picture_no_alpha.argb_stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WebPPictureRescale(&picture_no_alpha, resize_w, resize_h)) {
|
|
|
|
fprintf(stderr, "Error! Cannot resize temporary picture\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-03 02:19:00 +02:00
|
|
|
if (!WebPPictureRescale(&picture, resize_w, resize_h)) {
|
|
|
|
fprintf(stderr, "Error! Cannot resize picture\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
2018-09-25 13:02:30 +02:00
|
|
|
|
|
|
|
if (config.exact) { // Put back the alpha information.
|
|
|
|
int x, y;
|
|
|
|
uint32_t* argb_no_alpha = picture_no_alpha.argb;
|
|
|
|
uint32_t* argb = picture.argb;
|
|
|
|
for (y = 0; y < picture_no_alpha.height; ++y) {
|
|
|
|
for (x = 0; x < picture_no_alpha.width; ++x) {
|
|
|
|
argb[x] = (argb[x] & 0xff000000) | (argb_no_alpha[x] & 0x00ffffff);
|
|
|
|
}
|
|
|
|
argb_no_alpha += picture_no_alpha.argb_stride;
|
|
|
|
argb += picture.argb_stride;
|
|
|
|
}
|
|
|
|
WebPPictureFree(&picture_no_alpha);
|
|
|
|
}
|
2011-05-03 02:19:00 +02:00
|
|
|
}
|
2014-07-29 01:04:54 +02:00
|
|
|
if (verbose && (crop != 0 || (resize_w | resize_h) > 0)) {
|
|
|
|
const double preproc_time = StopwatchReadAndReset(&stop_watch);
|
|
|
|
fprintf(stderr, "Time to crop/resize picture: %.3fs\n", preproc_time);
|
|
|
|
}
|
|
|
|
|
2011-05-03 02:19:00 +02:00
|
|
|
if (picture.extra_info_type > 0) {
|
|
|
|
AllocExtraInfo(&picture);
|
|
|
|
}
|
2020-08-12 11:40:08 +02:00
|
|
|
// Save original picture for later comparison. Only for lossy as lossless does
|
|
|
|
// not modify 'picture' (even near-lossless).
|
|
|
|
if (print_distortion >= 0 && !config.lossless &&
|
|
|
|
!WebPPictureCopy(&picture, &original_picture)) {
|
|
|
|
fprintf(stderr, "Error! Cannot copy temporary picture\n");
|
|
|
|
goto Error;
|
2012-01-20 16:20:56 +01:00
|
|
|
}
|
2014-07-29 01:04:54 +02:00
|
|
|
|
|
|
|
// Compress.
|
|
|
|
if (verbose) {
|
|
|
|
StopwatchReset(&stop_watch);
|
|
|
|
}
|
2011-03-17 22:49:19 +01:00
|
|
|
if (!WebPEncode(&config, &picture)) {
|
|
|
|
fprintf(stderr, "Error! Cannot encode picture as WebP\n");
|
2011-06-02 15:55:03 +02:00
|
|
|
fprintf(stderr, "Error code: %d (%s)\n",
|
|
|
|
picture.error_code, kErrorMessages[picture.error_code]);
|
2011-03-17 22:49:19 +01:00
|
|
|
goto Error;
|
|
|
|
}
|
2011-02-19 08:33:46 +01:00
|
|
|
if (verbose) {
|
2013-01-25 09:44:16 +01:00
|
|
|
const double encode_time = StopwatchReadAndReset(&stop_watch);
|
|
|
|
fprintf(stderr, "Time to encode picture: %.3fs\n", encode_time);
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
2011-02-25 21:03:27 +01:00
|
|
|
|
2020-08-12 11:40:08 +02:00
|
|
|
// Get the decompressed image for the lossless pipeline.
|
|
|
|
if (!quiet && print_distortion >= 0 && config.lossless) {
|
|
|
|
if (config.near_lossless == 100) {
|
|
|
|
// Pure lossless: image was not modified, make 'original_picture' a view
|
|
|
|
// of 'picture' by copying all members except the freeable pointers.
|
|
|
|
original_picture = picture;
|
|
|
|
original_picture.memory_ = original_picture.memory_argb_ = NULL;
|
|
|
|
} else {
|
|
|
|
// Decode the bitstream stored in 'memory_writer' to get the altered image
|
|
|
|
// to 'picture'; save the 'original_picture' beforehand.
|
|
|
|
assert(use_memory_writer);
|
|
|
|
original_picture = picture;
|
|
|
|
if (!WebPPictureInit(&picture)) { // Do not free 'picture'.
|
|
|
|
fprintf(stderr, "Error! Version mismatch!\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
picture.use_argb = 1;
|
2022-08-09 01:42:00 +02:00
|
|
|
if (!ReadWebP(
|
|
|
|
memory_writer.mem, memory_writer.size, &picture,
|
|
|
|
/*keep_alpha=*/WebPPictureHasTransparency(&original_picture),
|
|
|
|
/*metadata=*/NULL)) {
|
2020-08-12 11:40:08 +02:00
|
|
|
fprintf(stderr, "Error! Cannot decode encoded WebP bitstream\n");
|
|
|
|
fprintf(stderr, "Error code: %d (%s)\n", picture.error_code,
|
|
|
|
kErrorMessages[picture.error_code]);
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
picture.stats = original_picture.stats;
|
|
|
|
}
|
|
|
|
original_picture.stats = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the YUV planes to a PGM file. Only available for lossy.
|
2011-05-05 07:59:51 +02:00
|
|
|
if (dump_file) {
|
2012-07-18 23:58:53 +02:00
|
|
|
if (picture.use_argb) {
|
2018-04-11 00:56:17 +02:00
|
|
|
fprintf(stderr, "Warning: can't dump file (-d option) "
|
|
|
|
"in lossless mode.\n");
|
2012-06-05 00:50:05 +02:00
|
|
|
} else if (!DumpPicture(&picture, dump_file)) {
|
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, "Warning, couldn't dump picture %s\n",
|
|
|
|
(const W_CHAR*)dump_file);
|
2012-06-05 00:50:05 +02:00
|
|
|
}
|
2011-05-05 07:59:51 +02:00
|
|
|
}
|
2012-01-20 16:20:56 +01:00
|
|
|
|
2020-08-12 11:40:08 +02:00
|
|
|
if (use_memory_writer && out != NULL &&
|
|
|
|
!WriteWebPWithMetadata(out, &picture, &memory_writer, &metadata,
|
|
|
|
keep_metadata, &metadata_written)) {
|
|
|
|
fprintf(stderr, "Error writing WebP file!\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
2013-12-10 05:15:54 +01:00
|
|
|
|
2020-08-12 11:40:08 +02:00
|
|
|
if (out == NULL && keep_metadata) {
|
|
|
|
// output is disabled, just display the metadata stats.
|
|
|
|
const struct {
|
|
|
|
const MetadataPayload* const payload;
|
|
|
|
int flag;
|
|
|
|
} *iter, info[] = {{&metadata.exif, METADATA_EXIF},
|
|
|
|
{&metadata.iccp, METADATA_ICC},
|
|
|
|
{&metadata.xmp, METADATA_XMP},
|
|
|
|
{NULL, 0}};
|
|
|
|
uint32_t unused1 = 0;
|
|
|
|
uint64_t unused2 = 0;
|
|
|
|
|
|
|
|
for (iter = info; iter->payload != NULL; ++iter) {
|
|
|
|
if (UpdateFlagsAndSize(iter->payload, !!(keep_metadata & iter->flag),
|
|
|
|
/*flag=*/0, &unused1, &unused2)) {
|
|
|
|
metadata_written |= iter->flag;
|
2013-12-10 05:15:54 +01:00
|
|
|
}
|
2013-01-15 03:32:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-05 07:59:51 +02:00
|
|
|
if (!quiet) {
|
2013-12-23 12:03:00 +01:00
|
|
|
if (!short_output || print_distortion < 0) {
|
|
|
|
if (config.lossless) {
|
|
|
|
PrintExtraInfoLossless(&picture, short_output, in_file);
|
|
|
|
} else {
|
|
|
|
PrintExtraInfoLossy(&picture, short_output, config.low_memory, in_file);
|
|
|
|
}
|
2013-03-13 22:41:38 +01:00
|
|
|
}
|
2013-12-23 12:03:00 +01:00
|
|
|
if (!short_output && picture.extra_info_type > 0) {
|
|
|
|
PrintMapInfo(&picture);
|
2013-12-04 11:17:37 +01:00
|
|
|
}
|
2013-12-23 12:03:00 +01:00
|
|
|
if (print_distortion >= 0) { // print distortion
|
|
|
|
static const char* distortion_names[] = { "PSNR", "SSIM", "LSIM" };
|
|
|
|
float values[5];
|
|
|
|
if (!WebPPictureDistortion(&picture, &original_picture,
|
|
|
|
print_distortion, values)) {
|
|
|
|
fprintf(stderr, "Error while computing the distortion.\n");
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
if (!short_output) {
|
2015-08-12 02:28:29 +02:00
|
|
|
fprintf(stderr, "%s: ", distortion_names[print_distortion]);
|
2016-10-19 09:12:13 +02:00
|
|
|
fprintf(stderr, "B:%.2f G:%.2f R:%.2f A:%.2f Total:%.2f\n",
|
|
|
|
values[0], values[1], values[2], values[3], values[4]);
|
2013-12-23 12:03:00 +01:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%7d %.4f\n", picture.stats->coded_size, values[4]);
|
|
|
|
}
|
2013-12-04 11:17:37 +01:00
|
|
|
}
|
2013-12-23 12:03:00 +01:00
|
|
|
if (!short_output) {
|
|
|
|
PrintMetadataInfo(&metadata, metadata_written);
|
2013-12-04 11:17:37 +01:00
|
|
|
}
|
2011-05-05 07:59:51 +02:00
|
|
|
}
|
2012-05-09 09:32:20 +02:00
|
|
|
return_value = 0;
|
2011-02-19 08:33:46 +01:00
|
|
|
|
|
|
|
Error:
|
2014-03-27 23:27:32 +01:00
|
|
|
WebPMemoryWriterClear(&memory_writer);
|
2019-10-15 23:16:51 +02:00
|
|
|
WebPFree(picture.extra_info);
|
2012-12-04 03:20:00 +01:00
|
|
|
MetadataFree(&metadata);
|
2011-02-19 08:33:46 +01:00
|
|
|
WebPPictureFree(&picture);
|
2012-01-20 16:20:56 +01:00
|
|
|
WebPPictureFree(&original_picture);
|
2014-03-12 19:48:00 +01:00
|
|
|
if (out != NULL && out != stdout) {
|
2011-02-19 08:33:46 +01:00
|
|
|
fclose(out);
|
|
|
|
}
|
|
|
|
|
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(return_value);
|
2011-02-19 08:33:46 +01:00
|
|
|
}
|
|
|
|
|
2011-08-25 23:22:32 +02:00
|
|
|
//------------------------------------------------------------------------------
|