From: Chris244@aol.com (Chris Hill) Subject: Re: Change Palette entry on 8-bit DIB Date: 10 Mar 1999 00:00:00 GMT Message-ID: <36e68fd6.2362893821@forums.borland.com> References: <36E533B1.2FBDDB3B@ix.netcom.com> <36e537bb.2274802162@forums.borland.com> <36E683BC.FB3ED914@ix.netcom.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.cppbuilder.graphics GetDIBColorTable is a Win32 API call, so perhaps you didn't search the Win32 help file. I have spent some time looking at the VCL source. You will notice that for bmDIB TBitmaps, CreateDIBSection is use to create the DIB and SetDIBColorTable is used to modify color table. The palette is used rather strangely, which reflects the historically DDB nature of TBitmap (in BCB 1 and Delphi 1-2). If a TBitmap uses a DIB section, the palette property extracts the colors from the palette handle and applies them to the DIB using SetDIBColorTable. You can't get direct pointer access to the palette using TBitmap (the API doen't permit it for DIB sections). It it is possible to create a DIB that allows direct access to the palette, but you must use the API to draw it. The term DIB is used it two different ways, and I think it would be helpful to explain. A DIB section created using CreateDIBSection has a handle; it can be selected into a DC and drawn on using GDI functions. The palette of this kind of DIB is specified at the time CreateDIBSection is called and may be modified using SetDIBColorTable. This is what TBitmap does. It must do so because it associates a Canvas with the bitmap, so it must be able to use GDI to draw on it. The second kind of DIB has no handle, so you can't draw on it with GDI. You allocate the memory for the image data and header (including the palette) yourself. You draw it using StretchDIBits. Since you have a pointer to the palette entries, you can modify them without a function call. Unlike the CreateDIBSection method, this technique was around in Win16. It is still perfectly acceptable to use it, it is NOT obsolete. The main difference is that a DIB section has a handle, while a DIB doesn't. People (myself included) often write DIB when it would be more correct to write DIB section. The image data has the same format for both kinds of DIBs. In your case, the main advantage would be pointer access to the palette. I'm not so sure that calling SetDIBColorTable with Bitmap->Canvas->Handle is a big performance problem, so I recommend sticking to that technique. You don't need to create, read and write the entries each time you want to set them. Just keep your pallete entries (an array of RGBQUAD structures) around. When you want to change the palette, just modify the RGBQUADs and call SetDIBColorTable once. I would avoid the Palette property if you want to rapidly change the palette entries. If you ever want to draw on the DIB using a Canvas rather than addressing each pixel, you should stick with TBitmap. On Wed, 10 Mar 1999 06:37:48 -0800, Charles Bond wrote: >Thanks. It's amazing how many useful functions are laying around without >the documentation they deserve. I couldn't find GetDIBColorTable in >the help files, but found it in the VCL source. You must have spent some >time there... > >By the way, since I can directly access the pixels in a bitmap using >ScanLine, is there an equivalent pointer to the bitmap palette? It >seems to me that once I have called CreatePalette, I should be able >to get a pointer to the actual Palette referenced by the bitmap pixel >values and directly alter Palette entries without having to incur the >overhead of a function call, much the same way I can alter RGBQUAD >or palPalEntry. Got Pointers? > >Chris Hill wrote: > >> Assuming you are using BCB3 with a TBitmap where HandleType == bmDIB, >> use Get/SetDIBColorTable. The first parameter to these functions >> would be YourBitmap->Canvas->Handle. Once you have modified the DIB >> palette, you must draw the bitmap again to reflect the changes. >> >> On Tue, 09 Mar 1999 06:44:01 -0800, Charles Bond >> wrote: >> >> >After I use CreatePalette to associate a palette with a bitmap, >> >I would like to modify individual colors. How can I read/write >> >an individual palette entry of an existing bitmap? >> > >> >> Chris Hill >> Chris244@aol.com > > > Chris Hill Chris244@aol.com