Changeset 521 for GraphicTest/Packages/bgrabitmap/bgrablend.pas
- Timestamp:
- Apr 17, 2019, 12:58:41 AM (5 years ago)
- Location:
- GraphicTest
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest
- Property svn:ignore
-
old new 8 8 GraphicTest.lps 9 9 GraphicTest.dbg 10 heaptrclog.trc
-
- Property svn:ignore
-
GraphicTest/Packages/bgrabitmap/bgrablend.pas
r494 r521 698 698 procedure DrawPixelInlineWithAlphaCheck(dest: PBGRAPixel; const c: TBGRAPixel); 699 699 begin 700 if c.alpha = 0 then 701 exit; 702 if c.alpha = 255 then 703 begin 704 dest^ := c; 705 exit; 706 end; 707 DrawPixelInlineNoAlphaCheck(dest,c); 700 case c.alpha of 701 0: ; 702 255: dest^ := c; 703 else 704 DrawPixelInlineNoAlphaCheck(dest,c); 705 end; 708 706 end; 709 707 … … 711 709 begin 712 710 c.alpha := ApplyOpacity(c.alpha,appliedOpacity); 713 if c.alpha = 0 then 714 exit; 715 if c.alpha = 255 then 716 begin 717 dest^ := c; 718 exit; 719 end; 720 DrawPixelInlineNoAlphaCheck(dest,c); 711 DrawPixelInlineWithAlphaCheck(dest, c); 721 712 end; 722 713 … … 748 739 begin 749 740 calpha := ec.alpha shr 8; 750 if calpha = 0 then 751 exit; 752 if calpha = 255 then 753 begin 754 dest^ := GammaCompression(ec); 755 exit; 756 end; 757 DrawExpandedPixelInlineNoAlphaCheck(dest,ec,calpha); 741 case calpha of 742 0: ; 743 255: dest^ := GammaCompression(ec); 744 else 745 DrawExpandedPixelInlineNoAlphaCheck(dest,ec,calpha); 746 end; 758 747 end; 759 748 760 749 procedure DrawPixelInlineExpandedOrNotWithAlphaCheck(dest: PBGRAPixel; const ec: TExpandedPixel; c: TBGRAPixel); 761 750 begin 762 if c.alpha = 0 then 763 exit; 764 if c.alpha = 255 then 765 begin 766 dest^ := c; 767 exit; 768 end; 769 DrawExpandedPixelInlineNoAlphaCheck(dest,ec,c.alpha); 751 case c.alpha of 752 0: ; 753 255: dest^ := c; 754 else 755 DrawExpandedPixelInlineNoAlphaCheck(dest,ec,c.alpha); 756 end; 770 757 end; 771 758 772 759 procedure DrawPixelInlineNoAlphaCheck(dest: PBGRAPixel; const c: TBGRAPixel); 773 760 var 774 a1f, a2f, a12, a12m: cardinal; 775 begin 776 {$HINTS OFF} 777 a12 := 65025 - (not dest^.alpha) * (not c.alpha); 778 {$HINTS ON} 779 a12m := a12 shr 1; 780 781 a1f := dest^.alpha * (not c.alpha); 782 a2f := (c.alpha shl 8) - c.alpha; 783 784 PDWord(dest)^ := ((GammaCompressionTab[(GammaExpansionTab[dest^.red] * a1f + 785 GammaExpansionTab[c.red] * a2f + a12m) div a12]) shl TBGRAPixel_RedShift) or 786 ((GammaCompressionTab[(GammaExpansionTab[dest^.green] * a1f + 787 GammaExpansionTab[c.green] * a2f + a12m) div a12]) shl TBGRAPixel_GreenShift) or 788 ((GammaCompressionTab[(GammaExpansionTab[dest^.blue] * a1f + 789 GammaExpansionTab[c.blue] * a2f + a12m) div a12]) shl TBGRAPixel_BlueShift) or 790 (((a12 + a12 shr 7) shr 8) shl TBGRAPixel_AlphaShift); 761 a1f, a2f, a12, a12m, alphaCorr: NativeUInt; 762 begin 763 case dest^.alpha of 764 0: dest^ := c; 765 255: 766 begin 767 alphaCorr := c.alpha; 768 if alphaCorr >= 128 then alphaCorr += 1; 769 dest^.red := GammaCompressionTab[(GammaExpansionTab[dest^.red] * NativeUInt(256-alphaCorr) + GammaExpansionTab[c.red]*alphaCorr) shr 8]; 770 dest^.green := GammaCompressionTab[(GammaExpansionTab[dest^.green] * NativeUInt(256-alphaCorr) + GammaExpansionTab[c.green]*alphaCorr) shr 8]; 771 dest^.blue := GammaCompressionTab[(GammaExpansionTab[dest^.blue] * NativeUInt(256-alphaCorr) + GammaExpansionTab[c.blue]*alphaCorr) shr 8]; 772 end; 773 else 774 begin 775 {$HINTS OFF} 776 a12 := 65025 - (not dest^.alpha) * (not c.alpha); 777 {$HINTS ON} 778 a12m := a12 shr 1; 779 780 a1f := dest^.alpha * (not c.alpha); 781 a2f := (c.alpha shl 8) - c.alpha; 782 783 PDWord(dest)^ := ((GammaCompressionTab[(GammaExpansionTab[dest^.red] * a1f + 784 GammaExpansionTab[c.red] * a2f + a12m) div a12]) shl TBGRAPixel_RedShift) or 785 ((GammaCompressionTab[(GammaExpansionTab[dest^.green] * a1f + 786 GammaExpansionTab[c.green] * a2f + a12m) div a12]) shl TBGRAPixel_GreenShift) or 787 ((GammaCompressionTab[(GammaExpansionTab[dest^.blue] * a1f + 788 GammaExpansionTab[c.blue] * a2f + a12m) div a12]) shl TBGRAPixel_BlueShift) or 789 (((a12 + a12 shr 7) shr 8) shl TBGRAPixel_AlphaShift); 790 end; 791 end; 791 792 end; 792 793 … … 794 795 const ec: TExpandedPixel; calpha: byte); 795 796 var 796 a1f, a2f, a12, a12m: cardinal; 797 begin 798 {$HINTS OFF} 799 a12 := 65025 - (not dest^.alpha) * (not calpha); 800 {$HINTS ON} 801 a12m := a12 shr 1; 802 803 a1f := dest^.alpha * (not calpha); 804 a2f := (calpha shl 8) - calpha; 805 806 PDWord(dest)^ := ((GammaCompressionTab[(GammaExpansionTab[dest^.red] * a1f + 807 ec.red * a2f + a12m) div a12]) shl TBGRAPixel_RedShift) or 808 ((GammaCompressionTab[(GammaExpansionTab[dest^.green] * a1f + 809 ec.green * a2f + a12m) div a12]) shl TBGRAPixel_GreenShift) or 810 ((GammaCompressionTab[(GammaExpansionTab[dest^.blue] * a1f + 811 ec.blue * a2f + a12m) div a12]) shl TBGRAPixel_BlueShift) or 812 (((a12 + a12 shr 7) shr 8) shl TBGRAPixel_AlphaShift); 797 a1f, a2f, a12, a12m, alphaCorr: NativeUInt; 798 begin 799 case dest^.alpha of 800 0: begin 801 dest^.red := GammaCompressionTab[ec.red]; 802 dest^.green := GammaCompressionTab[ec.green]; 803 dest^.blue := GammaCompressionTab[ec.blue]; 804 dest^.alpha := calpha; 805 end; 806 255: 807 begin 808 alphaCorr := calpha; 809 if alphaCorr >= 128 then alphaCorr += 1; 810 dest^.red := GammaCompressionTab[(GammaExpansionTab[dest^.red] * NativeUInt(256-alphaCorr) + ec.red*alphaCorr) shr 8]; 811 dest^.green := GammaCompressionTab[(GammaExpansionTab[dest^.green] * NativeUInt(256-alphaCorr) + ec.green*alphaCorr) shr 8]; 812 dest^.blue := GammaCompressionTab[(GammaExpansionTab[dest^.blue] * NativeUInt(256-alphaCorr) + ec.blue*alphaCorr) shr 8]; 813 end; 814 else 815 begin 816 {$HINTS OFF} 817 a12 := 65025 - (not dest^.alpha) * (not calpha); 818 {$HINTS ON} 819 a12m := a12 shr 1; 820 821 a1f := dest^.alpha * (not calpha); 822 a2f := (calpha shl 8) - calpha; 823 824 PDWord(dest)^ := ((GammaCompressionTab[(GammaExpansionTab[dest^.red] * a1f + 825 ec.red * a2f + a12m) div a12]) shl TBGRAPixel_RedShift) or 826 ((GammaCompressionTab[(GammaExpansionTab[dest^.green] * a1f + 827 ec.green * a2f + a12m) div a12]) shl TBGRAPixel_GreenShift) or 828 ((GammaCompressionTab[(GammaExpansionTab[dest^.blue] * a1f + 829 ec.blue * a2f + a12m) div a12]) shl TBGRAPixel_BlueShift) or 830 (((a12 + a12 shr 7) shr 8) shl TBGRAPixel_AlphaShift); 831 end; 832 end; 813 833 end; 814 834 815 835 procedure FastBlendPixelInline(dest: PBGRAPixel; const c: TBGRAPixel); 816 836 var 817 a1f, a2f, a12, a12m: cardinal; 818 begin 819 if c.alpha = 0 then 820 exit; 821 if c.alpha = 255 then 822 begin 823 dest^ := c; 824 exit; 825 end; 826 827 {$HINTS OFF} 828 a12 := 65025 - (not dest^.alpha) * (not c.alpha); 829 {$HINTS ON} 830 a12m := a12 shr 1; 831 832 a1f := dest^.alpha * (not c.alpha); 833 a2f := (c.alpha shl 8) - c.alpha; 834 835 PDWord(dest)^ := (((dest^.red * a1f + c.red * a2f + a12m) div a12) shl TBGRAPixel_RedShift) or 836 (((dest^.green * a1f + c.green * a2f + a12m) div a12) shl TBGRAPixel_GreenShift) or 837 (((dest^.blue * a1f + c.blue * a2f + a12m) div a12) shl TBGRAPixel_BlueShift) or 838 (((a12 + a12 shr 7) shr 8) shl TBGRAPixel_AlphaShift); 837 a1f, a2f, a12, a12m, alphaCorr: NativeUInt; 838 begin 839 case c.alpha of 840 0: ; 841 255: dest^ := c; 842 else 843 begin 844 case dest^.alpha of 845 0: dest^ := c; 846 255: 847 begin 848 alphaCorr := c.alpha; 849 if alphaCorr >= 128 then alphaCorr += 1; 850 dest^.red := (dest^.red * NativeUInt(256-alphaCorr) + c.red*(alphaCorr+1)) shr 8; 851 dest^.green := (dest^.green * NativeUInt(256-alphaCorr) + c.green*(alphaCorr+1)) shr 8; 852 dest^.blue := (dest^.blue * NativeUInt(256-alphaCorr) + c.blue*(alphaCorr+1)) shr 8; 853 end; 854 else 855 begin 856 {$HINTS OFF} 857 a12 := 65025 - (not dest^.alpha) * (not c.alpha); 858 {$HINTS ON} 859 a12m := a12 shr 1; 860 861 a1f := dest^.alpha * (not c.alpha); 862 a2f := (c.alpha shl 8) - c.alpha; 863 864 PDWord(dest)^ := (((dest^.red * a1f + c.red * a2f + a12m) div a12) shl TBGRAPixel_RedShift) or 865 (((dest^.green * a1f + c.green * a2f + a12m) div a12) shl TBGRAPixel_GreenShift) or 866 (((dest^.blue * a1f + c.blue * a2f + a12m) div a12) shl TBGRAPixel_BlueShift) or 867 (((a12 + a12 shr 7) shr 8) shl TBGRAPixel_AlphaShift); 868 end; 869 end; 870 end; 871 end; 839 872 end; 840 873
Note:
See TracChangeset
for help on using the changeset viewer.