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

Side by Side Diff: src/core/SkColorSpaceXform.cpp

Issue 2347473007: Revert of Support Float32 output from SkColorSpaceXform (Closed)
Patch Set: Created 4 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 | « src/core/SkColorSpaceXform.h ('k') | src/core/SkNx.h » ('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 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkColorSpace_Base.h" 9 #include "SkColorSpace_Base.h"
10 #include "SkColorSpacePriv.h" 10 #include "SkColorSpacePriv.h"
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 901
902 template <SwapRB kSwapRB> 902 template <SwapRB kSwapRB>
903 static inline void store_f16_1(void* dst, const uint32_t* src, 903 static inline void store_f16_1(void* dst, const uint32_t* src,
904 Sk4f& rgba, const Sk4f& a, 904 Sk4f& rgba, const Sk4f& a,
905 const uint8_t* const[3]) { 905 const uint8_t* const[3]) {
906 rgba = Sk4f(rgba[0], rgba[1], rgba[2], a[3]); 906 rgba = Sk4f(rgba[0], rgba[1], rgba[2], a[3]);
907 SkFloatToHalf_finite_ftz(rgba).store((uint64_t*) dst); 907 SkFloatToHalf_finite_ftz(rgba).store((uint64_t*) dst);
908 } 908 }
909 909
910 template <SwapRB kSwapRB> 910 template <SwapRB kSwapRB>
911 static inline void store_f32(void* dst, const uint32_t* src,
912 Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f& da,
913 const uint8_t* const[3]) {
914 Sk4f_store4(dst, dr, dg, db, da);
915 }
916
917 template <SwapRB kSwapRB>
918 static inline void store_f32_1(void* dst, const uint32_t* src,
919 Sk4f& rgba, const Sk4f& a,
920 const uint8_t* const[3]) {
921 rgba = Sk4f(rgba[0], rgba[1], rgba[2], a[3]);
922 rgba.store((float*) dst);
923 }
924
925 template <SwapRB kSwapRB>
926 static inline void store_f16_opaque(void* dst, const uint32_t* src, 911 static inline void store_f16_opaque(void* dst, const uint32_t* src,
927 Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f&, 912 Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f& da,
928 const uint8_t* const[3]) { 913 const uint8_t* const[3]) {
929 Sk4h_store4(dst, SkFloatToHalf_finite_ftz(dr), 914 Sk4h_store4(dst, SkFloatToHalf_finite_ftz(dr),
930 SkFloatToHalf_finite_ftz(dg), 915 SkFloatToHalf_finite_ftz(dg),
931 SkFloatToHalf_finite_ftz(db), 916 SkFloatToHalf_finite_ftz(db),
932 SK_Half1); 917 SK_Half1);
933 } 918 }
934 919
935 template <SwapRB kSwapRB> 920 template <SwapRB kSwapRB>
936 static inline void store_f16_1_opaque(void* dst, const uint32_t* src, 921 static inline void store_f16_1_opaque(void* dst, const uint32_t* src,
937 Sk4f& rgba, const Sk4f&, 922 Sk4f& rgba, const Sk4f& a,
938 const uint8_t* const[3]) { 923 const uint8_t* const[3]) {
939 uint64_t tmp; 924 uint64_t tmp;
940 SkFloatToHalf_finite_ftz(rgba).store(&tmp); 925 SkFloatToHalf_finite_ftz(rgba).store(&tmp);
941 tmp |= static_cast<uint64_t>(SK_Half1) << 48; 926 tmp |= static_cast<uint64_t>(SK_Half1) << 48;
942 *((uint64_t*) dst) = tmp; 927 *((uint64_t*) dst) = tmp;
943 } 928 }
944 929
945 template <SwapRB kSwapRB> 930 template <SwapRB kSwapRB>
946 static inline void store_generic(void* dst, const uint32_t* src, 931 static inline void store_generic(void* dst, const uint32_t* src,
947 Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f&, 932 Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f&,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 kRGBA_8888_Linear_SrcFormat, 1082 kRGBA_8888_Linear_SrcFormat,
1098 kRGBA_8888_Table_SrcFormat, 1083 kRGBA_8888_Table_SrcFormat,
1099 }; 1084 };
1100 1085
1101 enum DstFormat { 1086 enum DstFormat {
1102 k8888_Linear_DstFormat, 1087 k8888_Linear_DstFormat,
1103 k8888_SRGB_DstFormat, 1088 k8888_SRGB_DstFormat,
1104 k8888_2Dot2_DstFormat, 1089 k8888_2Dot2_DstFormat,
1105 k8888_Table_DstFormat, 1090 k8888_Table_DstFormat,
1106 kF16_Linear_DstFormat, 1091 kF16_Linear_DstFormat,
1107 kF32_Linear_DstFormat,
1108 }; 1092 };
1109 1093
1110 template <SrcFormat kSrc, 1094 template <SrcFormat kSrc,
1111 DstFormat kDst, 1095 DstFormat kDst,
1112 SkAlphaType kAlphaType, 1096 SkAlphaType kAlphaType,
1113 ColorSpaceMatch kCSM, 1097 ColorSpaceMatch kCSM,
1114 SwapRB kSwapRB> 1098 SwapRB kSwapRB>
1115 static void color_xform_RGBA(void* dst, const uint32_t* src, int len, 1099 static void color_xform_RGBA(void* dst, const uint32_t* src, int len,
1116 const float* const srcTables[3], const float matrix [16], 1100 const float* const srcTables[3], const float matrix [16],
1117 const uint8_t* const dstTables[3]) { 1101 const uint8_t* const dstTables[3]) {
1118 LoadFn load; 1102 LoadFn load;
1119 Load1Fn load_1; 1103 Load1Fn load_1;
1120 static constexpr bool loadAlpha = (kPremul_SkAlphaType == kAlphaType) ||
1121 (kF16_Linear_DstFormat == kDst) ||
1122 (kF32_Linear_DstFormat == kDst);
1123 switch (kSrc) { 1104 switch (kSrc) {
1124 case kRGBA_8888_Linear_SrcFormat: 1105 case kRGBA_8888_Linear_SrcFormat:
1125 if (loadAlpha) { 1106 if (kPremul_SkAlphaType == kAlphaType || kF16_Linear_DstFormat == kD st) {
1126 load = load_rgba_linear; 1107 load = load_rgba_linear;
1127 load_1 = load_rgba_linear_1; 1108 load_1 = load_rgba_linear_1;
1128 } else { 1109 } else {
1129 load = load_rgb_linear; 1110 load = load_rgb_linear;
1130 load_1 = load_rgb_linear_1; 1111 load_1 = load_rgb_linear_1;
1131 } 1112 }
1132 break; 1113 break;
1133 case kRGBA_8888_Table_SrcFormat: 1114 case kRGBA_8888_Table_SrcFormat:
1134 if (loadAlpha) { 1115 if (kPremul_SkAlphaType == kAlphaType || kF16_Linear_DstFormat == kD st) {
1135 load = load_rgba_from_tables; 1116 load = load_rgba_from_tables;
1136 load_1 = load_rgba_from_tables_1; 1117 load_1 = load_rgba_from_tables_1;
1137 } else { 1118 } else {
1138 load = load_rgb_from_tables; 1119 load = load_rgb_from_tables;
1139 load_1 = load_rgb_from_tables_1; 1120 load_1 = load_rgb_from_tables_1;
1140 } 1121 }
1141 break; 1122 break;
1142 } 1123 }
1143 1124
1144 StoreFn store; 1125 StoreFn store;
(...skipping 20 matching lines...) Expand all
1165 store_1 = store_generic_1<kSwapRB>; 1146 store_1 = store_generic_1<kSwapRB>;
1166 sizeOfDstPixel = 4; 1147 sizeOfDstPixel = 4;
1167 break; 1148 break;
1168 case kF16_Linear_DstFormat: 1149 case kF16_Linear_DstFormat:
1169 store = (kOpaque_SkAlphaType == kAlphaType) ? store_f16_opaque<kSw apRB> : 1150 store = (kOpaque_SkAlphaType == kAlphaType) ? store_f16_opaque<kSw apRB> :
1170 store_f16<kSwapRB>; 1151 store_f16<kSwapRB>;
1171 store_1 = (kOpaque_SkAlphaType == kAlphaType) ? store_f16_1_opaque<k SwapRB> : 1152 store_1 = (kOpaque_SkAlphaType == kAlphaType) ? store_f16_1_opaque<k SwapRB> :
1172 store_f16_1<kSwapRB> ; 1153 store_f16_1<kSwapRB> ;
1173 sizeOfDstPixel = 8; 1154 sizeOfDstPixel = 8;
1174 break; 1155 break;
1175 case kF32_Linear_DstFormat:
1176 store = store_f32<kSwapRB>;
1177 store_1 = store_f32_1<kSwapRB>;
1178 sizeOfDstPixel = 16;
1179 break;
1180 } 1156 }
1181 1157
1182 do_color_xform<kAlphaType, kCSM> 1158 do_color_xform<kAlphaType, kCSM>
1183 (dst, src, len, srcTables, matrix, dstTables, load, load_1, store, s tore_1, 1159 (dst, src, len, srcTables, matrix, dstTables, load, load_1, store, s tore_1,
1184 sizeOfDstPixel); 1160 sizeOfDstPixel);
1185 } 1161 }
1186 1162
1187 //////////////////////////////////////////////////////////////////////////////// /////////////////// 1163 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1188 1164
1189 static inline int num_tables(SkColorSpace* space) { 1165 static inline int num_tables(SkColorSpace* space) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 return apply_set_alpha<kRGBA_8888_Linear_SrcFormat, kDst, kCSM, kSwa p> 1238 return apply_set_alpha<kRGBA_8888_Linear_SrcFormat, kDst, kCSM, kSwa p>
1263 (dst, src, len, alphaType, nullptr, matrix, dstTables); 1239 (dst, src, len, alphaType, nullptr, matrix, dstTables);
1264 case kTable_SrcGamma: 1240 case kTable_SrcGamma:
1265 return apply_set_alpha<kRGBA_8888_Table_SrcFormat, kDst, kCSM, kSwap > 1241 return apply_set_alpha<kRGBA_8888_Table_SrcFormat, kDst, kCSM, kSwap >
1266 (dst, src, len, alphaType, srcTables, matrix, dstTables); 1242 (dst, src, len, alphaType, srcTables, matrix, dstTables);
1267 } 1243 }
1268 } 1244 }
1269 1245
1270 template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM> 1246 template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM>
1271 void SkColorSpaceXform_Base<kSrc, kDst, kCSM> 1247 void SkColorSpaceXform_Base<kSrc, kDst, kCSM>
1272 ::apply(void* dst, const uint32_t* src, int len, ColorFormat dstColorFormat, SkA lphaType alphaType) 1248 ::apply(void* dst, const uint32_t* src, int len, SkColorType dstColorType, SkAlp haType alphaType)
1273 const 1249 const
1274 { 1250 {
1275 if (kFull_ColorSpaceMatch == kCSM) { 1251 if (kFull_ColorSpaceMatch == kCSM) {
1276 switch (alphaType) { 1252 switch (alphaType) {
1277 case kPremul_SkAlphaType: 1253 case kPremul_SkAlphaType:
1278 // We can't skip the xform since we need to perform a premultipl y in the 1254 // We can't skip the xform since we need to perform a premultipl y in the
1279 // linear space. 1255 // linear space.
1280 break; 1256 break;
1281 default: 1257 default:
1282 switch (dstColorFormat) { 1258 switch (dstColorType) {
1283 case kRGBA_8888_ColorFormat: 1259 case kRGBA_8888_SkColorType:
1284 return (void) memcpy(dst, src, len * sizeof(uint32_t)); 1260 return (void) memcpy(dst, src, len * sizeof(uint32_t));
1285 case kBGRA_8888_ColorFormat: 1261 case kBGRA_8888_SkColorType:
1286 return SkOpts::RGBA_to_BGRA((uint32_t*) dst, src, len); 1262 return SkOpts::RGBA_to_BGRA((uint32_t*) dst, src, len);
1287 case kRGBA_F16_ColorFormat: 1263 case kRGBA_F16_SkColorType:
1288 case kRGBA_F32_ColorFormat: 1264 // There's still work to do to xform to linear F16.
1289 // There's still work to do to xform to linear floats.
1290 break; 1265 break;
1291 default: 1266 default:
1292 SkASSERT(false); 1267 SkASSERT(false);
1293 return; 1268 return;
1294 } 1269 }
1295 } 1270 }
1296 } 1271 }
1297 1272
1298 if (fColorLUT) { 1273 if (fColorLUT) {
1299 size_t storageBytes = len * sizeof(uint32_t); 1274 size_t storageBytes = len * sizeof(uint32_t);
1300 #if defined(GOOGLE3) 1275 #if defined(GOOGLE3)
1301 // Stack frame size is limited in GOOGLE3. 1276 // Stack frame size is limited in GOOGLE3.
1302 SkAutoSMalloc<256 * sizeof(uint32_t)> storage(storageBytes); 1277 SkAutoSMalloc<256 * sizeof(uint32_t)> storage(storageBytes);
1303 #else 1278 #else
1304 SkAutoSMalloc<1024 * sizeof(uint32_t)> storage(storageBytes); 1279 SkAutoSMalloc<1024 * sizeof(uint32_t)> storage(storageBytes);
1305 #endif 1280 #endif
1306 1281
1307 handle_color_lut((uint32_t*) storage.get(), src, len, fColorLUT.get()); 1282 handle_color_lut((uint32_t*) storage.get(), src, len, fColorLUT.get());
1308 src = (const uint32_t*) storage.get(); 1283 src = (const uint32_t*) storage.get();
1309 } 1284 }
1310 1285
1311 switch (dstColorFormat) { 1286 switch (dstColorType) {
1312 case kRGBA_8888_ColorFormat: 1287 case kRGBA_8888_SkColorType:
1313 switch (kDst) { 1288 switch (kDst) {
1314 case kLinear_DstGamma: 1289 case kLinear_DstGamma:
1315 return apply_set_src<kSrc, k8888_Linear_DstFormat, kCSM, kNo _SwapRB> 1290 return apply_set_src<kSrc, k8888_Linear_DstFormat, kCSM, kNo _SwapRB>
1316 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr); 1291 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr);
1317 case kSRGB_DstGamma: 1292 case kSRGB_DstGamma:
1318 return apply_set_src<kSrc, k8888_SRGB_DstFormat, kCSM, kNo_S wapRB> 1293 return apply_set_src<kSrc, k8888_SRGB_DstFormat, kCSM, kNo_S wapRB>
1319 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr); 1294 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr);
1320 case k2Dot2_DstGamma: 1295 case k2Dot2_DstGamma:
1321 return apply_set_src<kSrc, k8888_2Dot2_DstFormat, kCSM, kNo_ SwapRB> 1296 return apply_set_src<kSrc, k8888_2Dot2_DstFormat, kCSM, kNo_ SwapRB>
1322 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr); 1297 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr);
1323 case kTable_DstGamma: 1298 case kTable_DstGamma:
1324 return apply_set_src<kSrc, k8888_Table_DstFormat, kCSM, kNo_ SwapRB> 1299 return apply_set_src<kSrc, k8888_Table_DstFormat, kCSM, kNo_ SwapRB>
1325 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, fDstGammaTables); 1300 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, fDstGammaTables);
1326 } 1301 }
1327 case kBGRA_8888_ColorFormat: 1302 case kBGRA_8888_SkColorType:
1328 switch (kDst) { 1303 switch (kDst) {
1329 case kLinear_DstGamma: 1304 case kLinear_DstGamma:
1330 return apply_set_src<kSrc, k8888_Linear_DstFormat, kCSM, kYe s_SwapRB> 1305 return apply_set_src<kSrc, k8888_Linear_DstFormat, kCSM, kYe s_SwapRB>
1331 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr); 1306 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr);
1332 case kSRGB_DstGamma: 1307 case kSRGB_DstGamma:
1333 return apply_set_src<kSrc, k8888_SRGB_DstFormat, kCSM, kYes_ SwapRB> 1308 return apply_set_src<kSrc, k8888_SRGB_DstFormat, kCSM, kYes_ SwapRB>
1334 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr); 1309 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr);
1335 case k2Dot2_DstGamma: 1310 case k2Dot2_DstGamma:
1336 return apply_set_src<kSrc, k8888_2Dot2_DstFormat, kCSM, kYes _SwapRB> 1311 return apply_set_src<kSrc, k8888_2Dot2_DstFormat, kCSM, kYes _SwapRB>
1337 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr); 1312 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr);
1338 case kTable_DstGamma: 1313 case kTable_DstGamma:
1339 return apply_set_src<kSrc, k8888_Table_DstFormat, kCSM, kYes _SwapRB> 1314 return apply_set_src<kSrc, k8888_Table_DstFormat, kCSM, kYes _SwapRB>
1340 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, fDstGammaTables); 1315 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, fDstGammaTables);
1341 } 1316 }
1342 case kRGBA_F16_ColorFormat: 1317 case kRGBA_F16_SkColorType:
1343 switch (kDst) { 1318 switch (kDst) {
1344 case kLinear_DstGamma: 1319 case kLinear_DstGamma:
1345 return apply_set_src<kSrc, kF16_Linear_DstFormat, kCSM, kNo_ SwapRB> 1320 return apply_set_src<kSrc, kF16_Linear_DstFormat, kCSM, kNo_ SwapRB>
1346 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr); 1321 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr);
1347 default: 1322 default:
1348 SkASSERT(false); 1323 SkASSERT(false);
1349 return; 1324 return;
1350 } 1325 }
1351 case kRGBA_F32_ColorFormat:
1352 switch (kDst) {
1353 case kLinear_DstGamma:
1354 return apply_set_src<kSrc, kF32_Linear_DstFormat, kCSM, kNo_ SwapRB>
1355 (dst, src, len, alphaType, fSrcGammaTables, fSrcToDs t, nullptr);
1356 default:
1357 SkASSERT(false);
1358 return;
1359 }
1360 default: 1326 default:
1361 SkASSERT(false); 1327 SkASSERT(false);
1362 return; 1328 return;
1363 } 1329 }
1364 } 1330 }
1365 1331
1366 //////////////////////////////////////////////////////////////////////////////// /////////////////// 1332 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1367 1333
1368 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>& space) { 1334 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>& space) {
1369 return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base 1335 return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
1370 <kTable_SrcGamma, kTable_DstGamma, kNone_ColorSpaceMatch> 1336 <kTable_SrcGamma, kTable_DstGamma, kNone_ColorSpaceMatch>
1371 (space, SkMatrix::I(), space)); 1337 (space, SkMatrix::I(), space));
1372 } 1338 }
OLDNEW
« no previous file with comments | « src/core/SkColorSpaceXform.h ('k') | src/core/SkNx.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698