Changeset 196 for trunk/Packages


Ignore:
Timestamp:
May 7, 2020, 11:42:52 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Optimized drawing using BitBlt directly instead of CopyRect which is slower due to additional code.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CevoComponents/ScreenTools.pas

    r194 r196  
    3838procedure ImageOp_B(dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, w, h: integer);
    3939procedure ImageOp_BCC(dst, Src: TBitmap;
    40   xDst, yDst, xSrc, ySrc, w, h, Color1, Color2: integer);
     40  xDst, yDst, xSrc, ySrc, Width, Height, Color1, Color2: integer);
    4141procedure ImageOp_CCC(bmp: TBitmap; x, y, w, h, Color0, Color1, Color2: integer);
    4242function BitBltCanvas(DestCanvas: TCanvas; X, Y, Width, Height: Integer;
     
    615615end;
    616616
    617 procedure ImageOp_BCC(dst, Src: TBitmap;
    618   xDst, yDst, xSrc, ySrc, w, h, Color1, Color2: integer);
     617procedure ImageOp_BCC(dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height,
     618  Color1, Color2: integer);
    619619// Src is template
    620620// B channel = background amp (old Dst content), 128=original brightness
     
    626626begin
    627627  if xDst < 0 then begin
    628     w := w + xDst;
     628    Width := Width + xDst;
    629629    xSrc := xSrc - xDst;
    630630    xDst := 0;
    631631  end;
    632632  if yDst < 0 then begin
    633     h := h + yDst;
     633    Height := Height + yDst;
    634634    ySrc := ySrc - yDst;
    635635    yDst := 0;
    636636  end;
    637   if xDst + w > dst.Width then
    638     w := dst.Width - xDst;
    639   if yDst + h > dst.Height then
    640     h := dst.Height - yDst;
    641   if (w < 0) or (h < 0) then
     637  if xDst + Width > dst.Width then
     638    Width := dst.Width - xDst;
     639  if yDst + Height > dst.Height then
     640    Height := dst.Height - yDst;
     641  if (Width < 0) or (Height < 0) then
    642642    exit;
    643643
     
    646646  SrcPixel.Init(Src, xSrc, ySrc);
    647647  DstPixel.Init(Dst, xDst, yDst);
    648   for iy := 0 to h - 1 do begin
    649     for ix := 0 to w - 1 do begin
     648  for iy := 0 to Height - 1 do begin
     649    for ix := 0 to Width - 1 do begin
    650650      trans := SrcPixel.Pixel^.B * 2; // green channel = transparency
    651651      amp1 := SrcPixel.Pixel^.G * 2;
     
    654654        Value := (DstPixel.Pixel^.B * trans + ((Color2 shr 16) and $FF) *
    655655          amp2 + ((Color1 shr 16) and $FF) * amp1) div $FF;
    656         if Value < 256 then
    657           DstPixel.Pixel^.B := Value
    658         else
    659           DstPixel.Pixel^.B := 255;
     656        DstPixel.Pixel^.B := Min(Value, 255);
     657
    660658        Value := (DstPixel.Pixel^.G * trans + ((Color2 shr 8) and $FF) *
    661659          amp2 + ((Color1 shr 8) and $FF) * amp1) div $FF;
    662         if Value < 256 then
    663           DstPixel.Pixel^.G := Value
    664         else
    665           DstPixel.Pixel^.G := 255;
     660        DstPixel.Pixel^.G := Min(Value, 255);
     661
    666662        Value := (DstPixel.Pixel^.R * trans + (Color2 and $FF) *
    667663          amp2 + (Color1 and $FF) * amp1) div $FF;
    668         if Value < 256 then
    669           DstPixel.Pixel^.R := Value
    670         else
    671           DstPixel.Pixel^.R := 255;
     664        DstPixel.Pixel^.R := Min(Value, 255);
    672665      end;
     666
    673667      SrcPixel.NextPixel;
    674668      DstPixel.NextPixel;
     
    733727  SrcCanvas: TCanvas; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean;
    734728begin
    735   {Assert(Rop = SRCCOPY);}
    736   if Rop = SRCCOPY then begin
    737     DestCanvas.CopyRect(Rect(X, Y, X + Width, Y + Height), SrcCanvas,
    738       Rect(XSrc, YSrc, XSrc + Width, YSrc + Height));
    739     Result := True;
    740   end else Result := BitBlt(DestCanvas.Handle, X, Y, Width, Height, SrcCanvas.Handle, XSrc, YSrc, Rop);
     729  Result := BitBlt(DestCanvas.Handle, X, Y, Width, Height, SrcCanvas.Handle, XSrc, YSrc, Rop);
    741730end;
    742731
     
    13761365procedure PaintLogo(ca: TCanvas; x, y, clLight, clShade: Integer);
    13771366begin
     1367  // TODO: Explicitly clear background to black but in fact BitBlt SRCCOPY should do it
     1368  LogoBuffer.Canvas.FillRect(0, 0, LogoBuffer.Width, LogoBuffer.Height);
    13781369  BitBltCanvas(LogoBuffer.Canvas, 0, 0, wLogo, hLogo, ca, x, y);
    13791370  ImageOp_BCC(LogoBuffer, Templates, 0, 0, 1, 1, wLogo, hLogo,
Note: See TracChangeset for help on using the changeset viewer.