| 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 | 9 |
| 10 #include <algorithm> |
| 11 #include <cmath> |
| 12 #include <limits> |
| 13 #include "SkColor.h" |
| 14 #include "SkSize.h" |
| 15 |
| 10 struct X { | 16 struct X { |
| 11 explicit X(SkScalar val) : fVal{val} { } | 17 explicit X(SkScalar val) : fVal{val} { } |
| 12 explicit X(SkPoint pt) : fVal{pt.fX} { } | 18 explicit X(SkPoint pt) : fVal{pt.fX} { } |
| 13 explicit X(SkSize s) : fVal{s.fWidth} { } | 19 explicit X(SkSize s) : fVal{s.fWidth} { } |
| 14 explicit X(SkISize s) : fVal(s.fWidth) { } | 20 explicit X(SkISize s) : fVal(s.fWidth) { } |
| 15 operator float () const {return fVal;} | 21 operator float () const {return fVal;} |
| 16 private: | 22 private: |
| 17 float fVal; | 23 float fVal; |
| 18 }; | 24 }; |
| 19 | 25 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 return matrixProc->get(); | 189 return matrixProc->get(); |
| 184 } | 190 } |
| 185 | 191 |
| 186 template <typename Next = BilerpProcessorInterface> | 192 template <typename Next = BilerpProcessorInterface> |
| 187 class ExpandBilerp final : public PointProcessorInterface { | 193 class ExpandBilerp final : public PointProcessorInterface { |
| 188 public: | 194 public: |
| 189 ExpandBilerp(Next* next) : fNext{next} { } | 195 ExpandBilerp(Next* next) : fNext{next} { } |
| 190 | 196 |
| 191 void pointListFew(int n, Sk4fArg xs, Sk4fArg ys) override { | 197 void pointListFew(int n, Sk4fArg xs, Sk4fArg ys) override { |
| 192 SkASSERT(0 < n && n < 4); | 198 SkASSERT(0 < n && n < 4); |
| 193 // px00 px10 px01 px11 | 199 // px00 px10 px01 px11 |
| 194 const Sk4f kXOffsets{0.0f, 1.0f, 0.0f, 1.0f}, | 200 const Sk4f kXOffsets{-0.5f, 0.5f, -0.5f, 0.5f}, |
| 195 kYOffsets{0.0f, 0.0f, 1.0f, 1.0f}; | 201 kYOffsets{-0.5f, -0.5f, 0.5f, 0.5f}; |
| 196 if (n >= 1) fNext->bilerpList(Sk4f{xs[0]} + kXOffsets, Sk4f{ys[0]} + kYO
ffsets); | 202 if (n >= 1) fNext->bilerpList(Sk4f{xs[0]} + kXOffsets, Sk4f{ys[0]} + kYO
ffsets); |
| 197 if (n >= 2) fNext->bilerpList(Sk4f{xs[1]} + kXOffsets, Sk4f{ys[1]} + kYO
ffsets); | 203 if (n >= 2) fNext->bilerpList(Sk4f{xs[1]} + kXOffsets, Sk4f{ys[1]} + kYO
ffsets); |
| 198 if (n >= 3) fNext->bilerpList(Sk4f{xs[2]} + kXOffsets, Sk4f{ys[2]} + kYO
ffsets); | 204 if (n >= 3) fNext->bilerpList(Sk4f{xs[2]} + kXOffsets, Sk4f{ys[2]} + kYO
ffsets); |
| 199 } | 205 } |
| 200 | 206 |
| 201 void pointList4(Sk4fArg xs, Sk4fArg ys) override { | 207 void pointList4(Sk4fArg xs, Sk4fArg ys) override { |
| 202 // px00 px10 px01 px11 | 208 // px00 px10 px01 px11 |
| 203 const Sk4f kXOffsets{0.0f, 1.0f, 0.0f, 1.0f}, | 209 const Sk4f kXOffsets{-0.5f, 0.5f, -0.5f, 0.5f}, |
| 204 kYOffsets{0.0f, 0.0f, 1.0f, 1.0f}; | 210 kYOffsets{-0.5f, -0.5f, 0.5f, 0.5f}; |
| 205 fNext->bilerpList(Sk4f{xs[0]} + kXOffsets, Sk4f{ys[0]} + kYOffsets); | 211 fNext->bilerpList(Sk4f{xs[0]} + kXOffsets, Sk4f{ys[0]} + kYOffsets); |
| 206 fNext->bilerpList(Sk4f{xs[1]} + kXOffsets, Sk4f{ys[1]} + kYOffsets); | 212 fNext->bilerpList(Sk4f{xs[1]} + kXOffsets, Sk4f{ys[1]} + kYOffsets); |
| 207 fNext->bilerpList(Sk4f{xs[2]} + kXOffsets, Sk4f{ys[2]} + kYOffsets); | 213 fNext->bilerpList(Sk4f{xs[2]} + kXOffsets, Sk4f{ys[2]} + kYOffsets); |
| 208 fNext->bilerpList(Sk4f{xs[3]} + kXOffsets, Sk4f{ys[3]} + kYOffsets); | 214 fNext->bilerpList(Sk4f{xs[3]} + kXOffsets, Sk4f{ys[3]} + kYOffsets); |
| 209 } | 215 } |
| 210 | 216 |
| 211 private: | 217 private: |
| 212 Next* const fNext; | 218 Next* const fNext; |
| 213 }; | 219 }; |
| 214 | 220 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 fNext->placePixel(pixel); | 454 fNext->placePixel(pixel); |
| 449 } | 455 } |
| 450 | 456 |
| 451 private: | 457 private: |
| 452 PixelPlacerInterface* const fNext; | 458 PixelPlacerInterface* const fNext; |
| 453 SourceStrategy fStrategy; | 459 SourceStrategy fStrategy; |
| 454 }; | 460 }; |
| 455 | 461 |
| 456 static BilerpProcessorInterface* choose_pixel_sampler( | 462 static BilerpProcessorInterface* choose_pixel_sampler( |
| 457 PixelPlacerInterface* next, | 463 PixelPlacerInterface* next, |
| 458 const SkImageInfo& imageInfo, | 464 const SkPixmap& srcPixmap, |
| 459 const void* imageData, | |
| 460 SkLinearBitmapPipeline::SampleStage* sampleStage) { | 465 SkLinearBitmapPipeline::SampleStage* sampleStage) { |
| 466 const SkImageInfo& imageInfo = srcPixmap.info(); |
| 461 switch (imageInfo.colorType()) { | 467 switch (imageInfo.colorType()) { |
| 462 case kRGBA_8888_SkColorType: | 468 case kRGBA_8888_SkColorType: |
| 463 case kBGRA_8888_SkColorType: | 469 case kBGRA_8888_SkColorType: |
| 464 if (kN32_SkColorType == imageInfo.colorType()) { | 470 if (kN32_SkColorType == imageInfo.colorType()) { |
| 465 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { | 471 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { |
| 466 sampleStage->Initialize<Sampler<Passthrough8888<kSRGB_SkColo
rProfileType>>>( | 472 sampleStage->Initialize<Sampler<Passthrough8888<kSRGB_SkColo
rProfileType>>>( |
| 467 next, imageInfo.width(), | 473 next, static_cast<int>(srcPixmap.rowBytes() / 4), |
| 468 (uint32_t*)imageData); | 474 srcPixmap.addr32()); |
| 469 } else { | 475 } else { |
| 470 sampleStage->Initialize<Sampler<Passthrough8888<kLinear_SkCo
lorProfileType>>>( | 476 sampleStage->Initialize<Sampler<Passthrough8888<kLinear_SkCo
lorProfileType>>>( |
| 471 next, imageInfo.width(), | 477 next, static_cast<int>(srcPixmap.rowBytes() / 4), |
| 472 (uint32_t*)imageData); | 478 srcPixmap.addr32()); |
| 473 } | 479 } |
| 474 } else { | 480 } else { |
| 475 SkFAIL("Not implemented. No 8888 Swizzle"); | 481 SkFAIL("Not implemented. No 8888 Swizzle"); |
| 476 } | 482 } |
| 477 break; | 483 break; |
| 478 default: | 484 default: |
| 479 SkFAIL("Not implemented. Unsupported src"); | 485 SkFAIL("Not implemented. Unsupported src"); |
| 480 break; | 486 break; |
| 481 } | 487 } |
| 482 return sampleStage->get(); | 488 return sampleStage->get(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 // kOpaque_SkAlphaType is treated the same as kPremul_SkAlphaType | 534 // kOpaque_SkAlphaType is treated the same as kPremul_SkAlphaType |
| 529 placerStage->Initialize<PlaceFPPixel<kPremul_SkAlphaType>>(); | 535 placerStage->Initialize<PlaceFPPixel<kPremul_SkAlphaType>>(); |
| 530 } | 536 } |
| 531 return placerStage->get(); | 537 return placerStage->get(); |
| 532 } | 538 } |
| 533 | 539 |
| 534 SkLinearBitmapPipeline::SkLinearBitmapPipeline( | 540 SkLinearBitmapPipeline::SkLinearBitmapPipeline( |
| 535 const SkMatrix& inverse, | 541 const SkMatrix& inverse, |
| 536 SkFilterQuality filterQuality, | 542 SkFilterQuality filterQuality, |
| 537 SkShader::TileMode xTile, SkShader::TileMode yTile, | 543 SkShader::TileMode xTile, SkShader::TileMode yTile, |
| 538 const SkImageInfo& srcImageInfo, | 544 const SkPixmap& srcPixmap) { |
| 539 const void* srcImageData) { | 545 SkSize size = SkSize::Make(srcPixmap.width(), srcPixmap.height()); |
| 540 SkSize size; | 546 const SkImageInfo& srcImageInfo = srcPixmap.info(); |
| 541 size = srcImageInfo.dimensions(); | |
| 542 | 547 |
| 543 // As the stages are built, the chooser function may skip a stage. For examp
le, with the | 548 // As the stages are built, the chooser function may skip a stage. For examp
le, with the |
| 544 // identity matrix, the matrix stage is skipped, and the tilerStage is the f
irst stage. | 549 // identity matrix, the matrix stage is skipped, and the tilerStage is the f
irst stage. |
| 545 auto placementStage = choose_pixel_placer(srcImageInfo.alphaType(), &fPixelS
tage); | 550 auto placementStage = choose_pixel_placer(srcImageInfo.alphaType(), &fPixelS
tage); |
| 546 auto samplerStage = choose_pixel_sampler(placementStage, srcImageInfo, | 551 auto samplerStage = choose_pixel_sampler(placementStage, srcPixmap, &fSamp
leStage); |
| 547 srcImageData, &fSampleStage); | |
| 548 auto tilerStage = choose_tiler(samplerStage, size, xTile, yTile, &fTileX
OrBothStage, | 552 auto tilerStage = choose_tiler(samplerStage, size, xTile, yTile, &fTileX
OrBothStage, |
| 549 &fTileYStage); | 553 &fTileYStage); |
| 550 auto filterStage = choose_filter(tilerStage, filterQuality, &fFilterStage
); | 554 auto filterStage = choose_filter(tilerStage, filterQuality, &fFilterStage
); |
| 551 fFirstStage = choose_matrix(filterStage, inverse, &fMatrixStage); | 555 fFirstStage = choose_matrix(filterStage, inverse, &fMatrixStage); |
| 552 } | 556 } |
| 553 | 557 |
| 554 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { | 558 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { |
| 555 fPixelStage->setDestination(dst); | 559 fPixelStage->setDestination(dst); |
| 556 | 560 |
| 557 Sk4f Xs = Sk4f(x) + Sk4f{0.5f, 1.5f, 2.5f, 3.5f}; | 561 Sk4f Xs = Sk4f(x) + Sk4f{0.5f, 1.5f, 2.5f, 3.5f}; |
| 558 Sk4f Ys(y); | 562 Sk4f Ys(y); |
| 559 Sk4f fours{4.0f}; | 563 Sk4f fours{4.0f}; |
| 560 | 564 |
| 561 while (count >= 4) { | 565 while (count >= 4) { |
| 562 fFirstStage->pointList4(Xs, Ys); | 566 fFirstStage->pointList4(Xs, Ys); |
| 563 Xs = Xs + fours; | 567 Xs = Xs + fours; |
| 564 count -= 4; | 568 count -= 4; |
| 565 } | 569 } |
| 566 if (count > 0) { | 570 if (count > 0) { |
| 567 fFirstStage->pointListFew(count, Xs, Ys); | 571 fFirstStage->pointListFew(count, Xs, Ys); |
| 568 } | 572 } |
| 569 } | 573 } |
| OLD | NEW |