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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 case kRGBA_8888_SkColorType: | 509 case kRGBA_8888_SkColorType: |
510 case kBGRA_8888_SkColorType: | 510 case kBGRA_8888_SkColorType: |
511 base += x << 2; | 511 base += x << 2; |
512 break; | 512 break; |
513 case kARGB_4444_SkColorType: | 513 case kARGB_4444_SkColorType: |
514 case kRGB_565_SkColorType: | 514 case kRGB_565_SkColorType: |
515 base += x << 1; | 515 base += x << 1; |
516 break; | 516 break; |
517 case kAlpha_8_SkColorType: | 517 case kAlpha_8_SkColorType: |
518 case kIndex_8_SkColorType: | 518 case kIndex_8_SkColorType: |
| 519 case kGray_8_SkColorType: |
519 base += x; | 520 base += x; |
520 break; | 521 break; |
521 default: | 522 default: |
522 SkDEBUGFAIL("Can't return addr for config"); | 523 SkDEBUGFAIL("Can't return addr for config"); |
523 base = NULL; | 524 base = NULL; |
524 break; | 525 break; |
525 } | 526 } |
526 } | 527 } |
527 return base; | 528 return base; |
528 } | 529 } |
529 | 530 |
530 SkColor SkBitmap::getColor(int x, int y) const { | 531 SkColor SkBitmap::getColor(int x, int y) const { |
531 SkASSERT((unsigned)x < (unsigned)this->width()); | 532 SkASSERT((unsigned)x < (unsigned)this->width()); |
532 SkASSERT((unsigned)y < (unsigned)this->height()); | 533 SkASSERT((unsigned)y < (unsigned)this->height()); |
533 | 534 |
534 switch (this->colorType()) { | 535 switch (this->colorType()) { |
| 536 case kGray_8_SkColorType: { |
| 537 uint8_t* addr = this->getAddr8(x, y); |
| 538 return SkColorSetRGB(*addr, *addr, *addr); |
| 539 } |
535 case kAlpha_8_SkColorType: { | 540 case kAlpha_8_SkColorType: { |
536 uint8_t* addr = this->getAddr8(x, y); | 541 uint8_t* addr = this->getAddr8(x, y); |
537 return SkColorSetA(0, addr[0]); | 542 return SkColorSetA(0, addr[0]); |
538 } | 543 } |
539 case kIndex_8_SkColorType: { | 544 case kIndex_8_SkColorType: { |
540 SkPMColor c = this->getIndex8Color(x, y); | 545 SkPMColor c = this->getIndex8Color(x, y); |
541 return SkUnPreMultiply::PMColorToColor(c); | 546 return SkUnPreMultiply::PMColorToColor(c); |
542 } | 547 } |
543 case kRGB_565_SkColorType: { | 548 case kRGB_565_SkColorType: { |
544 uint16_t* addr = this->getAddr16(x, y); | 549 uint16_t* addr = this->getAddr16(x, y); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 return false; | 595 return false; |
591 } | 596 } |
592 const SkPMColor* table = bm.getColorTable()->readColors(); | 597 const SkPMColor* table = bm.getColorTable()->readColors(); |
593 SkPMColor c = (SkPMColor)~0; | 598 SkPMColor c = (SkPMColor)~0; |
594 for (int i = bm.getColorTable()->count() - 1; i >= 0; --i) { | 599 for (int i = bm.getColorTable()->count() - 1; i >= 0; --i) { |
595 c &= table[i]; | 600 c &= table[i]; |
596 } | 601 } |
597 return 0xFF == SkGetPackedA32(c); | 602 return 0xFF == SkGetPackedA32(c); |
598 } break; | 603 } break; |
599 case kRGB_565_SkColorType: | 604 case kRGB_565_SkColorType: |
| 605 case kGray_8_SkColorType: |
600 return true; | 606 return true; |
601 break; | 607 break; |
602 case kARGB_4444_SkColorType: { | 608 case kARGB_4444_SkColorType: { |
603 unsigned c = 0xFFFF; | 609 unsigned c = 0xFFFF; |
604 for (int y = 0; y < height; ++y) { | 610 for (int y = 0; y < height; ++y) { |
605 const SkPMColor16* row = bm.getAddr16(0, y); | 611 const SkPMColor16* row = bm.getAddr16(0, y); |
606 for (int x = 0; x < width; ++x) { | 612 for (int x = 0; x < width; ++x) { |
607 c &= row[x]; | 613 c &= row[x]; |
608 } | 614 } |
609 if (0xF != SkGetPackedA4444(c)) { | 615 if (0xF != SkGetPackedA4444(c)) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 // perform this check after the lock call | 673 // perform this check after the lock call |
668 if (!this->readyToDraw()) { | 674 if (!this->readyToDraw()) { |
669 return; | 675 return; |
670 } | 676 } |
671 | 677 |
672 int height = area.height(); | 678 int height = area.height(); |
673 const int width = area.width(); | 679 const int width = area.width(); |
674 const int rowBytes = fRowBytes; | 680 const int rowBytes = fRowBytes; |
675 | 681 |
676 switch (this->colorType()) { | 682 switch (this->colorType()) { |
| 683 case kGray_8_SkColorType: { |
| 684 if (255 != a) { |
| 685 r = SkMulDiv255Round(r, a); |
| 686 g = SkMulDiv255Round(g, a); |
| 687 b = SkMulDiv255Round(b, a); |
| 688 } |
| 689 int gray = SkComputeLuminance(r, g, b); |
| 690 uint8_t* p = this->getAddr8(area.fLeft, area.fTop); |
| 691 while (--height >= 0) { |
| 692 memset(p, gray, width); |
| 693 p += rowBytes; |
| 694 } |
| 695 break; |
| 696 } |
677 case kAlpha_8_SkColorType: { | 697 case kAlpha_8_SkColorType: { |
678 uint8_t* p = this->getAddr8(area.fLeft, area.fTop); | 698 uint8_t* p = this->getAddr8(area.fLeft, area.fTop); |
679 while (--height >= 0) { | 699 while (--height >= 0) { |
680 memset(p, a, width); | 700 memset(p, a, width); |
681 p += rowBytes; | 701 p += rowBytes; |
682 } | 702 } |
683 break; | 703 break; |
684 } | 704 } |
685 case kARGB_4444_SkColorType: | 705 case kARGB_4444_SkColorType: |
686 case kRGB_565_SkColorType: { | 706 case kRGB_565_SkColorType: { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 case kRGBA_8888_SkColorType: | 841 case kRGBA_8888_SkColorType: |
822 case kBGRA_8888_SkColorType: | 842 case kBGRA_8888_SkColorType: |
823 break; | 843 break; |
824 case kIndex_8_SkColorType: | 844 case kIndex_8_SkColorType: |
825 if (!sameConfigs) { | 845 if (!sameConfigs) { |
826 return false; | 846 return false; |
827 } | 847 } |
828 break; | 848 break; |
829 case kARGB_4444_SkColorType: | 849 case kARGB_4444_SkColorType: |
830 return sameConfigs || kN32_SkColorType == srcCT || kIndex_8_SkColorT
ype == srcCT; | 850 return sameConfigs || kN32_SkColorType == srcCT || kIndex_8_SkColorT
ype == srcCT; |
| 851 case kGray_8_SkColorType: |
| 852 switch (srcCT) { |
| 853 case kGray_8_SkColorType: |
| 854 case kRGBA_8888_SkColorType: |
| 855 case kBGRA_8888_SkColorType: |
| 856 return true; |
| 857 default: |
| 858 break; |
| 859 } |
| 860 return false; |
831 default: | 861 default: |
832 return false; | 862 return false; |
833 } | 863 } |
834 return true; | 864 return true; |
835 } | 865 } |
836 | 866 |
837 #include "SkConfig8888.h" | 867 #include "SkConfig8888.h" |
838 | 868 |
839 bool SkBitmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels,
size_t dstRB, | 869 bool SkBitmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels,
size_t dstRB, |
840 int x, int y) const { | 870 int x, int y) const { |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 /////////////////////////////////////////////////////////////////////////////// | 1412 /////////////////////////////////////////////////////////////////////////////// |
1383 | 1413 |
1384 #ifdef SK_DEBUG | 1414 #ifdef SK_DEBUG |
1385 void SkImageInfo::validate() const { | 1415 void SkImageInfo::validate() const { |
1386 SkASSERT(fWidth >= 0); | 1416 SkASSERT(fWidth >= 0); |
1387 SkASSERT(fHeight >= 0); | 1417 SkASSERT(fHeight >= 0); |
1388 SkASSERT(SkColorTypeIsValid(fColorType)); | 1418 SkASSERT(SkColorTypeIsValid(fColorType)); |
1389 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1419 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
1390 } | 1420 } |
1391 #endif | 1421 #endif |
OLD | NEW |