in delphi 3, i use the glaux dll to load a bmp in to memory, and i want to use some transparent color to make background visible. I have downloaded a lots of tutorials (nehe, Pythian project) but is painfull to do this code run.
i think that must exist the way to do this transformation in a simple subproc or function, reading the information loaded in memory and allocating it with the alpha feature in another memory address.
[This message has been edited by Coloro.cl (edited 02-12-2002).]
I think this will help:
allocate an array or a matrix of these dimension:
Widhtheight3/4
(bytes)
(i assume black is your trans color)
do a for loop inside the returned bitmap.
read 3 bytes at once. If the 3 bytes are 0,0,0 send them in the new allocated buffer as: 0,0,0,0.
If you read a different color ie blue(0,0,255) you must send it in the second buffer like: (0,0,255,255)
another ex:
(123,31,200)--------->(123,31,200,255)
Originally posted by Andrea Rossini:
[b]Sorry Sorry Sorry
the right formula is:
w * h * 4/3
Sorry Sorry Sorry[/b]
Umm, actually it’s:
w * h * 4 bytes
(RGBA is 4 bytes per pixel.) I don’t know what the glaux bitmap loader does, but BMP files pad each line to be an even multiple of 4 bytes, so a 3-pixel wide line would be 12 bytes instead of 9 (assuming 24 bit RGB). Make sure to take this into account when reading the BMP data if glaux doesn’t strip out the padding. Of course, if you’re using this file as a texture, it’s highly likely that your lines will already be an even multiple of 4 bytes.
function XYToOffset(ox,oy:integer):integer;
var pxoffset:integer;
begin
{
0 1 2 3 4 5 6 7 8 9 PxWidth=10
0 X X X X X X X X X X PxHeight=3
1 X X X X X X X X X X
2 X X X X X X X X X X }
oy := (PxHeight-1) - oy; // now y is OK
pxoffset := ox;
if oy > 0 then
begin
pxoffset := pxoffset + (oy*(PxWidth));
end;
pxoffset := pxoffset * 4; // move into position for RGBA data
Result := pxoffset;
end;
begin
if bmp.Bpp <> 24 then raise Exception.Create(‘TTexture.GenTexFromBMP: Don’‘t support non 24bit pixel formats! (image is ‘+IntToStr(bmp.bpp)+’)’);
pxWidth := bmp.Width;
pxHeight := bmp.Height;
// allocate memory for it, assume RGBA data (4 components)
pd := AllocMem( (bmp.Width*bmp.Height)*4 );
for y := 0 to pxHeight-1 do
begin
for x := 0 to pxWidth-1 do
begin
c := bmp.Pixels24[y,x];
os := XYToOffset(x,y);
pd^[ os + 0 ] := c.r;
pd^[ os + 1 ] := c.g;
pd^[ os + 2 ] := c.b;
// alpha transparency here
if useTransparency = false then
pd^[ os + 3 ] := 255
else if (c.r = transparentColor.r) and
(c.g = transparentColor.g) and
(c.b = transparentColor.b) then
pd^[ os + 3 ] := 0 else pd^[ os + 3 ] := 255;
end;
end;
// now we have pixel data generate the texture
Pointer(FImage) := pd;
FWidth := bmp.Width;
FHeight := bmp.Height;
Initialize;
end;
//------------------------------------------
it looks good, but again, is hard to do these units works, may be i check how the glaux load a bmp into memory and give this as parameter of the procedure above…(?)
[This message has been edited by Coloro.cl (edited 02-12-2002).]