| Index: third_party/libwebp/dsp/lossless.h
|
| diff --git a/third_party/libwebp/dsp/lossless.h b/third_party/libwebp/dsp/lossless.h
|
| index 9f0d7a25b72d9fb2802e407d1b19fea5a1e8bbb5..352a54e5095dc567f0724fd4d98e3c6e2f94d48a 100644
|
| --- a/third_party/libwebp/dsp/lossless.h
|
| +++ b/third_party/libwebp/dsp/lossless.h
|
| @@ -18,7 +18,7 @@
|
| #include "../webp/types.h"
|
| #include "../webp/decode.h"
|
|
|
| -#include "../enc/histogram.h"
|
| +#include "../enc/histogram_enc.h"
|
| #include "../utils/utils.h"
|
|
|
| #ifdef __cplusplus
|
| @@ -26,7 +26,7 @@ extern "C" {
|
| #endif
|
|
|
| #ifdef WEBP_EXPERIMENTAL_FEATURES
|
| -#include "../enc/delta_palettization.h"
|
| +#include "../enc/delta_palettization_enc.h"
|
| #endif // WEBP_EXPERIMENTAL_FEATURES
|
|
|
| //------------------------------------------------------------------------------
|
| @@ -34,9 +34,17 @@ extern "C" {
|
|
|
| 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 VP8LAddGreenToBlueAndRed;
|
| +extern VP8LPredictorFunc VP8LPredictors_C[16];
|
| +// These Add/Sub function expects upper[-1] and out[-1] to be readable.
|
| +typedef void (*VP8LPredictorAddSubFunc)(const uint32_t* in,
|
| + const uint32_t* upper, int num_pixels,
|
| + uint32_t* out);
|
| +extern VP8LPredictorAddSubFunc VP8LPredictorsAdd[16];
|
| +extern VP8LPredictorAddSubFunc VP8LPredictorsAdd_C[16];
|
| +
|
| +typedef void (*VP8LProcessDecBlueAndRedFunc)(const uint32_t* src,
|
| + int num_pixels, uint32_t* dst);
|
| +extern VP8LProcessDecBlueAndRedFunc VP8LAddGreenToBlueAndRed;
|
|
|
| typedef struct {
|
| // Note: the members are uint8_t, so that any negative values are
|
| @@ -45,9 +53,10 @@ typedef struct {
|
| uint8_t green_to_blue_;
|
| uint8_t red_to_blue_;
|
| } VP8LMultipliers;
|
| -typedef void (*VP8LTransformColorFunc)(const VP8LMultipliers* const m,
|
| - uint32_t* argb_data, int num_pixels);
|
| -extern VP8LTransformColorFunc VP8LTransformColorInverse;
|
| +typedef void (*VP8LTransformColorInverseFunc)(const VP8LMultipliers* const m,
|
| + const uint32_t* src,
|
| + int num_pixels, uint32_t* dst);
|
| +extern VP8LTransformColorInverseFunc VP8LTransformColorInverse;
|
|
|
| struct VP8LTransform; // Defined in dec/vp8li.h.
|
|
|
| @@ -72,23 +81,6 @@ extern VP8LConvertFunc VP8LConvertBGRAToBGR;
|
| 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,
|
| @@ -110,7 +102,8 @@ void VP8LColorIndexInverseTransformAlpha(
|
|
|
| // Expose some C-only fallback functions
|
| void VP8LTransformColorInverse_C(const VP8LMultipliers* const m,
|
| - uint32_t* data, int num_pixels);
|
| + const uint32_t* src, int num_pixels,
|
| + uint32_t* dst);
|
|
|
| void VP8LConvertBGRAToRGB_C(const uint32_t* src, int num_pixels, uint8_t* dst);
|
| void VP8LConvertBGRAToRGBA_C(const uint32_t* src, int num_pixels, uint8_t* dst);
|
| @@ -119,7 +112,8 @@ 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 VP8LAddGreenToBlueAndRed_C(uint32_t* data, int num_pixels);
|
| +void VP8LAddGreenToBlueAndRed_C(const uint32_t* src, int num_pixels,
|
| + uint32_t* dst);
|
|
|
| // Must be called before calling any of the above methods.
|
| void VP8LDspInit(void);
|
| @@ -127,7 +121,10 @@ void VP8LDspInit(void);
|
| //------------------------------------------------------------------------------
|
| // Encoding
|
|
|
| -extern VP8LProcessBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed;
|
| +typedef void (*VP8LProcessEncBlueAndRedFunc)(uint32_t* dst, int num_pixels);
|
| +extern VP8LProcessEncBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed;
|
| +typedef void (*VP8LTransformColorFunc)(const VP8LMultipliers* const m,
|
| + uint32_t* const dst, int num_pixels);
|
| extern VP8LTransformColorFunc VP8LTransformColor;
|
| typedef void (*VP8LCollectColorBlueTransformsFunc)(
|
| const uint32_t* argb, int stride,
|
| @@ -153,62 +150,8 @@ void VP8LCollectColorBlueTransforms_C(const uint32_t* argb, int stride,
|
| int green_to_blue, int red_to_blue,
|
| int histo[]);
|
|
|
| -//------------------------------------------------------------------------------
|
| -// Image transforms.
|
| -
|
| -void VP8LResidualImage(int width, int height, int bits, int low_effort,
|
| - uint32_t* const argb, uint32_t* const argb_scratch,
|
| - uint32_t* const image, int near_lossless, int exact,
|
| - int used_subtract_green);
|
| -
|
| -void VP8LColorSpaceTransform(int width, int height, int bits, int quality,
|
| - uint32_t* const argb, uint32_t* image);
|
| -
|
| -//------------------------------------------------------------------------------
|
| -// Misc methods.
|
| -
|
| -// Computes sampled size of 'size' when sampling using 'sampling bits'.
|
| -static WEBP_INLINE uint32_t VP8LSubSampleSize(uint32_t size,
|
| - uint32_t sampling_bits) {
|
| - return (size + (1 << sampling_bits) - 1) >> sampling_bits;
|
| -}
|
| -
|
| -// Converts near lossless quality into max number of bits shaved off.
|
| -static WEBP_INLINE int VP8LNearLosslessBits(int near_lossless_quality) {
|
| - // 100 -> 0
|
| - // 80..99 -> 1
|
| - // 60..79 -> 2
|
| - // 40..59 -> 3
|
| - // 20..39 -> 4
|
| - // 0..19 -> 5
|
| - return 5 - near_lossless_quality / 20;
|
| -}
|
| -
|
| -// -----------------------------------------------------------------------------
|
| -// 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];
|
| -typedef float (*VP8LFastLog2SlowFunc)(uint32_t v);
|
| -
|
| -extern VP8LFastLog2SlowFunc VP8LFastLog2Slow;
|
| -extern VP8LFastLog2SlowFunc VP8LFastSLog2Slow;
|
| -
|
| -static WEBP_INLINE float VP8LFastLog2(uint32_t v) {
|
| - return (v < LOG_LOOKUP_IDX_MAX) ? kLog2Table[v] : VP8LFastLog2Slow(v);
|
| -}
|
| -// Fast calculation of v * log2(v) for integer input.
|
| -static WEBP_INLINE float VP8LFastSLog2(uint32_t v) {
|
| - return (v < LOG_LOOKUP_IDX_MAX) ? kSLog2Table[v] : VP8LFastSLog2Slow(v);
|
| -}
|
| +extern VP8LPredictorAddSubFunc VP8LPredictorsSub[16];
|
| +extern VP8LPredictorAddSubFunc VP8LPredictorsSub_C[16];
|
|
|
| // -----------------------------------------------------------------------------
|
| // Huffman-cost related functions.
|
| @@ -228,11 +171,6 @@ typedef struct { // small struct to hold counters
|
| int streaks[2][2]; // [zero/non-zero][streak<3 / streak>=3]
|
| } VP8LStreaks;
|
|
|
| -typedef VP8LStreaks (*VP8LCostCombinedCountFunc)(const uint32_t* X,
|
| - const uint32_t* Y, int length);
|
| -
|
| -extern VP8LCostCombinedCountFunc VP8LHuffmanCostCombinedCount;
|
| -
|
| typedef struct { // small struct to hold bit entropy results
|
| double entropy; // entropy
|
| uint32_t sum; // sum of the population
|
| @@ -246,26 +184,20 @@ 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);
|
| +typedef void (*VP8LGetCombinedEntropyUnrefinedFunc)(
|
| + const uint32_t X[], const uint32_t Y[], int length,
|
| + VP8LBitEntropy* const bit_entropy, VP8LStreaks* const stats);
|
| +extern VP8LGetCombinedEntropyUnrefinedFunc VP8LGetCombinedEntropyUnrefined;
|
| +
|
| // Get the entropy for the distribution 'X'.
|
| -void VP8LGetEntropyUnrefined(const uint32_t* const X, int length,
|
| - VP8LBitEntropy* const bit_entropy,
|
| - VP8LStreaks* const stats);
|
| +typedef void (*VP8LGetEntropyUnrefinedFunc)(const uint32_t X[], int length,
|
| + VP8LBitEntropy* const bit_entropy,
|
| + VP8LStreaks* const stats);
|
| +extern VP8LGetEntropyUnrefinedFunc VP8LGetEntropyUnrefined;
|
|
|
| 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);
|
| @@ -279,86 +211,11 @@ typedef int (*VP8LVectorMismatchFunc)(const uint32_t* const array1,
|
| // Returns the first index where array1 and array2 are different.
|
| extern VP8LVectorMismatchFunc VP8LVectorMismatch;
|
|
|
| -static WEBP_INLINE int VP8LBitsLog2Ceiling(uint32_t n) {
|
| - const int log_floor = BitsLog2Floor(n);
|
| - if (n == (n & ~(n - 1))) // zero or a power of two.
|
| - return log_floor;
|
| - else
|
| - return log_floor + 1;
|
| -}
|
| -
|
| -// Splitting of distance and length codes into prefixes and
|
| -// extra bits. The prefixes are encoded with an entropy code
|
| -// while the extra bits are stored just as normal bits.
|
| -static WEBP_INLINE void VP8LPrefixEncodeBitsNoLUT(int distance, int* const code,
|
| - int* const extra_bits) {
|
| - const int highest_bit = BitsLog2Floor(--distance);
|
| - const int second_highest_bit = (distance >> (highest_bit - 1)) & 1;
|
| - *extra_bits = highest_bit - 1;
|
| - *code = 2 * highest_bit + second_highest_bit;
|
| -}
|
| -
|
| -static WEBP_INLINE void VP8LPrefixEncodeNoLUT(int distance, int* const code,
|
| - int* const extra_bits,
|
| - int* const extra_bits_value) {
|
| - const int highest_bit = BitsLog2Floor(--distance);
|
| - const int second_highest_bit = (distance >> (highest_bit - 1)) & 1;
|
| - *extra_bits = highest_bit - 1;
|
| - *extra_bits_value = distance & ((1 << *extra_bits) - 1);
|
| - *code = 2 * highest_bit + second_highest_bit;
|
| -}
|
| -
|
| -#define PREFIX_LOOKUP_IDX_MAX 512
|
| -typedef struct {
|
| - int8_t code_;
|
| - int8_t extra_bits_;
|
| -} VP8LPrefixCode;
|
| -
|
| -// These tables are derived using VP8LPrefixEncodeNoLUT.
|
| -extern const VP8LPrefixCode kPrefixEncodeCode[PREFIX_LOOKUP_IDX_MAX];
|
| -extern const uint8_t kPrefixEncodeExtraBitsValue[PREFIX_LOOKUP_IDX_MAX];
|
| -static WEBP_INLINE void VP8LPrefixEncodeBits(int distance, int* const code,
|
| - int* const extra_bits) {
|
| - if (distance < PREFIX_LOOKUP_IDX_MAX) {
|
| - const VP8LPrefixCode prefix_code = kPrefixEncodeCode[distance];
|
| - *code = prefix_code.code_;
|
| - *extra_bits = prefix_code.extra_bits_;
|
| - } else {
|
| - VP8LPrefixEncodeBitsNoLUT(distance, code, extra_bits);
|
| - }
|
| -}
|
| -
|
| -static WEBP_INLINE void VP8LPrefixEncode(int distance, int* const code,
|
| - int* const extra_bits,
|
| - int* const extra_bits_value) {
|
| - if (distance < PREFIX_LOOKUP_IDX_MAX) {
|
| - const VP8LPrefixCode prefix_code = kPrefixEncodeCode[distance];
|
| - *code = prefix_code.code_;
|
| - *extra_bits = prefix_code.extra_bits_;
|
| - *extra_bits_value = kPrefixEncodeExtraBitsValue[distance];
|
| - } else {
|
| - VP8LPrefixEncodeNoLUT(distance, code, extra_bits, extra_bits_value);
|
| - }
|
| -}
|
| -
|
| -// Sum of each component, mod 256.
|
| -static WEBP_INLINE uint32_t VP8LAddPixels(uint32_t a, uint32_t b) {
|
| - const uint32_t alpha_and_green = (a & 0xff00ff00u) + (b & 0xff00ff00u);
|
| - const uint32_t red_and_blue = (a & 0x00ff00ffu) + (b & 0x00ff00ffu);
|
| - return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu);
|
| -}
|
| -
|
| -// Difference of each component, mod 256.
|
| -static WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) {
|
| - const uint32_t alpha_and_green =
|
| - 0x00ff00ffu + (a & 0xff00ff00u) - (b & 0xff00ff00u);
|
| - const uint32_t red_and_blue =
|
| - 0xff00ff00u + (a & 0x00ff00ffu) - (b & 0x00ff00ffu);
|
| - return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu);
|
| -}
|
| -
|
| -void VP8LBundleColorMap(const uint8_t* const row, int width,
|
| - int xbits, uint32_t* const dst);
|
| +typedef void (*VP8LBundleColorMapFunc)(const uint8_t* const row, int width,
|
| + int xbits, uint32_t* dst);
|
| +extern VP8LBundleColorMapFunc VP8LBundleColorMap;
|
| +void VP8LBundleColorMap_C(const uint8_t* const row, int width, int xbits,
|
| + uint32_t* dst);
|
|
|
| // Must be called before calling any of the above methods.
|
| void VP8LEncDspInit(void);
|
|
|