Changeset 331 for trunk/Packages


Ignore:
Timestamp:
Mar 26, 2021, 3:24:15 PM (3 years ago)
Author:
chronos
Message:
  • Modified: Player border tile preparation code for bitmap color replacement moved to ScreenTools.
Location:
trunk/Packages/CevoComponents
Files:
2 edited

Legend:

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

    r323 r331  
    4242function LoadGraphicSet2(const Name: string): TGraphicSet;
    4343procedure Dump(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
     44procedure BitmapReplaceColor(Dst: TBitmap; X, Y, Width, Height: Integer; OldColor, NewColor: TColor);
    4445procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
    4546  overload;
     
    567568end;
    568569
     570procedure BitmapReplaceColor(Dst: TBitmap; X, Y, Width, Height: Integer; OldColor, NewColor: TColor);
     571var
     572  XX, YY: Integer;
     573  PixelPtr: TPixelPointer;
     574begin
     575  Dst.BeginUpdate;
     576  PixelPtr := PixelPointer(Dst, ScaleToNative(X), ScaleToNative(Y));
     577  for YY := 0 to ScaleToNative(Height) - 1 do begin
     578    for XX := 0 to ScaleToNative(Width) - 1 do begin
     579      if PixelPtr.Pixel^.RGB = SwapRedBlue(OldColor) then begin
     580        PixelPtr.Pixel^.RGB := SwapRedBlue(NewColor);
     581      end;
     582      PixelPtr.NextPixel;
     583    end;
     584    PixelPtr.NextLine;
     585  end;
     586  Dst.EndUpdate;
     587end;
     588
    569589procedure MakeBlue(Dst: TBitmap; X, Y, Width, Height: Integer);
    570590var
  • trunk/Packages/CevoComponents/UPixelPointer.pas

    r230 r331  
    99  TColor32 = type Cardinal;
    1010  TColor32Component = (ccBlue, ccGreen, ccRed, ccAlpha);
     11
     12  { TPixel32 }
     13
    1114  TPixel32 = packed record
     15  private
     16    function GetRGB: Cardinal;
     17    procedure SetRGB(AValue: Cardinal);
     18  public
     19    property RGB: Cardinal read GetRGB write SetRGB;
    1220    case Integer of
    1321      0: (B, G, R, A: Byte);
     
    3745
    3846  function PixelPointer(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0): TPixelPointer; inline;
    39 
     47  function SwapRedBlue(Color: TColor32): TColor32;
    4048
    4149implementation
     50
     51{ TPixel32 }
     52
     53function TPixel32.GetRGB: Cardinal;
     54begin
     55  Result := ARGB and $ffffff;
     56end;
     57
     58procedure TPixel32.SetRGB(AValue: Cardinal);
     59begin
     60  R := (AValue shr 16) and $ff;
     61  G := (AValue shr 8) and $ff;
     62  B := (AValue shr 0) and $ff;
     63end;
    4264
    4365{ TPixelPointer }
     
    86108end;
    87109
     110function SwapRedBlue(Color: TColor32): TColor32;
     111begin
     112  Result := (Color and $ff00ff00) or ((Color and $ff) shl 16) or ((Color shr 16) and $ff);
     113end;
     114
    88115
    89116end.
Note: See TracChangeset for help on using the changeset viewer.