CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 1999
    Posts
    3

    bitmap pixel manipulation

    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!!


  2. #2
    Join Date
    May 1999
    Posts
    78

    Re: bitmap pixel manipulation

    Using Shift operators makes the process faster..
    instaed of / use >>
    eg half=whole>>1;

    Hope this helps


  3. #3
    Join Date
    May 1999
    Location
    Germany
    Posts
    10

    Re: bitmap pixel manipulation

    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


  4. #4
    Guest

    Re: bitmap pixel manipulation

    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
    [email protected]


  5. #5
    Guest

    Re: bitmap pixel manipulation

    can you use setcolorajustment ? maybe modify the caBrightness
    field? clip the dc and do that?
    ah well. it tried.


  6. #6
    Join Date
    May 1999
    Posts
    3

    Re: bitmap pixel manipulation

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured