I was writing a little testprogram for my pnglib but ran into some problems when I tried to load a bitmap (which was generated from the png) into an imagelist, to use as toolbar images.
However no matter which color type (ILC_COLOR*) I used for the imagelist, the images didn't come out well. Sometimes they look blended and the colors were all wrong, sometimes parts of it were striped.
When I load the bitmap with LoadBitmap it works fine. I found out the problem lies in the fact that the png library creates a DIB (device independant bitmap), and somehow a DDB (device dependant bitmap) was required for the imagelist.
Is there a logic reason for this? Setting the bitmap with TB_ADDBITMAP did work with the DIB, however I couldn't use it because it didn't support masks.
I'm not sure what type of bitmap (DIB or DDB) to use as output for the pnglib... DIBs are slightly easier to build as windows provides the memory space for you automatically. What do you think?

Posted on 2002-04-08 13:35:57 by Thomas
I found some things searching google.. DDB's are a bit faster when drawing them to the screen etc, as they are already in the format of your display. This also means that they take more memory as the actual format may be much less than the display format.
I adjusted my pnglib, you can now simply choose between a DIB or a DBB using a boolean parameter. Everything works okay now but I wonder if the use of bitmaps with things like an imagelist is documented somewhere.

I also saw another funny thing. When I use DIBs and load a lot of big images the memory usage (read from the task manager) logically increases a lot (around 18MB when testing), however when I use DDBs, the memory usage stays 1.8MB, no matter how much images I load. The total memory usage of the system does increase though, and when I shut down the program it decreases again, however the memory usage of the program itself didn't exceed 1.8MB.

Posted on 2002-04-08 15:09:50 by Thomas
when you use DBB format OS instead of storing image in regular memory stores it video memory that is why DBB is faster then DIB, IMHO. Also probably that is why memory usage in taskbar almost doesnt change.
Posted on 2002-04-08 15:28:10 by pahan
As I understand it, DDB, or dependent bitmaps depend on being handed the proper color table, DIB (independent) bitmaps carry their own color tables with themselves.

DDB should be near obsolete now, just carried along for backwards compatability. Unless you need the thinest program possible, use dem DIBs.
Posted on 2002-04-08 20:27:37 by Ernie
DIBs probably have their memory allocated on your program heap
(at least you have direct access to the buffer), which would explain
why your program memory usage increases.

Iirc you dont have direct access to DDBs, so they might be allocated
from that small (on 9x anyway) USER heap, which would explain why
your program memory usage doesn't increase.

Just guesses though, it would probably be helpful to run something
like stress (does this exist for nt-ish windows?) and see what happens
to those various memory heaps.
Posted on 2002-04-09 12:14:36 by f0dder
Thanks for the info, I think I'll use DIB for the normal stuff.. However an imagelist really seems to need a DBB instead. But the library supports both now so that's no problem.

Posted on 2002-04-09 12:58:45 by Thomas

Setting the bitmap with TB_ADDBITMAP did work with the DIB, however I couldn't use it because it didn't support masks

Have you tried the ImageList_Add API call?

int WINAPI ImageList_Add(
HIMAGELIST himl, // handle to the image list
HBITMAP hbmImage, // handle to the bitmap containing the image
HBITMAP hbmMask // handle to the bitmap containing the mask
Posted on 2002-04-09 15:08:08 by Graebel
No, but I was using ImageList_AddMasked, which should create the mask automatically using a transparent color. But it mixed all the colors or draw stripes on the bitmap if I use a DIB for it, a DDB worked fine.

Posted on 2002-04-09 16:15:57 by Thomas
Well you got me stumped on this one. As long as you passed it the DIB initialization style and not the DDB one I would of course assume it would work without a hitch.

Blame it on M$...

Ahh maybe thats it... my docs say:

"Use the default behavior if none of the other ILC_COLOR* flags is specified. Typically, the default is ILC_COLOR4; but for older display drivers, the default is ILC_COLORDDB"

So if you dont specify you might be using the unintended ILC_COLORDDB :confused:
Posted on 2002-04-09 16:28:53 by Graebel
That isn't it either, as I tried all of those settings already :).. What bothers me is that this DIB behaviour is not documented...

Posted on 2002-04-09 16:53:38 by Thomas
I have been quite confused about DIB behavior also....
DDB's have always worked better for me....

From a very in depth book on the subject: which might be of interest:

Windows Programming - Win32, GDI, and Direct Draw,
by, Feng Yuan, 2001

"The main problem DIB images have is that GDI does not support writting to a DIB directly....A DDB is a GDI object managed by GDI and device drivers, having the same status as a logical pen,...brush,...or region.......DDB's can be used in pens, brushes, carets, menus....and common controls".....etc."

Posted on 2002-04-09 19:56:03 by Brad
Errr, I'm not sure which control you aere using, but it seems to be the Image List. My MSDN reference states:

There are two types of image lists: nonmasked and masked. A nonmasked image list consists of a color bitmap that contains one or more images. A masked image list consists of two bitmaps of equal size. The first is a color bitmap that contains the images, and the second is a monochrome bitmap that contains a series of masks?one for each image in the first bitmap.

Note that the mask is monochrome. Perhaps that is the secret.

Also note, as far as I understand (meaning I read it somewhere I know not, and never directly used the info) a monochrome bitmap may still specify a foreground and a background color, it is not limited to black and white.
Posted on 2002-04-09 22:35:34 by Ernie
Ernie: I am using a masked image list, but I do not create a mask bitmap. ImageList_AddMask will do that automatically for you, based on a transparent color. It works fine if I use a DDB or LoadBitmap, just not with a DIB..

Posted on 2002-04-10 01:10:28 by Thomas
there is another problem with imagelists, they work fine in 24 or 32 bit desktop resolution,
but if you select images with more than 16 static windows-colors, they will look ugly under 16 bit and completely distorted under 8 bit desktop resolution.
It seems, that there is no way to set any palette information to the imagelist.
Posted on 2002-04-10 13:08:46 by beaster