| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2007 The Android Open Source Project | 2 * Copyright 2007 The Android Open Source Project |
| 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 | 8 |
| 9 #include "SkScaledBitmapSampler.h" | 9 #include "SkScaledBitmapSampler.h" |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 src += deltaSrc; | 336 src += deltaSrc; |
| 337 alphaMask &= alpha; | 337 alphaMask &= alpha; |
| 338 } | 338 } |
| 339 return alphaMask != 0xFF; | 339 return alphaMask != 0xFF; |
| 340 } | 340 } |
| 341 | 341 |
| 342 static SkScaledBitmapSampler::RowProc | 342 static SkScaledBitmapSampler::RowProc |
| 343 get_RGBA_to_4444_proc(const SkScaledBitmapSampler::Options& opts) { | 343 get_RGBA_to_4444_proc(const SkScaledBitmapSampler::Options& opts) { |
| 344 if (!opts.fPremultiplyAlpha) { | 344 if (!opts.fPremultiplyAlpha) { |
| 345 // Unpremultiplied is not supported for 4444 | 345 // Unpremultiplied is not supported for 4444 |
| 346 return NULL; | 346 return nullptr; |
| 347 } | 347 } |
| 348 if (opts.fSkipZeros) { | 348 if (opts.fSkipZeros) { |
| 349 if (opts.fDither) { | 349 if (opts.fDither) { |
| 350 return Sample_RGBA_D4444_D_SkipZ; | 350 return Sample_RGBA_D4444_D_SkipZ; |
| 351 } | 351 } |
| 352 return Sample_RGBA_D4444_SkipZ; | 352 return Sample_RGBA_D4444_SkipZ; |
| 353 } | 353 } |
| 354 if (opts.fDither) { | 354 if (opts.fDither) { |
| 355 return Sample_RGBA_D4444_D; | 355 return Sample_RGBA_D4444_D; |
| 356 } | 356 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 } | 508 } |
| 509 src += deltaSrc; | 509 src += deltaSrc; |
| 510 } | 510 } |
| 511 return cc != A32_MASK_IN_PLACE; | 511 return cc != A32_MASK_IN_PLACE; |
| 512 } | 512 } |
| 513 | 513 |
| 514 static SkScaledBitmapSampler::RowProc | 514 static SkScaledBitmapSampler::RowProc |
| 515 get_index_to_4444_proc(const SkScaledBitmapSampler::Options& opts) { | 515 get_index_to_4444_proc(const SkScaledBitmapSampler::Options& opts) { |
| 516 // Unpremul not allowed | 516 // Unpremul not allowed |
| 517 if (!opts.fPremultiplyAlpha) { | 517 if (!opts.fPremultiplyAlpha) { |
| 518 return NULL; | 518 return nullptr; |
| 519 } | 519 } |
| 520 if (opts.fSkipZeros) { | 520 if (opts.fSkipZeros) { |
| 521 if (opts.fDither) { | 521 if (opts.fDither) { |
| 522 return Sample_Index_D4444_D_SkipZ; | 522 return Sample_Index_D4444_D_SkipZ; |
| 523 } | 523 } |
| 524 return Sample_Index_D4444_SkipZ; | 524 return Sample_Index_D4444_SkipZ; |
| 525 } | 525 } |
| 526 if (opts.fDither) { | 526 if (opts.fDither) { |
| 527 return Sample_Index_D4444_D; | 527 return Sample_Index_D4444_D; |
| 528 } | 528 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 541 src += deltaSrc; | 541 src += deltaSrc; |
| 542 } | 542 } |
| 543 } | 543 } |
| 544 return false; | 544 return false; |
| 545 } | 545 } |
| 546 | 546 |
| 547 static SkScaledBitmapSampler::RowProc | 547 static SkScaledBitmapSampler::RowProc |
| 548 get_index_to_index_proc(const SkScaledBitmapSampler::Options& opts) { | 548 get_index_to_index_proc(const SkScaledBitmapSampler::Options& opts) { |
| 549 // Unpremul not allowed | 549 // Unpremul not allowed |
| 550 if (!opts.fPremultiplyAlpha) { | 550 if (!opts.fPremultiplyAlpha) { |
| 551 return NULL; | 551 return nullptr; |
| 552 } | 552 } |
| 553 // Ignore dither and skip zeroes | 553 // Ignore dither and skip zeroes |
| 554 return Sample_Index_DI; | 554 return Sample_Index_DI; |
| 555 } | 555 } |
| 556 | 556 |
| 557 // A8 | 557 // A8 |
| 558 static bool Sample_Gray_DA8(void* SK_RESTRICT dstRow, | 558 static bool Sample_Gray_DA8(void* SK_RESTRICT dstRow, |
| 559 const uint8_t* SK_RESTRICT src, | 559 const uint8_t* SK_RESTRICT src, |
| 560 int width, int deltaSrc, int, | 560 int width, int deltaSrc, int, |
| 561 const SkPMColor[]) { | 561 const SkPMColor[]) { |
| 562 // Sampling Gray to A8 uses the same function as Index to Index8, | 562 // Sampling Gray to A8 uses the same function as Index to Index8, |
| 563 // except we assume that there is alpha for speed, since an A8 | 563 // except we assume that there is alpha for speed, since an A8 |
| 564 // bitmap with no alpha is not interesting. | 564 // bitmap with no alpha is not interesting. |
| 565 (void) Sample_Index_DI(dstRow, src, width, deltaSrc, /* y unused */ 0, | 565 (void) Sample_Index_DI(dstRow, src, width, deltaSrc, /* y unused */ 0, |
| 566 /* ctable unused */ NULL); | 566 /* ctable unused */ nullptr); |
| 567 return true; | 567 return true; |
| 568 } | 568 } |
| 569 | 569 |
| 570 static SkScaledBitmapSampler::RowProc | 570 static SkScaledBitmapSampler::RowProc |
| 571 get_gray_to_A8_proc(const SkScaledBitmapSampler::Options& opts) { | 571 get_gray_to_A8_proc(const SkScaledBitmapSampler::Options& opts) { |
| 572 if (!opts.fPremultiplyAlpha) { | 572 if (!opts.fPremultiplyAlpha) { |
| 573 return NULL; | 573 return nullptr; |
| 574 } | 574 } |
| 575 // Ignore skip and dither. | 575 // Ignore skip and dither. |
| 576 return Sample_Gray_DA8; | 576 return Sample_Gray_DA8; |
| 577 } | 577 } |
| 578 | 578 |
| 579 typedef SkScaledBitmapSampler::RowProc (*RowProcChooser)(const SkScaledBitmapSam
pler::Options&); | 579 typedef SkScaledBitmapSampler::RowProc (*RowProcChooser)(const SkScaledBitmapSam
pler::Options&); |
| 580 /////////////////////////////////////////////////////////////////////////////// | 580 /////////////////////////////////////////////////////////////////////////////// |
| 581 | 581 |
| 582 #include "SkScaledBitmapSampler.h" | 582 #include "SkScaledBitmapSampler.h" |
| 583 | 583 |
| 584 SkScaledBitmapSampler::SkScaledBitmapSampler(int width, int height, | 584 SkScaledBitmapSampler::SkScaledBitmapSampler(int width, int height, |
| 585 int sampleSize) { | 585 int sampleSize) { |
| 586 fCTable = NULL; | 586 fCTable = nullptr; |
| 587 fDstRow = NULL; | 587 fDstRow = nullptr; |
| 588 fRowProc = NULL; | 588 fRowProc = nullptr; |
| 589 | 589 |
| 590 if (width <= 0 || height <= 0) { | 590 if (width <= 0 || height <= 0) { |
| 591 sk_throw(); | 591 sk_throw(); |
| 592 } | 592 } |
| 593 | 593 |
| 594 SkDEBUGCODE(fSampleMode = kUninitialized_SampleMode); | 594 SkDEBUGCODE(fSampleMode = kUninitialized_SampleMode); |
| 595 | 595 |
| 596 if (sampleSize <= 1) { | 596 if (sampleSize <= 1) { |
| 597 fScaledWidth = width; | 597 fScaledWidth = width; |
| 598 fScaledHeight = height; | 598 fScaledHeight = height; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 624 } | 624 } |
| 625 | 625 |
| 626 bool SkScaledBitmapSampler::begin(SkBitmap* dst, SrcConfig sc, | 626 bool SkScaledBitmapSampler::begin(SkBitmap* dst, SrcConfig sc, |
| 627 const Options& opts, | 627 const Options& opts, |
| 628 const SkPMColor ctable[]) { | 628 const SkPMColor ctable[]) { |
| 629 static const RowProcChooser gProcChoosers[] = { | 629 static const RowProcChooser gProcChoosers[] = { |
| 630 get_gray_to_8888_proc, | 630 get_gray_to_8888_proc, |
| 631 get_RGBx_to_8888_proc, | 631 get_RGBx_to_8888_proc, |
| 632 get_RGBA_to_8888_proc, | 632 get_RGBA_to_8888_proc, |
| 633 get_index_to_8888_proc, | 633 get_index_to_8888_proc, |
| 634 NULL, // 565 to 8888 | 634 nullptr, // 565 to 8888 |
| 635 | 635 |
| 636 get_gray_to_565_proc, | 636 get_gray_to_565_proc, |
| 637 get_RGBx_to_565_proc, | 637 get_RGBx_to_565_proc, |
| 638 get_RGBx_to_565_proc, // The source alpha will be ignored. | 638 get_RGBx_to_565_proc, // The source alpha will be ignored. |
| 639 get_index_to_565_proc, | 639 get_index_to_565_proc, |
| 640 get_565_to_565_proc, | 640 get_565_to_565_proc, |
| 641 | 641 |
| 642 get_gray_to_4444_proc, | 642 get_gray_to_4444_proc, |
| 643 get_RGBx_to_4444_proc, | 643 get_RGBx_to_4444_proc, |
| 644 get_RGBA_to_4444_proc, | 644 get_RGBA_to_4444_proc, |
| 645 get_index_to_4444_proc, | 645 get_index_to_4444_proc, |
| 646 NULL, // 565 to 4444 | 646 nullptr, // 565 to 4444 |
| 647 | 647 |
| 648 NULL, // gray to index | 648 nullptr, // gray to index |
| 649 NULL, // rgbx to index | 649 nullptr, // rgbx to index |
| 650 NULL, // rgba to index | 650 nullptr, // rgba to index |
| 651 get_index_to_index_proc, | 651 get_index_to_index_proc, |
| 652 NULL, // 565 to index | 652 nullptr, // 565 to index |
| 653 | 653 |
| 654 get_gray_to_A8_proc, | 654 get_gray_to_A8_proc, |
| 655 NULL, // rgbx to a8 | 655 nullptr, // rgbx to a8 |
| 656 NULL, // rgba to a8 | 656 nullptr, // rgba to a8 |
| 657 NULL, // index to a8 | 657 nullptr, // index to a8 |
| 658 NULL, // 565 to a8 | 658 nullptr, // 565 to a8 |
| 659 }; | 659 }; |
| 660 | 660 |
| 661 // The jump between dst configs in the table | 661 // The jump between dst configs in the table |
| 662 static const int gProcDstConfigSpan = 5; | 662 static const int gProcDstConfigSpan = 5; |
| 663 static_assert(SK_ARRAY_COUNT(gProcChoosers) == 5 * gProcDstConfigSpan, | 663 static_assert(SK_ARRAY_COUNT(gProcChoosers) == 5 * gProcDstConfigSpan, |
| 664 "gProcs_has_the_wrong_number_of_entries"); | 664 "gProcs_has_the_wrong_number_of_entries"); |
| 665 | 665 |
| 666 fCTable = ctable; | 666 fCTable = ctable; |
| 667 | 667 |
| 668 int index = 0; | 668 int index = 0; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 index += 3 * gProcDstConfigSpan; | 709 index += 3 * gProcDstConfigSpan; |
| 710 break; | 710 break; |
| 711 case kAlpha_8_SkColorType: | 711 case kAlpha_8_SkColorType: |
| 712 index += 4 * gProcDstConfigSpan; | 712 index += 4 * gProcDstConfigSpan; |
| 713 break; | 713 break; |
| 714 default: | 714 default: |
| 715 return false; | 715 return false; |
| 716 } | 716 } |
| 717 | 717 |
| 718 RowProcChooser chooser = gProcChoosers[index]; | 718 RowProcChooser chooser = gProcChoosers[index]; |
| 719 if (NULL == chooser) { | 719 if (nullptr == chooser) { |
| 720 fRowProc = NULL; | 720 fRowProc = nullptr; |
| 721 } else { | 721 } else { |
| 722 fRowProc = chooser(opts); | 722 fRowProc = chooser(opts); |
| 723 } | 723 } |
| 724 fDstRow = (char*)dst->getPixels(); | 724 fDstRow = (char*)dst->getPixels(); |
| 725 fDstRowBytes = dst->rowBytes(); | 725 fDstRowBytes = dst->rowBytes(); |
| 726 fCurrY = 0; | 726 fCurrY = 0; |
| 727 return fRowProc != NULL; | 727 return fRowProc != nullptr; |
| 728 } | 728 } |
| 729 | 729 |
| 730 bool SkScaledBitmapSampler::begin(SkBitmap* dst, SrcConfig sc, | 730 bool SkScaledBitmapSampler::begin(SkBitmap* dst, SrcConfig sc, |
| 731 const SkImageDecoder& decoder, | 731 const SkImageDecoder& decoder, |
| 732 const SkPMColor ctable[]) { | 732 const SkPMColor ctable[]) { |
| 733 return this->begin(dst, sc, Options(decoder), ctable); | 733 return this->begin(dst, sc, Options(decoder), ctable); |
| 734 } | 734 } |
| 735 | 735 |
| 736 bool SkScaledBitmapSampler::next(const uint8_t* SK_RESTRICT src) { | 736 bool SkScaledBitmapSampler::next(const uint8_t* SK_RESTRICT src) { |
| 737 SkASSERT(kInterlaced_SampleMode != fSampleMode); | 737 SkASSERT(kInterlaced_SampleMode != fSampleMode); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 // Table formated as follows: | 787 // Table formated as follows: |
| 788 // Each group of 5 consecutive rows represents sampling from a single | 788 // Each group of 5 consecutive rows represents sampling from a single |
| 789 // SkScaledBitmapSampler::SrcConfig. | 789 // SkScaledBitmapSampler::SrcConfig. |
| 790 // Within each set, each row represents a different destination SkBitmap::Config | 790 // Within each set, each row represents a different destination SkBitmap::Config |
| 791 // Each column represents a different combination of dither and unpremul. | 791 // Each column represents a different combination of dither and unpremul. |
| 792 // D = dither ~D = no dither | 792 // D = dither ~D = no dither |
| 793 // U = unpremul ~U = no unpremul | 793 // U = unpremul ~U = no unpremul |
| 794 // ~D~U D~U ~DU DU | 794 // ~D~U D~U ~DU DU |
| 795 SkScaledBitmapSampler::RowProc gTestProcs[] = { | 795 SkScaledBitmapSampler::RowProc gTestProcs[] = { |
| 796 // Gray | 796 // Gray |
| 797 Sample_Gray_DA8, Sample_Gray_DA8, NULL, NULL
, // to A8 | 797 Sample_Gray_DA8, Sample_Gray_DA8, nullptr, n
ullptr, // to A8 |
| 798 NULL, NULL, NULL, NULL
, // to Index8 | 798 nullptr, nullptr, nullptr,
nullptr, // to Index8 |
| 799 Sample_Gray_D565, Sample_Gray_D565_D, Sample_Gray_D565, Samp
le_Gray_D565_D, // to 565 | 799 Sample_Gray_D565, Sample_Gray_D565_D, Sample_Gray_D565, Samp
le_Gray_D565_D, // to 565 |
| 800 Sample_Gray_D4444, Sample_Gray_D4444_D, Sample_Gray_D4444, Samp
le_Gray_D4444_D, // to 4444 | 800 Sample_Gray_D4444, Sample_Gray_D4444_D, Sample_Gray_D4444, Samp
le_Gray_D4444_D, // to 4444 |
| 801 Sample_Gray_D8888, Sample_Gray_D8888, Sample_Gray_D8888, Samp
le_Gray_D8888, // to 8888 | 801 Sample_Gray_D8888, Sample_Gray_D8888, Sample_Gray_D8888, Samp
le_Gray_D8888, // to 8888 |
| 802 // Index | 802 // Index |
| 803 NULL, NULL, NULL, NULL
, // to A8 | 803 nullptr, nullptr, nullptr,
nullptr, // to A8 |
| 804 Sample_Index_DI, Sample_Index_DI, NULL, NULL
, // to Index8 | 804 Sample_Index_DI, Sample_Index_DI, nullptr, n
ullptr, // to Index8 |
| 805 Sample_Index_D565, Sample_Index_D565_D, Sample_Index_D565, Samp
le_Index_D565_D, // to 565 | 805 Sample_Index_D565, Sample_Index_D565_D, Sample_Index_D565, Samp
le_Index_D565_D, // to 565 |
| 806 Sample_Index_D4444, Sample_Index_D4444_D, NULL, NULL
, // to 4444 | 806 Sample_Index_D4444, Sample_Index_D4444_D, nullptr, n
ullptr, // to 4444 |
| 807 Sample_Index_D8888, Sample_Index_D8888, Sample_Index_D8888, Samp
le_Index_D8888, // to 8888 | 807 Sample_Index_D8888, Sample_Index_D8888, Sample_Index_D8888, Samp
le_Index_D8888, // to 8888 |
| 808 // RGB | 808 // RGB |
| 809 NULL, NULL, NULL, NULL
, // to A8 | 809 nullptr, nullptr, nullptr,
nullptr, // to A8 |
| 810 NULL, NULL, NULL, NULL
, // to Index8 | 810 nullptr, nullptr, nullptr,
nullptr, // to Index8 |
| 811 Sample_RGBx_D565, Sample_RGBx_D565_D, Sample_RGBx_D565, Samp
le_RGBx_D565_D, // to 565 | 811 Sample_RGBx_D565, Sample_RGBx_D565_D, Sample_RGBx_D565, Samp
le_RGBx_D565_D, // to 565 |
| 812 Sample_RGBx_D4444, Sample_RGBx_D4444_D, Sample_RGBx_D4444, Samp
le_RGBx_D4444_D, // to 4444 | 812 Sample_RGBx_D4444, Sample_RGBx_D4444_D, Sample_RGBx_D4444, Samp
le_RGBx_D4444_D, // to 4444 |
| 813 Sample_RGBx_D8888, Sample_RGBx_D8888, Sample_RGBx_D8888, Samp
le_RGBx_D8888, // to 8888 | 813 Sample_RGBx_D8888, Sample_RGBx_D8888, Sample_RGBx_D8888, Samp
le_RGBx_D8888, // to 8888 |
| 814 // RGBx is the same as RGB | 814 // RGBx is the same as RGB |
| 815 NULL, NULL, NULL, NULL
, // to A8 | 815 nullptr, nullptr, nullptr,
nullptr, // to A8 |
| 816 NULL, NULL, NULL, NULL
, // to Index8 | 816 nullptr, nullptr, nullptr,
nullptr, // to Index8 |
| 817 Sample_RGBx_D565, Sample_RGBx_D565_D, Sample_RGBx_D565, Samp
le_RGBx_D565_D, // to 565 | 817 Sample_RGBx_D565, Sample_RGBx_D565_D, Sample_RGBx_D565, Samp
le_RGBx_D565_D, // to 565 |
| 818 Sample_RGBx_D4444, Sample_RGBx_D4444_D, Sample_RGBx_D4444, Samp
le_RGBx_D4444_D, // to 4444 | 818 Sample_RGBx_D4444, Sample_RGBx_D4444_D, Sample_RGBx_D4444, Samp
le_RGBx_D4444_D, // to 4444 |
| 819 Sample_RGBx_D8888, Sample_RGBx_D8888, Sample_RGBx_D8888, Samp
le_RGBx_D8888, // to 8888 | 819 Sample_RGBx_D8888, Sample_RGBx_D8888, Sample_RGBx_D8888, Samp
le_RGBx_D8888, // to 8888 |
| 820 // RGBA | 820 // RGBA |
| 821 NULL, NULL, NULL, NULL
, // to A8 | 821 nullptr, nullptr, nullptr,
nullptr, // to A8 |
| 822 NULL, NULL, NULL, NULL
, // to Index8 | 822 nullptr, nullptr, nullptr,
nullptr, // to Index8 |
| 823 Sample_RGBx_D565, Sample_RGBx_D565_D, Sample_RGBx_D565, Samp
le_RGBx_D565_D, // to 565 | 823 Sample_RGBx_D565, Sample_RGBx_D565_D, Sample_RGBx_D565, Samp
le_RGBx_D565_D, // to 565 |
| 824 Sample_RGBA_D4444, Sample_RGBA_D4444_D, NULL, NULL
, // to 4444 | 824 Sample_RGBA_D4444, Sample_RGBA_D4444_D, nullptr, n
ullptr, // to 4444 |
| 825 Sample_RGBA_D8888, Sample_RGBA_D8888, Sample_RGBA_D8888_Unpremul, Samp
le_RGBA_D8888_Unpremul, // to 8888 | 825 Sample_RGBA_D8888, Sample_RGBA_D8888, Sample_RGBA_D8888_Unpremul, Samp
le_RGBA_D8888_Unpremul, // to 8888 |
| 826 // RGB_565 | 826 // RGB_565 |
| 827 NULL, NULL, NULL, NULL
, // to A8 | 827 nullptr, nullptr, nullptr,
nullptr, // to A8 |
| 828 NULL, NULL, NULL, NULL
, // to Index8 | 828 nullptr, nullptr, nullptr,
nullptr, // to Index8 |
| 829 Sample_D565_D565, Sample_D565_D565, Sample_D565_D565, Samp
le_D565_D565, // to 565 | 829 Sample_D565_D565, Sample_D565_D565, Sample_D565_D565, Samp
le_D565_D565, // to 565 |
| 830 NULL, NULL, NULL, NULL
, // to 4444 | 830 nullptr, nullptr, nullptr,
nullptr, // to 4444 |
| 831 NULL, NULL, NULL, NULL
, // to 8888 | 831 nullptr, nullptr, nullptr,
nullptr, // to 8888 |
| 832 }; | 832 }; |
| 833 | 833 |
| 834 // Dummy class that allows instantiation of an ImageDecoder, so begin can query
its fields. | 834 // Dummy class that allows instantiation of an ImageDecoder, so begin can query
its fields. |
| 835 class DummyDecoder : public SkImageDecoder { | 835 class DummyDecoder : public SkImageDecoder { |
| 836 public: | 836 public: |
| 837 DummyDecoder() {} | 837 DummyDecoder() {} |
| 838 protected: | 838 protected: |
| 839 Result onDecode(SkStream*, SkBitmap*, SkImageDecoder::Mode) override { | 839 Result onDecode(SkStream*, SkBitmap*, SkImageDecoder::Mode) override { |
| 840 return kFailure; | 840 return kFailure; |
| 841 } | 841 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 868 SkScaledBitmapSampler::RowProc actual = RowProcTester::getRo
wProc(sampler); | 868 SkScaledBitmapSampler::RowProc actual = RowProcTester::getRo
wProc(sampler); |
| 869 SkASSERT(expected == actual); | 869 SkASSERT(expected == actual); |
| 870 procCounter++; | 870 procCounter++; |
| 871 } | 871 } |
| 872 } | 872 } |
| 873 } | 873 } |
| 874 } | 874 } |
| 875 SkASSERT(SK_ARRAY_COUNT(gTestProcs) == procCounter); | 875 SkASSERT(SK_ARRAY_COUNT(gTestProcs) == procCounter); |
| 876 } | 876 } |
| 877 #endif // SK_DEBUG | 877 #endif // SK_DEBUG |
| OLD | NEW |