PDA

View Full Version : How to combine a bitmap with a alpha mask



czar
12-01-2004, 10:22 PM
I have a program that I wrote using Graphics32 where I combine a user provided bitmap with a second bitmap that represents the alpha channel. The second image is grey scale. This allows me to display the user bitmaps using interesing masks.

Is it possible to load the two bitmaps and then strechdraw the second image onto the alpha layer of the first? The first image including the transparancy layer could then be placed in an image list.

Is this possible? And if so any help on how to approach the problem. Failing that would it be possible to combine the two images, save them as a tga and then load the tga into the imagelist?

I noticed that at some point a DrawMask option was available will this make a return, as it sounds like the sort of thing I would like to achieve.

R

Andreaz
13-01-2004, 05:46 AM
Yeah, the drawmask did just that wen it was avaiable, but it was slow and the tga version is much faster so i removed that function.

However, trhere are 2 ways of doing this.

The first way is to combine the 2 bitmaps during runtime with the following
function. (note that the source and the dest can't be the same bitmap).
Load the original bitmap with the imagelist and then replace the bitmap with GLXImageList1.Items[0].Picture.Bitmap.Assign(TheDestBitmap) and finnaly rebuild the texture GLXImageList1.Items[0].BuildTexture.



Type TRGBQuadArray = Array[WORD] of TRGBQuad;
Type PRGBQuadArray = ^TRGBQuadArray;

Type TRGBTripleArray = Array[WORD] of TRGBTriple;
Type PRGBTripleArray = ^TRGBTripleArray;


procedure LoadDataAlpha(Source, Dest: TBitmap);
var X, Y: Integer;
var SLine: PRGBTripleArray;
var DLine: PRGBQuadArray;
begin
Source.PixelFormat:=pf24Bit;
Dest .PixelFormat:=pf32Bit;

Dest.Width :=Source.Width;
Dest.Height:=Source.Height;

For Y:=0 to Source.Height-1 do begin
SLine := Source.ScanLine[Y];
DLine := Dest .ScanLine[Y];
For X:=0 to Source.Width-1 do begin
DLine[X].rgbRed :=SLine[X].rgbtRed;
DLine[X].rgbGreen :=SLine[X].rgbtGreen;
DLine[X].rgbBlue :=SLine[X].rgbtBlue;
DLine[X].rgbReserved:=Trunc((SLine[X].rgbtRed + SLine[X].rgbtGreen + SLine[X].rgbtBlue) / 3);
end;
end;
end;

The second, and the easiest way is to combine the bitmap with the alpha bitmap in a drawing program like Paint Shop Pro or Photoshop and then save it as a tga or png file.

Here's a steb-by-step guide on how to do in in psp:

1. Open both bitmaps (the colored is named Image1 and the grayscale Alpha1).
2. Select the Image1.
3. From the layer meny select "New Mask Layer->From Image"
4. Select Alpha1 as source, press Ok.
5. Save the mask into the alpha channel by selecting "Load / Save Mask->Save Mask To Alpha Channel" from the layers meny.
6. Press ok.
7. Delete the mask layer. Select no on the question "Doy you wan't to merge the mask..." ( Delete either vie the layer meny's "Delete" or by right clicking on the layer in the layer palette and selecting "Delete).
8. Save the image as "Truevision targa".
9. Load the file into GLXTreem with GLXImageList1.LoadTexture

czar
13-01-2004, 06:04 PM
Thanks for the code, I will certainly try it.

Late last night I fixed my problem another way. I used my current routine that I had written using Graphics32 to combine the bitmap with the mask. The result I save as a 32 bit bitmap and load that into glxtreem imagelist, it works sweet.

I have only been using glxtreem 1 day and I am very excited by it.

One other question.


Is it possible to query a computer's graphics card in software to make sure it can handle a Glxtreem application? If I know a copmputer can't handle my app I can start up a alternative software version instead.

For example, using the imagelist demo, in which I had replaced the images with a larger ones of up to 800x600, I got all sorts of problems on some computers. A number of computers here at work suffer from a problem that images will only go to 256 pixlels (or there abouts) wide. Even pentium 800mhz with a matrox g200 could't handle the app.

Andreaz
13-01-2004, 06:33 PM
Okey, nice. That way is the same as the first method i posted...

Hope you'll enyou glxtreem.

You can see what extentions the graphic card supports by checking the extention class of glxtreem, like multitexturing and so on, but the texture size i don't know actually. You can also see wich renderer and vendoe is used. Check the font demo on info how to use these tings.