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 // TODO: respect fDoDither | |
reed1
2015/01/21 14:40:20
Why is this a todo? If we need a todo comment, per
| |
554 flags |= SkBlitRow::kSrcPixelAlpha_Flag; | |
reed1
2015/01/21 14:40:20
If we're going to always set the alpha flag, lets
| |
555 | |
556 fColorProc16 = SkBlitRow::PlatformColorFactory565(flags); | |
mlee
2015/01/22 12:19:35
Oops. This is mistake and that's why there's test
| |
547 } | 557 } |
548 | 558 |
549 const SkBitmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) { | 559 const SkBitmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) { |
550 if (!fDoDither && 256 == fScale) { | 560 if (!fDoDither && 256 == fScale) { |
551 *value = fRawColor16; | 561 *value = fRawColor16; |
552 return &fDevice; | 562 return &fDevice; |
553 } | 563 } |
554 return NULL; | 564 return NULL; |
555 } | 565 } |
556 | 566 |
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) { | 567 void SkRGB16_Blitter::blitH(int x, int y, int width) { |
576 SkASSERT(width > 0); | 568 SkASSERT(width > 0); |
577 SkASSERT(x + width <= fDevice.width()); | 569 SkASSERT(x + width <= fDevice.width()); |
578 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 570 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
579 | 571 |
580 // TODO: respect fDoDither | 572 fColorProc16(device, fSrcColor32, width, x, y); |
581 blend32_16_row(fSrcColor32, device, width); | |
582 } | 573 } |
583 | 574 |
584 void SkRGB16_Blitter::blitAntiH(int x, int y, | 575 void SkRGB16_Blitter::blitAntiH(int x, int y, |
585 const SkAlpha* SK_RESTRICT antialias, | 576 const SkAlpha* SK_RESTRICT antialias, |
586 const int16_t* SK_RESTRICT runs) { | 577 const int16_t* SK_RESTRICT runs) { |
587 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 578 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
588 uint32_t srcExpanded = fExpandedRaw16; | 579 uint32_t srcExpanded = fExpandedRaw16; |
589 unsigned scale = fScale; | 580 unsigned scale = fScale; |
590 | 581 |
591 // TODO: respect fDoDither | 582 // 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; | 665 uint32_t dst32 = SkExpand_rgb_16(*device) * scale5; |
675 *device = SkCompact_rgb_16((src32 + dst32) >> 5); | 666 *device = SkCompact_rgb_16((src32 + dst32) >> 5); |
676 device = (uint16_t*)((char*)device + deviceRB); | 667 device = (uint16_t*)((char*)device + deviceRB); |
677 } while (--height != 0); | 668 } while (--height != 0); |
678 } | 669 } |
679 | 670 |
680 void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) { | 671 void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) { |
681 SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height()); | 672 SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height()); |
682 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 673 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
683 size_t deviceRB = fDevice.rowBytes(); | 674 size_t deviceRB = fDevice.rowBytes(); |
684 SkPMColor src32 = fSrcColor32; | |
685 | 675 |
686 while (--height >= 0) { | 676 while (--height >= 0) { |
687 blend32_16_row(src32, device, width); | 677 fColorProc16(device, fSrcColor32, width, x, y); |
688 device = (uint16_t*)((char*)device + deviceRB); | 678 device = (uint16_t*)((char*)device + deviceRB); |
689 } | 679 } |
690 } | 680 } |
691 | 681 |
692 /////////////////////////////////////////////////////////////////////////////// | 682 /////////////////////////////////////////////////////////////////////////////// |
693 | 683 |
694 SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkBitmap& device, | 684 SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkBitmap& device, |
695 const SkPaint& paint, | 685 const SkPaint& paint, |
696 SkShader::Context* shaderCont ext) | 686 SkShader::Context* shaderCont ext) |
697 : SkRGB16_Shader_Blitter(device, paint, shaderContext) { | 687 : SkRGB16_Shader_Blitter(device, paint, shaderContext) { |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1059 #endif | 1049 #endif |
1060 } else if (0xFF == SkColorGetA(color)) { | 1050 } else if (0xFF == SkColorGetA(color)) { |
1061 blitter = allocator->createT<SkRGB16_Opaque_Blitter>(device, paint); | 1051 blitter = allocator->createT<SkRGB16_Opaque_Blitter>(device, paint); |
1062 } else { | 1052 } else { |
1063 blitter = allocator->createT<SkRGB16_Blitter>(device, paint); | 1053 blitter = allocator->createT<SkRGB16_Blitter>(device, paint); |
1064 } | 1054 } |
1065 } | 1055 } |
1066 | 1056 |
1067 return blitter; | 1057 return blitter; |
1068 } | 1058 } |
OLD | NEW |