Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: source/row_common.cc

Issue 1359443005: move constants into common (Closed) Base URL: https://chromium.googlesource.com/libyuv/libyuv@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/libyuv/row.h ('k') | source/row_gcc.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 int x; 987 int x;
988 for (x = 0; x < width; ++x) { 988 for (x = 0; x < width; ++x) {
989 uint8 y = src_y[0]; 989 uint8 y = src_y[0];
990 dst_argb[2] = dst_argb[1] = dst_argb[0] = y; 990 dst_argb[2] = dst_argb[1] = dst_argb[0] = y;
991 dst_argb[3] = 255u; 991 dst_argb[3] = 255u;
992 dst_argb += 4; 992 dst_argb += 4;
993 ++src_y; 993 ++src_y;
994 } 994 }
995 } 995 }
996 996
997
harryjin 2015/09/18 22:48:31 Remove the extra line?
997 // BT.601 YUV to RGB reference 998 // BT.601 YUV to RGB reference
998 // R = (Y - 16) * 1.164 - V * -1.596 999 // R = (Y - 16) * 1.164 - V * -1.596
999 // G = (Y - 16) * 1.164 - U * 0.391 - V * 0.813 1000 // G = (Y - 16) * 1.164 - U * 0.391 - V * 0.813
1000 // B = (Y - 16) * 1.164 - U * -2.018 1001 // B = (Y - 16) * 1.164 - U * -2.018
1001 1002
1002 // Y contribution to R,G,B. Scale and bias. 1003 // Y contribution to R,G,B. Scale and bias.
1003 // TODO(fbarchard): Consider moving constants into a common header. 1004 // TODO(fbarchard): Consider moving constants into a common header.
1004 #define YG 18997 /* round(1.164 * 64 * 256 * 256 / 257) */ 1005 #define YG 18997 /* round(1.164 * 64 * 256 * 256 / 257) */
1005 #define YGB -1160 /* 1.164 * 64 * -16 + 64 / 2 */ 1006 #define YGB -1160 /* 1.164 * 64 * -16 + 64 / 2 */
1006 1007
1007 // U and V contributions to R,G,B. 1008 // U and V contributions to R,G,B.
1008 #define UB -128 /* max(-128, round(-2.018 * 64)) */ 1009 #define UB -128 /* max(-128, round(-2.018 * 64)) */
1009 #define UG 25 /* round(0.391 * 64) */ 1010 #define UG 25 /* round(0.391 * 64) */
1010 #define VG 52 /* round(0.813 * 64) */ 1011 #define VG 52 /* round(0.813 * 64) */
1011 #define VR -102 /* round(-1.596 * 64) */ 1012 #define VR -102 /* round(-1.596 * 64) */
1012 1013
1013 // Bias values to subtract 16 from Y and 128 from U and V, with rounding. 1014 // Bias values to subtract 16 from Y and 128 from U and V.
1014 #define BB (UB * 128 + YGB) 1015 #define BB (UB * 128 + YGB)
1015 #define BG (UG * 128 + VG * 128 + YGB) 1016 #define BG (UG * 128 + VG * 128 + YGB)
1016 #define BR (VR * 128 + YGB) 1017 #define BR (VR * 128 + YGB)
1017 1018
1019 // BT601 constants for YUV to RGB.
1020 YuvConstants SIMD_ALIGNED(kYuvConstants) = {
1021 { UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0,
1022 UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0 },
1023 { UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG,
1024 UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG },
1025 { 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR,
1026 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR },
1027 { BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB },
1028 { BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG },
1029 { BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR },
1030 { YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG }
1031 };
1032
1033 // BT601 constants for NV21 where chroma plane is VU instead of UV.
1034 YuvConstants SIMD_ALIGNED(kYvuConstants) = {
1035 { 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB,
1036 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB },
1037 { VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG,
1038 VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG },
1039 { VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0,
1040 VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0 },
1041 { BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB, BB },
1042 { BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG },
1043 { BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR, BR },
1044 { YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG, YG }
1045 };
1018 // C reference code that mimics the YUV assembly. 1046 // C reference code that mimics the YUV assembly.
1019 static __inline void YuvPixel(uint8 y, uint8 u, uint8 v, 1047 static __inline void YuvPixel(uint8 y, uint8 u, uint8 v,
1020 uint8* b, uint8* g, uint8* r) { 1048 uint8* b, uint8* g, uint8* r) {
1021 uint32 y1 = (uint32)(y * 0x0101 * YG) >> 16; 1049 uint32 y1 = (uint32)(y * 0x0101 * YG) >> 16;
1022 *b = Clamp((int32)(-(u * UB) + y1 + BB) >> 6); 1050 *b = Clamp((int32)(-(u * UB) + y1 + BB) >> 6);
1023 *g = Clamp((int32)(-(v * VG + u * UG) + y1 + BG) >> 6); 1051 *g = Clamp((int32)(-(v * VG + u * UG) + y1 + BG) >> 6);
1024 *r = Clamp((int32)(-(v * VR)+ y1 + BR) >> 6); 1052 *r = Clamp((int32)(-(v * VR)+ y1 + BR) >> 6);
1025 } 1053 }
1026 1054
1027 // C reference code that mimics the YUV assembly. 1055 // C reference code that mimics the YUV assembly.
1028 static __inline void YPixel(uint8 y, uint8* b, uint8* g, uint8* r) { 1056 static __inline void YPixel(uint8 y, uint8* b, uint8* g, uint8* r) {
1029 uint32 y1 = (uint32)(y * 0x0101 * YG) >> 16; 1057 uint32 y1 = (uint32)(y * 0x0101 * YG) >> 16;
1030 *b = Clamp((int32)(y1 + YGB) >> 6); 1058 *b = Clamp((int32)(y1 + YGB) >> 6);
1031 *g = Clamp((int32)(y1 + YGB) >> 6); 1059 *g = Clamp((int32)(y1 + YGB) >> 6);
1032 *r = Clamp((int32)(y1 + YGB) >> 6); 1060 *r = Clamp((int32)(y1 + YGB) >> 6);
1033 } 1061 }
1034
harryjin 2015/09/18 22:48:31 Why removing this empty line?
fbarchard 2015/09/18 22:51:11 Done.
1035 #undef YG 1062 #undef YG
1036 #undef YGB 1063 #undef YGB
1037 #undef UB 1064 #undef UB
1038 #undef UG 1065 #undef UG
1039 #undef VG 1066 #undef VG
1040 #undef VR 1067 #undef VR
1041 #undef BB 1068 #undef BB
1042 #undef BG 1069 #undef BG
1043 #undef BR 1070 #undef BR
1044 1071
1045 // JPEG YUV to RGB reference 1072 // JPEG YUV to RGB reference
1046 // * R = Y - V * -1.40200 1073 // * R = Y - V * -1.40200
1047 // * G = Y - U * 0.34414 - V * 0.71414 1074 // * G = Y - U * 0.34414 - V * 0.71414
1048 // * B = Y - U * -1.77200 1075 // * B = Y - U * -1.77200
1049 1076
1050 // Y contribution to R,G,B. Scale and bias. 1077 // Y contribution to R,G,B. Scale and bias.
1051 // TODO(fbarchard): Consider moving constants into a common header. 1078 // TODO(fbarchard): Consider moving constants into a common header.
1052 #define YGJ 16320 /* round(1.000 * 64 * 256 * 256 / 257) */ 1079 #define YGJ 16320 /* round(1.000 * 64 * 256 * 256 / 257) */
1053 #define YGBJ 32 /* 64 / 2 */ 1080 #define YGBJ 32 /* 64 / 2 */
1054 1081
1055 // U and V contributions to R,G,B. 1082 // U and V contributions to R,G,B.
1056 #define UBJ -113 /* round(-1.77200 * 64) */ 1083 #define UBJ -113 /* round(-1.77200 * 64) */
1057 #define UGJ 22 /* round(0.34414 * 64) */ 1084 #define UGJ 22 /* round(0.34414 * 64) */
1058 #define VGJ 46 /* round(0.71414 * 64) */ 1085 #define VGJ 46 /* round(0.71414 * 64) */
1059 #define VRJ -90 /* round(-1.40200 * 64) */ 1086 #define VRJ -90 /* round(-1.40200 * 64) */
1060 1087
1061 // Bias values to round Y and subtract 128 from U and V. 1088 // Bias values to subtract 16 from Y and 128 from U and V.
1062 #define BBJ (UBJ * 128 + YGBJ) 1089 #define BBJ (UBJ * 128 + YGBJ)
1063 #define BGJ (UGJ * 128 + VGJ * 128 + YGBJ) 1090 #define BGJ (UGJ * 128 + VGJ * 128 + YGBJ)
1064 #define BRJ (VRJ * 128 + YGBJ) 1091 #define BRJ (VRJ * 128 + YGBJ)
1065 1092
1093 // JPEG constants for YUV to RGB.
1094 YuvConstants SIMD_ALIGNED(kYuvJConstants) = {
1095 { UBJ, 0, UBJ, 0, UBJ, 0, UBJ, 0, UBJ, 0, UBJ, 0, UBJ, 0, UBJ, 0,
1096 UBJ, 0, UBJ, 0, UBJ, 0, UBJ, 0, UBJ, 0, UBJ, 0, UBJ, 0, UBJ, 0 },
1097 { UGJ, VGJ, UGJ, VGJ, UGJ, VGJ, UGJ, VGJ,
1098 UGJ, VGJ, UGJ, VGJ, UGJ, VGJ, UGJ, VGJ,
1099 UGJ, VGJ, UGJ, VGJ, UGJ, VGJ, UGJ, VGJ,
1100 UGJ, VGJ, UGJ, VGJ, UGJ, VGJ, UGJ, VGJ },
1101 { 0, VRJ, 0, VRJ, 0, VRJ, 0, VRJ, 0, VRJ, 0, VRJ, 0, VRJ, 0, VRJ,
1102 0, VRJ, 0, VRJ, 0, VRJ, 0, VRJ, 0, VRJ, 0, VRJ, 0, VRJ, 0, VRJ },
1103 { BBJ, BBJ, BBJ, BBJ, BBJ, BBJ, BBJ, BBJ,
1104 BBJ, BBJ, BBJ, BBJ, BBJ, BBJ, BBJ, BBJ },
1105 { BGJ, BGJ, BGJ, BGJ, BGJ, BGJ, BGJ, BGJ,
1106 BGJ, BGJ, BGJ, BGJ, BGJ, BGJ, BGJ, BGJ },
1107 { BRJ, BRJ, BRJ, BRJ, BRJ, BRJ, BRJ, BRJ,
1108 BRJ, BRJ, BRJ, BRJ, BRJ, BRJ, BRJ, BRJ },
1109 { YGJ, YGJ, YGJ, YGJ, YGJ, YGJ, YGJ, YGJ,
1110 YGJ, YGJ, YGJ, YGJ, YGJ, YGJ, YGJ, YGJ }
1111 };
1066 // C reference code that mimics the YUV assembly. 1112 // C reference code that mimics the YUV assembly.
1067 static __inline void YuvJPixel(uint8 y, uint8 u, uint8 v, 1113 static __inline void YuvJPixel(uint8 y, uint8 u, uint8 v,
1068 uint8* b, uint8* g, uint8* r) { 1114 uint8* b, uint8* g, uint8* r) {
1069 uint32 y1 = (uint32)(y * 0x0101 * YGJ) >> 16; 1115 uint32 y1 = (uint32)(y * 0x0101 * YGJ) >> 16;
1070 *b = Clamp((int32)(-(u * UBJ) + y1 + BBJ) >> 6); 1116 *b = Clamp((int32)(-(u * UBJ) + y1 + BBJ) >> 6);
1071 *g = Clamp((int32)(-(v * VGJ + u * UGJ) + y1 + BGJ) >> 6); 1117 *g = Clamp((int32)(-(v * VGJ + u * UGJ) + y1 + BGJ) >> 6);
1072 *r = Clamp((int32)(-(v * VRJ) + y1 + BRJ) >> 6); 1118 *r = Clamp((int32)(-(v * VRJ) + y1 + BRJ) >> 6);
1073 } 1119 }
1074 1120
1075 #undef YGJ 1121 #undef YGJ
(...skipping 20 matching lines...) Expand all
1096 #define UBH -128 /* max(-128, round(-2.12798 * 64)) */ 1142 #define UBH -128 /* max(-128, round(-2.12798 * 64)) */
1097 #define UGH 14 /* round(0.21482 * 64) */ 1143 #define UGH 14 /* round(0.21482 * 64) */
1098 #define VGH 24 /* round(0.38059 * 64) */ 1144 #define VGH 24 /* round(0.38059 * 64) */
1099 #define VRH -82 /* round(-1.28033 * 64) */ 1145 #define VRH -82 /* round(-1.28033 * 64) */
1100 1146
1101 // Bias values to round, and subtract 128 from U and V. 1147 // Bias values to round, and subtract 128 from U and V.
1102 #define BBH (UBH * 128 + YGBH) 1148 #define BBH (UBH * 128 + YGBH)
1103 #define BGH (UGH * 128 + VGH * 128 + YGBH) 1149 #define BGH (UGH * 128 + VGH * 128 + YGBH)
1104 #define BRH (VRH * 128 + YGBH) 1150 #define BRH (VRH * 128 + YGBH)
1105 1151
1152 // BT.709 constants for YUV to RGB.
1153 YuvConstants SIMD_ALIGNED(kYuvHConstants) = {
1154 { UBH, 0, UBH, 0, UBH, 0, UBH, 0, UBH, 0, UBH, 0, UBH, 0, UBH, 0,
1155 UBH, 0, UBH, 0, UBH, 0, UBH, 0, UBH, 0, UBH, 0, UBH, 0, UBH, 0 },
1156 { UGH, VGH, UGH, VGH, UGH, VGH, UGH, VGH,
1157 UGH, VGH, UGH, VGH, UGH, VGH, UGH, VGH,
1158 UGH, VGH, UGH, VGH, UGH, VGH, UGH, VGH,
1159 UGH, VGH, UGH, VGH, UGH, VGH, UGH, VGH },
1160 { 0, VRH, 0, VRH, 0, VRH, 0, VRH, 0, VRH, 0, VRH, 0, VRH, 0, VRH,
1161 0, VRH, 0, VRH, 0, VRH, 0, VRH, 0, VRH, 0, VRH, 0, VRH, 0, VRH },
1162 { BBH, BBH, BBH, BBH, BBH, BBH, BBH, BBH,
1163 BBH, BBH, BBH, BBH, BBH, BBH, BBH, BBH },
1164 { BGH, BGH, BGH, BGH, BGH, BGH, BGH, BGH,
1165 BGH, BGH, BGH, BGH, BGH, BGH, BGH, BGH },
1166 { BRH, BRH, BRH, BRH, BRH, BRH, BRH, BRH,
1167 BRH, BRH, BRH, BRH, BRH, BRH, BRH, BRH },
1168 { YGH, YGH, YGH, YGH, YGH, YGH, YGH, YGH,
1169 YGH, YGH, YGH, YGH, YGH, YGH, YGH, YGH }
1170 };
1171
1106 // C reference code that mimics the YUV assembly. 1172 // C reference code that mimics the YUV assembly.
1107 static __inline void YuvHPixel(uint8 y, uint8 u, uint8 v, 1173 static __inline void YuvHPixel(uint8 y, uint8 u, uint8 v,
1108 uint8* b, uint8* g, uint8* r) { 1174 uint8* b, uint8* g, uint8* r) {
1109 uint32 y1 = (uint32)(y * 0x0101 * YGH) >> 16; 1175 uint32 y1 = (uint32)(y * 0x0101 * YGH) >> 16;
1110 *b = Clamp((int32)(-(u * UBH) + y1 + BBH) >> 6); 1176 *b = Clamp((int32)(-(u * UBH) + y1 + BBH) >> 6);
1111 *g = Clamp((int32)(-(v * VGH + u * UGH) + y1 + BGH) >> 6); 1177 *g = Clamp((int32)(-(v * VGH + u * UGH) + y1 + BGH) >> 6);
1112 *r = Clamp((int32)(-(v * VRH) + y1 + BRH) >> 6); 1178 *r = Clamp((int32)(-(v * VRH) + y1 + BRH) >> 6);
1113 } 1179 }
1114 1180
1115 #undef YGH 1181 #undef YGH
1116 #undef YGBH 1182 #undef YGBH
1117 #undef UBH 1183 #undef UBH
1118 #undef UGH 1184 #undef UGH
1119 #undef VGH 1185 #undef VGH
1120 #undef VRH 1186 #undef VRH
1121 #undef BBH 1187 #undef BBH
1122 #undef BGH 1188 #undef BGH
1123 #undef BRH 1189 #undef BRH
1124 1190
1191
harryjin 2015/09/18 22:48:31 Remove the extra lines here?
fbarchard 2015/09/18 22:51:11 Done.
1192
1193
1194
1195
1196
1197
1125 #if !defined(LIBYUV_DISABLE_NEON) && \ 1198 #if !defined(LIBYUV_DISABLE_NEON) && \
1126 (defined(__ARM_NEON__) || defined(__aarch64__) || defined(LIBYUV_NEON)) 1199 (defined(__ARM_NEON__) || defined(__aarch64__) || defined(LIBYUV_NEON))
1127 // C mimic assembly. 1200 // C mimic assembly.
1128 // TODO(fbarchard): Remove subsampling from Neon. 1201 // TODO(fbarchard): Remove subsampling from Neon.
1129 void I444ToARGBRow_C(const uint8* src_y, 1202 void I444ToARGBRow_C(const uint8* src_y,
1130 const uint8* src_u, 1203 const uint8* src_u,
1131 const uint8* src_v, 1204 const uint8* src_v,
1132 uint8* rgb_buf, 1205 uint8* rgb_buf,
1133 int width) { 1206 int width) {
1134 int x; 1207 int x;
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 src_v += 1; 2380 src_v += 1;
2308 } 2381 }
2309 if (width & 1) { 2382 if (width & 1) {
2310 dst_frame[0] = src_u[0]; 2383 dst_frame[0] = src_u[0];
2311 dst_frame[1] = src_y[0]; 2384 dst_frame[1] = src_y[0];
2312 dst_frame[2] = src_v[0]; 2385 dst_frame[2] = src_v[0];
2313 dst_frame[3] = 0; 2386 dst_frame[3] = 0;
2314 } 2387 }
2315 } 2388 }
2316 2389
2317 extern struct YuvConstants kYuvConstants;
2318 extern struct YuvConstants kYuvJConstants;
2319 extern struct YuvConstants kYuvHConstants;
2320 extern struct YuvConstantsNEON kYuvConstantsNEON;
2321 extern struct YuvConstantsNEON kYuvJConstantsNEON;
2322 extern struct YuvConstantsNEON kYuvHConstantsNEON;
2323
2324 #define ANYYUV(NAMEANY, ANY_SIMD, YUVCONSTANTS) \ 2390 #define ANYYUV(NAMEANY, ANY_SIMD, YUVCONSTANTS) \
2325 void NAMEANY(const uint8* y_buf, \ 2391 void NAMEANY(const uint8* y_buf, \
2326 const uint8* u_buf, \ 2392 const uint8* u_buf, \
2327 const uint8* v_buf, \ 2393 const uint8* v_buf, \
2328 uint8* dst_argb, \ 2394 uint8* dst_argb, \
2329 int width) { \ 2395 int width) { \
2330 ANY_SIMD(y_buf, u_buf, v_buf, dst_argb, &YUVCONSTANTS, width); \ 2396 ANY_SIMD(y_buf, u_buf, v_buf, dst_argb, &YUVCONSTANTS, width); \
2331 } 2397 }
2332 2398
2333 #ifdef HAS_I422TOARGBMATRIXROW_NEON 2399 #ifdef HAS_I422TOARGBMATRIXROW_NEON
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
2785 } 2851 }
2786 if (width & 1) { 2852 if (width & 1) {
2787 dst[3] = src[0]; 2853 dst[3] = src[0];
2788 } 2854 }
2789 } 2855 }
2790 2856
2791 #ifdef __cplusplus 2857 #ifdef __cplusplus
2792 } // extern "C" 2858 } // extern "C"
2793 } // namespace libyuv 2859 } // namespace libyuv
2794 #endif 2860 #endif
OLDNEW
« no previous file with comments | « include/libyuv/row.h ('k') | source/row_gcc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698