| 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 <tuple> | 11 #include <tuple> | 
| 12 | 12 | 
|  | 13 #include "SkColor.h" | 
|  | 14 #include "SkColorPriv.h" | 
| 13 #include "SkFixed.h" | 15 #include "SkFixed.h" | 
| 14 #include "SkHalf.h" | 16 #include "SkHalf.h" | 
| 15 #include "SkLinearBitmapPipeline_core.h" | 17 #include "SkLinearBitmapPipeline_core.h" | 
|  | 18 #include "SkNx.h" | 
| 16 #include "SkPM4fPriv.h" | 19 #include "SkPM4fPriv.h" | 
| 17 | 20 | 
| 18 namespace { | 21 namespace { | 
| 19 // Explaination of the math: | 22 // Explaination of the math: | 
| 20 //              1 - x      x | 23 //              1 - x      x | 
| 21 //           +--------+--------+ | 24 //           +--------+--------+ | 
| 22 //           |        |        | | 25 //           |        |        | | 
| 23 //  1 - y    |  px00  |  px10  | | 26 //  1 - y    |  px00  |  px10  | | 
| 24 //           |        |        | | 27 //           |        |        | | 
| 25 //           +--------+--------+ | 28 //           +--------+--------+ | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 47     sum = sum + px10 * (fxs - fxys); | 50     sum = sum + px10 * (fxs - fxys); | 
| 48     sum = sum + px00 * (Sk4f{1.0f} - fxs - fys + fxys); | 51     sum = sum + px00 * (Sk4f{1.0f} - fxs - fys + fxys); | 
| 49     return sum; | 52     return sum; | 
| 50 } | 53 } | 
| 51 | 54 | 
| 52 ////////////////////////////////////////////////////////////////////////////////
     //////////////////// | 55 ////////////////////////////////////////////////////////////////////////////////
     //////////////////// | 
| 53 // PixelGetter is the lowest level interface to the source data. There is a Pixe
     lGetter for each | 56 // PixelGetter is the lowest level interface to the source data. There is a Pixe
     lGetter for each | 
| 54 // of the different SkColorTypes. | 57 // of the different SkColorTypes. | 
| 55 template <SkColorType colorType, SkColorProfileType colorProfile> class PixelGet
     ter; | 58 template <SkColorType colorType, SkColorProfileType colorProfile> class PixelGet
     ter; | 
| 56 | 59 | 
|  | 60 // Alpha handling: | 
|  | 61 //   The alpha from the paint (tintColor) is used in the blend part of the pipel
     ine to modulate | 
|  | 62 // the entire bitmap. So, the tint color is given an alpha of 1.0 so that the la
     ter alpha can | 
|  | 63 // modulate this color later. | 
|  | 64 template <> | 
|  | 65 class PixelGetter<kAlpha_8_SkColorType, kLinear_SkColorProfileType> { | 
|  | 66 public: | 
|  | 67     using Element = uint8_t; | 
|  | 68     PixelGetter(const SkPixmap& srcPixmap, SkColor tintColor) | 
|  | 69         : fTintColor{set_alpha(Sk4f_from_SkColor(tintColor), 1.0f)} { } | 
|  | 70 | 
|  | 71     Sk4f getPixelAt(const uint8_t* src) { | 
|  | 72         return fTintColor * (*src * (1.0f/255.0f)); | 
|  | 73     } | 
|  | 74 | 
|  | 75 private: | 
|  | 76     const Sk4f fTintColor; | 
|  | 77 }; | 
|  | 78 | 
|  | 79 template <SkColorProfileType colorProfile> | 
|  | 80 class PixelGetter<kRGB_565_SkColorType, colorProfile> { | 
|  | 81 public: | 
|  | 82     using Element = uint16_t; | 
|  | 83     PixelGetter(const SkPixmap& srcPixmap) { } | 
|  | 84 | 
|  | 85     Sk4f getPixelAt(const uint16_t* src) { | 
|  | 86         SkPMColor pixel = SkPixel16ToPixel32(*src); | 
|  | 87         return colorProfile == kSRGB_SkColorProfileType | 
|  | 88                ? Sk4f_fromS32(pixel) | 
|  | 89                : Sk4f_fromL32(pixel); | 
|  | 90     } | 
|  | 91 }; | 
|  | 92 | 
|  | 93 template <SkColorProfileType colorProfile> | 
|  | 94 class PixelGetter<kARGB_4444_SkColorType, colorProfile> { | 
|  | 95 public: | 
|  | 96     using Element = uint16_t; | 
|  | 97     PixelGetter(const SkPixmap& srcPixmap) { } | 
|  | 98 | 
|  | 99     Sk4f getPixelAt(const uint16_t* src) { | 
|  | 100         SkPMColor pixel = SkPixel4444ToPixel32(*src); | 
|  | 101         return colorProfile == kSRGB_SkColorProfileType | 
|  | 102                ? Sk4f_fromS32(pixel) | 
|  | 103                : Sk4f_fromL32(pixel); | 
|  | 104     } | 
|  | 105 }; | 
|  | 106 | 
| 57 template <SkColorProfileType colorProfile> | 107 template <SkColorProfileType colorProfile> | 
| 58 class PixelGetter<kRGBA_8888_SkColorType, colorProfile> { | 108 class PixelGetter<kRGBA_8888_SkColorType, colorProfile> { | 
| 59 public: | 109 public: | 
| 60     using Element = uint32_t; | 110     using Element = uint32_t; | 
| 61     PixelGetter(const SkPixmap& srcPixmap) { } | 111     PixelGetter(const SkPixmap& srcPixmap) { } | 
| 62 | 112 | 
| 63     Sk4f getPixelAt(const uint32_t* src) { | 113     Sk4f getPixelAt(const uint32_t* src) { | 
| 64         return colorProfile == kSRGB_SkColorProfileType | 114         return colorProfile == kSRGB_SkColorProfileType | 
| 65                ? Sk4f_fromS32(*src) | 115                ? Sk4f_fromS32(*src) | 
| 66                : Sk4f_fromL32(*src); | 116                : Sk4f_fromL32(*src); | 
| 67     } | 117     } | 
| 68 }; | 118 }; | 
| 69 | 119 | 
| 70 template <SkColorProfileType colorProfile> | 120 template <SkColorProfileType colorProfile> | 
| 71 class PixelGetter<kBGRA_8888_SkColorType, colorProfile> { | 121 class PixelGetter<kBGRA_8888_SkColorType, colorProfile> { | 
| 72 public: | 122 public: | 
| 73     using Element = uint32_t; | 123     using Element = uint32_t; | 
| 74     PixelGetter(const SkPixmap& srcPixmap) { } | 124     PixelGetter(const SkPixmap& srcPixmap) { } | 
| 75 | 125 | 
| 76     Sk4f getPixelAt(const uint32_t* src) { | 126     Sk4f getPixelAt(const uint32_t* src) { | 
| 77         Sk4f pixel = colorProfile == kSRGB_SkColorProfileType | 127         Sk4f pixel = colorProfile == kSRGB_SkColorProfileType | 
| 78                      ? Sk4f_fromS32(*src) | 128                      ? Sk4f_fromS32(*src) | 
| 79                      : Sk4f_fromL32(*src); | 129                      : Sk4f_fromL32(*src); | 
| 80         return SkNx_shuffle<2, 1, 0, 3>(pixel); | 130         return swizzle_rb(pixel); | 
| 81     } | 131     } | 
| 82 }; | 132 }; | 
| 83 | 133 | 
| 84 template <SkColorProfileType colorProfile> | 134 template <SkColorProfileType colorProfile> | 
| 85 class PixelGetter<kIndex_8_SkColorType, colorProfile> { | 135 class PixelGetter<kIndex_8_SkColorType, colorProfile> { | 
| 86 public: | 136 public: | 
| 87     using Element = uint8_t; | 137     using Element = uint8_t; | 
| 88     PixelGetter(const SkPixmap& srcPixmap) { | 138     PixelGetter(const SkPixmap& srcPixmap) { | 
| 89         SkColorTable* skColorTable = srcPixmap.ctable(); | 139         SkColorTable* skColorTable = srcPixmap.ctable(); | 
| 90         SkASSERT(skColorTable != nullptr); | 140         SkASSERT(skColorTable != nullptr); | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 121             } | 171             } | 
| 122             return pixel; | 172             return pixel; | 
| 123         } else { | 173         } else { | 
| 124             return Sk4f{0.0f}; | 174             return Sk4f{0.0f}; | 
| 125         } | 175         } | 
| 126     } | 176     } | 
| 127     SkAutoMalloc         fColorTableStorage{kColorTableSize}; | 177     SkAutoMalloc         fColorTableStorage{kColorTableSize}; | 
| 128     Sk4f*                fColorTable; | 178     Sk4f*                fColorTable; | 
| 129 }; | 179 }; | 
| 130 | 180 | 
|  | 181 template <SkColorProfileType colorProfile> | 
|  | 182 class PixelGetter<kGray_8_SkColorType, colorProfile> { | 
|  | 183 public: | 
|  | 184     using Element = uint8_t; | 
|  | 185     PixelGetter(const SkPixmap& srcPixmap) { } | 
|  | 186 | 
|  | 187     Sk4f getPixelAt(const uint8_t* src) { | 
|  | 188         float gray = *src * (1.0f/255.0f); | 
|  | 189         Sk4f pixel = Sk4f{gray, gray, gray, 1.0f}; | 
|  | 190         return colorProfile == kSRGB_SkColorProfileType | 
|  | 191                ? srgb_to_linear(pixel) | 
|  | 192                : pixel; | 
|  | 193     } | 
|  | 194 }; | 
|  | 195 | 
| 131 template <> | 196 template <> | 
| 132 class PixelGetter<kRGBA_F16_SkColorType, kLinear_SkColorProfileType> { | 197 class PixelGetter<kRGBA_F16_SkColorType, kLinear_SkColorProfileType> { | 
| 133 public: | 198 public: | 
| 134     using Element = uint64_t; | 199     using Element = uint64_t; | 
| 135     PixelGetter(const SkPixmap& srcPixmap) { } | 200     PixelGetter(const SkPixmap& srcPixmap) { } | 
| 136 | 201 | 
| 137     Sk4f getPixelAt(const uint64_t* src) { | 202     Sk4f getPixelAt(const uint64_t* src) { | 
| 138         return SkHalfToFloat_01(*src); | 203         return SkHalfToFloat_01(*src); | 
| 139     } | 204     } | 
| 140 }; | 205 }; | 
| 141 | 206 | 
| 142 ////////////////////////////////////////////////////////////////////////////////
     //////////////////// | 207 ////////////////////////////////////////////////////////////////////////////////
     //////////////////// | 
| 143 // PixelAccessor handles all the same plumbing for all the PixelGetters. | 208 // PixelAccessor handles all the same plumbing for all the PixelGetters. | 
| 144 template <SkColorType colorType, SkColorProfileType colorProfile> | 209 template <SkColorType colorType, SkColorProfileType colorProfile> | 
| 145 class PixelAccessor { | 210 class PixelAccessor { | 
| 146     using Element = typename PixelGetter<colorType, colorProfile>::Element; | 211     using Element = typename PixelGetter<colorType, colorProfile>::Element; | 
| 147 public: | 212 public: | 
| 148     PixelAccessor(const SkPixmap& srcPixmap) | 213     template <typename... Args> | 
|  | 214     PixelAccessor(const SkPixmap& srcPixmap, Args&&... args) | 
| 149         : fSrc{static_cast<const Element*>(srcPixmap.addr())} | 215         : fSrc{static_cast<const Element*>(srcPixmap.addr())} | 
| 150         , fWidth{srcPixmap.rowBytesAsPixels()} | 216         , fWidth{srcPixmap.rowBytesAsPixels()} | 
| 151         , fGetter{srcPixmap} { } | 217         , fGetter{srcPixmap, std::move<Args>(args)...} { } | 
| 152 | 218 | 
| 153     void VECTORCALL getFewPixels(int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, 
     Sk4f* px2) { | 219     void VECTORCALL getFewPixels(int n, Sk4s xs, Sk4s ys, Sk4f* px0, Sk4f* px1, 
     Sk4f* px2) { | 
| 154         Sk4i XIs = SkNx_cast<int, SkScalar>(xs); | 220         Sk4i XIs = SkNx_cast<int, SkScalar>(xs); | 
| 155         Sk4i YIs = SkNx_cast<int, SkScalar>(ys); | 221         Sk4i YIs = SkNx_cast<int, SkScalar>(ys); | 
| 156         Sk4i bufferLoc = YIs * fWidth + XIs; | 222         Sk4i bufferLoc = YIs * fWidth + XIs; | 
| 157         switch (n) { | 223         switch (n) { | 
| 158             case 3: | 224             case 3: | 
| 159                 *px2 = this->getPixelAt(bufferLoc[2]); | 225                 *px2 = this->getPixelAt(bufferLoc[2]); | 
| 160             case 2: | 226             case 2: | 
| 161                 *px1 = this->getPixelAt(bufferLoc[1]); | 227                 *px1 = this->getPixelAt(bufferLoc[1]); | 
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 704             Sk4f ys = {y - 0.5f, y - 0.5f, y1 + 0.5f, y1 + 0.5f}; | 770             Sk4f ys = {y - 0.5f, y - 0.5f, y1 + 0.5f, y1 + 0.5f}; | 
| 705             while (count > 0) { | 771             while (count > 0) { | 
| 706                 Sk4f xs = Sk4f{-0.5f, 0.5f, -0.5f, 0.5f} + Sk4f{x}; | 772                 Sk4f xs = Sk4f{-0.5f, 0.5f, -0.5f, 0.5f} + Sk4f{x}; | 
| 707                 this->bilerpEdge(xs, ys); | 773                 this->bilerpEdge(xs, ys); | 
| 708                 x += dx; | 774                 x += dx; | 
| 709                 count -= 1; | 775                 count -= 1; | 
| 710             } | 776             } | 
| 711         } | 777         } | 
| 712     } | 778     } | 
| 713 | 779 | 
| 714     Next* const fNext; | 780     Next* const                            fNext; | 
| 715     PixelAccessor<colorType, colorProfile> fStrategy; | 781     PixelAccessor<colorType, colorProfile> fStrategy; | 
| 716 }; | 782 }; | 
| 717 | 783 | 
| 718 |  | 
| 719 }  // namespace | 784 }  // namespace | 
| 720 | 785 | 
| 721 #endif  // SkLinearBitmapPipeline_sampler_DEFINED | 786 #endif  // SkLinearBitmapPipeline_sampler_DEFINED | 
| OLD | NEW | 
|---|