Python colorsys.yiq_to_rgb() Examples

The following are 10 code examples of colorsys.yiq_to_rgb(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module colorsys , or try the search function .
Example #1
Source File: test_colorsys.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def test_yiq_values(self):
        values = [
            # rgb, yiq
            ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), # black
            ((0.0, 0.0, 1.0), (0.11, -0.3217, 0.3121)), # blue
            ((0.0, 1.0, 0.0), (0.59, -0.2773, -0.5251)), # green
            ((0.0, 1.0, 1.0), (0.7, -0.599, -0.213)), # cyan
            ((1.0, 0.0, 0.0), (0.3, 0.599, 0.213)), # red
            ((1.0, 0.0, 1.0), (0.41, 0.2773, 0.5251)), # purple
            ((1.0, 1.0, 0.0), (0.89, 0.3217, -0.3121)), # yellow
            ((1.0, 1.0, 1.0), (1.0, 0.0, 0.0)), # white
            ((0.5, 0.5, 0.5), (0.5, 0.0, 0.0)), # grey
        ]
        for (rgb, yiq) in values:
            self.assertTripleEqual(yiq, colorsys.rgb_to_yiq(*rgb))
            self.assertTripleEqual(rgb, colorsys.yiq_to_rgb(*yiq)) 
Example #2
Source File: test_colorsys.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
def test_yiq_values(self):
        values = [
            # rgb, yiq
            ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), # black
            ((0.0, 0.0, 1.0), (0.11, -0.3217, 0.3121)), # blue
            ((0.0, 1.0, 0.0), (0.59, -0.2773, -0.5251)), # green
            ((0.0, 1.0, 1.0), (0.7, -0.599, -0.213)), # cyan
            ((1.0, 0.0, 0.0), (0.3, 0.599, 0.213)), # red
            ((1.0, 0.0, 1.0), (0.41, 0.2773, 0.5251)), # purple
            ((1.0, 1.0, 0.0), (0.89, 0.3217, -0.3121)), # yellow
            ((1.0, 1.0, 1.0), (1.0, 0.0, 0.0)), # white
            ((0.5, 0.5, 0.5), (0.5, 0.0, 0.0)), # grey
        ]
        for (rgb, yiq) in values:
            self.assertTripleEqual(yiq, colorsys.rgb_to_yiq(*rgb))
            self.assertTripleEqual(rgb, colorsys.yiq_to_rgb(*yiq)) 
Example #3
Source File: test_colorsys.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
def test_yiq_values(self):
        values = [
            # rgb, yiq
            ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)), # black
            ((0.0, 0.0, 1.0), (0.11, -0.3217, 0.3121)), # blue
            ((0.0, 1.0, 0.0), (0.59, -0.2773, -0.5251)), # green
            ((0.0, 1.0, 1.0), (0.7, -0.599, -0.213)), # cyan
            ((1.0, 0.0, 0.0), (0.3, 0.599, 0.213)), # red
            ((1.0, 0.0, 1.0), (0.41, 0.2773, 0.5251)), # purple
            ((1.0, 1.0, 0.0), (0.89, 0.3217, -0.3121)), # yellow
            ((1.0, 1.0, 1.0), (1.0, 0.0, 0.0)), # white
            ((0.5, 0.5, 0.5), (0.5, 0.0, 0.0)), # grey
        ]
        for (rgb, yiq) in values:
            self.assertTripleEqual(yiq, colorsys.rgb_to_yiq(*rgb))
            self.assertTripleEqual(rgb, colorsys.yiq_to_rgb(*yiq)) 
Example #4
Source File: colors.py    From rekall with GNU General Public License v2.0 5 votes vote down vote up
def YIQToRGB(y, i, q):
    red, green, blue = colorsys.yiq_to_rgb(y, i, q)
    return int(red * 0xff), int(green * 0xff), int(blue * 0xff)


# Text-color heuristics: 
Example #5
Source File: test_colorsys.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_yiq_roundtrip(self):
        for r in frange(0.0, 1.0, 0.2):
            for g in frange(0.0, 1.0, 0.2):
                for b in frange(0.0, 1.0, 0.2):
                    rgb = (r, g, b)
                    self.assertTripleEqual(
                        rgb,
                        colorsys.yiq_to_rgb(*colorsys.rgb_to_yiq(*rgb))
                    ) 
Example #6
Source File: uistuff.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def genColor(n, startpoint=0):
    assert n >= 1
    # This splits the 0 - 1 segment in the pizza way
    hue = (2 * n - 1) / (2.**(n - 1).bit_length()) - 1
    hue = (hue + startpoint) % 1
    # We set saturation based on the amount of green, scaled to the interval
    # [0.6..0.8]. This ensures a consistent lightness over all colors.
    rgb = colorsys.hsv_to_rgb(hue, 1, 1)
    rgb = colorsys.hsv_to_rgb(hue, 1, (1 - rgb[1]) * 0.2 + 0.6)
    # This algorithm ought to balance colors more precisely, but it overrates
    # the lightness of yellow, and nearly makes it black
    # yiq = colorsys.rgb_to_yiq(*rgb)
    # rgb = colorsys.yiq_to_rgb(.125, yiq[1], yiq[2])
    return rgb 
Example #7
Source File: test_colorsys.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_yiq_roundtrip(self):
        for r in frange(0.0, 1.0, 0.2):
            for g in frange(0.0, 1.0, 0.2):
                for b in frange(0.0, 1.0, 0.2):
                    rgb = (r, g, b)
                    self.assertTripleEqual(
                        rgb,
                        colorsys.yiq_to_rgb(*colorsys.rgb_to_yiq(*rgb))
                    ) 
Example #8
Source File: test_colorsys.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_yiq_roundtrip(self):
        for r in frange(0.0, 1.0, 0.2):
            for g in frange(0.0, 1.0, 0.2):
                for b in frange(0.0, 1.0, 0.2):
                    rgb = (r, g, b)
                    self.assertTripleEqual(
                        rgb,
                        colorsys.yiq_to_rgb(*colorsys.rgb_to_yiq(*rgb))
                    ) 
Example #9
Source File: cdr_utils.py    From uniconvertor with GNU Affero General Public License v3.0 5 votes vote down vote up
def parse_yiq(data):
    """
    Parses YIQ color bytes and returns fill style list.
    """
    y = ord(data[0]) / 255.0
    i = 2.0 * ord(data[1]) / 255.0 - 1.0
    q = 2.0 * ord(data[2]) / 255.0 - 1.0
    r, g, b = yiq_to_rgb(y, i, q)
    return [uc2const.COLOR_RGB, [r, g, b], 1.0, ''] 
Example #10
Source File: cmx_to_sk2.py    From uniconvertor with GNU Affero General Public License v3.0 4 votes vote down vote up
def set_v1_colors(self):
        rclr = self.cmx_model.chunk_map[cmx_const.RCLR_ID]
        colors = rclr.data['colors']
        for model, _pal, vals in colors:
            model = cmx_const.COLOR_MODEL_MAP.get(model, cmx_const.CMX_INVALID)
            clr = sk2const.CMYK_BLACK
            if model == cmx_const.CMX_CMYK:
                vals = cms.val_100_to_dec(vals)
                clr = [uc2const.COLOR_CMYK, vals, 1.0, '']
            elif model == cmx_const.CMX_CMYK255:
                vals = cms.val_255_to_dec(vals)
                clr = [uc2const.COLOR_CMYK, vals, 1.0, '']
            elif model == cmx_const.CMX_CMY:
                vals = cms.val_255_to_dec(vals) + (0.0,)
                clr = [uc2const.COLOR_CMYK, vals, 1.0, '']
            elif model == cmx_const.CMX_RGB:
                vals = cms.val_255_to_dec(vals)
                clr = [uc2const.COLOR_RGB, vals, 1.0, '']
            elif model == cmx_const.CMX_HSB:
                first = vals[0] * 255 + vals[1] \
                    if self.rifx else vals[0] + vals[1] * 255
                vals = (first / 360.0, vals[2] / 255.0, vals[3] / 255.0)
                r, g, b = colorsys.hsv_to_rgb(*vals)
                clr = [uc2const.COLOR_RGB, [r, g, b], 1.0, '']
            elif model == cmx_const.CMX_HLS:
                first = vals[0] * 255 + vals[1] \
                    if self.rifx else vals[0] + vals[1] * 255
                vals = (first / 360.0, vals[2] / 255.0, vals[3] / 255.0)
                r, g, b = colorsys.hls_to_rgb(*vals)
                clr = [uc2const.COLOR_RGB, [r, g, b], 1.0, '']
            elif model == cmx_const.CMX_BW:
                vals = [1.0, 1.0, 1.0] if vals[0] else [0.0, 0.0, 0.0]
                clr = [uc2const.COLOR_RGB, vals, 1.0, '']
            elif model == cmx_const.CMX_GRAY:
                clr = [uc2const.COLOR_GRAY, [vals[0] / 255.0, ], 1.0, '']
            elif model == cmx_const.CMX_YIQ255:
                y = vals[0] / 255.0
                i = 2.0 * vals[1] / 255.0 - 1.0
                q = 2.0 * vals[2] / 255.0 - 1.0
                r, g, b = colorsys.yiq_to_rgb(y, i, q)
                clr = [uc2const.COLOR_RGB, [r, g, b], 1.0, '']
            elif model == cmx_const.CMX_LAB:
                vals = cms.val_255_to_dec(vals)
                clr = [uc2const.COLOR_LAB, vals, 1.0, '']

            self._colors.append(clr)