1
// Copyright 2010 Google Inc. All Rights Reserved.
3
// Use of this source code is governed by a BSD-style license
4
// that can be found in the COPYING file in the root of the source
5
// tree. An additional intellectual property rights grant can be found
6
// in the file PATENTS. All contributing project authors may
7
// be found in the AUTHORS file in the root of the source tree.
8
// -----------------------------------------------------------------------------
10
// YUV->RGB conversion function
12
// Author: Skal (pascal.massimino@gmail.com)
16
#if defined(__cplusplus) || defined(c_plusplus)
20
#ifdef WEBP_YUV_USE_TABLE
22
int16_t VP8kVToR[256], VP8kUToB[256];
23
int32_t VP8kVToG[256], VP8kUToG[256];
24
uint8_t VP8kClip[YUV_RANGE_MAX - YUV_RANGE_MIN];
25
uint8_t VP8kClip4Bits[YUV_RANGE_MAX - YUV_RANGE_MIN];
29
static WEBP_INLINE uint8_t clip(int v, int max_value) {
30
return v < 0 ? 0 : v > max_value ? max_value : v;
33
void VP8YUVInit(void) {
39
for (i = 0; i < 256; ++i) {
40
VP8kVToR[i] = (89858 * (i - 128) + YUV_HALF) >> YUV_FIX;
41
VP8kUToG[i] = -22014 * (i - 128) + YUV_HALF;
42
VP8kVToG[i] = -45773 * (i - 128);
43
VP8kUToB[i] = (113618 * (i - 128) + YUV_HALF) >> YUV_FIX;
45
for (i = YUV_RANGE_MIN; i < YUV_RANGE_MAX; ++i) {
46
const int k = ((i - 16) * 76283 + YUV_HALF) >> YUV_FIX;
47
VP8kClip[i - YUV_RANGE_MIN] = clip(k, 255);
48
VP8kClip4Bits[i - YUV_RANGE_MIN] = clip((k + 8) >> 4, 15);
51
for (i = 0; i < 256; ++i) {
52
VP8kVToR[i] = (91881 * (i - 128) + YUV_HALF) >> YUV_FIX;
53
VP8kUToG[i] = -22554 * (i - 128) + YUV_HALF;
54
VP8kVToG[i] = -46802 * (i - 128);
55
VP8kUToB[i] = (116130 * (i - 128) + YUV_HALF) >> YUV_FIX;
57
for (i = YUV_RANGE_MIN; i < YUV_RANGE_MAX; ++i) {
59
VP8kClip[i - YUV_RANGE_MIN] = clip(k, 255);
60
VP8kClip4Bits[i - YUV_RANGE_MIN] = clip((k + 8) >> 4, 15);
69
void VP8YUVInit(void) {}
71
#endif // WEBP_YUV_USE_TABLE
73
#if defined(__cplusplus) || defined(c_plusplus)