mirror of
https://github.com/webmproject/libwebp.git
synced 2025-08-28 23:03:20 +02:00
add lossless quick encoding functions to the public API
New functions: WebPEncodeLosslessRGB() WebPEncodeLosslessBGR() WebPEncodeLosslessRGBA() WebPEncodeLosslessBGRA() Change-Id: Id56da7569eee80c57de8f1f053fb87b217d33a4b
This commit is contained in:
@@ -1008,7 +1008,8 @@ int WebPPictureDistortion(const WebPPicture* const pic1,
|
||||
typedef int (*Importer)(WebPPicture* const, const uint8_t* const, int);
|
||||
|
||||
static size_t Encode(const uint8_t* rgba, int width, int height, int stride,
|
||||
Importer import, float quality_factor, uint8_t** output) {
|
||||
Importer import, float quality_factor, int lossless,
|
||||
uint8_t** output) {
|
||||
WebPPicture pic;
|
||||
WebPConfig config;
|
||||
WebPMemoryWriter wrt;
|
||||
@@ -1019,6 +1020,8 @@ static size_t Encode(const uint8_t* rgba, int width, int height, int stride,
|
||||
return 0; // shouldn't happen, except if system installation is broken
|
||||
}
|
||||
|
||||
config.lossless = !!lossless;
|
||||
pic.use_argb_input = !!lossless;
|
||||
pic.width = width;
|
||||
pic.height = height;
|
||||
pic.writer = WebPMemoryWrite;
|
||||
@@ -1036,10 +1039,10 @@ static size_t Encode(const uint8_t* rgba, int width, int height, int stride,
|
||||
return wrt.size;
|
||||
}
|
||||
|
||||
#define ENCODE_FUNC(NAME, IMPORTER) \
|
||||
size_t NAME(const uint8_t* in, int w, int h, int bps, float q, \
|
||||
uint8_t** out) { \
|
||||
return Encode(in, w, h, bps, IMPORTER, q, out); \
|
||||
#define ENCODE_FUNC(NAME, IMPORTER) \
|
||||
size_t NAME(const uint8_t* in, int w, int h, int bps, float q, \
|
||||
uint8_t** out) { \
|
||||
return Encode(in, w, h, bps, IMPORTER, q, 0, out); \
|
||||
}
|
||||
|
||||
ENCODE_FUNC(WebPEncodeRGB, WebPPictureImportRGB);
|
||||
@@ -1049,6 +1052,19 @@ ENCODE_FUNC(WebPEncodeBGRA, WebPPictureImportBGRA);
|
||||
|
||||
#undef ENCODE_FUNC
|
||||
|
||||
#define LOSSLESS_DEFAULT_QUALITY 70.
|
||||
#define LOSSLESS_ENCODE_FUNC(NAME, IMPORTER) \
|
||||
size_t NAME(const uint8_t* in, int w, int h, int bps, uint8_t** out) { \
|
||||
return Encode(in, w, h, bps, IMPORTER, LOSSLESS_DEFAULT_QUALITY, 1, out); \
|
||||
}
|
||||
|
||||
LOSSLESS_ENCODE_FUNC(WebPEncodeLosslessRGB, WebPPictureImportRGB);
|
||||
LOSSLESS_ENCODE_FUNC(WebPEncodeLosslessBGR, WebPPictureImportBGR);
|
||||
LOSSLESS_ENCODE_FUNC(WebPEncodeLosslessRGBA, WebPPictureImportRGBA);
|
||||
LOSSLESS_ENCODE_FUNC(WebPEncodeLosslessBGRA, WebPPictureImportBGRA);
|
||||
|
||||
#undef LOSSLESS_ENCODE_FUNC
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
|
@@ -30,6 +30,9 @@ WEBP_EXTERN(int) WebPGetEncoderVersion(void);
|
||||
// Returns the size of the compressed data (pointed to by *output), or 0 if
|
||||
// an error occurred. The compressed data must be released by the caller
|
||||
// using the call 'free(*output)'.
|
||||
// These functions compress using the lossy format, and the quality_factor
|
||||
// can go from 0 (smaller output, lower quality) to 100 (best quality,
|
||||
// larger output).
|
||||
WEBP_EXTERN(size_t) WebPEncodeRGB(const uint8_t* rgb,
|
||||
int width, int height, int stride,
|
||||
float quality_factor, uint8_t** output);
|
||||
@@ -43,6 +46,22 @@ WEBP_EXTERN(size_t) WebPEncodeBGRA(const uint8_t* bgra,
|
||||
int width, int height, int stride,
|
||||
float quality_factor, uint8_t** output);
|
||||
|
||||
// These functions are the equivalent of the above, but compressing in a
|
||||
// lossless manner. Files are usually larger than lossy format, but will
|
||||
// not suffer any compression loss.
|
||||
WEBP_EXTERN(size_t) WebPEncodeLosslessRGB(const uint8_t* rgb,
|
||||
int width, int height, int stride,
|
||||
uint8_t** output);
|
||||
WEBP_EXTERN(size_t) WebPEncodeLosslessBGR(const uint8_t* bgr,
|
||||
int width, int height, int stride,
|
||||
uint8_t** output);
|
||||
WEBP_EXTERN(size_t) WebPEncodeLosslessRGBA(const uint8_t* rgba,
|
||||
int width, int height, int stride,
|
||||
uint8_t** output);
|
||||
WEBP_EXTERN(size_t) WebPEncodeLosslessBGRA(const uint8_t* bgra,
|
||||
int width, int height, int stride,
|
||||
uint8_t** output);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Coding parameters
|
||||
|
||||
|
Reference in New Issue
Block a user