mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-19 07:20:02 +02:00
a WebP encoder
converts PNG & JPEG to WebP This is an experimental early version, with lot of room of later optimizations in both speed and quality. Compile with the usual `./configure && make` Command line example is examples/cwebp Usage: cwebp [options] -q quality input.png -o output.webp where 'quality' is between 0 (poor) to 100 (very good). Typical value is around 80. More encoding options with 'cwebp -longhelp' Change-Id: I577a94f6f622a0c44bdfa9daf1086ace89d45539
This commit is contained in:
107
src/enc/config.c
Normal file
107
src/enc/config.c
Normal file
@ -0,0 +1,107 @@
|
||||
// Copyright 2011 Google Inc.
|
||||
//
|
||||
// This code is licensed under the same terms as WebM:
|
||||
// Software License Agreement: http://www.webmproject.org/license/software/
|
||||
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Coding tools configuration
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#include <assert.h>
|
||||
#include "webp/encode.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// WebPConfig
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int WebPConfigInitInternal(WebPConfig* const config,
|
||||
WebPPreset preset, float quality, int version) {
|
||||
if (version != WEBP_ENCODER_ABI_VERSION) {
|
||||
return 0; // caller/system version mismatch!
|
||||
}
|
||||
if (config == NULL) return 0;
|
||||
|
||||
config->quality = quality;
|
||||
config->target_size = 0;
|
||||
config->target_PSNR = 0.;
|
||||
config->method = 4;
|
||||
config->sns_strength = 50;
|
||||
config->filter_strength = 20; // default: light filtering
|
||||
config->filter_sharpness = 0;
|
||||
config->filter_type = 0; // default: simple
|
||||
config->partitions = 0;
|
||||
config->segments = 4;
|
||||
config->pass = 1;
|
||||
config->show_compressed = 0;
|
||||
config->preprocessing = 0;
|
||||
config->autofilter = 0;
|
||||
|
||||
// TODO(skal): tune.
|
||||
switch (preset) {
|
||||
case WEBP_PRESET_PICTURE:
|
||||
config->sns_strength = 80;
|
||||
config->filter_sharpness = 4;
|
||||
config->filter_strength = 35;
|
||||
break;
|
||||
case WEBP_PRESET_PHOTO:
|
||||
config->sns_strength = 80;
|
||||
config->filter_sharpness = 3;
|
||||
config->filter_strength = 30;
|
||||
break;
|
||||
case WEBP_PRESET_DRAWING:
|
||||
config->sns_strength = 25;
|
||||
config->filter_sharpness = 6;
|
||||
config->filter_strength = 10;
|
||||
break;
|
||||
case WEBP_PRESET_ICON:
|
||||
config->sns_strength = 0;
|
||||
config->filter_strength = 0; // disable filtering to retain sharpness
|
||||
break;
|
||||
case WEBP_PRESET_TEXT:
|
||||
config->sns_strength = 0;
|
||||
config->filter_strength = 0; // disable filtering to retain sharpness
|
||||
config->segments = 2;
|
||||
break;
|
||||
case WEBP_PRESET_DEFAULT:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return WebPValidateConfig(config);
|
||||
}
|
||||
|
||||
int WebPValidateConfig(const WebPConfig* const config) {
|
||||
if (config == NULL) return 0;
|
||||
if (config->quality < 0 || config->quality > 100)
|
||||
return 0;
|
||||
if (config->target_size < 0)
|
||||
return 0;
|
||||
if (config->target_PSNR < 0)
|
||||
return 0;
|
||||
if (config->method < 0 || config->method > 6)
|
||||
return 0;
|
||||
if (config->segments < 1 || config->segments > 4)
|
||||
return 0;
|
||||
if (config->sns_strength < 0 || config->sns_strength > 100)
|
||||
return 0;
|
||||
if (config->filter_strength < 0 || config->filter_strength > 100)
|
||||
return 0;
|
||||
if (config->filter_sharpness < 0 || config->filter_sharpness > 7)
|
||||
return 0;
|
||||
if (config->filter_type < 0 || config->filter_type > 1)
|
||||
return 0;
|
||||
if (config->autofilter < 0 || config->autofilter > 1)
|
||||
return 0;
|
||||
if (config->pass < 1 || config->pass > 10)
|
||||
return 0;
|
||||
if (config->show_compressed < 0 || config->show_compressed > 1)
|
||||
return 0;
|
||||
if (config->preprocessing < 0 || config->preprocessing > 1)
|
||||
return 0;
|
||||
if (config->partitions < 0 || config->partitions > 3)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
Reference in New Issue
Block a user