Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: src/core/SkLinearBitmapPipeline.cpp

Issue 1743123004: Handle spans in sampling. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Sync in the swizzle changes. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 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) {
739 Sk4i XIs = SkNx_cast<int, SkScalar>(xs); 739 Sk4i XIs = SkNx_cast<int, SkScalar>(xs);
740 Sk4i YIs = SkNx_cast<int, SkScalar>(ys); 740 Sk4i YIs = SkNx_cast<int, SkScalar>(ys);
741 Sk4i bufferLoc = YIs * fWidth + XIs; 741 Sk4i bufferLoc = YIs * fWidth + XIs;
742 *px0 = this->getPixel(fSrc, bufferLoc[0]); 742 *px0 = this->getPixel(fSrc, bufferLoc[0]);
743 *px1 = this->getPixel(fSrc, bufferLoc[1]); 743 *px1 = this->getPixel(fSrc, bufferLoc[1]);
744 *px2 = this->getPixel(fSrc, bufferLoc[2]); 744 *px2 = this->getPixel(fSrc, bufferLoc[2]);
745 *px3 = this->getPixel(fSrc, bufferLoc[3]); 745 *px3 = this->getPixel(fSrc, bufferLoc[3]);
746 } 746 }
747 747
748 void get4Pixels(const uint32_t* src, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) {
749 *px0 = this->getPixel(src, index + 0);
750 *px1 = this->getPixel(src, index + 1);
751 *px2 = this->getPixel(src, index + 2);
752 *px3 = this->getPixel(src, index + 3);
753 }
754
748 Sk4f getPixel(const uint32_t* src, int index) { 755 Sk4f getPixel(const uint32_t* src, int index) {
749 Sk4b bytePixel = Sk4b::Load((uint8_t *)(&src[index])); 756 Sk4b bytePixel = Sk4b::Load((uint8_t *)(&src[index]));
750 Sk4f pixel = SkNx_cast<float, uint8_t>(bytePixel); 757 Sk4f pixel = SkNx_cast<float, uint8_t>(bytePixel);
751 if (colorOrder == ColorOrder::kBGRA) { 758 if (colorOrder == ColorOrder::kBGRA) {
752 pixel = SkNx_shuffle<2, 1, 0, 3>(pixel); 759 pixel = SkNx_shuffle<2, 1, 0, 3>(pixel);
753 } 760 }
754 pixel = pixel * Sk4f{1.0f/255.0f}; 761 pixel = pixel * Sk4f{1.0f/255.0f};
755 if (colorProfile == kSRGB_SkColorProfileType) { 762 if (colorProfile == kSRGB_SkColorProfileType) {
756 pixel = sRGBFast::sRGBToLinear(pixel); 763 pixel = sRGBFast::sRGBToLinear(pixel);
757 } 764 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 } 829 }
823 830
824 void VECTORCALL bilerpList(Sk4s xs, Sk4s ys) override { 831 void VECTORCALL bilerpList(Sk4s xs, Sk4s ys) override {
825 Sk4f px00, px10, px01, px11; 832 Sk4f px00, px10, px01, px11;
826 fStrategy.get4Pixels(xs, ys, &px00, &px10, &px01, &px11); 833 fStrategy.get4Pixels(xs, ys, &px00, &px10, &px01, &px11);
827 Sk4f pixel = bilerp4(xs, ys, px00, px10, px01, px11); 834 Sk4f pixel = bilerp4(xs, ys, px00, px10, px01, px11);
828 fNext->placePixel(pixel); 835 fNext->placePixel(pixel);
829 } 836 }
830 837
831 void pointSpan(Span span) override { 838 void pointSpan(Span span) override {
839 SkASSERT(!span.isEmpty());
840 SkPoint start; SkScalar length; int count;
841 std::tie(start, length, count) = span;
842 if (length < (count - 1)) {
843 pointSpanSlowRate(span);
mtklein_C 2016/03/01 18:53:05 Please do a this-> pass.
herb_g 2016/03/01 20:57:06 Done.
844 } else if (length == (count - 1)) {
845 pointSpanUnitRate(span);
846 } else {
847 pointSpanFastRate(span);
848 }
849 }
850
851
852 private:
853 void pointSpanSlowRate(Span span) {
mtklein_C 2016/03/01 18:53:05 // When moving through source space more slowly th
herb_g 2016/03/01 20:57:06 Done.
854 SkPoint start; SkScalar length; int count;
855 std::tie(start, length, count) = span;
856 SkScalar x = X(start);
857 SkFixed fx = SkScalarToFixed(x);
858 SkScalar dx = length / (count - 1);
859 SkFixed fdx = SkScalarToFixed(dx);
860
861 const uint32_t* const row = fStrategy.row((int)std::floor(Y(start)));
mtklein_C 2016/03/01 18:53:05 Seems like we can't logically write uint32_t here.
herb_g 2016/03/01 20:57:07 Done.
862 SkLinearBitmapPipeline::PixelPlacerInterface* const next = fNext;
mtklein_C 2016/03/01 18:53:06 Just my opinion: I think marking pointers const us
herb_g 2016/03/01 20:57:07 Done.
863 int ix = SkFixedFloorToInt(fx);
864 int prevIX = ix;
865 Sk4f fpixel = fStrategy.getPixel(row, ix);
866 auto getNextPixel = [&]() {
mtklein_C 2016/03/01 18:53:05 // As dx gets smaller, we take more and more sampl
herb_g 2016/03/01 20:57:06 Done.
867 if (ix != prevIX) {
868 fpixel = fStrategy.getPixel(row, ix);
869 prevIX = ix;
870 }
871 fx += fdx;
872 ix = SkFixedFloorToInt(fx);
873 return fpixel;
874 };
875 while (count >= 4) {
876 Sk4f px0 = getNextPixel();
877 Sk4f px1 = getNextPixel();
878 Sk4f px2 = getNextPixel();
879 Sk4f px3 = getNextPixel();
880 next->place4Pixels(px0, px1, px2, px3);
881 count -= 4;
882 }
883 while (count > 0) {
884 next->placePixel(getNextPixel());
885 count -= 1;
886 }
887 }
888
889 void pointSpanUnitRate(Span span) {
mtklein_C 2016/03/01 18:53:05 // We're moving through source space at a rate of
herb_g 2016/03/01 20:57:06 Done.
890 SkPoint start; SkScalar length; int count;
891 std::tie(start, length, count) = span;
892 const uint32_t* const row = fStrategy.row((int)std::floor(Y(start)));
893 int ix = SkScalarFloorToInt(X(start));
894 SkLinearBitmapPipeline::PixelPlacerInterface* const next = fNext;
895 while (count >= 4) {
896 Sk4f px0, px1, px2, px3;
897 fStrategy.get4Pixels(row, ix, &px0, &px1, &px2, &px3);
898 next->place4Pixels(px0, px1, px2, px3);
899 ix += 4;
900 count -= 4;
901 }
902 while (count > 0) {
903 next->placePixel(fStrategy.getPixel(row, ix));
904 ix += 1;
905 count -= 1;
906 }
907 }
908
909 void pointSpanFastRate(Span span) {
mtklein_C 2016/03/01 18:53:06 // We're moving through source space faster than d
herb_g 2016/03/01 20:57:06 Done.
832 span_fallback(span, this); 910 span_fallback(span, this);
833 } 911 }
834 912
835 private: 913 private:
836 SkLinearBitmapPipeline::PixelPlacerInterface* const fNext; 914 SkLinearBitmapPipeline::PixelPlacerInterface* const fNext;
837 SourceStrategy fStrategy; 915 SourceStrategy fStrategy;
838 }; 916 };
839 917
840 using Pixel8888SRGB = Pixel8888<kSRGB_SkColorProfileType, ColorOrder::kRGBA>; 918 using Pixel8888SRGB = Pixel8888<kSRGB_SkColorProfileType, ColorOrder::kRGBA>;
841 using Pixel8888LRGB = Pixel8888<kLinear_SkColorProfileType, ColorOrder::kRGBA>; 919 using Pixel8888LRGB = Pixel8888<kLinear_SkColorProfileType, ColorOrder::kRGBA>;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 1019
942 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { 1020 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) {
943 SkASSERT(count > 0); 1021 SkASSERT(count > 0);
944 fPixelStage->setDestination(dst); 1022 fPixelStage->setDestination(dst);
945 // The count and length arguments start out in a precise relation in order t o keep the 1023 // The count and length arguments start out in a precise relation in order t o keep the
946 // math correct through the different stages. Count is the number of pixel t o produce. 1024 // math correct through the different stages. Count is the number of pixel t o produce.
947 // Since the code samples at pixel centers, length is the distance from the center of the 1025 // Since the code samples at pixel centers, length is the distance from the center of the
948 // first pixel to the center of the last pixel. This implies that length is count-1. 1026 // first pixel to the center of the last pixel. This implies that length is count-1.
949 fFirstStage->pointSpan(Span{SkPoint{x + 0.5f, y + 0.5f}, count - 1.0f, count }); 1027 fFirstStage->pointSpan(Span{SkPoint{x + 0.5f, y + 0.5f}, count - 1.0f, count });
950 } 1028 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698