Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/simd/convert_yuv_to_rgb.h" | 5 #include "media/base/simd/convert_yuv_to_rgb.h" |
| 6 #include "media/base/simd/yuv_to_rgb_table.h" | 6 #include "media/base/simd/yuv_to_rgb_table.h" |
| 7 | 7 |
| 8 #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x))) | 8 #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x))) |
| 9 #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \ | 9 #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \ |
| 10 (((x) + (y)) > 32767 ? 32767 : ((x) + (y)))) | 10 (((x) + (y)) > 32767 ? 32767 : ((x) + (y)))) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 g >>= 6; | 32 g >>= 6; |
| 33 r >>= 6; | 33 r >>= 6; |
| 34 a >>= 6; | 34 a >>= 6; |
| 35 | 35 |
| 36 *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b)) | | 36 *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b)) | |
| 37 (packuswb(g) << 8) | | 37 (packuswb(g) << 8) | |
| 38 (packuswb(r) << 16) | | 38 (packuswb(r) << 16) | |
| 39 (packuswb(a) << 24); | 39 (packuswb(a) << 24); |
| 40 } | 40 } |
| 41 | 41 |
| 42 static inline void ConvertYUVAToARGB_C(uint8 y, | |
| 43 uint8 u, | |
| 44 uint8 v, | |
| 45 uint8 a, | |
| 46 uint8* rgb_buf) { | |
| 47 int b = kCoefficientsRgbY[256+u][0]; | |
| 48 int g = kCoefficientsRgbY[256+u][1]; | |
| 49 int r = kCoefficientsRgbY[256+u][2]; | |
| 50 | |
| 51 b = paddsw(b, kCoefficientsRgbY[512+v][0]); | |
| 52 g = paddsw(g, kCoefficientsRgbY[512+v][1]); | |
| 53 r = paddsw(r, kCoefficientsRgbY[512+v][2]); | |
| 54 | |
| 55 b = paddsw(b, kCoefficientsRgbY[y][0]); | |
| 56 g = paddsw(g, kCoefficientsRgbY[y][1]); | |
| 57 r = paddsw(r, kCoefficientsRgbY[y][2]); | |
| 58 | |
| 59 b >>= 6; | |
| 60 g >>= 6; | |
| 61 r >>= 6; | |
| 62 | |
| 63 b = packuswb(b) * a >> 8; | |
| 64 g = packuswb(g) * a >> 8; | |
| 65 r = packuswb(r) * a >> 8; | |
| 66 | |
| 67 *reinterpret_cast<uint32*>(rgb_buf) = b | (g << 8) | (r << 16) | (a << 24); | |
| 68 } | |
| 69 | |
| 70 // 16.16 fixed point arithmetic | |
| 71 const int kFractionBits = 16; | |
| 72 const int kFractionMax = 1 << kFractionBits; | |
| 73 const int kFractionMask = ((1 << kFractionBits) - 1); | |
|
Tom Finegan
2013/02/25 22:56:06
Where are these used?
vignesh
2013/02/25 23:33:14
they aren't used. some experimental code that stuc
| |
| 74 | |
| 42 extern "C" { | 75 extern "C" { |
| 43 | 76 |
| 44 void ConvertYUVToRGB32Row_C(const uint8* y_buf, | 77 void ConvertYUVToRGB32Row_C(const uint8* y_buf, |
| 45 const uint8* u_buf, | 78 const uint8* u_buf, |
| 46 const uint8* v_buf, | 79 const uint8* v_buf, |
| 47 uint8* rgb_buf, | 80 uint8* rgb_buf, |
| 48 int width) { | 81 int width) { |
| 49 for (int x = 0; x < width; x += 2) { | 82 for (int x = 0; x < width; x += 2) { |
| 50 uint8 u = u_buf[x >> 1]; | 83 uint8 u = u_buf[x >> 1]; |
| 51 uint8 v = v_buf[x >> 1]; | 84 uint8 v = v_buf[x >> 1]; |
| 52 uint8 y0 = y_buf[x]; | 85 uint8 y0 = y_buf[x]; |
| 53 ConvertYUVToRGB32_C(y0, u, v, rgb_buf); | 86 ConvertYUVToRGB32_C(y0, u, v, rgb_buf); |
| 54 if ((x + 1) < width) { | 87 if ((x + 1) < width) { |
| 55 uint8 y1 = y_buf[x + 1]; | 88 uint8 y1 = y_buf[x + 1]; |
| 56 ConvertYUVToRGB32_C(y1, u, v, rgb_buf + 4); | 89 ConvertYUVToRGB32_C(y1, u, v, rgb_buf + 4); |
| 57 } | 90 } |
| 58 rgb_buf += 8; // Advance 2 pixels. | 91 rgb_buf += 8; // Advance 2 pixels. |
| 59 } | 92 } |
| 60 } | 93 } |
| 61 | 94 |
| 95 void ConvertYUVAToARGBRow_C(const uint8* y_buf, | |
| 96 const uint8* u_buf, | |
| 97 const uint8* v_buf, | |
| 98 const uint8* a_buf, | |
| 99 uint8* rgba_buf, | |
| 100 int width) { | |
| 101 for (int x = 0; x < width; x += 2) { | |
| 102 uint8 u = u_buf[x >> 1]; | |
| 103 uint8 v = v_buf[x >> 1]; | |
| 104 uint8 y0 = y_buf[x]; | |
| 105 uint8 a0 = a_buf[x]; | |
| 106 ConvertYUVAToARGB_C(y0, u, v, a0, rgba_buf); | |
| 107 if ((x + 1) < width) { | |
| 108 uint8 y1 = y_buf[x + 1]; | |
| 109 uint8 a1 = a_buf[x + 1]; | |
| 110 ConvertYUVAToARGB_C(y1, u, v, a1, rgba_buf + 4); | |
| 111 } | |
| 112 rgba_buf += 8; // Advance 2 pixels. | |
| 113 } | |
| 114 } | |
| 115 | |
| 62 // 16.16 fixed point is used. A shift by 16 isolates the integer. | 116 // 16.16 fixed point is used. A shift by 16 isolates the integer. |
| 63 // A shift by 17 is used to further subsample the chrominence channels. | 117 // A shift by 17 is used to further subsample the chrominence channels. |
| 64 // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits, | 118 // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits, |
| 65 // for 1/65536 pixel accurate interpolation. | 119 // for 1/65536 pixel accurate interpolation. |
| 66 void ScaleYUVToRGB32Row_C(const uint8* y_buf, | 120 void ScaleYUVToRGB32Row_C(const uint8* y_buf, |
| 67 const uint8* u_buf, | 121 const uint8* u_buf, |
| 68 const uint8* v_buf, | 122 const uint8* v_buf, |
| 69 uint8* rgb_buf, | 123 uint8* rgb_buf, |
| 70 int width, | 124 int width, |
| 71 int source_dx) { | 125 int source_dx) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 const uint8* v_ptr = vplane + (y >> y_shift) * uvstride; | 208 const uint8* v_ptr = vplane + (y >> y_shift) * uvstride; |
| 155 | 209 |
| 156 ConvertYUVToRGB32Row_C(y_ptr, | 210 ConvertYUVToRGB32Row_C(y_ptr, |
| 157 u_ptr, | 211 u_ptr, |
| 158 v_ptr, | 212 v_ptr, |
| 159 rgb_row, | 213 rgb_row, |
| 160 width); | 214 width); |
| 161 } | 215 } |
| 162 } | 216 } |
| 163 | 217 |
| 218 void ConvertYUVAToARGB_C(const uint8* yplane, | |
| 219 const uint8* uplane, | |
| 220 const uint8* vplane, | |
| 221 const uint8* aplane, | |
| 222 uint8* rgbaframe, | |
| 223 int width, | |
| 224 int height, | |
| 225 int ystride, | |
| 226 int uvstride, | |
| 227 int astride, | |
| 228 int rgbastride, | |
| 229 YUVType yuv_type) { | |
| 230 unsigned int y_shift = yuv_type; | |
| 231 for (int y = 0; y < height; y++) { | |
| 232 uint8* rgba_row = rgbaframe + y * rgbastride; | |
| 233 const uint8* y_ptr = yplane + y * ystride; | |
| 234 const uint8* u_ptr = uplane + (y >> y_shift) * uvstride; | |
| 235 const uint8* v_ptr = vplane + (y >> y_shift) * uvstride; | |
| 236 const uint8* a_ptr = aplane + y * astride; | |
| 237 | |
| 238 ConvertYUVAToARGBRow_C(y_ptr, | |
| 239 u_ptr, | |
| 240 v_ptr, | |
| 241 a_ptr, | |
| 242 rgba_row, | |
| 243 width); | |
| 244 } | |
| 245 } | |
| 246 | |
| 164 } // namespace media | 247 } // namespace media |
| OLD | NEW |