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 #ifndef SkLinearBitmapPipeline_sampler_DEFINED | 8 #ifndef SkLinearBitmapPipeline_sampler_DEFINED |
9 #define SkLinearBitmapPipeline_sampler_DEFINED | 9 #define SkLinearBitmapPipeline_sampler_DEFINED |
10 | 10 |
11 #include "SkFixed.h" | 11 #include "SkFixed.h" |
| 12 #include "SkHalf.h" |
12 #include "SkLinearBitmapPipeline_core.h" | 13 #include "SkLinearBitmapPipeline_core.h" |
13 #include <array> | 14 #include <array> |
14 #include <tuple> | 15 #include <tuple> |
15 | 16 |
16 namespace { | 17 namespace { |
17 // Explaination of the math: | 18 // Explaination of the math: |
18 // 1 - x x | 19 // 1 - x x |
19 // +--------+--------+ | 20 // +--------+--------+ |
20 // | | | | 21 // | | | |
21 // 1 - y | px00 | px10 | | 22 // 1 - y | px00 | px10 | |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 } | 728 } |
728 const uint8_t* const fSrc; | 729 const uint8_t* const fSrc; |
729 const Sk4i fWidth; | 730 const Sk4i fWidth; |
730 SkAutoMalloc fColorTableStorage{kColorTableSize}; | 731 SkAutoMalloc fColorTableStorage{kColorTableSize}; |
731 Sk4f* fColorTable; | 732 Sk4f* fColorTable; |
732 }; | 733 }; |
733 | 734 |
734 using PixelIndex8SRGB = PixelIndex8<kSRGB_SkColorProfileType>; | 735 using PixelIndex8SRGB = PixelIndex8<kSRGB_SkColorProfileType>; |
735 using PixelIndex8LRGB = PixelIndex8<kLinear_SkColorProfileType>; | 736 using PixelIndex8LRGB = PixelIndex8<kLinear_SkColorProfileType>; |
736 | 737 |
| 738 class PixelHalfSRGB { |
| 739 public: |
| 740 PixelHalfSRGB(int width, const uint64_t* src) : fSrc{src}, fWidth{width}{ } |
| 741 PixelHalfSRGB(const SkPixmap& srcPixmap) |
| 742 : fSrc{srcPixmap.addr64()} |
| 743 , fWidth{static_cast<int>(srcPixmap.rowBytes() / 8)} { } |
| 744 |
| 745 void VECTORCALL getFewPixels(int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1,
Sk4f* px2) { |
| 746 Sk4i XIs = SkNx_cast<int, SkScalar>(xs); |
| 747 Sk4i YIs = SkNx_cast<int, SkScalar>(ys); |
| 748 Sk4i bufferLoc = YIs * fWidth + XIs; |
| 749 switch (n) { |
| 750 case 3: |
| 751 *px2 = this->getPixelAt(fSrc, bufferLoc[2]); |
| 752 case 2: |
| 753 *px1 = this->getPixelAt(fSrc, bufferLoc[1]); |
| 754 case 1: |
| 755 *px0 = this->getPixelAt(fSrc, bufferLoc[0]); |
| 756 default: |
| 757 break; |
| 758 } |
| 759 } |
| 760 |
| 761 void VECTORCALL get4Pixels(Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, Sk4f* px2
, Sk4f* px3) { |
| 762 Sk4i XIs = SkNx_cast<int, SkScalar>(xs); |
| 763 Sk4i YIs = SkNx_cast<int, SkScalar>(ys); |
| 764 Sk4i bufferLoc = YIs * fWidth + XIs; |
| 765 *px0 = this->getPixelAt(fSrc, bufferLoc[0]); |
| 766 *px1 = this->getPixelAt(fSrc, bufferLoc[1]); |
| 767 *px2 = this->getPixelAt(fSrc, bufferLoc[2]); |
| 768 *px3 = this->getPixelAt(fSrc, bufferLoc[3]); |
| 769 } |
| 770 |
| 771 void get4Pixels(const void* vsrc, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2
, Sk4f* px3) { |
| 772 const uint32_t* src = static_cast<const uint32_t*>(vsrc); |
| 773 *px0 = this->getPixelAt(src, index + 0); |
| 774 *px1 = this->getPixelAt(src, index + 1); |
| 775 *px2 = this->getPixelAt(src, index + 2); |
| 776 *px3 = this->getPixelAt(src, index + 3); |
| 777 } |
| 778 |
| 779 Sk4f getPixelAt(const void* vsrc, int index) { |
| 780 const uint64_t* src = static_cast<const uint64_t*>(vsrc); |
| 781 return SkHalfToFloat_01(*src); |
| 782 } |
| 783 |
| 784 const void* row(int y) { return fSrc + y * fWidth[0]; } |
| 785 |
| 786 private: |
| 787 const uint64_t* const fSrc; |
| 788 const Sk4i fWidth; |
| 789 }; |
| 790 |
737 } // namespace | 791 } // namespace |
738 | 792 |
739 #endif // SkLinearBitmapPipeline_sampler_DEFINED | 793 #endif // SkLinearBitmapPipeline_sampler_DEFINED |
OLD | NEW |