Results 1 to 3 of 3

Thread: Counting pixels of a given color

  1. #1
    Guest

    Counting pixels of a given color

    I would like to count the pixels that are on the screen of a given color lets say represented by variables r g and b

    I think the way I should do this is something like the following, but I can't seem to be able to finish

    buff=(unsigned char *) calloc(1,w*h*3)
    glReadPixels(0,0,w,h,GL_RGB,GL_UNSIGNED_BYTE,buff)

    is that right?
    what do I do now with buff to get each pixel information out of it?

    Thanks
    Joan

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: Counting pixels of a given color

    Hi !

    In the buffer you get 3 bytes for each pixel pos=((y*width+x)*3) the first byte (pos) is the red color component in the range 0-255 the next (pos+1) is green and the last one (pos+2) is blue.

    Mikael

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: Counting pixels of a given color

    To make your life a little easier make your buffer an array of structs of...
    typedef struct RGB
    {
    GLubyte r, g, b;
    }SRGB;

    and malloc your array
    (SRGB*) malloc(sizeof(SRGB) * width*height);

    ok..... so then you access pixels

    myarray[i + (j*width)].r

Similar Threads

  1. Counting pixels
    By lbuckley in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-18-2005, 01:36 AM
  2. read textures pixels color???
    By queeroux in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-13-2004, 09:53 AM
  3. counting the no. of pixels within a bounded area
    By cs1dh in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 02-25-2004, 03:38 PM
  4. Color individual pixels
    By Dogcow in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-03-2003, 09:42 AM
  5. HELP Getting pixels color
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-27-2001, 03:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean