2010-09-30 09:34:38 -04:00
|
|
|
// Copyright 2010 Google Inc.
|
|
|
|
//
|
|
|
|
// This code is licensed under the same terms as WebM:
|
|
|
|
// Software License Agreement: http://www.webmproject.org/license/software/
|
|
|
|
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// inline YUV->RGB conversion function
|
|
|
|
//
|
|
|
|
// Author: Skal (pascal.massimino@gmail.com)
|
|
|
|
|
2011-09-02 21:30:08 +00:00
|
|
|
#ifndef WEBP_DSP_YUV_H_
|
|
|
|
#define WEBP_DSP_YUV_H_
|
2010-09-30 09:34:38 -04:00
|
|
|
|
2011-05-02 17:19:00 -07:00
|
|
|
#include "../webp/decode_vp8.h"
|
2010-09-30 09:34:38 -04:00
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum { YUV_FIX = 16, // fixed-point precision
|
|
|
|
YUV_RANGE_MIN = -227, // min value of r/g/b output
|
|
|
|
YUV_RANGE_MAX = 256 + 226 // max value of r/g/b output
|
|
|
|
};
|
|
|
|
extern int16_t VP8kVToR[256], VP8kUToB[256];
|
|
|
|
extern int32_t VP8kVToG[256], VP8kUToG[256];
|
|
|
|
extern uint8_t VP8kClip[YUV_RANGE_MAX - YUV_RANGE_MIN];
|
2011-07-13 09:08:58 -07:00
|
|
|
extern uint8_t VP8kClip4Bits[YUV_RANGE_MAX - YUV_RANGE_MIN];
|
2010-09-30 09:34:38 -04:00
|
|
|
|
2011-06-20 00:45:15 -07:00
|
|
|
static inline void VP8YuvToRgb(uint8_t y, uint8_t u, uint8_t v,
|
2010-09-30 09:34:38 -04:00
|
|
|
uint8_t* const rgb) {
|
|
|
|
const int r_off = VP8kVToR[v];
|
|
|
|
const int g_off = (VP8kVToG[v] + VP8kUToG[u]) >> YUV_FIX;
|
|
|
|
const int b_off = VP8kUToB[u];
|
|
|
|
rgb[0] = VP8kClip[y + r_off - YUV_RANGE_MIN];
|
|
|
|
rgb[1] = VP8kClip[y + g_off - YUV_RANGE_MIN];
|
|
|
|
rgb[2] = VP8kClip[y + b_off - YUV_RANGE_MIN];
|
|
|
|
}
|
|
|
|
|
2011-07-13 09:08:58 -07:00
|
|
|
static inline void VP8YuvToRgb565(uint8_t y, uint8_t u, uint8_t v,
|
|
|
|
uint8_t* const rgb) {
|
|
|
|
const int r_off = VP8kVToR[v];
|
|
|
|
const int g_off = (VP8kVToG[v] + VP8kUToG[u]) >> YUV_FIX;
|
|
|
|
const int b_off = VP8kUToB[u];
|
|
|
|
rgb[0] = ((VP8kClip[y + r_off - YUV_RANGE_MIN] & 0xf8) |
|
|
|
|
(VP8kClip[y + g_off - YUV_RANGE_MIN] >> 5));
|
|
|
|
rgb[1] = (((VP8kClip[y + g_off - YUV_RANGE_MIN] << 3) & 0xe0) |
|
|
|
|
(VP8kClip[y + b_off - YUV_RANGE_MIN] >> 3));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void VP8YuvToArgbKeepA(uint8_t y, uint8_t u, uint8_t v,
|
|
|
|
uint8_t* const argb) {
|
|
|
|
// Don't update Aplha (argb[0])
|
|
|
|
VP8YuvToRgb(y, u, v, argb + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void VP8YuvToArgb(uint8_t y, uint8_t u, uint8_t v,
|
|
|
|
uint8_t* const argb) {
|
|
|
|
argb[0] = 0xff;
|
|
|
|
VP8YuvToArgbKeepA(y, u, v, argb);
|
|
|
|
}
|
|
|
|
|
2011-07-14 11:41:23 -07:00
|
|
|
static inline void VP8YuvToRgba4444KeepA(uint8_t y, uint8_t u, uint8_t v,
|
2011-07-13 09:08:58 -07:00
|
|
|
uint8_t* const argb) {
|
|
|
|
const int r_off = VP8kVToR[v];
|
|
|
|
const int g_off = (VP8kVToG[v] + VP8kUToG[u]) >> YUV_FIX;
|
|
|
|
const int b_off = VP8kUToB[u];
|
2011-07-14 11:41:23 -07:00
|
|
|
// Don't update Aplha (last 4 bits of argb[1])
|
|
|
|
argb[0] = ((VP8kClip4Bits[y + r_off - YUV_RANGE_MIN] << 4) |
|
|
|
|
VP8kClip4Bits[y + g_off - YUV_RANGE_MIN]);
|
|
|
|
argb[1] = (argb[1] & 0x0f) | (VP8kClip4Bits[y + b_off - YUV_RANGE_MIN] << 4);
|
2011-07-13 09:08:58 -07:00
|
|
|
}
|
|
|
|
|
2011-07-14 11:41:23 -07:00
|
|
|
static inline void VP8YuvToRgba4444(uint8_t y, uint8_t u, uint8_t v,
|
2011-07-13 09:08:58 -07:00
|
|
|
uint8_t* const argb) {
|
2011-07-14 11:41:23 -07:00
|
|
|
argb[1] = 0x0f;
|
|
|
|
VP8YuvToRgba4444KeepA(y, u, v, argb);
|
2011-07-13 09:08:58 -07:00
|
|
|
}
|
|
|
|
|
2011-06-20 00:45:15 -07:00
|
|
|
static inline void VP8YuvToBgr(uint8_t y, uint8_t u, uint8_t v,
|
2010-09-30 09:34:38 -04:00
|
|
|
uint8_t* const bgr) {
|
|
|
|
const int r_off = VP8kVToR[v];
|
|
|
|
const int g_off = (VP8kVToG[v] + VP8kUToG[u]) >> YUV_FIX;
|
|
|
|
const int b_off = VP8kUToB[u];
|
|
|
|
bgr[0] = VP8kClip[y + b_off - YUV_RANGE_MIN];
|
|
|
|
bgr[1] = VP8kClip[y + g_off - YUV_RANGE_MIN];
|
|
|
|
bgr[2] = VP8kClip[y + r_off - YUV_RANGE_MIN];
|
|
|
|
}
|
|
|
|
|
2011-06-20 00:45:15 -07:00
|
|
|
static inline void VP8YuvToBgra(uint8_t y, uint8_t u, uint8_t v,
|
|
|
|
uint8_t* const bgra) {
|
2010-09-30 09:34:38 -04:00
|
|
|
VP8YuvToBgr(y, u, v, bgra);
|
|
|
|
bgra[3] = 0xff;
|
|
|
|
}
|
|
|
|
|
2011-06-20 00:45:15 -07:00
|
|
|
static inline void VP8YuvToRgba(uint8_t y, uint8_t u, uint8_t v,
|
|
|
|
uint8_t* const rgba) {
|
|
|
|
VP8YuvToRgb(y, u, v, rgba);
|
|
|
|
rgba[3] = 0xff;
|
|
|
|
}
|
|
|
|
|
2010-09-30 09:34:38 -04:00
|
|
|
// Must be called before everything, to initialize the tables.
|
2011-03-25 15:04:11 -07:00
|
|
|
void VP8YUVInit(void);
|
2010-09-30 09:34:38 -04:00
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2011-09-02 21:30:08 +00:00
|
|
|
#endif // WEBP_DSP_YUV_H_
|