Click to See Complete Forum and Search --> : bitmap pixel manipulation
AdriGerritsen
May 16th, 1999, 01:43 PM
Imagine a 24 bit bitmap (true color). And suppose you want to make a specific area of the bitmap darker, e.g. a pixel with RGB value (x,y,z) should become (x/2, y/2, z/2). By dividing each pixel by a certain amount, the effect of darkening is achieved.
Iterating through the entire bitmap by manipulating each pixel seperately is one possibility (a relatively slow one). On the other hand a tried a lot of BitBlt's, but unfortunately with no success....
Is there anyone who know an efficient algorithm??
Thanks!!
Saeed R
May 16th, 1999, 08:20 PM
Using Shift operators makes the process faster..
instaed of / use >>
eg half=whole>>1;
Hope this helps
Ralf Herrmann
May 18th, 1999, 04:09 AM
From my point of view it should not be so slow to modify the bitmap But you have two more choices:
- use the windows palette, if you only want to modify the display, not the bitmap by itself
- use MMX assembler code if you want to have the ulitimate speed.
Ralff
The reason it is slow is because you are using division. Create a table and for every possible value of a pixel(1 through 256) divide the number and fill the table. (that is 256 divisions)
The table should look something like (if you are dividing by 2 lets say)
1 0
2 1
3 1
4 2
...
256 128
table[r] = r/2;
Now transverse through your image if r is the red value new red value rr would be
rr = table[r]; just a look up.
this should speed up the operation.
UNLESS your image has total of less then 256 pixels.
yalcin
yalcin@ioflex.com
can you use setcolorajustment ? maybe modify the caBrightness
field? clip the dc and do that?
ah well. it tried.
AdriGerritsen
May 19th, 1999, 05:55 PM
I eventually found the solution for my problem: manipulate the data bytes corresponding to the pixels in the device independent bitmap directly. After doing so, the new device independent bitmap can be shown on screen by using SetDIBitsToDevice. That's all! And: extremely fast.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.