OLD | NEW |
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 "SkColorSpace.h" | 8 #include "SkColorSpace.h" |
9 #include "SkColorSpace_Base.h" | 9 #include "SkColorSpace_Base.h" |
10 #include "SkEndian.h" | 10 #include "SkEndian.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 , fToXYZD50(toXYZD50) | 25 , fToXYZD50(toXYZD50) |
26 , fNamed(named) | 26 , fNamed(named) |
27 {} | 27 {} |
28 | 28 |
29 SkColorSpace_Base::SkColorSpace_Base(GammaNamed gammaNamed, const SkMatrix44& to
XYZD50, Named named) | 29 SkColorSpace_Base::SkColorSpace_Base(GammaNamed gammaNamed, const SkMatrix44& to
XYZD50, Named named) |
30 : INHERITED(gammaNamed, toXYZD50, named) | 30 : INHERITED(gammaNamed, toXYZD50, named) |
31 , fGammas(nullptr) | 31 , fGammas(nullptr) |
32 , fProfileData(nullptr) | 32 , fProfileData(nullptr) |
33 {} | 33 {} |
34 | 34 |
35 SkColorSpace_Base::SkColorSpace_Base(SkColorLookUpTable* colorLUT, sk_sp<SkGamma
s> gammas, | 35 SkColorSpace_Base::SkColorSpace_Base(sk_sp<SkColorLookUpTable> colorLUT, sk_sp<S
kGammas> gammas, |
36 const SkMatrix44& toXYZD50, sk_sp<SkData> p
rofileData) | 36 const SkMatrix44& toXYZD50, sk_sp<SkData> p
rofileData) |
37 : INHERITED(kNonStandard_GammaNamed, toXYZD50, kUnknown_Named) | 37 : INHERITED(kNonStandard_GammaNamed, toXYZD50, kUnknown_Named) |
38 , fColorLUT(colorLUT) | 38 , fColorLUT(std::move(colorLUT)) |
39 , fGammas(std::move(gammas)) | 39 , fGammas(std::move(gammas)) |
40 , fProfileData(std::move(profileData)) | 40 , fProfileData(std::move(profileData)) |
41 {} | 41 {} |
42 | 42 |
43 static constexpr float gSRGB_toXYZD50[] { | 43 static constexpr float gSRGB_toXYZD50[] { |
44 0.4358f, 0.2224f, 0.0139f, // * R | 44 0.4358f, 0.2224f, 0.0139f, // * R |
45 0.3853f, 0.7170f, 0.0971f, // * G | 45 0.3853f, 0.7170f, 0.0971f, // * G |
46 0.1430f, 0.0606f, 0.7139f, // * B | 46 0.1430f, 0.0606f, 0.7139f, // * B |
47 }; | 47 }; |
48 | 48 |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 const uint8_t* src, size_t len) { | 670 const uint8_t* src, size_t len) { |
671 // 16 bytes reserved for grid points, 2 for precision, 2 for padding. | 671 // 16 bytes reserved for grid points, 2 for precision, 2 for padding. |
672 // The color LUT data follows after this header. | 672 // The color LUT data follows after this header. |
673 static constexpr uint32_t kColorLUTHeaderSize = 20; | 673 static constexpr uint32_t kColorLUTHeaderSize = 20; |
674 if (len < kColorLUTHeaderSize) { | 674 if (len < kColorLUTHeaderSize) { |
675 SkColorSpacePrintf("Color LUT tag is too small (%d bytes).", len); | 675 SkColorSpacePrintf("Color LUT tag is too small (%d bytes).", len); |
676 return false; | 676 return false; |
677 } | 677 } |
678 size_t dataLen = len - kColorLUTHeaderSize; | 678 size_t dataLen = len - kColorLUTHeaderSize; |
679 | 679 |
680 SkASSERT(inputChannels <= SkColorLookUpTable::kMaxChannels && 3 == outputCha
nnels); | 680 SkASSERT(3 == inputChannels && 3 == outputChannels); |
681 colorLUT->fInputChannels = inputChannels; | 681 colorLUT->fInputChannels = inputChannels; |
682 colorLUT->fOutputChannels = outputChannels; | 682 colorLUT->fOutputChannels = outputChannels; |
683 uint32_t numEntries = 1; | 683 uint32_t numEntries = 1; |
684 for (uint32_t i = 0; i < inputChannels; i++) { | 684 for (uint32_t i = 0; i < inputChannels; i++) { |
685 colorLUT->fGridPoints[i] = src[i]; | 685 colorLUT->fGridPoints[i] = src[i]; |
686 if (0 == src[i]) { | 686 if (0 == src[i]) { |
687 SkColorSpacePrintf("Each input channel must have at least one grid p
oint."); | 687 SkColorSpacePrintf("Each input channel must have at least one grid p
oint."); |
688 return false; | 688 return false; |
689 } | 689 } |
690 | 690 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 if (kTAG_AtoBType != type) { | 776 if (kTAG_AtoBType != type) { |
777 // FIXME (msarett): Need to support lut8Type and lut16Type. | 777 // FIXME (msarett): Need to support lut8Type and lut16Type. |
778 SkColorSpacePrintf("Unsupported A to B tag type.\n"); | 778 SkColorSpacePrintf("Unsupported A to B tag type.\n"); |
779 return false; | 779 return false; |
780 } | 780 } |
781 | 781 |
782 // Read the number of channels. The four bytes that we skipped are reserved
and | 782 // Read the number of channels. The four bytes that we skipped are reserved
and |
783 // must be zero. | 783 // must be zero. |
784 uint8_t inputChannels = src[8]; | 784 uint8_t inputChannels = src[8]; |
785 uint8_t outputChannels = src[9]; | 785 uint8_t outputChannels = src[9]; |
786 if (0 == inputChannels || inputChannels > SkColorLookUpTable::kMaxChannels |
| | 786 if (3 != inputChannels || 3 != outputChannels) { |
787 3 != outputChannels) { | 787 // We only handle (supposedly) RGB inputs and RGB outputs. The numbers
of input |
788 // The color LUT assumes that there are at most 16 input channels. For
RGB | 788 // channels and output channels both must be 3. |
789 // profiles, output channels should be 3. | 789 SkColorSpacePrintf("Input and output channels must equal 3 in A to B tag
.\n"); |
790 SkColorSpacePrintf("Too many input or output channels in A to B tag.\n")
; | |
791 return false; | 790 return false; |
792 } | 791 } |
793 | 792 |
794 // Read the offsets of each element in the A to B tag. With the exception o
f A curves and | 793 // Read the offsets of each element in the A to B tag. With the exception o
f A curves and |
795 // B curves (which we do not yet support), we will handle these elements in
the order in | 794 // B curves (which we do not yet support), we will handle these elements in
the order in |
796 // which they should be applied (rather than the order in which they occur i
n the tag). | 795 // which they should be applied (rather than the order in which they occur i
n the tag). |
797 // If the offset is non-zero it indicates that the element is present. | 796 // If the offset is non-zero it indicates that the element is present. |
798 uint32_t offsetToACurves = read_big_endian_int(src + 28); | 797 uint32_t offsetToACurves = read_big_endian_int(src + 28); |
799 uint32_t offsetToBCurves = read_big_endian_int(src + 12); | 798 uint32_t offsetToBCurves = read_big_endian_int(src + 12); |
800 if ((0 != offsetToACurves) || (0 != offsetToBCurves)) { | 799 if ((0 != offsetToACurves) || (0 != offsetToBCurves)) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 return sk_sp<SkColorSpace>(new SkColorSpace_Base(nullptr, st
d::move(gammas), | 928 return sk_sp<SkColorSpace>(new SkColorSpace_Base(nullptr, st
d::move(gammas), |
930 mat, std::m
ove(data))); | 929 mat, std::m
ove(data))); |
931 } else { | 930 } else { |
932 return SkColorSpace_Base::NewRGB(gammaNamed, mat); | 931 return SkColorSpace_Base::NewRGB(gammaNamed, mat); |
933 } | 932 } |
934 } | 933 } |
935 | 934 |
936 // Recognize color profile specified by A2B0 tag. | 935 // Recognize color profile specified by A2B0 tag. |
937 const ICCTag* a2b0 = ICCTag::Find(tags.get(), tagCount, kTAG_A2B0); | 936 const ICCTag* a2b0 = ICCTag::Find(tags.get(), tagCount, kTAG_A2B0); |
938 if (a2b0) { | 937 if (a2b0) { |
939 SkAutoTDelete<SkColorLookUpTable> colorLUT(new SkColorLookUpTabl
e()); | 938 sk_sp<SkColorLookUpTable> colorLUT = sk_make_sp<SkColorLookUpTab
le>(); |
940 SkGammaCurve curves[3]; | 939 SkGammaCurve curves[3]; |
941 SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); | 940 SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); |
942 if (!load_a2b0(colorLUT, curves, &toXYZ, a2b0->addr((const uint8
_t*) base), | 941 if (!load_a2b0(colorLUT.get(), curves, &toXYZ, a2b0->addr((const
uint8_t*) base), |
943 a2b0->fLength)) { | 942 a2b0->fLength)) { |
944 return_null("Failed to parse A2B0 tag"); | 943 return_null("Failed to parse A2B0 tag"); |
945 } | 944 } |
946 | 945 |
947 GammaNamed gammaNamed = SkGammas::Named(curves); | 946 GammaNamed gammaNamed = SkGammas::Named(curves); |
948 if (colorLUT->fTable || kNonStandard_GammaNamed == gammaNamed) { | 947 colorLUT = colorLUT->fTable ? colorLUT : nullptr; |
| 948 if (colorLUT || kNonStandard_GammaNamed == gammaNamed) { |
949 sk_sp<SkGammas> gammas = sk_make_sp<SkGammas>(std::move(curv
es[0]), | 949 sk_sp<SkGammas> gammas = sk_make_sp<SkGammas>(std::move(curv
es[0]), |
950 std::move(curv
es[1]), | 950 std::move(curv
es[1]), |
951 std::move(curv
es[2])); | 951 std::move(curv
es[2])); |
952 | 952 |
953 return sk_sp<SkColorSpace>(new SkColorSpace_Base(colorLUT.re
lease(), | 953 return sk_sp<SkColorSpace>(new SkColorSpace_Base(std::move(c
olorLUT), |
954 std::move(g
ammas), toXYZ, | 954 std::move(g
ammas), toXYZ, |
955 std::move(d
ata))); | 955 std::move(d
ata))); |
956 } else { | 956 } else { |
957 return SkColorSpace_Base::NewRGB(gammaNamed, toXYZ); | 957 return SkColorSpace_Base::NewRGB(gammaNamed, toXYZ); |
958 } | 958 } |
959 } | 959 } |
960 } | 960 } |
961 default: | 961 default: |
962 break; | 962 break; |
963 } | 963 } |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 | 1350 |
1351 uint32_t profileSize = *((uint32_t*) data); | 1351 uint32_t profileSize = *((uint32_t*) data); |
1352 data = SkTAddOffset<const void>(data, sizeof(uint32_t)); | 1352 data = SkTAddOffset<const void>(data, sizeof(uint32_t)); |
1353 length -= sizeof(uint32_t); | 1353 length -= sizeof(uint32_t); |
1354 if (length < profileSize) { | 1354 if (length < profileSize) { |
1355 return nullptr; | 1355 return nullptr; |
1356 } | 1356 } |
1357 | 1357 |
1358 return NewICC(data, profileSize); | 1358 return NewICC(data, profileSize); |
1359 } | 1359 } |
OLD | NEW |