CMYK to RGB Color

Here given code implementation process.

// C program 
// CMYK to RGB Color
#include <stdio.h>

#include <math.h>

// Convert CMYK to RGB
void cmyk_to_rgb(int c, int m, int y, int k)
{
	if (c < 0 || m < 0 || y < 0 || k < 0)
	{
		// Invalid parameter
		return;
	}
	printf("\n Given CMYK");
	printf("\n C = %d ", c);
	printf("\n M = %d ", m);
	printf("\n Y = %d ", y);
	printf("\n K = %d \n", k);
	double c1 = c / 100.0;
	double m1 = m / 100.0;
	double y1 = y / 100.0;
	double k1 = k / 100.0;
	int r = round((1 - c1) *(1 - k1) *255);
	int g = round((1 - m1) *(1 - k1) *255);
	int b = round((1 - y1) *(1 - k1) *255);
	// Display Calculate results
	printf("\n Calculate RGB");
	printf("\n R = %d ", r);
	printf("\n G = %d ", g);
	printf("\n B = %d ", b);
}
int main()
{
	// Test Case
	cmyk_to_rgb(71, 48, 60, 35);
	cmyk_to_rgb(24, 66, 32, 42);
	return 0;
}

Output

 Given CMYK
 C = 71
 M = 48
 Y = 60
 K = 35

 Calculate RGB
 R = 48
 G = 86
 B = 66
 Given CMYK
 C = 24
 M = 66
 Y = 32
 K = 42

 Calculate RGB
 R = 112
 G = 50
 B = 101
/*
  Java Program
  CMYK to RGB color
*/
public class ColorConversion
{
	// Convert CMYK to RGB
	public void cmyk_to_rgb(int c, int m, int y, int k)
	{
		if (c < 0 || m < 0 || y < 0 || k < 0)
		{
			return;
		}
		System.out.print("\n Given CMYK");
		System.out.print("\n C = " + c);
		System.out.print("\n M = " + m);
		System.out.print("\n Y = " + y);
		System.out.print("\n K = " + k + " \n");
		double c1 = c / 100.0;
		double m1 = m / 100.0;
		double y1 = y / 100.0;
		double k1 = k / 100.0;
		int r = (int) Math.round((1 - c1) * (1 - k1) * 255);
		int g = (int) Math.round((1 - m1) * (1 - k1) * 255);
		int b = (int) Math.round((1 - y1) * (1 - k1) * 255);
		// Display Calculate results
		System.out.print("\n Calculate RGB");
		System.out.print("\n R = " + r);
		System.out.print("\n G = " + g);
		System.out.print("\n B = " + b);
	}
	public static void main(String[] args)
	{
		ColorConversion color = new ColorConversion();
		// Test Case
		color.cmyk_to_rgb(71, 48, 60, 35);
		color.cmyk_to_rgb(24, 66, 32, 42);
	}
}

Output

 Given CMYK
 C = 71
 M = 48
 Y = 60
 K = 35

 Calculate RGB
 R = 48
 G = 86
 B = 66
 Given CMYK
 C = 24
 M = 66
 Y = 32
 K = 42

 Calculate RGB
 R = 112
 G = 50
 B = 101
// Include header file
#include <iostream>
#include <math.h>

using namespace std;
/*
  C++ Program
  CMYK to RGB color
*/
class ColorConversion
{
	public:
		// Convert CMYK to RGB
		void cmyk_to_rgb(int c, int m, int y, int k)
		{
			if (c < 0 || m < 0 || y < 0 || k < 0)
			{
				return;
			}
			cout << "\n Given CMYK";
			cout << "\n C = " << c;
			cout << "\n M = " << m;
			cout << "\n Y = " << y;
			cout << "\n K = " << k << " \n";
			double c1 = c / 100.0;
			double m1 = m / 100.0;
			double y1 = y / 100.0;
			double k1 = k / 100.0;
			int r = (int) round((1 - c1) * (1 - k1) *255);
			int g = (int) round((1 - m1) * (1 - k1) *255);
			int b = (int) round((1 - y1) * (1 - k1) *255);
			// Display Calculate results
			cout << "\n Calculate RGB";
			cout << "\n R = " << r;
			cout << "\n G = " << g;
			cout << "\n B = " << b;
		}
};
int main()
{
	ColorConversion color = ColorConversion();
	// Test Case
	color.cmyk_to_rgb(71, 48, 60, 35);
	color.cmyk_to_rgb(24, 66, 32, 42);
	return 0;
}

Output

 Given CMYK
 C = 71
 M = 48
 Y = 60
 K = 35

 Calculate RGB
 R = 48
 G = 86
 B = 66
 Given CMYK
 C = 24
 M = 66
 Y = 32
 K = 42

 Calculate RGB
 R = 112
 G = 50
 B = 101
// Include namespace system
using System;
/*
  C# Program
  CMYK to RGB color
*/
public class ColorConversion
{
	// Convert CMYK to RGB
	public void cmyk_to_rgb(int c, int m, int y, int k)
	{
		if (c < 0 || m < 0 || y < 0 || k < 0)
		{
			return;
		}
		Console.Write("\n Given CMYK");
		Console.Write("\n C = " + c);
		Console.Write("\n M = " + m);
		Console.Write("\n Y = " + y);
		Console.Write("\n K = " + k + " \n");
		double c1 = c / 100.0;
		double m1 = m / 100.0;
		double y1 = y / 100.0;
		double k1 = k / 100.0;
		int r = (int) Math.Round((1 - c1) * (1 - k1) * 255);
		int g = (int) Math.Round((1 - m1) * (1 - k1) * 255);
		int b = (int) Math.Round((1 - y1) * (1 - k1) * 255);
		// Display Calculate results
		Console.Write("\n Calculate RGB");
		Console.Write("\n R = " + r);
		Console.Write("\n G = " + g);
		Console.Write("\n B = " + b);
	}
	public static void Main(String[] args)
	{
		ColorConversion color = new ColorConversion();
		// Test Case
		color.cmyk_to_rgb(71, 48, 60, 35);
		color.cmyk_to_rgb(24, 66, 32, 42);
	}
}

Output

 Given CMYK
 C = 71
 M = 48
 Y = 60
 K = 35

 Calculate RGB
 R = 48
 G = 86
 B = 66
 Given CMYK
 C = 24
 M = 66
 Y = 32
 K = 42

 Calculate RGB
 R = 112
 G = 50
 B = 101
<?php
/*
  Php Program
  CMYK to RGB color
*/
class ColorConversion
{
	// Convert CMYK to RGB
	public	function cmyk_to_rgb($c, $m, $y, $k)
	{
		if ($c < 0 || $m < 0 || $y < 0 || $k < 0)
		{
			return;
		}
		echo "\n Given CMYK";
		echo "\n C = ". $c;
		echo "\n M = ". $m;
		echo "\n Y = ". $y;
		echo "\n K = ". $k ." \n";
		$c1 = ($c / 100.0);
		$m1 = ($m / 100.0);
		$y1 = ($y / 100.0);
		$k1 = ($k / 100.0);
		$r =  round((1 - $c1) * (1 - $k1) * 255);
		$g =  round((1 - $m1) * (1 - $k1) * 255);
		$b =  round((1 - $y1) * (1 - $k1) * 255);
		// Display Calculate results
		echo ord("\n Calculate RGB");
		echo "\n R = ". $r;
		echo "\n G = ". $g;
		echo "\n B = ". $b;
	}
}

function main()
{
	$color = new ColorConversion();
	// Test Case
	$color->cmyk_to_rgb(71, 48, 60, 35);
	$color->cmyk_to_rgb(24, 66, 32, 42);
}
main();

Output

 Given CMYK
 C = 71
 M = 48
 Y = 60
 K = 35
10
 R = 48
 G = 86
 B = 66
 Given CMYK
 C = 24
 M = 66
 Y = 32
 K = 42
10
 R = 112
 G = 50
 B = 101
/*
  Node Js Program
  CMYK to RGB color
*/
class ColorConversion
{
	// Convert CMYK to RGB
	cmyk_to_rgb(c, m, y, k)
	{
		if (c < 0 || m < 0 || y < 0 || k < 0)
		{
			return;
		}
		process.stdout.write("\n Given CMYK");
		process.stdout.write("\n C = " + c);
		process.stdout.write("\n M = " + m);
		process.stdout.write("\n Y = " + y);
		process.stdout.write("\n K = " + k + " \n");
		var c1 = (c / 100.0);
		var m1 = (m / 100.0);
		var y1 = (y / 100.0);
		var k1 = (k / 100.0);
		var r = parseInt(Math.round((1 - c1) * (1 - k1) * 255));
		var g = parseInt(Math.round((1 - m1) * (1 - k1) * 255));
		var b = parseInt(Math.round((1 - y1) * (1 - k1) * 255));
		// Display Calculate results
		process.stdout.write("\n Calculate RGB");
		process.stdout.write("\n R = " + r);
		process.stdout.write("\n G = " + g);
		process.stdout.write("\n B = " + b);
	}
}

function main()
{
	var color = new ColorConversion();
	// Test Case
	color.cmyk_to_rgb(71, 48, 60, 35);
	color.cmyk_to_rgb(24, 66, 32, 42);
}
main();

Output

 Given CMYK
 C = 71
 M = 48
 Y = 60
 K = 35

 Calculate RGB
 R = 48
 G = 86
 B = 66
 Given CMYK
 C = 24
 M = 66
 Y = 32
 K = 42

 Calculate RGB
 R = 112
 G = 50
 B = 101
#   Python 3 Program
#   CMYK to RGB color

class ColorConversion :
	#  Convert CMYK to RGB
	def cmyk_to_rgb(self, c, m, y, k) :
		if (c < 0 or m < 0 or y < 0 or k < 0) :
			return
		
		print(" Given CMYK\n", end = "")
		print(" C = ", c )
		print(" M = ", m )
		print(" Y = ", y )
		print(" K = ", k ," \n")
		c1 = (c / 100.0)
		m1 = (m / 100.0)
		y1 = (y / 100.0)
		k1 = (k / 100.0)
		r = int(round((1 - c1) * (1 - k1) * 255))
		g = int(round((1 - m1) * (1 - k1) * 255))
		b = int(round((1 - y1) * (1 - k1) * 255))
		#  Display Calculate results
		print(" Calculate RGB")
		print(" R = ", r )
		print(" G = ", g )
		print(" B = ", b,"\n" )
	

def main() :
	color = ColorConversion()
	#  Test Case
	color.cmyk_to_rgb(71, 48, 60, 35)
	color.cmyk_to_rgb(24, 66, 32, 42)

if __name__ == "__main__": main()

Output

 Given CMYK
 C =  71
 M =  48
 Y =  60
 K =  35

 Calculate RGB
 R =  48
 G =  86
 B =  66

 Given CMYK
 C =  24
 M =  66
 Y =  32
 K =  42

 Calculate RGB
 R =  112
 G =  50
 B =  101
#   Ruby Program
#   CMYK to RGB color

class ColorConversion 
    #  Convert CMYK to RGB
    def cmyk_to_rgb(c, m, y, k) 
        if (c < 0 || m < 0 || y < 0 || k < 0) 
            return
        end

        print("Given CMYK\n")
        print(" C = ", c ,"\n")
        print(" M = ", m ,"\n")
        print(" Y = ", y ,"\n")
        print(" K = ", k ," \n\n")
        c1 = c / 100.0
        m1 = m / 100.0
        y1 = y / 100.0
        k1 = k / 100.0
        r = (((1 - c1) * (1 - k1) * 255).round).to_i
        g = (((1 - m1) * (1 - k1) * 255).round).to_i
        b = (((1 - y1) * (1 - k1) * 255).round).to_i
        #  Display Calculate results
        print(" Calculate RGB\n")
        print(" R = ", r ,"\n")
        print(" G = ", g ,"\n")
        print(" B = ", b ,"\n\n")
    end

end

def main() 
    color = ColorConversion.new()
    #  Test Case
    color.cmyk_to_rgb(71, 48, 60, 35)
    color.cmyk_to_rgb(24, 66, 32, 42)
end

main()

Output

Given CMYK
 C = 71
 M = 48
 Y = 60
 K = 35 

 Calculate RGB
 R = 48
 G = 86
 B = 66

Given CMYK
 C = 24
 M = 66
 Y = 32
 K = 42 

 Calculate RGB
 R = 112
 G = 50
 B = 101

/*
  Scala Program
  CMYK to RGB color
*/
class ColorConversion
{
	// Convert CMYK to RGB
	def cmyk_to_rgb(c: Int, m: Int, y: Int, k: Int): Unit = {
		if (c < 0 || m < 0 || y < 0 || k < 0)
		{
			return;
		}
		print("Given CMYK\n");
		print(" C = " + c + "\n");
		print(" M = " + m + "\n");
		print(" Y = " + y + "\n");
		print(" K = " + k + " \n\n");
		var c1: Double = (c / 100.0);
		var m1: Double = (m / 100.0);
		var y1: Double = (y / 100.0);
		var k1: Double = (k / 100.0);
		var r: Int = (Math.round((1 - c1) * (1 - k1) * 255)).toInt;
		var g: Int = (Math.round((1 - m1) * (1 - k1) * 255)).toInt;
		var b: Int = (Math.round((1 - y1) * (1 - k1) * 255)).toInt;
		// Display Calculate results
		print(" Calculate RGB\n");
		print(" R = " + r + "\n");
		print(" G = " + g + "\n");
		print(" B = " + b + "\n\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var color: ColorConversion = new ColorConversion();
		// Test Case
		color.cmyk_to_rgb(71, 48, 60, 35);
		color.cmyk_to_rgb(24, 66, 32, 42);
	}
}

Output

Given CMYK
 C = 71
 M = 48
 Y = 60
 K = 35

 Calculate RGB
 R = 48
 G = 86
 B = 66

Given CMYK
 C = 24
 M = 66
 Y = 32
 K = 42

 Calculate RGB
 R = 112
 G = 50
 B = 101
import Foundation
/*
  Swift 4 Program
  CMYK to RGB color
*/
class ColorConversion
{
	// Convert CMYK to RGB
	func cmyk_to_rgb(_ c: Int, _ m: Int, _ y: Int, _ k: Int)
	{
		if (c < 0 || m < 0 || y < 0 || k < 0)
		{
			return;
		}
		print("Given CMYK");
		print(" C = ", c);
		print(" M = ", m);
		print(" Y = ", y);
		print(" K = ", k, " \n");
		let c1: Double = Double(c) / 100.0;
		let m1: Double = Double(m) / 100.0;
		let y1: Double = Double(y) / 100.0;
		let k1: Double = Double(k) / 100.0;
		let r: Int = Int(round((1 - c1) * (1 - k1) * 255));
		let g: Int = Int(round((1 - m1) * (1 - k1) * 255));
		let b: Int = Int(round((1 - y1) * (1 - k1) * 255));
		// Display Calculate results
		print(" Calculate RGB");
		print(" R = ", r);
		print(" G = ", g);
		print(" B = ", b, "\n");
	}
}
func main()
{
	let color: ColorConversion = ColorConversion();
	// Test Case
	color.cmyk_to_rgb(71, 48, 60, 35);
	color.cmyk_to_rgb(24, 66, 32, 42);
}
main();

Output

Given CMYK
 C =  71
 M =  48
 Y =  60
 K =  35

 Calculate RGB
 R =  48
 G =  86
 B =  66

Given CMYK
 C =  24
 M =  66
 Y =  32
 K =  42

 Calculate RGB
 R =  112
 G =  50
 B =  101
/*
  Kotlin Program
  CMYK to RGB color
*/
class ColorConversion
{
	// Convert CMYK to RGB
	fun cmyk_to_rgb(c: Int, m: Int, y: Int, k: Int): Unit
	{
		if (c<0 || m<0 || y<0 || k<0)
		{
			return;
		}
		print("Given CMYK\n");
		print(" C = " + c + "\n");
		print(" M = " + m + "\n");
		print(" Y = " + y + "\n");
		print(" K = " + k + " \n\n");
		var c1: Double = c / 100.0;
		var m1: Double = m / 100.0;
		var y1: Double = y / 100.0;
		var k1: Double = k / 100.0;
		var r: Int =  Math.round((1 - c1) * (1 - k1) * 255).toInt();
		var g: Int =  Math.round((1 - m1) * (1 - k1) * 255).toInt();
		var b: Int =  Math.round((1 - y1) * (1 - k1) * 255).toInt();
		// Display Calculate results
		print(" Calculate RGB\n");
		print(" R = " + r + "\n");
		print(" G = " + g + "\n");
		print(" B = " + b + "\n\n");
	}
}
fun main(args: Array<String>): Unit
{
	var color: ColorConversion = ColorConversion();
	// Test Case
	color.cmyk_to_rgb(71, 48, 60, 35);
	color.cmyk_to_rgb(24, 66, 32, 42);
}

Output

Given CMYK
 C = 71
 M = 48
 Y = 60
 K = 35

 Calculate RGB
 R = 48
 G = 86
 B = 66

Given CMYK
 C = 24
 M = 66
 Y = 32
 K = 42

 Calculate RGB
 R = 112
 G = 50
 B = 101


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved