CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Graphics Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Graphics Programming Discussion graphics programming using C++. Valid topics include OpenGL, DirectX, GDI/GDI+, Aero, and more.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old August 17th, 2004, 08:56 AM
    bogho bogho is offline
    Junior Member
     
    Join Date: Aug 2004
    Location: ROMANIA
    Posts: 2
    bogho is an unknown quantity at this point (<10)
    Convert CMYK image to RGB image

    Hi!

    I'm want to convert a CMYK image to a RGB image using VisualC++6.0 and CMM.

    The code looks like this:

    Input :
    inputPixels - a structure with the pixels from the image
    profile1 - char* the name for the CMYK file profile
    profile2 - char* the name for the RGB file profile

    Output :
    outputPixels- the output pixels


    HPROFILE inputProfile, outputProfile;
    HTRANSFORM transform;
    BOOL result;
    int nPixels = columns * rows;

    inputProfile = OpenColorProfileFromFile(profile1);
    outputProfile = OpenColorProfileFromFile(profile2);

    PHPROFILE pProf = (PHPROFILE)malloc(sizeof(HPROFILE)*2);
    pProf[0] = inputProfile;
    pProf[1] = outputProfile;

    PDWORD intent = (PDWORD)malloc(sizeof(DWORD));
    intent[0] = INTENT_SATURATION;
    transform = CreateMultiProfileTransform(pProf,2, intent,1, BEST_MODE, 2);
    if (transform == NULL)
    {
    ShowError(GetLastError());
    }

    outputPixels = (PixelStruct*)malloc(sizeof(PixelStruct)*nPixels);

    result = TranslateBitmapBits(transform, inputPixels, BM_KYMCQUADS, columns, rows, 0, outputPixels, BM_xBGRQUADS,0,NULL,0);

    if (!result)
    {
    ShowError(GetLastError());
    return NULL;
    }

    return outputPixels;
    }

    This code show the image, but not quite good.
    Those anyone know how to do that.

    P.S. Using the profile1 and profile2 files, in Photoshop the result image is correct.
    Reply With Quote
      #2    
    Old August 18th, 2004, 12:14 PM
    yiannakop's Avatar
    yiannakop yiannakop is offline
    Member +
     
    Join Date: Dec 2001
    Location: Greece, Athens
    Posts: 1,015
    yiannakop has a spectacular aura about (150+)yiannakop has a spectacular aura about (150+)
    My answer won't be code based, cause I don't know how to directly display a CMYK image. But I know that to convert an CMYK image to RGB values you just do the following


    CMY2RGB:
    --> RED = 1-C
    --> GREEN = 1-M
    --> BLUE = 1-Y ,


    since the RGB ans CMY color spaces are complements. Before doing that though, you have to convert CMYK to CMY by adding the "black" (K) value to the CMY values. The black value is the minimum of the other 3 values:


    CMYK2CMY
    Cyan = minimum(1,Cyan*(1-Black)+Black)
    Magenta = minimum(1,Magenta*(1-Black)+Black)
    Yellow = minimum(1,Yellow*(1-Black)+Black)


    Hope this helps.
    __________________
    Theodore
    Personal Web Page (some audio segmentation tools): www.di.uoa.gr/~tyiannak
    Reply With Quote
      #3    
    Old August 18th, 2004, 12:17 PM
    yiannakop's Avatar
    yiannakop yiannakop is offline
    Member +
     
    Join Date: Dec 2001
    Location: Greece, Athens
    Posts: 1,015
    yiannakop has a spectacular aura about (150+)yiannakop has a spectacular aura about (150+)
    I also have found the following link with a demo of such conversion:
    http://www.codeproject.com/tools/xcmyk.asp
    __________________
    Theodore
    Personal Web Page (some audio segmentation tools): www.di.uoa.gr/~tyiannak
    Reply With Quote
      #4    
    Old April 9th, 2009, 11:35 PM
    softmuthu84 softmuthu84 is offline
    Junior Member
     
    Join Date: Apr 2009
    Posts: 3
    softmuthu84 is an unknown quantity at this point (<10)
    Re: Convert CMYK image to RGB image

    Give rgb value
    r=
    g=
    b=
    double R, G, B;
    R = (double) r;
    G = (double) g;
    B = (double) b;

    R = 1.0 - (R / 255.0);
    G = 1.0 - (G / 255.0);
    B = 1.0 - (B / 255.0);

    double C, M, Y, K;
    if (R < G)
    K = R;
    else
    K = G;
    if (B < K)
    K = B;

    C = (R - K)/(1.0 - K);
    M = (G - K)/(1.0 - K);
    Y = (B - K)/(1.0 - K);

    C = (C * 100) + 0.5;
    M = (M * 100) + 0.5;
    Y = (Y * 100) + 0.5;
    K = (K * 100) + 0.5;
    Reply With Quote
      #5    
    Old November 3rd, 2009, 09:00 AM
    gratzielu gratzielu is offline
    Junior Member
     
    Join Date: Nov 2008
    Posts: 6
    gratzielu is an unknown quantity at this point (<10)
    Re: Convert CMYK image to RGB image

    No he wants to convert the image using ICC profiles color conversion. I have the same problem when I convert from CMYK to RGB. My code is similar to yours. The result is not what I expect. If you find the cause to the problem please post it.
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Graphics Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 01:25 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009