Help! Need to make my own color...

Discussion in 'C Programming' started by arun, Jan 27, 2006.

  1. arun

    arun Guest

    I have 3 compilers at home: MSVC++, DEV-C++, and Turbo C++ 3.0.

    I would like to know how to make a color of my choice by specifying RGB
    values. Perhaps MSVC++, Dev- C++ have their own libraries to do so.
    Well, I would like to hear of that...

    I am also kind of a knowledge seeker. I would like to know how to
    actually make programs to create a color of your choice by specifying
    RGB values. I work a lot with turbo c++ graphics. If anyone here knows
    how to help me, it would be great.
    arun, Jan 27, 2006
    #1
    1. Advertising

  2. arun

    pemo Guest

    arun wrote:
    > I have 3 compilers at home: MSVC++, DEV-C++, and Turbo C++ 3.0.
    >
    > I would like to know how to make a color of my choice by specifying
    > RGB values. Perhaps MSVC++, Dev- C++ have their own libraries to do
    > so. Well, I would like to hear of that...
    >
    > I am also kind of a knowledge seeker. I would like to know how to
    > actually make programs to create a color of your choice by specifying
    > RGB values. I work a lot with turbo c++ graphics. If anyone here knows
    > how to help me, it would be great.


    Colors!

    Think you'd best ask on a newsgroup where you'll get an answer - presumably
    one to do with Windows programming? microsoft.public.win32.programmer.gdi
    perhaps?

    --
    ==============
    *Not a pedant*
    ==============
    pemo, Jan 27, 2006
    #2
    1. Advertising

  3. arun

    Mike Wahler Guest

    Re: [OT] Help! Need to make my own color...

    "arun" <> wrote in message
    news:...
    >I have 3 compilers at home: MSVC++, DEV-C++, and Turbo C++ 3.0.
    >
    > I would like to know how to make a color of my choice by specifying RGB
    > values.


    The C language has no notion of 'color' or 'screen'
    or any other particular hardware device.

    > Perhaps MSVC++, Dev- C++ have their own libraries to do so.


    Of those three implementations, I'm only familiar with Microsoft
    Visual C++. And yes, it does come with extensive libraries
    for doing many platform-specific things, such as video graphics
    with colors, fonts, etc.

    > Well, I would like to hear of that...


    See your VC++ documentation. Look up 'RGB', 'color', etc.
    Also don't forget MSDN (www.mdsn.microsoft.com), where virtually
    all the documentation for developer products is available, also
    with much more useful information (code samples), bug workarounds,
    etc.

    > I am also kind of a knowledge seeker.


    Great. So are you reading books?

    > I would like to know how to
    > actually make programs to create a color of your choice by specifying
    > RGB values.


    Simply put, RTFM.

    >I work a lot with turbo c++ graphics. If anyone here knows
    > how to help me, it would be great.


    See above.

    -Mike
    Mike Wahler, Jan 27, 2006
    #3
  4. arun

    Malcolm Guest

    "arun" <> wrote
    >
    >I have 3 compilers at home: MSVC++, DEV-C++, and Turbo C++ 3.0.
    >
    > I would like to know how to make a color of my choice by specifying RGB
    > values. Perhaps MSVC++, Dev- C++ have their own libraries to do so.
    > Well, I would like to hear of that...
    >
    > I am also kind of a knowledge seeker. I would like to know how to
    > actually make programs to create a color of your choice by specifying
    > RGB values. I work a lot with turbo c++ graphics. If anyone here knows
    > how to help me, it would be great.
    >

    An image is basically this

    struct colour
    {
    unsigned char red;
    unsigned char green;
    unsigned char blue;
    };

    struct image
    {
    int width;
    int height;
    struct colour *pixels;
    }

    Now you can manipulate this data in a totally portable way. For instance you
    could write a routine to turn a full-colour image to black and white, by
    changing all the pixels to an average value of grey.

    To view it, you need to save it in an image format. Look up wotsit .org for
    your favourite image format. (Choose a simple one, not GIF or JPEG, for a
    first attempt).
    Malcolm, Jan 27, 2006
    #4
  5. Malcolm said:

    > An image is basically this
    >
    > struct colour
    > {
    > unsigned char red;
    > unsigned char green;
    > unsigned char blue;
    > };


    Wot, no alpha channel?!?

    :)

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
    Richard Heathfield, Jan 27, 2006
    #5
  6. arun

    Malcolm Guest

    "Richard Heathfield" <> wrote
    >> struct colour
    >> {
    >> unsigned char red;
    >> unsigned char green;
    >> unsigned char blue;
    >> };

    >
    > Wot, no alpha channel?!?
    >
    > :)
    >

    Alpha means that you can access pixels on 32 bit boundaries, as well as use
    transparency.
    But I thought it might confuse the OP, who doesn't seem to be very clear on
    RGB colour values.
    Malcolm, Jan 28, 2006
    #6
  7. On Fri, 27 Jan 2006 21:13:12 +0000 (UTC), "Malcolm"
    <> wrote:
    >"arun" <> wrote
    >>
    >>I have 3 compilers at home: MSVC++, DEV-C++, and Turbo C++ 3.0.
    >>
    >> I would like to know how to make a color of my choice by specifying RGB
    >> values. Perhaps MSVC++, Dev- C++ have their own libraries to do so.
    >> Well, I would like to hear of that...
    >>
    >> I am also kind of a knowledge seeker. I would like to know how to
    >> actually make programs to create a color of your choice by specifying
    >> RGB values. I work a lot with turbo c++ graphics. If anyone here knows
    >> how to help me, it would be great.
    >>

    >An image is basically this
    >
    >struct colour
    >{
    > unsigned char red;
    > unsigned char green;
    > unsigned char blue;
    >};
    >
    >struct image
    >{
    > int width;
    > int height;
    > struct colour *pixels;
    >}


    why not this?

    struct color{
    unsigned char red;
    unsigned char green;
    unsigned char blue;
    };

    struct image
    {struct color pixel[1024][768];};
    RSoIsCaIrLiIoA, Jan 31, 2006
    #7
  8. RSoIsCaIrLiIoA wrote:
    > On Fri, 27 Jan 2006 21:13:12 +0000 (UTC), "Malcolm"
    > <> wrote:
    > >An image is basically this
    > >
    > >struct colour
    > >{
    > > unsigned char red;
    > > unsigned char green;
    > > unsigned char blue;
    > >};
    > >
    > >struct image
    > >{
    > > int width;
    > > int height;
    > > struct colour *pixels;
    > >}

    >
    > why not this?
    >
    > struct color{
    > unsigned char red;
    > unsigned char green;
    > unsigned char blue;
    > };
    >
    > struct image
    > {struct color pixel[1024][768];};


    Because 1024x768 is not the only resolution allowed by laws of physics!

    Malcolm's code would work on my digital watch with 53x231 screen, and
    only 16K of RAM, yours probably wouldn't even link (at least not
    without serious warnings).

    Cheers

    Vladimir
    Vladimir S. Oka, Jan 31, 2006
    #8
  9. arun

    Barry Guest

    "Vladimir S. Oka" <> wrote in message
    news:...
    > RSoIsCaIrLiIoA wrote:
    > > On Fri, 27 Jan 2006 21:13:12 +0000 (UTC), "Malcolm"
    > > <> wrote:
    > > >An image is basically this
    > > >
    > > >struct colour
    > > >{
    > > > unsigned char red;
    > > > unsigned char green;
    > > > unsigned char blue;
    > > >};
    > > >
    > > >struct image
    > > >{
    > > > int width;
    > > > int height;
    > > > struct colour *pixels;
    > > >}

    > >
    > > why not this?
    > >
    > > struct color{
    > > unsigned char red;
    > > unsigned char green;
    > > unsigned char blue;
    > > };
    > >
    > > struct image
    > > {struct color pixel[1024][768];};

    >
    > Because 1024x768 is not the only resolution allowed by laws of physics!
    >
    > Malcolm's code would work on my digital watch with 53x231 screen, and
    > only 16K of RAM, yours probably wouldn't even link (at least not
    > without serious warnings).
    >
    > Cheers
    >
    > Vladimir
    >


    But Malcolm's code may or may not work on MS Windows, depending on
    how the graphics side is treated. Windows likes to use:

    struct color {
    BYTE blue;
    BYTE green;
    BYTE red;
    };

    Thus another reason why such discussions don't belong on clc.
    Barry, Jan 31, 2006
    #9
  10. Barry wrote:
    > "Vladimir S. Oka" <> wrote in message
    > news:...
    > > RSoIsCaIrLiIoA wrote:
    > > > On Fri, 27 Jan 2006 21:13:12 +0000 (UTC), "Malcolm"
    > > > <> wrote:
    > > > >An image is basically this
    > > > >
    > > > >struct colour
    > > > >{
    > > > > unsigned char red;
    > > > > unsigned char green;
    > > > > unsigned char blue;
    > > > >};
    > > > >
    > > > >struct image
    > > > >{
    > > > > int width;
    > > > > int height;
    > > > > struct colour *pixels;
    > > > >}
    > > >
    > > > why not this?
    > > >
    > > > struct color{
    > > > unsigned char red;
    > > > unsigned char green;
    > > > unsigned char blue;
    > > > };
    > > >
    > > > struct image
    > > > {struct color pixel[1024][768];};

    > >
    > > Because 1024x768 is not the only resolution allowed by laws of physics!
    > >
    > > Malcolm's code would work on my digital watch with 53x231 screen, and
    > > only 16K of RAM, yours probably wouldn't even link (at least not
    > > without serious warnings).
    > >
    > > Cheers
    > >
    > > Vladimir
    > >

    >
    > But Malcolm's code may or may not work on MS Windows, depending on
    > how the graphics side is treated.


    And why wouldn't it? Malcom just stated that images, in principle, can
    be represented as above, and in standard C. There was no discussion on
    how such an image would be displayed (if at all). The method of
    displaying could certainly include casting to system-defined types.

    My comment was meant to highlight better portability of Malcolm's
    example.

    OP's question, whilst off topic, was about representing colors using
    RGB values, not displaying them on any given device/system. Admittedly,
    OP muddied the waters by listing a few specific implementations.

    Pixels certainly can be represented as below as well, but /not/ in
    standard C, so that'd be even more off-topic. ;-)

    > Windows likes to use:
    >
    > struct color {
    > BYTE blue;
    > BYTE green;
    > BYTE red;
    > };
    >
    > Thus another reason why such discussions don't belong on clc.


    I do agree that the OP's original question was quite off topic.

    Cheers

    Vladimir
    Vladimir S. Oka, Jan 31, 2006
    #10
  11. "Vladimir S. Oka" <> writes:
    > Barry wrote:

    [snip]
    > Pixels certainly can be represented as below as well, but /not/ in
    > standard C, so that'd be even more off-topic. ;-)
    >
    >> Windows likes to use:
    >>
    >> struct color {
    >> BYTE blue;
    >> BYTE green;
    >> BYTE red;
    >> };


    There's nothing non-standard about that as long as BYTE is a typedef.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Jan 31, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Josch
    Replies:
    1
    Views:
    832
    Alvin Bruney [MVP]
    Mar 2, 2004
  2. Stefan Siegl
    Replies:
    1
    Views:
    769
  3. Saverio M.
    Replies:
    0
    Views:
    511
    Saverio M.
    Jul 3, 2006
  4. Kamaljeet Saini
    Replies:
    0
    Views:
    410
    Kamaljeet Saini
    Feb 13, 2009
  5. David Filmer
    Replies:
    17
    Views:
    259
    J. Romano
    Aug 18, 2004
Loading...

Share This Page