-
August 17th, 2004, 07:56 AM
#1
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.
-
August 18th, 2004, 11:14 AM
#2
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.
-
August 18th, 2004, 11:17 AM
#3
I also have found the following link with a demo of such conversion:
http://www.codeproject.com/tools/xcmyk.asp
-
April 9th, 2009, 10:35 PM
#4
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;
-
November 3rd, 2009, 09:00 AM
#5
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|