This is the readme.txt for LOADBMP.GFW / LOADBMP.LST 

LOADBMP() is a replacement for GFABasic for Windows' LOADBMP() function.

Developed by:

Sjouke Hamstra
Biotoop 2
NL-3893 BK Zeewolde
Netherlands

Why this replacement?

Simply put: the LOADBMP() function implemented in GFABasic for Windows does not do a valid job. The color information from some bitmaps is not processed. It beats me why. The LOADBMP() function I present is a stripped version from a greater program that loads, stores and prints multiple DIBs. In this program a bitmap is kept with a seperate palette, where GFA stores the color information in the window palette. 

Some background information

GFA stores the color information from a bitmap in the current palette of the active window. You can retrieve GFA's active window with the function WIN(). The current palette can then be obtained with _PAL(WIN()). Every window has its own palette with a maximum of 256 entries. The exact amount of entries depends on the video mode of your PC.

The LOADBMP() function simply replaces GFA's LOADBMP() and will store the colors in the current window palette.

Now for the program.

The LOADBMP() function uses some TYPEs that should be defined earlier. So when you merge the FUNCTION into your own program don't forget to add a call to the DEFDIB() procedure.

In the function LOADBMP() you will find a routine that loads large block of information (>64K) form disk to memory. Also you find information on how to use the API function RealizePalette() and GFA's REALIZE command which are poorly documented. RealizePalette calculates and sets the palette selectes in the given DC to the systempalette. In fact RealizePalette calculates a translation table in which every color of the palette is mapped to a color of the systempalette. When no color match is found and an entrie of the system palette is free, GDI will fill it with the requested color. Otherwise the color is mapped to the nearest color available in the systempalette. Once GDI has calculated the translation table it won't do it again!! Any consequent RealizePalette() call simply resets the calculated translation table. 
The LOADBMP() function sets the palette entries of the current GFA window palette using the API function SetPaletteEntries(). To force GDI to recalculate the translation table you must first select the logical palette again in the current DC. GDI then knows to recalculate the mapping at the next RealizePalette().

WM_PAINT

Before The bitmap is put to the screen (allways as a result of a WM_PAINT message! I cannot emphasize this enough!) first the calculated palette is activated. No calculation is done at that moment, the palette is just activated, so it won't take any precious computertime. 

BONUS

Under Windows an application is never alone, so any program can and may change the systempalette. When your bitmap has to redrawn, either in the background or in the foreground, it should be drawn with the right colors. Windows sends two messages to inform the application about a palette change. (Windows only sends these messages to the application that used SelectPalette())
As a bonus I added a callback procedure which handles these messages. WM_PALETTECHANGED is send whenever the systempalette is changed by another application and the WM_QUERYNEWPALETTE message when your appliction receives the input focus again. The source is well documented and can be understood when you take the notes about RealizePalette into account.

Caveat.

I developed and tested all this on a 256 color SpeedStar PRO video adapter. No problems noticed

LOADBMP() does not load PCX files as GFA's LOADBMP() does.


June, 4th 1995
Sjouke Hamstra