OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 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 #include "SkAtomics.h" | 8 #include "SkAtomics.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 #include "SkConfig8888.h" |
11 #include "SkData.h" | 12 #include "SkData.h" |
12 #include "SkFilterQuality.h" | 13 #include "SkFilterQuality.h" |
13 #include "SkMallocPixelRef.h" | 14 #include "SkMallocPixelRef.h" |
14 #include "SkMask.h" | 15 #include "SkMask.h" |
15 #include "SkMath.h" | 16 #include "SkMath.h" |
16 #include "SkPixelRef.h" | 17 #include "SkPixelRef.h" |
17 #include "SkReadBuffer.h" | 18 #include "SkReadBuffer.h" |
18 #include "SkRect.h" | 19 #include "SkRect.h" |
19 #include "SkScalar.h" | 20 #include "SkScalar.h" |
20 #include "SkTemplates.h" | 21 #include "SkTemplates.h" |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 const SkColorType dstCT = this->colorType(); | 900 const SkColorType dstCT = this->colorType(); |
900 | 901 |
901 if (!this->canCopyTo(dstCT)) { | 902 if (!this->canCopyTo(dstCT)) { |
902 return false; | 903 return false; |
903 } | 904 } |
904 return this->copyTo(dst, dstCT, nullptr); | 905 return this->copyTo(dst, dstCT, nullptr); |
905 } | 906 } |
906 | 907 |
907 /////////////////////////////////////////////////////////////////////////////// | 908 /////////////////////////////////////////////////////////////////////////////// |
908 | 909 |
909 static void rect_memset(uint8_t* array, U8CPU value, SkISize size, size_t rowByt
es) { | |
910 for (int y = 0; y < size.height(); ++y) { | |
911 memset(array, value, size.width()); | |
912 array += rowBytes; | |
913 } | |
914 } | |
915 | |
916 static void get_bitmap_alpha(const SkPixmap& pmap, uint8_t* SK_RESTRICT alpha, i
nt alphaRowBytes) { | |
917 SkColorType colorType = pmap.colorType(); | |
918 int w = pmap.width(); | |
919 int h = pmap.height(); | |
920 size_t rb = pmap.rowBytes(); | |
921 | |
922 if (kAlpha_8_SkColorType == colorType && !pmap.isOpaque()) { | |
923 const uint8_t* s = pmap.addr8(0, 0); | |
924 while (--h >= 0) { | |
925 memcpy(alpha, s, w); | |
926 s += rb; | |
927 alpha += alphaRowBytes; | |
928 } | |
929 } else if (kN32_SkColorType == colorType && !pmap.isOpaque()) { | |
930 const SkPMColor* SK_RESTRICT s = pmap.addr32(0, 0); | |
931 while (--h >= 0) { | |
932 for (int x = 0; x < w; x++) { | |
933 alpha[x] = SkGetPackedA32(s[x]); | |
934 } | |
935 s = (const SkPMColor*)((const char*)s + rb); | |
936 alpha += alphaRowBytes; | |
937 } | |
938 } else if (kARGB_4444_SkColorType == colorType && !pmap.isOpaque()) { | |
939 const SkPMColor16* SK_RESTRICT s = pmap.addr16(0, 0); | |
940 while (--h >= 0) { | |
941 for (int x = 0; x < w; x++) { | |
942 alpha[x] = SkPacked4444ToA32(s[x]); | |
943 } | |
944 s = (const SkPMColor16*)((const char*)s + rb); | |
945 alpha += alphaRowBytes; | |
946 } | |
947 } else if (kIndex_8_SkColorType == colorType && !pmap.isOpaque()) { | |
948 const SkColorTable* ct = pmap.ctable(); | |
949 if (ct) { | |
950 const SkPMColor* SK_RESTRICT table = ct->readColors(); | |
951 const uint8_t* SK_RESTRICT s = pmap.addr8(0, 0); | |
952 while (--h >= 0) { | |
953 for (int x = 0; x < w; x++) { | |
954 alpha[x] = SkGetPackedA32(table[s[x]]); | |
955 } | |
956 s += rb; | |
957 alpha += alphaRowBytes; | |
958 } | |
959 } | |
960 } else { // src is opaque, so just fill alpha[] with 0xFF | |
961 rect_memset(alpha, 0xFF, pmap.info().dimensions(), alphaRowBytes); | |
962 } | |
963 } | |
964 | |
965 static bool GetBitmapAlpha(const SkBitmap& src, uint8_t* SK_RESTRICT alpha, int
alphaRowBytes) { | 910 static bool GetBitmapAlpha(const SkBitmap& src, uint8_t* SK_RESTRICT alpha, int
alphaRowBytes) { |
966 SkASSERT(alpha != nullptr); | 911 SkASSERT(alpha != nullptr); |
967 SkASSERT(alphaRowBytes >= src.width()); | 912 SkASSERT(alphaRowBytes >= src.width()); |
968 | 913 |
969 SkAutoPixmapUnlock apl; | 914 SkAutoPixmapUnlock apl; |
970 if (!src.requestLock(&apl)) { | 915 if (!src.requestLock(&apl)) { |
971 rect_memset(alpha, 0, src.info().dimensions(), alphaRowBytes); | 916 for (int y = 0; y < src.height(); ++y) { |
| 917 memset(alpha, 0, src.width()); |
| 918 alpha += alphaRowBytes; |
| 919 } |
972 return false; | 920 return false; |
973 } | 921 } |
974 get_bitmap_alpha(apl.pixmap(), alpha, alphaRowBytes); | 922 const SkPixmap& pmap = apl.pixmap(); |
| 923 SkPixelInfo::CopyPixels(SkImageInfo::MakeA8(pmap.width(), pmap.height()), al
pha, alphaRowBytes, |
| 924 pmap.info(), pmap.addr(), pmap.rowBytes(), pmap.ctab
le()); |
975 return true; | 925 return true; |
976 } | 926 } |
977 | 927 |
978 #include "SkPaint.h" | 928 #include "SkPaint.h" |
979 #include "SkMaskFilter.h" | 929 #include "SkMaskFilter.h" |
980 #include "SkMatrix.h" | 930 #include "SkMatrix.h" |
981 | 931 |
982 bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint, | 932 bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint, |
983 Allocator *allocator, SkIPoint* offset) const { | 933 Allocator *allocator, SkIPoint* offset) const { |
984 SkDEBUGCODE(this->validate();) | 934 SkDEBUGCODE(this->validate();) |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 /////////////////////////////////////////////////////////////////////////////// | 1252 /////////////////////////////////////////////////////////////////////////////// |
1303 | 1253 |
1304 #ifdef SK_DEBUG | 1254 #ifdef SK_DEBUG |
1305 void SkImageInfo::validate() const { | 1255 void SkImageInfo::validate() const { |
1306 SkASSERT(fWidth >= 0); | 1256 SkASSERT(fWidth >= 0); |
1307 SkASSERT(fHeight >= 0); | 1257 SkASSERT(fHeight >= 0); |
1308 SkASSERT(SkColorTypeIsValid(fColorType)); | 1258 SkASSERT(SkColorTypeIsValid(fColorType)); |
1309 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1259 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
1310 } | 1260 } |
1311 #endif | 1261 #endif |
OLD | NEW |