// Copyright 2012 Google Inc. All Rights Reserved. // // Use of this source code is governed by a BSD-style license // that can be found in the COPYING file in the root of the source // tree. An additional intellectual property rights grant can be found // in the file PATENTS. All contributing project authors may // be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Image transforms and color space conversion methods for lossless decoder. // // Authors: Vikas Arora ([email protected]) // Jyrki Alakuijala ([email protected]) // Vincent Rabaud ([email protected]) #ifndef WEBP_DSP_LOSSLESS_COMMON_H_ #define WEBP_DSP_LOSSLESS_COMMON_H_ #include "src/dsp/cpu.h" #include "src/utils/utils.h" #include "src/webp/types.h" #ifdef __cplusplus extern "C" { #endif //------------------------------------------------------------------------------ // Decoding // color mapping related functions. static WEBP_INLINE uint32_t VP8GetARGBIndex(uint32_t idx) { … } static WEBP_INLINE uint8_t VP8GetAlphaIndex(uint8_t idx) { … } static WEBP_INLINE uint32_t VP8GetARGBValue(uint32_t val) { … } static WEBP_INLINE uint8_t VP8GetAlphaValue(uint32_t val) { … } //------------------------------------------------------------------------------ // 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) { … } // Converts near lossless quality into max number of bits shaved off. static WEBP_INLINE int VP8LNearLosslessBits(int near_lossless_quality) { … } // ----------------------------------------------------------------------------- // 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 … #define APPROX_LOG_MAX … #define LOG_2_RECIPROCAL … #define LOG_LOOKUP_IDX_MAX … extern const float kLog2Table[LOG_LOOKUP_IDX_MAX]; extern const float kSLog2Table[LOG_LOOKUP_IDX_MAX]; VP8LFastLog2SlowFunc; extern VP8LFastLog2SlowFunc VP8LFastLog2Slow; extern VP8LFastLog2SlowFunc VP8LFastSLog2Slow; static WEBP_INLINE float VP8LFastLog2(uint32_t v) { … } // Fast calculation of v * log2(v) for integer input. static WEBP_INLINE float VP8LFastSLog2(uint32_t v) { … } // ----------------------------------------------------------------------------- // PrefixEncode() // 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) { … } static WEBP_INLINE void VP8LPrefixEncodeNoLUT(int distance, int* const code, int* const extra_bits, int* const extra_bits_value) { … } #define PREFIX_LOOKUP_IDX_MAX … 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) { … } static WEBP_INLINE void VP8LPrefixEncode(int distance, int* const code, int* const extra_bits, int* const extra_bits_value) { … } // Sum of each component, mod 256. static WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW WEBP_INLINE uint32_t VP8LAddPixels(uint32_t a, uint32_t b) { … } // Difference of each component, mod 256. static WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) { … } //------------------------------------------------------------------------------ // Transform-related functions used in both encoding and decoding. // Macros used to create a batch predictor that iteratively uses a // one-pixel predictor. // The predictor is added to the output pixel (which // is therefore considered as a residual) to get the final prediction. #define GENERATE_PREDICTOR_ADD(PREDICTOR, PREDICTOR_ADD) … #ifdef __cplusplus } // extern "C" #endif #endif // WEBP_DSP_LOSSLESS_COMMON_H_