120 for (
int i = 0; i < 256; i++) {
121 r_2_pix_alloc[i + 256] = i;
122 g_2_pix_alloc[i + 256] = i;
123 b_2_pix_alloc[i + 256] = i;
128 for (
int i = 0; i < 256; i++) {
129 r_2_pix_alloc[i] = r_2_pix_alloc[256];
130 r_2_pix_alloc[i + 512] = r_2_pix_alloc[511];
131 g_2_pix_alloc[i] = g_2_pix_alloc[256];
132 g_2_pix_alloc[i + 512] = g_2_pix_alloc[511];
133 b_2_pix_alloc[i] = b_2_pix_alloc[256];
134 b_2_pix_alloc[i + 512] = b_2_pix_alloc[511];
138 for (
int i = 16; i < 236; i++) {
139 int scaledValue = (i - 16) * 255 / 219;
140 r_2_pix_alloc[i + 256] = scaledValue;
141 g_2_pix_alloc[i + 256] = scaledValue;
142 b_2_pix_alloc[i + 256] = scaledValue;
147 for (
int i = 0; i < 256 + 16; i++) {
148 r_2_pix_alloc[i] = r_2_pix_alloc[256 + 16];
149 g_2_pix_alloc[i] = g_2_pix_alloc[256 + 16];
150 b_2_pix_alloc[i] = b_2_pix_alloc[256 + 16];
153 for (
int i = 256 + 236; i < 768; i++) {
154 r_2_pix_alloc[i] = r_2_pix_alloc[256 + 236 - 1];
155 g_2_pix_alloc[i] = g_2_pix_alloc[256 + 236 - 1];
156 b_2_pix_alloc[i] = b_2_pix_alloc[256 + 236 - 1];
169 for (
int i = 0; i < 256; i++) {
173 int16 CR = (i - 128), CB = CR;
174 Cr_r_tab[i] = (
int16) ( (0.419 / 0.299) * CR) + 0 * 768 + 256;
175 Cr_g_tab[i] = (
int16) (-(0.299 / 0.419) * CR) + 1 * 768 + 256;
176 Cb_g_tab[i] = (
int16) (-(0.114 / 0.331) * CB);
177 Cb_b_tab[i] = (
int16) ( (0.587 / 0.331) * CB) + 2 * 768 + 256;
192 #define PUT_PIXEL(s, a, d) \ 193 L = &rgbToPix[(s)]; \ 195 *((d) + 1) = L[crb_g]; \ 196 *((d) + 2) = L[cr_r]; \ 199 void YUVToRGBManager::convert420(
LuminanceScale scale,
byte *dst,
int dstPitch,
const byte *ySrc,
const byte *uSrc,
const byte *vSrc,
const byte *aSrc,
int yWidth,
int yHeight,
int yPitch,
int uvPitch) {
203 int halfHeight = yHeight >> 1;
204 int halfWidth = yWidth >> 1;
206 dst += dstPitch * (yHeight - 2);
208 for (
int h = 0; h < halfHeight; h++) {
209 for (
int w = 0; w < halfWidth; w++) {
219 PUT_PIXEL(*(ySrc + yPitch), *(aSrc + yPitch), dst);
224 PUT_PIXEL(*(ySrc + yPitch), *(aSrc + yPitch), dst);
230 dst -= yWidth * 4 + dstPitch * 2;
231 ySrc += (yPitch << 1) - yWidth;
232 aSrc += (yPitch << 1) - yWidth;
233 uSrc += uvPitch - halfWidth;
234 vSrc += uvPitch - halfWidth;
242 int halfHeight = yHeight >> 1;
243 int halfWidth = yWidth >> 1;
245 dst += dstPitch * (yHeight - 2);
247 for (
int h = 0; h < halfHeight; h++) {
248 for (
int w = 0; w < halfWidth; w++) {
267 dst -= yWidth * 4 + dstPitch * 2;
268 ySrc += (yPitch << 1) - yWidth;
269 uSrc += uvPitch - halfWidth;
270 vSrc += uvPitch - halfWidth;
Class and macro for implementing singletons.
LuminanceScale
The scale of the luminance values.
void convert420(LuminanceScale scale, byte *dst, int dstPitch, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch)
Convert a YUV420 image to an RGBA surface.
YUVToRGBLookup(YUVToRGBManager::LuminanceScale scale)
YUVToRGBManager::LuminanceScale getScale() const
Basic exceptions to throw.
Utility templates and functions.
#define PUT_PIXEL(s, a, d)
#define DECLARE_SINGLETON(T)
Note that you need to use this macro from the global namespace.
Common::ScopedPtr< YUVToRGBLookup > _lookup
Efficient YUV to RGB conversion.
const YUVToRGBLookup * getLookup(LuminanceScale scale)
YUVToRGBManager::LuminanceScale _scale
const byte * getRGBToPix() const