You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

733 lines
30 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2007-06-21
  5. // Updated : 2007-08-03
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/color_cast.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. namespace glm
  10. {
  11. template <typename T>
  12. GLM_FUNC_QUALIFIER uint8 u8channel_cast(T a)
  13. {
  14. return static_cast<uint8>(a * T(255));
  15. }
  16. template <typename T>
  17. GLM_FUNC_QUALIFIER uint16 u16channel_cast(T a)
  18. {
  19. return static_cast<uint16>(a * T(65535));
  20. }
  21. template <typename T>
  22. GLM_FUNC_QUALIFIER uint32 u32_rgbx_cast(const detail::tvec3<T>& c)
  23. {
  24. uint32 result = 0;
  25. result += static_cast<uint32>(c.x * detail::tvec3<T>::value_type(255)) << 0;
  26. result += static_cast<uint32>(c.y * detail::tvec3<T>::value_type(255)) << 8;
  27. result += static_cast<uint32>(c.z * detail::tvec3<T>::value_type(255)) << 16;
  28. return result;
  29. }
  30. template <typename T>
  31. GLM_FUNC_QUALIFIER uint32 u32_xrgb_cast(const detail::tvec3<T>& c)
  32. {
  33. uint32 result = 0;
  34. result += static_cast<uint32>(c.x * detail::tvec3<T>::value_type(255)) << 8;
  35. result += static_cast<uint32>(c.y * detail::tvec3<T>::value_type(255)) << 16;
  36. result += static_cast<uint32>(c.z * detail::tvec3<T>::value_type(255)) << 24;
  37. return result;
  38. }
  39. template <typename T>
  40. GLM_FUNC_QUALIFIER uint32 u32_bgrx_cast(const detail::tvec3<T>& c)
  41. {
  42. uint32 result = 0;
  43. result += static_cast<uint32>(c.x * detail::tvec3<T>::value_type(255)) << 16;
  44. result += static_cast<uint32>(c.y * detail::tvec3<T>::value_type(255)) << 8;
  45. result += static_cast<uint32>(c.z * detail::tvec3<T>::value_type(255)) << 0;
  46. return result;
  47. }
  48. template <typename T>
  49. GLM_FUNC_QUALIFIER uint32 u32_xbgr_cast(const detail::tvec3<T>& c)
  50. {
  51. uint32 result = 0;
  52. result += static_cast<uint32>(c.x * detail::tvec3<T>::value_type(255)) << 24;
  53. result += static_cast<uint32>(c.y * detail::tvec3<T>::value_type(255)) << 16;
  54. result += static_cast<uint32>(c.z * detail::tvec3<T>::value_type(255)) << 8;
  55. result += static_cast<uint32>(c.w * detail::tvec3<T>::value_type(255)) << 0;
  56. return result;
  57. }
  58. template <typename T>
  59. GLM_FUNC_QUALIFIER uint32 u32_rgba_cast(const detail::tvec4<T>& c)
  60. {
  61. uint32 result = 0;
  62. result += static_cast<uint32>(c.x * detail::tvec4<T>::value_type(255)) << 0;
  63. result += static_cast<uint32>(c.y * detail::tvec4<T>::value_type(255)) << 8;
  64. result += static_cast<uint32>(c.z * detail::tvec4<T>::value_type(255)) << 16;
  65. result += static_cast<uint32>(c.w * detail::tvec4<T>::value_type(255)) << 24;
  66. return result;
  67. }
  68. template <typename T>
  69. GLM_FUNC_QUALIFIER uint32 u32_argb_cast(const detail::tvec4<T>& c)
  70. {
  71. uint32 result = 0;
  72. result += static_cast<uint32>(c.x * detail::tvec4<T>::value_type(255)) << 8;
  73. result += static_cast<uint32>(c.y * detail::tvec4<T>::value_type(255)) << 16;
  74. result += static_cast<uint32>(c.z * detail::tvec4<T>::value_type(255)) << 24;
  75. result += static_cast<uint32>(c.w * detail::tvec4<T>::value_type(255)) << 0;
  76. return result;
  77. }
  78. template <typename T>
  79. GLM_FUNC_QUALIFIER uint32 u32_bgra_cast(const detail::tvec4<T>& c)
  80. {
  81. uint32 result = 0;
  82. result += static_cast<uint32>(c.x * detail::tvec4<T>::value_type(255)) << 16;
  83. result += static_cast<uint32>(c.y * detail::tvec4<T>::value_type(255)) << 8;
  84. result += static_cast<uint32>(c.z * detail::tvec4<T>::value_type(255)) << 0;
  85. result += static_cast<uint32>(c.w * detail::tvec4<T>::value_type(255)) << 24;
  86. return result;
  87. }
  88. template <typename T>
  89. GLM_FUNC_QUALIFIER uint32 u32_abgr_cast(const detail::tvec4<T>& c)
  90. {
  91. uint32 result = 0;
  92. result += static_cast<uint32>(c.x * detail::tvec4<T>::value_type(255)) << 24;
  93. result += static_cast<uint32>(c.y * detail::tvec4<T>::value_type(255)) << 16;
  94. result += static_cast<uint32>(c.z * detail::tvec4<T>::value_type(255)) << 8;
  95. result += static_cast<uint32>(c.w * detail::tvec4<T>::value_type(255)) << 0;
  96. return result;
  97. }
  98. template <typename T>
  99. GLM_FUNC_QUALIFIER uint64 u64_rgbx_cast(const detail::tvec3<T>& c)
  100. {
  101. uint64 result = 0;
  102. result += static_cast<uint64>(c.x * detail::tvec3<T>::value_type(65535)) << 0;
  103. result += static_cast<uint64>(c.y * detail::tvec3<T>::value_type(65535)) << 16;
  104. result += static_cast<uint64>(c.z * detail::tvec3<T>::value_type(65535)) << 32;
  105. return result;
  106. }
  107. template <typename T>
  108. GLM_FUNC_QUALIFIER uint64 u32_xrgb_cast(const detail::tvec3<T>& c)
  109. {
  110. uint64 result = 0;
  111. result += static_cast<uint64>(c.x * detail::tvec3<T>::value_type(65535)) << 16;
  112. result += static_cast<uint64>(c.y * detail::tvec3<T>::value_type(65535)) << 32;
  113. result += static_cast<uint64>(c.z * detail::tvec3<T>::value_type(65535)) << 48;
  114. return result;
  115. }
  116. template <typename T>
  117. GLM_FUNC_QUALIFIER uint64 u32_bgrx_cast(const detail::tvec3<T>& c)
  118. {
  119. uint64 result = 0;
  120. result += static_cast<uint64>(c.x * detail::tvec3<T>::value_type(65535)) << 32;
  121. result += static_cast<uint64>(c.y * detail::tvec3<T>::value_type(65535)) << 16;
  122. result += static_cast<uint64>(c.z * detail::tvec3<T>::value_type(65535)) << 0;
  123. return result;
  124. }
  125. template <typename T>
  126. GLM_FUNC_QUALIFIER uint64 u32_xbgr_cast(const detail::tvec3<T>& c)
  127. {
  128. uint64 result = 0;
  129. result += static_cast<uint64>(c.x * detail::tvec3<T>::value_type(65535)) << 48;
  130. result += static_cast<uint64>(c.y * detail::tvec3<T>::value_type(65535)) << 32;
  131. result += static_cast<uint64>(c.z * detail::tvec3<T>::value_type(65535)) << 16;
  132. result += static_cast<uint64>(c.w * detail::tvec3<T>::value_type(65535)) << 0;
  133. return result;
  134. }
  135. template <typename T>
  136. GLM_FUNC_QUALIFIER uint64 u64_rgba_cast(const detail::tvec4<T>& c)
  137. {
  138. uint64 result = 0;
  139. result += static_cast<uint64>(c.x * detail::tvec4<T>::value_type(65535)) << 0;
  140. result += static_cast<uint64>(c.y * detail::tvec4<T>::value_type(65535)) << 16;
  141. result += static_cast<uint64>(c.z * detail::tvec4<T>::value_type(65535)) << 32;
  142. result += static_cast<uint64>(c.w * detail::tvec4<T>::value_type(65535)) << 48;
  143. return result;
  144. }
  145. template <typename T>
  146. GLM_FUNC_QUALIFIER uint64 u64_argb_cast(const detail::tvec4<T>& c)
  147. {
  148. uint64 result = 0;
  149. result += static_cast<uint64>(c.x * detail::tvec4<T>::value_type(65535)) << 16;
  150. result += static_cast<uint64>(c.y * detail::tvec4<T>::value_type(65535)) << 32;
  151. result += static_cast<uint64>(c.z * detail::tvec4<T>::value_type(65535)) << 48;
  152. result += static_cast<uint64>(c.w * detail::tvec4<T>::value_type(65535)) << 0;
  153. return result;
  154. }
  155. template <typename T>
  156. GLM_FUNC_QUALIFIER uint64 u64_bgra_cast(const detail::tvec4<T>& c)
  157. {
  158. uint64 result = 0;
  159. result += static_cast<uint64>(c.x * detail::tvec4<T>::value_type(65535)) << 32;
  160. result += static_cast<uint64>(c.y * detail::tvec4<T>::value_type(65535)) << 16;
  161. result += static_cast<uint64>(c.z * detail::tvec4<T>::value_type(65535)) << 0;
  162. result += static_cast<uint64>(c.w * detail::tvec4<T>::value_type(65535)) << 48;
  163. return result;
  164. }
  165. template <typename T>
  166. GLM_FUNC_QUALIFIER uint64 u64_abgr_cast(const detail::tvec4<T>& c)
  167. {
  168. uint64 result = 0;
  169. result += static_cast<uint64>(c.x * detail::tvec4<T>::value_type(65535)) << 48;
  170. result += static_cast<uint64>(c.y * detail::tvec4<T>::value_type(65535)) << 32;
  171. result += static_cast<uint64>(c.z * detail::tvec4<T>::value_type(65535)) << 16;
  172. result += static_cast<uint64>(c.w * detail::tvec4<T>::value_type(65535)) << 0;
  173. return result;
  174. }
  175. template <>
  176. GLM_FUNC_QUALIFIER f16 f16_channel_cast<uint32>(uint32 color)
  177. {
  178. return f16(static_cast<float>(color >> 0) / static_cast<float>(255));
  179. }
  180. template <>
  181. GLM_FUNC_QUALIFIER f16vec3 f16_rgbx_cast<uint32>(uint32 color)
  182. {
  183. f16vec3 result;
  184. result.x = f16(static_cast<float>((color >> 0) & 0xFF) / static_cast<float>(255));
  185. result.y = f16(static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255));
  186. result.z = f16(static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255));
  187. return result;
  188. }
  189. template <>
  190. GLM_FUNC_QUALIFIER f16vec3 f16_xrgb_cast<uint32>(uint32 color)
  191. {
  192. f16vec3 result;
  193. result.x = f16(static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255));
  194. result.y = f16(static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255));
  195. result.z = f16(static_cast<float>((color >> 24) & 0xFF) / static_cast<float>(255));
  196. return result;
  197. }
  198. template <>
  199. GLM_FUNC_QUALIFIER f16vec3 f16_bgrx_cast<uint32>(uint32 color)
  200. {
  201. f16vec3 result;
  202. result.x = f16(static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255));
  203. result.y = f16(static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255));
  204. result.z = f16(static_cast<float>((color >> 0) & 0xFF) / static_cast<float>(255));
  205. return result;
  206. }
  207. template <>
  208. GLM_FUNC_QUALIFIER f16vec3 f16_xbgr_cast<uint32>(uint32 color)
  209. {
  210. f16vec3 result;
  211. result.x = f16(static_cast<float>((color >> 24) & 0xFF) / static_cast<float>(255));
  212. result.y = f16(static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255));
  213. result.z = f16(static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255));
  214. return result;
  215. }
  216. template <>
  217. GLM_FUNC_QUALIFIER f16vec4 f16_rgba_cast<uint32>(uint32 color)
  218. {
  219. f16vec4 result;
  220. result.x = f16(static_cast<float>((color >> 0) & 0xFF) / static_cast<float>(255));
  221. result.y = f16(static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255));
  222. result.z = f16(static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255));
  223. result.w = f16(static_cast<float>((color >> 24) & 0xFF) / static_cast<float>(255));
  224. return result;
  225. }
  226. template <>
  227. GLM_FUNC_QUALIFIER f16vec4 f16_argb_cast<uint32>(uint32 color)
  228. {
  229. f16vec4 result;
  230. result.x = f16(static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255));
  231. result.y = f16(static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255));
  232. result.z = f16(static_cast<float>((color >> 24) & 0xFF) / static_cast<float>(255));
  233. result.w = f16(static_cast<float>((color >> 0) & 0xFF) / static_cast<float>(255));
  234. return result;
  235. }
  236. template <>
  237. GLM_FUNC_QUALIFIER f16vec4 f16_bgra_cast<uint32>(uint32 color)
  238. {
  239. f16vec4 result;
  240. result.x = f16(static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255));
  241. result.y = f16(static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255));
  242. result.z = f16(static_cast<float>((color >> 0) & 0xFF) / static_cast<float>(255));
  243. result.w = f16(static_cast<float>((color >> 24) & 0xFF) / static_cast<float>(255));
  244. return result;
  245. }
  246. template <>
  247. GLM_FUNC_QUALIFIER f16vec4 f16_abgr_cast<uint32>(uint32 color)
  248. {
  249. f16vec4 result;
  250. result.x = f16(static_cast<float>((color >> 24) & 0xFF) / static_cast<float>(255));
  251. result.y = f16(static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255));
  252. result.z = f16(static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255));
  253. result.w = f16(static_cast<float>((color >> 0) & 0xFF) / static_cast<float>(255));
  254. return result;
  255. }
  256. template <>
  257. GLM_FUNC_QUALIFIER float f32_channel_cast<uint8>(uint8 color)
  258. {
  259. return static_cast<float>(color >> 0) / static_cast<float>(255);
  260. }
  261. template <>
  262. GLM_FUNC_QUALIFIER detail::tvec3<float> f32_rgbx_cast<uint32>(uint32 color)
  263. {
  264. detail::tvec3<float> result;
  265. result.x = static_cast<float>((color >> 0) & 0xFF) / static_cast<float>(255);
  266. result.y = static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255);
  267. result.z = static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255);
  268. return result;
  269. }
  270. template <>
  271. GLM_FUNC_QUALIFIER detail::tvec3<float> f32_xrgb_cast<uint32>(uint32 color)
  272. {
  273. detail::tvec3<float> result;
  274. result.x = static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255);
  275. result.y = static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255);
  276. result.z = static_cast<float>((color >> 24) & 0xFF) / static_cast<float>(255);
  277. return result;
  278. }
  279. template <>
  280. GLM_FUNC_QUALIFIER detail::tvec3<float> f32_bgrx_cast<uint32>(uint32 color)
  281. {
  282. detail::tvec3<float> result;
  283. result.x = static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255);
  284. result.y = static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255);
  285. result.z = static_cast<float>((color >> 0) & 0xFF) / static_cast<float>(255);
  286. return result;
  287. }
  288. template <>
  289. GLM_FUNC_QUALIFIER detail::tvec3<float> f32_xbgr_cast<uint32>(uint32 color)
  290. {
  291. detail::tvec3<float> result;
  292. result.x = static_cast<float>((color >> 24) & 0xFF) / static_cast<float>(255);
  293. result.y = static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255);
  294. result.z = static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255);
  295. return result;
  296. }
  297. template <>
  298. GLM_FUNC_QUALIFIER detail::tvec4<float> f32_rgba_cast<uint32>(uint32 color)
  299. {
  300. detail::tvec4<float> result;
  301. result.x = static_cast<float>((color >> 0) & 0xFF) / static_cast<float>(255);
  302. result.y = static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255);
  303. result.z = static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255);
  304. result.w = static_cast<float>((color >> 24) & 0xFF) / static_cast<float>(255);
  305. return result;
  306. }
  307. template <>
  308. GLM_FUNC_QUALIFIER detail::tvec4<float> f32_argb_cast<uint32>(uint32 color)
  309. {
  310. detail::tvec4<float> result;
  311. result.x = static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255);
  312. result.y = static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255);
  313. result.z = static_cast<float>((color >> 24) & 0xFF) / static_cast<float>(255);
  314. result.w = static_cast<float>((color >> 0) & 0xFF) / static_cast<float>(255);
  315. return result;
  316. }
  317. template <>
  318. GLM_FUNC_QUALIFIER detail::tvec4<float> f32_bgra_cast<uint32>(uint32 color)
  319. {
  320. detail::tvec4<float> result;
  321. result.x = static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255);
  322. result.y = static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255);
  323. result.z = static_cast<float>((color >> 0) & 0xFF) / static_cast<float>(255);
  324. result.w = static_cast<float>((color >> 24) & 0xFF) / static_cast<float>(255);
  325. return result;
  326. }
  327. template <>
  328. GLM_FUNC_QUALIFIER detail::tvec4<float> f32_abgr_cast<uint32>(uint32 color)
  329. {
  330. detail::tvec4<float> result;
  331. result.x = static_cast<float>((color >> 24) & 0xFF) / static_cast<float>(255);
  332. result.y = static_cast<float>((color >> 16) & 0xFF) / static_cast<float>(255);
  333. result.z = static_cast<float>((color >> 8) & 0xFF) / static_cast<float>(255);
  334. result.w = static_cast<float>((color >> 0) & 0xFF) / static_cast<float>(255);
  335. return result;
  336. }
  337. template <>
  338. GLM_FUNC_QUALIFIER double f64_channel_cast<uint8>(uint8 color)
  339. {
  340. return static_cast<double>(color >> 0) / static_cast<double>(255);
  341. }
  342. template <>
  343. GLM_FUNC_QUALIFIER detail::tvec3<double> f64_rgbx_cast<uint32>(uint32 color)
  344. {
  345. detail::tvec3<double> result;
  346. result.x = static_cast<double>((color >> 0) & 0xFF) / static_cast<double>(255);
  347. result.y = static_cast<double>((color >> 8) & 0xFF) / static_cast<double>(255);
  348. result.z = static_cast<double>((color >> 16) & 0xFF) / static_cast<double>(255);
  349. return result;
  350. }
  351. template <>
  352. GLM_FUNC_QUALIFIER detail::tvec3<double> f64_xrgb_cast<uint32>(uint32 color)
  353. {
  354. detail::tvec3<double> result;
  355. result.x = static_cast<double>((color >> 8) & 0xFF) / static_cast<double>(255);
  356. result.y = static_cast<double>((color >> 16) & 0xFF) / static_cast<double>(255);
  357. result.z = static_cast<double>((color >> 24) & 0xFF) / static_cast<double>(255);
  358. return result;
  359. }
  360. template <>
  361. GLM_FUNC_QUALIFIER detail::tvec3<double> f64_bgrx_cast<uint32>(uint32 color)
  362. {
  363. detail::tvec3<double> result;
  364. result.x = static_cast<double>((color >> 16) & 0xFF) / static_cast<double>(255);
  365. result.y = static_cast<double>((color >> 8) & 0xFF) / static_cast<double>(255);
  366. result.z = static_cast<double>((color >> 0) & 0xFF) / static_cast<double>(255);
  367. return result;
  368. }
  369. template <>
  370. GLM_FUNC_QUALIFIER detail::tvec3<double> f64_xbgr_cast<uint32>(uint32 color)
  371. {
  372. detail::tvec3<double> result;
  373. result.x = static_cast<double>((color >> 24) & 0xFF) / static_cast<double>(255);
  374. result.y = static_cast<double>((color >> 16) & 0xFF) / static_cast<double>(255);
  375. result.z = static_cast<double>((color >> 8) & 0xFF) / static_cast<double>(255);
  376. return result;
  377. }
  378. template <>
  379. GLM_FUNC_QUALIFIER detail::tvec4<double> f64_rgba_cast<uint32>(uint32 color)
  380. {
  381. detail::tvec4<double> result;
  382. result.x = static_cast<double>((color >> 0) & 0xFF) / static_cast<double>(255);
  383. result.y = static_cast<double>((color >> 8) & 0xFF) / static_cast<double>(255);
  384. result.z = static_cast<double>((color >> 16) & 0xFF) / static_cast<double>(255);
  385. result.w = static_cast<double>((color >> 24) & 0xFF) / static_cast<double>(255);
  386. return result;
  387. }
  388. template <>
  389. GLM_FUNC_QUALIFIER detail::tvec4<double> f64_argb_cast<uint32>(uint32 color)
  390. {
  391. detail::tvec4<double> result;
  392. result.x = static_cast<double>((color >> 8) & 0xFF) / static_cast<double>(255);
  393. result.y = static_cast<double>((color >> 16) & 0xFF) / static_cast<double>(255);
  394. result.z = static_cast<double>((color >> 24) & 0xFF) / static_cast<double>(255);
  395. result.w = static_cast<double>((color >> 0) & 0xFF) / static_cast<double>(255);
  396. return result;
  397. }
  398. template <>
  399. GLM_FUNC_QUALIFIER detail::tvec4<double> f64_bgra_cast<uint32>(uint32 color)
  400. {
  401. detail::tvec4<double> result;
  402. result.x = static_cast<double>((color >> 16) & 0xFF) / static_cast<double>(255);
  403. result.y = static_cast<double>((color >> 8) & 0xFF) / static_cast<double>(255);
  404. result.z = static_cast<double>((color >> 0) & 0xFF) / static_cast<double>(255);
  405. result.w = static_cast<double>((color >> 24) & 0xFF) / static_cast<double>(255);
  406. return result;
  407. }
  408. template <>
  409. GLM_FUNC_QUALIFIER detail::tvec4<double> f64_abgr_cast<uint32>(uint32 color)
  410. {
  411. detail::tvec4<double> result;
  412. result.x = static_cast<double>((color >> 24) & 0xFF) / static_cast<double>(255);
  413. result.y = static_cast<double>((color >> 16) & 0xFF) / static_cast<double>(255);
  414. result.z = static_cast<double>((color >> 8) & 0xFF) / static_cast<double>(255);
  415. result.w = static_cast<double>((color >> 0) & 0xFF) / static_cast<double>(255);
  416. return result;
  417. }
  418. template <>
  419. GLM_FUNC_QUALIFIER detail::half f16_channel_cast<uint16>(uint16 color)
  420. {
  421. return detail::half(static_cast<float>(color >> 0) / static_cast<float>(65535));
  422. }
  423. template <>
  424. GLM_FUNC_QUALIFIER detail::tvec3<detail::half> f16_rgbx_cast<uint64>(uint64 color)
  425. {
  426. detail::tvec3<detail::half> result;
  427. result.x = detail::half(static_cast<float>((color >> 0) & 0xFFFF) / static_cast<float>(65535));
  428. result.y = detail::half(static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535));
  429. result.z = detail::half(static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535));
  430. return result;
  431. }
  432. template <>
  433. GLM_FUNC_QUALIFIER detail::tvec3<detail::half> f16_xrgb_cast<uint64>(uint64 color)
  434. {
  435. detail::tvec3<detail::half> result;
  436. result.x = detail::half(static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535));
  437. result.y = detail::half(static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535));
  438. result.z = detail::half(static_cast<float>((color >> 48) & 0xFFFF) / static_cast<float>(65535));
  439. return result;
  440. }
  441. template <>
  442. GLM_FUNC_QUALIFIER detail::tvec3<detail::half> f16_bgrx_cast<uint64>(uint64 color)
  443. {
  444. detail::tvec3<detail::half> result;
  445. result.x = detail::half(static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535));
  446. result.y = detail::half(static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535));
  447. result.z = detail::half(static_cast<float>((color >> 0) & 0xFFFF) / static_cast<float>(65535));
  448. return result;
  449. }
  450. template <>
  451. GLM_FUNC_QUALIFIER detail::tvec3<detail::half> f16_xbgr_cast<uint64>(uint64 color)
  452. {
  453. detail::tvec3<detail::half> result;
  454. result.x = detail::half(static_cast<float>((color >> 48) & 0xFFFF) / static_cast<float>(65535));
  455. result.y = detail::half(static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535));
  456. result.z = detail::half(static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535));
  457. return result;
  458. }
  459. template <>
  460. GLM_FUNC_QUALIFIER detail::tvec4<detail::half> f16_rgba_cast<uint64>(uint64 color)
  461. {
  462. detail::tvec4<detail::half> result;
  463. result.x = detail::half(static_cast<float>((color >> 0) & 0xFFFF) / static_cast<float>(65535));
  464. result.y = detail::half(static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535));
  465. result.z = detail::half(static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535));
  466. result.w = detail::half(static_cast<float>((color >> 48) & 0xFFFF) / static_cast<float>(65535));
  467. return result;
  468. }
  469. template <>
  470. GLM_FUNC_QUALIFIER detail::tvec4<detail::half> f16_argb_cast<uint64>(uint64 color)
  471. {
  472. detail::tvec4<detail::half> result;
  473. result.x = detail::half(static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535));
  474. result.y = detail::half(static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535));
  475. result.z = detail::half(static_cast<float>((color >> 48) & 0xFFFF) / static_cast<float>(65535));
  476. result.w = detail::half(static_cast<float>((color >> 0) & 0xFFFF) / static_cast<float>(65535));
  477. return result;
  478. }
  479. template <>
  480. GLM_FUNC_QUALIFIER detail::tvec4<detail::half> f16_bgra_cast<uint64>(uint64 color)
  481. {
  482. detail::tvec4<detail::half> result;
  483. result.x = detail::half(static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535));
  484. result.y = detail::half(static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535));
  485. result.z = detail::half(static_cast<float>((color >> 0) & 0xFFFF) / static_cast<float>(65535));
  486. result.w = detail::half(static_cast<float>((color >> 48) & 0xFFFF) / static_cast<float>(65535));
  487. return result;
  488. }
  489. template <>
  490. GLM_FUNC_QUALIFIER detail::tvec4<detail::half> f16_abgr_cast<uint64>(uint64 color)
  491. {
  492. detail::tvec4<detail::half> result;
  493. result.x = detail::half(static_cast<float>((color >> 48) & 0xFFFF) / static_cast<float>(65535));
  494. result.y = detail::half(static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535));
  495. result.z = detail::half(static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535));
  496. result.w = detail::half(static_cast<float>((color >> 0) & 0xFFFF) / static_cast<float>(65535));
  497. return result;
  498. }
  499. template <>
  500. GLM_FUNC_QUALIFIER float f32_channel_cast<uint16>(uint16 color)
  501. {
  502. return static_cast<float>(color >> 0) / static_cast<float>(65535);
  503. }
  504. template <>
  505. GLM_FUNC_QUALIFIER detail::tvec3<float> f32_rgbx_cast<uint64>(uint64 color)
  506. {
  507. detail::tvec3<float> result;
  508. result.x = static_cast<float>((color >> 0) & 0xFFFF) / static_cast<float>(65535);
  509. result.y = static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535);
  510. result.z = static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535);
  511. return result;
  512. }
  513. template <>
  514. GLM_FUNC_QUALIFIER detail::tvec3<float> f32_xrgb_cast<uint64>(uint64 color)
  515. {
  516. detail::tvec3<float> result;
  517. result.x = static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535);
  518. result.y = static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535);
  519. result.z = static_cast<float>((color >> 48) & 0xFFFF) / static_cast<float>(65535);
  520. return result;
  521. }
  522. template <>
  523. GLM_FUNC_QUALIFIER detail::tvec3<float> f32_bgrx_cast<uint64>(uint64 color)
  524. {
  525. detail::tvec3<float> result;
  526. result.x = static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535);
  527. result.y = static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535);
  528. result.z = static_cast<float>((color >> 0) & 0xFFFF) / static_cast<float>(65535);
  529. return result;
  530. }
  531. template <>
  532. GLM_FUNC_QUALIFIER detail::tvec3<float> f32_xbgr_cast<uint64>(uint64 color)
  533. {
  534. detail::tvec3<float> result;
  535. result.x = static_cast<float>((color >> 48) & 0xFFFF) / static_cast<float>(65535);
  536. result.y = static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535);
  537. result.z = static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535);
  538. return result;
  539. }
  540. template <>
  541. GLM_FUNC_QUALIFIER detail::tvec4<float> f32_rgba_cast<uint64>(uint64 color)
  542. {
  543. detail::tvec4<float> result;
  544. result.x = static_cast<float>((color >> 0) & 0xFFFF) / static_cast<float>(65535);
  545. result.y = static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535);
  546. result.z = static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535);
  547. result.w = static_cast<float>((color >> 48) & 0xFFFF) / static_cast<float>(65535);
  548. return result;
  549. }
  550. template <>
  551. GLM_FUNC_QUALIFIER detail::tvec4<float> f32_argb_cast<uint64>(uint64 color)
  552. {
  553. detail::tvec4<float> result;
  554. result.x = static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535);
  555. result.y = static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535);
  556. result.z = static_cast<float>((color >> 48) & 0xFFFF) / static_cast<float>(65535);
  557. result.w = static_cast<float>((color >> 0) & 0xFFFF) / static_cast<float>(65535);
  558. return result;
  559. }
  560. template <>
  561. GLM_FUNC_QUALIFIER detail::tvec4<float> f32_bgra_cast<uint64>(uint64 color)
  562. {
  563. detail::tvec4<float> result;
  564. result.x = static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535);
  565. result.y = static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535);
  566. result.z = static_cast<float>((color >> 0) & 0xFFFF) / static_cast<float>(65535);
  567. result.w = static_cast<float>((color >> 48) & 0xFFFF) / static_cast<float>(65535);
  568. return result;
  569. }
  570. template <>
  571. GLM_FUNC_QUALIFIER detail::tvec4<float> f32_abgr_cast<uint64>(uint64 color)
  572. {
  573. detail::tvec4<float> result;
  574. result.x = static_cast<float>((color >> 48) & 0xFFFF) / static_cast<float>(65535);
  575. result.y = static_cast<float>((color >> 32) & 0xFFFF) / static_cast<float>(65535);
  576. result.z = static_cast<float>((color >> 16) & 0xFFFF) / static_cast<float>(65535);
  577. result.w = static_cast<float>((color >> 0) & 0xFFFF) / static_cast<float>(65535);
  578. return result;
  579. }
  580. template <>
  581. GLM_FUNC_QUALIFIER double f64_channel_cast<uint16>(uint16 color)
  582. {
  583. return static_cast<double>(color >> 0) / static_cast<double>(65535);
  584. }
  585. template <>
  586. GLM_FUNC_QUALIFIER detail::tvec3<double> f64_rgbx_cast<uint64>(uint64 color)
  587. {
  588. detail::tvec3<double> result;
  589. result.x = static_cast<double>((color >> 0) & 0xFFFF) / static_cast<double>(65535);
  590. result.y = static_cast<double>((color >> 16) & 0xFFFF) / static_cast<double>(65535);
  591. result.z = static_cast<double>((color >> 32) & 0xFFFF) / static_cast<double>(65535);
  592. return result;
  593. }
  594. template <>
  595. GLM_FUNC_QUALIFIER detail::tvec3<double> f64_xrgb_cast<uint64>(uint64 color)
  596. {
  597. detail::tvec3<double> result;
  598. result.x = static_cast<double>((color >> 16) & 0xFFFF) / static_cast<double>(65535);
  599. result.y = static_cast<double>((color >> 32) & 0xFFFF) / static_cast<double>(65535);
  600. result.z = static_cast<double>((color >> 48) & 0xFFFF) / static_cast<double>(65535);
  601. return result;
  602. }
  603. template <>
  604. GLM_FUNC_QUALIFIER detail::tvec3<double> f64_bgrx_cast<uint64>(uint64 color)
  605. {
  606. detail::tvec3<double> result;
  607. result.x = static_cast<double>((color >> 32) & 0xFFFF) / static_cast<double>(65535);
  608. result.y = static_cast<double>((color >> 16) & 0xFFFF) / static_cast<double>(65535);
  609. result.z = static_cast<double>((color >> 0) & 0xFFFF) / static_cast<double>(65535);
  610. return result;
  611. }
  612. template <>
  613. GLM_FUNC_QUALIFIER detail::tvec3<double> f64_xbgr_cast<uint64>(uint64 color)
  614. {
  615. detail::tvec3<double> result;
  616. result.x = static_cast<double>((color >> 48) & 0xFFFF) / static_cast<double>(65535);
  617. result.y = static_cast<double>((color >> 32) & 0xFFFF) / static_cast<double>(65535);
  618. result.z = static_cast<double>((color >> 16) & 0xFFFF) / static_cast<double>(65535);
  619. return result;
  620. }
  621. template <>
  622. GLM_FUNC_QUALIFIER detail::tvec4<double> f64_rgba_cast<uint64>(uint64 color)
  623. {
  624. detail::tvec4<double> result;
  625. result.x = static_cast<double>((color >> 0) & 0xFFFF) / static_cast<double>(65535);
  626. result.y = static_cast<double>((color >> 16) & 0xFFFF) / static_cast<double>(65535);
  627. result.z = static_cast<double>((color >> 32) & 0xFFFF) / static_cast<double>(65535);
  628. result.w = static_cast<double>((color >> 48) & 0xFFFF) / static_cast<double>(65535);
  629. return result;
  630. }
  631. template <>
  632. GLM_FUNC_QUALIFIER detail::tvec4<double> f64_argb_cast<uint64>(uint64 color)
  633. {
  634. detail::tvec4<double> result;
  635. result.x = static_cast<double>((color >> 16) & 0xFFFF) / static_cast<double>(65535);
  636. result.y = static_cast<double>((color >> 32) & 0xFFFF) / static_cast<double>(65535);
  637. result.z = static_cast<double>((color >> 48) & 0xFFFF) / static_cast<double>(65535);
  638. result.w = static_cast<double>((color >> 0) & 0xFFFF) / static_cast<double>(65535);
  639. return result;
  640. }
  641. template <>
  642. GLM_FUNC_QUALIFIER detail::tvec4<double> f64_bgra_cast<uint64>(uint64 color)
  643. {
  644. detail::tvec4<double> result;
  645. result.x = static_cast<double>((color >> 32) & 0xFFFF) / static_cast<double>(65535);
  646. result.y = static_cast<double>((color >> 16) & 0xFFFF) / static_cast<double>(65535);
  647. result.z = static_cast<double>((color >> 0) & 0xFFFF) / static_cast<double>(65535);
  648. result.w = static_cast<double>((color >> 48) & 0xFFFF) / static_cast<double>(65535);
  649. return result;
  650. }
  651. template <>
  652. GLM_FUNC_QUALIFIER detail::tvec4<double> f64_abgr_cast<uint64>(uint64 color)
  653. {
  654. detail::tvec4<double> result;
  655. result.x = static_cast<double>((color >> 48) & 0xFFFF) / static_cast<double>(65535);
  656. result.y = static_cast<double>((color >> 32) & 0xFFFF) / static_cast<double>(65535);
  657. result.z = static_cast<double>((color >> 16) & 0xFFFF) / static_cast<double>(65535);
  658. result.w = static_cast<double>((color >> 0) & 0xFFFF) / static_cast<double>(65535);
  659. return result;
  660. }
  661. }//namespace glm