Currently, I loop the Canvas.Pixels[] property and read each pixel on a canvas to swap Red/Blue bytes around (for specific reasons). However, it takes an average of 2 seconds per picture, and I have over 8,000 pictures I need to convert (overnight). I understand I can use a method of ScanLine to accomplish this much faster, but I know nothing about ScanLine - it's a much lower level of coding than I'm comfortable with. What's the fastest way to accomplish this? I'm willing to wait some time for this to run through, but it would still be nice if I could chop that time in half or more.
Right now, this is the procedure I use:
procedure SwapBytes(var Bmp: TBitmap);
var
X, Y: Integer;
R, G, B: Byte;
C: TColor;
begin
for Y := 0 to Bmp.Height - 1 do begin
for X := 0 to Bmp.Width - 1 do begin
C:= Bmp.Canvas.Pixels[X,Y];
R:= GetRValue(C);
G:= GetGValue(C);
B:= GetBValue(C);
Bmp.Canvas.Pixels[X,Y]:= RGB(B, G, R)
end;
end;
end;
Added Note: An initial conversion of over 8,000 images is the first step of why I need this. However, I also will be using the same thing in our software to automatically convert any image on the spot, as needed. So a third-party converter won't work, because I cannot distribute this to our clients.
I would try something like follows. This version is only for 24-bit bitmaps:
procedure SwapRedBluePixels(ABitmap: TBitmap);
var
X: Integer;
Y: Integer;
Red: Byte;
Pixel: PRGBTriple;
begin
// check for the bit depth, it must be 24-bit if you use PRGBTriple pointer
// for line scan; if it wouldn't the iterated line pointers would point to
// another place in the memory
if ABitmap.PixelFormat <> pf24bit then
begin
ShowMessage('Your bitmap has color depth different from 24-bit');
Exit;
end;
// iterate through the image vertically
for Y := 0 to (ABitmap.Height - 1) do
begin
// access the line of pixels and get the pointer to the first pixel of
// that line
Pixel := ABitmap.ScanLine[Y];
// iterate through the scanned line pixels horizontally
for X := 0 to (ABitmap.Width - 1) do
begin
// store the pixel's red channel value
Red := Pixel.rgbtRed;
// modify the pixel's red channel value
Pixel.rgbtRed := Pixel.rgbtBlue;
// modify the pixel's blue channel value
Pixel.rgbtBlue := Red;
// increment to get the next pixel pointer of the scanned line
Inc(Pixel);
end;
end;
end;
Update 2:
This version is for 24-bit and 32-bit bitmaps:
procedure SwapRedBluePixels(ABitmap: TBitmap);
var
X: Integer;
Y: Integer;
Red: Byte;
Size: Integer;
Pixels: PByteArray;
begin
// check the color depth and set the size of the pixel arrangement
case ABitmap.PixelFormat of
pf24bit: Size := SizeOf(TRGBTriple);
pf32bit: Size := SizeOf(TRGBQuad);
else
// if the image is not 24-bit or 32-bit go away
begin
ShowMessage('Your bitmap has unsupported color depth!');
Exit;
end;
end;
// iterate through the image vertically
for Y := 0 to (ABitmap.Height - 1) do
begin
// access the line of pixels and get the pointer to the first pixel of
// that line
Pixels := ABitmap.ScanLine[Y];
// iterate through the scanned line pixels horizontally
// for 24-bit images the pixels are stored like
// B -> G -> R -> B -> G -> R etc.
// for 32-bit images the pixels are stored like
// B -> G -> R -> A -> B -> G -> R -> A etc.
// so we can simply use e.g. byte array and iterate through
// it, if we have 24-bit image, we have to read each element,
// if 32-bit we have to skip the alpha (reserved) channel
for X := 0 to (ABitmap.Width - 1) do
begin
// store the pixel's red channel value
Red := Pixels^[(X * Size) + 2];
// modify the pixel's red channel value
Pixels^[(X * Size) + 2] := Pixels^[(X * Size)];
// modify the pixel's blue channel value
Pixels^[(X * Size)] := Red;
end;
end;
end;
Related
I want to copy pixels from BMP1 to BMP2 but the copied image is gabbled. Why?
Note: The input image is pf8bit;
TYPE
TPixArray = array[0..4095] of Byte;
PPixArray = ^TPixArray;
procedure Tfrm1.CopyImage;
VAR
BMP1, BMP2: TBitmap;
y, x: Integer;
LineI, LineO: PPixArray;
begin
BMP1:= TBitmap.Create;
BMP2:= TBitmap.Create;
TRY
BMP1.LoadFromFile('test.bmp');
BMP2.SetSize(BMP1.Width, BMP1.Height);
BMP2.PixelFormat:= BMP1.PixelFormat;
for y:= 0 to BMP1.Height -1 DO
begin
LineI := BMP1.ScanLine[y];
LineO := BMP2.ScanLine[y];
for x := 0 to BMP1.Width -1 DO
LineO[x]:= LineI[x];
end;
//BMP2.SaveToFile('out.bmp');
imgOut.Picture.Assign(BMP2); //TImage
FINALLY
FreeAndNil(BMP2);
FreeAndNil(BMP1);
END;
end;
For the saved image, a graphic editor says "Pixel depth/colors: indexed, 256 color palette".
It might be worth pointing out that an 8-bit bitmap isn't necessarily greyscale.
Instead, it is a bitmap with a "colour table" consisting of up to 256 entries, and each pixel refers to an entry in this table. So if a pixel's value is 185, this means that it should use the colour at location 185 in the bitmap's "colour table". Hence, an 8-bit bitmap works entirely different compared to a 16-, 24- or 32-bit bitmap, which does not have a colour table, but instead has actual RGB(A) values at each pixel.
The problem in your case is likely that the target pixmap doesn't have the same colour table as the source bitmap.
I have actually never worked with 8-bit bitmaps and palettes before, but I think it is this simple:
var
s, t: TBitmap;
y: Integer;
sp, tp: PByte;
x: Integer;
begin
s := TBitmap.Create;
try
s.LoadFromFile('C:\Users\Andreas Rejbrand\Desktop\bitmap.bmp');
Assert(s.PixelFormat = pf8bit);
t := TBitmap.Create;
try
t.PixelFormat := pf8bit;
t.SetSize(s.Width, s.Height);
t.Palette := s.Palette; // <-- Let the new image have the same colour table
for y := 0 to s.Height - 1 do
begin
sp := s.ScanLine[y];
tp := t.ScanLine[y];
for x := 0 to s.Width - 1 do
tp[x] := sp[x];
end;
t.SaveToFile('C:\Users\Andreas Rejbrand\Desktop\bitmap2.bmp');
finally
t.Free;
end;
finally
s.Free;
end;
How can I set TImage size as double value? Example Image1.width := 50.1; or what component accept it, because TImage only accept integer values.
I'm working with download files, and one image should be the number of elements to download, so Image1.width max value is 340, i need to divide this value by the amount of files who will be downloaded, and increase this value on image1.width when every download be finished, but TImage only accept Integer value.
I already did it using "Round" but it is not what I need.
As answered, you cannot set the image's size to any floating point value.
However, using coordinate spaces and transformations functions, you can set an arbitrary transformation between a logical coordinate system and the viewing device. This can be used to increase the logical extent of the image's canvas size with each download and yet keep the image on the screen with an entirely different size.
The below example demonstrates the concept by drawing 4 rows and 4 columns of a 256x256 image on a 105x105 bitmap canvas of a TPicture of a TImage. Basically it achieves to draw a single 256x256 image on a 26.25x26.25 px. surface.
uses
pngimage;
procedure TForm1.Button1Click(Sender: TObject);
const
Col = 4;
Row = 4;
var
Png: TPngImage;
ImgCanvas: TCanvas;
ExtX, ExtY: Integer;
MapMode: Integer;
Size: TSize;
i, j: Integer;
begin
Png := TPngImage.Create;
try
Png.LoadFromFile('...\Attention.png');
Png.Draw(Canvas, Rect(0, 0, Png.Width, Png.Height)); // original picture
Image1.Picture.Bitmap.Canvas.Brush.Color := Color;
Image1.Picture.Bitmap.SetSize(Image1.Width, Image1.Height);
ImgCanvas := Image1.Picture.Bitmap.Canvas;
SetStretchBltMode(ImgCanvas.Handle, HALFTONE);
MapMode := SetMapMode(ImgCanvas.Handle, MM_ISOTROPIC);
if MapMode <> 0 then
try
ExtX := Png.Width * Col;
ExtY := Png.Height * Row;
if not GetWindowExtEx(ImgCanvas.Handle, Size) then
RaiseLastOSError;
if not SetWindowExtEx(ImgCanvas.Handle, Size.cx * ExtX div Image1.Width,
Size.cy * ExtY div Image1.Height, nil) then
RaiseLastOSError;
if not SetViewportExtEx(ImgCanvas.Handle, Size.cx, Size.cy, nil) then
RaiseLastOSError;
i := 0;
j := 0;
while j < ExtY do begin
while i < ExtX do begin
Png.Draw(ImgCanvas, Rect(i, j, i + Png.Width, j + Png.Height));
Inc(i, Png.Width);
end;
i := 0;
Inc(j, Png.Height);
end;
finally
SetMapMode(ImgCanvas.Handle, MapMode);
end
else
RaiseLastOSError;
finally
Png.Free;
end;
end;
Probably worth noting that GDI may not be the best graphics system when scaling is involved. For quick reference, here's what the above yields:
Assuming you're using the VCL framework, all controls across Delphi are Integer based. You simply cannot assign a float value, not without first converting it to an integer.
The Firemonkey framework on the other hand is widely based on float values.
I want to paint a monochome bitmap stretched at 200% with two colors: pure black and pure white.
I use the following code, but nothing gets displayed.
If I replace SRCCOPY with SRCPAINT I get a white rectangle, but still no random 2x2 blocks get painted as is supposed to happen.
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowCell(Form1.Canvas); //Using another canvas does not help.
end;
procedure ShowCell(Canvas: TCanvas);
const
cHeight = 100;
cWidth = 50; //50 * 8 = 400 pixels
var
bmpinfo: PBitmapInfo;
color: PRGBQUAD;
i: Integer;
x,y,h: integer;
DataBuffer: array[0..cHeight-1,0..cWidth-1] of byte;
ScanLineWidth: integer;
Cell: TLifeCell;
Coordinate: TCoordinate;
begin
GetMem(bmpinfo, SizeOf(TBitmapInfo) + SizeOf(TRGBQUAD)*2);
color:= #bmpinfo^.bmiColors[0];
color^.rgbRed:= 255;
color^.rgbBlue:= 255;
color^.rgbGreen:= 255;
color^.rgbReserved:= 0;
Inc(color);
color^.rgbRed:= 0;
color^.rgbBlue:= 0;
color^.rgbGreen:= 0;
color^.rgbReserved:= 0;
with bmpinfo.bmiHeader do begin
biSize:= SizeOf(bmpinfo.bmiHeader);
biWidth:= cWidth*8; //8 pixels per byte
biHeight:= cHeight;
biPlanes:= 1;
biBitCount:= 1;
biCompression:= BI_RGB;
biSizeImage:= 0;
biXPelsPerMeter:= 0;
biYPelsPerMeter:= 0;
biClrUsed:= 0;
biClrImportant:= 0;
end;
ScanlineWidth:= cWidth div 8;
if (ScanlineWidth mod 4) <> 0 then Inc(ScanlineWidth, 4 - ScanlineWidth mod 4);
for x:= 0 to cwidth-1 do begin
for y:= 0 to cheight-1 do begin
DataBuffer[x][y]:= Random(255);
end;
end;
StretchDIBits(Canvas.Handle, 0, 0, cHeight*2, cWidth*2*8, 0, 0, cHeight, cWidth*8,
#DataBuffer, bmpinfo^, DIB_RGB_COLORS, SRCCOPY);
FreeMem(bmpinfo);
end;
What am I doing wrong here?
It works for me with some corrections - cwidth/cheight in the cycle and main - width and height arguments of StretchDiBits function were exchanged. Has GetLastError reported wrong param values? (In my case - not)
for x:= 0 to cwidth-1 do begin
for y:= 0 to cheight-1 do begin
DataBuffer[x][y]:= Random(255);
end;
end;
StretchDIBits(Canvas.Handle, 0,0,cWidth*2*8,cHeight*2,0,0,cwidth*8,cHeight,#DataBuffer,
bmpinfo^, DIB_RGB_COLORS, SRCCOPY);
Another possible issue - you defined cWidth (data buffer width) independently of ScanlineWidth calculation.
There are a number of errors:
Bitmap declaration does not match StretchDIBits call.
Bitmap is upside down
Loop has x and y reversed
Status code is not checked (and finally)
For performance reasons the width of a bitmap should be a multiple of 4 (or 8) bytes
Bitmap declaration does not match StretchDIBits call
The problem is that the declaration of the bitmap must match the arguments of StretchDIBits. If these do not match you'll get a silent error and nothing will get displayed.
Here are the problem lines:
with bmpinfo.bmiHeader do begin
biSize:= SizeOf(bmpinfo.bmiHeader);
biWidth:= cWidth*8; //8 pixels per byte must match srcWidth.
biHeight:= cHeight; // must match srcHeight below.
StretchDIBits(Canvas.Handle,0,0,cWidth*2*8,cHeight*2
,0,0,cwidth*8,cHeight, //srcWidth,srcHeight
#DataBuffer, bmpinfo^, DIB_RGB_COLORS, SRCCOPY);
If either the srcWidth or srcHeight parameter exceed the dimensions of the bitmap the call will fail.
In the call to StretchDIBits in the question Height and Width are reversed, making the bitmap too large and forcing an error, preventing display.
Bitmap is upside down
Because IBM has had it's grubby hands on the bitmap format logic went out the window and the default for bitmaps is to be upside down.
BITMAPINFOHEADER
biHeight The height of the bitmap, in pixels. If biHeight is positive, the bitmap is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, the bitmap is a top-down DIB and its origin is the upper-left corner.
Unless you want your data to be upside down, you'd better make biHeight negative, like so:
with bmpinfo.bmiHeader do begin
biSize:= SizeOf(bmpinfo.bmiHeader);
biWidth:= cWidth*8; //8 pixels per byte must match srcWidth.
biHeight:= -cHeight; // "-" = TopDown: must match srcHeight below.
Loop has x and y reversed
In the loop, take note that x and y are reversed in the buffer.
for y:= 0 to cHeight-1 do begin
for x:= 0 to cWidth-1 do begin //fill scanlines in the inner loop.
DataBuffer[y][x]:= Random(256); //y,x must be reversed!
end; {for x}
end; {for y}
Status code is not checked
If I had bothered to check the return value of StretchDIBits than I could have saved myself the bother. I would have known there was an error.
If the function succeeds, the return value is the number of scan lines copied. Note that this value can be negative for mirrored content.
If the function fails, or no scan lines are copied, the return value is 0.
Success:= StretchDIBits(.....
Assert(Success <> 0,'StretchDIBits error, check your arguments');
For performance reasons the width of a bitmap should be a multiple of 4 bytes
If you are going to write to your bitmap buffer using (32-bit) integers, you'd better make sure your bitmap width is a multiple of 4 bytes, or you're going to suffer delays due to misaligned writes.
If you use 64-bit Int64 writes, make it a multiple of 8 bytes.
Windows only enforces a 2-byte alignment. This is because the bitmaps need to stay compatible with 16-bit Windows bitmaps.
bmWidthBytes The number of bytes in each scan line. This value must be divisible by 2, because the system assumes that the bit values of a bitmap form an array that is word aligned
With vcl I used this:
procedure MovingDots(X, Y: Integer; ACanvas: TCanvas); stdcall;
begin
{$R-}
Inc(ALooper);
ACounter := ACounter shl 1; // Shift the bit left one
if ACounter = 0 then
ACounter := 1; // If it shifts off left, reset it
if (ACounter and 224) > 0 then // Are any of the left 3 bits set?
// FMX.Canvas does not have Pixels
ACanvas.Pixels[X, Y] := ASelectionColor1 // Erase the pixel
else
ACanvas.Pixels[X, Y] := ASelectionColor2; // Draw the pixel
{$R+}
end;
How can I set the color at X,Y from a FMX Canvas?
According to this example, this should work:
var
vBitMapData : TBitmapData;
ASelectionColor : TAlphaColor;
...
// Define ASelectionColor somewhere
// Get write access to the bitmap
if ACanvas.Bitmap.Map (TMapAccess.maWrite, vBitMapData) then
begin
try
vBitmapData.SetPixel (x, y, ASelectionColor); // set the pixel color at x, y
finally
ACanvas.Bitmap.Unmap(vBitMapData);
end;
end;
Note that the mapping strategy with locking/unlocking the bitmap was introduced in FM2, i.e. Delphi-XE3.
Download source code here: http://www.eyeClaxton.com/download/delphi/ColorSwap.zip
Yes, I want to convert something "mostly blue" to something "mostly green".
I would like to take a original bitmap (light blue) and change the colors (Pixel by Pixel) to the red, green, blue and gray equivalence relation. To get an idea of what I mean, I have include the source code and a screen shot. Any help would be greatly appreciated. If more information is needed, please feel free to ask.
If you could take a look at the code below, I have three functions that I'm looking for help on. The functions "RGBToRed, RGBToGreen and RGBToRed" I can't seem to come up with the right formulas.
unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TMainFrm = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Panel2: TPanel;
Label2: TLabel;
Button1: TButton;
BeforeImage1: TImage;
AfterImage1: TImage;
RadioGroup1: TRadioGroup;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainFrm: TMainFrm;
implementation
{$R *.DFM}
function RGBToGray(RGBColor: TColor): TColor;
var
Gray: Byte;
begin
Gray := Round(
(0.90 * GetRValue(RGBColor)) +
(0.88 * GetGValue(RGBColor)) +
(0.33 * GetBValue(RGBColor)));
Result := RGB(Gray, Gray, Gray);
end;
function RGBToRed(RGBColor: TColor): TColor;
var
Red: Byte;
begin
// Not sure of the algorithm for this color
Result := RGB(Red, Red, Red);
end;
function RGBToGreen(RGBColor: TColor): TColor;
var
Green: Byte;
begin
// Not sure of the algorithm for this color
Result := RGB(Green, Green, Green);
end;
function RGBToBlue(RGBColor: TColor): TColor;
var
Blue: Byte;
begin
// Not sure of the algorithm for this color
Result := RGB(Blue, Blue, Blue);
end;
procedure TMainFrm.FormCreate(Sender: TObject);
begin
BeforeImage1.Picture.LoadFromFile('Images\RightCenter.bmp');
end;
procedure TMainFrm.Button1Click(Sender: TObject);
var
Bitmap: TBitmap;
I, X: Integer;
Color: Integer;
begin
Bitmap := TBitmap.Create;
try
Bitmap.LoadFromFile('Images\RightCenter.bmp');
for X := 0 to Bitmap.Height do
begin
for I := 0 to Bitmap.Width do
begin
Color := ColorToRGB(Bitmap.Canvas.Pixels[I, X]);
case Color of
$00000000: ; // Skip any Color Here!
else
case RadioGroup1.ItemIndex of
0: Bitmap.Canvas.Pixels[I, X] := RGBToBlue(Color);
1: Bitmap.Canvas.Pixels[I, X] := RGBToRed(Color);
2: Bitmap.Canvas.Pixels[I, X] := RGBToGreen(Color);
3: Bitmap.Canvas.Pixels[I, X] := RGBToGray(Color);
end;
end;
end;
end;
AfterImage1.Picture.Graphic := Bitmap;
finally
Bitmap.Free;
end;
end;
end.
Okay, I apologize for not making it clearer. I'm trying to take a bitmap (blue in color) and swap the blue pixels with another color. Like the shots below.
I have no idea what you are trying to achieve. First, what does the question have to do with equivalence relations?
Secondly, the code
function RGBToRed(RGBColor: TColor): TColor;
var
Red: Byte;
begin
// Not sure of the algorithm for this color
Result := RGB(Red, Red, Red);
end;
is meaningless. The return value is undefined. The RGB functions takes red, green, and blue intensities in the range 0 to 255 and returns the TColor having these components. For instance, RGB(255, 0, 0) is pure red, that is, 255 red, 0 green, and 0 blue. In the code above, however, Red is not initialized, so Result can be any grey colour (depending on what Red happens to be). [And, as you probably know, if you mix equal amounts of red, green, and blue, as you do, you get grey.] For instance, Red might happen to be 45 one time you run the application, and then the result will be the grey colour RGB(45, 45, 45). Next time it might be 163.
Maybe you want a function that accepts a TColor and returns the red component of it? Then GetRValue will do, and - of course - there is also GetGValue and GetBValue.
Or, maybe you want to create a grey colour from a given TColor, as you do when you use Photoshop to create a greyscale image from a colour image. Then, if Color is the TColor, the appropriate grey value is
grey := (GetRValue(Color) + GetGValue(Color) + GetBValue(Color)) div 3;
There are other ways of doing this (resulting in subtly different greyscale images, but this is the easiest (and fastest)). (For instance, you can convert the colour from RGB to HSV or HSL and then set the saturation equal to zero.)
Update
I think I see what you want to do. Maybe you want to extract the red, green, and blue channels. That is, you want to transform each pixel RGB(R, G, B) to RGB(R, 0, 0) in the red case. If this is what you want to do, then you should do
function RGBToRed(RGBColor: TColor): TColor;
begin
Result := RGB(GetRValue(RGBColor), 0, 0);
end;
and similarly for the other components, that is
function RGBToGreen(RGBColor: TColor): TColor;
begin
Result := RGB(0, GetGValue(RGBColor), 0);
end;
and
function RGBToBlue(RGBColor: TColor): TColor;
begin
Result := RGB(0, 0, GetBValue(RGBColor));
end;
Or, maybe
Or maybe you just want to make the image greyscale, and then "colour" it red (or green, or blue). Then you need the heavy machinery. Theoretically, you wish to replace each pixel from HSV(h, s, v) to HSV(0, s, v) in the red case, HSV(120, s, v) in the green case, and HSV(240, s, v) in the blue case. Or, maybe you also wish to set the saturation s to 1.
I use the following rutines to convert between RGB and HSV:
function RGBToHSV(const Color: TRGB): THSV;
var
cmax, cmin, cdiff: real;
begin
cmax := MaxComponent(Color);
cmin := MinComponent(Color);
cdiff := cmax - cmin;
with Color, result do
begin
// Hue
if cmax = cmin then
hsvHue := 0
else if cmax = rgbRed then
hsvHue := (60 * (rgbGreen - rgbBlue) / cdiff)
else if cmax = rgbGreen then
hsvHue := (60 * (rgbBlue - rgbRed) / cdiff) + 120
else
hsvHue := (60 * (rgbRed - rgbGreen) / cdiff) + 240;
hsvHue := Fix360(hsvHue);
// Saturation
if cmax = 0 then
hsvSaturation := 0
else
hsvSaturation := 1 - cmin / cmax;
// Value
hsvValue := cmax;
end;
end;
and
function HSVToRGB(const Color: THSV): TRGB;
var
hi: integer;
f, q, p, t: real;
begin
with Color do
begin
hi := floor(hsvHue / 60) mod 6;
f := hsvHue / 60 - floor(hsvHue / 60);
p := hsvValue * (1 - hsvSaturation);
q := hsvValue * (1 - f * hsvSaturation);
t := hsvValue * (1 - (1 - f) * hsvSaturation);
case hi of
0: result := RGB(hsvValue, t, p);
1: result := RGB(q, hsvValue, p);
2: result := RGB(p, hsvValue, t);
3: result := RGB(p, q, hsvValue);
4: result := RGB(t, p, hsvValue);
5: result := RGB(hsvValue, p, q);
end;
end;
end;
where
type
TRGB = record
rgbRed, // red intensity between 0 and 1
rgbGreen, // green intensity between 0 and 1
rgbBlue: double; // blue intensity between 0 and 1
end;
THSV = record
hsvHue, // hue angle between 0 and 360
hsvSaturation, // saturation between 0 (grey) and 1 (full colour)
hsvValue: double; // value between 0 (dark) and 1 ("normal")
end;
The end result, in the green case, will be like
in the first case (hue fixed to 120) and
in the latter case (hue fixed to 120, saturation fixed to 1).
Or, possibly
Your question is very vauge, even with the edit. You want to convert something "mostly blue" to something "mostly green". But there are a thousand ways of doing that! A very simple way, of course, is just to swap the blue and green channels, that is, replace RGB(r, g, b) with RGB(r, b, g), or, explicitly,
function SwapBlueGreen(Color: TColor): TColor;
begin
result := RGB(GetRValue(Color), GetBValue(Color), GetGValue(Color));
end;
Then you get something like
where the red and green channels have been swapped. Notice that the red stick is now green, and the green grass is now red. What's white remains white.
Finally
Welcome to the world of pixmap manipulation! There is a lot of easy and fun things to do. Some more of my examples: https://english.rejbrand.se/algosim/manual/pmproc/pmproc.html
Accessing color information via "Pixels" property is really slow. You should consider using "Scanline" property to get about 2 levels of magnitude faster code.
http://blogs.embarcadero.com/pawelglowacki/2010/04/15/39051 contains code samples how to do it.
Success!