Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
f4562a7a
Kaydet (Commit)
f4562a7a
authored
Şub 11, 1998
tarafından
Barry Warsaw
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Simplification of conversion routines
üst
4a445c68
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
22 deletions
+21
-22
ColorDB.py
Tools/pynche/ColorDB.py
+21
-22
No files found.
Tools/pynche/ColorDB.py
Dosyayı görüntüle @
f4562a7a
...
@@ -15,10 +15,13 @@ Supporte file types are:
...
@@ -15,10 +15,13 @@ Supporte file types are:
import
sys
import
sys
import
re
import
re
from
types
import
*
class
BadColor
(
Exception
):
class
BadColor
(
Exception
):
pass
pass
DEFAULT_DB
=
None
# generic class
# generic class
class
ColorDB
:
class
ColorDB
:
...
@@ -80,10 +83,11 @@ class ColorDB:
...
@@ -80,10 +83,11 @@ class ColorDB:
except
KeyError
:
except
KeyError
:
raise
BadColor
(
name
)
raise
BadColor
(
name
)
def
nearest
(
self
,
r
ed
,
green
,
blu
e
):
def
nearest
(
self
,
r
gbtupl
e
):
# TBD: use Voronoi diagrams, Delaunay triangulation, or octree for
# TBD: use Voronoi diagrams, Delaunay triangulation, or octree for
# speeding up the locating of nearest point. This is really
# speeding up the locating of nearest point. This is really
# inefficient!
# inefficient!
red
,
green
,
blue
=
rgbtuple
nearest
=
-
1
nearest
=
-
1
nearest_name
=
''
nearest_name
=
''
for
name
,
aliases
in
self
.
__byrrggbb
.
values
():
for
name
,
aliases
in
self
.
__byrrggbb
.
values
():
...
@@ -132,6 +136,9 @@ def get_colordb(file, filetype=X_RGB_TXT):
...
@@ -132,6 +136,9 @@ def get_colordb(file, filetype=X_RGB_TXT):
finally
:
finally
:
if
fp
:
if
fp
:
fp
.
close
()
fp
.
close
()
# save a global copy
global
DEFAULT_DB
DEFAULT_DB
=
colordb
return
colordb
return
colordb
...
@@ -141,28 +148,20 @@ def rrggbb_to_triplet(color):
...
@@ -141,28 +148,20 @@ def rrggbb_to_triplet(color):
if
color
[
0
]
<>
'#'
:
if
color
[
0
]
<>
'#'
:
raise
BadColor
(
color
)
raise
BadColor
(
color
)
zero
=
ord
(
'0'
)
red
=
color
[
1
:
3
]
a
=
ord
(
'a'
)
green
=
color
[
3
:
5
]
A
=
ord
(
'A'
)
blue
=
color
[
5
:
7
]
def
_hexchar
(
c
,
zero
=
zero
,
a
=
a
,
A
=
A
):
return
tuple
(
map
(
lambda
v
:
string
.
atoi
(
v
,
16
),
(
red
,
green
,
blue
)))
v
=
ord
(
c
)
if
v
>=
zero
and
v
<=
zero
+
9
:
return
v
-
zero
elif
v
>=
a
and
v
<=
a
+
26
:
return
v
-
a
+
10
elif
v
>=
A
and
v
<=
A
+
26
:
return
v
-
A
+
10
else
:
raise
BadColor
try
:
digits
=
map
(
_hexchar
,
color
[
1
:])
def
triplet_to_rrggbb
(
rgbtuple
):
except
BadColor
:
"""Converts a (red, green, blue) tuple to #rrggbb."""
raise
BadColor
(
color
)
def
hexify
(
v
):
red
=
digits
[
0
]
*
16
+
digits
[
1
]
hexstr
=
hex
(
v
)[
2
:
4
]
green
=
digits
[
2
]
*
16
+
digits
[
3
]
if
len
(
hexstr
)
<
2
:
blue
=
digits
[
4
]
*
16
+
digits
[
5
]
hexstr
=
'0'
+
hexstr
return
(
red
,
green
,
blue
)
return
hexstr
return
'#
%
s
%
s
%
s'
%
tuple
(
map
(
hexify
,
rgbtuple
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment