Changeset 736 for trunk


Ignore:
Timestamp:
Jan 20, 2026, 11:44:28 PM (21 hours ago)
Author:
chronos
Message:
  • Fixed: Map drawing with Qt5 widgetset. Used slower software replacement of BitBlt function.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/DpiControls/Dpi.Common.pas

    r657 r736  
    2626  X, Y, cx, cy: Integer; uFlags: UINT): Boolean;
    2727function ScaleToNative(Value: Integer): Integer; inline;
    28 function ScaleToNativeDist(Base, Value: Integer): Integer;
    29 function ScaleFromNative(Value: Integer): Integer;
     28function ScaleToNativeDist(Base, Value: Integer): Integer; inline;
     29function ScaleFromNative(Value: Integer): Integer; inline;
    3030function ScalePointToNative(Value: TPoint): TPoint;
    3131function ScalePointFromNative(Value: TPoint): TPoint;
     
    5656end;
    5757
     58function BitBltBitmapSimple(Dest: TBitmap; X, Y, Width, Height: Integer;
     59  Src: TBitmap; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean;
     60var
     61  SrcPixel: TPixelPointer;
     62  DstPixel: TPixelPointer;
     63  XX, YY: Integer;
     64begin
     65  if XSrc < 0 then begin
     66    X := X - XSrc;
     67    Width := Width - XSrc;
     68    XSrc := 0;
     69  end;
     70  if YSrc < 0 then begin
     71    Y := Y - YSrc;
     72    Height := Height - YSrc;
     73    YSrc := 0;
     74  end;
     75
     76  if X < 0 then begin
     77    Width := Width + X;
     78    XSrc := XSrc - X;
     79    X := 0;
     80  end;
     81  if Y < 0 then begin
     82    Height := Height + Y;
     83    YSrc := YSrc - Y;
     84    Y := 0;
     85  end;
     86  if (X + Width) >= Dest.Width then begin
     87    Width := Dest.Width - X;
     88  end;
     89  if (Y + Height) >= Dest.Height then begin
     90    Height := Dest.Height - Y;
     91  end;
     92  if (Width < 0) or (Height < 0) then begin
     93    Result := True;
     94    Exit;
     95  end;
     96
     97  Dest.BeginUpdate;
     98  SrcPixel := TPixelPointer.Create(Src.NativeBitmap, XSrc, YSrc);
     99  DstPixel := TPixelPointer.Create(Dest.NativeBitmap, X, Y);
     100  if Rop = SRCCOPY then begin
     101    for YY := 0 to Height - 1 do begin
     102      for XX := 0 to Width - 1 do begin
     103        DstPixel.PixelRGB := SrcPixel.PixelARGB;
     104        DstPixel.NextPixel;
     105        SrcPixel.NextPixel;
     106      end;
     107      DstPixel.NextLine;
     108      SrcPixel.NextLine;
     109    end;
     110  end else
     111  if Rop = SRCPAINT then begin
     112    for YY := 0 to Height - 1 do begin
     113      for XX := 0 to Width - 1 do begin
     114        DstPixel.PixelRGB := DstPixel.PixelRGB or SrcPixel.PixelARGB;
     115        DstPixel.NextPixel;
     116        SrcPixel.NextPixel;
     117      end;
     118      DstPixel.NextLine;
     119      SrcPixel.NextLine;
     120    end;
     121  end else
     122  if Rop = SRCAND then begin
     123    for YY := 0 to Height - 1 do begin
     124      for XX := 0 to Width - 1 do begin
     125        DstPixel.PixelRGB := DstPixel.PixelRGB and SrcPixel.PixelARGB;
     126        DstPixel.NextPixel;
     127        SrcPixel.NextPixel;
     128      end;
     129      DstPixel.NextLine;
     130      SrcPixel.NextLine;
     131    end;
     132  end else
     133  if Rop = DSTINVERT then begin
     134    for YY := 0 to Height - 1 do begin
     135      for XX := 0 to Width - 1 do begin
     136        DstPixel.PixelRGB := not DstPixel.PixelRGB;
     137        DstPixel.NextPixel;
     138      end;
     139      DstPixel.NextLine;
     140    end;
     141  end else raise Exception.Create(SUnsupportedPaintOperationType);
     142  Dest.EndUpdate;
     143  Result := True;
     144end;
     145
    58146function BitBltBitmapPrecise(Dest: TBitmap; X, Y, Width, Height: Integer;
    59147  Src: TBitmap; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY;
     
    66154  DstPixelWidth, DstPixelHeight: Integer;
    67155begin
    68   if not Precise or (Frac(ScreenInfo.Dpi / 96) = 0) then begin
     156  if Frac(ScreenInfo.Dpi / 96) = 0 then begin
     157    {$IF defined(LCLQT5)}
     158    Result := BitBltBitmapSimple(Dest, X, Y, Width, Height, Src,
     159      XSrc, YSrc, Rop);
     160    {$ELSEIF defined(LCLQT6)}
     161    Result := BitBltBitmapDirect(Dest, X, Y, Width, Height, Src,
     162      XSrc, YSrc, Rop);
     163    {$ELSE}
     164    // Use faster non-fractional scaling
     165    Result := BitBlt(Dest.Canvas.Handle, X, Y, Width, Height, Src.Canvas.Handle,
     166      XSrc, YSrc, Rop);
     167    {$ENDIF}
     168    Exit;
     169  end;
     170
     171  if not Precise then begin
     172    {$IF defined(LCLQT5)}
     173    {$ELSEIF defined(LCLQT6)}
     174    {$ELSE}
    69175    // Use faster non-fractional scaling
    70176    Result := BitBlt(Dest.Canvas.Handle, X, Y, Width, Height, Src.Canvas.Handle,
    71177      XSrc, YSrc, Rop);
    72178    Exit;
     179    {$ENDIF}
    73180  end;
    74181
     
    161268  if Rop = DSTINVERT then begin
    162269    for YY := 0 to Height - 1 do begin
    163       SrcPixel.SetXY(0, ScaleToNative(YSrc + YY));
    164270      DstPixelHeight := ScaleToNative(Y + YY + 1) - ScaleToNative(Y + YY);
    165271      for DstPixelY := 0 to DstPixelHeight - 1 do begin
    166272        for XX := 0 to Width - 1 do begin
    167           SrcPixel.SetX(ScaleToNative(XSrc + XX));
    168273          DstPixelWidth := ScaleToNative(X + XX + 1) - ScaleToNative(X + XX);
    169274          for DstPixelX := 0 to DstPixelWidth - 1 do begin
Note: See TracChangeset for help on using the changeset viewer.