OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 #define VR -102 /* round(-1.596 * 64) */ | 1011 #define VR -102 /* round(-1.596 * 64) */ |
1012 | 1012 |
1013 // Bias values to subtract 16 from Y and 128 from U and V. | 1013 // Bias values to subtract 16 from Y and 128 from U and V. |
1014 #define BB (UB * 128 + YGB) | 1014 #define BB (UB * 128 + YGB) |
1015 #define BG (UG * 128 + VG * 128 + YGB) | 1015 #define BG (UG * 128 + VG * 128 + YGB) |
1016 #define BR (VR * 128 + YGB) | 1016 #define BR (VR * 128 + YGB) |
1017 | 1017 |
1018 // BT.601 constants for YUV to RGB. | 1018 // BT.601 constants for YUV to RGB. |
1019 // TODO(fbarchard): Unify these structures to be platform independent. | 1019 // TODO(fbarchard): Unify these structures to be platform independent. |
1020 // TODO(fbarchard): Generate SIMD structures from float matrix. | 1020 // TODO(fbarchard): Generate SIMD structures from float matrix. |
1021 | |
1022 // BT601 constants for YUV to RGB. | |
1023 #if defined(__aarch64__) | 1021 #if defined(__aarch64__) |
1024 const YuvConstants SIMD_ALIGNED(kYuvIConstants) = { | 1022 const YuvConstants SIMD_ALIGNED(kYuvIConstants) = { |
1025 { -UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR }, | 1023 { -UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR }, |
1026 { -UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR }, | 1024 { -UB, -VR, -UB, -VR, -UB, -VR, -UB, -VR }, |
1027 { UG, VG, UG, VG, UG, VG, UG, VG }, | 1025 { UG, VG, UG, VG, UG, VG, UG, VG }, |
1028 { UG, VG, UG, VG, UG, VG, UG, VG }, | 1026 { UG, VG, UG, VG, UG, VG, UG, VG }, |
1029 { BB, BG, BR, 0, 0, 0, 0, 0 }, | 1027 { BB, BG, BR, 0, 0, 0, 0, 0 }, |
1030 { 0x0101 * YG, 0, 0, 0 } | 1028 { 0x0101 * YG, 0, 0, 0 } |
1031 }; | 1029 }; |
1032 | |
1033 #elif defined(__arm__) | 1030 #elif defined(__arm__) |
1034 const YuvConstants SIMD_ALIGNED(kYuvIConstants) = { | 1031 const YuvConstants SIMD_ALIGNED(kYuvIConstants) = { |
1035 { -UB, -UB, -UB, -UB, -VR, -VR, -VR, -VR, 0, 0, 0, 0, 0, 0, 0, 0 }, | 1032 { -UB, -UB, -UB, -UB, -VR, -VR, -VR, -VR, 0, 0, 0, 0, 0, 0, 0, 0 }, |
1036 { UG, UG, UG, UG, VG, VG, VG, VG, 0, 0, 0, 0, 0, 0, 0, 0 }, | 1033 { UG, UG, UG, UG, VG, VG, VG, VG, 0, 0, 0, 0, 0, 0, 0, 0 }, |
1037 { BB, BG, BR, 0, 0, 0, 0, 0 }, | 1034 { BB, BG, BR, 0, 0, 0, 0, 0 }, |
1038 { 0x0101 * YG, 0, 0, 0 } | 1035 { 0x0101 * YG, 0, 0, 0 } |
1039 }; | 1036 }; |
1040 #else | 1037 #else |
1041 const YuvConstants SIMD_ALIGNED(kYuvIConstants) = { | 1038 const YuvConstants SIMD_ALIGNED(kYuvIConstants) = { |
1042 { UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, | 1039 { UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 } | 1089 } |
1093 | 1090 |
1094 // C reference code that mimics the YUV assembly. | 1091 // C reference code that mimics the YUV assembly. |
1095 static __inline void YPixel(uint8 y, uint8* b, uint8* g, uint8* r) { | 1092 static __inline void YPixel(uint8 y, uint8* b, uint8* g, uint8* r) { |
1096 uint32 y1 = (uint32)(y * 0x0101 * YG) >> 16; | 1093 uint32 y1 = (uint32)(y * 0x0101 * YG) >> 16; |
1097 *b = Clamp((int32)(y1 + YGB) >> 6); | 1094 *b = Clamp((int32)(y1 + YGB) >> 6); |
1098 *g = Clamp((int32)(y1 + YGB) >> 6); | 1095 *g = Clamp((int32)(y1 + YGB) >> 6); |
1099 *r = Clamp((int32)(y1 + YGB) >> 6); | 1096 *r = Clamp((int32)(y1 + YGB) >> 6); |
1100 } | 1097 } |
1101 | 1098 |
| 1099 // BT.601 constants for YVU to BGR. |
| 1100 // Allows YUV TO RGB code to implement YUV to BGR by swapping UV and using this |
| 1101 // matrix. |
| 1102 |
| 1103 #if defined(__aarch64__) |
| 1104 const YuvConstants SIMD_ALIGNED(kYvuIConstants) = { |
| 1105 { -VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB }, |
| 1106 { -VR, -UB, -VR, -UB, -VR, -UB, -VR, -UB }, |
| 1107 { VG, UG, VG, UG, VG, UG, VG, UG }, |
| 1108 { VG, UG, VG, UG, VG, UG, VG, UG }, |
| 1109 { BR, BG, BB, 0, 0, 0, 0, 0 }, |
| 1110 { 0x0101 * YG, 0, 0, 0 } |
| 1111 }; |
| 1112 |
| 1113 #elif defined(__arm__) |
| 1114 const YuvConstants SIMD_ALIGNED(kYvuIConstants) = { |
| 1115 { -VR, -VR, -VR, -VR, -UB, -UB, -UB, -UB, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1116 { VG, VG, VG, VG, UG, UG, UG, UG, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1117 { BR, BG, BB, 0, 0, 0, 0, 0 }, |
| 1118 { 0x0101 * YG, 0, 0, 0 } |
| 1119 }; |
| 1120 #else |
| 1121 const YuvConstants SIMD_ALIGNED(kYvuIConstants) = { |
| 1122 { VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, |
| 1123 VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, UB, 0 }, |
| 1124 { VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, |
| 1125 VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG }, |
| 1126 { 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, |
| 1127 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, VR }, |
| 1128 { BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR }, |
| 1129 { BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG }, |
| 1130 { BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB }, |
| 1131 { YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG } |
| 1132 }; |
| 1133 #endif |
| 1134 |
1102 #undef BB | 1135 #undef BB |
1103 #undef BG | 1136 #undef BG |
1104 #undef BR | 1137 #undef BR |
1105 #undef YGB | 1138 #undef YGB |
1106 #undef UB | 1139 #undef UB |
1107 #undef UG | 1140 #undef UG |
1108 #undef VG | 1141 #undef VG |
1109 #undef VR | 1142 #undef VR |
1110 #undef YG | 1143 #undef YG |
1111 | 1144 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 src_u += 2; | 1305 src_u += 2; |
1273 src_v += 2; | 1306 src_v += 2; |
1274 rgb_buf += 8; // Advance 2 pixels. | 1307 rgb_buf += 8; // Advance 2 pixels. |
1275 } | 1308 } |
1276 if (width & 1) { | 1309 if (width & 1) { |
1277 YuvPixel(src_y[0], src_u[0], src_v[0], | 1310 YuvPixel(src_y[0], src_u[0], src_v[0], |
1278 rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); | 1311 rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
1279 rgb_buf[3] = 255; | 1312 rgb_buf[3] = 255; |
1280 } | 1313 } |
1281 } | 1314 } |
1282 | |
1283 void I444ToABGRRow_C(const uint8* src_y, | |
1284 const uint8* src_u, | |
1285 const uint8* src_v, | |
1286 uint8* rgb_buf, | |
1287 const struct YuvConstants* yuvconstants, | |
1288 int width) { | |
1289 int x; | |
1290 for (x = 0; x < width - 1; x += 2) { | |
1291 uint8 u = (src_u[0] + src_u[1] + 1) >> 1; | |
1292 uint8 v = (src_v[0] + src_v[1] + 1) >> 1; | |
1293 YuvPixel(src_y[0], u, v, rgb_buf + 2, rgb_buf + 1, rgb_buf + 0, | |
1294 yuvconstants); | |
1295 rgb_buf[3] = 255; | |
1296 YuvPixel(src_y[1], u, v, rgb_buf + 6, rgb_buf + 5, rgb_buf + 4, | |
1297 yuvconstants); | |
1298 rgb_buf[7] = 255; | |
1299 src_y += 2; | |
1300 src_u += 2; | |
1301 src_v += 2; | |
1302 rgb_buf += 8; // Advance 2 pixels. | |
1303 } | |
1304 if (width & 1) { | |
1305 YuvPixel(src_y[0], src_u[0], src_v[0], | |
1306 rgb_buf + 2, rgb_buf + 1, rgb_buf + 0, yuvconstants); | |
1307 rgb_buf[3] = 255; | |
1308 } | |
1309 } | |
1310 #else | 1315 #else |
1311 void I444ToARGBRow_C(const uint8* src_y, | 1316 void I444ToARGBRow_C(const uint8* src_y, |
1312 const uint8* src_u, | 1317 const uint8* src_u, |
1313 const uint8* src_v, | 1318 const uint8* src_v, |
1314 uint8* rgb_buf, | 1319 uint8* rgb_buf, |
1315 const struct YuvConstants* yuvconstants, | 1320 const struct YuvConstants* yuvconstants, |
1316 int width) { | 1321 int width) { |
1317 int x; | 1322 int x; |
1318 for (x = 0; x < width; ++x) { | 1323 for (x = 0; x < width; ++x) { |
1319 YuvPixel(src_y[0], src_u[0], src_v[0], | 1324 YuvPixel(src_y[0], src_u[0], src_v[0], |
1320 rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); | 1325 rgb_buf + 0, rgb_buf + 1, rgb_buf + 2, yuvconstants); |
1321 rgb_buf[3] = 255; | 1326 rgb_buf[3] = 255; |
1322 src_y += 1; | 1327 src_y += 1; |
1323 src_u += 1; | 1328 src_u += 1; |
1324 src_v += 1; | 1329 src_v += 1; |
1325 rgb_buf += 4; // Advance 1 pixel. | 1330 rgb_buf += 4; // Advance 1 pixel. |
1326 } | 1331 } |
1327 } | 1332 } |
1328 | |
1329 void I444ToABGRRow_C(const uint8* src_y, | |
1330 const uint8* src_u, | |
1331 const uint8* src_v, | |
1332 uint8* rgb_buf, | |
1333 const struct YuvConstants* yuvconstants, | |
1334 int width) { | |
1335 int x; | |
1336 for (x = 0; x < width; ++x) { | |
1337 YuvPixel(src_y[0], src_u[0], src_v[0], | |
1338 rgb_buf + 2, rgb_buf + 1, rgb_buf + 0, yuvconstants); | |
1339 rgb_buf[3] = 255; | |
1340 src_y += 1; | |
1341 src_u += 1; | |
1342 src_v += 1; | |
1343 rgb_buf += 4; // Advance 1 pixel. | |
1344 } | |
1345 } | |
1346 #endif | 1333 #endif |
1347 | 1334 |
1348 // Also used for 420 | 1335 // Also used for 420 |
1349 void I422ToARGBRow_C(const uint8* src_y, | 1336 void I422ToARGBRow_C(const uint8* src_y, |
1350 const uint8* src_u, | 1337 const uint8* src_u, |
1351 const uint8* src_v, | 1338 const uint8* src_v, |
1352 uint8* rgb_buf, | 1339 uint8* rgb_buf, |
1353 const struct YuvConstants* yuvconstants, | 1340 const struct YuvConstants* yuvconstants, |
1354 int width) { | 1341 int width) { |
1355 int x; | 1342 int x; |
(...skipping 1347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2703 dst_rgb565 += twidth * 2; | 2690 dst_rgb565 += twidth * 2; |
2704 width -= twidth; | 2691 width -= twidth; |
2705 } | 2692 } |
2706 } | 2693 } |
2707 #endif | 2694 #endif |
2708 | 2695 |
2709 #ifdef __cplusplus | 2696 #ifdef __cplusplus |
2710 } // extern "C" | 2697 } // extern "C" |
2711 } // namespace libyuv | 2698 } // namespace libyuv |
2712 #endif | 2699 #endif |
OLD | NEW |