Solved

Fading a 24 bit bitmap using win32

Posted on 1997-05-05
4
438 Views
Last Modified: 2013-12-04
Is there a quick way to fade a 24 bit BMP from black to the original bitmap and back? My solution so far is to get the RGB values of the bitmap and scale them form 0 to x and back. Unfortunately this solution quite slow for big (say 640x480) bitmaps because of the time it takes to calculate and blit (I use SetDIBitsToDevice) the image. Is there a way to use the palette to do this (as I understand there is no real palette in 16 or 24 bit color modes)?. Or to adjust the bitmap in the videomemory directly both in 16 and 24 bit video modes? Could I use some ROP code and PatBlt to 'blend' colors? What is the fastest way? I'm using C and the win32 API.

Thanks,

Pieter.
0
Comment
Question by:SysEx
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
dtowell earned 95 total points
Comment Utility
Theoritically Get/SetDeviceGammaRamp() will allow you to control the RGB intensity mappings to the display.  However, I have never found a machine/driver that actually implements them.

The fastest way (assuming you have to blit the bitmap) is to use a DIB created with CreateDIBSection() and then blit'd to the screen (it saves a memory copy).  Also, use a table lookup for the RGB values (ie, for each step of fade, compute the scaled value for all possible RGB values (there are only 256) and then just look up the answer for each RGB value).
0
 

Author Comment

by:SysEx
Comment Utility
First of all, thanks for responding to my question. As you said the Get/SetDeviceGammeRamp() is of no practical use. Also the gamma ramp will change the colors on the entire screen, I'm interested in fading a bitmap in a window.

The fastest method you describe is, like I said in my question, exactly what I'm using now:
* Create 'FadeTable' once (BYTE FadeTable[256][100]) in wich every value lineary descends to zero.
* Use GetDIBits() to fill a BITMAPINFO structure
* malloc two buffers, one for the source RGB values and one for the faded RGB values to use SetDIBitsToDevice() on
* Use GetDIBits() to fill the source buffer.
Now for every step 0-99:
* Copy every byte from the source buffer to the fade buffer using the FadeTable
* Use SetDIBitsToDevice() to copy the image from the fade buffer to the screen.

For a bitmap of the size of an average window (about 1MB of RGB data) this method is far to slow, both the fading and the SetDIBitsToDevice() take to long to get a smooth fade on my P133 with S3 TRIO64V+ based videocard.

So my question is: Is there a faster way that works on the average win95 computer and works with a 16 bit color or better videomode.

Regards,

Pieter. (p.g.m.vandermeulen@student.utwente.nl)
0
 
LVL 1

Expert Comment

by:dtowell
Comment Utility
There is still one thing you can do: use CreateDIBSection() to create/allocate the buffer.  Trust me, this is not just a convient-all-in-one-package function.  It creates the buffer "sitting on the fence" between user mode and kernel mode code.  This removes a memory copy (from user to kernel mode) that occurs when using "roll your own" DIBs.  This will still not be real fast because you still have to touch every pixel and then blit them, but it is the fastest non-DirectDraw method available in Win32.  

Another thing to consider is the maximum potential speed.  Say your bus is running at 60MHz.  Each faded pixel takes 9 bus cycles (read pixel value, read faded value, write pixel for each RGB value) and each pixel transferred to the display takes 2 cycles (read 4 bytes, write 4 bytes).  Assuming you have a 640x480 image, it takes 3.4M cycles to do one fade step; thats a little over 17 frames per second.  Of course that assumes no overhead, no non-cache hits and all pipelined code.  None of these are good assumptions.
0
 

Author Comment

by:SysEx
Comment Utility
Using CreateDIBSection did speed up the blitting a bit. The limiting factor is the huge amount of data that has to be moved. I would be nice if there had been a function that could translate RGB values while blitting them from a DIB to the screen.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now