Home | History | Annotate | Download | only in dsp
      1 // Copyright 2010 Google Inc. All Rights Reserved.
      2 //
      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 // -----------------------------------------------------------------------------
      9 //
     10 // YUV->RGB conversion function
     11 //
     12 // Author: Skal (pascal.massimino (at) gmail.com)
     13 
     14 #include "./yuv.h"
     15 
     16 #if defined(__cplusplus) || defined(c_plusplus)
     17 extern "C" {
     18 #endif
     19 
     20 #ifdef WEBP_YUV_USE_TABLE
     21 
     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];
     26 
     27 static int done = 0;
     28 
     29 static WEBP_INLINE uint8_t clip(int v, int max_value) {
     30   return v < 0 ? 0 : v > max_value ? max_value : v;
     31 }
     32 
     33 void VP8YUVInit(void) {
     34   int i;
     35   if (done) {
     36     return;
     37   }
     38 #ifndef USE_YUVj
     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;
     44   }
     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);
     49   }
     50 #else
     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;
     56   }
     57   for (i = YUV_RANGE_MIN; i < YUV_RANGE_MAX; ++i) {
     58     const int k = i;
     59     VP8kClip[i - YUV_RANGE_MIN] = clip(k, 255);
     60     VP8kClip4Bits[i - YUV_RANGE_MIN] = clip((k + 8) >> 4, 15);
     61   }
     62 #endif
     63 
     64   done = 1;
     65 }
     66 
     67 #else
     68 
     69 void VP8YUVInit(void) {}
     70 
     71 #endif  // WEBP_YUV_USE_TABLE
     72 
     73 #if defined(__cplusplus) || defined(c_plusplus)
     74 }    // extern "C"
     75 #endif
     76