OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 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 "SkBlitRow.h" | 10 #include "SkBlitRow.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 protected: | 71 protected: |
72 SkPMColor fSrcColor32; | 72 SkPMColor fSrcColor32; |
73 uint32_t fExpandedRaw16; | 73 uint32_t fExpandedRaw16; |
74 unsigned fScale; | 74 unsigned fScale; |
75 uint16_t fColor16; // already scaled by fScale | 75 uint16_t fColor16; // already scaled by fScale |
76 uint16_t fRawColor16; // unscaled | 76 uint16_t fRawColor16; // unscaled |
77 uint16_t fRawDither16; // unscaled | 77 uint16_t fRawDither16; // unscaled |
78 SkBool8 fDoDither; | 78 SkBool8 fDoDither; |
79 | 79 |
| 80 SkBlitRow::ColorProc16 fColorProc16; |
| 81 |
80 // illegal | 82 // illegal |
81 SkRGB16_Blitter& operator=(const SkRGB16_Blitter&); | 83 SkRGB16_Blitter& operator=(const SkRGB16_Blitter&); |
82 | 84 |
83 typedef SkRasterBlitter INHERITED; | 85 typedef SkRasterBlitter INHERITED; |
84 }; | 86 }; |
85 | 87 |
86 class SkRGB16_Opaque_Blitter : public SkRGB16_Blitter { | 88 class SkRGB16_Opaque_Blitter : public SkRGB16_Blitter { |
87 public: | 89 public: |
88 SkRGB16_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint); | 90 SkRGB16_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint); |
89 void blitH(int x, int y, int width) SK_OVERRIDE; | 91 void blitH(int x, int y, int width) SK_OVERRIDE; |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 // if we're dithered, use fRawDither16 to hold that. | 539 // if we're dithered, use fRawDither16 to hold that. |
538 if ((fDoDither = paint.isDither()) != false) { | 540 if ((fDoDither = paint.isDither()) != false) { |
539 fRawDither16 = SkDitherPack888ToRGB16(r, g, b); | 541 fRawDither16 = SkDitherPack888ToRGB16(r, g, b); |
540 } | 542 } |
541 | 543 |
542 fExpandedRaw16 = SkExpand_rgb_16(fRawColor16); | 544 fExpandedRaw16 = SkExpand_rgb_16(fRawColor16); |
543 | 545 |
544 fColor16 = SkPackRGB16( SkAlphaMul(r, fScale) >> (8 - SK_R16_BITS), | 546 fColor16 = SkPackRGB16( SkAlphaMul(r, fScale) >> (8 - SK_R16_BITS), |
545 SkAlphaMul(g, fScale) >> (8 - SK_G16_BITS), | 547 SkAlphaMul(g, fScale) >> (8 - SK_G16_BITS), |
546 SkAlphaMul(b, fScale) >> (8 - SK_B16_BITS)); | 548 SkAlphaMul(b, fScale) >> (8 - SK_B16_BITS)); |
| 549 |
| 550 // compute SkBlitRow::Procs |
| 551 unsigned flags = 0; |
| 552 |
| 553 if (SkGetPackedA32(fSrcColor32) < 0xFF) { |
| 554 flags |= SkBlitRow::kSrcPixelAlpha_Flag; |
| 555 } |
| 556 |
| 557 if (fDoDither) { |
| 558 flags |= SkBlitRow::kDither_Flag; |
| 559 } |
| 560 |
| 561 fColorProc16 = SkBlitRow::ColorFactory16(flags); |
547 } | 562 } |
548 | 563 |
549 const SkBitmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) { | 564 const SkBitmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) { |
550 if (!fDoDither && 256 == fScale) { | 565 if (!fDoDither && 256 == fScale) { |
551 *value = fRawColor16; | 566 *value = fRawColor16; |
552 return &fDevice; | 567 return &fDevice; |
553 } | 568 } |
554 return NULL; | 569 return NULL; |
555 } | 570 } |
556 | 571 |
557 static uint32_t pmcolor_to_expand16(SkPMColor c) { | |
558 unsigned r = SkGetPackedR32(c); | |
559 unsigned g = SkGetPackedG32(c); | |
560 unsigned b = SkGetPackedB32(c); | |
561 return (g << 24) | (r << 13) | (b << 2); | |
562 } | |
563 | |
564 static inline void blend32_16_row(SkPMColor src, uint16_t dst[], int count) { | |
565 SkASSERT(count > 0); | |
566 uint32_t src_expand = pmcolor_to_expand16(src); | |
567 unsigned scale = SkAlpha255To256(0xFF - SkGetPackedA32(src)) >> 3; | |
568 do { | |
569 uint32_t dst_expand = SkExpand_rgb_16(*dst) * scale; | |
570 *dst = SkCompact_rgb_16((src_expand + dst_expand) >> 5); | |
571 dst += 1; | |
572 } while (--count != 0); | |
573 } | |
574 | |
575 void SkRGB16_Blitter::blitH(int x, int y, int width) { | 572 void SkRGB16_Blitter::blitH(int x, int y, int width) { |
576 SkASSERT(width > 0); | 573 SkASSERT(width > 0); |
577 SkASSERT(x + width <= fDevice.width()); | 574 SkASSERT(x + width <= fDevice.width()); |
578 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 575 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
579 | 576 |
580 // TODO: respect fDoDither | 577 fColorProc16(device, fSrcColor32, width, x, y); |
581 blend32_16_row(fSrcColor32, device, width); | |
582 } | 578 } |
583 | 579 |
584 void SkRGB16_Blitter::blitAntiH(int x, int y, | 580 void SkRGB16_Blitter::blitAntiH(int x, int y, |
585 const SkAlpha* SK_RESTRICT antialias, | 581 const SkAlpha* SK_RESTRICT antialias, |
586 const int16_t* SK_RESTRICT runs) { | 582 const int16_t* SK_RESTRICT runs) { |
587 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 583 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
588 uint32_t srcExpanded = fExpandedRaw16; | 584 uint32_t srcExpanded = fExpandedRaw16; |
589 unsigned scale = fScale; | 585 unsigned scale = fScale; |
590 | 586 |
591 // TODO: respect fDoDither | 587 // TODO: respect fDoDither |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 uint32_t dst32 = SkExpand_rgb_16(*device) * scale5; | 670 uint32_t dst32 = SkExpand_rgb_16(*device) * scale5; |
675 *device = SkCompact_rgb_16((src32 + dst32) >> 5); | 671 *device = SkCompact_rgb_16((src32 + dst32) >> 5); |
676 device = (uint16_t*)((char*)device + deviceRB); | 672 device = (uint16_t*)((char*)device + deviceRB); |
677 } while (--height != 0); | 673 } while (--height != 0); |
678 } | 674 } |
679 | 675 |
680 void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) { | 676 void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) { |
681 SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height()); | 677 SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height()); |
682 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 678 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
683 size_t deviceRB = fDevice.rowBytes(); | 679 size_t deviceRB = fDevice.rowBytes(); |
684 SkPMColor src32 = fSrcColor32; | |
685 | 680 |
686 while (--height >= 0) { | 681 while (--height >= 0) { |
687 blend32_16_row(src32, device, width); | 682 fColorProc16(device, fSrcColor32, width, x, y); |
688 device = (uint16_t*)((char*)device + deviceRB); | 683 device = (uint16_t*)((char*)device + deviceRB); |
689 } | 684 } |
690 } | 685 } |
691 | 686 |
692 /////////////////////////////////////////////////////////////////////////////// | 687 /////////////////////////////////////////////////////////////////////////////// |
693 | 688 |
694 SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkBitmap& device, | 689 SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkBitmap& device, |
695 const SkPaint& paint, | 690 const SkPaint& paint, |
696 SkShader::Context* shaderCont
ext) | 691 SkShader::Context* shaderCont
ext) |
697 : SkRGB16_Shader_Blitter(device, paint, shaderContext) { | 692 : SkRGB16_Shader_Blitter(device, paint, shaderContext) { |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 #endif | 1054 #endif |
1060 } else if (0xFF == SkColorGetA(color)) { | 1055 } else if (0xFF == SkColorGetA(color)) { |
1061 blitter = allocator->createT<SkRGB16_Opaque_Blitter>(device, paint); | 1056 blitter = allocator->createT<SkRGB16_Opaque_Blitter>(device, paint); |
1062 } else { | 1057 } else { |
1063 blitter = allocator->createT<SkRGB16_Blitter>(device, paint); | 1058 blitter = allocator->createT<SkRGB16_Blitter>(device, paint); |
1064 } | 1059 } |
1065 } | 1060 } |
1066 | 1061 |
1067 return blitter; | 1062 return blitter; |
1068 } | 1063 } |
OLD | NEW |