Yes, that's what it is.
It can be also faster by applying the filter at the beginning in FormCreate:
procedure TfrmMain.FormCreate(Sender: TObject);
begin
{ Load TileMap }
TileMap := TBGTileMap.Create('map.ini');
{ Apply Filter }
GameBoy(TileMap.TileSet.Bitmap);
TileMap.Map.BackgroundColor := GameBoy(TileMap.Map.BackgroundColor);
So the drawing becomes:
procedure TfrmMain.bgMapRedraw(Sender: TObject; Bitmap: TBGRABitmap);
begin
{ Draw Cache }
Bitmap.PutImage(0, 0, CacheBitmap, dmSet);
{ Draw Player }
TileMap.DrawTile(Bitmap, PlayerPosition.x, PlayerPosition.y, 3, 255);
end;
For this, you need a function GameBoy to apply to one TBGRAPixel:
//filter to be applied on any sequence of pixels in memory
procedure GameBoy(P: PBGRAPixel; Count: integer);
var
c: NativeInt;
begin
while Count > 0 do
begin
c := p^.red + p^.green + p^.blue;
if c <= 382 then
begin
if c <= 191 then
p^ := BGRA(0, 80, 32, p^.alpha)
else
p^ := BGRA(0, 104, 24, p^.alpha);
end
else
begin
if c <= 573 then
p^ := BGRA(0, 176, 0, p^.alpha)
else
p^ := BGRA(112, 224, 48, p^.alpha);
end;
Inc(p);
dec(Count);
end;
end;
//filter to be applied on a bitmap, uses the generic function
procedure GameBoy(Bitmap: TBGRABitmap);
begin
GameBoy(Bitmap.Data,Bitmap.NbPixels);
end;
//filter on one TBGRAPixel, transmit the address of the variable to the generic function
function GameBoy(c: TBGRAPixel): TBGRAPixel;
begin
result := c;
GameBoy(@result,1);
end;