Example #1
0
def test_cmyk_to_rgb():
    """
    Test translation function cmyk_to_rgb
    """
    cmyk = cornell.CMYK(0.000, 0.000, 0.000, 0.000);
    rgb = a3.cmyk_to_rgb(cmyk);
    cornell.assert_equals(255, (rgb.red))
    cornell.assert_equals(255, (rgb.green))
    cornell.assert_equals(255, (rgb.blue))

    cmyk = cornell.CMYK(100.0, 100.0, 100.0, 0.000);
    rgb = a3.cmyk_to_rgb(cmyk);
    cornell.assert_equals(0, (rgb.red))
    cornell.assert_equals(0, (rgb.green))
    cornell.assert_equals(0, (rgb.blue))
    
    cmyk = cornell.CMYK(75.60, 99.99, 0.123, 2.000);
    rgb = a3.cmyk_to_rgb(cmyk);
    cornell.assert_equals(61, (rgb.red))
    cornell.assert_equals(0, (rgb.green))
    cornell.assert_equals(250, (rgb.blue))
    
    cmyk = cornell.CMYK(0.000, 0.000, 0.000, 100.0);
    rgb = a3.cmyk_to_rgb(cmyk);
    cornell.assert_equals(0, (rgb.red))
    cornell.assert_equals(0, (rgb.green))
    cornell.assert_equals(0, (rgb.blue))
Example #2
0
def test_str5_color():
    """
    Test the str5 functions for cmyk and hsv.
    """
    cornell.assert_equals('(98.45, 25.36, 72.80, 1.000)',
                          a3.str5_cmyk(cornell.CMYK(98.448, 25.362, 72.8, 1.0)))
    cornell.assert_equals('(1.000, 0.000, 100.0, 100.0)',
                          a3.str5_cmyk(cornell.CMYK(1, 0.0, 99.999999, 100)))
    cornell.assert_equals('(0.000, 0.000, 0.000)',
                          a3.str5_hsv(cornell.HSV(0, 0.0, 0)))
    cornell.assert_equals('(360.0, 1.000, 1.000)',
                          a3.str5_hsv(cornell.HSV(359.999, 1.0, 1)))
    cornell.assert_equals('(279.5, 1.000, 0.735)',
                          a3.str5_hsv(cornell.HSV(279.547, 1, 0.7346983)))
Example #3
0
def test_str5_color():
    """
    Test the str5 functions for cmyk and hsv.
    """
    cornell.assert_equals(
        '(98.45, 25.36, 72.80, 1.000)',
        a3.str5_cmyk(cornell.CMYK(98.448, 25.362, 72.8, 1.0)))
Example #4
0
def test_cmyk_to_rgb():
    """
    Test translation function cmyk_to_rgb
    """
    #Test 1
    cmyk = cornell.CMYK(0.000, 0.000, 0.000, 0.000)
    rgb = a3.cmyk_to_rgb(cmyk)
    cornell.assert_equals(255, rgb.red)
    cornell.assert_equals(255, rgb.green)
    cornell.assert_equals(255, rgb.blue)

    #Test 2
    cmyk = cornell.CMYK(29.00, 40.00, 32.00, 60.00)
    rgb = a3.cmyk_to_rgb(cmyk)
    cornell.assert_equals(72, rgb.red)
    cornell.assert_equals(61, rgb.green)
    cornell.assert_equals(69, rgb.blue)
Example #5
0
def test_str5_color():
    """
    Test the str5 functions for cmyk and hsv.
    """
    cornell.assert_equals(
        '(98.45, 25.36, 72.80, 1.000)',
        a3.str5_cmyk(cornell.CMYK(98.448, 25.362, 72.8, 1.0)))
    #cornell.assert_equals('(98.45, 25.36, 72.80, 1.000)',
    #                      a3.str5_cmyk(cornell.CMYK(98.448, 25.362, 72.8, 1.0)))
    cornell.assert_equals('(0.000, 0.314, 1.000)',
                          a3.str5_hsv(cornell.HSV(0.0, 0.313725490196, 1.0)))
    cornell.assert_equals('(0.500, 0.666, 1.000)',
                          a3.str5_hsv(cornell.HSV(0.5, 0.666352839474, 1)))
Example #6
0
    def on_cmyk_press(self, c, m, y, k):
        """
        Callback to cmyk button
        """
        self.cmyk = cornell.CMYK(c, m, y, k)
        temp = a3.cmyk_to_rgb(self.cmyk)
        assert (temp == None or type(temp) == cornell.RGB), \
                'cmyk_to_rgb does not return a RGB object'

        self.rgb = self.rgb if temp is None else temp
        self.hsv = a3.rgb_to_hsv(self.rgb)
        assert (self.hsv == None or type(self.hsv) == cornell.HSV), \
                'rgb_to_hsv does not return a HSV object'
        self.update()
Example #7
0
def rgb_to_cmyk(rgb):
    """
    Returns: color rgb in space CMYK, with the most black possible.
    
    Formulae from en.wikipedia.org/wiki/CMYK_color_model.
    
    Parameter rgb: the color to convert to a CMYK object
    Precondition: rgb is an RGB object
    """
    
    r_new = rgb.red/255.0
    g_new = rgb.green/255.0
    b_new = rgb.blue/255.0
    
    c_new = 1 - r_new
    m_new = 1 - g_new
    y_new = 1 - b_new
    
    if c_new == 1 and m_new == 1 and y_new == 1:
        c_final = 0
        m_final = 0
        y_final = 0
        k_final = 1
        
        c_final_final = c_final *100.0
        m_final_final = m_final *100.0
        y_final_final = y_final *100.0
        k_final_final = k_final *100.0
        
        
    else:
        k_final = min(c_new, m_new, y_new)
        c_final = (c_new - k_final)/(1 - k_final)
        m_final = (m_new - k_final)/(1 - k_final)
        y_final = (y_new - k_final)/(1 - k_final)
        
        c_final_final = c_final * 100.0
        m_final_final = m_final * 100.0
        y_final_final = y_final * 100.0
        k_final_final = k_final * 100.0
        
    
    return cornell.CMYK(c_final_final, m_final_final, y_final_final, \
                        k_final_final)
Example #8
0
    def on_cmyk_slide(self, c, m, y, k):
        """
        Callback to cmyk sliders
        """
        if not self.active:
            return
        cyan = c / 100.0
        magenta = m / 100.0
        yellow = y / 100.0
        black = k / 100.0
        self.cmyk = cornell.CMYK(cyan, magenta, yellow, black)
        temp = a3.cmyk_to_rgb(self.cmyk)
        assert (temp == None or type(temp) == cornell.RGB),\
                'cmyk_to_rgb does not return a RGB object'

        self.rgb = self.rgb if temp is None else temp
        self.hsv = a3.rgb_to_hsv(self.rgb)
        assert (self.hsv == None or type(self.hsv) == cornell.HSV), \
                'rgb_to_hsv does not return a HSV object'
        self.update()
Example #9
0
def rgb_to_cmyk(rgb):
    """
    Returns: color rgb in space CMYK, with the most black possible.

    Formulae from en.wikipedia.org/wiki/CMYK_color_model.

    Parameter rgb: the color to convert to a CMYK object
    Precondition: rgb is an RGB object
    """
    # The RGB numbers are in the range 0..255.
    # Change the RGB numbers to the range 0..1 by dividing them by 255.0.

    #Initial Varibles
    red = rgb.red
    green = rgb.green
    blue = rgb.blue

    red_1 = red / 255.0
    green_1 = green / 255.0
    blue_1 = blue / 255.0

    C_1 = 1 - red_1
    M_1 = 1 - green_1
    Y_1 = 1 - blue_1
    K_1 = 0

    #Determing K value
    if (C_1 == 1 and M_1 == 1 and Y_1 == 1):
        K_1 = 1

    if (C_1 <= M_1 and C_1 <= Y_1):
        K_1 = C_1

    if (M_1 <= C_1 and M_1 <= Y_1):
        K_1 = M_1

    if (Y_1 <= M_1 and Y_1 <= C_1):
        K_1 = Y_1

    #Changing CMY values based on new K
    if (K_1 == 1):
        C_1 = 0
        M_1 = 0
        Y_1 = 0

    if (K_1 != 1):
        C_2 = (C_1 - K_1) / (1 - K_1)
        M_2 = (M_1 - K_1) / (1 - K_1)
        Y_2 = (Y_1 - K_1) / (1 - K_1)

    #Converting CMYK values to proper range
    if (K_1 == 1):
        C_3 = C_1 * 100
        M_3 = M_1 * 100
        Y_3 = Y_1 * 100
        K_3 = K_1 * 100

    if (K_1 != 1):
        C_3 = C_2 * 100
        M_3 = M_2 * 100
        Y_3 = Y_2 * 100
        K_3 = K_1 * 100

    #Return CMYK Object
    return cornell.CMYK(C_3, M_3, Y_3, K_3)