Look at ReplaceColor for details.
function ImReplaceColor(var Image: TImageData; X: LongInt; Y: LongInt; Width: LongInt; Height: LongInt; OldPixel: Pointer; NewPixel: Pointer): Boolean; cdecl;
ImagingExport (at line 143)