| Index: third_party/libwebp/dsp/lossless.h
|
| diff --git a/third_party/libwebp/dsp/lossless.h b/third_party/libwebp/dsp/lossless.h
|
| index 8c7551c9c2afbfff32df286c19d525db66441b3c..e063bdd1aa1fa91da6445cebbdbd99a722601f94 100644
|
| --- a/third_party/libwebp/dsp/lossless.h
|
| +++ b/third_party/libwebp/dsp/lossless.h
|
| @@ -25,14 +25,17 @@
|
| extern "C" {
|
| #endif
|
|
|
| +#ifdef WEBP_EXPERIMENTAL_FEATURES
|
| +#include "../enc/delta_palettization.h"
|
| +#endif // WEBP_EXPERIMENTAL_FEATURES
|
| +
|
| //------------------------------------------------------------------------------
|
| -// Signatures and generic function-pointers
|
| +// Decoding
|
|
|
| typedef uint32_t (*VP8LPredictorFunc)(uint32_t left, const uint32_t* const top);
|
| extern VP8LPredictorFunc VP8LPredictors[16];
|
|
|
| typedef void (*VP8LProcessBlueAndRedFunc)(uint32_t* argb_data, int num_pixels);
|
| -extern VP8LProcessBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed;
|
| extern VP8LProcessBlueAndRedFunc VP8LAddGreenToBlueAndRed;
|
|
|
| typedef struct {
|
| @@ -44,9 +47,19 @@ typedef struct {
|
| } VP8LMultipliers;
|
| typedef void (*VP8LTransformColorFunc)(const VP8LMultipliers* const m,
|
| uint32_t* argb_data, int num_pixels);
|
| -extern VP8LTransformColorFunc VP8LTransformColor;
|
| extern VP8LTransformColorFunc VP8LTransformColorInverse;
|
|
|
| +struct VP8LTransform; // Defined in dec/vp8li.h.
|
| +
|
| +// Performs inverse transform of data given transform information, start and end
|
| +// rows. Transform will be applied to rows [row_start, row_end[.
|
| +// The *in and *out pointers refer to source and destination data respectively
|
| +// corresponding to the intermediate row (row_start).
|
| +void VP8LInverseTransform(const struct VP8LTransform* const transform,
|
| + int row_start, int row_end,
|
| + const uint32_t* const in, uint32_t* const out);
|
| +
|
| +// Color space conversion.
|
| typedef void (*VP8LConvertFunc)(const uint32_t* src, int num_pixels,
|
| uint8_t* dst);
|
| extern VP8LConvertFunc VP8LConvertBGRAToRGB;
|
| @@ -55,9 +68,47 @@ extern VP8LConvertFunc VP8LConvertBGRAToRGBA4444;
|
| extern VP8LConvertFunc VP8LConvertBGRAToRGB565;
|
| extern VP8LConvertFunc VP8LConvertBGRAToBGR;
|
|
|
| +// Converts from BGRA to other color spaces.
|
| +void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels,
|
| + WEBP_CSP_MODE out_colorspace, uint8_t* const rgba);
|
| +
|
| +// color mapping related functions.
|
| +static WEBP_INLINE uint32_t VP8GetARGBIndex(uint32_t idx) {
|
| + return (idx >> 8) & 0xff;
|
| +}
|
| +
|
| +static WEBP_INLINE uint8_t VP8GetAlphaIndex(uint8_t idx) {
|
| + return idx;
|
| +}
|
| +
|
| +static WEBP_INLINE uint32_t VP8GetARGBValue(uint32_t val) {
|
| + return val;
|
| +}
|
| +
|
| +static WEBP_INLINE uint8_t VP8GetAlphaValue(uint32_t val) {
|
| + return (val >> 8) & 0xff;
|
| +}
|
| +
|
| +typedef void (*VP8LMapARGBFunc)(const uint32_t* src,
|
| + const uint32_t* const color_map,
|
| + uint32_t* dst, int y_start,
|
| + int y_end, int width);
|
| +typedef void (*VP8LMapAlphaFunc)(const uint8_t* src,
|
| + const uint32_t* const color_map,
|
| + uint8_t* dst, int y_start,
|
| + int y_end, int width);
|
| +
|
| +extern VP8LMapARGBFunc VP8LMapColor32b;
|
| +extern VP8LMapAlphaFunc VP8LMapColor8b;
|
| +
|
| +// Similar to the static method ColorIndexInverseTransform() that is part of
|
| +// lossless.c, but used only for alpha decoding. It takes uint8_t (rather than
|
| +// uint32_t) arguments for 'src' and 'dst'.
|
| +void VP8LColorIndexInverseTransformAlpha(
|
| + const struct VP8LTransform* const transform, int y_start, int y_end,
|
| + const uint8_t* src, uint8_t* dst);
|
| +
|
| // Expose some C-only fallback functions
|
| -void VP8LTransformColor_C(const VP8LMultipliers* const m,
|
| - uint32_t* data, int num_pixels);
|
| void VP8LTransformColorInverse_C(const VP8LMultipliers* const m,
|
| uint32_t* data, int num_pixels);
|
|
|
| @@ -68,47 +119,51 @@ void VP8LConvertBGRAToRGBA4444_C(const uint32_t* src,
|
| void VP8LConvertBGRAToRGB565_C(const uint32_t* src,
|
| int num_pixels, uint8_t* dst);
|
| void VP8LConvertBGRAToBGR_C(const uint32_t* src, int num_pixels, uint8_t* dst);
|
| -void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels);
|
| void VP8LAddGreenToBlueAndRed_C(uint32_t* data, int num_pixels);
|
|
|
| // Must be called before calling any of the above methods.
|
| void VP8LDspInit(void);
|
|
|
| //------------------------------------------------------------------------------
|
| -// Image transforms.
|
| +// Encoding
|
|
|
| -struct VP8LTransform; // Defined in dec/vp8li.h.
|
| +extern VP8LProcessBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed;
|
| +extern VP8LTransformColorFunc VP8LTransformColor;
|
| +typedef void (*VP8LCollectColorBlueTransformsFunc)(
|
| + const uint32_t* argb, int stride,
|
| + int tile_width, int tile_height,
|
| + int green_to_blue, int red_to_blue, int histo[]);
|
| +extern VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms;
|
| +
|
| +typedef void (*VP8LCollectColorRedTransformsFunc)(
|
| + const uint32_t* argb, int stride,
|
| + int tile_width, int tile_height,
|
| + int green_to_red, int histo[]);
|
| +extern VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms;
|
|
|
| -// Performs inverse transform of data given transform information, start and end
|
| -// rows. Transform will be applied to rows [row_start, row_end[.
|
| -// The *in and *out pointers refer to source and destination data respectively
|
| -// corresponding to the intermediate row (row_start).
|
| -void VP8LInverseTransform(const struct VP8LTransform* const transform,
|
| - int row_start, int row_end,
|
| - const uint32_t* const in, uint32_t* const out);
|
| +// Expose some C-only fallback functions
|
| +void VP8LTransformColor_C(const VP8LMultipliers* const m,
|
| + uint32_t* data, int num_pixels);
|
| +void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels);
|
| +void VP8LCollectColorRedTransforms_C(const uint32_t* argb, int stride,
|
| + int tile_width, int tile_height,
|
| + int green_to_red, int histo[]);
|
| +void VP8LCollectColorBlueTransforms_C(const uint32_t* argb, int stride,
|
| + int tile_width, int tile_height,
|
| + int green_to_blue, int red_to_blue,
|
| + int histo[]);
|
|
|
| -// Similar to the static method ColorIndexInverseTransform() that is part of
|
| -// lossless.c, but used only for alpha decoding. It takes uint8_t (rather than
|
| -// uint32_t) arguments for 'src' and 'dst'.
|
| -void VP8LColorIndexInverseTransformAlpha(
|
| - const struct VP8LTransform* const transform, int y_start, int y_end,
|
| - const uint8_t* src, uint8_t* dst);
|
| +//------------------------------------------------------------------------------
|
| +// Image transforms.
|
|
|
| -void VP8LResidualImage(int width, int height, int bits,
|
| +void VP8LResidualImage(int width, int height, int bits, int low_effort,
|
| uint32_t* const argb, uint32_t* const argb_scratch,
|
| - uint32_t* const image);
|
| + uint32_t* const image, int exact);
|
|
|
| void VP8LColorSpaceTransform(int width, int height, int bits, int quality,
|
| uint32_t* const argb, uint32_t* image);
|
|
|
| //------------------------------------------------------------------------------
|
| -// Color space conversion.
|
| -
|
| -// Converts from BGRA to other color spaces.
|
| -void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels,
|
| - WEBP_CSP_MODE out_colorspace, uint8_t* const rgba);
|
| -
|
| -//------------------------------------------------------------------------------
|
| // Misc methods.
|
|
|
| // Computes sampled size of 'size' when sampling using 'sampling bits'.
|
| @@ -119,6 +174,14 @@ static WEBP_INLINE uint32_t VP8LSubSampleSize(uint32_t size,
|
|
|
| // -----------------------------------------------------------------------------
|
| // Faster logarithm for integers. Small values use a look-up table.
|
| +
|
| +// The threshold till approximate version of log_2 can be used.
|
| +// Practically, we can get rid of the call to log() as the two values match to
|
| +// very high degree (the ratio of these two is 0.99999x).
|
| +// Keeping a high threshold for now.
|
| +#define APPROX_LOG_WITH_CORRECTION_MAX 65536
|
| +#define APPROX_LOG_MAX 4096
|
| +#define LOG_2_RECIPROCAL 1.44269504088896338700465094007086
|
| #define LOG_LOOKUP_IDX_MAX 256
|
| extern const float kLog2Table[LOG_LOOKUP_IDX_MAX];
|
| extern const float kSLog2Table[LOG_LOOKUP_IDX_MAX];
|
| @@ -141,23 +204,56 @@ static WEBP_INLINE float VP8LFastSLog2(uint32_t v) {
|
| typedef double (*VP8LCostFunc)(const uint32_t* population, int length);
|
| typedef double (*VP8LCostCombinedFunc)(const uint32_t* X, const uint32_t* Y,
|
| int length);
|
| +typedef float (*VP8LCombinedShannonEntropyFunc)(const int X[256],
|
| + const int Y[256]);
|
|
|
| extern VP8LCostFunc VP8LExtraCost;
|
| extern VP8LCostCombinedFunc VP8LExtraCostCombined;
|
| +extern VP8LCombinedShannonEntropyFunc VP8LCombinedShannonEntropy;
|
|
|
| typedef struct { // small struct to hold counters
|
| int counts[2]; // index: 0=zero steak, 1=non-zero streak
|
| int streaks[2][2]; // [zero/non-zero][streak<3 / streak>=3]
|
| } VP8LStreaks;
|
|
|
| -typedef VP8LStreaks (*VP8LCostCountFunc)(const uint32_t* population,
|
| - int length);
|
| typedef VP8LStreaks (*VP8LCostCombinedCountFunc)(const uint32_t* X,
|
| const uint32_t* Y, int length);
|
|
|
| -extern VP8LCostCountFunc VP8LHuffmanCostCount;
|
| extern VP8LCostCombinedCountFunc VP8LHuffmanCostCombinedCount;
|
|
|
| +typedef struct { // small struct to hold bit entropy results
|
| + double entropy; // entropy
|
| + uint32_t sum; // sum of the population
|
| + int nonzeros; // number of non-zero elements in the population
|
| + uint32_t max_val; // maximum value in the population
|
| + uint32_t nonzero_code; // index of the last non-zero in the population
|
| +} VP8LBitEntropy;
|
| +
|
| +void VP8LBitEntropyInit(VP8LBitEntropy* const entropy);
|
| +
|
| +// Get the combined symbol bit entropy and Huffman cost stats for the
|
| +// distributions 'X' and 'Y'. Those results can then be refined according to
|
| +// codec specific heuristics.
|
| +void VP8LGetCombinedEntropyUnrefined(const uint32_t* const X,
|
| + const uint32_t* const Y, int length,
|
| + VP8LBitEntropy* const bit_entropy,
|
| + VP8LStreaks* const stats);
|
| +// Get the entropy for the distribution 'X'.
|
| +void VP8LGetEntropyUnrefined(const uint32_t* const X, int length,
|
| + VP8LBitEntropy* const bit_entropy,
|
| + VP8LStreaks* const stats);
|
| +
|
| +void VP8LBitsEntropyUnrefined(const uint32_t* const array, int n,
|
| + VP8LBitEntropy* const entropy);
|
| +
|
| +typedef void (*GetEntropyUnrefinedHelperFunc)(uint32_t val, int i,
|
| + uint32_t* const val_prev,
|
| + int* const i_prev,
|
| + VP8LBitEntropy* const bit_entropy,
|
| + VP8LStreaks* const stats);
|
| +// Internal function used by VP8LGet*EntropyUnrefined.
|
| +extern GetEntropyUnrefinedHelperFunc VP8LGetEntropyUnrefinedHelper;
|
| +
|
| typedef void (*VP8LHistogramAddFunc)(const VP8LHistogram* const a,
|
| const VP8LHistogram* const b,
|
| VP8LHistogram* const out);
|
| @@ -240,6 +336,9 @@ static WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) {
|
| void VP8LBundleColorMap(const uint8_t* const row, int width,
|
| int xbits, uint32_t* const dst);
|
|
|
| +// Must be called before calling any of the above methods.
|
| +void VP8LEncDspInit(void);
|
| +
|
| //------------------------------------------------------------------------------
|
|
|
| #ifdef __cplusplus
|
|
|