| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#ifndef WEBP_DSP_YUV_H_ |
| 36 |
#define WEBP_DSP_YUV_H_ |
| 37 |
|
| 38 |
#include "src/dsp/dsp.h" |
| 39 |
#include "src/dec/vp8_dec.h" |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#ifdef __cplusplus |
| 45 |
extern "C" { |
| 46 |
#endif |
| 47 |
|
| 48 |
enum { |
| 49 |
YUV_FIX = 16, |
| 50 |
YUV_HALF = 1 << (YUV_FIX - 1), |
| 51 |
|
| 52 |
YUV_FIX2 = 6, |
| 53 |
YUV_MASK2 = (256 << YUV_FIX2) - 1 |
| 54 |
}; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
static WEBP_INLINE int MultHi(int v, int coeff) { |
| 60 |
return (v * coeff) >> 8; |
| 61 |
} |
| 62 |
|
| 63 |
static WEBP_INLINE int VP8Clip8(int v) { |
| 64 |
return ((v & ~YUV_MASK2) == 0) ? (v >> YUV_FIX2) : (v < 0) ? 0 : 255; |
| 65 |
} |
| 66 |
|
| 67 |
static WEBP_INLINE int VP8YUVToR(int y, int v) { |
| 68 |
return VP8Clip8(MultHi(y, 19077) + MultHi(v, 26149) - 14234); |
| 69 |
} |
| 70 |
|
| 71 |
static WEBP_INLINE int VP8YUVToG(int y, int u, int v) { |
| 72 |
return VP8Clip8(MultHi(y, 19077) - MultHi(u, 6419) - MultHi(v, 13320) + 8708); |
| 73 |
} |
| 74 |
|
| 75 |
static WEBP_INLINE int VP8YUVToB(int y, int u) { |
| 76 |
return VP8Clip8(MultHi(y, 19077) + MultHi(u, 33050) - 17685); |
| 77 |
} |
| 78 |
|
| 79 |
static WEBP_INLINE void VP8YuvToRgb(int y, int u, int v, |
| 80 |
uint8_t* const rgb) { |
| 81 |
rgb[0] = VP8YUVToR(y, v); |
| 82 |
rgb[1] = VP8YUVToG(y, u, v); |
| 83 |
rgb[2] = VP8YUVToB(y, u); |
| 84 |
} |
| 85 |
|
| 86 |
static WEBP_INLINE void VP8YuvToBgr(int y, int u, int v, |
| 87 |
uint8_t* const bgr) { |
| 88 |
bgr[0] = VP8YUVToB(y, u); |
| 89 |
bgr[1] = VP8YUVToG(y, u, v); |
| 90 |
bgr[2] = VP8YUVToR(y, v); |
| 91 |
} |
| 92 |
|
| 93 |
static WEBP_INLINE void VP8YuvToRgb565(int y, int u, int v, |
| 94 |
uint8_t* const rgb) { |
| 95 |
const int r = VP8YUVToR(y, v); |
| 96 |
const int g = VP8YUVToG(y, u, v); |
| 97 |
const int b = VP8YUVToB(y, u); |
| 98 |
const int rg = (r & 0xf8) | (g >> 5); |
| 99 |
const int gb = ((g << 3) & 0xe0) | (b >> 3); |
| 100 |
#if (WEBP_SWAP_16BIT_CSP == 1) |
| 101 |
rgb[0] = gb; |
| 102 |
rgb[1] = rg; |
| 103 |
#else |
| 104 |
rgb[0] = rg; |
| 105 |
rgb[1] = gb; |
| 106 |
#endif |
| 107 |
} |
| 108 |
|
| 109 |
static WEBP_INLINE void VP8YuvToRgba4444(int y, int u, int v, |
| 110 |
uint8_t* const argb) { |
| 111 |
const int r = VP8YUVToR(y, v); |
| 112 |
const int g = VP8YUVToG(y, u, v); |
| 113 |
const int b = VP8YUVToB(y, u); |
| 114 |
const int rg = (r & 0xf0) | (g >> 4); |
| 115 |
const int ba = (b & 0xf0) | 0x0f; |
| 116 |
#if (WEBP_SWAP_16BIT_CSP == 1) |
| 117 |
argb[0] = ba; |
| 118 |
argb[1] = rg; |
| 119 |
#else |
| 120 |
argb[0] = rg; |
| 121 |
argb[1] = ba; |
| 122 |
#endif |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
static WEBP_INLINE void VP8YuvToArgb(uint8_t y, uint8_t u, uint8_t v, |
| 129 |
uint8_t* const argb) { |
| 130 |
argb[0] = 0xff; |
| 131 |
VP8YuvToRgb(y, u, v, argb + 1); |
| 132 |
} |
| 133 |
|
| 134 |
static WEBP_INLINE void VP8YuvToBgra(uint8_t y, uint8_t u, uint8_t v, |
| 135 |
uint8_t* const bgra) { |
| 136 |
VP8YuvToBgr(y, u, v, bgra); |
| 137 |
bgra[3] = 0xff; |
| 138 |
} |
| 139 |
|
| 140 |
static WEBP_INLINE void VP8YuvToRgba(uint8_t y, uint8_t u, uint8_t v, |
| 141 |
uint8_t* const rgba) { |
| 142 |
VP8YuvToRgb(y, u, v, rgba); |
| 143 |
rgba[3] = 0xff; |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
#if defined(WEBP_USE_SSE2) |
| 150 |
|
| 151 |
|
| 152 |
void VP8YuvToRgba32_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, |
| 153 |
uint8_t* dst); |
| 154 |
void VP8YuvToRgb32_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, |
| 155 |
uint8_t* dst); |
| 156 |
void VP8YuvToBgra32_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, |
| 157 |
uint8_t* dst); |
| 158 |
void VP8YuvToBgr32_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, |
| 159 |
uint8_t* dst); |
| 160 |
void VP8YuvToArgb32_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, |
| 161 |
uint8_t* dst); |
| 162 |
void VP8YuvToRgba444432_SSE2(const uint8_t* y, const uint8_t* u, |
| 163 |
const uint8_t* v, uint8_t* dst); |
| 164 |
void VP8YuvToRgb56532_SSE2(const uint8_t* y, const uint8_t* u, const uint8_t* v, |
| 165 |
uint8_t* dst); |
| 166 |
|
| 167 |
#endif |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
#if defined(WEBP_USE_SSE41) |
| 173 |
|
| 174 |
|
| 175 |
void VP8YuvToRgb32_SSE41(const uint8_t* y, const uint8_t* u, const uint8_t* v, |
| 176 |
uint8_t* dst); |
| 177 |
void VP8YuvToBgr32_SSE41(const uint8_t* y, const uint8_t* u, const uint8_t* v, |
| 178 |
uint8_t* dst); |
| 179 |
|
| 180 |
#endif |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
static WEBP_INLINE int VP8ClipUV(int uv, int rounding) { |
| 187 |
uv = (uv + rounding + (128 << (YUV_FIX + 2))) >> (YUV_FIX + 2); |
| 188 |
return ((uv & ~0xff) == 0) ? uv : (uv < 0) ? 0 : 255; |
| 189 |
} |
| 190 |
|
| 191 |
static WEBP_INLINE int VP8RGBToY(int r, int g, int b, int rounding) { |
| 192 |
const int luma = 16839 * r + 33059 * g + 6420 * b; |
| 193 |
return (luma + rounding + (16 << YUV_FIX)) >> YUV_FIX; |
| 194 |
} |
| 195 |
|
| 196 |
static WEBP_INLINE int VP8RGBToU(int r, int g, int b, int rounding) { |
| 197 |
const int u = -9719 * r - 19081 * g + 28800 * b; |
| 198 |
return VP8ClipUV(u, rounding); |
| 199 |
} |
| 200 |
|
| 201 |
static WEBP_INLINE int VP8RGBToV(int r, int g, int b, int rounding) { |
| 202 |
const int v = +28800 * r - 24116 * g - 4684 * b; |
| 203 |
return VP8ClipUV(v, rounding); |
| 204 |
} |
| 205 |
|
| 206 |
#ifdef __cplusplus |
| 207 |
} |
| 208 |
#endif |
| 209 |
|
| 210 |
#endif |