Chromium Code Reviews| 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 RGBA8888 { | 711 kRGBA = false, |
| 712 kBGRA = true, | |
| 713 }; | |
| 714 template <SkColorProfileType colorProfile, ColorOrder colorOrder> | |
| 715 class Pixel8888 { | |
| 712 public: | 716 public: |
| 713 RGBA8888(int width, const uint32_t* src) | 717 Pixel8888(int width, const uint32_t* src) |
| 714 : fSrc{src}, fWidth{width}{ } | 718 : fSrc{src}, fWidth{width}{ } |
| 715 | 719 |
| 716 void VECTORCALL getFewPixels(int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2) { | 720 void VECTORCALL getFewPixels(int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2) { |
| 717 Sk4i XIs = SkNx_cast<int, SkScalar>(xs); | 721 Sk4i XIs = SkNx_cast<int, SkScalar>(xs); |
| 718 Sk4i YIs = SkNx_cast<int, SkScalar>(ys); | 722 Sk4i YIs = SkNx_cast<int, SkScalar>(ys); |
| 719 Sk4i bufferLoc = YIs * fWidth + XIs; | 723 Sk4i bufferLoc = YIs * fWidth + XIs; |
| 720 switch (n) { | 724 switch (n) { |
| 721 case 3: | 725 case 3: |
| 722 *px2 = this->getPixel(fSrc, bufferLoc[2]); | 726 *px2 = this->getPixel(fSrc, bufferLoc[2]); |
| 723 case 2: | 727 case 2: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 742 void get4Pixels(const uint32_t* src, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) { | 746 void get4Pixels(const uint32_t* src, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) { |
| 743 *px0 = this->getPixel(src, index + 0); | 747 *px0 = this->getPixel(src, index + 0); |
| 744 *px1 = this->getPixel(src, index + 1); | 748 *px1 = this->getPixel(src, index + 1); |
| 745 *px2 = this->getPixel(src, index + 2); | 749 *px2 = this->getPixel(src, index + 2); |
| 746 *px3 = this->getPixel(src, index + 3); | 750 *px3 = this->getPixel(src, index + 3); |
| 747 } | 751 } |
| 748 | 752 |
| 749 Sk4f getPixel(const uint32_t* src, int index) { | 753 Sk4f getPixel(const uint32_t* src, int index) { |
| 750 Sk4b bytePixel = Sk4b::Load((uint8_t *)(&src[index])); | 754 Sk4b bytePixel = Sk4b::Load((uint8_t *)(&src[index])); |
| 751 Sk4f pixel = SkNx_cast<float, uint8_t>(bytePixel); | 755 Sk4f pixel = SkNx_cast<float, uint8_t>(bytePixel); |
| 756 if (colorOrder == ColorOrder::kBGRA) { | |
| 757 pixel = SkNx_shuffle<2, 1, 0, 3>(pixel); | |
| 758 } | |
| 752 pixel = pixel * Sk4f{1.0f/255.0f}; | 759 pixel = pixel * Sk4f{1.0f/255.0f}; |
| 753 if (colorProfile == kSRGB_SkColorProfileType) { | 760 if (colorProfile == kSRGB_SkColorProfileType) { |
| 754 pixel = sRGBFast::sRGBToLinear(pixel); | 761 pixel = sRGBFast::sRGBToLinear(pixel); |
| 755 } | 762 } |
| 756 return pixel; | 763 return pixel; |
| 757 } | 764 } |
| 758 | 765 |
| 759 const uint32_t* row(int y) { return fSrc + y * fWidth[0]; } | 766 const uint32_t* row(int y) { return fSrc + y * fWidth[0]; } |
| 760 | 767 |
| 761 private: | 768 private: |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 SourceStrategy fStrategy; | 913 SourceStrategy fStrategy; |
| 907 }; | 914 }; |
| 908 | 915 |
| 909 static SkLinearBitmapPipeline::BilerpProcessorInterface* choose_pixel_sampler( | 916 static SkLinearBitmapPipeline::BilerpProcessorInterface* choose_pixel_sampler( |
| 910 SkLinearBitmapPipeline::PixelPlacerInterface* next, | 917 SkLinearBitmapPipeline::PixelPlacerInterface* next, |
| 911 const SkPixmap& srcPixmap, | 918 const SkPixmap& srcPixmap, |
| 912 SkLinearBitmapPipeline::SampleStage* sampleStage) { | 919 SkLinearBitmapPipeline::SampleStage* sampleStage) { |
| 913 const SkImageInfo& imageInfo = srcPixmap.info(); | 920 const SkImageInfo& imageInfo = srcPixmap.info(); |
| 914 switch (imageInfo.colorType()) { | 921 switch (imageInfo.colorType()) { |
| 915 case kRGBA_8888_SkColorType: | 922 case kRGBA_8888_SkColorType: |
| 923 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { | |
| 924 sampleStage->Initialize<Sampler<Pixel8888<kSRGB_SkColorProfileTy pe, | |
|
mtklein
2016/02/29 22:04:26
these calls to Initialize() are not very pretty.
mtklein
2016/03/01 15:17:55
Very pretty now!
| |
| 925 ColorOrder::kRGBA>>>( | |
| 926 next, static_cast<int>(srcPixmap.rowBytes() / 4), | |
| 927 srcPixmap.addr32()); | |
| 928 } else { | |
| 929 sampleStage->Initialize<Sampler<Pixel8888<kLinear_SkColorProfile Type, | |
| 930 ColorOrder::kRGBA>>>( | |
| 931 next, static_cast<int>(srcPixmap.rowBytes() / 4), | |
| 932 srcPixmap.addr32()); | |
| 933 } | |
| 934 break; | |
| 916 case kBGRA_8888_SkColorType: | 935 case kBGRA_8888_SkColorType: |
| 917 if (kN32_SkColorType == imageInfo.colorType()) { | 936 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { |
| 918 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { | 937 sampleStage->Initialize<Sampler<Pixel8888<kSRGB_SkColorProfileTy pe, |
| 919 sampleStage->Initialize<Sampler<RGBA8888<kSRGB_SkColorProfil eType>>>( | 938 ColorOrder::kBGRA>>>( |
| 920 next, static_cast<int>(srcPixmap.rowBytes() / 4), | 939 next, static_cast<int>(srcPixmap.rowBytes() / 4), |
| 921 srcPixmap.addr32()); | 940 srcPixmap.addr32()); |
| 922 } else { | |
| 923 sampleStage->Initialize<Sampler<RGBA8888<kLinear_SkColorProf ileType>>>( | |
| 924 next, static_cast<int>(srcPixmap.rowBytes() / 4), | |
| 925 srcPixmap.addr32()); | |
| 926 } | |
| 927 } else { | 941 } else { |
| 928 SkFAIL("Not implemented. No 8888 Swizzle"); | 942 sampleStage->Initialize<Sampler<Pixel8888<kLinear_SkColorProfile Type, |
| 943 ColorOrder::kBGRA>>>( | |
| 944 next, static_cast<int>(srcPixmap.rowBytes() / 4), | |
| 945 srcPixmap.addr32()); | |
| 929 } | 946 } |
| 930 break; | 947 break; |
| 931 default: | 948 default: |
| 932 SkFAIL("Not implemented. Unsupported src"); | 949 SkFAIL("Not implemented. Unsupported src"); |
| 933 break; | 950 break; |
| 934 } | 951 } |
| 935 return sampleStage->get(); | 952 return sampleStage->get(); |
| 936 } | 953 } |
| 937 | 954 |
| 938 template <SkAlphaType alphaType> | 955 template <SkAlphaType alphaType> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 | 1024 |
| 1008 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { | 1025 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { |
| 1009 SkASSERT(count > 0); | 1026 SkASSERT(count > 0); |
| 1010 fPixelStage->setDestination(dst); | 1027 fPixelStage->setDestination(dst); |
| 1011 // The count and length arguments start out in a precise relation in order t o keep the | 1028 // The count and length arguments start out in a precise relation in order t o keep the |
| 1012 // math correct through the different stages. Count is the number of pixel t o produce. | 1029 // math correct through the different stages. Count is the number of pixel t o produce. |
| 1013 // Since the code samples at pixel centers, length is the distance from the center of the | 1030 // Since the code samples at pixel centers, length is the distance from the center of the |
| 1014 // first pixel to the center of the last pixel. This implies that length is count-1. | 1031 // first pixel to the center of the last pixel. This implies that length is count-1. |
| 1015 fFirstStage->pointSpan(Span{SkPoint{x + 0.5f, y + 0.5f}, count - 1.0f, count }); | 1032 fFirstStage->pointSpan(Span{SkPoint{x + 0.5f, y + 0.5f}, count - 1.0f, count }); |
| 1016 } | 1033 } |
| OLD | NEW |