procedure bmp_swaprgbacomps(abitmap : tbitmap);
type
TRGBA32b = array[0..3] of Byte;
PRGBA32b = ^TRGBA32b;
TRGB24b = array[0..2] of Byte;
PRGB24b = ^TRGB24b;
var
i, j, tempi : Integer;
oldformat : TPixelFormat;
l32 : PRGBA32b;
l24 : PRGB24b;
begin
oldformat := aBitmap.PixelFormat;
if not (aBitmap.PixelFormat in [pf24bit, pf32bit]) then
aBitmap.PixelFormat := pf24bit;
case aBitmap.PixelFormat of
pf24bit :
for i:=0 to aBitmap.Height-1 do
begin
l24 := aBitmap.Scanline[i];
for j:=0 to aBitmap.Width-1 do
begin
tempi := l24[0];
l24[0] := l24[2];
l24[2] := tempi;
inc(l24);
end;
end;
pf32bit :
for i:=0 to aBitmap.Height-1 do
begin
l32 := aBitmap.Scanline[i];
for j:=0 to aBitmap.Width-1 do
begin
tempi := l32[0];
l32[0] := l32[2];
l32[2] := tempi;
inc(l32);
end;
end;
end;
if (aBitmap.PixelFormat <> oldformat) then
aBitmap.PixelFormat := oldformat;
end;