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.
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;
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.