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 { |
mtklein
2016/02/29 21:34:07
spelling....
let's either make this an enum class
herb_g
2016/02/29 21:54:56
Done.
| |
717 class RGBA8888 { | 717 k8888Passthrough = false, |
718 k8888RBSwap = true, | |
mtklein
2016/02/29 21:34:07
I don't understand why 8888 is important here?
herb_g
2016/02/29 21:54:56
Acknowledged.
| |
719 }; | |
720 template <SkColorProfileType colorProfile, ShouldSizzle swizzle = k8888Passthrou gh> | |
mtklein
2016/02/29 21:34:07
I think this might read more clearly without a def
herb_g
2016/02/29 21:54:56
Done.
| |
721 class Pixel8888 { | |
718 public: | 722 public: |
719 RGBA8888(int width, const uint32_t* src) | 723 Pixel8888(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) { |
727 case 3: | 731 case 3: |
728 *px2 = this->getPixel(fSrc, bufferLoc[2]); | 732 *px2 = this->getPixel(fSrc, bufferLoc[2]); |
729 case 2: | 733 case 2: |
(...skipping 18 matching lines...) Expand all Loading... | |
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])); |
757 Sk4f pixel = SkNx_cast<float, uint8_t>(bytePixel); | 761 Sk4f pixel = SkNx_cast<float, uint8_t>(bytePixel); |
762 if (swizzle == k8888RBSwap) { | |
763 pixel = SkNx_shuffle<2, 1, 0, 3>(pixel); | |
764 } | |
758 pixel = pixel * Sk4f{1.0f/255.0f}; | 765 pixel = pixel * Sk4f{1.0f/255.0f}; |
759 if (colorProfile == kSRGB_SkColorProfileType) { | 766 if (colorProfile == kSRGB_SkColorProfileType) { |
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: |
(...skipping 144 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<Pixel8888<kSRGB_SkColorProfileTy pe>>>( | |
931 next, static_cast<int>(srcPixmap.rowBytes() / 4), | |
932 srcPixmap.addr32()); | |
933 } else { | |
934 sampleStage->Initialize<Sampler<Pixel8888<kLinear_SkColorProfile Type>>>( | |
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 (imageInfo.profileType() == kSRGB_SkColorProfileType) { |
924 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { | 941 sampleStage->Initialize<Sampler<Pixel8888<kSRGB_SkColorProfileTy pe, k8888RBSwap>>>( |
925 sampleStage->Initialize<Sampler<RGBA8888<kSRGB_SkColorProfil eType>>>( | 942 next, static_cast<int>(srcPixmap.rowBytes() / 4), |
926 next, static_cast<int>(srcPixmap.rowBytes() / 4), | 943 srcPixmap.addr32()); |
927 srcPixmap.addr32()); | |
928 } else { | |
929 sampleStage->Initialize<Sampler<RGBA8888<kLinear_SkColorProf ileType>>>( | |
930 next, static_cast<int>(srcPixmap.rowBytes() / 4), | |
931 srcPixmap.addr32()); | |
932 } | |
933 } else { | 944 } else { |
934 SkFAIL("Not implemented. No 8888 Swizzle"); | 945 sampleStage->Initialize<Sampler<Pixel8888<kLinear_SkColorProfile Type, k8888RBSwap>>>( |
946 next, static_cast<int>(srcPixmap.rowBytes() / 4), | |
947 srcPixmap.addr32()); | |
935 } | 948 } |
936 break; | 949 break; |
937 default: | 950 default: |
938 SkFAIL("Not implemented. Unsupported src"); | 951 SkFAIL("Not implemented. Unsupported src"); |
939 break; | 952 break; |
940 } | 953 } |
941 return sampleStage->get(); | 954 return sampleStage->get(); |
942 } | 955 } |
943 | 956 |
944 template <SkAlphaType alphaType> | 957 template <SkAlphaType alphaType> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1013 | 1026 |
1014 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { | 1027 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { |
1015 SkASSERT(count > 0); | 1028 SkASSERT(count > 0); |
1016 fPixelStage->setDestination(dst); | 1029 fPixelStage->setDestination(dst); |
1017 // The count and length arguments start out in a precise relation in order t o keep the | 1030 // 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. | 1031 // 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 | 1032 // 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. | 1033 // 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 }); | 1034 fFirstStage->pointSpan(Span{SkPoint{x + 0.5f, y + 0.5f}, count - 1.0f, count }); |
1022 } | 1035 } |
OLD | NEW |