Merge "vwebp: add a -fit option"

This commit is contained in:
Pascal Massimino 2019-05-29 08:27:48 +00:00 committed by Gerrit Code Review
commit e1c8acb5bd
3 changed files with 27 additions and 3 deletions

1
README
View File

@ -405,6 +405,7 @@ Options are:
-dither <int> dithering strength (0..100), default=50
-noalphadither disable alpha plane dithering
-usebgcolor .. display background color
-fit ......... downscale large images to preserve aspect ratio
-mt .......... use multi-threading
-info ........ print info
-h ........... this help message

View File

@ -72,6 +72,7 @@ static struct {
WebPIterator prev_frame;
WebPChunkIterator iccp;
int viewport_width, viewport_height;
int fit; // if true, rescale large images to preserve aspect ratio.
} kParams;
static void ClearPreviousPic(void) {
@ -418,8 +419,9 @@ static void HandleDisplay(void) {
}
static void StartDisplay(void) {
const int width = kParams.canvas_width;
const int height = kParams.canvas_height;
int width = kParams.canvas_width;
int height = kParams.canvas_height;
int screen_width, screen_height;
// TODO(webp:365) GLUT_DOUBLE results in flickering / old frames to be
// partially displayed with animated webp + alpha.
#if defined(__APPLE__) || defined(_WIN32)
@ -427,6 +429,18 @@ static void StartDisplay(void) {
#else
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
#endif
screen_width = glutGet(GLUT_SCREEN_WIDTH);
screen_height = glutGet(GLUT_SCREEN_HEIGHT);
if ((width > screen_width || height > screen_height) && kParams.fit) {
if (width > screen_width) {
height = (height * screen_width + width - 1) / width;
width = screen_width;
}
if (height > screen_height) {
width = (width * screen_height + height - 1) / height;
height = screen_height;
}
}
glutInitWindowSize(width, height);
glutCreateWindow("WebP viewer");
glutDisplayFunc(HandleDisplay);
@ -454,6 +468,7 @@ static void Help(void) {
" -dither <int> dithering strength (0..100), default=50\n"
" -noalphadither disable alpha plane dithering\n"
" -usebgcolor .. display background color\n"
" -fit ......... downscale large images to preserve aspect ratio\n"
" -mt .......... use multi-threading\n"
" -info ........ print info\n"
" -h ........... this help message\n"
@ -482,6 +497,8 @@ int main(int argc, char *argv[]) {
kParams.use_color_profile = 1;
// Background color hidden by default to see transparent areas.
kParams.draw_anim_background_color = 0;
// By default don't rescale too-large input images to preserve aspect ratio.
kParams.fit = 0;
for (c = 1; c < argc; ++c) {
int parse_error = 0;
@ -498,6 +515,8 @@ int main(int argc, char *argv[]) {
config->options.alpha_dithering_strength = 0;
} else if (!strcmp(argv[c], "-usebgcolor")) {
kParams.draw_anim_background_color = 1;
} else if (!strcmp(argv[c], "-fit")) {
kParams.fit = 1;
} else if (!strcmp(argv[c], "-dither") && c + 1 < argc) {
config->options.dithering_strength =
ExUtilGetInt(argv[++c], 0, &parse_error);

View File

@ -1,5 +1,5 @@
.\" Hey, EMACS: -*- nroff -*-
.TH VWEBP 1 "July 20, 2018"
.TH VWEBP 1 "May 28, 2019"
.SH NAME
vwebp \- decompress a WebP file and display it in a window
.SH SYNOPSIS
@ -42,6 +42,10 @@ to smooth the gradients. This flag will prevent this dithering.
Fill transparent areas with the bitstream's own background color instead of
checkerboard only. Default is white for non-animated images.
.TP
.B \-fit
If an image is larger than the display dimension, rescale it to preserve
the aspect ratio.
.TP
.B \-mt
Use multi-threading for decoding, if possible.
.TP