diff --git a/README b/README index 02cd6fa4..2d8df64c 100644 --- a/README +++ b/README @@ -405,6 +405,7 @@ Options are: -dither 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 diff --git a/examples/vwebp.c b/examples/vwebp.c index bcd202f5..7d83994a 100644 --- a/examples/vwebp.c +++ b/examples/vwebp.c @@ -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 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); diff --git a/man/vwebp.1 b/man/vwebp.1 index aea2794c..ff39f42c 100644 --- a/man/vwebp.1 +++ b/man/vwebp.1 @@ -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