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

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

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

Powered by Google App Engine
This is Rietveld 408576698