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

Unified Diff: src/core/SkColorSpaceXform.cpp

Issue 2325793002: Well let's see (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkColorSpaceXform.cpp
diff --git a/src/core/SkColorSpaceXform.cpp b/src/core/SkColorSpaceXform.cpp
index 136b4da6b922522c72fb6e8de955061304fa3e02..45f27365c6fd64ee11d598d09d79e371dfac668d 100644
--- a/src/core/SkColorSpaceXform.cpp
+++ b/src/core/SkColorSpaceXform.cpp
@@ -82,128 +82,6 @@ static constexpr float sk_linear_from_2dot2[256] = {
///////////////////////////////////////////////////////////////////////////////////////////////////
-static constexpr uint8_t linear_to_srgb[1024] = {
- 0, 3, 6, 10, 13, 15, 18, 20, 22, 23, 25, 27, 28, 30, 31, 32, 34, 35,
- 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 49, 50, 51, 52,
- 53, 53, 54, 55, 56, 56, 57, 58, 58, 59, 60, 61, 61, 62, 62, 63, 64, 64,
- 65, 66, 66, 67, 67, 68, 68, 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 74,
- 75, 76, 76, 77, 77, 78, 78, 79, 79, 79, 80, 80, 81, 81, 82, 82, 83, 83,
- 84, 84, 85, 85, 85, 86, 86, 87, 87, 88, 88, 88, 89, 89, 90, 90, 91, 91,
- 91, 92, 92, 93, 93, 93, 94, 94, 95, 95, 95, 96, 96, 97, 97, 97, 98, 98,
- 98, 99, 99, 99, 100, 100, 101, 101, 101, 102, 102, 102, 103, 103, 103, 104, 104, 104,
- 105, 105, 106, 106, 106, 107, 107, 107, 108, 108, 108, 109, 109, 109, 110, 110, 110, 110,
- 111, 111, 111, 112, 112, 112, 113, 113, 113, 114, 114, 114, 115, 115, 115, 115, 116, 116,
- 116, 117, 117, 117, 118, 118, 118, 118, 119, 119, 119, 120, 120, 120, 121, 121, 121, 121,
- 122, 122, 122, 123, 123, 123, 123, 124, 124, 124, 125, 125, 125, 125, 126, 126, 126, 126,
- 127, 127, 127, 128, 128, 128, 128, 129, 129, 129, 129, 130, 130, 130, 130, 131, 131, 131,
- 131, 132, 132, 132, 133, 133, 133, 133, 134, 134, 134, 134, 135, 135, 135, 135, 136, 136,
- 136, 136, 137, 137, 137, 137, 138, 138, 138, 138, 138, 139, 139, 139, 139, 140, 140, 140,
- 140, 141, 141, 141, 141, 142, 142, 142, 142, 143, 143, 143, 143, 143, 144, 144, 144, 144,
- 145, 145, 145, 145, 146, 146, 146, 146, 146, 147, 147, 147, 147, 148, 148, 148, 148, 148,
- 149, 149, 149, 149, 150, 150, 150, 150, 150, 151, 151, 151, 151, 152, 152, 152, 152, 152,
- 153, 153, 153, 153, 153, 154, 154, 154, 154, 155, 155, 155, 155, 155, 156, 156, 156, 156,
- 156, 157, 157, 157, 157, 157, 158, 158, 158, 158, 158, 159, 159, 159, 159, 159, 160, 160,
- 160, 160, 160, 161, 161, 161, 161, 161, 162, 162, 162, 162, 162, 163, 163, 163, 163, 163,
- 164, 164, 164, 164, 164, 165, 165, 165, 165, 165, 166, 166, 166, 166, 166, 167, 167, 167,
- 167, 167, 168, 168, 168, 168, 168, 168, 169, 169, 169, 169, 169, 170, 170, 170, 170, 170,
- 171, 171, 171, 171, 171, 171, 172, 172, 172, 172, 172, 173, 173, 173, 173, 173, 173, 174,
- 174, 174, 174, 174, 175, 175, 175, 175, 175, 175, 176, 176, 176, 176, 176, 177, 177, 177,
- 177, 177, 177, 178, 178, 178, 178, 178, 178, 179, 179, 179, 179, 179, 179, 180, 180, 180,
- 180, 180, 181, 181, 181, 181, 181, 181, 182, 182, 182, 182, 182, 182, 183, 183, 183, 183,
- 183, 183, 184, 184, 184, 184, 184, 184, 185, 185, 185, 185, 185, 185, 186, 186, 186, 186,
- 186, 186, 187, 187, 187, 187, 187, 187, 188, 188, 188, 188, 188, 188, 189, 189, 189, 189,
- 189, 189, 190, 190, 190, 190, 190, 190, 191, 191, 191, 191, 191, 191, 191, 192, 192, 192,
- 192, 192, 192, 193, 193, 193, 193, 193, 193, 194, 194, 194, 194, 194, 194, 194, 195, 195,
- 195, 195, 195, 195, 196, 196, 196, 196, 196, 196, 197, 197, 197, 197, 197, 197, 197, 198,
- 198, 198, 198, 198, 198, 199, 199, 199, 199, 199, 199, 199, 200, 200, 200, 200, 200, 200,
- 200, 201, 201, 201, 201, 201, 201, 202, 202, 202, 202, 202, 202, 202, 203, 203, 203, 203,
- 203, 203, 203, 204, 204, 204, 204, 204, 204, 204, 205, 205, 205, 205, 205, 205, 206, 206,
- 206, 206, 206, 206, 206, 207, 207, 207, 207, 207, 207, 207, 208, 208, 208, 208, 208, 208,
- 208, 209, 209, 209, 209, 209, 209, 209, 210, 210, 210, 210, 210, 210, 210, 211, 211, 211,
- 211, 211, 211, 211, 212, 212, 212, 212, 212, 212, 212, 212, 213, 213, 213, 213, 213, 213,
- 213, 214, 214, 214, 214, 214, 214, 214, 215, 215, 215, 215, 215, 215, 215, 216, 216, 216,
- 216, 216, 216, 216, 216, 217, 217, 217, 217, 217, 217, 217, 218, 218, 218, 218, 218, 218,
- 218, 219, 219, 219, 219, 219, 219, 219, 219, 220, 220, 220, 220, 220, 220, 220, 221, 221,
- 221, 221, 221, 221, 221, 221, 222, 222, 222, 222, 222, 222, 222, 222, 223, 223, 223, 223,
- 223, 223, 223, 224, 224, 224, 224, 224, 224, 224, 224, 225, 225, 225, 225, 225, 225, 225,
- 225, 226, 226, 226, 226, 226, 226, 226, 227, 227, 227, 227, 227, 227, 227, 227, 228, 228,
- 228, 228, 228, 228, 228, 228, 229, 229, 229, 229, 229, 229, 229, 229, 230, 230, 230, 230,
- 230, 230, 230, 230, 231, 231, 231, 231, 231, 231, 231, 231, 232, 232, 232, 232, 232, 232,
- 232, 232, 233, 233, 233, 233, 233, 233, 233, 233, 234, 234, 234, 234, 234, 234, 234, 234,
- 235, 235, 235, 235, 235, 235, 235, 235, 236, 236, 236, 236, 236, 236, 236, 236, 236, 237,
- 237, 237, 237, 237, 237, 237, 237, 238, 238, 238, 238, 238, 238, 238, 238, 239, 239, 239,
- 239, 239, 239, 239, 239, 239, 240, 240, 240, 240, 240, 240, 240, 240, 241, 241, 241, 241,
- 241, 241, 241, 241, 241, 242, 242, 242, 242, 242, 242, 242, 242, 243, 243, 243, 243, 243,
- 243, 243, 243, 243, 244, 244, 244, 244, 244, 244, 244, 244, 245, 245, 245, 245, 245, 245,
- 245, 245, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 247, 247, 247, 247, 247,
- 247, 247, 248, 248, 248, 248, 248, 248, 248, 248, 248, 249, 249, 249, 249, 249, 249, 249,
- 249, 249, 250, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 251, 251, 251, 251,
- 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 253, 253, 253, 253,
- 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255
-};
-
-static constexpr uint8_t linear_to_2dot2_table[1024] = {
- 0, 11, 15, 18, 21, 23, 25, 26, 28, 30, 31, 32, 34, 35, 36, 37, 39, 40,
- 41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 50, 50, 51, 52, 53, 54, 54, 55,
- 56, 56, 57, 58, 58, 59, 60, 60, 61, 62, 62, 63, 63, 64, 65, 65, 66, 66,
- 67, 68, 68, 69, 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 74, 75, 75, 76,
- 76, 77, 77, 78, 78, 79, 79, 80, 80, 81, 81, 81, 82, 82, 83, 83, 84, 84,
- 84, 85, 85, 86, 86, 87, 87, 87, 88, 88, 89, 89, 89, 90, 90, 91, 91, 91,
- 92, 92, 93, 93, 93, 94, 94, 94, 95, 95, 96, 96, 96, 97, 97, 97, 98, 98,
- 98, 99, 99, 99, 100, 100, 101, 101, 101, 102, 102, 102, 103, 103, 103, 104, 104, 104,
- 105, 105, 105, 106, 106, 106, 107, 107, 107, 108, 108, 108, 108, 109, 109, 109, 110, 110,
- 110, 111, 111, 111, 112, 112, 112, 112, 113, 113, 113, 114, 114, 114, 115, 115, 115, 115,
- 116, 116, 116, 117, 117, 117, 117, 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, 121,
- 121, 121, 121, 122, 122, 122, 123, 123, 123, 123, 124, 124, 124, 124, 125, 125, 125, 125,
- 126, 126, 126, 127, 127, 127, 127, 128, 128, 128, 128, 129, 129, 129, 129, 130, 130, 130,
- 130, 131, 131, 131, 131, 132, 132, 132, 132, 133, 133, 133, 133, 134, 134, 134, 134, 135,
- 135, 135, 135, 136, 136, 136, 136, 137, 137, 137, 137, 138, 138, 138, 138, 138, 139, 139,
- 139, 139, 140, 140, 140, 140, 141, 141, 141, 141, 142, 142, 142, 142, 142, 143, 143, 143,
- 143, 144, 144, 144, 144, 144, 145, 145, 145, 145, 146, 146, 146, 146, 146, 147, 147, 147,
- 147, 148, 148, 148, 148, 148, 149, 149, 149, 149, 149, 150, 150, 150, 150, 151, 151, 151,
- 151, 151, 152, 152, 152, 152, 152, 153, 153, 153, 153, 154, 154, 154, 154, 154, 155, 155,
- 155, 155, 155, 156, 156, 156, 156, 156, 157, 157, 157, 157, 157, 158, 158, 158, 158, 158,
- 159, 159, 159, 159, 159, 160, 160, 160, 160, 160, 161, 161, 161, 161, 161, 162, 162, 162,
- 162, 162, 163, 163, 163, 163, 163, 164, 164, 164, 164, 164, 165, 165, 165, 165, 165, 165,
- 166, 166, 166, 166, 166, 167, 167, 167, 167, 167, 168, 168, 168, 168, 168, 168, 169, 169,
- 169, 169, 169, 170, 170, 170, 170, 170, 171, 171, 171, 171, 171, 171, 172, 172, 172, 172,
- 172, 173, 173, 173, 173, 173, 173, 174, 174, 174, 174, 174, 174, 175, 175, 175, 175, 175,
- 176, 176, 176, 176, 176, 176, 177, 177, 177, 177, 177, 177, 178, 178, 178, 178, 178, 179,
- 179, 179, 179, 179, 179, 180, 180, 180, 180, 180, 180, 181, 181, 181, 181, 181, 181, 182,
- 182, 182, 182, 182, 182, 183, 183, 183, 183, 183, 183, 184, 184, 184, 184, 184, 185, 185,
- 185, 185, 185, 185, 186, 186, 186, 186, 186, 186, 186, 187, 187, 187, 187, 187, 187, 188,
- 188, 188, 188, 188, 188, 189, 189, 189, 189, 189, 189, 190, 190, 190, 190, 190, 190, 191,
- 191, 191, 191, 191, 191, 192, 192, 192, 192, 192, 192, 192, 193, 193, 193, 193, 193, 193,
- 194, 194, 194, 194, 194, 194, 195, 195, 195, 195, 195, 195, 195, 196, 196, 196, 196, 196,
- 196, 197, 197, 197, 197, 197, 197, 197, 198, 198, 198, 198, 198, 198, 199, 199, 199, 199,
- 199, 199, 199, 200, 200, 200, 200, 200, 200, 201, 201, 201, 201, 201, 201, 201, 202, 202,
- 202, 202, 202, 202, 202, 203, 203, 203, 203, 203, 203, 204, 204, 204, 204, 204, 204, 204,
- 205, 205, 205, 205, 205, 205, 205, 206, 206, 206, 206, 206, 206, 206, 207, 207, 207, 207,
- 207, 207, 207, 208, 208, 208, 208, 208, 208, 209, 209, 209, 209, 209, 209, 209, 210, 210,
- 210, 210, 210, 210, 210, 211, 211, 211, 211, 211, 211, 211, 212, 212, 212, 212, 212, 212,
- 212, 213, 213, 213, 213, 213, 213, 213, 213, 214, 214, 214, 214, 214, 214, 214, 215, 215,
- 215, 215, 215, 215, 215, 216, 216, 216, 216, 216, 216, 216, 217, 217, 217, 217, 217, 217,
- 217, 218, 218, 218, 218, 218, 218, 218, 218, 219, 219, 219, 219, 219, 219, 219, 220, 220,
- 220, 220, 220, 220, 220, 221, 221, 221, 221, 221, 221, 221, 221, 222, 222, 222, 222, 222,
- 222, 222, 223, 223, 223, 223, 223, 223, 223, 223, 224, 224, 224, 224, 224, 224, 224, 225,
- 225, 225, 225, 225, 225, 225, 225, 226, 226, 226, 226, 226, 226, 226, 226, 227, 227, 227,
- 227, 227, 227, 227, 228, 228, 228, 228, 228, 228, 228, 228, 229, 229, 229, 229, 229, 229,
- 229, 229, 230, 230, 230, 230, 230, 230, 230, 230, 231, 231, 231, 231, 231, 231, 231, 232,
- 232, 232, 232, 232, 232, 232, 232, 233, 233, 233, 233, 233, 233, 233, 233, 234, 234, 234,
- 234, 234, 234, 234, 234, 235, 235, 235, 235, 235, 235, 235, 235, 236, 236, 236, 236, 236,
- 236, 236, 236, 237, 237, 237, 237, 237, 237, 237, 237, 238, 238, 238, 238, 238, 238, 238,
- 238, 238, 239, 239, 239, 239, 239, 239, 239, 239, 240, 240, 240, 240, 240, 240, 240, 240,
- 241, 241, 241, 241, 241, 241, 241, 241, 242, 242, 242, 242, 242, 242, 242, 242, 243, 243,
- 243, 243, 243, 243, 243, 243, 243, 244, 244, 244, 244, 244, 244, 244, 244, 245, 245, 245,
- 245, 245, 245, 245, 245, 245, 246, 246, 246, 246, 246, 246, 246, 246, 247, 247, 247, 247,
- 247, 247, 247, 247, 248, 248, 248, 248, 248, 248, 248, 248, 248, 249, 249, 249, 249, 249,
- 249, 249, 249, 249, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 251, 251, 251,
- 251, 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 253, 253, 253,
- 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255,
-};
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
static void build_table_linear_from_gamma(float* outTable, float exponent) {
for (float x = 0.0f; x <= 1.0f; x += (1.0f/255.0f)) {
*outTable++ = powf(x, exponent);
@@ -369,8 +247,8 @@ static const GammaFns<float> kToLinear {
};
static const GammaFns<uint8_t> kFromLinear {
- linear_to_srgb,
- linear_to_2dot2_table,
+ nullptr,
+ nullptr,
&build_table_linear_to_gamma,
&build_table_linear_to_gamma,
&build_table_linear_to_gamma,
@@ -388,8 +266,7 @@ static void build_gamma_tables(const T* outGammaTables[3], T* gammaTableStorage,
outGammaTables[0] = outGammaTables[1] = outGammaTables[2] = fns.f2Dot2Table;
break;
case kLinear_SkGammaNamed:
- (*fns.fBuildFromValue)(gammaTableStorage, 1.0f);
- outGammaTables[0] = outGammaTables[1] = outGammaTables[2] = gammaTableStorage;
+ outGammaTables[0] = outGammaTables[1] = outGammaTables[2] = nullptr;
break;
default: {
const SkGammas* gammas = as_CSB(space)->gammas();
@@ -410,10 +287,13 @@ static void build_gamma_tables(const T* outGammaTables[3], T* gammaTableStorage,
if (gammas->isNamed(i)) {
switch (gammas->data(i).fNamed) {
case kSRGB_SkGammaNamed:
- outGammaTables[i] = fns.fSRGBTable;
+ (*fns.fBuildFromParam)(&gammaTableStorage[i * gammaTableSize], 2.4f,
+ (1.0f / 1.055f), (0.055f / 1.055f), 0.0f,
+ 0.04045, (1.0f / 12.92), 0.0f);
break;
case k2Dot2Curve_SkGammaNamed:
- outGammaTables[i] = fns.f2Dot2Table;
+ (*fns.fBuildFromValue)(&gammaTableStorage[i * gammaTableSize], 2.2f);
+ outGammaTables[i] = &gammaTableStorage[i * gammaTableSize];
break;
case kLinear_SkGammaNamed:
(*fns.fBuildFromValue)(&gammaTableStorage[i * gammaTableSize], 1.0f);
@@ -498,6 +378,10 @@ std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(const sk_sp<SkColorSpa
return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
<k2Dot2Curve_SkGammaNamed, kNone_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
+ case kLinear_SkGammaNamed:
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ <kLinear_SkGammaNamed, kNone_ColorSpaceMatch>
+ (srcSpace, srcToDst, dstSpace));
default:
return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
<kNonStandard_SkGammaNamed, kNone_ColorSpaceMatch>
@@ -513,6 +397,10 @@ std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(const sk_sp<SkColorSpa
return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
<k2Dot2Curve_SkGammaNamed, kGamut_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
+ case kLinear_SkGammaNamed:
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ <kLinear_SkGammaNamed, kGamut_ColorSpaceMatch>
+ (srcSpace, srcToDst, dstSpace));
default:
return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
<kNonStandard_SkGammaNamed, kGamut_ColorSpaceMatch>
@@ -528,6 +416,10 @@ std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(const sk_sp<SkColorSpa
return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
<k2Dot2Curve_SkGammaNamed, kFull_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
+ case kLinear_SkGammaNamed:
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ <kLinear_SkGammaNamed, kFull_ColorSpaceMatch>
+ (srcSpace, srcToDst, dstSpace));
default:
return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
<kNonStandard_SkGammaNamed, kFull_ColorSpaceMatch>
@@ -721,11 +613,28 @@ static inline void load_rgba_from_tables(const uint32_t* src,
a = (1.0f / 255.0f) * SkNx_cast<float>(Sk4u::Load(src) >> 24);
}
+static inline void load_rgb_linear(const uint32_t* src,
+ Sk4f& r, Sk4f& g, Sk4f& b, Sk4f&,
+ const float* const[3]) {
+ r = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) ) & 0xFF);
+ g = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) >> 8) & 0xFF);
+ b = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) >> 16) & 0xFF);
+}
+
+static inline void load_rgba_linear(const uint32_t* src,
+ Sk4f& r, Sk4f& g, Sk4f& b, Sk4f& a,
+ const float* const[3]) {
+ r = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) ) & 0xFF);
+ g = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) >> 8) & 0xFF);
+ b = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) >> 16) & 0xFF);
+ a = (1.0f / 255.0f) * SkNx_cast<float>((Sk4u::Load(src) >> 24) );
+}
+
static inline void load_rgb_from_tables_1(const uint32_t* src,
Sk4f& r, Sk4f& g, Sk4f& b, Sk4f&,
const float* const srcTables[3]) {
// Splat r,g,b across a register each.
- r = Sk4f(srcTables[0][(*src >> 0) & 0xFF]);
+ r = Sk4f(srcTables[0][(*src ) & 0xFF]);
g = Sk4f(srcTables[1][(*src >> 8) & 0xFF]);
b = Sk4f(srcTables[2][(*src >> 16) & 0xFF]);
}
@@ -733,13 +642,32 @@ static inline void load_rgb_from_tables_1(const uint32_t* src,
static inline void load_rgba_from_tables_1(const uint32_t* src,
Sk4f& r, Sk4f& g, Sk4f& b, Sk4f& a,
const float* const srcTables[3]) {
- // Splat r,g,b across a register each.
- r = Sk4f(srcTables[0][(*src >> 0) & 0xFF]);
+ // Splat r,g,b,a across a register each.
+ r = Sk4f(srcTables[0][(*src ) & 0xFF]);
g = Sk4f(srcTables[1][(*src >> 8) & 0xFF]);
b = Sk4f(srcTables[2][(*src >> 16) & 0xFF]);
a = (1.0f / 255.0f) * Sk4f(*src >> 24);
}
+static inline void load_rgb_linear_1(const uint32_t* src,
+ Sk4f& r, Sk4f& g, Sk4f& b, Sk4f&,
+ const float* const srcTables[3]) {
+ // Splat r,g,b across a register each.
+ r = Sk4f((1.0f / 255.0f) * ((*src ) & 0xFF));
+ g = Sk4f((1.0f / 255.0f) * ((*src >> 8) & 0xFF));
+ b = Sk4f((1.0f / 255.0f) * ((*src >> 16) & 0xFF));
+}
+
+static inline void load_rgba_linear_1(const uint32_t* src,
+ Sk4f& r, Sk4f& g, Sk4f& b, Sk4f& a,
+ const float* const srcTables[3]) {
+ // Splat r,g,b,a across a register each.
+ r = Sk4f((1.0f / 255.0f) * ((*src ) & 0xFF));
+ g = Sk4f((1.0f / 255.0f) * ((*src >> 8) & 0xFF));
+ b = Sk4f((1.0f / 255.0f) * ((*src >> 16) & 0xFF));
+ a = Sk4f((1.0f / 255.0f) * ((*src >> 24) ));
+}
+
static inline void transform_gamut(const Sk4f& r, const Sk4f& g, const Sk4f& b, const Sk4f& a,
const Sk4f& rXgXbX, const Sk4f& rYgYbY, const Sk4f& rZgZbZ,
Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f& da) {
@@ -871,6 +799,45 @@ static inline void store_2dot2_1(void* dst, const uint32_t* src,
*(uint32_t*)dst = tmp;
}
+static inline void store_linear(void* dst, const uint32_t* src,
+ Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f&,
+ const uint8_t* const[3], SwapRB kSwapRB) {
+ int kRShift = 0;
+ int kGShift = 8;
+ int kBShift = 16;
+ if (kYes_SwapRB == kSwapRB) {
+ kBShift = 0;
+ kRShift = 16;
+ }
+
+ dr = sk_clamp_0_255(dr);
+ dg = sk_clamp_0_255(dg);
+ db = sk_clamp_0_255(db);
+
+ Sk4i da = Sk4i::Load(src) & 0xFF000000;
+
+ Sk4i rgba = (Sk4f_round(dr) << kRShift)
+ | (Sk4f_round(dg) << kGShift)
+ | (Sk4f_round(db) << kBShift)
+ | (da );
+ rgba.store(dst);
+}
+
+static inline void store_linear_1(void* dst, const uint32_t* src,
+ Sk4f& rgba, const Sk4f&,
+ const uint8_t* const[3], SwapRB kSwapRB) {
+ rgba = sk_clamp_0_255(rgba);
+
+ uint32_t tmp;
+ SkNx_cast<uint8_t>(Sk4f_round(rgba)).store(&tmp);
+ tmp = (*src & 0xFF000000) | (tmp & 0x00FFFFFF);
+ if (kYes_SwapRB == kSwapRB) {
+ tmp = SkSwizzle_RB(tmp);
+ }
+
+ *(uint32_t*)dst = tmp;
+}
+
static inline void store_f16(void* dst, const uint32_t* src,
Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f& da,
const uint8_t* const[3], SwapRB) {
@@ -966,51 +933,76 @@ static inline void store_generic_1(void* dst, const uint32_t* src,
| (*src & 0xFF000000);
}
-template <SkGammaNamed kDstGamma,
+enum Src : uint8_t {
+ kTable_Src,
+ kLinear_Src,
+};
+
+enum Dst : uint8_t {
+ // Making these enums correspond to the SkGammaNamed enum allows us to avoid
+ // converting between enums.
+ kLinear_8888_Dst = kLinear_SkGammaNamed,
+ kSRGB_8888_Dst = kSRGB_SkGammaNamed,
+ k2Dot2_8888_Dst = k2Dot2Curve_SkGammaNamed,
+ kGeneric_8888_Dst = kNonStandard_SkGammaNamed,
+ kLinear_F16_Dst,
+};
+
+template <Src kSrc,
+ Dst kDst,
ColorSpaceMatch kCSM,
SkAlphaType kAlphaType,
SwapRB kSwapRB>
static void color_xform_RGBA(void* dst, const uint32_t* src, int len,
const float* const srcTables[3], const float matrix[16],
const uint8_t* const dstTables[3]) {
- decltype(store_srgb )* store;
- decltype(store_srgb_1 )* store_1;
decltype(load_rgb_from_tables )* load;
decltype(load_rgb_from_tables_1)* load_1;
+ if (kSrc == kTable_Src) {
+ if (kPremul_SkAlphaType == kAlphaType || kLinear_F16_Dst == kDst) {
+ load = load_rgba_from_tables;
+ load_1 = load_rgba_from_tables_1;
+ } else {
+ load = load_rgb_from_tables;
+ load_1 = load_rgb_from_tables_1;
+ }
+ } else {
+ if (kPremul_SkAlphaType == kAlphaType || kLinear_F16_Dst == kDst) {
+ load = load_rgba_linear;
+ load_1 = load_rgba_linear_1;
+ } else {
+ load = load_rgb_linear;
+ load_1 = load_rgb_linear_1;
+ }
+ }
+
+ decltype(store_srgb )* store;
+ decltype(store_srgb_1 )* store_1;
size_t sizeOfDstPixel;
- switch (kDstGamma) {
- case kSRGB_SkGammaNamed:
- load = (kPremul_SkAlphaType == kAlphaType) ? load_rgba_from_tables :
- load_rgb_from_tables;
- load_1 = (kPremul_SkAlphaType == kAlphaType) ? load_rgba_from_tables_1 :
- load_rgb_from_tables_1;
+ switch (kDst) {
+ case kLinear_8888_Dst:
+ store = store_linear;
+ store_1 = store_linear_1;
+ sizeOfDstPixel = 4;
+ break;
+ case kSRGB_8888_Dst:
store = store_srgb;
store_1 = store_srgb_1;
sizeOfDstPixel = 4;
break;
- case k2Dot2Curve_SkGammaNamed:
- load = (kPremul_SkAlphaType == kAlphaType) ? load_rgba_from_tables :
- load_rgb_from_tables;
- load_1 = (kPremul_SkAlphaType == kAlphaType) ? load_rgba_from_tables_1 :
- load_rgb_from_tables_1;
+ case k2Dot2_8888_Dst:
store = store_2dot2;
store_1 = store_2dot2_1;
sizeOfDstPixel = 4;
break;
- case kLinear_SkGammaNamed:
- load = load_rgba_from_tables;
- load_1 = load_rgba_from_tables_1;
+ case kLinear_F16_Dst:
store = (kOpaque_SkAlphaType == kAlphaType) ? store_f16_opaque :
store_f16;
store_1 = (kOpaque_SkAlphaType == kAlphaType) ? store_f16_1_opaque :
store_f16_1;
sizeOfDstPixel = 8;
break;
- case kNonStandard_SkGammaNamed:
- load = (kPremul_SkAlphaType == kAlphaType) ? load_rgba_from_tables :
- load_rgb_from_tables;
- load_1 = (kPremul_SkAlphaType == kAlphaType) ? load_rgba_from_tables_1 :
- load_rgb_from_tables_1;
+ case kGeneric_8888_Dst:
store = store_generic;
store_1 = store_generic_1;
sizeOfDstPixel = 4;
@@ -1148,59 +1140,116 @@ const
src = (const uint32_t*) storage.get();
}
- switch (dstAlphaType) {
- case kPremul_SkAlphaType:
- switch (dstColorType) {
- case kRGBA_8888_SkColorType:
- return color_xform_RGBA<kDst, kCSM, kPremul_SkAlphaType, kNo_SwapRB>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
- case kBGRA_8888_SkColorType:
- return color_xform_RGBA<kDst, kCSM, kPremul_SkAlphaType, kYes_SwapRB>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
- case kRGBA_F16_SkColorType:
- return color_xform_RGBA<kLinear_SkGammaNamed, kCSM,
- kPremul_SkAlphaType, kNo_SwapRB>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
- default:
- SkASSERT(false);
- return;
- }
- break;
- case kUnpremul_SkAlphaType:
- switch (dstColorType) {
- case kRGBA_8888_SkColorType:
- return color_xform_RGBA<kDst, kCSM, kUnpremul_SkAlphaType, kNo_SwapRB>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
- case kBGRA_8888_SkColorType:
- return color_xform_RGBA<kDst, kCSM, kUnpremul_SkAlphaType, kYes_SwapRB>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
- case kRGBA_F16_SkColorType:
- return color_xform_RGBA<kLinear_SkGammaNamed, kCSM,
- kUnpremul_SkAlphaType, kNo_SwapRB>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
- default:
- SkASSERT(false);
- return;
- }
- case kOpaque_SkAlphaType:
- switch (dstColorType) {
- case kRGBA_8888_SkColorType:
- return color_xform_RGBA<kDst, kCSM, kOpaque_SkAlphaType, kNo_SwapRB>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
- case kBGRA_8888_SkColorType:
- return color_xform_RGBA<kDst, kCSM, kOpaque_SkAlphaType, kYes_SwapRB>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
- case kRGBA_F16_SkColorType:
- return color_xform_RGBA<kLinear_SkGammaNamed, kCSM,
- kOpaque_SkAlphaType, kNo_SwapRB>
- (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
- default:
- SkASSERT(false);
- return;
- }
- default:
- SkASSERT(false);
- return;
+ if (fSrcGammaTables[0]) {
+ switch (dstAlphaType) {
+ case kPremul_SkAlphaType:
+ switch (dstColorType) {
+ case kRGBA_8888_SkColorType:
+ return color_xform_RGBA<kTable_Src, (Dst) kDst, kCSM, kPremul_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kBGRA_8888_SkColorType:
+ return color_xform_RGBA<kTable_Src, (Dst) kDst, kCSM, kPremul_SkAlphaType, kYes_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kRGBA_F16_SkColorType:
+ return color_xform_RGBA<kTable_Src, kLinear_F16_Dst, kCSM,
+ kPremul_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ default:
+ SkASSERT(false);
+ return;
+ }
+ break;
+ case kUnpremul_SkAlphaType:
+ switch (dstColorType) {
+ case kRGBA_8888_SkColorType:
+ return color_xform_RGBA<kTable_Src, (Dst) kDst, kCSM, kUnpremul_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kBGRA_8888_SkColorType:
+ return color_xform_RGBA<kTable_Src, (Dst) kDst, kCSM, kUnpremul_SkAlphaType, kYes_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kRGBA_F16_SkColorType:
+ return color_xform_RGBA<kTable_Src, kLinear_F16_Dst, kCSM,
+ kUnpremul_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ default:
+ SkASSERT(false);
+ return;
+ }
+ case kOpaque_SkAlphaType:
+ switch (dstColorType) {
+ case kRGBA_8888_SkColorType:
+ return color_xform_RGBA<kTable_Src, (Dst) kDst, kCSM, kOpaque_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kBGRA_8888_SkColorType:
+ return color_xform_RGBA<kTable_Src, (Dst) kDst, kCSM, kOpaque_SkAlphaType, kYes_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kRGBA_F16_SkColorType:
+ return color_xform_RGBA<kTable_Src, kLinear_F16_Dst, kCSM,
+ kOpaque_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ default:
+ SkASSERT(false);
+ return;
+ }
+ default:
+ SkASSERT(false);
+ return;
+ }
+ } else {
+ switch (dstAlphaType) {
+ case kPremul_SkAlphaType:
+ switch (dstColorType) {
+ case kRGBA_8888_SkColorType:
+ return color_xform_RGBA<kLinear_Src, (Dst) kDst, kCSM, kPremul_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kBGRA_8888_SkColorType:
+ return color_xform_RGBA<kLinear_Src, (Dst) kDst, kCSM, kPremul_SkAlphaType, kYes_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kRGBA_F16_SkColorType:
+ return color_xform_RGBA<kLinear_Src, kLinear_F16_Dst, kCSM,
+ kPremul_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ default:
+ SkASSERT(false);
+ return;
+ }
+ break;
+ case kUnpremul_SkAlphaType:
+ switch (dstColorType) {
+ case kRGBA_8888_SkColorType:
+ return color_xform_RGBA<kLinear_Src, (Dst) kDst, kCSM, kUnpremul_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kBGRA_8888_SkColorType:
+ return color_xform_RGBA<kLinear_Src, (Dst) kDst, kCSM, kUnpremul_SkAlphaType, kYes_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kRGBA_F16_SkColorType:
+ return color_xform_RGBA<kLinear_Src, kLinear_F16_Dst, kCSM,
+ kUnpremul_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ default:
+ SkASSERT(false);
+ return;
+ }
+ case kOpaque_SkAlphaType:
+ switch (dstColorType) {
+ case kRGBA_8888_SkColorType:
+ return color_xform_RGBA<kLinear_Src, (Dst) kDst, kCSM, kOpaque_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kBGRA_8888_SkColorType:
+ return color_xform_RGBA<kLinear_Src, (Dst) kDst, kCSM, kOpaque_SkAlphaType, kYes_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ case kRGBA_F16_SkColorType:
+ return color_xform_RGBA<kLinear_Src, kLinear_F16_Dst, kCSM,
+ kOpaque_SkAlphaType, kNo_SwapRB>
+ (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables);
+ default:
+ SkASSERT(false);
+ return;
+ }
+ default:
+ SkASSERT(false);
+ return;
+ }
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698