Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: src/core/SkBitmap.cpp

Issue 212643014: fix SkBitmap::erase to handle RGBA and BGRA (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 SkASSERT(!area.isEmpty()); 832 SkASSERT(!area.isEmpty());
833 { 833 {
834 SkIRect total = { 0, 0, this->width(), this->height() }; 834 SkIRect total = { 0, 0, this->width(), this->height() };
835 SkASSERT(total.contains(area)); 835 SkASSERT(total.contains(area));
836 } 836 }
837 #endif 837 #endif
838 838
839 switch (fInfo.colorType()) { 839 switch (fInfo.colorType()) {
840 case kUnknown_SkColorType: 840 case kUnknown_SkColorType:
841 case kIndex_8_SkColorType: 841 case kIndex_8_SkColorType:
842 return; // can't erase 842 return; // can't erase. Should we bzero so the memory is not uniniti alized?
843 default: 843 default:
844 break; 844 break;
845 } 845 }
846 846
847 SkAutoLockPixels alp(*this); 847 SkAutoLockPixels alp(*this);
848 // perform this check after the lock call 848 // perform this check after the lock call
849 if (!this->readyToDraw()) { 849 if (!this->readyToDraw()) {
850 return; 850 return;
851 } 851 }
852 852
853 int height = area.height(); 853 int height = area.height();
854 const int width = area.width(); 854 const int width = area.width();
855 const int rowBytes = fRowBytes; 855 const int rowBytes = fRowBytes;
856 856
857 // make rgb premultiplied
858 if (255 != a) {
859 r = SkAlphaMul(r, a);
860 g = SkAlphaMul(g, a);
861 b = SkAlphaMul(b, a);
862 }
863
864 switch (this->colorType()) { 857 switch (this->colorType()) {
865 case kAlpha_8_SkColorType: { 858 case kAlpha_8_SkColorType: {
866 uint8_t* p = this->getAddr8(area.fLeft, area.fTop); 859 uint8_t* p = this->getAddr8(area.fLeft, area.fTop);
867 while (--height >= 0) { 860 while (--height >= 0) {
868 memset(p, a, width); 861 memset(p, a, width);
869 p += rowBytes; 862 p += rowBytes;
870 } 863 }
871 break; 864 break;
872 } 865 }
873 case kARGB_4444_SkColorType: 866 case kARGB_4444_SkColorType:
874 case kRGB_565_SkColorType: { 867 case kRGB_565_SkColorType: {
875 uint16_t* p = this->getAddr16(area.fLeft, area.fTop);; 868 uint16_t* p = this->getAddr16(area.fLeft, area.fTop);;
876 uint16_t v; 869 uint16_t v;
877 870
871 // make rgb premultiplied
872 if (255 != a) {
873 r = SkAlphaMul(r, a);
874 g = SkAlphaMul(g, a);
875 b = SkAlphaMul(b, a);
876 }
877
878 if (kARGB_4444_SkColorType == this->colorType()) { 878 if (kARGB_4444_SkColorType == this->colorType()) {
879 v = pack_8888_to_4444(a, r, g, b); 879 v = pack_8888_to_4444(a, r, g, b);
880 } else { 880 } else {
881 v = SkPackRGB16(r >> (8 - SK_R16_BITS), 881 v = SkPackRGB16(r >> (8 - SK_R16_BITS),
882 g >> (8 - SK_G16_BITS), 882 g >> (8 - SK_G16_BITS),
883 b >> (8 - SK_B16_BITS)); 883 b >> (8 - SK_B16_BITS));
884 } 884 }
885 while (--height >= 0) { 885 while (--height >= 0) {
886 sk_memset16(p, v, width); 886 sk_memset16(p, v, width);
887 p = (uint16_t*)((char*)p + rowBytes); 887 p = (uint16_t*)((char*)p + rowBytes);
888 } 888 }
889 break; 889 break;
890 } 890 }
891 case kPMColor_SkColorType: { 891 case kBGRA_8888_SkColorType:
892 // what to do about BGRA or RGBA (which ever is != PMColor ? 892 case kRGBA_8888_SkColorType: {
893 // for now we don't support them.
894 uint32_t* p = this->getAddr32(area.fLeft, area.fTop); 893 uint32_t* p = this->getAddr32(area.fLeft, area.fTop);
895 uint32_t v = SkPackARGB32(a, r, g, b); 894
895 if (255 != a && kPremul_SkAlphaType == this->alphaType()) {
896 r = SkAlphaMul(r, a);
897 g = SkAlphaMul(g, a);
898 b = SkAlphaMul(b, a);
899 }
900 uint32_t v = kRGBA_8888_SkColorType == this->colorType() ?
901 SkPackARGB_as_RGBA(a, r, g, b) : SkPackARGB_as_BGRA(a, r, g, b);
896 902
897 while (--height >= 0) { 903 while (--height >= 0) {
898 sk_memset32(p, v, width); 904 sk_memset32(p, v, width);
899 p = (uint32_t*)((char*)p + rowBytes); 905 p = (uint32_t*)((char*)p + rowBytes);
900 } 906 }
901 break; 907 break;
902 } 908 }
903 default: 909 default:
904 return; // no change, so don't call notifyPixelsChanged() 910 return; // no change, so don't call notifyPixelsChanged()
905 } 911 }
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 /////////////////////////////////////////////////////////////////////////////// 1728 ///////////////////////////////////////////////////////////////////////////////
1723 1729
1724 #ifdef SK_DEBUG 1730 #ifdef SK_DEBUG
1725 void SkImageInfo::validate() const { 1731 void SkImageInfo::validate() const {
1726 SkASSERT(fWidth >= 0); 1732 SkASSERT(fWidth >= 0);
1727 SkASSERT(fHeight >= 0); 1733 SkASSERT(fHeight >= 0);
1728 SkASSERT(SkColorTypeIsValid(fColorType)); 1734 SkASSERT(SkColorTypeIsValid(fColorType));
1729 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); 1735 SkASSERT(SkAlphaTypeIsValid(fAlphaType));
1730 } 1736 }
1731 #endif 1737 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698