CMYK To RGB

This algorithm converts CMYK color model to RGB color model.



									Public Structure CMYK
	Private _c As Double
	Private _m As Double
	Private _y As Double
	Private _k As Double

	Public Sub New(c As Double, m As Double, y As Double, k As Double)
		Me._c = c
		Me._m = m
		Me._y = y
		Me._k = k
	End Sub

	Public Property C() As Double
		Get
			Return Me._c
		End Get
		Set(value As Double)
			Me._c = value
		End Set
	End Property

	Public Property M() As Double
		Get
			Return Me._m
		End Get
		Set(value As Double)
			Me._m = value
		End Set
	End Property

	Public Property Y() As Double
		Get
			Return Me._y
		End Get
		Set(value As Double)
			Me._y = value
		End Set
	End Property

	Public Property K() As Double
		Get
			Return Me._k
		End Get
		Set(value As Double)
			Me._k = value
		End Set
	End Property

	Public Overloads Function Equals(cmyk As CMYK) As Boolean
		Return (Me.C = cmyk.C) AndAlso (Me.M = cmyk.M) AndAlso (Me.Y = cmyk.Y) AndAlso (Me.K = cmyk.K)
	End Function
End Structure

Public Structure RGB
	Private _r As Byte
	Private _g As Byte
	Private _b As Byte

	Public Sub New(r As Byte, g As Byte, b As Byte)
		Me._r = r
		Me._g = g
		Me._b = b
	End Sub

	Public Property R() As Byte
		Get
			Return Me._r
		End Get
		Set(value As Byte)
			Me._r = value
		End Set
	End Property

	Public Property G() As Byte
		Get
			Return Me._g
		End Get
		Set(value As Byte)
			Me._g = value
		End Set
	End Property

	Public Property B() As Byte
		Get
			Return Me._b
		End Get
		Set(value As Byte)
			Me._b = value
		End Set
	End Property

	Public Overloads Function Equals(rgb As RGB) As Boolean
		Return (Me.R = rgb.R) AndAlso (Me.G = rgb.G) AndAlso (Me.B = rgb.B)
	End Function
End Structure

Public Shared Function CMYKToRGB(cmyk As CMYK) As RGB
	Dim r As Byte = CByte(Math.Truncate(255 * (1 - cmyk.C) * (1 - cmyk.K)))
	Dim g As Byte = CByte(Math.Truncate(255 * (1 - cmyk.M) * (1 - cmyk.K)))
	Dim b As Byte = CByte(Math.Truncate(255 * (1 - cmyk.Y) * (1 - cmyk.K)))

	Return New RGB(r, g, b)
End Function
								


Example

									Dim data As New CMYK(0.47, 1, 0.44, 0.39)
Dim value = CMYKToRGB(data)
								


Output

									R: 82
G: 0
B: 87