| 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 extern "C" { | 42 extern "C" { |
| 71 | 43 |
| 72 void ConvertYUVToRGB32Row_C(const uint8* y_buf, | 44 void ConvertYUVToRGB32Row_C(const uint8* y_buf, |
| 73 const uint8* u_buf, | 45 const uint8* u_buf, |
| 74 const uint8* v_buf, | 46 const uint8* v_buf, |
| 75 uint8* rgb_buf, | 47 uint8* rgb_buf, |
| 76 ptrdiff_t width) { | 48 ptrdiff_t width) { |
| 77 for (int x = 0; x < width; x += 2) { | 49 for (int x = 0; x < width; x += 2) { |
| 78 uint8 u = u_buf[x >> 1]; | 50 uint8 u = u_buf[x >> 1]; |
| 79 uint8 v = v_buf[x >> 1]; | 51 uint8 v = v_buf[x >> 1]; |
| 80 uint8 y0 = y_buf[x]; | 52 uint8 y0 = y_buf[x]; |
| 81 ConvertYUVToRGB32_C(y0, u, v, rgb_buf); | 53 ConvertYUVToRGB32_C(y0, u, v, rgb_buf); |
| 82 if ((x + 1) < width) { | 54 if ((x + 1) < width) { |
| 83 uint8 y1 = y_buf[x + 1]; | 55 uint8 y1 = y_buf[x + 1]; |
| 84 ConvertYUVToRGB32_C(y1, u, v, rgb_buf + 4); | 56 ConvertYUVToRGB32_C(y1, u, v, rgb_buf + 4); |
| 85 } | 57 } |
| 86 rgb_buf += 8; // Advance 2 pixels. | 58 rgb_buf += 8; // Advance 2 pixels. |
| 87 } | 59 } |
| 88 } | 60 } |
| 89 | 61 |
| 90 void ConvertYUVAToARGBRow_C(const uint8* y_buf, | |
| 91 const uint8* u_buf, | |
| 92 const uint8* v_buf, | |
| 93 const uint8* a_buf, | |
| 94 uint8* rgba_buf, | |
| 95 ptrdiff_t width) { | |
| 96 for (int x = 0; x < width; x += 2) { | |
| 97 uint8 u = u_buf[x >> 1]; | |
| 98 uint8 v = v_buf[x >> 1]; | |
| 99 uint8 y0 = y_buf[x]; | |
| 100 uint8 a0 = a_buf[x]; | |
| 101 ConvertYUVAToARGB_C(y0, u, v, a0, rgba_buf); | |
| 102 if ((x + 1) < width) { | |
| 103 uint8 y1 = y_buf[x + 1]; | |
| 104 uint8 a1 = a_buf[x + 1]; | |
| 105 ConvertYUVAToARGB_C(y1, u, v, a1, rgba_buf + 4); | |
| 106 } | |
| 107 rgba_buf += 8; // Advance 2 pixels. | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 // 16.16 fixed point is used. A shift by 16 isolates the integer. | 62 // 16.16 fixed point is used. A shift by 16 isolates the integer. |
| 112 // A shift by 17 is used to further subsample the chrominence channels. | 63 // A shift by 17 is used to further subsample the chrominence channels. |
| 113 // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits, | 64 // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits, |
| 114 // for 1/65536 pixel accurate interpolation. | 65 // for 1/65536 pixel accurate interpolation. |
| 115 void ScaleYUVToRGB32Row_C(const uint8* y_buf, | 66 void ScaleYUVToRGB32Row_C(const uint8* y_buf, |
| 116 const uint8* u_buf, | 67 const uint8* u_buf, |
| 117 const uint8* v_buf, | 68 const uint8* v_buf, |
| 118 uint8* rgb_buf, | 69 uint8* rgb_buf, |
| 119 ptrdiff_t width, | 70 ptrdiff_t width, |
| 120 ptrdiff_t source_dx) { | 71 ptrdiff_t source_dx) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 const uint8* v_ptr = vplane + (y >> y_shift) * uvstride; | 154 const uint8* v_ptr = vplane + (y >> y_shift) * uvstride; |
| 204 | 155 |
| 205 ConvertYUVToRGB32Row_C(y_ptr, | 156 ConvertYUVToRGB32Row_C(y_ptr, |
| 206 u_ptr, | 157 u_ptr, |
| 207 v_ptr, | 158 v_ptr, |
| 208 rgb_row, | 159 rgb_row, |
| 209 width); | 160 width); |
| 210 } | 161 } |
| 211 } | 162 } |
| 212 | 163 |
| 213 void ConvertYUVAToARGB_C(const uint8* yplane, | |
| 214 const uint8* uplane, | |
| 215 const uint8* vplane, | |
| 216 const uint8* aplane, | |
| 217 uint8* rgbaframe, | |
| 218 int width, | |
| 219 int height, | |
| 220 int ystride, | |
| 221 int uvstride, | |
| 222 int astride, | |
| 223 int rgbastride, | |
| 224 YUVType yuv_type) { | |
| 225 unsigned int y_shift = yuv_type; | |
| 226 for (int y = 0; y < height; y++) { | |
| 227 uint8* rgba_row = rgbaframe + y * rgbastride; | |
| 228 const uint8* y_ptr = yplane + y * ystride; | |
| 229 const uint8* u_ptr = uplane + (y >> y_shift) * uvstride; | |
| 230 const uint8* v_ptr = vplane + (y >> y_shift) * uvstride; | |
| 231 const uint8* a_ptr = aplane + y * astride; | |
| 232 | |
| 233 ConvertYUVAToARGBRow_C(y_ptr, | |
| 234 u_ptr, | |
| 235 v_ptr, | |
| 236 a_ptr, | |
| 237 rgba_row, | |
| 238 width); | |
| 239 } | |
| 240 } | |
| 241 | |
| 242 } // namespace media | 164 } // namespace media |
| OLD | NEW |