rgb color map

This is a discussion on rgb color map within the C++ Programming forums, part of the General Programming Boards category; Hello, i'm using a different compiler which uses custom opengl functions for doing many different things, but i was having ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    10

    rgb color map

    Hello, i'm using a different compiler which uses custom opengl functions for doing many different things, but i was having some trouble when printing out an rgb color map.

    using a certain function:
    Code:
    void graphics_pixel(int iX,int iY, int iR,int iG,int iB);
    which prints a pixel with the assigned color depth at the assigned x&y coordinates.

    so far, i've gotten this:
    Code:
    for(r=0;r<=255;r++){
    		for(g=0;g<=255;g++){
    			for(b=0;b<=255;b++){
    				graphics_pixel(x,y,r,g,b);
    				y++;
    				if(y==255){y=0;x++;}
    				if(x==255)x=0;
    			}
    		}
    	}
    which does not exactly work,printing this yellow and red square thing, how would you go about writing this? sorry if i didn't describe anything enough, also how large do you think the max size would have to be?

    thanks soo much in advance!

    ~Wiiplayer12

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,765
    > i'm using a different compiler which uses custom opengl functions
    Interesting, but useless information. Which one specifically?

    What types are those variables?

    Have you managed to write any opengl program with this compiler which produces the expected result?

    Perhaps your rgb values run from 0 to 65535 ?
    Ie, try setting all the values in 0x0000xx00 and not 0x000000xx
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    printing this yellow and red square thing
    That looks like what you wrote... is this what you see:
    yellow.png?

    What did you want to occur, and are you sure you're using openGL? unless graphics_pixel() is a function you wrote, the only hit Google gives for it is this thread...
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    10
    yes, that's exactly what i got, and the organization i work with made the function, haven't released it to the public yet...so how do you think you would fix it, you don't have to if you don't want to...
    ~Wiiplayer12

  5. #5
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    the output is correct for the code you gave.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    More to the point, you're trying to draw 256*256*256 pixels in a 255*255 square, so you're going to lose a lot of pixels.

  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    10
    well, then how do you think i could fix it to look more along the lines of this?

    ~Wiiplayer12

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    For starters, you'll need a 4096*4096 square -- that will at least get you all tlhe pixels. Then if you want your picture to look like that, you'll have to figure out what changes along a row (it appears, based on no evidence whatsoever, that they're using degrees of a color wheel, so you'll have to think about that).

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The math behind a HLS/HSV colour mapping can be found here: http://en.wikipedia.org/wiki/HSL_color_space

    As tabstop says, there's 16 million (16 777 216 to be precise) if you have 256 values for each of the R, G and B colours, so you'd need a 4096 x 4096 square to represent all of them. But you can skip a few here and there and still get "most" of them.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    not exactly what you're looking for, but it should get you on the right path.

    Code:
            int s = 256;
            for(int i=0;i<s;i++)
            {
                    for(int j=0;j<s;j++)
                    {
                            int c1 = ((256-i)*(256-j))/256;
                            int c2 = (i*(256-j))/256;
                            Image1->Canvas->Pixels[i][j] = (c1<<16)+(c2<<8);
                    }
            }
            for(int i=0;i<s;i++)
            {
                    for(int j=0;j<s;j++)
                    {
                            int c1 = ((256-i)*(256-j))/256;
                            int c2 = (i*(256-j))/256;
                            Image1->Canvas->Pixels[i+256][j] = (c1<<8)+c2;
                    }
            }
            for(int i=0;i<s;i++)
            {
                    for(int j=0;j<s;j++)
                    {
                            int c1 = ((256-i)*(256-j))/256;
                            int c2 = (i*(256-j))/256;
                            Image1->Canvas->Pixels[i+512][j] = c1+(c2<<16);
                    }
            }
    bitshift of 0 denotes red, bitshift of 8 is green, and 16 is blue.
    Last edited by m37h0d; 07-17-2008 at 01:58 PM.

  11. #11
    Registered User
    Join Date
    May 2008
    Posts
    10
    thanks alot guys! but this seems too complicated, so i might just try it another time, sorry if i wasted all of you're time...

    ~Wiiplayer12

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL: Pixel addition
    By Hunter2 in forum Game Programming
    Replies: 4
    Last Post: 12-15-2008, 02:36 PM
  2. RGB Colours
    By rogster001 in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 04-22-2008, 01:56 PM
  3. Stopwatch program (need help!)
    By modnar in forum C Programming
    Replies: 9
    Last Post: 03-22-2004, 12:42 AM
  4. DirectDraw RGB in 32 bpp modes
    By Stan100 in forum Game Programming
    Replies: 12
    Last Post: 09-24-2003, 01:02 AM
  5. Background color in RGB
    By bennyandthejets in forum Windows Programming
    Replies: 16
    Last Post: 06-20-2003, 06:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21