コード例 #1
0
ファイル: husl_test.py プロジェクト: bjoernenders/husl-python
    def test_snapshot(self):
        for hex_color, colors in self.snapshot.items():

            # Test forward functions
            test_rgb = husl.hex_to_rgb(hex_color)
            self.assertTuplesClose(test_rgb, colors['rgb'])
            test_xyz = husl.rgb_to_xyz(test_rgb)
            self.assertTuplesClose(test_xyz, colors['xyz'])
            test_luv = husl.xyz_to_luv(test_xyz)
            self.assertTuplesClose(test_luv, colors['luv'])
            test_lch = husl.luv_to_lch(test_luv)
            self.assertTuplesClose(test_lch, colors['lch'])
            test_husl = husl.lch_to_husl(test_lch)
            self.assertTuplesClose(test_husl, colors['husl'])
            test_huslp = husl.lch_to_huslp(test_lch)
            self.assertTuplesClose(test_huslp, colors['huslp'])

            # Test backward functions
            test_lch = husl.husl_to_lch(colors['husl'])
            self.assertTuplesClose(test_lch, colors['lch'])
            test_lch = husl.huslp_to_lch(colors['huslp'])
            self.assertTuplesClose(test_lch, colors['lch'])
            test_luv = husl.lch_to_luv(test_lch)
            self.assertTuplesClose(test_luv, colors['luv'])
            test_xyz = husl.luv_to_xyz(test_luv)
            self.assertTuplesClose(test_xyz, colors['xyz'])
            test_rgb = husl.xyz_to_rgb(test_xyz)
            self.assertTuplesClose(test_rgb, colors['rgb'])
            self.assertEqual(husl.rgb_to_hex(test_rgb), hex_color)

            # Full test
            self.assertEqual(husl.husl_to_hex(*colors['husl']), hex_color)
            self.assertTuplesClose(husl.hex_to_husl(hex_color), colors['husl'])
            self.assertEqual(husl.huslp_to_hex(*colors['huslp']), hex_color)
            self.assertTuplesClose(husl.hex_to_huslp(hex_color), colors['huslp'])
コード例 #2
0
ファイル: test.py プロジェクト: TadLeonard/husl-numpy
def test_luv_to_lch():
    rgb_arr = _img()[:, 0]
    rgb_arr = _img()
    rgb_arr = rgb_arr.reshape((rgb_arr.size // 3, 3))
    xyz_arr = nphusl.rgb_to_xyz(rgb_arr)
    luv_arr = nphusl.xyz_to_luv(xyz_arr)
    lch_arr = nphusl.luv_to_lch(luv_arr)
    for i in range(rgb_arr.shape[0]):
        xyz = husl.rgb_to_xyz(rgb_arr[i])
        assert _diff(xyz, xyz_arr[i])
        luv = husl.xyz_to_luv(xyz)
        assert _diff(luv, luv_arr[i])
        lch = husl.luv_to_lch(luv)
        assert _diff(lch, lch_arr[i])
コード例 #3
0
def test_luv_to_lch():
    rgb_arr = _img()[:, 14]
    float_arr = transform.ensure_rgb_float(rgb_arr)
    rgb_arr = rgb_arr.reshape((rgb_arr.size // 3, 3))
    xyz_arr = _nphusl._rgb_to_xyz(rgb_arr)
    luv_arr = _nphusl._xyz_to_luv(xyz_arr)
    lch_arr = _nphusl._luv_to_lch(luv_arr)
    for i in range(rgb_arr.shape[0]):
        xyz = husl.rgb_to_xyz(float_arr[i])
        _diff(xyz, xyz_arr[i])
        luv = husl.xyz_to_luv(xyz)
        _diff(luv, luv_arr[i])
        lch = husl.luv_to_lch(luv)
        _diff(lch, lch_arr[i])
コード例 #4
0
ファイル: husl_test.py プロジェクト: exphp-forks/husl-python
    def test_snapshot(self):
        for hex_color, colors in self.snapshot.items():

            # Test forward functions
            test_rgb = husl.hex_to_rgb(hex_color)
            self.assertTuplesClose(test_rgb, colors['rgb'])
            test_xyz = husl.rgb_to_xyz(test_rgb)
            self.assertTuplesClose(test_xyz, colors['xyz'])
            test_luv = husl.xyz_to_luv(test_xyz)
            self.assertTuplesClose(test_luv, colors['luv'])
            test_lch = husl.luv_to_lch(test_luv)
            self.assertTuplesClose(test_lch, colors['lch'])
            test_husl = husl.lch_to_husl(test_lch)
            self.assertTuplesClose(test_husl, colors['husl'])
            test_huslp = husl.lch_to_huslp(test_lch)
            self.assertTuplesClose(test_huslp, colors['huslp'])

            # Test backward functions
            test_lch = husl.husl_to_lch(colors['husl'])
            self.assertTuplesClose(test_lch, colors['lch'])
            test_lch = husl.huslp_to_lch(colors['huslp'])
            self.assertTuplesClose(test_lch, colors['lch'])
            test_luv = husl.lch_to_luv(test_lch)
            self.assertTuplesClose(test_luv, colors['luv'])
            test_xyz = husl.luv_to_xyz(test_luv)
            self.assertTuplesClose(test_xyz, colors['xyz'])
            test_rgb = husl.xyz_to_rgb(test_xyz)
            self.assertTuplesClose(test_rgb, colors['rgb'])
            self.assertEqual(husl.rgb_to_hex(test_rgb), hex_color)

            # Full test
            self.assertEqual(husl.husl_to_hex(*colors['husl']), hex_color)
            self.assertTuplesClose(husl.hex_to_husl(hex_color), colors['husl'])
            self.assertEqual(husl.huslp_to_hex(*colors['huslp']), hex_color)
            self.assertTuplesClose(husl.hex_to_huslp(hex_color),
                                   colors['huslp'])