Need to Replace Color A by Color B on Large Image

Need to Replace Color A by Color B on Large Image

Post by Olivier Be » Thu, 22 Jun 2006 02:45:19


Hello,

I have a large (1600*1200) image that uses 32-bits colors, and I need to
write a Delphi 7 program to traverse it and replace all pixels of a specific
color by another color. I have done it in the past for small (16*16*16)
images, but with this type of image I am worried about memory problems
(speed is not a major issue at the process would run once a day, during the
night.

Any suggestions would be greatlu appreciated.

TIA,

Olivier
 
 
 

Need to Replace Color A by Color B on Large Image

Post by willem van » Thu, 22 Jun 2006 03:08:47

G32 can handle large bitmaps and is fast!

http://www.yqcomputer.com/

Use the scanline property to access the individual pixels

Willem



--
Willem van Deursen, The Netherlands
XXXX@XXXXX.COM
replace _nospam@nospam_ for @ to get a valid email address
www.carthago.nl

 
 
 

Need to Replace Color A by Color B on Large Image

Post by Lord Cr » Thu, 22 Jun 2006 07:19:56

On Tue, 20 Jun 2006 19:45:19 +0200, "Olivier Beltrami"



I'd say 10800x10800 is large ;)

If you're using TBitmap, here's one way.

procedure ReplaceColor(Bmp: TBitmap; OldColor, NewColor: TRGBQuad);
var
x, y, dx: integer;
p: PRGBQuad;
begin
for y := 0 to Bmp.Height - 1 do
begin
p:= Bmp.ScanLine[y];
for x := 0 to Bmp.Width - 1 do
begin
if (p^.rgbRed = OldColor.rgbRed) and
(p^.rgbGreen = OldColor.rgbGreen) and
(p^.rgbBlue = OldColor.rgbBlue) and
(p^.rgbReserved = OldColor.rgbReserved) then
begin
p^:= NewColor;
end;

inc(p);
end;
end;
end;

Use it like this:

var
oc, nc: TRGBQuad;
begin
// old is default TBitmap white
oc.rgbBlue:= 255;
oc.rgbGreen:= 255;
oc.rgbRed:= 255;
oc.rgbReserved:= 0;

// light blue shade
nc.rgbBlue:= 255;
nc.rgbGreen:= 192;
nc.rgbRed:= 128;
nc.rgbReserved:= 0;
ReplaceColor(TheBitmap, oc, nc);
end;

- Asbjn
 
 
 

Need to Replace Color A by Color B on Large Image

Post by Olivier Be » Thu, 22 Jun 2006 17:53:26

> I'd say 10800x10800 is large ;)

Good so my case is "easy" ;-)


I'm actually usin a JPG, becuase it is the wallpaper background used in one
of my freewares (www.qppstudio.net/freeware.htm). Any suggestions ?

Olivier
 
 
 

Need to Replace Color A by Color B on Large Image

Post by Lord Cr » Thu, 22 Jun 2006 22:41:12

On Wed, 21 Jun 2006 10:53:26 +0200, "Olivier Beltrami"



You want to save it back as jpeg aswell?

In any case, you can get the bitmap from a jpeg this way:

var
jpg: TJPEGImage;
bmp: TBitmap;
begin
jpg:= TJPEGImage.Create;
try
jpg.LoadFromFile(...); // or similar
bmp:= TBitmap.Create;
try
bmp.Assign(jpg);

ReplaceColor(bmp, ...);

// if you want to save the changes
// to the jpeg back then do this:
jpg.Assign(bmp);
finally
bmp.Free;
end;

// and this to save the jpeg
jpg.Compress;
jpg.SaveToFile(...);
finally
jpg.Free;
end;
end;
 
 
 

Need to Replace Color A by Color B on Large Image

Post by Loren Pech » Fri, 23 Jun 2006 13:00:30

On Tue, 20 Jun 2006 19:45:19 +0200, "Olivier Beltrami"



Why are you worried about memory? It's not going to take any more
memory than simply holding the image and that's under 8mb.
 
 
 

Need to Replace Color A by Color B on Large Image

Post by Olivier Be » Fri, 23 Jun 2006 19:36:30

Thanks to Asbjn and Loren for their help !
Olivier