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

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

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