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 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 } | 700 } |
701 | 701 |
702 class sRGBFast { | 702 class sRGBFast { |
703 public: | 703 public: |
704 static Sk4s VECTORCALL sRGBToLinear(Sk4s pixel) { | 704 static Sk4s VECTORCALL sRGBToLinear(Sk4s pixel) { |
705 Sk4s l = pixel * pixel; | 705 Sk4s l = pixel * pixel; |
706 return Sk4s{l[0], l[1], l[2], pixel[3]}; | 706 return Sk4s{l[0], l[1], l[2], pixel[3]}; |
707 } | 707 } |
708 }; | 708 }; |
709 | 709 |
710 template <SkColorProfileType colorProfile> | 710 enum class ColorOrder { |
711 class Passthrough8888 { | 711 kRGBA = false, |
| 712 kBGRA = true, |
| 713 }; |
| 714 template <SkColorProfileType colorProfile, ColorOrder colorOrder> |
| 715 class Pixel8888 { |
712 public: | 716 public: |
713 Passthrough8888(int width, const uint32_t* src) | 717 Pixel8888(int width, const uint32_t* src) : fSrc{src}, fWidth{width}{ } |
714 : fSrc{src}, fWidth{width}{ } | 718 Pixel8888(const SkPixmap& srcPixmap) |
| 719 : fSrc{srcPixmap.addr32()} |
| 720 , fWidth{static_cast<int>(srcPixmap.rowBytes() / 4)} { } |
715 | 721 |
716 void VECTORCALL getFewPixels(int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1,
Sk4f* px2) { | 722 void VECTORCALL getFewPixels(int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1,
Sk4f* px2) { |
717 Sk4i XIs = SkNx_cast<int, SkScalar>(xs); | 723 Sk4i XIs = SkNx_cast<int, SkScalar>(xs); |
718 Sk4i YIs = SkNx_cast<int, SkScalar>(ys); | 724 Sk4i YIs = SkNx_cast<int, SkScalar>(ys); |
719 Sk4i bufferLoc = YIs * fWidth + XIs; | 725 Sk4i bufferLoc = YIs * fWidth + XIs; |
720 switch (n) { | 726 switch (n) { |
721 case 3: | 727 case 3: |
722 *px2 = getPixel(fSrc, bufferLoc[2]); | 728 *px2 = this->getPixel(fSrc, bufferLoc[2]); |
723 case 2: | 729 case 2: |
724 *px1 = getPixel(fSrc, bufferLoc[1]); | 730 *px1 = this->getPixel(fSrc, bufferLoc[1]); |
725 case 1: | 731 case 1: |
726 *px0 = getPixel(fSrc, bufferLoc[0]); | 732 *px0 = this->getPixel(fSrc, bufferLoc[0]); |
727 default: | 733 default: |
728 break; | 734 break; |
729 } | 735 } |
730 } | 736 } |
731 | 737 |
732 void VECTORCALL get4Pixels(Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2
, Sk4f* px3) { | 738 void VECTORCALL get4Pixels(Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2
, Sk4f* px3) { |
733 Sk4i XIs = SkNx_cast<int, SkScalar>(xs); | 739 Sk4i XIs = SkNx_cast<int, SkScalar>(xs); |
734 Sk4i YIs = SkNx_cast<int, SkScalar>(ys); | 740 Sk4i YIs = SkNx_cast<int, SkScalar>(ys); |
735 Sk4i bufferLoc = YIs * fWidth + XIs; | 741 Sk4i bufferLoc = YIs * fWidth + XIs; |
736 *px0 = getPixel(fSrc, bufferLoc[0]); | 742 *px0 = this->getPixel(fSrc, bufferLoc[0]); |
737 *px1 = getPixel(fSrc, bufferLoc[1]); | 743 *px1 = this->getPixel(fSrc, bufferLoc[1]); |
738 *px2 = getPixel(fSrc, bufferLoc[2]); | 744 *px2 = this->getPixel(fSrc, bufferLoc[2]); |
739 *px3 = getPixel(fSrc, bufferLoc[3]); | 745 *px3 = this->getPixel(fSrc, bufferLoc[3]); |
740 } | 746 } |
741 | 747 |
742 const uint32_t* row(int y) { return fSrc + y * fWidth[0]; } | |
743 | |
744 private: | |
745 Sk4f getPixel(const uint32_t* src, int index) { | 748 Sk4f getPixel(const uint32_t* src, int index) { |
746 Sk4b bytePixel = Sk4b::Load((uint8_t *)(&src[index])); | 749 Sk4b bytePixel = Sk4b::Load((uint8_t *)(&src[index])); |
747 Sk4f pixel = SkNx_cast<float, uint8_t>(bytePixel); | 750 Sk4f pixel = SkNx_cast<float, uint8_t>(bytePixel); |
| 751 if (colorOrder == ColorOrder::kBGRA) { |
| 752 pixel = SkNx_shuffle<2, 1, 0, 3>(pixel); |
| 753 } |
748 pixel = pixel * Sk4f{1.0f/255.0f}; | 754 pixel = pixel * Sk4f{1.0f/255.0f}; |
749 if (colorProfile == kSRGB_SkColorProfileType) { | 755 if (colorProfile == kSRGB_SkColorProfileType) { |
750 pixel = sRGBFast::sRGBToLinear(pixel); | 756 pixel = sRGBFast::sRGBToLinear(pixel); |
751 } | 757 } |
752 return pixel; | 758 return pixel; |
753 } | 759 } |
| 760 |
| 761 const uint32_t* row(int y) { return fSrc + y * fWidth[0]; } |
| 762 |
| 763 private: |
754 const uint32_t* const fSrc; | 764 const uint32_t* const fSrc; |
755 const Sk4i fWidth; | 765 const Sk4i fWidth; |
756 }; | 766 }; |
757 | 767 |
758 // Explaination of the math: | 768 // Explaination of the math: |
759 // 1 - x x | 769 // 1 - x x |
760 // +--------+--------+ | 770 // +--------+--------+ |
761 // | | | | 771 // | | | |
762 // 1 - y | px00 | px10 | | 772 // 1 - y | px00 | px10 | |
763 // | | | | 773 // | | | |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 | 830 |
821 void pointSpan(Span span) override { | 831 void pointSpan(Span span) override { |
822 span_fallback(span, this); | 832 span_fallback(span, this); |
823 } | 833 } |
824 | 834 |
825 private: | 835 private: |
826 SkLinearBitmapPipeline::PixelPlacerInterface* const fNext; | 836 SkLinearBitmapPipeline::PixelPlacerInterface* const fNext; |
827 SourceStrategy fStrategy; | 837 SourceStrategy fStrategy; |
828 }; | 838 }; |
829 | 839 |
| 840 using Pixel8888SRGB = Pixel8888<kSRGB_SkColorProfileType, ColorOrder::kRGBA>; |
| 841 using Pixel8888LRGB = Pixel8888<kLinear_SkColorProfileType, ColorOrder::kRGBA>; |
| 842 using Pixel8888SBGR = Pixel8888<kSRGB_SkColorProfileType, ColorOrder::kBGRA>; |
| 843 using Pixel8888LBGR = Pixel8888<kLinear_SkColorProfileType, ColorOrder::kBGRA>; |
| 844 |
830 static SkLinearBitmapPipeline::BilerpProcessorInterface* choose_pixel_sampler( | 845 static SkLinearBitmapPipeline::BilerpProcessorInterface* choose_pixel_sampler( |
831 SkLinearBitmapPipeline::PixelPlacerInterface* next, | 846 SkLinearBitmapPipeline::PixelPlacerInterface* next, |
832 const SkPixmap& srcPixmap, | 847 const SkPixmap& srcPixmap, |
833 SkLinearBitmapPipeline::SampleStage* sampleStage) { | 848 SkLinearBitmapPipeline::SampleStage* sampleStage) { |
834 const SkImageInfo& imageInfo = srcPixmap.info(); | 849 const SkImageInfo& imageInfo = srcPixmap.info(); |
835 switch (imageInfo.colorType()) { | 850 switch (imageInfo.colorType()) { |
836 case kRGBA_8888_SkColorType: | 851 case kRGBA_8888_SkColorType: |
| 852 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { |
| 853 sampleStage->Initialize<Sampler<Pixel8888SRGB>>(next, srcPixmap)
; |
| 854 } else { |
| 855 sampleStage->Initialize<Sampler<Pixel8888LRGB>>(next, srcPixmap)
; |
| 856 } |
| 857 break; |
837 case kBGRA_8888_SkColorType: | 858 case kBGRA_8888_SkColorType: |
838 if (kN32_SkColorType == imageInfo.colorType()) { | 859 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { |
839 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { | 860 sampleStage->Initialize<Sampler<Pixel8888SBGR>>(next, srcPixmap)
; |
840 sampleStage->Initialize<Sampler<Passthrough8888<kSRGB_SkColo
rProfileType>>>( | |
841 next, static_cast<int>(srcPixmap.rowBytes() / 4), | |
842 srcPixmap.addr32()); | |
843 } else { | |
844 sampleStage->Initialize<Sampler<Passthrough8888<kLinear_SkCo
lorProfileType>>>( | |
845 next, static_cast<int>(srcPixmap.rowBytes() / 4), | |
846 srcPixmap.addr32()); | |
847 } | |
848 } else { | 861 } else { |
849 SkFAIL("Not implemented. No 8888 Swizzle"); | 862 sampleStage->Initialize<Sampler<Pixel8888LBGR>>(next, srcPixmap)
; |
850 } | 863 } |
851 break; | 864 break; |
852 default: | 865 default: |
853 SkFAIL("Not implemented. Unsupported src"); | 866 SkFAIL("Not implemented. Unsupported src"); |
854 break; | 867 break; |
855 } | 868 } |
856 return sampleStage->get(); | 869 return sampleStage->get(); |
857 } | 870 } |
858 | 871 |
859 template <SkAlphaType alphaType> | 872 template <SkAlphaType alphaType> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 | 941 |
929 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { | 942 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { |
930 SkASSERT(count > 0); | 943 SkASSERT(count > 0); |
931 fPixelStage->setDestination(dst); | 944 fPixelStage->setDestination(dst); |
932 // The count and length arguments start out in a precise relation in order t
o keep the | 945 // The count and length arguments start out in a precise relation in order t
o keep the |
933 // math correct through the different stages. Count is the number of pixel t
o produce. | 946 // math correct through the different stages. Count is the number of pixel t
o produce. |
934 // Since the code samples at pixel centers, length is the distance from the
center of the | 947 // Since the code samples at pixel centers, length is the distance from the
center of the |
935 // first pixel to the center of the last pixel. This implies that length is
count-1. | 948 // first pixel to the center of the last pixel. This implies that length is
count-1. |
936 fFirstStage->pointSpan(Span{SkPoint{x + 0.5f, y + 0.5f}, count - 1.0f, count
}); | 949 fFirstStage->pointSpan(Span{SkPoint{x + 0.5f, y + 0.5f}, count - 1.0f, count
}); |
937 } | 950 } |
OLD | NEW |