Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » [Proposal] RGB <-> CMYK conversion functions.
[Proposal] RGB <-> CMYK conversion functions. [message #53569] Mon, 13 April 2020 13:10 Go to next message
Oblivion is currently offline  Oblivion
Messages: 1092
Registered: August 2007
Senior Contributor
Hello,

U++ already has RGB <-> HSV conversion functions.

Below functions might be a handy addition to them, for people using color conversion a lot.

void CMYKtoRGB(double c, double m, double y, double k, double& r, double& g, double& b)
{
	k = clamp(k, 0.0, 1.0);
	r = (1 - c) * (1 - k);
	g = (1 - m) * (1 - k);
	b = (1 - y) * (1 - k);
}

void RGBtoCMYK(double r, double g, double b, double& c, double& m, double& y, double& k)
{
	k = 1 - max(max(r, g), b);
	c = (1 - r - k) / (1 - k);
	m = (1 - g - k) / (1 - k);
	y = (1 - b - k) / (1 - k);
}

Color CmykColorf(double c, double m, double y, double k)
{
	double r, g, b;
	CMYKtoRGB(c, m, y, k, r, g, b);
	return Color(min(int(r * 255), 255), min(int(g * 255), 255), min(int(b * 255), 255));
}

Color CmyColorf(double c, double m, double y)
{
	double r, g, b;
	CMYKtoRGB(c, m, y, 0.0, r, g, b);
	return Color(min(int(r * 255), 255), min(int(g * 255), 255), min(int(b * 255), 255));
}



Best regards,
Oblivion


Re: [Proposal] RGB <-> CMYK conversion functions. [message #53572 is a reply to message #53569] Mon, 13 April 2020 13:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Cool, added, without CmyColorf, using

Color CmykColorf(double c, double m, double y, double k = 0);

instead
Re: [Proposal] RGB <-> CMYK conversion functions. [message #53576 is a reply to message #53572] Mon, 13 April 2020 13:43 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1092
Registered: August 2007
Senior Contributor
Thanks!

Re: [Proposal] RGB <-> CMYK conversion functions. [message #53583 is a reply to message #53576] Mon, 13 April 2020 19:31 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hello,

As there is an RGBA type, a Color type : adding a CMYK would be quite logical with conversion methods available
What do you think ?
Re: [Proposal] RGB <-> CMYK conversion functions. [message #53590 is a reply to message #53583] Tue, 14 April 2020 10:20 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Didier wrote on Mon, 13 April 2020 19:31
Hello,

As there is an RGBA type, a Color type : adding a CMYK would be quite logical with conversion methods available
What do you think ?


I think I do not unnderstand what exactly do you mean Smile

Mirek
Re: [Proposal] RGB <-> CMYK conversion functions. [message #53620 is a reply to message #53590] Wed, 15 April 2020 21:20 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hello Mirek,

Well it would be nice to have:

Class Color {
   operator RGBA() const
   operator CMYK() const
}

class RGBA {
   operator Color() const
   operator CMYK() const
}

class CMYK {
   operator Color() const
   operator RGBA() const
}


So conversion from one to another is as simple as it can get
Re: [Proposal] RGB <-> CMYK conversion functions. [message #53622 is a reply to message #53620] Wed, 15 April 2020 22:31 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Didier wrote on Wed, 15 April 2020 21:20
Hello Mirek,

Well it would be nice to have:

Class Color {
   operator RGBA() const
   operator CMYK() const
}

class RGBA {
   operator Color() const
   operator CMYK() const
}

class CMYK {
   operator Color() const
   operator RGBA() const
}



There is no CMYK class. Conversions operators RGBA<->Color already exist.


Re: [Proposal] RGB <-> CMYK conversion functions. [message #53629 is a reply to message #53622] Thu, 16 April 2020 20:50 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Quote:
There is no CMYK class

That is exactly my point Smile

Quote:
Conversions operators RGBA<->Color already exist

So if we add a CMYK class, we can have conversion operators for all three color type classes : Colors, RGBA and CMYK
Re: [Proposal] RGB <-> CMYK conversion functions. [message #53632 is a reply to message #53629] Thu, 16 April 2020 22:52 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
What would be the point? I think current conversion functions for CMYK, CMY and HSV are enough, if your software is really using them so often, which I doubt, you can add CMYK class to your code with conversion operators/constructors..
Re: [Proposal] RGB <-> CMYK conversion functions. [message #53697 is a reply to message #53632] Wed, 22 April 2020 10:22 Go to previous message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Helle Mirek,

I don't use colors except for simple use cases (and don't know much abput their full usage neither)
My point was only a suggestion
Previous Topic: Patch for Algo.h
Next Topic: c++ 17 support
Goto Forum:
  


Current Time: Tue Apr 16 21:04:03 CEST 2024

Total time taken to generate the page: 0.01196 seconds