OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 /////////////////////////////////////////////////////////////////////////////// | 732 /////////////////////////////////////////////////////////////////////////////// |
733 | 733 |
734 static uint16_t pack_8888_to_4444(unsigned a, unsigned r, unsigned g, unsigned b
) { | 734 static uint16_t pack_8888_to_4444(unsigned a, unsigned r, unsigned g, unsigned b
) { |
735 unsigned pixel = (SkA32To4444(a) << SK_A4444_SHIFT) | | 735 unsigned pixel = (SkA32To4444(a) << SK_A4444_SHIFT) | |
736 (SkR32To4444(r) << SK_R4444_SHIFT) | | 736 (SkR32To4444(r) << SK_R4444_SHIFT) | |
737 (SkG32To4444(g) << SK_G4444_SHIFT) | | 737 (SkG32To4444(g) << SK_G4444_SHIFT) | |
738 (SkB32To4444(b) << SK_B4444_SHIFT); | 738 (SkB32To4444(b) << SK_B4444_SHIFT); |
739 return SkToU16(pixel); | 739 return SkToU16(pixel); |
740 } | 740 } |
741 | 741 |
742 void SkBitmap::eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const { | 742 void SkBitmap::internalErase(const SkIRect& area, |
| 743 U8CPU a, U8CPU r, U8CPU g, U8CPU b) const { |
| 744 #ifdef SK_DEBUG |
743 SkDEBUGCODE(this->validate();) | 745 SkDEBUGCODE(this->validate();) |
| 746 SkASSERT(!area.isEmpty()); |
| 747 { |
| 748 SkIRect total = { 0, 0, fWidth, fHeight }; |
| 749 SkASSERT(total.contains(area)); |
| 750 } |
| 751 #endif |
744 | 752 |
745 if (0 == fWidth || 0 == fHeight || | 753 if (kNo_Config == fConfig || kIndex8_Config == fConfig) { |
746 kNo_Config == fConfig || kIndex8_Config == fConfig) { | |
747 return; | 754 return; |
748 } | 755 } |
749 | 756 |
750 SkAutoLockPixels alp(*this); | 757 SkAutoLockPixels alp(*this); |
751 // perform this check after the lock call | 758 // perform this check after the lock call |
752 if (!this->readyToDraw()) { | 759 if (!this->readyToDraw()) { |
753 return; | 760 return; |
754 } | 761 } |
755 | 762 |
756 int height = fHeight; | 763 int height = area.height(); |
757 const int width = fWidth; | 764 const int width = area.width(); |
758 const int rowBytes = fRowBytes; | 765 const int rowBytes = fRowBytes; |
759 | 766 |
760 // make rgb premultiplied | 767 // make rgb premultiplied |
761 if (255 != a) { | 768 if (255 != a) { |
762 r = SkAlphaMul(r, a); | 769 r = SkAlphaMul(r, a); |
763 g = SkAlphaMul(g, a); | 770 g = SkAlphaMul(g, a); |
764 b = SkAlphaMul(b, a); | 771 b = SkAlphaMul(b, a); |
765 } | 772 } |
766 | 773 |
767 switch (fConfig) { | 774 switch (fConfig) { |
768 case kA1_Config: { | 775 case kA1_Config: { |
769 uint8_t* p = (uint8_t*)fPixels; | 776 uint8_t* p = this->getAddr1(area.fLeft, area.fTop); |
770 const int count = (width + 7) >> 3; | 777 const int left = area.fLeft >> 3; |
| 778 const int right = area.fRight >> 3; |
| 779 |
| 780 int middle = right - left - 1; |
| 781 |
| 782 uint8_t leftMask = 0xFF >> (area.fLeft & 7); |
| 783 uint8_t rightMask = ~(0xFF >> (area.fRight & 7)); |
| 784 if (left == right) { |
| 785 leftMask &= rightMask; |
| 786 rightMask = 0; |
| 787 } |
| 788 |
771 a = (a >> 7) ? 0xFF : 0; | 789 a = (a >> 7) ? 0xFF : 0; |
772 SkASSERT(count <= rowBytes); | |
773 while (--height >= 0) { | 790 while (--height >= 0) { |
774 memset(p, a, count); | 791 uint8_t* startP = p; |
775 p += rowBytes; | 792 |
| 793 *p = (*p & ~leftMask) | (a & leftMask); |
| 794 p++; |
| 795 if (middle > 0) { |
| 796 memset(p, a, middle); |
| 797 p += middle; |
| 798 } |
| 799 if (rightMask) { |
| 800 *p = (*p & ~rightMask) | (a & rightMask); |
| 801 } |
| 802 |
| 803 p = startP + rowBytes; |
776 } | 804 } |
777 break; | 805 break; |
778 } | 806 } |
779 case kA8_Config: { | 807 case kA8_Config: { |
780 uint8_t* p = (uint8_t*)fPixels; | 808 uint8_t* p = this->getAddr8(area.fLeft, area.fTop); |
781 while (--height >= 0) { | 809 while (--height >= 0) { |
782 memset(p, a, width); | 810 memset(p, a, width); |
783 p += rowBytes; | 811 p += rowBytes; |
784 } | 812 } |
785 break; | 813 break; |
786 } | 814 } |
787 case kARGB_4444_Config: | 815 case kARGB_4444_Config: |
788 case kRGB_565_Config: { | 816 case kRGB_565_Config: { |
789 uint16_t* p = (uint16_t*)fPixels; | 817 uint16_t* p = this->getAddr16(area.fLeft, area.fTop);; |
790 uint16_t v; | 818 uint16_t v; |
791 | 819 |
792 if (kARGB_4444_Config == fConfig) { | 820 if (kARGB_4444_Config == fConfig) { |
793 v = pack_8888_to_4444(a, r, g, b); | 821 v = pack_8888_to_4444(a, r, g, b); |
794 } else { | 822 } else { |
795 v = SkPackRGB16(r >> (8 - SK_R16_BITS), | 823 v = SkPackRGB16(r >> (8 - SK_R16_BITS), |
796 g >> (8 - SK_G16_BITS), | 824 g >> (8 - SK_G16_BITS), |
797 b >> (8 - SK_B16_BITS)); | 825 b >> (8 - SK_B16_BITS)); |
798 } | 826 } |
799 while (--height >= 0) { | 827 while (--height >= 0) { |
800 sk_memset16(p, v, width); | 828 sk_memset16(p, v, width); |
801 p = (uint16_t*)((char*)p + rowBytes); | 829 p = (uint16_t*)((char*)p + rowBytes); |
802 } | 830 } |
803 break; | 831 break; |
804 } | 832 } |
805 case kARGB_8888_Config: { | 833 case kARGB_8888_Config: { |
806 uint32_t* p = (uint32_t*)fPixels; | 834 uint32_t* p = this->getAddr32(area.fLeft, area.fTop); |
807 uint32_t v = SkPackARGB32(a, r, g, b); | 835 uint32_t v = SkPackARGB32(a, r, g, b); |
808 | 836 |
809 while (--height >= 0) { | 837 while (--height >= 0) { |
810 sk_memset32(p, v, width); | 838 sk_memset32(p, v, width); |
811 p = (uint32_t*)((char*)p + rowBytes); | 839 p = (uint32_t*)((char*)p + rowBytes); |
812 } | 840 } |
813 break; | 841 break; |
814 } | 842 } |
815 } | 843 } |
816 | 844 |
817 this->notifyPixelsChanged(); | 845 this->notifyPixelsChanged(); |
818 } | 846 } |
819 | 847 |
| 848 void SkBitmap::eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) const { |
| 849 SkIRect area = { 0, 0, fWidth, fHeight }; |
| 850 if (!area.isEmpty()) { |
| 851 this->internalErase(area, a, r, g, b); |
| 852 } |
| 853 } |
| 854 |
| 855 void SkBitmap::eraseArea(const SkIRect& rect, SkColor c) const { |
| 856 SkIRect area = { 0, 0, fWidth, fHeight }; |
| 857 if (area.intersect(rect)) { |
| 858 this->internalErase(area, SkColorGetA(c), SkColorGetR(c), |
| 859 SkColorGetG(c), SkColorGetB(c)); |
| 860 } |
| 861 } |
| 862 |
820 ////////////////////////////////////////////////////////////////////////////////
////// | 863 ////////////////////////////////////////////////////////////////////////////////
////// |
821 ////////////////////////////////////////////////////////////////////////////////
////// | 864 ////////////////////////////////////////////////////////////////////////////////
////// |
822 | 865 |
823 #define SUB_OFFSET_FAILURE ((size_t)-1) | 866 #define SUB_OFFSET_FAILURE ((size_t)-1) |
824 | 867 |
825 /** | 868 /** |
826 * Based on the Config and rowBytes() of bm, return the offset into an SkPixelR
ef of the pixel at | 869 * Based on the Config and rowBytes() of bm, return the offset into an SkPixelR
ef of the pixel at |
827 * (x, y). | 870 * (x, y). |
828 * Note that the SkPixelRef does not need to be set yet. deepCopyTo takes advan
tage of this fact. | 871 * Note that the SkPixelRef does not need to be set yet. deepCopyTo takes advan
tage of this fact. |
829 * Also note that (x, y) may be outside the range of (0 - width(), 0 - height()
), so long as it is | 872 * Also note that (x, y) may be outside the range of (0 - width(), 0 - height()
), so long as it is |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1643 if (NULL != uri) { | 1686 if (NULL != uri) { |
1644 str->appendf(" uri:\"%s\"", uri); | 1687 str->appendf(" uri:\"%s\"", uri); |
1645 } else { | 1688 } else { |
1646 str->appendf(" pixelref:%p", pr); | 1689 str->appendf(" pixelref:%p", pr); |
1647 } | 1690 } |
1648 } | 1691 } |
1649 | 1692 |
1650 str->append(")"); | 1693 str->append(")"); |
1651 } | 1694 } |
1652 #endif | 1695 #endif |
OLD | NEW |