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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 SkScaledBitmapSampler::SkScaledBitmapSampler(int width, int height, | 569 SkScaledBitmapSampler::SkScaledBitmapSampler(int width, int height, |
570 int sampleSize) { | 570 int sampleSize) { |
571 fCTable = NULL; | 571 fCTable = NULL; |
572 fDstRow = NULL; | 572 fDstRow = NULL; |
573 fRowProc = NULL; | 573 fRowProc = NULL; |
574 | 574 |
575 if (width <= 0 || height <= 0) { | 575 if (width <= 0 || height <= 0) { |
576 sk_throw(); | 576 sk_throw(); |
577 } | 577 } |
578 | 578 |
| 579 SkDEBUGCODE(fSampleMode = kUninitialized_SampleMode); |
| 580 |
579 if (sampleSize <= 1) { | 581 if (sampleSize <= 1) { |
580 fScaledWidth = width; | 582 fScaledWidth = width; |
581 fScaledHeight = height; | 583 fScaledHeight = height; |
582 fX0 = fY0 = 0; | 584 fX0 = fY0 = 0; |
583 fDX = fDY = 1; | 585 fDX = fDY = 1; |
584 return; | 586 return; |
585 } | 587 } |
586 | 588 |
587 int dx = SkMin32(sampleSize, width); | 589 int dx = SkMin32(sampleSize, width); |
588 int dy = SkMin32(sampleSize, height); | 590 int dy = SkMin32(sampleSize, height); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 } else { | 706 } else { |
705 fRowProc = chooser(decoder); | 707 fRowProc = chooser(decoder); |
706 } | 708 } |
707 fDstRow = (char*)dst->getPixels(); | 709 fDstRow = (char*)dst->getPixels(); |
708 fDstRowBytes = dst->rowBytes(); | 710 fDstRowBytes = dst->rowBytes(); |
709 fCurrY = 0; | 711 fCurrY = 0; |
710 return fRowProc != NULL; | 712 return fRowProc != NULL; |
711 } | 713 } |
712 | 714 |
713 bool SkScaledBitmapSampler::next(const uint8_t* SK_RESTRICT src) { | 715 bool SkScaledBitmapSampler::next(const uint8_t* SK_RESTRICT src) { |
| 716 SkASSERT(kInterlaced_SampleMode != fSampleMode); |
| 717 SkDEBUGCODE(fSampleMode = kConsecutive_SampleMode); |
714 SkASSERT((unsigned)fCurrY < (unsigned)fScaledHeight); | 718 SkASSERT((unsigned)fCurrY < (unsigned)fScaledHeight); |
715 | 719 |
716 bool hadAlpha = fRowProc(fDstRow, src + fX0 * fSrcPixelSize, fScaledWidth, | 720 bool hadAlpha = fRowProc(fDstRow, src + fX0 * fSrcPixelSize, fScaledWidth, |
717 fDX * fSrcPixelSize, fCurrY, fCTable); | 721 fDX * fSrcPixelSize, fCurrY, fCTable); |
718 fDstRow += fDstRowBytes; | 722 fDstRow += fDstRowBytes; |
719 fCurrY += 1; | 723 fCurrY += 1; |
720 return hadAlpha; | 724 return hadAlpha; |
721 } | 725 } |
722 | 726 |
| 727 bool SkScaledBitmapSampler::sampleInterlaced(const uint8_t* SK_RESTRICT src, int
srcY) { |
| 728 SkASSERT(kConsecutive_SampleMode != fSampleMode); |
| 729 SkDEBUGCODE(fSampleMode = kInterlaced_SampleMode); |
| 730 // Any line that should be a part of the destination can be created by the f
ormula: |
| 731 // fY0 + (some multiplier) * fDY |
| 732 // so if srcY - fY0 is not an integer multiple of fDY that srcY will be skip
ped. |
| 733 const int srcYMinusY0 = srcY - fY0; |
| 734 if (srcYMinusY0 % fDY != 0) { |
| 735 // This line is not part of the output, so return false for alpha, since
we have |
| 736 // not added an alpha to the output. |
| 737 return false; |
| 738 } |
| 739 // Unlike in next(), where the data is used sequentially, this function skip
s around, |
| 740 // so fDstRow and fCurrY are never updated. fDstRow must always be the start
ing point |
| 741 // of the destination bitmap's pixels, which is used to calculate the destin
ation row |
| 742 // each time this function is called. |
| 743 const int dstY = srcYMinusY0 / fDY; |
| 744 SkASSERT(dstY < fScaledHeight); |
| 745 char* dstRow = fDstRow + dstY * fDstRowBytes; |
| 746 return fRowProc(dstRow, src + fX0 * fSrcPixelSize, fScaledWidth, |
| 747 fDX * fSrcPixelSize, dstY, fCTable); |
| 748 } |
| 749 |
723 #ifdef SK_DEBUG | 750 #ifdef SK_DEBUG |
724 // The following code is for a test to ensure that changing the method to get th
e right row proc | 751 // The following code is for a test to ensure that changing the method to get th
e right row proc |
725 // did not change the row proc unintentionally. Tested by ImageDecodingTest.cpp | 752 // did not change the row proc unintentionally. Tested by ImageDecodingTest.cpp |
726 | 753 |
727 // friend of SkScaledBitmapSampler solely for the purpose of accessing fRowProc. | 754 // friend of SkScaledBitmapSampler solely for the purpose of accessing fRowProc. |
728 class RowProcTester { | 755 class RowProcTester { |
729 public: | 756 public: |
730 static SkScaledBitmapSampler::RowProc getRowProc(const SkScaledBitmapSampler
& sampler) { | 757 static SkScaledBitmapSampler::RowProc getRowProc(const SkScaledBitmapSampler
& sampler) { |
731 return sampler.fRowProc; | 758 return sampler.fRowProc; |
732 } | 759 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 SkScaledBitmapSampler::RowProc actual = RowProcTester::getRo
wProc(sampler); | 839 SkScaledBitmapSampler::RowProc actual = RowProcTester::getRo
wProc(sampler); |
813 SkASSERT(expected == actual); | 840 SkASSERT(expected == actual); |
814 procCounter++; | 841 procCounter++; |
815 } | 842 } |
816 } | 843 } |
817 } | 844 } |
818 } | 845 } |
819 SkASSERT(SK_ARRAY_COUNT(gTestProcs) == procCounter); | 846 SkASSERT(SK_ARRAY_COUNT(gTestProcs) == procCounter); |
820 } | 847 } |
821 #endif // SK_DEBUG | 848 #endif // SK_DEBUG |
OLD | NEW |