From 4c82284d2e19afab9967962b11484a240f83e89c Mon Sep 17 00:00:00 2001 From: Vikas Arora Date: Thu, 5 Feb 2015 11:16:37 -0800 Subject: [PATCH] Updated the near-lossless level mapping. Updated the near-lossless level mapping and make it correlated to lossy quality i.e 100 => minimum loss (in-fact no-loss) and the visual-quality loss increases with decrease in near-lossless level (quality) till value 0. The new mapping implies following (PSNR) loss-metric: -near_lossless 100: No-loss (bit-stream same as -lossless). -near_lossless 80: Very very high PSNR (around 54dB). -near_lossless 60: Very high PSNR (around 48dB). -near_lossless 40: High PSNR (around 42dB). -near_lossless 20: Moderate PSNR (around 36dB). -near_lossless 0: Low PSNR (around 30dB). Change-Id: I930de4b18950faf2868c97d42e9e49ba0b642960 --- examples/cwebp.c | 2 +- man/cwebp.1 | 4 ++-- src/enc/config.c | 2 +- src/enc/near_lossless.c | 11 ++++++++--- src/enc/vp8l.c | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/cwebp.c b/examples/cwebp.c index 8b305266..eb50540f 100644 --- a/examples/cwebp.c +++ b/examples/cwebp.c @@ -616,7 +616,7 @@ static void HelpLong(void) { printf(" -noalpha ............... discard any transparency information\n"); printf(" -lossless .............. encode image losslessly\n"); printf(" -near_lossless ... use near-lossless image\n" - " preprocessing (0=off..100)\n"); + " preprocessing (0..100=off)\n"); printf(" -hint ......... specify image characteristics hint,\n"); printf(" one of: photo, picture or graph\n"); diff --git a/man/cwebp.1 b/man/cwebp.1 index 8460fa45..a12d63b3 100644 --- a/man/cwebp.1 +++ b/man/cwebp.1 @@ -1,5 +1,5 @@ .\" Hey, EMACS: -*- nroff -*- -.TH CWEBP 1 "July 30, 2014" +.TH CWEBP 1 "Feb 4, 2015" .SH NAME cwebp \- compress an image file to a WebP file .SH SYNOPSIS @@ -222,7 +222,7 @@ Encode the image without any loss. Use near-lossless image preprocessing. This option adjusts pixel values to help compressibility, but has minimal impact on the visual quality. It triggers lossless compression mode automatically. -Range is 0 (no preprocessing, the default) to 100. +Range is 0 (maximum preprocessing) to 100 (no preprocessing, the default). .TP .BI \-hint " string Specify the hint about input image type. Possible values are: diff --git a/src/enc/config.c b/src/enc/config.c index 2af8782b..fbbdecf8 100644 --- a/src/enc/config.c +++ b/src/enc/config.c @@ -47,7 +47,7 @@ int WebPConfigInitInternal(WebPConfig* config, config->emulate_jpeg_size = 0; config->thread_level = 0; config->low_memory = 0; - config->near_lossless = 0; + config->near_lossless = 100; // TODO(skal): tune. switch (preset) { diff --git a/src/enc/near_lossless.c b/src/enc/near_lossless.c index a8bcf35d..9bc0f0e7 100644 --- a/src/enc/near_lossless.c +++ b/src/enc/near_lossless.c @@ -125,9 +125,14 @@ static void NearLossless(int xsize, int ysize, uint32_t* argb, } static int QualityToLimitBits(int quality) { - // quality mapping 0..12 -> 5 - // 13..100 -> 4..1 - return MAX_LIMIT_BITS - (quality + 12) / 25; + // quality mapping: + // 0..19 -> 5 + // 0..39 -> 4 + // 0..59 -> 3 + // 0..79 -> 2 + // 0..99 -> 1 + // 100 -> 0 + return MAX_LIMIT_BITS - quality / 20; } int VP8ApplyNearLossless(int xsize, int ysize, uint32_t* argb, int quality) { diff --git a/src/enc/vp8l.c b/src/enc/vp8l.c index ea676789..11da0993 100644 --- a/src/enc/vp8l.c +++ b/src/enc/vp8l.c @@ -1254,7 +1254,7 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config, } // Apply near-lossless preprocessing. - use_near_lossless = !enc->use_palette_ && config->near_lossless; + use_near_lossless = !enc->use_palette_ && (config->near_lossless < 100); if (use_near_lossless) { if (!VP8ApplyNearLossless(width, height, picture->argb, config->near_lossless)) {