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) | |
reed1
2015/01/28 19:16:12
nit: Skia always uses { } for if-statements
| |
554 flags |= SkBlitRow::kSrcPixelAlpha_Flag; | |
555 | |
mlee
2015/01/22 12:19:35
Removed todo comment, but I try to set flag here.
| |
556 if (fDoDither) | |
reed1
2015/01/28 19:16:12
same nit about { }
| |
557 flags |= SkBlitRow::kDither_Flag; | |
558 | |
559 fColorProc16 = SkBlitRow::ColorFactory16(flags); | |
mlee
2015/01/22 12:19:35
Compared to previous patchset, we should have Colo
| |
547 } | 560 } |
548 | 561 |
549 const SkBitmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) { | 562 const SkBitmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) { |
550 if (!fDoDither && 256 == fScale) { | 563 if (!fDoDither && 256 == fScale) { |
551 *value = fRawColor16; | 564 *value = fRawColor16; |
552 return &fDevice; | 565 return &fDevice; |
553 } | 566 } |
554 return NULL; | 567 return NULL; |
555 } | 568 } |
556 | 569 |
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) { | 570 void SkRGB16_Blitter::blitH(int x, int y, int width) { |
576 SkASSERT(width > 0); | 571 SkASSERT(width > 0); |
577 SkASSERT(x + width <= fDevice.width()); | 572 SkASSERT(x + width <= fDevice.width()); |
578 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 573 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
579 | 574 |
580 // TODO: respect fDoDither | 575 fColorProc16(device, fSrcColor32, width, x, y); |
581 blend32_16_row(fSrcColor32, device, width); | |
582 } | 576 } |
583 | 577 |
584 void SkRGB16_Blitter::blitAntiH(int x, int y, | 578 void SkRGB16_Blitter::blitAntiH(int x, int y, |
585 const SkAlpha* SK_RESTRICT antialias, | 579 const SkAlpha* SK_RESTRICT antialias, |
586 const int16_t* SK_RESTRICT runs) { | 580 const int16_t* SK_RESTRICT runs) { |
587 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 581 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
588 uint32_t srcExpanded = fExpandedRaw16; | 582 uint32_t srcExpanded = fExpandedRaw16; |
589 unsigned scale = fScale; | 583 unsigned scale = fScale; |
590 | 584 |
591 // TODO: respect fDoDither | 585 // 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; | 668 uint32_t dst32 = SkExpand_rgb_16(*device) * scale5; |
675 *device = SkCompact_rgb_16((src32 + dst32) >> 5); | 669 *device = SkCompact_rgb_16((src32 + dst32) >> 5); |
676 device = (uint16_t*)((char*)device + deviceRB); | 670 device = (uint16_t*)((char*)device + deviceRB); |
677 } while (--height != 0); | 671 } while (--height != 0); |
678 } | 672 } |
679 | 673 |
680 void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) { | 674 void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) { |
681 SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height()); | 675 SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height()); |
682 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); | 676 uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
683 size_t deviceRB = fDevice.rowBytes(); | 677 size_t deviceRB = fDevice.rowBytes(); |
684 SkPMColor src32 = fSrcColor32; | |
685 | 678 |
686 while (--height >= 0) { | 679 while (--height >= 0) { |
687 blend32_16_row(src32, device, width); | 680 fColorProc16(device, fSrcColor32, width, x, y); |
688 device = (uint16_t*)((char*)device + deviceRB); | 681 device = (uint16_t*)((char*)device + deviceRB); |
689 } | 682 } |
690 } | 683 } |
691 | 684 |
692 /////////////////////////////////////////////////////////////////////////////// | 685 /////////////////////////////////////////////////////////////////////////////// |
693 | 686 |
694 SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkBitmap& device, | 687 SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkBitmap& device, |
695 const SkPaint& paint, | 688 const SkPaint& paint, |
696 SkShader::Context* shaderCont ext) | 689 SkShader::Context* shaderCont ext) |
697 : SkRGB16_Shader_Blitter(device, paint, shaderContext) { | 690 : SkRGB16_Shader_Blitter(device, paint, shaderContext) { |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1059 #endif | 1052 #endif |
1060 } else if (0xFF == SkColorGetA(color)) { | 1053 } else if (0xFF == SkColorGetA(color)) { |
1061 blitter = allocator->createT<SkRGB16_Opaque_Blitter>(device, paint); | 1054 blitter = allocator->createT<SkRGB16_Opaque_Blitter>(device, paint); |
1062 } else { | 1055 } else { |
1063 blitter = allocator->createT<SkRGB16_Blitter>(device, paint); | 1056 blitter = allocator->createT<SkRGB16_Blitter>(device, paint); |
1064 } | 1057 } |
1065 } | 1058 } |
1066 | 1059 |
1067 return blitter; | 1060 return blitter; |
1068 } | 1061 } |
OLD | NEW |