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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 277 |
278 /////////////////////////////////////////////////////////////////////////////// | 278 /////////////////////////////////////////////////////////////////////////////// |
279 | 279 |
280 bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes)
{ | 280 bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes)
{ |
281 if (kIndex_8_SkColorType == requestedInfo.colorType()) { | 281 if (kIndex_8_SkColorType == requestedInfo.colorType()) { |
282 return reset_return_false(this); | 282 return reset_return_false(this); |
283 } | 283 } |
284 if (!this->setInfo(requestedInfo, rowBytes)) { | 284 if (!this->setInfo(requestedInfo, rowBytes)) { |
285 return reset_return_false(this); | 285 return reset_return_false(this); |
286 } | 286 } |
287 | 287 |
288 // setInfo may have corrected info (e.g. 565 is always opaque). | 288 // setInfo may have corrected info (e.g. 565 is always opaque). |
289 const SkImageInfo& correctedInfo = this->info(); | 289 const SkImageInfo& correctedInfo = this->info(); |
290 // setInfo may have computed a valid rowbytes if 0 were passed in | 290 // setInfo may have computed a valid rowbytes if 0 were passed in |
291 rowBytes = this->rowBytes(); | 291 rowBytes = this->rowBytes(); |
292 | 292 |
293 SkMallocPixelRef::PRFactory defaultFactory; | 293 SkMallocPixelRef::PRFactory defaultFactory; |
294 | 294 |
295 SkPixelRef* pr = defaultFactory.create(correctedInfo, rowBytes, NULL); | 295 SkPixelRef* pr = defaultFactory.create(correctedInfo, rowBytes, NULL); |
296 if (NULL == pr) { | 296 if (NULL == pr) { |
297 return reset_return_false(this); | 297 return reset_return_false(this); |
298 } | 298 } |
299 this->setPixelRef(pr)->unref(); | 299 this->setPixelRef(pr)->unref(); |
300 | 300 |
301 // TODO: lockPixels could/should return bool or void*/NULL | 301 // TODO: lockPixels could/should return bool or void*/NULL |
302 this->lockPixels(); | 302 this->lockPixels(); |
303 if (NULL == this->getPixels()) { | 303 if (NULL == this->getPixels()) { |
304 return reset_return_false(this); | 304 return reset_return_false(this); |
305 } | 305 } |
306 return true; | 306 return true; |
307 } | 307 } |
308 | 308 |
309 bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactor
y* factory, | 309 bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactor
y* factory, |
310 SkColorTable* ctable) { | 310 SkColorTable* ctable) { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 for (int x = 0; x < width; ++x) { | 579 for (int x = 0; x < width; ++x) { |
580 a &= row[x]; | 580 a &= row[x]; |
581 } | 581 } |
582 if (0xFF != a) { | 582 if (0xFF != a) { |
583 return false; | 583 return false; |
584 } | 584 } |
585 } | 585 } |
586 return true; | 586 return true; |
587 } break; | 587 } break; |
588 case kIndex_8_SkColorType: { | 588 case kIndex_8_SkColorType: { |
589 SkAutoLockColors alc(bm); | 589 if (!bm.getColorTable()) { |
590 const SkPMColor* table = alc.colors(); | |
591 if (!table) { | |
592 return false; | 590 return false; |
593 } | 591 } |
| 592 const SkPMColor* table = bm.getColorTable()->readColors(); |
594 SkPMColor c = (SkPMColor)~0; | 593 SkPMColor c = (SkPMColor)~0; |
595 for (int i = bm.getColorTable()->count() - 1; i >= 0; --i) { | 594 for (int i = bm.getColorTable()->count() - 1; i >= 0; --i) { |
596 c &= table[i]; | 595 c &= table[i]; |
597 } | 596 } |
598 return 0xFF == SkGetPackedA32(c); | 597 return 0xFF == SkGetPackedA32(c); |
599 } break; | 598 } break; |
600 case kRGB_565_SkColorType: | 599 case kRGB_565_SkColorType: |
601 return true; | 600 return true; |
602 break; | 601 break; |
603 case kARGB_4444_SkColorType: { | 602 case kARGB_4444_SkColorType: { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 int x, int y) const { | 840 int x, int y) const { |
842 if (kUnknown_SkColorType == requestedDstInfo.colorType()) { | 841 if (kUnknown_SkColorType == requestedDstInfo.colorType()) { |
843 return false; | 842 return false; |
844 } | 843 } |
845 if (NULL == dstPixels || dstRB < requestedDstInfo.minRowBytes()) { | 844 if (NULL == dstPixels || dstRB < requestedDstInfo.minRowBytes()) { |
846 return false; | 845 return false; |
847 } | 846 } |
848 if (0 == requestedDstInfo.width() || 0 == requestedDstInfo.height()) { | 847 if (0 == requestedDstInfo.width() || 0 == requestedDstInfo.height()) { |
849 return false; | 848 return false; |
850 } | 849 } |
851 | 850 |
852 SkIRect srcR = SkIRect::MakeXYWH(x, y, requestedDstInfo.width(), requestedDs
tInfo.height()); | 851 SkIRect srcR = SkIRect::MakeXYWH(x, y, requestedDstInfo.width(), requestedDs
tInfo.height()); |
853 if (!srcR.intersect(0, 0, this->width(), this->height())) { | 852 if (!srcR.intersect(0, 0, this->width(), this->height())) { |
854 return false; | 853 return false; |
855 } | 854 } |
856 | 855 |
857 // the intersect may have shrunk info's logical size | 856 // the intersect may have shrunk info's logical size |
858 const SkImageInfo dstInfo = requestedDstInfo.makeWH(srcR.width(), srcR.heigh
t()); | 857 const SkImageInfo dstInfo = requestedDstInfo.makeWH(srcR.width(), srcR.heigh
t()); |
859 | 858 |
860 // if x or y are negative, then we have to adjust pixels | 859 // if x or y are negative, then we have to adjust pixels |
861 if (x > 0) { | 860 if (x > 0) { |
862 x = 0; | 861 x = 0; |
863 } | 862 } |
864 if (y > 0) { | 863 if (y > 0) { |
865 y = 0; | 864 y = 0; |
866 } | 865 } |
867 // here x,y are either 0 or negative | 866 // here x,y are either 0 or negative |
868 dstPixels = ((char*)dstPixels - y * dstRB - x * dstInfo.bytesPerPixel()); | 867 dstPixels = ((char*)dstPixels - y * dstRB - x * dstInfo.bytesPerPixel()); |
869 | 868 |
870 ////////////// | 869 ////////////// |
871 | 870 |
872 SkAutoLockPixels alp(*this); | 871 SkAutoLockPixels alp(*this); |
873 | 872 |
874 // since we don't stop creating un-pixeled devices yet, check for no pixels
here | 873 // since we don't stop creating un-pixeled devices yet, check for no pixels
here |
875 if (NULL == this->getPixels()) { | 874 if (NULL == this->getPixels()) { |
876 return false; | 875 return false; |
877 } | 876 } |
878 | 877 |
879 const SkImageInfo srcInfo = this->info().makeWH(dstInfo.width(), dstInfo.hei
ght()); | 878 const SkImageInfo srcInfo = this->info().makeWH(dstInfo.width(), dstInfo.hei
ght()); |
880 | 879 |
881 const void* srcPixels = this->getAddr(srcR.x(), srcR.y()); | 880 const void* srcPixels = this->getAddr(srcR.x(), srcR.y()); |
882 return SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRB, srcInfo, srcPixels
, this->rowBytes(), | 881 return SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRB, srcInfo, srcPixels
, this->rowBytes(), |
883 this->getColorTable()); | 882 this->getColorTable()); |
884 } | 883 } |
885 | 884 |
886 bool SkBitmap::copyTo(SkBitmap* dst, SkColorType dstColorType, Allocator* alloc)
const { | 885 bool SkBitmap::copyTo(SkBitmap* dst, SkColorType dstColorType, Allocator* alloc)
const { |
887 if (!this->canCopyTo(dstColorType)) { | 886 if (!this->canCopyTo(dstColorType)) { |
888 return false; | 887 return false; |
889 } | 888 } |
890 | 889 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 while (--h >= 0) { | 1059 while (--h >= 0) { |
1061 for (int x = 0; x < w; x++) { | 1060 for (int x = 0; x < w; x++) { |
1062 alpha[x] = SkPacked4444ToA32(s[x]); | 1061 alpha[x] = SkPacked4444ToA32(s[x]); |
1063 } | 1062 } |
1064 s = (const SkPMColor16*)((const char*)s + rb); | 1063 s = (const SkPMColor16*)((const char*)s + rb); |
1065 alpha += alphaRowBytes; | 1064 alpha += alphaRowBytes; |
1066 } | 1065 } |
1067 } else if (kIndex_8_SkColorType == colorType && !src.isOpaque()) { | 1066 } else if (kIndex_8_SkColorType == colorType && !src.isOpaque()) { |
1068 SkColorTable* ct = src.getColorTable(); | 1067 SkColorTable* ct = src.getColorTable(); |
1069 if (ct) { | 1068 if (ct) { |
1070 const SkPMColor* SK_RESTRICT table = ct->lockColors(); | 1069 const SkPMColor* SK_RESTRICT table = ct->readColors(); |
1071 const uint8_t* SK_RESTRICT s = src.getAddr8(0, 0); | 1070 const uint8_t* SK_RESTRICT s = src.getAddr8(0, 0); |
1072 while (--h >= 0) { | 1071 while (--h >= 0) { |
1073 for (int x = 0; x < w; x++) { | 1072 for (int x = 0; x < w; x++) { |
1074 alpha[x] = SkGetPackedA32(table[s[x]]); | 1073 alpha[x] = SkGetPackedA32(table[s[x]]); |
1075 } | 1074 } |
1076 s += rb; | 1075 s += rb; |
1077 alpha += alphaRowBytes; | 1076 alpha += alphaRowBytes; |
1078 } | 1077 } |
1079 ct->unlockColors(); | |
1080 } | 1078 } |
1081 } else { // src is opaque, so just fill alpha[] with 0xFF | 1079 } else { // src is opaque, so just fill alpha[] with 0xFF |
1082 memset(alpha, 0xFF, h * alphaRowBytes); | 1080 memset(alpha, 0xFF, h * alphaRowBytes); |
1083 } | 1081 } |
1084 return true; | 1082 return true; |
1085 } | 1083 } |
1086 | 1084 |
1087 #include "SkPaint.h" | 1085 #include "SkPaint.h" |
1088 #include "SkMaskFilter.h" | 1086 #include "SkMaskFilter.h" |
1089 #include "SkMatrix.h" | 1087 #include "SkMatrix.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 /////////////////////////////////////////////////////////////////////////////// | 1378 /////////////////////////////////////////////////////////////////////////////// |
1381 | 1379 |
1382 #ifdef SK_DEBUG | 1380 #ifdef SK_DEBUG |
1383 void SkImageInfo::validate() const { | 1381 void SkImageInfo::validate() const { |
1384 SkASSERT(fWidth >= 0); | 1382 SkASSERT(fWidth >= 0); |
1385 SkASSERT(fHeight >= 0); | 1383 SkASSERT(fHeight >= 0); |
1386 SkASSERT(SkColorTypeIsValid(fColorType)); | 1384 SkASSERT(SkColorTypeIsValid(fColorType)); |
1387 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1385 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
1388 } | 1386 } |
1389 #endif | 1387 #endif |
OLD | NEW |