1// 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// inline YUV->RGB conversion function 9// 10// Author: Skal (pascal.massimino@gmail.com) 11 12#ifndef WEBP_DEC_YUV_H_ 13#define WEBP_DEC_YUV_H_ 14 15#include "webp/decode_vp8.h" 16 17#if defined(__cplusplus) || defined(c_plusplus) 18extern "C" { 19#endif 20 21enum { YUV_FIX = 16, // fixed-point precision 22 YUV_RANGE_MIN = -227, // min value of r/g/b output 23 YUV_RANGE_MAX = 256 + 226 // max value of r/g/b output 24}; 25extern int16_t VP8kVToR[256], VP8kUToB[256]; 26extern int32_t VP8kVToG[256], VP8kUToG[256]; 27extern uint8_t VP8kClip[YUV_RANGE_MAX - YUV_RANGE_MIN]; 28 29inline static void VP8YuvToRgb(uint8_t y, uint8_t u, uint8_t v, 30 uint8_t* const rgb) { 31 const int r_off = VP8kVToR[v]; 32 const int g_off = (VP8kVToG[v] + VP8kUToG[u]) >> YUV_FIX; 33 const int b_off = VP8kUToB[u]; 34 rgb[0] = VP8kClip[y + r_off - YUV_RANGE_MIN]; 35 rgb[1] = VP8kClip[y + g_off - YUV_RANGE_MIN]; 36 rgb[2] = VP8kClip[y + b_off - YUV_RANGE_MIN]; 37} 38 39inline static void VP8YuvToRgba(int y, int u, int v, uint8_t* const rgba) { 40 VP8YuvToRgb(y, u, v, rgba); 41 rgba[3] = 0xff; 42} 43 44inline static void VP8YuvToBgr(uint8_t y, uint8_t u, uint8_t v, 45 uint8_t* const bgr) { 46 const int r_off = VP8kVToR[v]; 47 const int g_off = (VP8kVToG[v] + VP8kUToG[u]) >> YUV_FIX; 48 const int b_off = VP8kUToB[u]; 49 bgr[0] = VP8kClip[y + b_off - YUV_RANGE_MIN]; 50 bgr[1] = VP8kClip[y + g_off - YUV_RANGE_MIN]; 51 bgr[2] = VP8kClip[y + r_off - YUV_RANGE_MIN]; 52} 53 54inline static void VP8YuvToBgra(int y, int u, int v, uint8_t* const bgra) { 55 VP8YuvToBgr(y, u, v, bgra); 56 bgra[3] = 0xff; 57} 58 59// Must be called before everything, to initialize the tables. 60void VP8YUVInit(); 61 62#if defined(__cplusplus) || defined(c_plusplus) 63} // extern "C" 64#endif 65 66#endif // WEBP_DEC_YUV_H_ 67