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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 dst->lockPixels(); | 495 dst->lockPixels(); |
496 return true; | 496 return true; |
497 } | 497 } |
498 | 498 |
499 /////////////////////////////////////////////////////////////////////////////// | 499 /////////////////////////////////////////////////////////////////////////////// |
500 | 500 |
501 size_t SkBitmap::getSafeSize() const { | 501 size_t SkBitmap::getSafeSize() const { |
502 // This is intended to be a size_t version of ComputeSafeSize64(), just | 502 // This is intended to be a size_t version of ComputeSafeSize64(), just |
503 // faster. The computation is meant to be identical. | 503 // faster. The computation is meant to be identical. |
504 return (fHeight ? ((fHeight - 1) * fRowBytes) + | 504 return (fHeight ? ((fHeight - 1) * fRowBytes) + |
505 ComputeRowBytes(getConfig(), fWidth): 0); | 505 ComputeRowBytes(this->config(), fWidth): 0); |
506 } | 506 } |
507 | 507 |
508 Sk64 SkBitmap::getSafeSize64() const { | 508 Sk64 SkBitmap::getSafeSize64() const { |
509 return ComputeSafeSize64(getConfig(), fWidth, fHeight, fRowBytes); | 509 return ComputeSafeSize64(this->config(), fWidth, fHeight, fRowBytes); |
510 } | 510 } |
511 | 511 |
512 bool SkBitmap::copyPixelsTo(void* const dst, size_t dstSize, | 512 bool SkBitmap::copyPixelsTo(void* const dst, size_t dstSize, |
513 size_t dstRowBytes, bool preserveDstPad) const { | 513 size_t dstRowBytes, bool preserveDstPad) const { |
514 | 514 |
515 if (0 == dstRowBytes) { | 515 if (0 == dstRowBytes) { |
516 dstRowBytes = fRowBytes; | 516 dstRowBytes = fRowBytes; |
517 } | 517 } |
518 | 518 |
519 if (dstRowBytes < ComputeRowBytes(getConfig(), fWidth) || | 519 if (dstRowBytes < ComputeRowBytes(this->config(), fWidth) || |
520 dst == NULL || (getPixels() == NULL && pixelRef() == NULL)) | 520 dst == NULL || (getPixels() == NULL && pixelRef() == NULL)) |
521 return false; | 521 return false; |
522 | 522 |
523 if (!preserveDstPad && static_cast<uint32_t>(dstRowBytes) == fRowBytes) { | 523 if (!preserveDstPad && static_cast<uint32_t>(dstRowBytes) == fRowBytes) { |
524 size_t safeSize = getSafeSize(); | 524 size_t safeSize = this->getSafeSize(); |
525 if (safeSize > dstSize || safeSize == 0) | 525 if (safeSize > dstSize || safeSize == 0) |
526 return false; | 526 return false; |
527 else { | 527 else { |
528 SkAutoLockPixels lock(*this); | 528 SkAutoLockPixels lock(*this); |
529 // This implementation will write bytes beyond the end of each row, | 529 // This implementation will write bytes beyond the end of each row, |
530 // excluding the last row, if the bitmap's stride is greater than | 530 // excluding the last row, if the bitmap's stride is greater than |
531 // strictly required by the current config. | 531 // strictly required by the current config. |
532 memcpy(dst, getPixels(), safeSize); | 532 memcpy(dst, getPixels(), safeSize); |
533 | 533 |
534 return true; | 534 return true; |
535 } | 535 } |
536 } else { | 536 } else { |
537 // If destination has different stride than us, then copy line by line. | 537 // If destination has different stride than us, then copy line by line. |
538 if (ComputeSafeSize(getConfig(), fWidth, fHeight, dstRowBytes) > | 538 if (ComputeSafeSize(this->config(), fWidth, fHeight, dstRowBytes) > |
539 dstSize) | 539 dstSize) |
540 return false; | 540 return false; |
541 else { | 541 else { |
542 // Just copy what we need on each line. | 542 // Just copy what we need on each line. |
543 size_t rowBytes = ComputeRowBytes(getConfig(), fWidth); | 543 size_t rowBytes = ComputeRowBytes(this->config(), fWidth); |
544 SkAutoLockPixels lock(*this); | 544 SkAutoLockPixels lock(*this); |
545 const uint8_t* srcP = reinterpret_cast<const uint8_t*>(getPixels()); | 545 const uint8_t* srcP = reinterpret_cast<const uint8_t*>(getPixels()); |
546 uint8_t* dstP = reinterpret_cast<uint8_t*>(dst); | 546 uint8_t* dstP = reinterpret_cast<uint8_t*>(dst); |
547 for (uint32_t row = 0; row < fHeight; | 547 for (uint32_t row = 0; row < fHeight; |
548 row++, srcP += fRowBytes, dstP += dstRowBytes) { | 548 row++, srcP += fRowBytes, dstP += dstRowBytes) { |
549 memcpy(dstP, srcP, rowBytes); | 549 memcpy(dstP, srcP, rowBytes); |
550 } | 550 } |
551 | 551 |
552 return true; | 552 return true; |
553 } | 553 } |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 #define SUB_OFFSET_FAILURE ((size_t)-1) | 867 #define SUB_OFFSET_FAILURE ((size_t)-1) |
868 | 868 |
869 /** | 869 /** |
870 * Based on the Config and rowBytes() of bm, return the offset into an SkPixelR
ef of the pixel at | 870 * Based on the Config and rowBytes() of bm, return the offset into an SkPixelR
ef of the pixel at |
871 * (x, y). | 871 * (x, y). |
872 * Note that the SkPixelRef does not need to be set yet. deepCopyTo takes advan
tage of this fact. | 872 * Note that the SkPixelRef does not need to be set yet. deepCopyTo takes advan
tage of this fact. |
873 * Also note that (x, y) may be outside the range of (0 - width(), 0 - height()
), so long as it is | 873 * Also note that (x, y) may be outside the range of (0 - width(), 0 - height()
), so long as it is |
874 * within the bounds of the SkPixelRef being used. | 874 * within the bounds of the SkPixelRef being used. |
875 */ | 875 */ |
876 static size_t get_sub_offset(const SkBitmap& bm, int x, int y) { | 876 static size_t get_sub_offset(const SkBitmap& bm, int x, int y) { |
877 switch (bm.getConfig()) { | 877 switch (bm.config()) { |
878 case SkBitmap::kA8_Config: | 878 case SkBitmap::kA8_Config: |
879 case SkBitmap:: kIndex8_Config: | 879 case SkBitmap:: kIndex8_Config: |
880 // x is fine as is for the calculation | 880 // x is fine as is for the calculation |
881 break; | 881 break; |
882 | 882 |
883 case SkBitmap::kRGB_565_Config: | 883 case SkBitmap::kRGB_565_Config: |
884 case SkBitmap::kARGB_4444_Config: | 884 case SkBitmap::kARGB_4444_Config: |
885 x <<= 1; | 885 x <<= 1; |
886 break; | 886 break; |
887 | 887 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 result->swap(dst); | 998 result->swap(dst); |
999 return true; | 999 return true; |
1000 } | 1000 } |
1001 | 1001 |
1002 /////////////////////////////////////////////////////////////////////////////// | 1002 /////////////////////////////////////////////////////////////////////////////// |
1003 | 1003 |
1004 #include "SkCanvas.h" | 1004 #include "SkCanvas.h" |
1005 #include "SkPaint.h" | 1005 #include "SkPaint.h" |
1006 | 1006 |
1007 bool SkBitmap::canCopyTo(Config dstConfig) const { | 1007 bool SkBitmap::canCopyTo(Config dstConfig) const { |
1008 if (this->getConfig() == kNo_Config) { | 1008 if (this->config() == kNo_Config) { |
1009 return false; | 1009 return false; |
1010 } | 1010 } |
1011 | 1011 |
1012 bool sameConfigs = (this->config() == dstConfig); | 1012 bool sameConfigs = (this->config() == dstConfig); |
1013 switch (dstConfig) { | 1013 switch (dstConfig) { |
1014 case kA8_Config: | 1014 case kA8_Config: |
1015 case kRGB_565_Config: | 1015 case kRGB_565_Config: |
1016 case kARGB_8888_Config: | 1016 case kARGB_8888_Config: |
1017 break; | 1017 break; |
1018 case kA1_Config: | 1018 case kA1_Config: |
1019 case kIndex8_Config: | 1019 case kIndex8_Config: |
1020 if (!sameConfigs) { | 1020 if (!sameConfigs) { |
1021 return false; | 1021 return false; |
1022 } | 1022 } |
1023 break; | 1023 break; |
1024 case kARGB_4444_Config: | 1024 case kARGB_4444_Config: |
1025 return sameConfigs || kARGB_8888_Config == this->config(); | 1025 return sameConfigs || kARGB_8888_Config == this->config(); |
1026 default: | 1026 default: |
1027 return false; | 1027 return false; |
1028 } | 1028 } |
1029 | 1029 |
1030 // do not copy src if srcConfig == kA1_Config while dstConfig != kA1_Config | 1030 // do not copy src if srcConfig == kA1_Config while dstConfig != kA1_Config |
1031 if (this->getConfig() == kA1_Config && !sameConfigs) { | 1031 if (this->config() == kA1_Config && !sameConfigs) { |
1032 return false; | 1032 return false; |
1033 } | 1033 } |
1034 | 1034 |
1035 return true; | 1035 return true; |
1036 } | 1036 } |
1037 | 1037 |
1038 bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const { | 1038 bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const { |
1039 if (!this->canCopyTo(dstConfig)) { | 1039 if (!this->canCopyTo(dstConfig)) { |
1040 return false; | 1040 return false; |
1041 } | 1041 } |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 void SkBitmap::buildMipMap(bool forceRebuild) { | 1298 void SkBitmap::buildMipMap(bool forceRebuild) { |
1299 if (forceRebuild) | 1299 if (forceRebuild) |
1300 this->freeMipMap(); | 1300 this->freeMipMap(); |
1301 else if (fMipMap) | 1301 else if (fMipMap) |
1302 return; // we're already built | 1302 return; // we're already built |
1303 | 1303 |
1304 SkASSERT(NULL == fMipMap); | 1304 SkASSERT(NULL == fMipMap); |
1305 | 1305 |
1306 void (*proc)(SkBitmap* dst, int x, int y, const SkBitmap& src); | 1306 void (*proc)(SkBitmap* dst, int x, int y, const SkBitmap& src); |
1307 | 1307 |
1308 const SkBitmap::Config config = this->getConfig(); | 1308 const SkBitmap::Config config = this->config(); |
1309 | 1309 |
1310 switch (config) { | 1310 switch (config) { |
1311 case kARGB_8888_Config: | 1311 case kARGB_8888_Config: |
1312 proc = downsampleby2_proc32; | 1312 proc = downsampleby2_proc32; |
1313 break; | 1313 break; |
1314 case kRGB_565_Config: | 1314 case kRGB_565_Config: |
1315 proc = downsampleby2_proc16; | 1315 proc = downsampleby2_proc16; |
1316 break; | 1316 break; |
1317 case kARGB_4444_Config: | 1317 case kARGB_4444_Config: |
1318 proc = downsampleby2_proc4444; | 1318 proc = downsampleby2_proc4444; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 return SkIntToFixed(15 - clz) + ((unsigned)(sx << (clz + 1)) >> 16); | 1437 return SkIntToFixed(15 - clz) + ((unsigned)(sx << (clz + 1)) >> 16); |
1438 } | 1438 } |
1439 | 1439 |
1440 /////////////////////////////////////////////////////////////////////////////// | 1440 /////////////////////////////////////////////////////////////////////////////// |
1441 | 1441 |
1442 static bool GetBitmapAlpha(const SkBitmap& src, uint8_t* SK_RESTRICT alpha, | 1442 static bool GetBitmapAlpha(const SkBitmap& src, uint8_t* SK_RESTRICT alpha, |
1443 int alphaRowBytes) { | 1443 int alphaRowBytes) { |
1444 SkASSERT(alpha != NULL); | 1444 SkASSERT(alpha != NULL); |
1445 SkASSERT(alphaRowBytes >= src.width()); | 1445 SkASSERT(alphaRowBytes >= src.width()); |
1446 | 1446 |
1447 SkBitmap::Config config = src.getConfig(); | 1447 SkBitmap::Config config = src.config(); |
1448 int w = src.width(); | 1448 int w = src.width(); |
1449 int h = src.height(); | 1449 int h = src.height(); |
1450 size_t rb = src.rowBytes(); | 1450 size_t rb = src.rowBytes(); |
1451 | 1451 |
1452 SkAutoLockPixels alp(src); | 1452 SkAutoLockPixels alp(src); |
1453 if (!src.readyToDraw()) { | 1453 if (!src.readyToDraw()) { |
1454 // zero out the alpha buffer and return | 1454 // zero out the alpha buffer and return |
1455 while (--h >= 0) { | 1455 while (--h >= 0) { |
1456 memset(alpha, 0, w); | 1456 memset(alpha, 0, w); |
1457 alpha += alphaRowBytes; | 1457 alpha += alphaRowBytes; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 if (NULL != uri) { | 1703 if (NULL != uri) { |
1704 str->appendf(" uri:\"%s\"", uri); | 1704 str->appendf(" uri:\"%s\"", uri); |
1705 } else { | 1705 } else { |
1706 str->appendf(" pixelref:%p", pr); | 1706 str->appendf(" pixelref:%p", pr); |
1707 } | 1707 } |
1708 } | 1708 } |
1709 | 1709 |
1710 str->append(")"); | 1710 str->append(")"); |
1711 } | 1711 } |
1712 #endif | 1712 #endif |
OLD | NEW |