Thread: picture colour 2 gray

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    1

    picture colour 2 gray

    hello,
    it's my first time i need to program with c and i have a lot off questions.
    The biggest one:
    i just want to load a picture in color (jpg).
    After that i wanna put it into Black & white or gray.
    thanks

  2. #2
    Registered User
    Join Date
    Sep 2009
    Posts
    61
    I'd suggest you to use the allegro library.
    Allegro library - Wikipedia, the free encyclopedia

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    The equation for that is:

    From the DX9 SDK Aug. 2009
    The input alpha channel is copied, unmodified, to the output alpha channel.

    The return value for this function is the same value returned in the pOut parameter. In this way, this function can be used as a parameter for another function.

    This function interpolates the red, green, and blue color components of a D3DXCOLOR structure between an unsaturated color and a color, as shown in the following example.

    // Approximate values for each component's contribution to luminance.
    // Based upon the NTSC standard described in ITU-R Recommendation BT.709.
    FLOAT grey = pC->r * 0.2125f + pC->g * 0.7154f + pC->b * 0.0721f;

    pOut->r = grey + s * (pC->r - grey);

    If s is greater than 0 and less than 1, the saturation is decreased. If s is greater than 1, the saturation is increased.

    The grayscale color is computed as:

    r = g = b = 0.2125*r + 0.7154*g + 0.0721*b

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Those colour channel weightings seem a little extreme!
    I'd use the weightings found here:
    Grayscale - Wikipedia, the free encyclopedia

    For loading the picture in Windows, I'd recommend using OleLoadPicture. You should be able to find a good bit of sample code that uses this.
    If you are using a different platform, you'll have to give more details.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    It's based on one type of colorspace as the comments in the code suggest. The NTSC standard is the preferred standard for televisions and monitors as I understand it - IE: it's color space conversions are preferred for TV's and monitors. Not sure I would trust Wiki over the NTSC standard.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  2. Replies: 5
    Last Post: 03-01-2003, 04:52 PM
  3. DirectDraw colour matching
    By Hunter2 in forum Game Programming
    Replies: 2
    Last Post: 12-10-2002, 02:17 PM
  4. how to set the background colour of a static box?
    By Cobras2 in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 04:57 PM
  5. Colour theory... (weird title)
    By Magos in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2001, 04:16 PM