Delphi Quick pixel routine

A Old routine I had laying around.
This code has a much better performance compared to the Delphi Get/Set pixel methodes.
A Bitmap is not much more than a big chunk of memory. This methode creates a pointer to the exact place where the pixel value is stored in memory, then it uses the pointer to get or change the pixel value.

I’ve also put a check in the routine to make sure the caller does not try to access a place in memory that is not reserved for the bitmap. This will however effect the performance a little. If you are 100% sure you are using the routine to access only pixels within the bitmap you could remove the check thus making the routines even faster. Only use 24 bit bitmaps with these routines.

function GetPixel(aBitmap: Graphics.TBitmap; const X, Y: Integer): TColor;
var
  P: PRGBTriple;
begin
  if (Y < 0) or (X < 0) or (Y >= aBitmap.Height) or (X >= aBitmap.Width) then
  begin
    Result := clBlack;
    Exit;
  end;
  P := aBitmap.ScanLine[Y];
  Inc(P, X);
  Result := (P^.rgbtBlue shl 16) or (P^.rgbtGreen shl 8) or P^.rgbtRed;
end;

procedure SetPixel(aBitmap: Graphics.TBitmap; const X, Y: Integer; const Value: TColor);
var
  P: PRGBTriple;
begin
  if (Y < 0) or (X < 0) or (Y >= aBitmap.Height) or (X >= aBitmap.Width) then
    Exit;
  P := aBitmap.ScanLine[Y];
  Inc(P, X);
  P^.rgbtBlue := (Value and $FF0000) shr 16;
  P^.rgbtGreen := (Value and $00FF00) shr 8;
  P^.rgbtRed := Value and $0000FF;
end;

Note that these routines are based on the code from the TQuickPixel class wich can be found here: http://www.delphi3000.com/articles/article_2421.asp?SK=