Changeset 246 for branches/highdpi/Packages/CevoComponents/ScreenTools.pas
- Timestamp:
- May 21, 2020, 8:17:38 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/CevoComponents/ScreenTools.pas
r244 r246 35 35 procedure Sprite(dst: TDpiBitmap; HGr, xDst, yDst, Width, Height, xGr, yGr: integer); 36 36 overload; 37 procedure MakeBlue(dst: TDpiBitmap; x, y, Width, Height: Integer); 37 procedure MakeBlue(Dst: TDpiBitmap; X, Y, Width, Height: Integer); 38 procedure MakeRed(Dst: TDpiBitmap; X, Y, Width, Height: Integer); 38 39 procedure ImageOp_B(dst, Src: TDpiBitmap; xDst, yDst, xSrc, ySrc, Width, Height: Integer); 39 40 procedure ImageOp_BCC(dst, Src: TDpiBitmap; … … 41 42 procedure ImageOp_CBC(Dst, Src: TDpiBitmap; xDst, yDst, xSrc, ySrc, Width, Height, 42 43 Color0, Color2: Integer); 43 procedure ImageOp_CCC(bmp: TDpiBitmap; x, y, w, h, Color0, Color1, Color2: Integer);44 procedure ImageOp_CCC(bmp: TDpiBitmap; x, y, Width, Height, Color0, Color1, Color2: Integer); 44 45 function DpiBitCanvas(DestCanvas: TDpiCanvas; X, Y, Width, Height: Integer; 45 46 SrcCanvas: TDpiCanvas; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean; overload; … … 57 58 procedure FrameImage(ca: TDpiCanvas; Src: TDpiBitmap; 58 59 x, y, Width, Height, xSrc, ySrc: integer; IsControl: boolean = False); 59 procedure GlowFrame( dst: TDpiBitmap; x0, y0, Width, Height: integer; cl: TColor);60 procedure GlowFrame(Dst: TDpiBitmap; x0, y0, Width, Height: integer; cl: TColor); 60 61 procedure InitOrnament; 61 62 procedure InitCityMark(const T: TTexture); … … 363 364 Bitmap.BeginUpdate; 364 365 PixelPtr := PixelPointer(Bitmap); 365 for Y := 0 to ScaleTo Vcl(Bitmap.Height) - 1 do begin366 for X := 0 to ScaleTo Vcl(Bitmap.Width) - 1 do begin366 for Y := 0 to ScaleToNative(Bitmap.Height) - 1 do begin 367 for X := 0 to ScaleToNative(Bitmap.Width) - 1 do begin 367 368 PixelPtr.Pixel^ := ApplyGammaToPixel(PixelPtr.Pixel^); 368 369 PixelPtr.NextPixel; … … 381 382 SrcPtr := PixelPointer(Src); 382 383 DstPtr := PixelPointer(Dst); 383 for Y := 0 to ScaleTo Vcl(Src.Height) - 1do begin384 for X := 0 to ScaleTo Vcl(Src.Width) - 1do begin384 for Y := 0 to ScaleToNative(Src.Height - 1) do begin 385 for X := 0 to ScaleToNative(Src.Width - 1) do begin 385 386 DstPtr.Pixel^.B := SrcPtr.Pixel^.B; 386 387 DstPtr.Pixel^.G := SrcPtr.Pixel^.B; … … 403 404 Path := Path + '.png'; 404 405 if ExtractFileExt(Path) = '.jpg' then begin 405 jtex := tDpijpegimage.Create;406 jtex := TDpiJpegImage.Create; 406 407 try 407 408 jtex.LoadFromFile(Path); … … 505 506 DataPixel := PixelPointer(GrExt[nGrExt].Data); 506 507 MaskPixel := PixelPointer(GrExt[nGrExt].Mask); 507 for y := 0 to ScaleTo Vcl(Source.Height) - 1 do begin508 for x := 0 to ScaleTo Vcl(xmax) - 1 do begin508 for y := 0 to ScaleToNative(Source.Height) - 1 do begin 509 for x := 0 to ScaleToNative(xmax) - 1 do begin 509 510 OriginalColor := DataPixel.Pixel^.ARGB and $FFFFFF; 510 511 if (OriginalColor = $FF00FF) or (OriginalColor = $7F007F) then … … 538 539 end; 539 540 540 procedure MakeBlue( dst: TDpiBitmap; x, y, Width, Height: Integer);541 var 542 XX, YY: integer;541 procedure MakeBlue(Dst: TDpiBitmap; X, Y, Width, Height: Integer); 542 var 543 XX, YY: Integer; 543 544 PixelPtr: TPixelPointer; 544 545 begin 545 X := ScaleToVcl(X);546 Y := ScaleToVcl(Y);547 Width := ScaleToVcl(Width);548 Height := ScaleToVcl(Height);549 546 Dst.BeginUpdate; 550 PixelPtr := PixelPointer(Dst, X, Y);551 for yy := 0 to Height- 1 do begin552 for xx := 0 to Width- 1 do begin547 PixelPtr := PixelPointer(Dst, ScaleToNative(X), ScaleToNative(Y)); 548 for yy := 0 to ScaleToNative(Height) - 1 do begin 549 for xx := 0 to ScaleToNative(Width) - 1 do begin 553 550 PixelPtr.Pixel^.B := PixelPtr.Pixel^.B div 2; 554 551 PixelPtr.Pixel^.G := PixelPtr.Pixel^.G div 2; … … 561 558 end; 562 559 560 procedure MakeRed(Dst: TDpiBitmap; X, Y, Width, Height: Integer); 561 var 562 XX, YY: Integer; 563 Gray: Integer; 564 PixelPtr: TPixelPointer; 565 begin 566 Dst.BeginUpdate; 567 PixelPtr := PixelPointer(Dst, ScaleToNative(X), ScaleToNative(Y)); 568 for YY := 0 to ScaleToNative(Height) - 1 do begin 569 for XX := 0 to ScaleToNative(Width) - 1 do begin 570 Gray := (Integer(PixelPtr.Pixel^.B) + Integer(PixelPtr.Pixel^.G) + 571 Integer(PixelPtr.Pixel^.R)) * 85 shr 8; 572 PixelPtr.Pixel^.B := 0; 573 PixelPtr.Pixel^.G := 0; 574 PixelPtr.Pixel^.R := Gray; // 255-(255-gray) div 2; 575 PixelPtr.NextPixel; 576 end; 577 PixelPtr.NextLine; 578 end; 579 Dst.EndUpdate; 580 end; 581 563 582 procedure ImageOp_B(dst, Src: TDpiBitmap; xDst, yDst, xSrc, ySrc, Width, Height: Integer); 564 583 // Src is template … … 570 589 PixelDst: TPixelPointer; 571 590 begin 572 xDst := ScaleTo Vcl(xDst);573 yDst := ScaleTo Vcl(yDst);574 xSrc := ScaleTo Vcl(xSrc);575 ySrc := ScaleTo Vcl(ySrc);576 Width := ScaleTo Vcl(Width);577 Height := ScaleTo Vcl(Height);591 xDst := ScaleToNative(xDst); 592 yDst := ScaleToNative(yDst); 593 xSrc := ScaleToNative(xSrc); 594 ySrc := ScaleToNative(ySrc); 595 Width := ScaleToNative(Width); 596 Height := ScaleToNative(Height); 578 597 //Assert(Src.PixelFormat = pf8bit); 579 598 Assert(dst.PixelFormat = pf24bit); … … 588 607 yDst := 0; 589 608 end; 590 if xDst + Width > ScaleTo Vcl(dst.Width) then591 Width := ScaleTo Vcl(dst.Width) - xDst;592 if yDst + Height > ScaleTo Vcl(dst.Height) then593 Height := ScaleTo Vcl(dst.Height) - yDst;609 if xDst + Width > ScaleToNative(dst.Width) then 610 Width := ScaleToNative(dst.Width) - xDst; 611 if yDst + Height > ScaleToNative(dst.Height) then 612 Height := ScaleToNative(dst.Height) - yDst; 594 613 if (Width < 0) or (Height < 0) then 595 614 exit; … … 638 657 DstPixel: TPixelPointer; 639 658 begin 640 xDst := ScaleTo Vcl(xDst);641 yDst := ScaleTo Vcl(yDst);642 xSrc := ScaleTo Vcl(xSrc);643 ySrc := ScaleTo Vcl(ySrc);644 Width := ScaleTo Vcl(Width);645 Height := ScaleTo Vcl(Height);659 xDst := ScaleToNative(xDst); 660 yDst := ScaleToNative(yDst); 661 xSrc := ScaleToNative(xSrc); 662 ySrc := ScaleToNative(ySrc); 663 Width := ScaleToNative(Width); 664 Height := ScaleToNative(Height); 646 665 if xDst < 0 then begin 647 666 Width := Width + xDst; … … 654 673 yDst := 0; 655 674 end; 656 if xDst + Width > ScaleTo Vcl(dst.Width) then657 Width := ScaleTo Vcl(dst.Width) - xDst;658 if yDst + Height > ScaleTo Vcl(dst.Height) then659 Height := ScaleTo Vcl(dst.Height) - yDst;675 if xDst + Width > ScaleToNative(dst.Width) then 676 Width := ScaleToNative(dst.Width) - xDst; 677 if yDst + Height > ScaleToNative(dst.Height) then 678 Height := ScaleToNative(dst.Height) - yDst; 660 679 if (Width < 0) or (Height < 0) then 661 680 exit; … … 705 724 DstPixel: TPixelPointer; 706 725 begin 707 xDst := ScaleTo Vcl(xDst);708 yDst := ScaleTo Vcl(yDst);709 xSrc := ScaleTo Vcl(xSrc);710 ySrc := ScaleTo Vcl(ySrc);711 Width := ScaleTo Vcl(Width);712 Height := ScaleTo Vcl(Height);726 xDst := ScaleToNative(xDst); 727 yDst := ScaleToNative(yDst); 728 xSrc := ScaleToNative(xSrc); 729 ySrc := ScaleToNative(ySrc); 730 Width := ScaleToNative(Width); 731 Height := ScaleToNative(Height); 713 732 Src.BeginUpdate; 714 733 Dst.BeginUpdate; … … 743 762 end; 744 763 745 procedure ImageOp_CCC(bmp: TDpiBitmap; x, y, w, h, Color0, Color1, Color2: Integer);764 procedure ImageOp_CCC(bmp: TDpiBitmap; x, y, Width, Height, Color0, Color1, Color2: Integer); 746 765 // Bmp is template 747 766 // B channel = Color0 amp, 128=original brightness … … 752 771 PixelPtr: TPixelPointer; 753 772 begin 754 X := ScaleTo Vcl(X);755 Y := ScaleTo Vcl(Y);756 W := ScaleToVcl(W);757 H := ScaleToVcl(H);773 X := ScaleToNative(X); 774 Y := ScaleToNative(Y); 775 Width := ScaleToNative(Width); 776 Height := ScaleToNative(Height); 758 777 bmp.BeginUpdate; 759 778 assert(bmp.PixelFormat = pf24bit); 760 h := y + h;779 Height := y + Height; 761 780 PixelPtr := PixelPointer(Bmp, x, y); 762 while y < hdo begin763 for i := 0 to w- 1 do begin781 while y < Height do begin 782 for i := 0 to Width - 1 do begin 764 783 Red := ((PixelPtr.Pixel^.B * (Color0 and $0000FF) + PixelPtr.Pixel^.G * 765 784 (Color1 and $0000FF) + PixelPtr.Pixel^.R * (Color2 and $0000FF)) shr 8) and $ff; … … 799 818 SrcCanvas: TDpiCanvas; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean; 800 819 begin 820 {$IFDEF WINDOWS} 821 // LCLIntf.BitBlt is slower than direct Windows BitBlt 822 Result := Windows.DpiBitBlt(DestCanvas.Handle, X, Y, Width, Height, SrcCanvas.Handle, XSrc, YSrc, Rop); 823 {$ELSE} 801 824 Result := DpiBitBlt(DestCanvas.Handle, X, Y, Width, Height, SrcCanvas.Handle, XSrc, YSrc, Rop); 825 {$ENDIF} 802 826 end; 803 827 … … 903 927 end; 904 928 905 procedure GlowFrame( dst: TDpiBitmap; x0, y0, Width, Height: Integer; cl: TColor);929 procedure GlowFrame(Dst: TDpiBitmap; x0, y0, Width, Height: Integer; cl: TColor); 906 930 var 907 931 x, y, ch, r: Integer; … … 909 933 DpiGlowRange: Integer; 910 934 begin 911 DpiGlowRange := ScaleTo Vcl(GlowRange);912 X0 := ScaleTo Vcl(X0);913 Y0 := ScaleTo Vcl(Y0);914 Width := ScaleTo Vcl(Width);915 Height := ScaleTo Vcl(Height);916 dst.BeginUpdate;917 DstPtr := PixelPointer( dst, x0, y0);935 DpiGlowRange := ScaleToNative(GlowRange); 936 X0 := ScaleToNative(X0); 937 Y0 := ScaleToNative(Y0); 938 Width := ScaleToNative(Width); 939 Height := ScaleToNative(Height); 940 Dst.BeginUpdate; 941 DstPtr := PixelPointer(Dst, x0 - DpiGlowRange + 1, y0 - DpiGlowRange + 1); 918 942 for y := -DpiGlowRange + 1 to Height - 1 + DpiGlowRange - 1 do begin 919 943 for x := -DpiGlowRange + 1 to Width - 1 + DpiGlowRange - 1 do begin 920 DstPtr.SetXY(x, y);921 944 if x < 0 then 922 945 if y < 0 then … … 937 960 else if y >= Height then 938 961 r := y - (Height - 1) 939 else 962 else begin 963 DstPtr.NextPixel; 940 964 continue; 965 end; 941 966 if r = 0 then 942 967 r := 1; … … 946 971 (DstPtr.Pixel^.Planes[2 - ch] * (r - 1) + (cl shr (8 * ch) and $FF) * 947 972 (DpiGlowRange - r)) div (DpiGlowRange - 1); 948 end; 949 end; 950 dst.EndUpdate; 973 DstPtr.NextPixel; 974 end; 975 DstPtr.NextLine; 976 end; 977 Dst.EndUpdate; 951 978 end; 952 979 … … 1509 1536 // texturize background 1510 1537 Dest.BeginUpdate; 1511 TexWidth := ScaleToVcl(Texture.Width);1512 TexHeight := ScaleToVcl(Texture.Height);1538 TexWidth := Texture.Width; 1539 TexHeight := Texture.Height; 1513 1540 DstPixel := PixelPointer(Dest); 1514 1541 SrcPixel := PixelPointer(Texture); 1515 for Y := 0 to ScaleTo Vcl(Dest.Height) - 1 do begin1516 for X := 0 to ScaleTo Vcl(Dest.Width) - 1 do begin1542 for Y := 0 to ScaleToNative(Dest.Height) - 1 do begin 1543 for X := 0 to ScaleToNative(Dest.Width) - 1 do begin 1517 1544 if (DstPixel.Pixel^.ARGB and $FFFFFF) = TransparentColor then begin 1518 1545 SrcPixel.SetXY(X mod TexWidth, Y mod TexHeight); … … 1535 1562 Bitmap.BeginUpdate; 1536 1563 PicturePixel := PixelPointer(Bitmap); 1537 for y := 0 to ScaleTo Vcl(Bitmap.Height) - 1 do begin1538 for x := 0 to ScaleTo Vcl(Bitmap.Width) - 1 do begin1564 for y := 0 to ScaleToNative(Bitmap.Height) - 1 do begin 1565 for x := 0 to ScaleToNative(Bitmap.Width) - 1 do begin 1539 1566 PicturePixel.Pixel^.B := Max(PicturePixel.Pixel^.B - Change, 0); 1540 1567 PicturePixel.Pixel^.G := Max(PicturePixel.Pixel^.G - Change, 0); … … 1545 1572 end; 1546 1573 Bitmap.EndUpdate; 1574 end; 1575 1576 function ScaleToNative(Value: Integer): Integer; 1577 begin 1578 Result := Value; 1579 end; 1580 1581 function ScaleFromNative(Value: Integer): Integer; 1582 begin 1583 Result := Value; 1547 1584 end; 1548 1585
Note:
See TracChangeset
for help on using the changeset viewer.