[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


DDB / DIB advanced drawing question...

Posted on 2001-06-03
Medium Priority
Last Modified: 2013-12-03
This is an advanced DDB/DIB Section drawing question...

I have an application that uses 3 memory DC's to draw various layers of a final screen presentation in memory.  The multiple mem DCs are for best efficiency, since some layers change quite often and others do not.  Those that do not change very often tend to take quite a lot of time to draw and therefore I create 3 levels of mem DCs... if something has only changed on level 2, I just blt level 1 to 2 and then draw 2 and 3.  If something changed on level 3 I just blt level 2 to 3 and draw 3.  Much faster than redrawing all levels each time.

Another important fact is that I use a 256 color logical palette... my app only needs 256 colors and 8 bits per pixel... and has no need for 16/24/32 bit graphics.

Now... here's my question... I am trying to figire out which of the two following methods is more efficient.

Method 1 (current method):
The 3 mem DC's have DDBs selected into them...

Method 2 (possibly more efficient):
The 3 mem DC's would have an 8 bit/pixel DIB Section selected into them.

Now, I am pretty good with Windows GDI... and I realize that the Method 1 (using a Device compatible bitmap) does make the drawing and blt'ing to the screen a little faster... but, the fact is that if the user's screen is set to 16, 24 or 32 bit color, each of the 3 selected bitmaps is 2, 3 or 4 times the size it really needs to be... this could equate to over 10 MBytes of Virtual memory that is used unnecessarilly.

Using Method #2 would keep the virtual memory fixed at 1 byte per pixel for each of the mem DC's DIB Sections, and since each share the same palette, instead of Blting from one mem DC to the other I could just do a CopyMemory, which should be even faster than a Blt... BUT... by using the GDI drawing functions on a DIB section as opposed to a compatible bitmap, will all the GDI functions slow down at all?  I realize that the final blt from the level 3 MEM DC to the screen DC would take a little longer as Windows does the conversion... but would all the GDI drawing on the DIB Section backed mem DC's be the same, or slower, or faster than on a DDB basked DC?

In general, given the above scenario, which of the two methods would be faster?

Another factor, and appeal for the DIB Section backed memDC's is that I do some pixel manipulation with SetPixel, that would absolutely be faster by manipulating the DIBSection bits... but, even ignoring that, I am interested in how the performance would compare with the above two methods and straight GDI drawing...

Question by:jeffs1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 6151180
Hmmm, I tried a little somthin' with 3 dib's vrs. 3 ddb (1024x1024 filled with random values) and found not noticable difference (Duron 850, 256pc133, win98 SE, Delphi 5).  I would think, though, that the DDB should be faster only if the display is set to < 16bit color. As the bitblt operation is largely mem bound and bliting 3 24 (or 32) bit bmp's would have 3 or 4 times the optimum bandwidth requirements.  Performance aside, i think I would prob. prefer the dib approach as it allows you more flexibility with your palettes - a gradient neddn't always be linear.


Accepted Solution

robpitt earned 800 total points
ID: 6151791
I would use 8bit DIBSections for all the preparation work then rely on windows converting this to final screen format.

As you say using 8bit DIBs will save you tonnes of memory *plus* any interim GDI operations will actually be faster!. Why faster?... because GDI operations on memory are done in software, hence accessing an 8bit dib is less memory to physically write than say a ddb which may be 24bits.

More importantly conversion of 8bit DIB to final screen format is the *fastest* of all the software pixel format conversions. Think about it, the operation is just a simple lookup of pixel colour from the palette - almost as quick as a straight memory copy.

Hence I say use 8bit DIBs for the interim work then let GDI convert to screen.


PS And of course don't use ever use SetPixel()!

Expert Comment

ID: 6233722
DDB's are obsolete since windows 95.. everything is DIBs anyways, besides 8bit blits are accelerated just as well under any video mode.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question