// 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 (vikaas.arora@gmail.com) // Jyrki Alakuijala (jyrki@google.com) // Vincent Rabaud (vrabaud@google.com)
// 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 // VP8LFastLog2 and VP8LFastSLog2 are used on elements from image histograms. // The histogram values cannot exceed the maximum number of pixels, which // is (1 << 14) * (1 << 14). Therefore S * log(S) < (1 << 33). // No more than 32 bits of precision should be chosen. // To match the original float implementation, 23 bits of precision are used. #define LOG_2_PRECISION_BITS 23 #define LOG_2_RECIPROCAL 1.44269504088896338700465094007086 // LOG_2_RECIPROCAL * (1 << LOG_2_PRECISION_BITS) #define LOG_2_RECIPROCAL_FIXED_DOUBLE 12102203.161561485379934310913085937500 #define LOG_2_RECIPROCAL_FIXED ((uint64_t)12102203) #define LOG_LOOKUP_IDX_MAX 256 externconst uint32_t kLog2Table[LOG_LOOKUP_IDX_MAX]; externconst uint64_t kSLog2Table[LOG_LOOKUP_IDX_MAX]; typedef uint32_t (*VP8LFastLog2SlowFunc)(uint32_t v); typedef uint64_t (*VP8LFastSLog2SlowFunc)(uint32_t v);
// 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) { constint highest_bit = BitsLog2Floor(--distance); constint second_highest_bit = (distance >> (highest_bit - 1)) & 1;
*extra_bits = highest_bit - 1;
*code = 2 * highest_bit + second_highest_bit;
}
// Sum of each component, mod 256. static WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW 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_UBSAN_IGNORE_UNSIGNED_OVERFLOW 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);
}
//------------------------------------------------------------------------------ // 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) \ staticvoid PREDICTOR_ADD(const uint32_t* in, const uint32_t* upper, \ int num_pixels, uint32_t* WEBP_RESTRICT out) { \ int x; \
assert(upper != NULL); \ for (x = 0; x < num_pixels; ++x) { \ const uint32_t pred = (PREDICTOR)(&out[x - 1], upper + x); \
out[x] = VP8LAddPixels(in[x], pred); \
} \
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.