[lazarus] Bitmap transparency?

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Nov 10 18:05:24 EST 2003

On Mon, 10 Nov 2003 08:23:10 +0100
Micha Nelissen <M.Nelissen at student.tue.nl> wrote:

> Mattias Gaertner wrote:
> > On Sun, 09 Nov 2003 18:23:39 +0100
> > Micha Nelissen <M.Nelissen at student.tue.nl> wrote:
> > 
> > 
> >>Mattias Gaertner wrote:
> >>
> >>
> >>>On Sun, 09 Nov 2003 15:08:06 +0100
> >>>Micha Nelissen <M.Nelissen at student.tue.nl> wrote:
> >>>
> >>>>I have been looking, but I can't find it in the archives / code: what 
> >>>>functions do I need to implement?
> >>>
> >>>
> >>>See winapih.inc, search for RawImage.
> >>>See graphtype.pp for the RawImage format. 
> >>>intfgraphics.pas contains the TLazIntfImage which uses the 5 functions.
> >>
> >>Is GetDescriptionFromDevice only used to create a device compatible 
> >>bitmap? 
> > 
> > 
> > I guess, you mean the right thing.
> > GetDescriptionFromDevice should return only a RawImage description. No
> > width, no height. Just the information about color depth, bits per
> > pixel,... . No real data. This information is used to calculate the
> > needed memory and to know, how to set pixels.
> Ok, so what fields need to be filled in GetDescriptionFromDevice?

For the default, simply use FillChar(,0);.

Set all except the -

    Format: TRawImageColorFormat;
    HasPalette: boolean; 
    Depth: cardinal; 
-   Width: cardinal;
-   Height: cardinal;
-   PaletteColorCount: integer;
    ByteOrder: TRawImageByteOrder;
    LineOrder: TRawImageLineOrder;
-   ColorCount: cardinal; 
    BitsPerPixel: cardinal;
    LineEnd: TRawImageLineEnd;
    RedPrec: cardinal; 
    RedShift: cardinal;
    GreenPrec: cardinal;
    GreenShift: cardinal;
    BluePrec: cardinal;
    BlueShift: cardinal;
    AlphaPrec: cardinal;
    AlphaShift: cardinal;
    AlphaSeparate: boolean;
    AlphaBitsPerPixel: cardinal; 
    AlphaLineEnd: TRawImageLineEnd;

> >>If so, this can be done in win32 via CreateCompatibleBitmap. 
> >>Retrieving all information requested by TRawImageDescription from a 
> >>device context is very tedious, requires handling several cases (because
> >
> >>in win32 objective a DC is a 'stateless' something to be drawn to).
> >>
> >>Second reason is that the following lcl call CreateBitmapFromRawImage 
> >>will use CreateBitmap which is not recommended by the win32 docs for 
> >>most bitmaps:
> >>
> >>---
> >>While the CreateBitmap function can be used to create color bitmaps, for
> >
> >>performance reasons applications should use CreateBitmap to create 
> >>monochrome bitmaps and CreateCompatibleBitmap to create color bitmaps. 
> >>When a color bitmap returned from CreateBitmap is selected into a device
> >
> >>context, Windows must ensure that the bitmap matches the format of the 
> >>device context it is being selected into. 
> > 
> > 
> > Sounds like what we want. With the information in the RawImage
> > description the data created already matches the color format. The
> > interface only needs to setup the header.
> > The idea is to implement "CreateCompatibleBitmap" in a platform
> > independent way.
> > Under win32 afaik you would normally use CreateCompatibleBitmap to
> > create a bitmap. 
> The 'compatible' in CreateCompatibleBitmap means compatible to some DC. 
> With the current 5 fpimage functions, this function cannot be used, 
> because I don't know what DC to create a compatible bitmap to.
> What I was trying to say is: in the example at the top of the 
> intfgraphics unit, there is the sequence (GetDescriptionFromDevice, 
> CreateBitmap); my question is: is GetDescriptionFromDevice in any other 
> context? Ie. is it used for anything else than calling CreateBitmap 
> later on? Otherwise we could remove the GetDescriptionFromDevice and 
> replace it with CreateBitmapCompatibleToDevice, as you suggested later 
> in this post.

The goal of TLazIntfImage/fpImage is not only to handle interface images,
but to work with them. If an application needs information about the image
format of a DC, why should it create a bitmap? So, I think,
GetDescriptionFromDevice is a useful function.

If the win32 intf needs to create a bitmap to get the needed information, it
can create a small bitmap 1x1 and release it instantly.

About CreateBitmapCompatibleToDevice:
I think, you are right. It does not make much sense to create a RawImage
from incompatible data. The conversion process should be done by
TLazIntfImage and not by the interface. So, I think, I will change
TLazIntfmage to store a DC and to use CreateBitmapCompatibleToDevice instead
of CreateBitmapFromRawImage. But then we also need a function


More information about the Lazarus mailing list