Enable Near-lossless feature.

Enable the WebP near-lossless feature by pre-processing the image to smoothen
the pixels.

On a 1000 PNG image corpus, for which WebP lossless (default settings) gets
25% compression gains, following is the performance of near-lossless feature
at various '-near_lossless' levels:
-near_lossless 90: 30% (very very high PSNR 54-60dB)
-near_lossless 75: 38% (very high PSNR 48-54dB)
-near_lossless 50: 45% (high PSNR 42-48dB)
-near_lossless 25: 48% (moderate PSNR 36-42dB)
-near_lossless 10: 50% (PSNR 30-36dB)

WebP near-lossless is specifically useful for discrete-tone images like
line-art, icons etc.

Change-Id: I7d12a2c9362ccd076d09710ea05c85fa64664c38
This commit is contained in:
Vikas Arora 2015-01-29 16:02:09 -08:00
parent c6b24543fc
commit 98c8138663
3 changed files with 7 additions and 19 deletions

View File

@ -615,10 +615,8 @@ static void HelpLong(void) {
" green=0xe0 and blue=0xd0\n"); " green=0xe0 and blue=0xd0\n");
printf(" -noalpha ............... discard any transparency information\n"); printf(" -noalpha ............... discard any transparency information\n");
printf(" -lossless .............. encode image losslessly\n"); printf(" -lossless .............. encode image losslessly\n");
#ifdef WEBP_EXPERIMENTAL_FEATURES printf(" -near_lossless <int> ... use near-lossless image\n"
printf(" -near_lossless ......... use near-lossless image\n"
" preprocessing (0=off..100)\n"); " preprocessing (0=off..100)\n");
#endif
printf(" -hint <string> ......... specify image characteristics hint,\n"); printf(" -hint <string> ......... specify image characteristics hint,\n");
printf(" one of: photo, picture or graph\n"); printf(" one of: photo, picture or graph\n");

View File

@ -218,12 +218,12 @@ Using this option will discard the alpha channel.
.B \-lossless .B \-lossless
Encode the image without any loss. Encode the image without any loss.
.TP .TP
.\" .B \-near_lossless " int .BI \-near_lossless " int
.\" Use near-lossless image preprocessing. This option adjusts pixel values Use near-lossless image preprocessing. This option adjusts pixel values
.\" to help compressibility, but has minimal impact on the visual quality. to help compressibility, but has minimal impact on the visual quality.
.\" It triggers lossless compression mode automatically. It triggers lossless compression mode automatically.
.\" Range is 0 (no preprocessing, the default) to 100. Range is 0 (no preprocessing, the default) to 100.
.\" .TP .TP
.BI \-hint " string .BI \-hint " string
Specify the hint about input image type. Possible values are: Specify the hint about input image type. Possible values are:
\fBphoto\fP, \fBpicture\fP or \fBgraph\fP. \fBphoto\fP, \fBpicture\fP or \fBgraph\fP.

View File

@ -20,8 +20,6 @@
#include "../utils/utils.h" #include "../utils/utils.h"
#include "./vp8enci.h" #include "./vp8enci.h"
#ifdef WEBP_EXPERIMENTAL_FEATURES
#define MIN_DIM_FOR_NEAR_LOSSLESS 64 #define MIN_DIM_FOR_NEAR_LOSSLESS 64
#define MAX_LIMIT_BITS 5 #define MAX_LIMIT_BITS 5
@ -131,15 +129,8 @@ static int QualityToLimitBits(int quality) {
// 13..100 -> 4..1 // 13..100 -> 4..1
return MAX_LIMIT_BITS - (quality + 12) / 25; return MAX_LIMIT_BITS - (quality + 12) / 25;
} }
#endif // WEBP_EXPERIMENTAL_FEATURES
int VP8ApplyNearLossless(int xsize, int ysize, uint32_t* argb, int quality) { int VP8ApplyNearLossless(int xsize, int ysize, uint32_t* argb, int quality) {
#ifndef WEBP_EXPERIMENTAL_FEATURES
(void)xsize;
(void)ysize;
(void)argb;
(void)quality;
#else
int i; int i;
uint32_t* const copy_buffer = uint32_t* const copy_buffer =
(uint32_t*)WebPSafeMalloc(xsize * 3, sizeof(*copy_buffer)); (uint32_t*)WebPSafeMalloc(xsize * 3, sizeof(*copy_buffer));
@ -160,6 +151,5 @@ int VP8ApplyNearLossless(int xsize, int ysize, uint32_t* argb, int quality) {
NearLossless(xsize, ysize, argb, i, copy_buffer); NearLossless(xsize, ysize, argb, i, copy_buffer);
} }
WebPSafeFree(copy_buffer); WebPSafeFree(copy_buffer);
#endif // WEBP_EXPERIMENTAL_FEATURES
return 1; return 1;
} }