| 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 27 matching lines...) Expand all Loading... |
| 38 (packuswb(r) << 16) | | 38 (packuswb(r) << 16) | |
| 39 (packuswb(a) << 24); | 39 (packuswb(a) << 24); |
| 40 } | 40 } |
| 41 | 41 |
| 42 extern "C" { | 42 extern "C" { |
| 43 | 43 |
| 44 void ConvertYUVToRGB32Row_C(const uint8* y_buf, | 44 void ConvertYUVToRGB32Row_C(const uint8* y_buf, |
| 45 const uint8* u_buf, | 45 const uint8* u_buf, |
| 46 const uint8* v_buf, | 46 const uint8* v_buf, |
| 47 uint8* rgb_buf, | 47 uint8* rgb_buf, |
| 48 int width) { | 48 ptrdiff_t width) { |
| 49 for (int x = 0; x < width; x += 2) { | 49 for (int x = 0; x < width; x += 2) { |
| 50 uint8 u = u_buf[x >> 1]; | 50 uint8 u = u_buf[x >> 1]; |
| 51 uint8 v = v_buf[x >> 1]; | 51 uint8 v = v_buf[x >> 1]; |
| 52 uint8 y0 = y_buf[x]; | 52 uint8 y0 = y_buf[x]; |
| 53 ConvertYUVToRGB32_C(y0, u, v, rgb_buf); | 53 ConvertYUVToRGB32_C(y0, u, v, rgb_buf); |
| 54 if ((x + 1) < width) { | 54 if ((x + 1) < width) { |
| 55 uint8 y1 = y_buf[x + 1]; | 55 uint8 y1 = y_buf[x + 1]; |
| 56 ConvertYUVToRGB32_C(y1, u, v, rgb_buf + 4); | 56 ConvertYUVToRGB32_C(y1, u, v, rgb_buf + 4); |
| 57 } | 57 } |
| 58 rgb_buf += 8; // Advance 2 pixels. | 58 rgb_buf += 8; // Advance 2 pixels. |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 // 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. |
| 63 // 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. |
| 64 // & 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, |
| 65 // for 1/65536 pixel accurate interpolation. | 65 // for 1/65536 pixel accurate interpolation. |
| 66 void ScaleYUVToRGB32Row_C(const uint8* y_buf, | 66 void ScaleYUVToRGB32Row_C(const uint8* y_buf, |
| 67 const uint8* u_buf, | 67 const uint8* u_buf, |
| 68 const uint8* v_buf, | 68 const uint8* v_buf, |
| 69 uint8* rgb_buf, | 69 uint8* rgb_buf, |
| 70 int width, | 70 ptrdiff_t width, |
| 71 int source_dx) { | 71 ptrdiff_t source_dx) { |
| 72 int x = 0; | 72 int x = 0; |
| 73 for (int i = 0; i < width; i += 2) { | 73 for (int i = 0; i < width; i += 2) { |
| 74 int y = y_buf[x >> 16]; | 74 int y = y_buf[x >> 16]; |
| 75 int u = u_buf[(x >> 17)]; | 75 int u = u_buf[(x >> 17)]; |
| 76 int v = v_buf[(x >> 17)]; | 76 int v = v_buf[(x >> 17)]; |
| 77 ConvertYUVToRGB32_C(y, u, v, rgb_buf); | 77 ConvertYUVToRGB32_C(y, u, v, rgb_buf); |
| 78 x += source_dx; | 78 x += source_dx; |
| 79 if ((i + 1) < width) { | 79 if ((i + 1) < width) { |
| 80 y = y_buf[x >> 16]; | 80 y = y_buf[x >> 16]; |
| 81 ConvertYUVToRGB32_C(y, u, v, rgb_buf+4); | 81 ConvertYUVToRGB32_C(y, u, v, rgb_buf+4); |
| 82 x += source_dx; | 82 x += source_dx; |
| 83 } | 83 } |
| 84 rgb_buf += 8; | 84 rgb_buf += 8; |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 void LinearScaleYUVToRGB32Row_C(const uint8* y_buf, | 88 void LinearScaleYUVToRGB32Row_C(const uint8* y_buf, |
| 89 const uint8* u_buf, | 89 const uint8* u_buf, |
| 90 const uint8* v_buf, | 90 const uint8* v_buf, |
| 91 uint8* rgb_buf, | 91 uint8* rgb_buf, |
| 92 int width, | 92 ptrdiff_t width, |
| 93 int source_dx) { | 93 ptrdiff_t source_dx) { |
| 94 // Avoid point-sampling for down-scaling by > 2:1. | 94 // Avoid point-sampling for down-scaling by > 2:1. |
| 95 int source_x = 0; | 95 int source_x = 0; |
| 96 if (source_dx >= 0x20000) | 96 if (source_dx >= 0x20000) |
| 97 source_x += 0x8000; | 97 source_x += 0x8000; |
| 98 LinearScaleYUVToRGB32RowWithRange_C(y_buf, u_buf, v_buf, rgb_buf, width, | 98 LinearScaleYUVToRGB32RowWithRange_C(y_buf, u_buf, v_buf, rgb_buf, width, |
| 99 source_x, source_dx); | 99 source_x, source_dx); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void LinearScaleYUVToRGB32RowWithRange_C(const uint8* y_buf, | 102 void LinearScaleYUVToRGB32RowWithRange_C(const uint8* y_buf, |
| 103 const uint8* u_buf, | 103 const uint8* u_buf, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 ConvertYUVToRGB32Row_C(y_ptr, | 156 ConvertYUVToRGB32Row_C(y_ptr, |
| 157 u_ptr, | 157 u_ptr, |
| 158 v_ptr, | 158 v_ptr, |
| 159 rgb_row, | 159 rgb_row, |
| 160 width); | 160 width); |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace media | 164 } // namespace media |
| OLD | NEW |