Thread: 24bit pixel plotting

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    31

    24bit pixel plotting

    Im reading the book "Tricks of the Windows Game Programming Gurus." I just now read over plotting pixels in 16bit, 24bit, 32bit colors. I know how to do them now but I dont exactly understand how 24 bit is working(although I do know how...but I hate not understanding how its doing it). Heres the code the book shows...

    Code:
    inline void Plot_Pixel_24(int x, int y, 
                              int red, int green, int blue, 
                              UCHAR *video_buffer, int lpitch)
    {
    // this function plots a pixel in 24-bit color mode
    // assuming that the caller already locked the surface
    // and is sending a pointer and byte pitch to it
    
    // in byte or 8-bit math the proper address is: 3*x + y*lpitch
    // this is the address of the low order byte which is the Blue channel
    // since the data is in RGB order
    DWORD pixel_addr = (x+x+x) + y*lpitch;
    
    // write the data, first blue
    video_buffer[pixel_addr]   = blue;
    
    // now red
    video_buffer[pixel_addr+1] = green;
    
    // finally green
    video_buffer[pixel_addr+2] = red;
    
    } // end Plot_Pixel_24
    When it plots the three different colors is it just ploting them very close to each other to where it mixes the colors or what? I was also wandering why [pixel_addr] has to be blue, [pixel_addr+1] has to be green, [pixel_addr+2] has to be red.

    video_buffer is a pointer to surface and lpitch is a pointer to the direct draw surface description lpitch.

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    because 24 bit color takes three bytes, each byte holds a color, they are almost always ordered (R)ed,(G)reen,(B)lue, or RGB.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing pixel colour
    By redruby147 in forum C Programming
    Replies: 11
    Last Post: 06-09-2009, 05:28 AM
  2. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  3. Getting Pixel Colour Screen
    By god_of_war in forum C++ Programming
    Replies: 3
    Last Post: 03-14-2006, 01:17 PM
  4. Plotting a pixel.
    By lozdg in forum C++ Programming
    Replies: 5
    Last Post: 05-11-2005, 03:01 PM
  5. plotting a pixel on a primary surface
    By agerealm in forum Windows Programming
    Replies: 0
    Last Post: 04-17-2003, 12:01 PM