rgb.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. # Purpose: work with true color values
  2. # Created: 03.07.2015 taken from my dxfgrabber package
  3. # Copyright (c) 2011-2018, Manfred Moitzi
  4. # License: MIT License
  5. from typing import Tuple
  6. RGB = Tuple[int, int, int]
  7. def int2rgb(value: int) -> RGB:
  8. return (
  9. (value >> 16) & 0xFF, # red
  10. (value >> 8) & 0xFF, # green
  11. value & 0xFF, # blue
  12. )
  13. def rgb2int(rgb: RGB) -> int:
  14. r, g, b = rgb
  15. return ((int(r) & 0xff) << 16) | ((int(g) & 0xff) << 8) | (int(b) & 0xff)
  16. def aci2rgb(index: int) -> RGB:
  17. if index < 1:
  18. raise IndexError(index)
  19. return int2rgb(dxf_default_colors[index])
  20. dxf_default_colors = [
  21. 0x000000,
  22. 0xff0000,
  23. 0xffff00,
  24. 0x00ff00,
  25. 0x00ffff,
  26. 0x0000ff,
  27. 0xff00ff,
  28. 0xffffff,
  29. 0x414141,
  30. 0x808080,
  31. 0xff0000,
  32. 0xffaaaa,
  33. 0xbd0000,
  34. 0xbd7e7e,
  35. 0x810000,
  36. 0x815656,
  37. 0x680000,
  38. 0x684545,
  39. 0x4f0000,
  40. 0x4f3535,
  41. 0xff3f00,
  42. 0xffbfaa,
  43. 0xbd2e00,
  44. 0xbd8d7e,
  45. 0x811f00,
  46. 0x816056,
  47. 0x681900,
  48. 0x684e45,
  49. 0x4f1300,
  50. 0x4f3b35,
  51. 0xff7f00,
  52. 0xffd4aa,
  53. 0xbd5e00,
  54. 0xbd9d7e,
  55. 0x814000,
  56. 0x816b56,
  57. 0x683400,
  58. 0x685645,
  59. 0x4f2700,
  60. 0x4f4235,
  61. 0xffbf00,
  62. 0xffeaaa,
  63. 0xbd8d00,
  64. 0xbdad7e,
  65. 0x816000,
  66. 0x817656,
  67. 0x684e00,
  68. 0x685f45,
  69. 0x4f3b00,
  70. 0x4f4935,
  71. 0xffff00,
  72. 0xffffaa,
  73. 0xbdbd00,
  74. 0xbdbd7e,
  75. 0x818100,
  76. 0x818156,
  77. 0x686800,
  78. 0x686845,
  79. 0x4f4f00,
  80. 0x4f4f35,
  81. 0xbfff00,
  82. 0xeaffaa,
  83. 0x8dbd00,
  84. 0xadbd7e,
  85. 0x608100,
  86. 0x768156,
  87. 0x4e6800,
  88. 0x5f6845,
  89. 0x3b4f00,
  90. 0x494f35,
  91. 0x7fff00,
  92. 0xd4ffaa,
  93. 0x5ebd00,
  94. 0x9dbd7e,
  95. 0x408100,
  96. 0x6b8156,
  97. 0x346800,
  98. 0x566845,
  99. 0x274f00,
  100. 0x424f35,
  101. 0x3fff00,
  102. 0xbfffaa,
  103. 0x2ebd00,
  104. 0x8dbd7e,
  105. 0x1f8100,
  106. 0x608156,
  107. 0x196800,
  108. 0x4e6845,
  109. 0x134f00,
  110. 0x3b4f35,
  111. 0x00ff00,
  112. 0xaaffaa,
  113. 0x00bd00,
  114. 0x7ebd7e,
  115. 0x008100,
  116. 0x568156,
  117. 0x006800,
  118. 0x456845,
  119. 0x004f00,
  120. 0x354f35,
  121. 0x00ff3f,
  122. 0xaaffbf,
  123. 0x00bd2e,
  124. 0x7ebd8d,
  125. 0x00811f,
  126. 0x568160,
  127. 0x006819,
  128. 0x45684e,
  129. 0x004f13,
  130. 0x354f3b,
  131. 0x00ff7f,
  132. 0xaaffd4,
  133. 0x00bd5e,
  134. 0x7ebd9d,
  135. 0x008140,
  136. 0x56816b,
  137. 0x006834,
  138. 0x456856,
  139. 0x004f27,
  140. 0x354f42,
  141. 0x00ffbf,
  142. 0xaaffea,
  143. 0x00bd8d,
  144. 0x7ebdad,
  145. 0x008160,
  146. 0x568176,
  147. 0x00684e,
  148. 0x45685f,
  149. 0x004f3b,
  150. 0x354f49,
  151. 0x00ffff,
  152. 0xaaffff,
  153. 0x00bdbd,
  154. 0x7ebdbd,
  155. 0x008181,
  156. 0x568181,
  157. 0x006868,
  158. 0x456868,
  159. 0x004f4f,
  160. 0x354f4f,
  161. 0x00bfff,
  162. 0xaaeaff,
  163. 0x008dbd,
  164. 0x7eadbd,
  165. 0x006081,
  166. 0x567681,
  167. 0x004e68,
  168. 0x455f68,
  169. 0x003b4f,
  170. 0x35494f,
  171. 0x007fff,
  172. 0xaad4ff,
  173. 0x005ebd,
  174. 0x7e9dbd,
  175. 0x004081,
  176. 0x566b81,
  177. 0x003468,
  178. 0x455668,
  179. 0x00274f,
  180. 0x35424f,
  181. 0x003fff,
  182. 0xaabfff,
  183. 0x002ebd,
  184. 0x7e8dbd,
  185. 0x001f81,
  186. 0x566081,
  187. 0x001968,
  188. 0x454e68,
  189. 0x00134f,
  190. 0x353b4f,
  191. 0x0000ff,
  192. 0xaaaaff,
  193. 0x0000bd,
  194. 0x7e7ebd,
  195. 0x000081,
  196. 0x565681,
  197. 0x000068,
  198. 0x454568,
  199. 0x00004f,
  200. 0x35354f,
  201. 0x3f00ff,
  202. 0xbfaaff,
  203. 0x2e00bd,
  204. 0x8d7ebd,
  205. 0x1f0081,
  206. 0x605681,
  207. 0x190068,
  208. 0x4e4568,
  209. 0x13004f,
  210. 0x3b354f,
  211. 0x7f00ff,
  212. 0xd4aaff,
  213. 0x5e00bd,
  214. 0x9d7ebd,
  215. 0x400081,
  216. 0x6b5681,
  217. 0x340068,
  218. 0x564568,
  219. 0x27004f,
  220. 0x42354f,
  221. 0xbf00ff,
  222. 0xeaaaff,
  223. 0x8d00bd,
  224. 0xad7ebd,
  225. 0x600081,
  226. 0x765681,
  227. 0x4e0068,
  228. 0x5f4568,
  229. 0x3b004f,
  230. 0x49354f,
  231. 0xff00ff,
  232. 0xffaaff,
  233. 0xbd00bd,
  234. 0xbd7ebd,
  235. 0x810081,
  236. 0x815681,
  237. 0x680068,
  238. 0x684568,
  239. 0x4f004f,
  240. 0x4f354f,
  241. 0xff00bf,
  242. 0xffaaea,
  243. 0xbd008d,
  244. 0xbd7ead,
  245. 0x810060,
  246. 0x815676,
  247. 0x68004e,
  248. 0x68455f,
  249. 0x4f003b,
  250. 0x4f3549,
  251. 0xff007f,
  252. 0xffaad4,
  253. 0xbd005e,
  254. 0xbd7e9d,
  255. 0x810040,
  256. 0x81566b,
  257. 0x680034,
  258. 0x684556,
  259. 0x4f0027,
  260. 0x4f3542,
  261. 0xff003f,
  262. 0xffaabf,
  263. 0xbd002e,
  264. 0xbd7e8d,
  265. 0x81001f,
  266. 0x815660,
  267. 0x680019,
  268. 0x68454e,
  269. 0x4f0013,
  270. 0x4f353b,
  271. 0x333333,
  272. 0x505050,
  273. 0x696969,
  274. 0x828282,
  275. 0xbebebe,
  276. 0xffffff,
  277. ]