blob: 30f59c132dc635e759c6d33d0a33c6d68fe582ca [file] [log] [blame]
Eric Hassold9aea6422011-01-04 17:22:46 -08001// Copyright 2010 Google Inc.
2//
3// This code is licensed under the same terms as WebM:
4// Software License Agreement: http://www.webmproject.org/license/software/
5// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
6// -----------------------------------------------------------------------------
7//
8// YUV->RGB conversion function
9//
10// Author: Skal (pascal.massimino@gmail.com)
11
12#include "yuv.h"
13
14#if defined(__cplusplus) || defined(c_plusplus)
15extern "C" {
16#endif
17
18enum { YUV_HALF = 1 << (YUV_FIX - 1) };
19
20int16_t VP8kVToR[256], VP8kUToB[256];
21int32_t VP8kVToG[256], VP8kUToG[256];
22uint8_t VP8kClip[YUV_RANGE_MAX - YUV_RANGE_MIN];
23
24static int done = 0;
25
26void VP8YUVInit() {
27 int i;
28 if (done) {
29 return;
30 }
31 for (i = 0; i < 256; ++i) {
32 VP8kVToR[i] = (89858 * (i - 128) + YUV_HALF) >> YUV_FIX;
33 VP8kUToG[i] = -22014 * (i - 128) + YUV_HALF;
34 VP8kVToG[i] = -45773 * (i - 128);
35 VP8kUToB[i] = (113618 * (i - 128) + YUV_HALF) >> YUV_FIX;
36 }
37 for (i = YUV_RANGE_MIN; i < YUV_RANGE_MAX; ++i) {
38 const int k = ((i - 16) * 76283 + YUV_HALF) >> YUV_FIX;
39 VP8kClip[i - YUV_RANGE_MIN] = (k < 0) ? 0 : (k > 255) ? 255 : k;
40 }
41 done = 1;
42}
43
44#if defined(__cplusplus) || defined(c_plusplus)
45} // extern "C"
46#endif