gif2webp: add support for reading from stdin
output to stdout is already supported; this matches [cd]webp BUG=webp:371 Change-Id: Ib1ce1661b16ea792943bca2980f779584e90cc86
This commit is contained in:
parent
cf1c5054c7
commit
cbde5728c8
@ -23,6 +23,10 @@
|
||||
|
||||
#ifdef WEBP_HAVE_GIF
|
||||
|
||||
#if defined(HAVE_UNISTD_H) && HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <gif_lib.h>
|
||||
#include "webp/encode.h"
|
||||
#include "webp/mux.h"
|
||||
@ -30,6 +34,10 @@
|
||||
#include "../imageio/imageio_util.h"
|
||||
#include "./gifdec.h"
|
||||
|
||||
#if !defined(STDIN_FILENO)
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
static int transparent_index = GIF_INDEX_INVALID; // Opaque by default.
|
||||
@ -263,9 +271,11 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
// Start the decoder object
|
||||
#if LOCAL_GIF_PREREQ(5,0)
|
||||
gif = DGifOpenFileName(in_file, &gif_error);
|
||||
gif = !strcmp(in_file, "-") ? DGifOpenFileHandle(STDIN_FILENO, &gif_error)
|
||||
: DGifOpenFileName(in_file, &gif_error);
|
||||
#else
|
||||
gif = DGifOpenFileName(in_file);
|
||||
gif = !strcmp(in_file, "-") ? DGifOpenFileHandle(STDIN_FILENO)
|
||||
: DGifOpenFileName(in_file);
|
||||
#endif
|
||||
if (gif == NULL) goto End;
|
||||
|
||||
@ -532,8 +542,13 @@ int main(int argc, const char *argv[]) {
|
||||
goto End;
|
||||
}
|
||||
if (!quiet) {
|
||||
fprintf(stderr, "Saved output file (%d bytes): %s\n",
|
||||
(int)webp_data.size, out_file);
|
||||
if (!strcmp(out_file, "-")) {
|
||||
fprintf(stderr, "Saved %d bytes to STDIO\n",
|
||||
(int)webp_data.size);
|
||||
} else {
|
||||
fprintf(stderr, "Saved output file (%d bytes): %s\n",
|
||||
(int)webp_data.size, out_file);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!quiet) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH GIF2WEBP 1 "November 29, 2017"
|
||||
.TH GIF2WEBP 1 "January 25, 2018"
|
||||
.SH NAME
|
||||
gif2webp \- Convert a GIF image to WebP
|
||||
.SH SYNOPSIS
|
||||
@ -20,6 +20,12 @@ Specify the name of the output WebP file. If omitted, \fBgif2webp\fP will
|
||||
perform conversion but only report statistics.
|
||||
Using "\-" as output name will direct output to 'stdout'.
|
||||
.TP
|
||||
.BI \-\- " string
|
||||
Explicitly specify the input file. This option is useful if the input
|
||||
file starts with an '\-' for instance. This option must appear \fBlast\fP.
|
||||
Any other options afterward will be ignored. If the input file is "\-",
|
||||
the data will be read from \fIstdin\fP instead of a file.
|
||||
.TP
|
||||
.B \-h, \-help
|
||||
Usage information.
|
||||
.TP
|
||||
@ -137,6 +143,8 @@ gif2webp \-lossy \-m 3 picture.gif \-o picture_lossy.webp
|
||||
gif2webp \-lossy \-f 50 picture.gif \-o picture.webp
|
||||
.br
|
||||
gif2webp \-q 70 \-o picture.webp \-\- \-\-\-picture.gif
|
||||
.br
|
||||
cat picture.gif | gif2webp \-o \- \-\- \- > output.webp
|
||||
|
||||
.SH AUTHORS
|
||||
\fBgif2webp\fP is a part of libwebp and was written by the WebP team.
|
||||
|
Loading…
Reference in New Issue
Block a user