// Copyright 2010 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. // ----------------------------------------------------------------------------- // // inline YUV<->RGB conversion function // // The exact naming is Y'CbCr, following the ITU-R BT.601 standard. // More information at: https://en.wikipedia.org/wiki/YCbCr // Y = 0.2569 * R + 0.5044 * G + 0.0979 * B + 16 // U = -0.1483 * R - 0.2911 * G + 0.4394 * B + 128 // V = 0.4394 * R - 0.3679 * G - 0.0715 * B + 128 // We use 16bit fixed point operations for RGB->YUV conversion (YUV_FIX). // // For the Y'CbCr to RGB conversion, the BT.601 specification reads: // R = 1.164 * (Y-16) + 1.596 * (V-128) // G = 1.164 * (Y-16) - 0.813 * (V-128) - 0.391 * (U-128) // B = 1.164 * (Y-16) + 2.018 * (U-128) // where Y is in the [16,235] range, and U/V in the [16,240] range. // // The fixed-point implementation used here is: // R = (19077 . y + 26149 . v - 14234) >> 6 // G = (19077 . y - 6419 . u - 13320 . v + 8708) >> 6 // B = (19077 . y + 33050 . u - 17685) >> 6 // where the '.' operator is the mulhi_epu16 variant: // a . b = ((a << 8) * b) >> 16 // that preserves 8 bits of fractional precision before final descaling. // Author: Skal ([email protected]) #ifndef WEBP_DSP_YUV_H_ #define WEBP_DSP_YUV_H_ #include "src/dsp/dsp.h" #include "src/dec/vp8_dec.h" //------------------------------------------------------------------------------ // YUV -> RGB conversion #ifdef __cplusplus extern "C" { #endif enum { … }; //------------------------------------------------------------------------------ // slower on x86 by ~7-8%, but bit-exact with the SSE2/NEON version static WEBP_INLINE int MultHi(int v, int coeff) { … } static WEBP_INLINE int VP8Clip8(int v) { … } static WEBP_INLINE int VP8YUVToR(int y, int v) { … } static WEBP_INLINE int VP8YUVToG(int y, int u, int v) { … } static WEBP_INLINE int VP8YUVToB(int y, int u) { … } static WEBP_INLINE void VP8YuvToRgb(int y, int u, int v, uint8_t* const rgb) { … } static WEBP_INLINE void VP8YuvToBgr(int y, int u, int v, uint8_t* const bgr) { … } static WEBP_INLINE void VP8YuvToRgb565(int y, int u, int v, uint8_t* const rgb) { … } static WEBP_INLINE void VP8YuvToRgba4444(int y, int u, int v, uint8_t* const argb) { … } //----------------------------------------------------------------------------- // Alpha handling variants static WEBP_INLINE void VP8YuvToArgb(uint8_t y, uint8_t u, uint8_t v, uint8_t* const argb) { … } static WEBP_INLINE void VP8YuvToBgra(uint8_t y, uint8_t u, uint8_t v, uint8_t* const bgra) { … } static WEBP_INLINE void VP8YuvToRgba(uint8_t y, uint8_t u, uint8_t v, uint8_t* const rgba) { … } //----------------------------------------------------------------------------- // SSE2 extra functions (mostly for upsampling_sse2.c) #if defined(WEBP_USE_SSE2) // Process 32 pixels and store the result (16b, 24b or 32b per pixel) in *dst. void VP8YuvToRgba32_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, uint8_t* dst); void VP8YuvToRgb32_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, uint8_t* dst); void VP8YuvToBgra32_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, uint8_t* dst); void VP8YuvToBgr32_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, uint8_t* dst); void VP8YuvToArgb32_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, uint8_t* dst); void VP8YuvToRgba444432_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, uint8_t* dst); void VP8YuvToRgb56532_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, uint8_t* dst); #endif // WEBP_USE_SSE2 //----------------------------------------------------------------------------- // SSE41 extra functions (mostly for upsampling_sse41.c) #if defined(WEBP_USE_SSE41) // Process 32 pixels and store the result (16b, 24b or 32b per pixel) in *dst. void VP8YuvToRgb32_SSE41(const uint8_t* y, const uint8_t* u, const uint8_t* v, uint8_t* dst); void VP8YuvToBgr32_SSE41(const uint8_t* y, const uint8_t* u, const uint8_t* v, uint8_t* dst); #endif // WEBP_USE_SSE41 //------------------------------------------------------------------------------ // RGB -> YUV conversion // Stub functions that can be called with various rounding values: static WEBP_INLINE int VP8ClipUV(int uv, int rounding) { … } static WEBP_INLINE int VP8RGBToY(int r, int g, int b, int rounding) { … } static WEBP_INLINE int VP8RGBToU(int r, int g, int b, int rounding) { … } static WEBP_INLINE int VP8RGBToV(int r, int g, int b, int rounding) { … } #ifdef __cplusplus } // extern "C" #endif #endif // WEBP_DSP_YUV_H_