[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Fading a 24 bit bitmap using win32

Posted on 1997-05-05
4
Medium Priority
?
481 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 190 total points
ID: 1397108
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
ID: 1397109
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
ID: 1397110
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
ID: 1397111
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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

834 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