Advertisement
WarPie90

Cache(1) finder - simple

Mar 12th, 2023
1,479
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.42 KB | None | 0 0
  1. function TColorFinder.Find(Buffer: PRGB32; BufferWidth: Integer; SearchWidth, SearchHeight: Integer; Offset: TPoint; MaxToFind: Integer): TPointArray;
  2. var
  3.   X, Y, RowSize: Integer;
  4.   RowPtr, Ptr: PByte;
  5.   PointBuffer: TSimbaPointBuffer;
  6.   PrevColor: record Hit: Boolean; Color: TColor; end;
  7.   Hit: Boolean;
  8. label
  9.   Finished;
  10. begin
  11.   Result := nil;
  12.   if (SearchWidth <= 0) or (SearchHeight <= 0) or (Buffer = nil) or (BufferWidth <= 0) then
  13.     Exit;
  14.  
  15.   RowSize := BufferWidth * SizeOf(TRGB32);
  16.   RowPtr := PByte(Buffer);
  17.  
  18.   PrevColor.Hit   := Self.FCompareFunc(FColor, PColorBGRA(RowPtr)^, FMultipliers) / FMaxDistance * 100 <= FTolerance;
  19.   PrevColor.Color := PColorBGRA(RowPtr)^;
  20.  
  21.   Dec(SearchHeight);
  22.   Dec(SearchWidth);
  23.   for Y := 0 to SearchHeight do
  24.   begin
  25.     Ptr := RowPtr;
  26.     for X := 0 to SearchWidth do
  27.     begin
  28.       if (PrevColor.Hit and (PrevColor.Color = PColorBGRA(Ptr)^)) or
  29.          (Self.FCompareFunc(FColor, PColorBGRA(Ptr)^, FMultipliers) / FMaxDistance * 100 <= FTolerance) then
  30.       begin
  31.         PointBuffer.Add(X + Offset.X, Y + Offset.Y);
  32.         if (PointBuffer.Count = MaxToFind) then
  33.           goto Finished;
  34.       end else
  35.       begin
  36.         PrevColor.Hit := False;
  37.         PrevColor.Color := PColorBGRA(Ptr)^;        
  38.       end;
  39.      
  40.       Inc(Ptr, SizeOf(TRGB32));
  41.     end;
  42.  
  43.     Inc(RowPtr, RowSize);
  44.   end;
  45.   Finished:
  46.  
  47.   Result := PointBuffer.Trim();
  48. end;
  49.  
Advertisement
Comments
  • showboxapk12
    1 year
    # text 0.51 KB | 0 0
    1. Show Box The Best Movie App
    2. Are you looking for a great movie app? ShowBox is the best one out there! With a massive selection of movies and TV shows, it’s perfect for anyone who loves to watch films. And with new releases being added, you’ll never run out of things to watch.
    3. You need to check out Show Box if you’re a movie lover. It’s the best movie app, with a vast selection of films and TV shows.
    4. https://show-boxapk.com/
    5. https://giphy.com/channel/showboxapk
    6. https://www.quora.com/profile/Showbox-Apk-3
Add Comment
Please, Sign In to add comment
Advertisement