RGB image to CMYK gdi+
-
Hello, I am trying to adjust the color balance (CYMK) of an image like this is in photoshop or some other applications. From examples, i tried changing the current RGB to CMYK (for each pixel) using the below code.
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
tmpbmp->GetPixel(i, j, &clr);R = clr.GetR(); G = clr.GetG(); B = clr.GetB(); c = \_cyanclr / 255.0; // \_cyanclr - user input in % m = \_magentaclr / 255.0; y = \_yellowclr / 255.0; k = \_blackclr / 255.0; rr = c \* (1.0 - k) + k; gg = m \* (1.0 - k) + k; bb = y \* (1.0 - k) + k; rr = (1.0 - rr) \* 255.0 + 0.5; gg = (1.0 - gg) \* 255.0 + 0.5; bb = (1.0 - bb) \* 255.0 + 0.5; // here i dont know how to adjust new RGB with old one R += rr; G += gg; B += bb; R = R < 0 ? 0 : (R > 255) ? 255 : R; G = G < 0 ? 0 : (G > 255) ? 255 : G; B = B < 0 ? 0 : (B > 255) ? 255 : B; output->SetPixel(i, j, Gdiplus::Color(R, G, B)); } }
With this code, i am not getting the same result like in photoshop and other applications. I am not sure whether I am doing in right method or not. Please suggest. I am using C++ and gdi+. Regards, Gopinath.
-
Hello, I am trying to adjust the color balance (CYMK) of an image like this is in photoshop or some other applications. From examples, i tried changing the current RGB to CMYK (for each pixel) using the below code.
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
tmpbmp->GetPixel(i, j, &clr);R = clr.GetR(); G = clr.GetG(); B = clr.GetB(); c = \_cyanclr / 255.0; // \_cyanclr - user input in % m = \_magentaclr / 255.0; y = \_yellowclr / 255.0; k = \_blackclr / 255.0; rr = c \* (1.0 - k) + k; gg = m \* (1.0 - k) + k; bb = y \* (1.0 - k) + k; rr = (1.0 - rr) \* 255.0 + 0.5; gg = (1.0 - gg) \* 255.0 + 0.5; bb = (1.0 - bb) \* 255.0 + 0.5; // here i dont know how to adjust new RGB with old one R += rr; G += gg; B += bb; R = R < 0 ? 0 : (R > 255) ? 255 : R; G = G < 0 ? 0 : (G > 255) ? 255 : G; B = B < 0 ? 0 : (B > 255) ? 255 : B; output->SetPixel(i, j, Gdiplus::Color(R, G, B)); } }
With this code, i am not getting the same result like in photoshop and other applications. I am not sure whether I am doing in right method or not. Please suggest. I am using C++ and gdi+. Regards, Gopinath.
-
Hello, I am trying to adjust the color balance (CYMK) of an image like this is in photoshop or some other applications. From examples, i tried changing the current RGB to CMYK (for each pixel) using the below code.
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
tmpbmp->GetPixel(i, j, &clr);R = clr.GetR(); G = clr.GetG(); B = clr.GetB(); c = \_cyanclr / 255.0; // \_cyanclr - user input in % m = \_magentaclr / 255.0; y = \_yellowclr / 255.0; k = \_blackclr / 255.0; rr = c \* (1.0 - k) + k; gg = m \* (1.0 - k) + k; bb = y \* (1.0 - k) + k; rr = (1.0 - rr) \* 255.0 + 0.5; gg = (1.0 - gg) \* 255.0 + 0.5; bb = (1.0 - bb) \* 255.0 + 0.5; // here i dont know how to adjust new RGB with old one R += rr; G += gg; B += bb; R = R < 0 ? 0 : (R > 255) ? 255 : R; G = G < 0 ? 0 : (G > 255) ? 255 : G; B = B < 0 ? 0 : (B > 255) ? 255 : B; output->SetPixel(i, j, Gdiplus::Color(R, G, B)); } }
With this code, i am not getting the same result like in photoshop and other applications. I am not sure whether I am doing in right method or not. Please suggest. I am using C++ and gdi+. Regards, Gopinath.