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 "SkLinearBitmapPipeline.h" | 8 #include "SkLinearBitmapPipeline.h" |
9 #include "SkPM4f.h" | 9 #include "SkPM4f.h" |
10 | 10 |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 } | 706 } |
707 | 707 |
708 class sRGBFast { | 708 class sRGBFast { |
709 public: | 709 public: |
710 static Sk4s VECTORCALL sRGBToLinear(Sk4s pixel) { | 710 static Sk4s VECTORCALL sRGBToLinear(Sk4s pixel) { |
711 Sk4s l = pixel * pixel; | 711 Sk4s l = pixel * pixel; |
712 return Sk4s{l[0], l[1], l[2], pixel[3]}; | 712 return Sk4s{l[0], l[1], l[2], pixel[3]}; |
713 } | 713 } |
714 }; | 714 }; |
715 | 715 |
716 template <SkColorProfileType colorProfile> | 716 enum ShouldSizzle { |
717 kPassthrough = false, | |
718 kSwizzle = true, | |
mtklein_C
2016/02/29 20:15:54
Let's call this kSwapRB or kSwap02? It'd be nice
herb_g
2016/02/29 21:30:58
Done.
| |
719 }; | |
720 template <SkColorProfileType colorProfile, ShouldSizzle swizzle = kPassthrough> | |
717 class RGBA8888 { | 721 class RGBA8888 { |
718 public: | 722 public: |
719 RGBA8888(int width, const uint32_t* src) | 723 RGBA8888(int width, const uint32_t* src) |
720 : fSrc{src}, fWidth{width}{ } | 724 : fSrc{src}, fWidth{width}{ } |
721 | 725 |
722 void VECTORCALL getFewPixels(int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2) { | 726 void VECTORCALL getFewPixels(int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2) { |
723 Sk4i XIs = SkNx_cast<int, SkScalar>(xs); | 727 Sk4i XIs = SkNx_cast<int, SkScalar>(xs); |
724 Sk4i YIs = SkNx_cast<int, SkScalar>(ys); | 728 Sk4i YIs = SkNx_cast<int, SkScalar>(ys); |
725 Sk4i bufferLoc = YIs * fWidth + XIs; | 729 Sk4i bufferLoc = YIs * fWidth + XIs; |
726 switch (n) { | 730 switch (n) { |
(...skipping 20 matching lines...) Expand all Loading... | |
747 | 751 |
748 void get4Pixels(const uint32_t* src, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) { | 752 void get4Pixels(const uint32_t* src, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) { |
749 *px0 = this->getPixel(src, index + 0); | 753 *px0 = this->getPixel(src, index + 0); |
750 *px1 = this->getPixel(src, index + 1); | 754 *px1 = this->getPixel(src, index + 1); |
751 *px2 = this->getPixel(src, index + 2); | 755 *px2 = this->getPixel(src, index + 2); |
752 *px3 = this->getPixel(src, index + 3); | 756 *px3 = this->getPixel(src, index + 3); |
753 } | 757 } |
754 | 758 |
755 Sk4f getPixel(const uint32_t* src, int index) { | 759 Sk4f getPixel(const uint32_t* src, int index) { |
756 Sk4b bytePixel = Sk4b::Load((uint8_t *)(&src[index])); | 760 Sk4b bytePixel = Sk4b::Load((uint8_t *)(&src[index])); |
761 if (kSwizzle == swizzle) { | |
762 bytePixel = SkNx_shuffle<2, 1, 0, 3>(bytePixel); | |
mtklein_C
2016/02/29 20:15:54
Is there some reason we need to swap the bytes bef
herb_g
2016/02/29 21:30:58
Done.
| |
763 } | |
757 Sk4f pixel = SkNx_cast<float, uint8_t>(bytePixel); | 764 Sk4f pixel = SkNx_cast<float, uint8_t>(bytePixel); |
758 pixel = pixel * Sk4f{1.0f/255.0f}; | 765 pixel = pixel * Sk4f{1.0f/255.0f}; |
759 if (colorProfile == kSRGB_SkColorProfileType) { | 766 if (kSRGB_SkColorProfileType == colorProfile) { |
mtklein_C
2016/02/29 20:15:54
This seems fine if you like this style, but I thin
herb_g
2016/02/29 21:30:58
Great. I do not like yoda ==.
| |
760 pixel = sRGBFast::sRGBToLinear(pixel); | 767 pixel = sRGBFast::sRGBToLinear(pixel); |
761 } | 768 } |
762 return pixel; | 769 return pixel; |
763 } | 770 } |
764 | 771 |
765 const uint32_t* row(int y) { return fSrc + y * fWidth[0]; } | 772 const uint32_t* row(int y) { return fSrc + y * fWidth[0]; } |
766 | 773 |
767 private: | 774 private: |
768 const uint32_t* const fSrc; | 775 const uint32_t* const fSrc; |
769 const Sk4i fWidth; | 776 const Sk4i fWidth; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 SourceStrategy fStrategy; | 919 SourceStrategy fStrategy; |
913 }; | 920 }; |
914 | 921 |
915 static SkLinearBitmapPipeline::BilerpProcessorInterface* choose_pixel_sampler( | 922 static SkLinearBitmapPipeline::BilerpProcessorInterface* choose_pixel_sampler( |
916 SkLinearBitmapPipeline::PixelPlacerInterface* next, | 923 SkLinearBitmapPipeline::PixelPlacerInterface* next, |
917 const SkPixmap& srcPixmap, | 924 const SkPixmap& srcPixmap, |
918 SkLinearBitmapPipeline::SampleStage* sampleStage) { | 925 SkLinearBitmapPipeline::SampleStage* sampleStage) { |
919 const SkImageInfo& imageInfo = srcPixmap.info(); | 926 const SkImageInfo& imageInfo = srcPixmap.info(); |
920 switch (imageInfo.colorType()) { | 927 switch (imageInfo.colorType()) { |
921 case kRGBA_8888_SkColorType: | 928 case kRGBA_8888_SkColorType: |
929 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { | |
930 sampleStage->Initialize<Sampler<RGBA8888<kSRGB_SkColorProfileTyp e>>>( | |
931 next, static_cast<int>(srcPixmap.rowBytes() / 4), | |
932 srcPixmap.addr32()); | |
933 } else { | |
934 sampleStage->Initialize<Sampler<RGBA8888<kLinear_SkColorProfileT ype>>>( | |
935 next, static_cast<int>(srcPixmap.rowBytes() / 4), | |
936 srcPixmap.addr32()); | |
937 } | |
938 break; | |
922 case kBGRA_8888_SkColorType: | 939 case kBGRA_8888_SkColorType: |
923 if (kN32_SkColorType == imageInfo.colorType()) { | 940 if (kN32_SkColorType == imageInfo.colorType()) { |
mtklein_C
2016/02/29 20:15:54
remove
herb_g
2016/02/29 21:30:58
Done.
| |
924 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { | 941 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { |
925 sampleStage->Initialize<Sampler<RGBA8888<kSRGB_SkColorProfil eType>>>( | 942 sampleStage->Initialize<Sampler<RGBA8888<kSRGB_SkColorProfil eType, kSwizzle>>>( |
926 next, static_cast<int>(srcPixmap.rowBytes() / 4), | 943 next, static_cast<int>(srcPixmap.rowBytes() / 4), |
927 srcPixmap.addr32()); | 944 srcPixmap.addr32()); |
928 } else { | 945 } else { |
929 sampleStage->Initialize<Sampler<RGBA8888<kLinear_SkColorProf ileType>>>( | 946 sampleStage->Initialize<Sampler<RGBA8888<kLinear_SkColorProf ileType, kSwizzle>>>( |
930 next, static_cast<int>(srcPixmap.rowBytes() / 4), | 947 next, static_cast<int>(srcPixmap.rowBytes() / 4), |
931 srcPixmap.addr32()); | 948 srcPixmap.addr32()); |
932 } | 949 } |
933 } else { | |
934 SkFAIL("Not implemented. No 8888 Swizzle"); | |
935 } | 950 } |
936 break; | 951 break; |
937 default: | 952 default: |
938 SkFAIL("Not implemented. Unsupported src"); | 953 SkFAIL("Not implemented. Unsupported src"); |
939 break; | 954 break; |
940 } | 955 } |
941 return sampleStage->get(); | 956 return sampleStage->get(); |
942 } | 957 } |
943 | 958 |
944 template <SkAlphaType alphaType> | 959 template <SkAlphaType alphaType> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1013 | 1028 |
1014 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { | 1029 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { |
1015 SkASSERT(count > 0); | 1030 SkASSERT(count > 0); |
1016 fPixelStage->setDestination(dst); | 1031 fPixelStage->setDestination(dst); |
1017 // The count and length arguments start out in a precise relation in order t o keep the | 1032 // The count and length arguments start out in a precise relation in order t o keep the |
1018 // math correct through the different stages. Count is the number of pixel t o produce. | 1033 // math correct through the different stages. Count is the number of pixel t o produce. |
1019 // Since the code samples at pixel centers, length is the distance from the center of the | 1034 // Since the code samples at pixel centers, length is the distance from the center of the |
1020 // first pixel to the center of the last pixel. This implies that length is count-1. | 1035 // first pixel to the center of the last pixel. This implies that length is count-1. |
1021 fFirstStage->pointSpan(Span{SkPoint{x + 0.5f, y + 0.5f}, count - 1.0f, count }); | 1036 fFirstStage->pointSpan(Span{SkPoint{x + 0.5f, y + 0.5f}, count - 1.0f, count }); |
1022 } | 1037 } |
OLD | NEW |