herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkLinearBitmapPipeline_sampler_DEFINED |
| 9 | #define SkLinearBitmapPipeline_sampler_DEFINED |
| 10 | |
herb | cf05dcd | 2016-05-11 11:53:36 -0700 | [diff] [blame] | 11 | #include <tuple> |
| 12 | |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 13 | #include "SkColor.h" |
| 14 | #include "SkColorPriv.h" |
benjaminwagner | 6c71e0a | 2016-04-07 08:49:31 -0700 | [diff] [blame] | 15 | #include "SkFixed.h" |
herb | d5f2e2e | 2016-04-14 11:16:44 -0700 | [diff] [blame] | 16 | #include "SkHalf.h" |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 17 | #include "SkLinearBitmapPipeline_core.h" |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 18 | #include "SkNx.h" |
herb | cf05dcd | 2016-05-11 11:53:36 -0700 | [diff] [blame] | 19 | #include "SkPM4fPriv.h" |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 20 | |
| 21 | namespace { |
| 22 | // Explaination of the math: |
| 23 | // 1 - x x |
| 24 | // +--------+--------+ |
| 25 | // | | | |
| 26 | // 1 - y | px00 | px10 | |
| 27 | // | | | |
| 28 | // +--------+--------+ |
| 29 | // | | | |
| 30 | // y | px01 | px11 | |
| 31 | // | | | |
| 32 | // +--------+--------+ |
| 33 | // |
| 34 | // |
| 35 | // Given a pixelxy each is multiplied by a different factor derived from the fractional part of x |
| 36 | // and y: |
| 37 | // * px00 -> (1 - x)(1 - y) = 1 - x - y + xy |
| 38 | // * px10 -> x(1 - y) = x - xy |
| 39 | // * px01 -> (1 - x)y = y - xy |
| 40 | // * px11 -> xy |
| 41 | // So x * y is calculated first and then used to calculate all the other factors. |
mtklein | e5fb9c8 | 2016-07-07 08:12:09 -0700 | [diff] [blame] | 42 | static Sk4s SK_VECTORCALL bilerp4(Sk4s xs, Sk4s ys, Sk4f px00, Sk4f px10, |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 43 | Sk4f px01, Sk4f px11) { |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 44 | // Calculate fractional xs and ys. |
| 45 | Sk4s fxs = xs - xs.floor(); |
| 46 | Sk4s fys = ys - ys.floor(); |
| 47 | Sk4s fxys{fxs * fys}; |
| 48 | Sk4f sum = px11 * fxys; |
| 49 | sum = sum + px01 * (fys - fxys); |
| 50 | sum = sum + px10 * (fxs - fxys); |
| 51 | sum = sum + px00 * (Sk4f{1.0f} - fxs - fys + fxys); |
| 52 | return sum; |
| 53 | } |
| 54 | |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 55 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 56 | // PixelGetter is the lowest level interface to the source data. There is a PixelConverter for each |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 57 | // of the different SkColorTypes. |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 58 | template <SkColorType, SkGammaType> class PixelConverter; |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 59 | |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 60 | // Alpha handling: |
| 61 | // The alpha from the paint (tintColor) is used in the blend part of the pipeline to modulate |
| 62 | // the entire bitmap. So, the tint color is given an alpha of 1.0 so that the later alpha can |
| 63 | // modulate this color later. |
| 64 | template <> |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 65 | class PixelConverter<kAlpha_8_SkColorType, kLinear_SkGammaType> { |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 66 | public: |
| 67 | using Element = uint8_t; |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 68 | PixelConverter(const SkPixmap& srcPixmap, SkColor tintColor) |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 69 | : fTintColor{set_alpha(Sk4f_from_SkColor(tintColor), 1.0f)} { } |
| 70 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 71 | Sk4f toSk4f(const Element pixel) const { |
| 72 | return fTintColor * (pixel * (1.0f/255.0f)); |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | private: |
| 76 | const Sk4f fTintColor; |
| 77 | }; |
| 78 | |
reed | dabe5d3 | 2016-06-21 10:28:14 -0700 | [diff] [blame] | 79 | template <SkGammaType gammaType> |
mtklein | 53574b7 | 2016-07-20 05:23:31 -0700 | [diff] [blame] | 80 | static inline Sk4f pmcolor_to_rgba(SkPMColor pixel) { |
| 81 | return swizzle_rb_if_bgra( |
| 82 | (gammaType == kSRGB_SkGammaType) ? Sk4f_fromS32(pixel) |
| 83 | : Sk4f_fromL32(pixel)); |
| 84 | } |
| 85 | |
| 86 | template <SkGammaType gammaType> |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 87 | class PixelConverter<kRGB_565_SkColorType, gammaType> { |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 88 | public: |
| 89 | using Element = uint16_t; |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 90 | PixelConverter(const SkPixmap& srcPixmap) { } |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 91 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 92 | Sk4f toSk4f(Element pixel) const { |
mtklein | 53574b7 | 2016-07-20 05:23:31 -0700 | [diff] [blame] | 93 | return pmcolor_to_rgba<gammaType>(SkPixel16ToPixel32(pixel)); |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 94 | } |
| 95 | }; |
| 96 | |
| 97 | template <SkGammaType gammaType> |
| 98 | class PixelConverter<kARGB_4444_SkColorType, gammaType> { |
| 99 | public: |
| 100 | using Element = uint16_t; |
| 101 | PixelConverter(const SkPixmap& srcPixmap) { } |
| 102 | |
| 103 | Sk4f toSk4f(Element pixel) const { |
mtklein | 53574b7 | 2016-07-20 05:23:31 -0700 | [diff] [blame] | 104 | return pmcolor_to_rgba<gammaType>(SkPixel4444ToPixel32(pixel)); |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 105 | } |
| 106 | }; |
| 107 | |
| 108 | template <SkGammaType gammaType> |
| 109 | class PixelConverter<kRGBA_8888_SkColorType, gammaType> { |
| 110 | public: |
| 111 | using Element = uint32_t; |
| 112 | PixelConverter(const SkPixmap& srcPixmap) { } |
| 113 | |
| 114 | Sk4f toSk4f(Element pixel) const { |
reed | dabe5d3 | 2016-06-21 10:28:14 -0700 | [diff] [blame] | 115 | return gammaType == kSRGB_SkGammaType |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 116 | ? Sk4f_fromS32(pixel) |
| 117 | : Sk4f_fromL32(pixel); |
| 118 | } |
| 119 | }; |
| 120 | |
reed | dabe5d3 | 2016-06-21 10:28:14 -0700 | [diff] [blame] | 121 | template <SkGammaType gammaType> |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 122 | class PixelConverter<kBGRA_8888_SkColorType, gammaType> { |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 123 | public: |
| 124 | using Element = uint32_t; |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 125 | PixelConverter(const SkPixmap& srcPixmap) { } |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 126 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 127 | Sk4f toSk4f(Element pixel) const { |
| 128 | return swizzle_rb( |
| 129 | gammaType == kSRGB_SkGammaType ? Sk4f_fromS32(pixel) : Sk4f_fromL32(pixel)); |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 130 | } |
| 131 | }; |
| 132 | |
reed | dabe5d3 | 2016-06-21 10:28:14 -0700 | [diff] [blame] | 133 | template <SkGammaType gammaType> |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 134 | class PixelConverter<kIndex_8_SkColorType, gammaType> { |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 135 | public: |
| 136 | using Element = uint8_t; |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 137 | PixelConverter(const SkPixmap& srcPixmap) |
| 138 | : fColorTableSize(srcPixmap.ctable()->count()){ |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 139 | SkColorTable* skColorTable = srcPixmap.ctable(); |
| 140 | SkASSERT(skColorTable != nullptr); |
| 141 | |
| 142 | fColorTable = (Sk4f*)SkAlign16((intptr_t)fColorTableStorage.get()); |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 143 | for (int i = 0; i < fColorTableSize; i++) { |
mtklein | 53574b7 | 2016-07-20 05:23:31 -0700 | [diff] [blame] | 144 | fColorTable[i] = pmcolor_to_rgba<gammaType>((*skColorTable)[i]); |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 148 | PixelConverter(const PixelConverter& strategy) |
| 149 | : fColorTableSize{strategy.fColorTableSize}{ |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 150 | fColorTable = (Sk4f*)SkAlign16((intptr_t)fColorTableStorage.get()); |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 151 | for (int i = 0; i < fColorTableSize; i++) { |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 152 | fColorTable[i] = strategy.fColorTable[i]; |
| 153 | } |
| 154 | } |
| 155 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 156 | Sk4f toSk4f(Element index) const { |
| 157 | return fColorTable[index]; |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | private: |
| 161 | static const size_t kColorTableSize = sizeof(Sk4f[256]) + 12; |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 162 | const int fColorTableSize; |
| 163 | SkAutoMalloc fColorTableStorage{kColorTableSize}; |
| 164 | Sk4f* fColorTable; |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 165 | }; |
| 166 | |
reed | dabe5d3 | 2016-06-21 10:28:14 -0700 | [diff] [blame] | 167 | template <SkGammaType gammaType> |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 168 | class PixelConverter<kGray_8_SkColorType, gammaType> { |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 169 | public: |
| 170 | using Element = uint8_t; |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 171 | PixelConverter(const SkPixmap& srcPixmap) { } |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 172 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 173 | Sk4f toSk4f(Element pixel) const { |
mtklein | 0c90247 | 2016-07-20 18:10:07 -0700 | [diff] [blame] | 174 | float gray = (gammaType == kSRGB_SkGammaType) |
| 175 | ? sk_linear_from_srgb[pixel] |
| 176 | : pixel * (1/255.0f); |
| 177 | return {gray, gray, gray, 1.0f}; |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 178 | } |
| 179 | }; |
| 180 | |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 181 | template <> |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 182 | class PixelConverter<kRGBA_F16_SkColorType, kLinear_SkGammaType> { |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 183 | public: |
| 184 | using Element = uint64_t; |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 185 | PixelConverter(const SkPixmap& srcPixmap) { } |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 186 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 187 | Sk4f toSk4f(const Element pixel) const { |
mtklein | 58e389b | 2016-07-15 07:00:11 -0700 | [diff] [blame] | 188 | return SkHalfToFloat_finite(pixel); |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 189 | } |
| 190 | }; |
| 191 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 192 | class PixelAccessorShim { |
| 193 | public: |
| 194 | explicit PixelAccessorShim(SkLinearBitmapPipeline::PixelAccessorInterface* accessor) |
| 195 | : fPixelAccessor(accessor) { } |
| 196 | |
| 197 | void SK_VECTORCALL getFewPixels( |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 198 | int n, Sk4i xs, Sk4i ys, Sk4f* px0, Sk4f* px1, Sk4f* px2) const { |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 199 | fPixelAccessor->getFewPixels(n, xs, ys, px0, px1, px2); |
| 200 | } |
| 201 | |
| 202 | void SK_VECTORCALL get4Pixels( |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 203 | Sk4i xs, Sk4i ys, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) const { |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 204 | fPixelAccessor->get4Pixels(xs, ys, px0, px1, px2, px3); |
| 205 | } |
| 206 | |
| 207 | void get4Pixels( |
| 208 | const void* src, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) const { |
| 209 | fPixelAccessor->get4Pixels(src, index, px0, px1, px2, px3); |
| 210 | }; |
| 211 | |
| 212 | Sk4f getPixelFromRow(const void* row, int index) const { |
| 213 | return fPixelAccessor->getPixelFromRow(row, index); |
| 214 | } |
| 215 | |
| 216 | Sk4f getPixelAt(int index) const { |
| 217 | return fPixelAccessor->getPixelAt(index); |
| 218 | } |
| 219 | |
| 220 | const void* row(int y) const { |
| 221 | return fPixelAccessor->row(y); |
| 222 | } |
| 223 | |
| 224 | private: |
| 225 | SkLinearBitmapPipeline::PixelAccessorInterface* const fPixelAccessor; |
| 226 | }; |
| 227 | |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 228 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 229 | // PixelAccessor handles all the same plumbing for all the PixelGetters. |
reed | dabe5d3 | 2016-06-21 10:28:14 -0700 | [diff] [blame] | 230 | template <SkColorType colorType, SkGammaType gammaType> |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 231 | class PixelAccessor final : public SkLinearBitmapPipeline::PixelAccessorInterface { |
| 232 | using Element = typename PixelConverter<colorType, gammaType>::Element; |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 233 | public: |
herb | 670f01f | 2016-05-13 10:04:46 -0700 | [diff] [blame] | 234 | template <typename... Args> |
| 235 | PixelAccessor(const SkPixmap& srcPixmap, Args&&... args) |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 236 | : fSrc{static_cast<const Element*>(srcPixmap.addr())} |
| 237 | , fWidth{srcPixmap.rowBytesAsPixels()} |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 238 | , fConverter{srcPixmap, std::move<Args>(args)...} { } |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 239 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 240 | void SK_VECTORCALL getFewPixels ( |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 241 | int n, Sk4i xs, Sk4i ys, Sk4f* px0, Sk4f* px1, Sk4f* px2) const override { |
| 242 | Sk4i bufferLoc = ys * fWidth + xs; |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 243 | switch (n) { |
| 244 | case 3: |
| 245 | *px2 = this->getPixelAt(bufferLoc[2]); |
| 246 | case 2: |
| 247 | *px1 = this->getPixelAt(bufferLoc[1]); |
| 248 | case 1: |
| 249 | *px0 = this->getPixelAt(bufferLoc[0]); |
| 250 | default: |
| 251 | break; |
| 252 | } |
| 253 | } |
| 254 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 255 | void SK_VECTORCALL get4Pixels( |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 256 | Sk4i xs, Sk4i ys, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) const override { |
| 257 | Sk4i bufferLoc = ys * fWidth + xs; |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 258 | *px0 = this->getPixelAt(bufferLoc[0]); |
| 259 | *px1 = this->getPixelAt(bufferLoc[1]); |
| 260 | *px2 = this->getPixelAt(bufferLoc[2]); |
| 261 | *px3 = this->getPixelAt(bufferLoc[3]); |
| 262 | } |
| 263 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 264 | void get4Pixels( |
| 265 | const void* src, int index, Sk4f* px0, Sk4f* px1, Sk4f* px2, Sk4f* px3) const override { |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 266 | *px0 = this->getPixelFromRow(src, index + 0); |
| 267 | *px1 = this->getPixelFromRow(src, index + 1); |
| 268 | *px2 = this->getPixelFromRow(src, index + 2); |
| 269 | *px3 = this->getPixelFromRow(src, index + 3); |
| 270 | } |
| 271 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 272 | Sk4f getPixelFromRow(const void* row, int index) const override { |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 273 | const Element* src = static_cast<const Element*>(row); |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 274 | return fConverter.toSk4f(src[index]); |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 275 | } |
| 276 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 277 | Sk4f getPixelAt(int index) const override { |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 278 | return this->getPixelFromRow(fSrc, index); |
| 279 | } |
| 280 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 281 | const void* row(int y) const override { return fSrc + y * fWidth; } |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 282 | |
| 283 | private: |
| 284 | const Element* const fSrc; |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 285 | const int fWidth; |
| 286 | PixelConverter<colorType, gammaType> fConverter; |
herb | 15332a8 | 2016-05-12 11:37:00 -0700 | [diff] [blame] | 287 | }; |
| 288 | |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 289 | // We're moving through source space at a rate of 1 source pixel per 1 dst pixel. |
| 290 | // We'll never re-use pixels, but we can at least load contiguous pixels. |
| 291 | template <typename Next, typename Strategy> |
| 292 | static void src_strategy_blend(Span span, Next* next, Strategy* strategy) { |
| 293 | SkPoint start; |
| 294 | SkScalar length; |
| 295 | int count; |
| 296 | std::tie(start, length, count) = span; |
| 297 | int ix = SkScalarFloorToInt(X(start)); |
| 298 | const void* row = strategy->row((int)std::floor(Y(start))); |
| 299 | if (length > 0) { |
| 300 | while (count >= 4) { |
| 301 | Sk4f px0, px1, px2, px3; |
| 302 | strategy->get4Pixels(row, ix, &px0, &px1, &px2, &px3); |
| 303 | next->blend4Pixels(px0, px1, px2, px3); |
| 304 | ix += 4; |
| 305 | count -= 4; |
| 306 | } |
| 307 | |
| 308 | while (count > 0) { |
| 309 | next->blendPixel(strategy->getPixelFromRow(row, ix)); |
| 310 | ix += 1; |
| 311 | count -= 1; |
| 312 | } |
| 313 | } else { |
| 314 | while (count >= 4) { |
| 315 | Sk4f px0, px1, px2, px3; |
| 316 | strategy->get4Pixels(row, ix - 3, &px3, &px2, &px1, &px0); |
| 317 | next->blend4Pixels(px0, px1, px2, px3); |
| 318 | ix -= 4; |
| 319 | count -= 4; |
| 320 | } |
| 321 | |
| 322 | while (count > 0) { |
| 323 | next->blendPixel(strategy->getPixelFromRow(row, ix)); |
| 324 | ix -= 1; |
| 325 | count -= 1; |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 330 | // -- NearestNeighborSampler ----------------------------------------------------------------------- |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 331 | // NearestNeighborSampler - use nearest neighbor filtering to create runs of destination pixels. |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 332 | template<typename Accessor, typename Next> |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 333 | class NearestNeighborSampler : public SkLinearBitmapPipeline::SampleProcessorInterface { |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 334 | public: |
| 335 | template<typename... Args> |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 336 | NearestNeighborSampler(SkLinearBitmapPipeline::BlendProcessorInterface* next, Args&& ... args) |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 337 | : fNext{next}, fAccessor{std::forward<Args>(args)...} { } |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 338 | |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 339 | NearestNeighborSampler(SkLinearBitmapPipeline::BlendProcessorInterface* next, |
| 340 | const NearestNeighborSampler& sampler) |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 341 | : fNext{next}, fAccessor{sampler.fAccessor} { } |
herb | 9e0efe5 | 2016-04-08 13:25:28 -0700 | [diff] [blame] | 342 | |
mtklein | e5fb9c8 | 2016-07-07 08:12:09 -0700 | [diff] [blame] | 343 | void SK_VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override { |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 344 | SkASSERT(0 < n && n < 4); |
| 345 | Sk4f px0, px1, px2; |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 346 | fAccessor.getFewPixels(n, SkNx_cast<int>(xs), SkNx_cast<int>(ys), &px0, &px1, &px2); |
herb | 9e0efe5 | 2016-04-08 13:25:28 -0700 | [diff] [blame] | 347 | if (n >= 1) fNext->blendPixel(px0); |
| 348 | if (n >= 2) fNext->blendPixel(px1); |
| 349 | if (n >= 3) fNext->blendPixel(px2); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 350 | } |
| 351 | |
mtklein | e5fb9c8 | 2016-07-07 08:12:09 -0700 | [diff] [blame] | 352 | void SK_VECTORCALL pointList4(Sk4s xs, Sk4s ys) override { |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 353 | Sk4f px0, px1, px2, px3; |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 354 | fAccessor.get4Pixels(SkNx_cast<int>(xs), SkNx_cast<int>(ys), &px0, &px1, &px2, &px3); |
herb | 9e0efe5 | 2016-04-08 13:25:28 -0700 | [diff] [blame] | 355 | fNext->blend4Pixels(px0, px1, px2, px3); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 356 | } |
| 357 | |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 358 | void pointSpan(Span span) override { |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 359 | SkASSERT(!span.isEmpty()); |
| 360 | SkPoint start; |
| 361 | SkScalar length; |
| 362 | int count; |
| 363 | std::tie(start, length, count) = span; |
| 364 | SkScalar absLength = SkScalarAbs(length); |
| 365 | if (absLength < (count - 1)) { |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 366 | this->spanSlowRate(span); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 367 | } else if (absLength == (count - 1)) { |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 368 | src_strategy_blend(span, fNext, &fAccessor); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 369 | } else { |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 370 | this->spanFastRate(span); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 374 | void repeatSpan(Span span, int32_t repeatCount) override { |
| 375 | while (repeatCount > 0) { |
| 376 | this->pointSpan(span); |
| 377 | repeatCount--; |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
| 381 | private: |
| 382 | // When moving through source space more slowly than dst space (zoomed in), |
| 383 | // we'll be sampling from the same source pixel more than once. |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 384 | void spanSlowRate(Span span) { |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 385 | SkPoint start; SkScalar length; int count; |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 386 | std::tie(start, length, count) = span; |
| 387 | SkScalar x = X(start); |
| 388 | SkFixed fx = SkScalarToFixed(x); |
| 389 | SkScalar dx = length / (count - 1); |
| 390 | SkFixed fdx = SkScalarToFixed(dx); |
| 391 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 392 | const void* row = fAccessor.row((int)std::floor(Y(start))); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 393 | Next* next = fNext; |
| 394 | |
| 395 | int ix = SkFixedFloorToInt(fx); |
| 396 | int prevIX = ix; |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 397 | Sk4f fpixel = fAccessor.getPixelFromRow(row, ix); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 398 | |
| 399 | // When dx is less than one, each pixel is used more than once. Using the fixed point fx |
| 400 | // allows the code to quickly check that the same pixel is being used. The code uses this |
| 401 | // same pixel check to do the sRGB and normalization only once. |
| 402 | auto getNextPixel = [&]() { |
| 403 | if (ix != prevIX) { |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 404 | fpixel = fAccessor.getPixelFromRow(row, ix); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 405 | prevIX = ix; |
| 406 | } |
| 407 | fx += fdx; |
| 408 | ix = SkFixedFloorToInt(fx); |
| 409 | return fpixel; |
| 410 | }; |
| 411 | |
| 412 | while (count >= 4) { |
| 413 | Sk4f px0 = getNextPixel(); |
| 414 | Sk4f px1 = getNextPixel(); |
| 415 | Sk4f px2 = getNextPixel(); |
| 416 | Sk4f px3 = getNextPixel(); |
herb | 9e0efe5 | 2016-04-08 13:25:28 -0700 | [diff] [blame] | 417 | next->blend4Pixels(px0, px1, px2, px3); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 418 | count -= 4; |
| 419 | } |
| 420 | while (count > 0) { |
herb | 9e0efe5 | 2016-04-08 13:25:28 -0700 | [diff] [blame] | 421 | next->blendPixel(getNextPixel()); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 422 | count -= 1; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | // We're moving through source space at a rate of 1 source pixel per 1 dst pixel. |
| 427 | // We'll never re-use pixels, but we can at least load contiguous pixels. |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 428 | void spanUnitRate(Span span) { |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 429 | src_strategy_blend(span, fNext, &fAccessor); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | // We're moving through source space faster than dst (zoomed out), |
| 433 | // so we'll never reuse a source pixel or be able to do contiguous loads. |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 434 | void spanFastRate(Span span) { |
| 435 | span_fallback(span, this); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 436 | } |
| 437 | |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 438 | Next* const fNext; |
| 439 | Accessor fAccessor; |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 440 | }; |
| 441 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 442 | // From an edgeType, the integer value of a pixel vs, and the integer value of the extreme edge |
| 443 | // vMax, take the point which might be off the tile by one pixel and either wrap it or pin it to |
| 444 | // generate the right pixel. The value vs is on the interval [-1, vMax + 1]. It produces a value |
| 445 | // on the interval [0, vMax]. |
| 446 | // Note: vMax is not width or height, but width-1 or height-1 because it is the largest valid pixel. |
| 447 | static inline int adjust_edge(SkShader::TileMode edgeType, int vs, int vMax) { |
caryclark | d656200 | 2016-07-27 12:02:07 -0700 | [diff] [blame^] | 448 | SkASSERT(-1 <= vs && vs <= vMax + 1); |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 449 | switch (edgeType) { |
| 450 | case SkShader::kClamp_TileMode: |
| 451 | case SkShader::kMirror_TileMode: |
| 452 | vs = std::max(vs, 0); |
| 453 | vs = std::min(vs, vMax); |
| 454 | break; |
| 455 | case SkShader::kRepeat_TileMode: |
| 456 | vs = (vs <= vMax) ? vs : 0; |
| 457 | vs = (vs >= 0) ? vs : vMax; |
| 458 | break; |
| 459 | } |
| 460 | SkASSERT(0 <= vs && vs <= vMax); |
| 461 | return vs; |
| 462 | } |
| 463 | |
| 464 | // From a sample point on the tile, return the top or left filter value. |
| 465 | // The result r should be in the range (0, 1]. Since this represents the weight given to the top |
| 466 | // left element, then if x == 0.5 the filter value should be 1.0. |
| 467 | // The input sample point must be on the tile, therefore it must be >= 0. |
| 468 | static SkScalar sample_to_filter(SkScalar x) { |
| 469 | SkASSERT(x >= 0.0f); |
| 470 | // The usual form of the top or left edge is x - .5, but since we are working on the unit |
| 471 | // square, then x + .5 works just as well. This also guarantees that v > 0.0 allowing the use |
| 472 | // of trunc. |
| 473 | SkScalar v = x + 0.5f; |
| 474 | // Produce the top or left offset a value on the range [0, 1). |
| 475 | SkScalar f = v - SkScalarTruncToScalar(v); |
| 476 | // Produce the filter value which is on the range (0, 1]. |
| 477 | SkScalar r = 1.0f - f; |
| 478 | SkASSERT(0.0f < r && r <= 1.0f); |
| 479 | return r; |
| 480 | } |
| 481 | |
herb | 7df9e4a | 2016-06-10 13:01:27 -0700 | [diff] [blame] | 482 | // -- BilerpSampler -------------------------------------------------------------------------------- |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 483 | // BilerpSampler - use a bilerp filter to create runs of destination pixels. |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 484 | // Note: in the code below, there are two types of points |
| 485 | // * sample points - these are the points passed in by pointList* and Spans. |
| 486 | // * filter points - are created from a sample point to form the coordinates of the points |
| 487 | // to use in the filter and to generate the filter values. |
herb | 00dd453 | 2016-07-11 10:33:37 -0700 | [diff] [blame] | 488 | template<typename Accessor, typename Next> |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 489 | class BilerpSampler : public SkLinearBitmapPipeline::SampleProcessorInterface { |
| 490 | public: |
| 491 | template<typename... Args> |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 492 | BilerpSampler( |
| 493 | SkLinearBitmapPipeline::BlendProcessorInterface* next, |
| 494 | SkISize dimensions, |
| 495 | SkShader::TileMode xTile, SkShader::TileMode yTile, |
| 496 | Args&& ... args |
| 497 | ) |
| 498 | : fNext{next} |
| 499 | , fXEdgeType{xTile} |
| 500 | , fXMax{dimensions.width() - 1} |
| 501 | , fYEdgeType{yTile} |
| 502 | , fYMax{dimensions.height() - 1} |
| 503 | , fAccessor{std::forward<Args>(args)...} { } |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 504 | |
| 505 | BilerpSampler(SkLinearBitmapPipeline::BlendProcessorInterface* next, |
| 506 | const BilerpSampler& sampler) |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 507 | : fNext{next} |
| 508 | , fXEdgeType{sampler.fXEdgeType} |
| 509 | , fXMax{sampler.fXMax} |
| 510 | , fYEdgeType{sampler.fYEdgeType} |
| 511 | , fYMax{sampler.fYMax} |
| 512 | , fAccessor{sampler.fAccessor} { } |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 513 | |
mtklein | e5fb9c8 | 2016-07-07 08:12:09 -0700 | [diff] [blame] | 514 | void SK_VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override { |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 515 | SkASSERT(0 < n && n < 4); |
| 516 | auto bilerpPixel = [&](int index) { |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 517 | return this->bilerpSamplePoint(SkPoint{xs[index], ys[index]}); |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 518 | }; |
| 519 | |
| 520 | if (n >= 1) fNext->blendPixel(bilerpPixel(0)); |
| 521 | if (n >= 2) fNext->blendPixel(bilerpPixel(1)); |
| 522 | if (n >= 3) fNext->blendPixel(bilerpPixel(2)); |
| 523 | } |
| 524 | |
mtklein | e5fb9c8 | 2016-07-07 08:12:09 -0700 | [diff] [blame] | 525 | void SK_VECTORCALL pointList4(Sk4s xs, Sk4s ys) override { |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 526 | auto bilerpPixel = [&](int index) { |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 527 | return this->bilerpSamplePoint(SkPoint{xs[index], ys[index]}); |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 528 | }; |
| 529 | fNext->blend4Pixels(bilerpPixel(0), bilerpPixel(1), bilerpPixel(2), bilerpPixel(3)); |
| 530 | } |
| 531 | |
| 532 | void pointSpan(Span span) override { |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 533 | SkASSERT(!span.isEmpty()); |
| 534 | SkPoint start; |
| 535 | SkScalar length; |
| 536 | int count; |
| 537 | std::tie(start, length, count) = span; |
| 538 | |
| 539 | // Nothing to do. |
| 540 | if (count == 0) { |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | // Trivial case. No sample points are generated other than start. |
| 545 | if (count == 1) { |
| 546 | fNext->blendPixel(this->bilerpSamplePoint(start)); |
| 547 | return; |
| 548 | } |
| 549 | |
| 550 | // Note: the following code could be done in terms of dx = length / (count -1), but that |
| 551 | // would introduce a divide that is not needed for the most common dx == 1 cases. |
| 552 | SkScalar absLength = SkScalarAbs(length); |
| 553 | if (absLength == 0.0f) { |
| 554 | // |dx| == 0 |
| 555 | // length is zero, so clamp an edge pixel. |
| 556 | this->spanZeroRate(span); |
| 557 | } else if (absLength < (count - 1)) { |
| 558 | // 0 < |dx| < 1. |
| 559 | this->spanSlowRate(span); |
| 560 | } else if (absLength == (count - 1)) { |
| 561 | // |dx| == 1. |
| 562 | if (sample_to_filter(span.startX()) == 1.0f |
| 563 | && sample_to_filter(span.startY()) == 1.0f) { |
| 564 | // All the pixels are aligned with the dest; go fast. |
| 565 | src_strategy_blend(span, fNext, &fAccessor); |
| 566 | } else { |
| 567 | // There is some sub-pixel offsets, so bilerp. |
| 568 | this->spanUnitRate(span); |
| 569 | } |
| 570 | } else if (absLength < 2.0f * (count - 1)) { |
| 571 | // 1 < |dx| < 2. |
| 572 | this->spanMediumRate(span); |
| 573 | } else { |
| 574 | // |dx| >= 2. |
| 575 | this->spanFastRate(span); |
| 576 | } |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | void repeatSpan(Span span, int32_t repeatCount) override { |
| 580 | while (repeatCount > 0) { |
| 581 | this->pointSpan(span); |
| 582 | repeatCount--; |
| 583 | } |
| 584 | } |
| 585 | |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 586 | private: |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 587 | |
| 588 | // Convert a sample point to the points used by the filter. |
| 589 | void filterPoints(SkPoint sample, Sk4i* filterXs, Sk4i* filterYs) { |
| 590 | // May be less than zero. Be careful to use Floor. |
| 591 | int x0 = adjust_edge(fXEdgeType, SkScalarFloorToInt(X(sample) - 0.5), fXMax); |
| 592 | // Always greater than zero. Use the faster Trunc. |
| 593 | int x1 = adjust_edge(fXEdgeType, SkScalarTruncToInt(X(sample) + 0.5), fXMax); |
| 594 | int y0 = adjust_edge(fYEdgeType, SkScalarFloorToInt(Y(sample) - 0.5), fYMax); |
| 595 | int y1 = adjust_edge(fYEdgeType, SkScalarTruncToInt(Y(sample) + 0.5), fYMax); |
| 596 | |
| 597 | *filterXs = Sk4i{x0, x1, x0, x1}; |
| 598 | *filterYs = Sk4i{y0, y0, y1, y1}; |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 599 | } |
| 600 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 601 | // Given a sample point, generate a color by bilerping the four filter points. |
| 602 | Sk4f bilerpSamplePoint(SkPoint sample) { |
| 603 | Sk4i iXs, iYs; |
| 604 | filterPoints(sample, &iXs, &iYs); |
| 605 | Sk4f px00, px10, px01, px11; |
| 606 | fAccessor.get4Pixels(iXs, iYs, &px00, &px10, &px01, &px11); |
| 607 | return bilerp4(Sk4f{X(sample) - 0.5f}, Sk4f{Y(sample) - 0.5f}, px00, px10, px01, px11); |
| 608 | } |
| 609 | |
| 610 | // Get two pixels at x from row0 and row1. |
| 611 | void get2PixelColumn(const void* row0, const void* row1, int x, Sk4f* px0, Sk4f* px1) { |
| 612 | *px0 = fAccessor.getPixelFromRow(row0, x); |
| 613 | *px1 = fAccessor.getPixelFromRow(row1, x); |
| 614 | } |
| 615 | |
| 616 | // |dx| == 0. This code assumes that length is zero. |
| 617 | void spanZeroRate(Span span) { |
| 618 | SkPoint start; SkScalar length; int count; |
herb | 8602ede | 2016-07-21 13:22:04 -0700 | [diff] [blame] | 619 | std::tie(start, length, count) = span; |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 620 | SkASSERT(length == 0.0f); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 621 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 622 | // Filter for the blending of the top and bottom pixels. |
| 623 | SkScalar filterY = sample_to_filter(Y(start)); |
herb | 8602ede | 2016-07-21 13:22:04 -0700 | [diff] [blame] | 624 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 625 | // Generate the four filter points from the sample point start. Generate the row* values. |
| 626 | Sk4i iXs, iYs; |
| 627 | this->filterPoints(start, &iXs, &iYs); |
| 628 | const void* const row0 = fAccessor.row(iYs[0]); |
| 629 | const void* const row1 = fAccessor.row(iYs[2]); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 630 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 631 | // Get the two pixels that make up the clamping pixel. |
| 632 | Sk4f pxTop, pxBottom; |
| 633 | this->get2PixelColumn(row0, row1, SkScalarFloorToInt(X(start)), &pxTop, &pxBottom); |
| 634 | Sk4f pixel = pxTop * filterY + (1.0f - filterY) * pxBottom; |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 635 | |
| 636 | while (count >= 4) { |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 637 | fNext->blend4Pixels(pixel, pixel, pixel, pixel); |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 638 | count -= 4; |
| 639 | } |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 640 | while (count > 0) { |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 641 | fNext->blendPixel(pixel); |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 642 | count -= 1; |
| 643 | } |
| 644 | } |
| 645 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 646 | // 0 < |dx| < 1. This code reuses the calculations from previous pixels to reduce |
| 647 | // computation. In particular, several destination pixels maybe generated from the same four |
| 648 | // source pixels. |
| 649 | // In the following code a "part" is a combination of two pixels from the same column of the |
| 650 | // filter. |
| 651 | void spanSlowRate(Span span) { |
| 652 | SkPoint start; SkScalar length; int count; |
| 653 | std::tie(start, length, count) = span; |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 654 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 655 | // Calculate the distance between each sample point. |
| 656 | const SkScalar dx = length / (count - 1); |
| 657 | SkASSERT(-1.0f < dx && dx < 1.0f && dx != 0.0f); |
| 658 | |
| 659 | // Generate the filter values for the top-left corner. |
| 660 | // Note: these values are in filter space; this has implications about how to adjust |
| 661 | // these values at each step. For example, as the sample point increases, the filter |
| 662 | // value decreases, this is because the filter and position are related by |
| 663 | // (1 - (X(sample) - .5)) % 1. The (1 - stuff) causes the filter to move in the opposite |
| 664 | // direction of the sample point which is increasing by dx. |
| 665 | SkScalar filterX = sample_to_filter(X(start)); |
| 666 | SkScalar filterY = sample_to_filter(Y(start)); |
| 667 | |
| 668 | // Generate the four filter points from the sample point start. Generate the row* values. |
| 669 | Sk4i iXs, iYs; |
| 670 | this->filterPoints(start, &iXs, &iYs); |
| 671 | const void* const row0 = fAccessor.row(iYs[0]); |
| 672 | const void* const row1 = fAccessor.row(iYs[2]); |
| 673 | |
| 674 | // Generate part of the filter value at xColumn. |
| 675 | auto partAtColumn = [&](int xColumn) { |
| 676 | int adjustedColumn = adjust_edge(fXEdgeType, xColumn, fXMax); |
| 677 | Sk4f pxTop, pxBottom; |
| 678 | this->get2PixelColumn(row0, row1, adjustedColumn, &pxTop, &pxBottom); |
| 679 | return pxTop * filterY + (1.0f - filterY) * pxBottom; |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 680 | }; |
| 681 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 682 | // The leftPart is made up of two pixels from the left column of the filter, right part |
| 683 | // is similar. The top and bottom pixels in the *Part are created as a linear blend of |
| 684 | // the top and bottom pixels using filterY. See the partAtColumn function above. |
| 685 | Sk4f leftPart = partAtColumn(iXs[0]); |
| 686 | Sk4f rightPart = partAtColumn(iXs[1]); |
| 687 | |
| 688 | // Create a destination color by blending together a left and right part using filterX. |
| 689 | auto bilerp = [&](const Sk4f& leftPart, const Sk4f& rightPart) { |
| 690 | Sk4f pixel = leftPart * filterX + rightPart * (1.0f - filterX); |
| 691 | return check_pixel(pixel); |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 692 | }; |
| 693 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 694 | // Send the first pixel to the destination. This simplifies the loop structure so that no |
| 695 | // extra pixels are fetched for the last iteration of the loop. |
| 696 | fNext->blendPixel(bilerp(leftPart, rightPart)); |
| 697 | count -= 1; |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 698 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 699 | if (dx > 0.0f) { |
| 700 | // * positive direction - generate destination pixels by sliding the filter from left |
| 701 | // to right. |
| 702 | int rightPartCursor = iXs[1]; |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 703 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 704 | // Advance the filter from left to right. Remember that moving the top-left corner of |
| 705 | // the filter to the right actually makes the filter value smaller. |
| 706 | auto advanceFilter = [&]() { |
| 707 | filterX -= dx; |
| 708 | if (filterX <= 0.0f) { |
| 709 | filterX += 1.0f; |
| 710 | leftPart = rightPart; |
| 711 | rightPartCursor += 1; |
| 712 | rightPart = partAtColumn(rightPartCursor); |
| 713 | } |
| 714 | SkASSERT(0.0f < filterX && filterX <= 1.0f); |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 715 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 716 | return bilerp(leftPart, rightPart); |
| 717 | }; |
| 718 | |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 719 | while (count >= 4) { |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 720 | Sk4f px0 = advanceFilter(), |
| 721 | px1 = advanceFilter(), |
| 722 | px2 = advanceFilter(), |
| 723 | px3 = advanceFilter(); |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 724 | fNext->blend4Pixels(px0, px1, px2, px3); |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 725 | count -= 4; |
| 726 | } |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 727 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 728 | while (count > 0) { |
| 729 | fNext->blendPixel(advanceFilter()); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 730 | count -= 1; |
| 731 | } |
| 732 | } else { |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 733 | // * negative direction - generate destination pixels by sliding the filter from |
| 734 | // right to left. |
| 735 | int leftPartCursor = iXs[0]; |
| 736 | |
| 737 | // Advance the filter from right to left. Remember that moving the top-left corner of |
| 738 | // the filter to the left actually makes the filter value larger. |
| 739 | auto advanceFilter = [&]() { |
| 740 | // Remember, dx < 0 therefore this adds |dx| to filterX. |
| 741 | filterX -= dx; |
| 742 | // At this point filterX may be > 1, and needs to be wrapped back on to the filter |
| 743 | // interval, and the next column in the filter is calculated. |
| 744 | if (filterX > 1.0f) { |
| 745 | filterX -= 1.0f; |
| 746 | rightPart = leftPart; |
| 747 | leftPartCursor -= 1; |
| 748 | leftPart = partAtColumn(leftPartCursor); |
| 749 | } |
| 750 | SkASSERT(0.0f < filterX && filterX <= 1.0f); |
| 751 | |
| 752 | return bilerp(leftPart, rightPart); |
| 753 | }; |
| 754 | |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 755 | while (count >= 4) { |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 756 | Sk4f px0 = advanceFilter(), |
| 757 | px1 = advanceFilter(), |
| 758 | px2 = advanceFilter(), |
| 759 | px3 = advanceFilter(); |
herb | 9e0efe5 | 2016-04-08 13:25:28 -0700 | [diff] [blame] | 760 | fNext->blend4Pixels(px0, px1, px2, px3); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 761 | count -= 4; |
| 762 | } |
jcgregorio | da626aa | 2016-07-22 05:40:58 -0700 | [diff] [blame] | 763 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 764 | while (count > 0) { |
| 765 | fNext->blendPixel(advanceFilter()); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 766 | count -= 1; |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 771 | // |dx| == 1. Moving through source space at a rate of 1 source pixel per 1 dst pixel. |
| 772 | // Every filter part is used for two destination pixels, and the code can bulk load four |
| 773 | // pixels at a time. |
| 774 | void spanUnitRate(Span span) { |
| 775 | SkPoint start; SkScalar length; int count; |
| 776 | std::tie(start, length, count) = span; |
| 777 | SkASSERT(SkScalarAbs(length) == (count - 1)); |
| 778 | |
| 779 | // Calculate the four filter points of start, and use the two different Y values to |
| 780 | // generate the row pointers. |
| 781 | Sk4i iXs, iYs; |
| 782 | filterPoints(start, &iXs, &iYs); |
| 783 | const void* row0 = fAccessor.row(iYs[0]); |
| 784 | const void* row1 = fAccessor.row(iYs[2]); |
| 785 | |
| 786 | // Calculate the filter values for the top-left filter element. |
| 787 | const SkScalar filterX = sample_to_filter(X(start)); |
| 788 | const SkScalar filterY = sample_to_filter(Y(start)); |
| 789 | |
| 790 | // Generate part of the filter value at xColumn. |
| 791 | auto partAtColumn = [&](int xColumn) { |
| 792 | int adjustedColumn = adjust_edge(fXEdgeType, xColumn, fXMax); |
| 793 | Sk4f pxTop, pxBottom; |
| 794 | this->get2PixelColumn(row0, row1, adjustedColumn, &pxTop, &pxBottom); |
| 795 | return pxTop * filterY + (1.0f - filterY) * pxBottom; |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 796 | }; |
| 797 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 798 | auto get4Parts = [&](int ix, Sk4f* part0, Sk4f* part1, Sk4f* part2, Sk4f* part3) { |
| 799 | // Check if the pixels needed are near the edges. If not go fast using bulk pixels, |
| 800 | // otherwise be careful. |
| 801 | if (0 <= ix && ix <= fXMax - 3) { |
| 802 | Sk4f px00, px10, px20, px30, |
| 803 | px01, px11, px21, px31; |
| 804 | fAccessor.get4Pixels(row0, ix, &px00, &px10, &px20, &px30); |
| 805 | fAccessor.get4Pixels(row1, ix, &px01, &px11, &px21, &px31); |
| 806 | *part0 = filterY * px00 + (1.0f - filterY) * px01; |
| 807 | *part1 = filterY * px10 + (1.0f - filterY) * px11; |
| 808 | *part2 = filterY * px20 + (1.0f - filterY) * px21; |
| 809 | *part3 = filterY * px30 + (1.0f - filterY) * px31; |
| 810 | } else { |
| 811 | *part0 = partAtColumn(ix + 0); |
| 812 | *part1 = partAtColumn(ix + 1); |
| 813 | *part2 = partAtColumn(ix + 2); |
| 814 | *part3 = partAtColumn(ix + 3); |
| 815 | } |
| 816 | }; |
| 817 | |
| 818 | auto bilerp = [&](const Sk4f& part0, const Sk4f& part1) { |
| 819 | return part0 * filterX + part1 * (1.0f - filterX); |
| 820 | }; |
| 821 | |
| 822 | if (length > 0) { |
| 823 | // * positive direction - generate destination pixels by sliding the filter from left |
| 824 | // to right. |
| 825 | |
| 826 | // overlapPart is the filter part from the end of the previous four pixels used at |
| 827 | // the start of the next four pixels. |
| 828 | Sk4f overlapPart = partAtColumn(iXs[0]); |
| 829 | int rightColumnCursor = iXs[1]; |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 830 | while (count >= 4) { |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 831 | Sk4f part0, part1, part2, part3; |
| 832 | get4Parts(rightColumnCursor, &part0, &part1, &part2, &part3); |
| 833 | Sk4f px0 = bilerp(overlapPart, part0); |
| 834 | Sk4f px1 = bilerp(part0, part1); |
| 835 | Sk4f px2 = bilerp(part1, part2); |
| 836 | Sk4f px3 = bilerp(part2, part3); |
| 837 | overlapPart = part3; |
| 838 | fNext->blend4Pixels(px0, px1, px2, px3); |
| 839 | rightColumnCursor += 4; |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 840 | count -= 4; |
| 841 | } |
herb | 8602ede | 2016-07-21 13:22:04 -0700 | [diff] [blame] | 842 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 843 | while (count > 0) { |
| 844 | Sk4f rightPart = partAtColumn(rightColumnCursor); |
| 845 | |
| 846 | fNext->blendPixel(bilerp(overlapPart, rightPart)); |
| 847 | overlapPart = rightPart; |
| 848 | rightColumnCursor += 1; |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 849 | count -= 1; |
| 850 | } |
| 851 | } else { |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 852 | // * negative direction - generate destination pixels by sliding the filter from |
| 853 | // right to left. |
| 854 | Sk4f overlapPart = partAtColumn(iXs[1]); |
| 855 | int leftColumnCursor = iXs[0]; |
| 856 | |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 857 | while (count >= 4) { |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 858 | Sk4f part0, part1, part2, part3; |
| 859 | get4Parts(leftColumnCursor - 3, &part3, &part2, &part1, &part0); |
| 860 | Sk4f px0 = bilerp(part0, overlapPart); |
| 861 | Sk4f px1 = bilerp(part1, part0); |
| 862 | Sk4f px2 = bilerp(part2, part1); |
| 863 | Sk4f px3 = bilerp(part3, part2); |
| 864 | overlapPart = part3; |
| 865 | fNext->blend4Pixels(px0, px1, px2, px3); |
| 866 | leftColumnCursor -= 4; |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 867 | count -= 4; |
| 868 | } |
herb | 8602ede | 2016-07-21 13:22:04 -0700 | [diff] [blame] | 869 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 870 | while (count > 0) { |
| 871 | Sk4f leftPart = partAtColumn(leftColumnCursor); |
| 872 | |
| 873 | fNext->blendPixel(bilerp(leftPart, overlapPart)); |
| 874 | overlapPart = leftPart; |
| 875 | leftColumnCursor -= 1; |
| 876 | count -= 1; |
| 877 | } |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | // 1 < |dx| < 2. Going through the source pixels at a faster rate than the dest pixels, but |
| 882 | // still slow enough to take advantage of previous calculations. |
| 883 | void spanMediumRate(Span span) { |
| 884 | SkPoint start; SkScalar length; int count; |
| 885 | std::tie(start, length, count) = span; |
| 886 | |
| 887 | // Calculate the distance between each sample point. |
| 888 | const SkScalar dx = length / (count - 1); |
| 889 | SkASSERT((-2.0f < dx && dx < -1.0f) || (1.0f < dx && dx < 2.0f)); |
| 890 | |
| 891 | // Generate the filter values for the top-left corner. |
| 892 | // Note: these values are in filter space; this has implications about how to adjust |
| 893 | // these values at each step. For example, as the sample point increases, the filter |
| 894 | // value decreases, this is because the filter and position are related by |
| 895 | // (1 - (X(sample) - .5)) % 1. The (1 - stuff) causes the filter to move in the opposite |
| 896 | // direction of the sample point which is increasing by dx. |
| 897 | SkScalar filterX = sample_to_filter(X(start)); |
| 898 | SkScalar filterY = sample_to_filter(Y(start)); |
| 899 | |
| 900 | // Generate the four filter points from the sample point start. Generate the row* values. |
| 901 | Sk4i iXs, iYs; |
| 902 | this->filterPoints(start, &iXs, &iYs); |
| 903 | const void* const row0 = fAccessor.row(iYs[0]); |
| 904 | const void* const row1 = fAccessor.row(iYs[2]); |
| 905 | |
| 906 | // Generate part of the filter value at xColumn. |
| 907 | auto partAtColumn = [&](int xColumn) { |
| 908 | int adjustedColumn = adjust_edge(fXEdgeType, xColumn, fXMax); |
| 909 | Sk4f pxTop, pxBottom; |
| 910 | this->get2PixelColumn(row0, row1, adjustedColumn, &pxTop, &pxBottom); |
| 911 | return pxTop * filterY + (1.0f - filterY) * pxBottom; |
| 912 | }; |
| 913 | |
| 914 | // The leftPart is made up of two pixels from the left column of the filter, right part |
| 915 | // is similar. The top and bottom pixels in the *Part are created as a linear blend of |
| 916 | // the top and bottom pixels using filterY. See the nextPart function below. |
| 917 | Sk4f leftPart = partAtColumn(iXs[0]); |
| 918 | Sk4f rightPart = partAtColumn(iXs[1]); |
| 919 | |
| 920 | // Create a destination color by blending together a left and right part using filterX. |
| 921 | auto bilerp = [&](const Sk4f& leftPart, const Sk4f& rightPart) { |
| 922 | Sk4f pixel = leftPart * filterX + rightPart * (1.0f - filterX); |
| 923 | return check_pixel(pixel); |
| 924 | }; |
| 925 | |
| 926 | // Send the first pixel to the destination. This simplifies the loop structure so that no |
| 927 | // extra pixels are fetched for the last iteration of the loop. |
| 928 | fNext->blendPixel(bilerp(leftPart, rightPart)); |
| 929 | count -= 1; |
| 930 | |
| 931 | if (dx > 0.0f) { |
| 932 | // * positive direction - generate destination pixels by sliding the filter from left |
| 933 | // to right. |
| 934 | int rightPartCursor = iXs[1]; |
| 935 | |
| 936 | // Advance the filter from left to right. Remember that moving the top-left corner of |
| 937 | // the filter to the right actually makes the filter value smaller. |
| 938 | auto advanceFilter = [&]() { |
| 939 | filterX -= dx; |
| 940 | // At this point filterX is less than zero, but might actually be less than -1. |
| 941 | if (filterX > -1.0f) { |
| 942 | filterX += 1.0f; |
| 943 | leftPart = rightPart; |
| 944 | rightPartCursor += 1; |
| 945 | rightPart = partAtColumn(rightPartCursor); |
| 946 | } else { |
| 947 | filterX += 2.0f; |
| 948 | rightPartCursor += 2; |
| 949 | leftPart = partAtColumn(rightPartCursor - 1); |
| 950 | rightPart = partAtColumn(rightPartCursor); |
| 951 | } |
| 952 | SkASSERT(0.0f < filterX && filterX <= 1.0f); |
| 953 | |
| 954 | return bilerp(leftPart, rightPart); |
| 955 | }; |
| 956 | |
| 957 | while (count >= 4) { |
| 958 | Sk4f px0 = advanceFilter(), |
| 959 | px1 = advanceFilter(), |
| 960 | px2 = advanceFilter(), |
| 961 | px3 = advanceFilter(); |
| 962 | fNext->blend4Pixels(px0, px1, px2, px3); |
| 963 | count -= 4; |
| 964 | } |
| 965 | |
| 966 | while (count > 0) { |
| 967 | fNext->blendPixel(advanceFilter()); |
| 968 | count -= 1; |
| 969 | } |
| 970 | } else { |
| 971 | // * negative direction - generate destination pixels by sliding the filter from |
| 972 | // right to left. |
| 973 | int leftPartCursor = iXs[0]; |
| 974 | |
| 975 | auto advanceFilter = [&]() { |
| 976 | // Remember, dx < 0 therefore this adds |dx| to filterX. |
| 977 | filterX -= dx; |
| 978 | // At this point, filterX is greater than one, but may actually be greater than two. |
| 979 | if (filterX < 2.0f) { |
| 980 | filterX -= 1.0f; |
| 981 | rightPart = leftPart; |
| 982 | leftPartCursor -= 1; |
| 983 | leftPart = partAtColumn(leftPartCursor); |
| 984 | } else { |
| 985 | filterX -= 2.0f; |
| 986 | leftPartCursor -= 2; |
| 987 | rightPart = partAtColumn(leftPartCursor - 1); |
| 988 | leftPart = partAtColumn(leftPartCursor); |
| 989 | } |
| 990 | SkASSERT(0.0f < filterX && filterX <= 1.0f); |
| 991 | return bilerp(leftPart, rightPart); |
| 992 | }; |
| 993 | |
| 994 | while (count >= 4) { |
| 995 | Sk4f px0 = advanceFilter(), |
| 996 | px1 = advanceFilter(), |
| 997 | px2 = advanceFilter(), |
| 998 | px3 = advanceFilter(); |
| 999 | fNext->blend4Pixels(px0, px1, px2, px3); |
| 1000 | count -= 4; |
| 1001 | } |
| 1002 | |
| 1003 | while (count > 0) { |
| 1004 | fNext->blendPixel(advanceFilter()); |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 1005 | count -= 1; |
| 1006 | } |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | // We're moving through source space faster than dst (zoomed out), |
| 1011 | // so we'll never reuse a source pixel or be able to do contiguous loads. |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 1012 | void spanFastRate(Span span) { |
| 1013 | SkPoint start; SkScalar length; int count; |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 1014 | std::tie(start, length, count) = span; |
| 1015 | SkScalar x = X(start); |
| 1016 | SkScalar y = Y(start); |
herb | 7ccbc1a | 2016-06-09 09:05:00 -0700 | [diff] [blame] | 1017 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 1018 | SkScalar dx = length / (count - 1); |
| 1019 | while (count > 0) { |
| 1020 | fNext->blendPixel(this->bilerpSamplePoint(SkPoint{x, y})); |
| 1021 | x += dx; |
| 1022 | count -= 1; |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | |
herb | 86a6c6d | 2016-07-22 14:06:27 -0700 | [diff] [blame] | 1026 | Next* const fNext; |
| 1027 | const SkShader::TileMode fXEdgeType; |
| 1028 | const int fXMax; |
| 1029 | const SkShader::TileMode fYEdgeType; |
| 1030 | const int fYMax; |
| 1031 | Accessor fAccessor; |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 1032 | }; |
| 1033 | |
herb | 6eff52a | 2016-03-23 09:00:33 -0700 | [diff] [blame] | 1034 | } // namespace |
| 1035 | |
| 1036 | #endif // SkLinearBitmapPipeline_sampler_DEFINED |