• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2010 Google Inc. All Rights Reserved.
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)
15 extern "C" {
16 #endif
17 
18 enum { YUV_HALF = 1 << (YUV_FIX - 1) };
19 
20 int16_t VP8kVToR[256], VP8kUToB[256];
21 int32_t VP8kVToG[256], VP8kUToG[256];
22 uint8_t VP8kClip[YUV_RANGE_MAX - YUV_RANGE_MIN];
23 uint8_t VP8kClip4Bits[YUV_RANGE_MAX - YUV_RANGE_MIN];
24 
25 static int done = 0;
26 
clip(int v,int max_value)27 static WEBP_INLINE uint8_t clip(int v, int max_value) {
28   return v < 0 ? 0 : v > max_value ? max_value : v;
29 }
30 
VP8YUVInit(void)31 void VP8YUVInit(void) {
32   int i;
33   if (done) {
34     return;
35   }
36 #ifndef USE_YUVj
37   for (i = 0; i < 256; ++i) {
38     VP8kVToR[i] = (89858 * (i - 128) + YUV_HALF) >> YUV_FIX;
39     VP8kUToG[i] = -22014 * (i - 128) + YUV_HALF;
40     VP8kVToG[i] = -45773 * (i - 128);
41     VP8kUToB[i] = (113618 * (i - 128) + YUV_HALF) >> YUV_FIX;
42   }
43   for (i = YUV_RANGE_MIN; i < YUV_RANGE_MAX; ++i) {
44     const int k = ((i - 16) * 76283 + YUV_HALF) >> YUV_FIX;
45     VP8kClip[i - YUV_RANGE_MIN] = clip(k, 255);
46     VP8kClip4Bits[i - YUV_RANGE_MIN] = clip((k + 8) >> 4, 15);
47   }
48 #else
49   for (i = 0; i < 256; ++i) {
50     VP8kVToR[i] = (91881 * (i - 128) + YUV_HALF) >> YUV_FIX;
51     VP8kUToG[i] = -22554 * (i - 128) + YUV_HALF;
52     VP8kVToG[i] = -46802 * (i - 128);
53     VP8kUToB[i] = (116130 * (i - 128) + YUV_HALF) >> YUV_FIX;
54   }
55   for (i = YUV_RANGE_MIN; i < YUV_RANGE_MAX; ++i) {
56     const int k = i;
57     VP8kClip[i - YUV_RANGE_MIN] = clip(k, 255);
58     VP8kClip4Bits[i - YUV_RANGE_MIN] = clip((k + 8) >> 4, 15);
59   }
60 #endif
61 
62   done = 1;
63 }
64 
65 #if defined(__cplusplus) || defined(c_plusplus)
66 }    // extern "C"
67 #endif
68