yuv.h revision 03d5e34c70f174c16282b0efdc6bb9473df5f8f1
19aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Copyright 2010 Google Inc.
29aea642eefa7a641ab8b89d953251939221d2719Eric Hassold//
39aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// This code is licensed under the same terms as WebM:
49aea642eefa7a641ab8b89d953251939221d2719Eric Hassold//  Software License Agreement:  http://www.webmproject.org/license/software/
59aea642eefa7a641ab8b89d953251939221d2719Eric Hassold//  Additional IP Rights Grant:  http://www.webmproject.org/license/additional/
69aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// -----------------------------------------------------------------------------
79aea642eefa7a641ab8b89d953251939221d2719Eric Hassold//
89aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// inline YUV->RGB conversion function
99aea642eefa7a641ab8b89d953251939221d2719Eric Hassold//
109aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Author: Skal (pascal.massimino@gmail.com)
119aea642eefa7a641ab8b89d953251939221d2719Eric Hassold
1203d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora#ifndef WEBP_DEC_YUV_H_
1303d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora#define WEBP_DEC_YUV_H_
149aea642eefa7a641ab8b89d953251939221d2719Eric Hassold
159aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#include "webp/decode_vp8.h"
169aea642eefa7a641ab8b89d953251939221d2719Eric Hassold
179aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#if defined(__cplusplus) || defined(c_plusplus)
189aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldextern "C" {
199aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#endif
209aea642eefa7a641ab8b89d953251939221d2719Eric Hassold
219aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldenum { YUV_FIX = 16,                // fixed-point precision
229aea642eefa7a641ab8b89d953251939221d2719Eric Hassold       YUV_RANGE_MIN = -227,        // min value of r/g/b output
239aea642eefa7a641ab8b89d953251939221d2719Eric Hassold       YUV_RANGE_MAX = 256 + 226    // max value of r/g/b output
249aea642eefa7a641ab8b89d953251939221d2719Eric Hassold};
259aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldextern int16_t VP8kVToR[256], VP8kUToB[256];
269aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldextern int32_t VP8kVToG[256], VP8kUToG[256];
279aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldextern uint8_t VP8kClip[YUV_RANGE_MAX - YUV_RANGE_MIN];
289aea642eefa7a641ab8b89d953251939221d2719Eric Hassold
299aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldinline static void VP8YuvToRgb(uint8_t y, uint8_t u, uint8_t v,
309aea642eefa7a641ab8b89d953251939221d2719Eric Hassold                               uint8_t* const rgb) {
319aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  const int r_off = VP8kVToR[v];
329aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  const int g_off = (VP8kVToG[v] + VP8kUToG[u]) >> YUV_FIX;
339aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  const int b_off = VP8kUToB[u];
349aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  rgb[0] = VP8kClip[y + r_off - YUV_RANGE_MIN];
359aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  rgb[1] = VP8kClip[y + g_off - YUV_RANGE_MIN];
369aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  rgb[2] = VP8kClip[y + b_off - YUV_RANGE_MIN];
379aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}
389aea642eefa7a641ab8b89d953251939221d2719Eric Hassold
399aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldinline static void VP8YuvToRgba(int y, int u, int v, uint8_t* const rgba) {
409aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  VP8YuvToRgb(y, u, v, rgba);
419aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  rgba[3] = 0xff;
429aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}
439aea642eefa7a641ab8b89d953251939221d2719Eric Hassold
449aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldinline static void VP8YuvToBgr(uint8_t y, uint8_t u, uint8_t v,
459aea642eefa7a641ab8b89d953251939221d2719Eric Hassold                               uint8_t* const bgr) {
469aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  const int r_off = VP8kVToR[v];
479aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  const int g_off = (VP8kVToG[v] + VP8kUToG[u]) >> YUV_FIX;
489aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  const int b_off = VP8kUToB[u];
499aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  bgr[0] = VP8kClip[y + b_off - YUV_RANGE_MIN];
509aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  bgr[1] = VP8kClip[y + g_off - YUV_RANGE_MIN];
519aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  bgr[2] = VP8kClip[y + r_off - YUV_RANGE_MIN];
529aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}
539aea642eefa7a641ab8b89d953251939221d2719Eric Hassold
549aea642eefa7a641ab8b89d953251939221d2719Eric Hassoldinline static void VP8YuvToBgra(int y, int u, int v, uint8_t* const bgra) {
559aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  VP8YuvToBgr(y, u, v, bgra);
569aea642eefa7a641ab8b89d953251939221d2719Eric Hassold  bgra[3] = 0xff;
579aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}
589aea642eefa7a641ab8b89d953251939221d2719Eric Hassold
599aea642eefa7a641ab8b89d953251939221d2719Eric Hassold// Must be called before everything, to initialize the tables.
6003d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Aroravoid VP8YUVInit(void);
619aea642eefa7a641ab8b89d953251939221d2719Eric Hassold
629aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#if defined(__cplusplus) || defined(c_plusplus)
639aea642eefa7a641ab8b89d953251939221d2719Eric Hassold}    // extern "C"
649aea642eefa7a641ab8b89d953251939221d2719Eric Hassold#endif
659aea642eefa7a641ab8b89d953251939221d2719Eric Hassold
6603d5e34c70f174c16282b0efdc6bb9473df5f8f1Vikas Arora#endif  // WEBP_DEC_YUV_H_
67