ruby-iup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (323) hide show
  1. data/Rakefile +97 -0
  2. data/doc/README +10 -0
  3. data/doc/build_install.txt +77 -0
  4. data/examples/README +16 -0
  5. data/examples/ctrl/cbox.rb +221 -0
  6. data/examples/ctrl/checkboard.rb +33 -0
  7. data/examples/ctrl/degrade.rb +73 -0
  8. data/examples/ctrl/example1.rb +53 -0
  9. data/examples/ctrl/example2.rb +39 -0
  10. data/examples/ctrl/iupcolorbar.rb +95 -0
  11. data/examples/ctrl/iupcolorbrowser.rb +45 -0
  12. data/examples/ctrl/iupdial.rb +117 -0
  13. data/examples/ctrl/iupgauge.rb +242 -0
  14. data/examples/ctrl/iupgetcolor.rb +8 -0
  15. data/examples/ctrl/iupgetparam.rb +62 -0
  16. data/examples/ctrl/iupglcanvas.rb +172 -0
  17. data/examples/ctrl/iupmask.rb +15 -0
  18. data/examples/ctrl/iupmatrix.rb +39 -0
  19. data/examples/ctrl/iupplot2.rb +603 -0
  20. data/examples/ctrl/iuptabs.rb +22 -0
  21. data/examples/ctrl/iuptree.rb +190 -0
  22. data/examples/ctrl/iupval.rb +71 -0
  23. data/examples/ctrl/numbering.rb +46 -0
  24. data/examples/ctrl/sample.rb +166 -0
  25. data/examples/dlg/iupalarm.rb +14 -0
  26. data/examples/dlg/iupfiledlg.rb +19 -0
  27. data/examples/dlg/iupgetfile.rb +19 -0
  28. data/examples/dlg/iuplistdialog.rb +26 -0
  29. data/examples/dlg/iupmessage.rb +5 -0
  30. data/examples/dlg/iupscanf.rb +17 -0
  31. data/examples/elem/iupbutton.rb +197 -0
  32. data/examples/elem/iupcanvas.rb +27 -0
  33. data/examples/elem/iupcanvas2.rb +113 -0
  34. data/examples/elem/iupcanvas3.rb +62 -0
  35. data/examples/elem/iupdialog.rb +71 -0
  36. data/examples/elem/iupdialog2.rb +25 -0
  37. data/examples/elem/iupfill.rb +51 -0
  38. data/examples/elem/iupframe.rb +25 -0
  39. data/examples/elem/iuphbox.rb +68 -0
  40. data/examples/elem/iupimage.rb +113 -0
  41. data/examples/elem/iupitem.rb +60 -0
  42. data/examples/elem/iuplabel.rb +57 -0
  43. data/examples/elem/iuplist.rb +41 -0
  44. data/examples/elem/iuplist2.rb +125 -0
  45. data/examples/elem/iupmenu.rb +32 -0
  46. data/examples/elem/iupmultiline.rb +24 -0
  47. data/examples/elem/iupmultiline2.rb +156 -0
  48. data/examples/elem/iupradio.rb +32 -0
  49. data/examples/elem/iupseparator.rb +81 -0
  50. data/examples/elem/iupsubmenu.rb +85 -0
  51. data/examples/elem/iuptext.rb +61 -0
  52. data/examples/elem/iuptimer.rb +36 -0
  53. data/examples/elem/iuptoggle.rb +110 -0
  54. data/examples/elem/iupvbox.rb +87 -0
  55. data/examples/elem/iupzbox.rb +60 -0
  56. data/examples/elem/mdisample.rb +376 -0
  57. data/examples/elem/progressbar.rb +294 -0
  58. data/examples/elem/scrollbar.rb +66 -0
  59. data/examples/elem/tray.rb +90 -0
  60. data/examples/func/iupgetattribute.rb +32 -0
  61. data/examples/func/iupidle.rb +48 -0
  62. data/ext/extconf.rb +27 -0
  63. data/ext/iup-linux/include/cd.h +494 -0
  64. data/ext/iup-linux/include/cd_canvas.hpp +358 -0
  65. data/ext/iup-linux/include/cd_old.h +158 -0
  66. data/ext/iup-linux/include/cd_private.h +362 -0
  67. data/ext/iup-linux/include/cdcgm.h +34 -0
  68. data/ext/iup-linux/include/cdclipbd.h +22 -0
  69. data/ext/iup-linux/include/cddbuf.h +23 -0
  70. data/ext/iup-linux/include/cddebug.h +24 -0
  71. data/ext/iup-linux/include/cddgn.h +23 -0
  72. data/ext/iup-linux/include/cddxf.h +22 -0
  73. data/ext/iup-linux/include/cdemf.h +22 -0
  74. data/ext/iup-linux/include/cdgdiplus.h +29 -0
  75. data/ext/iup-linux/include/cdimage.h +23 -0
  76. data/ext/iup-linux/include/cdirgb.h +30 -0
  77. data/ext/iup-linux/include/cdiup.h +22 -0
  78. data/ext/iup-linux/include/cdlua.h +39 -0
  79. data/ext/iup-linux/include/cdlua3_private.h +120 -0
  80. data/ext/iup-linux/include/cdlua5_private.h +141 -0
  81. data/ext/iup-linux/include/cdluaim.h +24 -0
  82. data/ext/iup-linux/include/cdluaiup.h +27 -0
  83. data/ext/iup-linux/include/cdluapdf.h +27 -0
  84. data/ext/iup-linux/include/cdmf.h +24 -0
  85. data/ext/iup-linux/include/cdmf_private.h +32 -0
  86. data/ext/iup-linux/include/cdnative.h +26 -0
  87. data/ext/iup-linux/include/cdpdf.h +38 -0
  88. data/ext/iup-linux/include/cdpicture.h +22 -0
  89. data/ext/iup-linux/include/cdprint.h +23 -0
  90. data/ext/iup-linux/include/cdps.h +37 -0
  91. data/ext/iup-linux/include/cdwmf.h +22 -0
  92. data/ext/iup-linux/include/im.h +282 -0
  93. data/ext/iup-linux/include/im_attrib.h +116 -0
  94. data/ext/iup-linux/include/im_attrib_flat.h +39 -0
  95. data/ext/iup-linux/include/im_binfile.h +214 -0
  96. data/ext/iup-linux/include/im_capture.h +365 -0
  97. data/ext/iup-linux/include/im_color.h +465 -0
  98. data/ext/iup-linux/include/im_colorhsi.h +61 -0
  99. data/ext/iup-linux/include/im_complex.h +160 -0
  100. data/ext/iup-linux/include/im_convert.h +127 -0
  101. data/ext/iup-linux/include/im_counter.h +69 -0
  102. data/ext/iup-linux/include/im_dib.h +195 -0
  103. data/ext/iup-linux/include/im_file.h +111 -0
  104. data/ext/iup-linux/include/im_format.h +79 -0
  105. data/ext/iup-linux/include/im_format_all.h +576 -0
  106. data/ext/iup-linux/include/im_format_avi.h +87 -0
  107. data/ext/iup-linux/include/im_format_ecw.h +93 -0
  108. data/ext/iup-linux/include/im_format_jp2.h +78 -0
  109. data/ext/iup-linux/include/im_format_raw.h +64 -0
  110. data/ext/iup-linux/include/im_format_wmv.h +100 -0
  111. data/ext/iup-linux/include/im_image.h +403 -0
  112. data/ext/iup-linux/include/im_kernel.h +315 -0
  113. data/ext/iup-linux/include/im_lib.h +191 -0
  114. data/ext/iup-linux/include/im_math.h +368 -0
  115. data/ext/iup-linux/include/im_math_op.h +219 -0
  116. data/ext/iup-linux/include/im_palette.h +172 -0
  117. data/ext/iup-linux/include/im_plus.h +73 -0
  118. data/ext/iup-linux/include/im_process.h +35 -0
  119. data/ext/iup-linux/include/im_process_ana.h +221 -0
  120. data/ext/iup-linux/include/im_process_glo.h +170 -0
  121. data/ext/iup-linux/include/im_process_loc.h +577 -0
  122. data/ext/iup-linux/include/im_process_pon.h +712 -0
  123. data/ext/iup-linux/include/im_raw.h +34 -0
  124. data/ext/iup-linux/include/im_util.h +277 -0
  125. data/ext/iup-linux/include/imlua.h +83 -0
  126. data/ext/iup-linux/include/iup.h +255 -0
  127. data/ext/iup-linux/include/iup_pplot.h +40 -0
  128. data/ext/iup-linux/include/iupcb.h +25 -0
  129. data/ext/iup-linux/include/iupcbox.h +23 -0
  130. data/ext/iup-linux/include/iupcbs.h +42 -0
  131. data/ext/iup-linux/include/iupcells.h +130 -0
  132. data/ext/iup-linux/include/iupcolorbar.h +126 -0
  133. data/ext/iup-linux/include/iupcompat.h +62 -0
  134. data/ext/iup-linux/include/iupcontrols.h +40 -0
  135. data/ext/iup-linux/include/iupcpi.h +76 -0
  136. data/ext/iup-linux/include/iupdef.h +520 -0
  137. data/ext/iup-linux/include/iupdial.h +64 -0
  138. data/ext/iup-linux/include/iupgauge.h +57 -0
  139. data/ext/iup-linux/include/iupgc.h +20 -0
  140. data/ext/iup-linux/include/iupgetparam.h +27 -0
  141. data/ext/iup-linux/include/iupgl.h +101 -0
  142. data/ext/iup-linux/include/iupim.h +21 -0
  143. data/ext/iup-linux/include/iupkey.h +290 -0
  144. data/ext/iup-linux/include/iuplua.h +41 -0
  145. data/ext/iup-linux/include/iuplua_pplot.h +26 -0
  146. data/ext/iup-linux/include/iupluacontrols.h +27 -0
  147. data/ext/iup-linux/include/iupluagl.h +26 -0
  148. data/ext/iup-linux/include/iupluaim.h +26 -0
  149. data/ext/iup-linux/include/iupluaole.h +26 -0
  150. data/ext/iup-linux/include/iupmask.h +52 -0
  151. data/ext/iup-linux/include/iupmatrix.h +69 -0
  152. data/ext/iup-linux/include/iupole.h +24 -0
  153. data/ext/iup-linux/include/iupsbox.h +20 -0
  154. data/ext/iup-linux/include/iupspeech.h +23 -0
  155. data/ext/iup-linux/include/iupspin.h +21 -0
  156. data/ext/iup-linux/include/iuptabs.h +79 -0
  157. data/ext/iup-linux/include/iuptree.h +93 -0
  158. data/ext/iup-linux/include/iupval.h +46 -0
  159. data/ext/iup-linux/include/lauxlib.h +174 -0
  160. data/ext/iup-linux/include/lua.h +388 -0
  161. data/ext/iup-linux/include/lua.hpp +9 -0
  162. data/ext/iup-linux/include/luaconf.h +763 -0
  163. data/ext/iup-linux/include/lualib.h +53 -0
  164. data/ext/iup-linux/include/old_im.h +59 -0
  165. data/ext/iup-linux/include/wd.h +78 -0
  166. data/ext/iup-linux/include/wd_old.h +85 -0
  167. data/ext/iup-linux/libcd.so +0 -0
  168. data/ext/iup-linux/libcdcontextplus.so +0 -0
  169. data/ext/iup-linux/libcdluacontextplus51.so +0 -0
  170. data/ext/iup-linux/libcdpdf.so +0 -0
  171. data/ext/iup-linux/libfreetype.so +0 -0
  172. data/ext/iup-linux/libim.so +0 -0
  173. data/ext/iup-linux/libim_fftw.so +0 -0
  174. data/ext/iup-linux/libim_jp2.so +0 -0
  175. data/ext/iup-linux/libim_process.so +0 -0
  176. data/ext/iup-linux/libiup.so +0 -0
  177. data/ext/iup-linux/libiup_pplot.so +0 -0
  178. data/ext/iup-linux/libiupcd.so +0 -0
  179. data/ext/iup-linux/libiupcontrols.so +0 -0
  180. data/ext/iup-linux/libiupgl.so +0 -0
  181. data/ext/iup-linux/libiupim.so +0 -0
  182. data/ext/iup-linux/libiupimglib.so +0 -0
  183. data/ext/iup-linux/libpdflib.so +0 -0
  184. data/ext/iup-win32/cd.dll +0 -0
  185. data/ext/iup-win32/cd.lib +0 -0
  186. data/ext/iup-win32/cdcontextplus.dll +0 -0
  187. data/ext/iup-win32/cdcontextplus.lib +0 -0
  188. data/ext/iup-win32/cdlua51.lib +0 -0
  189. data/ext/iup-win32/cdluacontextplus51.lib +0 -0
  190. data/ext/iup-win32/cdluaim51.lib +0 -0
  191. data/ext/iup-win32/cdluapdf51.lib +0 -0
  192. data/ext/iup-win32/cdpdf.dll +0 -0
  193. data/ext/iup-win32/cdpdf.lib +0 -0
  194. data/ext/iup-win32/freetype6.dll +0 -0
  195. data/ext/iup-win32/freetype6.lib +0 -0
  196. data/ext/iup-win32/im.dll +0 -0
  197. data/ext/iup-win32/im_avi.dll +0 -0
  198. data/ext/iup-win32/im_capture.dll +0 -0
  199. data/ext/iup-win32/im_ecw.dll +0 -0
  200. data/ext/iup-win32/im_fftw.dll +0 -0
  201. data/ext/iup-win32/im_jp2.dll +0 -0
  202. data/ext/iup-win32/im_process.dll +0 -0
  203. data/ext/iup-win32/im_wmv.dll +0 -0
  204. data/ext/iup-win32/include/cd.h +494 -0
  205. data/ext/iup-win32/include/cd_canvas.hpp +358 -0
  206. data/ext/iup-win32/include/cd_old.h +158 -0
  207. data/ext/iup-win32/include/cd_private.h +362 -0
  208. data/ext/iup-win32/include/cdcgm.h +34 -0
  209. data/ext/iup-win32/include/cdclipbd.h +22 -0
  210. data/ext/iup-win32/include/cddbuf.h +23 -0
  211. data/ext/iup-win32/include/cddebug.h +24 -0
  212. data/ext/iup-win32/include/cddgn.h +23 -0
  213. data/ext/iup-win32/include/cddxf.h +22 -0
  214. data/ext/iup-win32/include/cdemf.h +22 -0
  215. data/ext/iup-win32/include/cdgdiplus.h +29 -0
  216. data/ext/iup-win32/include/cdimage.h +23 -0
  217. data/ext/iup-win32/include/cdirgb.h +30 -0
  218. data/ext/iup-win32/include/cdiup.h +22 -0
  219. data/ext/iup-win32/include/cdlua.h +39 -0
  220. data/ext/iup-win32/include/cdlua3_private.h +120 -0
  221. data/ext/iup-win32/include/cdlua5_private.h +141 -0
  222. data/ext/iup-win32/include/cdluaim.h +24 -0
  223. data/ext/iup-win32/include/cdluaiup.h +27 -0
  224. data/ext/iup-win32/include/cdluapdf.h +27 -0
  225. data/ext/iup-win32/include/cdmf.h +24 -0
  226. data/ext/iup-win32/include/cdmf_private.h +32 -0
  227. data/ext/iup-win32/include/cdnative.h +26 -0
  228. data/ext/iup-win32/include/cdpdf.h +38 -0
  229. data/ext/iup-win32/include/cdpicture.h +22 -0
  230. data/ext/iup-win32/include/cdprint.h +23 -0
  231. data/ext/iup-win32/include/cdps.h +37 -0
  232. data/ext/iup-win32/include/cdwmf.h +22 -0
  233. data/ext/iup-win32/include/iup.h +255 -0
  234. data/ext/iup-win32/include/iup_pplot.h +40 -0
  235. data/ext/iup-win32/include/iupcb.h +25 -0
  236. data/ext/iup-win32/include/iupcbox.h +23 -0
  237. data/ext/iup-win32/include/iupcbs.h +42 -0
  238. data/ext/iup-win32/include/iupcells.h +130 -0
  239. data/ext/iup-win32/include/iupcolorbar.h +126 -0
  240. data/ext/iup-win32/include/iupcompat.h +62 -0
  241. data/ext/iup-win32/include/iupcontrols.h +40 -0
  242. data/ext/iup-win32/include/iupcpi.h +76 -0
  243. data/ext/iup-win32/include/iupdef.h +520 -0
  244. data/ext/iup-win32/include/iupdial.h +64 -0
  245. data/ext/iup-win32/include/iupgauge.h +57 -0
  246. data/ext/iup-win32/include/iupgc.h +20 -0
  247. data/ext/iup-win32/include/iupgetparam.h +27 -0
  248. data/ext/iup-win32/include/iupgl.h +101 -0
  249. data/ext/iup-win32/include/iupim.h +21 -0
  250. data/ext/iup-win32/include/iupkey.h +290 -0
  251. data/ext/iup-win32/include/iuplua.h +41 -0
  252. data/ext/iup-win32/include/iuplua_pplot.h +26 -0
  253. data/ext/iup-win32/include/iupluacontrols.h +27 -0
  254. data/ext/iup-win32/include/iupluagl.h +26 -0
  255. data/ext/iup-win32/include/iupluaim.h +26 -0
  256. data/ext/iup-win32/include/iupluaole.h +26 -0
  257. data/ext/iup-win32/include/iupmask.h +52 -0
  258. data/ext/iup-win32/include/iupmatrix.h +69 -0
  259. data/ext/iup-win32/include/iupole.h +24 -0
  260. data/ext/iup-win32/include/iupsbox.h +20 -0
  261. data/ext/iup-win32/include/iupspeech.h +23 -0
  262. data/ext/iup-win32/include/iupspin.h +21 -0
  263. data/ext/iup-win32/include/iuptabs.h +79 -0
  264. data/ext/iup-win32/include/iuptree.h +93 -0
  265. data/ext/iup-win32/include/iupval.h +46 -0
  266. data/ext/iup-win32/include/wd.h +78 -0
  267. data/ext/iup-win32/include/wd_old.h +85 -0
  268. data/ext/iup-win32/iup.dll +0 -0
  269. data/ext/iup-win32/iup.lib +0 -0
  270. data/ext/iup-win32/iup_pplot.dll +0 -0
  271. data/ext/iup-win32/iup_pplot.lib +0 -0
  272. data/ext/iup-win32/iupcd.dll +0 -0
  273. data/ext/iup-win32/iupcd.lib +0 -0
  274. data/ext/iup-win32/iupcontrols.dll +0 -0
  275. data/ext/iup-win32/iupcontrols.lib +0 -0
  276. data/ext/iup-win32/iupgl.dll +0 -0
  277. data/ext/iup-win32/iupgl.lib +0 -0
  278. data/ext/iup-win32/iupim.dll +0 -0
  279. data/ext/iup-win32/iupim.lib +0 -0
  280. data/ext/iup-win32/iupimglib.dll +0 -0
  281. data/ext/iup-win32/iupimglib.lib +0 -0
  282. data/ext/iup-win32/iuplua51.lib +0 -0
  283. data/ext/iup-win32/iuplua_pplot51.lib +0 -0
  284. data/ext/iup-win32/iupluacd51.lib +0 -0
  285. data/ext/iup-win32/iupluacontrols51.lib +0 -0
  286. data/ext/iup-win32/iupluagl51.lib +0 -0
  287. data/ext/iup-win32/iupluaim51.lib +0 -0
  288. data/ext/iup-win32/iupluaimglib51.lib +0 -0
  289. data/ext/iup-win32/iupluaole51.lib +0 -0
  290. data/ext/iup-win32/iupole.dll +0 -0
  291. data/ext/iup-win32/iupole.lib +0 -0
  292. data/ext/iup-win32/iupstub.lib +0 -0
  293. data/ext/iup-win32/pdflib.dll +0 -0
  294. data/ext/iup-win32/pdflib.lib +0 -0
  295. data/ext/iup.c +1261 -0
  296. data/ext/mkrf_conf.rb +72 -0
  297. data/ext/rb_cd.h +1525 -0
  298. data/ext/rb_iup.h +2446 -0
  299. data/ext/rb_iup_pplot.h +129 -0
  300. data/ext/rb_iupcb.h +13 -0
  301. data/ext/rb_iupcbox.h +40 -0
  302. data/ext/rb_iupcells.h +15 -0
  303. data/ext/rb_iupcolorbar.h +17 -0
  304. data/ext/rb_iupcompat.h +237 -0
  305. data/ext/rb_iupcontrols.h +28 -0
  306. data/ext/rb_iupdef.h +3 -0
  307. data/ext/rb_iupdial.h +24 -0
  308. data/ext/rb_iupgauge.h +15 -0
  309. data/ext/rb_iupgc.h +18 -0
  310. data/ext/rb_iupgetparam.h +72 -0
  311. data/ext/rb_iupgl.h +58 -0
  312. data/ext/rb_iupim.h +25 -0
  313. data/ext/rb_iupmask.h +189 -0
  314. data/ext/rb_iupmatrix.h +80 -0
  315. data/ext/rb_iupole.h +24 -0
  316. data/ext/rb_iupsbox.h +23 -0
  317. data/ext/rb_iupspeech.h +25 -0
  318. data/ext/rb_iupspin.h +29 -0
  319. data/ext/rb_iuptabs.h +29 -0
  320. data/ext/rb_iuptree.h +94 -0
  321. data/ext/rb_iupval.h +24 -0
  322. data/lib/README +1 -0
  323. metadata +391 -0
@@ -0,0 +1,465 @@
1
+ /** \file
2
+ * \brief Color Manipulation
3
+ *
4
+ * See Copyright Notice in im_lib.h
5
+ */
6
+
7
+ #ifndef __IM_COLOR_H
8
+ #define __IM_COLOR_H
9
+
10
+ #include "im_math.h"
11
+
12
+ /** \defgroup color Color Manipulation
13
+ *
14
+ * \par
15
+ * Functions to convert from one color space to another,
16
+ * and color gammut utilities.
17
+ * \par
18
+ * See \ref im_color.h
19
+ *
20
+ * \section s1 Some Color Science
21
+ * \par
22
+ * Y is luminance, a linear-light quantity.
23
+ * It is directly proportional to physical intensity
24
+ * weighted by the spectral sensitivity of human vision.
25
+ * \par
26
+ * L* is lightness, a nonlinear luminance
27
+ * that aproximates the perception of brightness.
28
+ * It is nearly perceptual uniform.
29
+ * It has a range of 0 to 100.
30
+ * \par
31
+ * Y' is luma, a nonlinear luminance that aproximates lightness.
32
+ * \par
33
+ * Brightness is a visual sensation according to which an area
34
+ * apears to exhibit more or less light.
35
+ * It is a subjective quantity and can not be measured.
36
+ * \par
37
+ * One unit of euclidian distante in CIE L*u*v* or CIE L*a*b* corresponds
38
+ * roughly to a just-noticeable difference (JND) of color.
39
+ * \par
40
+ \verbatim
41
+ ChromaUV = sqrt(u*u + v*v)
42
+ HueUV = atan2(v, u)
43
+ SaturationUV = ChromaUV / L (called psychometric saturation)
44
+ (the same can be calculated for Lab)
45
+ \endverbatim
46
+ * \par
47
+ * IEC 61966-2.1 Default RGB colour space - sRGB
48
+ * \li ITU-R Recommendation BT.709 (D65 white point).
49
+ * \li D65 White Point (X,Y,Z) = (0.9505 1.0000 1.0890)
50
+ * \par
51
+ * Documentation extracted from Charles Poynton - Digital Video and HDTV - Morgan Kaufmann - 2003.
52
+ *
53
+ * \section Links
54
+ * \li www.color.org - ICC
55
+ * \li www.srgb.com - sRGB
56
+ * \li www.poynton.com - Charles Poynton
57
+ * \li www.littlecms.com - A free Color Management System (use this if you need precise color conversions)
58
+ *
59
+ * \section cci Color Component Intervals
60
+ * \par
61
+ * All the color components are stored in the 0-max interval, even the signed ones. \n
62
+ * Here are the pre-defined intervals for each data type. These values are used for standard color conversion.
63
+ * You should normalize data before converting betwwen color spaces.
64
+ * \par
65
+ \verbatim
66
+ byte [0,255] or [-128,+127] (1 byte)
67
+ ushort [0,65535] or [-32768,+32767] (2 bytes)
68
+ int [0,16777215] or [-8388608,+8388607] (3 bytes)
69
+ float [0,1] or [-0.5,+0.5] (4 bytes)
70
+ \endverbatim
71
+ * \ingroup util */
72
+
73
+ /** Returns the zero value for color conversion porpouses. \n
74
+ * This is a value to be compensated when the data_type is unsigned and component is signed. \n
75
+ * \ingroup color */
76
+ inline float imColorZero(int data_type)
77
+ {
78
+ float zero[] = {128.0f, 32768.0f, 8388608.0f, 0.5f};
79
+ return zero[data_type];
80
+ }
81
+
82
+ /** Returns the maximum value for color conversion porpouses. \n
83
+ * \ingroup color */
84
+ inline int imColorMax(int data_type)
85
+ {
86
+ int max[] = {255, 65535, 16777215, 1};
87
+ return max[data_type];
88
+ }
89
+
90
+ /** Quantize r=0-1 values into q=0-max.
91
+ * max is the maximum value.
92
+ * max and the returned value are usually integers,
93
+ * but the dummy quantizer uses real values.
94
+ * See also \ref math.
95
+ * \ingroup color */
96
+ template <class T>
97
+ inline T imColorQuantize(const float& value, const T& max)
98
+ {
99
+ if (max == 1) return (T)value; // to allow a dummy quantizer
100
+ if (value >= 1) return max;
101
+ if (value <= 0) return 0;
102
+ /* return (T)imRound(value*(max + 1) - 0.5f); not necessary since all values are positive */
103
+ return (T)(value*(max + 1));
104
+ }
105
+
106
+ /** Reconstruct 0-max values into 0-1. \n
107
+ * max is the maximum value.
108
+ * max and the given value are usually integers,
109
+ * but the dummy reconstructor uses real values.
110
+ * See also \ref math.
111
+ * \ingroup color */
112
+ template <class T>
113
+ inline float imColorReconstruct(const T& value, const T& max)
114
+ {
115
+ if (max == 1) return (float)value; // to allow a dummy reconstructor
116
+ if (value <= 0) return 0;
117
+ if (value >= max) return 1;
118
+ return (((float)value + 0.5f)/((float)max + 1.0f));
119
+ }
120
+
121
+ /** Converts Y'CbCr to R'G'B' (all nonlinear). \n
122
+ * ITU-R Recommendation 601-1 with no headroom/footroom.
123
+ \verbatim
124
+ 0 <= Y <= 1 ; -0.5 <= CbCr <= 0.5 ; 0 <= RGB <= 1
125
+
126
+ R'= Y' + 0.000 *Cb + 1.402 *Cr
127
+ G'= Y' - 0.344 *Cb - 0.714 *Cr
128
+ B'= Y' + 1.772 *Cb + 0.000 *Cr
129
+ \endverbatim
130
+ * \ingroup color */
131
+ template <class T>
132
+ inline void imColorYCbCr2RGB(const T Y, const T Cb, const T Cr,
133
+ T& R, T& G, T& B,
134
+ const T& zero, const T& max)
135
+ {
136
+ float r = float(Y + 1.402f * (Cr - zero));
137
+ float g = float(Y - 0.344f * (Cb - zero) - 0.714f * (Cr - zero));
138
+ float b = float(Y + 1.772f * (Cb - zero));
139
+
140
+ // now we should enforce 0<= rgb <= max
141
+
142
+ R = (T)IM_CROPMAX(r, max);
143
+ G = (T)IM_CROPMAX(g, max);
144
+ B = (T)IM_CROPMAX(b, max);
145
+ }
146
+
147
+ /** Converts R'G'B' to Y'CbCr (all nonlinear). \n
148
+ * ITU-R Recommendation 601-1 with no headroom/footroom.
149
+ \verbatim
150
+ 0 <= Y <= 1 ; -0.5 <= CbCr <= 0.5 ; 0 <= RGB <= 1
151
+
152
+ Y' = 0.299 *R' + 0.587 *G' + 0.114 *B'
153
+ Cb = -0.169 *R' - 0.331 *G' + 0.500 *B'
154
+ Cr = 0.500 *R' - 0.419 *G' - 0.081 *B'
155
+ \endverbatim
156
+ * \ingroup color */
157
+ template <class T>
158
+ inline void imColorRGB2YCbCr(const T R, const T G, const T B,
159
+ T& Y, T& Cb, T& Cr,
160
+ const T& zero)
161
+ {
162
+ Y = (T)( 0.299f *R + 0.587f *G + 0.114f *B);
163
+ Cb = (T)(-0.169f *R - 0.331f *G + 0.500f *B + (float)zero);
164
+ Cr = (T)( 0.500f *R - 0.419f *G - 0.081f *B + (float)zero);
165
+
166
+ // there is no need for cropping here, YCrCr is already at the limits
167
+ }
168
+
169
+ /** Converts C'M'Y'K' to R'G'B' (all nonlinear). \n
170
+ * This is a poor conversion that works for a simple visualization.
171
+ \verbatim
172
+ 0 <= CMYK <= 1 ; 0 <= RGB <= 1
173
+
174
+ R = (1 - K) * (1 - C)
175
+ G = (1 - K) * (1 - M)
176
+ B = (1 - K) * (1 - Y)
177
+ \endverbatim
178
+ * \ingroup color */
179
+ template <class T>
180
+ inline void imColorCMYK2RGB(const T C, const T M, const T Y, const T K,
181
+ T& R, T& G, T& B, const T& max)
182
+ {
183
+ T W = max - K;
184
+ R = (T)((W * (max - C)) / max);
185
+ G = (T)((W * (max - M)) / max);
186
+ B = (T)((W * (max - Y)) / max);
187
+
188
+ // there is no need for cropping here, RGB is already at the limits
189
+ }
190
+
191
+ /** Converts CIE XYZ to Rec 709 RGB (all linear). \n
192
+ * ITU-R Recommendation BT.709 (D65 white point). \n
193
+ \verbatim
194
+ 0 <= XYZ <= 1 ; 0 <= RGB <= 1
195
+
196
+ R = 3.2406 *X - 1.5372 *Y - 0.4986 *Z
197
+ G = -0.9689 *X + 1.8758 *Y + 0.0415 *Z
198
+ B = 0.0557 *X - 0.2040 *Y + 1.0570 *Z
199
+ \endverbatim
200
+ * \ingroup color */
201
+ template <class T>
202
+ inline void imColorXYZ2RGB(const T X, const T Y, const T Z,
203
+ T& R, T& G, T& B, const T& max)
204
+ {
205
+ float r = 3.2406f *X - 1.5372f *Y - 0.4986f *Z;
206
+ float g = -0.9689f *X + 1.8758f *Y + 0.0415f *Z;
207
+ float b = 0.0557f *X - 0.2040f *Y + 1.0570f *Z;
208
+
209
+ // we need to crop because not all XYZ colors are visible
210
+
211
+ R = (T)IM_CROPMAX(r, max);
212
+ G = (T)IM_CROPMAX(g, max);
213
+ B = (T)IM_CROPMAX(b, max);
214
+ }
215
+
216
+ /** Converts Rec 709 RGB to CIE XYZ (all linear). \n
217
+ * ITU-R Recommendation BT.709 (D65 white point). \n
218
+ \verbatim
219
+ 0 <= XYZ <= 1 ; 0 <= RGB <= 1
220
+
221
+ X = 0.4124 *R + 0.3576 *G + 0.1805 *B
222
+ Y = 0.2126 *R + 0.7152 *G + 0.0722 *B
223
+ Z = 0.0193 *R + 0.1192 *G + 0.9505 *B
224
+ \endverbatim
225
+ * \ingroup color */
226
+ template <class T>
227
+ inline void imColorRGB2XYZ(const T R, const T G, const T B,
228
+ T& X, T& Y, T& Z)
229
+ {
230
+ X = (T)(0.4124f *R + 0.3576f *G + 0.1805f *B);
231
+ Y = (T)(0.2126f *R + 0.7152f *G + 0.0722f *B);
232
+ Z = (T)(0.0193f *R + 0.1192f *G + 0.9505f *B);
233
+
234
+ // there is no need for cropping here, XYZ is already at the limits
235
+ }
236
+
237
+ #define IM_FWLAB(_w) (_w > 0.008856f? \
238
+ powf(_w, 1.0f/3.0f): \
239
+ 7.787f * _w + 0.16f/1.16f)
240
+
241
+ /** Converts CIE XYZ (linear) to CIE L*a*b* (nonlinear). \n
242
+ * The white point is D65. \n
243
+ \verbatim
244
+ 0 <= L <= 1 ; -0.5 <= ab <= +0.5 ; 0 <= XYZ <= 1
245
+
246
+ if (t > 0.008856)
247
+ f(t) = pow(t, 1/3)
248
+ else
249
+ f(t) = 7.787*t + 16/116
250
+
251
+ fX = f(X / Xn) fY = f(Y / Yn) fZ = f(Z / Zn)
252
+
253
+ L = 1.16 * fY - 0.16
254
+ a = 2.5 * (fX - fY)
255
+ b = (fY - fZ)
256
+
257
+ \endverbatim
258
+ * \ingroup color */
259
+ inline void imColorXYZ2Lab(const float X, const float Y, const float Z,
260
+ float& L, float& a, float& b)
261
+ {
262
+ float fX = X / 0.9505f; // white point D65
263
+ float fY = Y / 1.0f;
264
+ float fZ = Z / 1.0890f;
265
+
266
+ fX = IM_FWLAB(fX);
267
+ fY = IM_FWLAB(fY);
268
+ fZ = IM_FWLAB(fZ);
269
+
270
+ L = 1.16f * fY - 0.16f;
271
+ a = 2.5f * (fX - fY);
272
+ b = (fY - fZ);
273
+ }
274
+
275
+ #define IM_GWLAB(_w) (_w > 0.20689f? \
276
+ powf(_w, 3.0f): \
277
+ 0.1284f * (_w - 0.16f/1.16f))
278
+
279
+ /** Converts CIE L*a*b* (nonlinear) to CIE XYZ (linear). \n
280
+ * The white point is D65. \n
281
+ * 0 <= L <= 1 ; -0.5 <= ab <= +0.5 ; 0 <= XYZ <= 1
282
+ * \ingroup color */
283
+ inline void imColorLab2XYZ(const float L, const float a, const float b,
284
+ float& X, float& Y, float& Z)
285
+
286
+ {
287
+ float fY = (L + 0.16f) / 1.16f;
288
+ float gY = IM_GWLAB(fY);
289
+
290
+ float fgY = IM_FWLAB(gY);
291
+ float gX = fgY + a / 2.5f;
292
+ float gZ = fgY - b;
293
+ gX = IM_GWLAB(gX);
294
+ gZ = IM_GWLAB(gZ);
295
+
296
+ X = gX * 0.9505f; // white point D65
297
+ Y = gY * 1.0f;
298
+ Z = gZ * 1.0890f;
299
+ }
300
+
301
+ /** Converts CIE XYZ (linear) to CIE L*u*v* (nonlinear). \n
302
+ * The white point is D65. \n
303
+ \verbatim
304
+ 0 <= L <= 1 ; -1 <= uv <= +1 ; 0 <= XYZ <= 1
305
+
306
+ Y = Y / 1.0 (for D65)
307
+ if (Y > 0.008856)
308
+ fY = pow(Y, 1/3)
309
+ else
310
+ fY = 7.787 * Y + 0.16/1.16
311
+ L = 1.16 * fY - 0.16
312
+
313
+ U(x, y, z) = (4 * x)/(x + 15 * y + 3 * z)
314
+ V(x, y, z) = (9 * x)/(x + 15 * y + 3 * z)
315
+ un = U(Xn, Yn, Zn) = 0.1978 (for D65)
316
+ vn = V(Xn, Yn, Zn) = 0.4683 (for D65)
317
+ fu = U(X, Y, Z)
318
+ fv = V(X, Y, Z)
319
+
320
+ u = 13 * L * (fu - un)
321
+ v = 13 * L * (fv - vn)
322
+ \endverbatim
323
+ * \ingroup color */
324
+ inline void imColorXYZ2Luv(const float X, const float Y, const float Z,
325
+ float& L, float& u, float& v)
326
+ {
327
+ float XYZ = (float)(X + 15 * Y + 3 * Z);
328
+ float fY = Y / 1.0f;
329
+
330
+ if (XYZ != 0)
331
+ {
332
+ L = 1.16f * IM_FWLAB(fY) - 0.16f;
333
+ u = 6.5f * L * ((4 * X)/XYZ - 0.1978f);
334
+ v = 6.5f * L * ((9 * Y)/XYZ - 0.4683f);
335
+ }
336
+ else
337
+ {
338
+ L = u = v = 0;
339
+ }
340
+ }
341
+
342
+ /** Converts CIE L*u*v* (nonlinear) to CIE XYZ (linear). \n
343
+ * The white point is D65.
344
+ * 0 <= L <= 1 ; -0.5 <= uv <= +0.5 ; 0 <= XYZ <= 1 \n
345
+ * \ingroup color */
346
+ inline void imColorLuv2XYZ(const float L, const float u, const float v,
347
+ float& X, float& Y, float& Z)
348
+
349
+ {
350
+ float fY = (L + 0.16f) / 1.16f;
351
+ Y = IM_GWLAB(fY) * 1.0f;
352
+
353
+ float ul = 0.1978f, vl = 0.4683f;
354
+ if (L != 0)
355
+ {
356
+ ul = u / (6.5f * L) + 0.1978f;
357
+ vl = v / (6.5f * L) + 0.4683f;
358
+ }
359
+
360
+ X = ((9 * ul) / (4 * vl)) * Y;
361
+ Z = ((12 - 3 * ul - 20 * vl) / (4 * vl)) * Y;
362
+ }
363
+
364
+ /** Converts nonlinear values to linear values. \n
365
+ * We use the sRGB transfer function. sRGB uses ITU-R 709 primaries and D65 white point. \n
366
+ \verbatim
367
+ 0 <= l <= 1 ; 0 <= v <= 1
368
+
369
+ if (v < 0.03928)
370
+ l = v / 12.92
371
+ else
372
+ l = pow((v + 0.055) / 1.055, 2.4)
373
+ \endverbatim
374
+ * \ingroup color */
375
+ inline float imColorTransfer2Linear(const float& nonlinear_value)
376
+ {
377
+ if (nonlinear_value < 0.03928f)
378
+ return nonlinear_value / 12.92f;
379
+ else
380
+ return powf((nonlinear_value + 0.055f) / 1.055f, 2.4f);
381
+ }
382
+
383
+ /** Converts linear values to nonlinear values. \n
384
+ * We use the sRGB transfer function. sRGB uses ITU-R 709 primaries and D65 white point. \n
385
+ \verbatim
386
+ 0 <= l <= 1 ; 0 <= v <= 1
387
+
388
+ if (l < 0.0031308)
389
+ v = 12.92 * l
390
+ else
391
+ v = 1.055 * pow(l, 1/2.4) - 0.055
392
+ \endverbatim
393
+ * \ingroup color */
394
+ inline float imColorTransfer2Nonlinear(const float& value)
395
+ {
396
+ if (value < 0.0031308f)
397
+ return 12.92f * value;
398
+ else
399
+ return 1.055f * powf(value, 1.0f/2.4f) - 0.055f;
400
+ }
401
+
402
+ /** Converts RGB (linear) to R'G'B' (nonlinear).
403
+ * \ingroup color */
404
+ inline void imColorRGB2RGBNonlinear(const float RL, const float GL, const float BL,
405
+ float& R, float& G, float& B)
406
+ {
407
+ R = imColorTransfer2Nonlinear(RL);
408
+ G = imColorTransfer2Nonlinear(GL);
409
+ B = imColorTransfer2Nonlinear(BL);
410
+ }
411
+
412
+ /** Converts R'G'B' to Y' (all nonlinear). \n
413
+ \verbatim
414
+ Y' = 0.299 *R' + 0.587 *G' + 0.114 *B'
415
+ \endverbatim
416
+ * \ingroup color */
417
+ template <class T>
418
+ inline T imColorRGB2Luma(const T R, const T G, const T B)
419
+ {
420
+ return (T)((299 * R + 587 * G + 114 * B) / 1000);
421
+ }
422
+
423
+ /** Converts Luminance (CIE Y) to Lightness (CIE L*) (all linear). \n
424
+ * The white point is D65.
425
+ \verbatim
426
+ 0 <= Y <= 1 ; 0 <= L* <= 1
427
+
428
+ Y = Y / 1.0 (for D65)
429
+ if (Y > 0.008856)
430
+ fY = pow(Y, 1/3)
431
+ else
432
+ fY = 7.787 * Y + 0.16/1.16
433
+ L = 1.16 * fY - 0.16
434
+ \endverbatim
435
+ * \ingroup color */
436
+ inline float imColorLuminance2Lightness(const float& Y)
437
+ {
438
+ return 1.16f * IM_FWLAB(Y) - 0.16f;
439
+ }
440
+
441
+ /** Converts Lightness (CIE L*) to Luminance (CIE Y) (all linear). \n
442
+ * The white point is D65.
443
+ \verbatim
444
+ 0 <= Y <= 1 ; 0 <= L* <= 1
445
+
446
+ fY = (L + 0.16)/1.16
447
+ if (fY > 0.20689)
448
+ Y = pow(fY, 3)
449
+ else
450
+ Y = 0.1284 * (fY - 0.16/1.16)
451
+ Y = Y * 1.0 (for D65)
452
+ \endverbatim
453
+ * \ingroup color */
454
+ inline float imColorLightness2Luminance(const float& L)
455
+ {
456
+ float fY = (L + 0.16f) / 1.16f;
457
+ return IM_GWLAB(fY);
458
+ }
459
+
460
+ #undef IM_FWLAB
461
+ #undef IM_GWLAB
462
+ #undef IM_CROPL
463
+ #undef IM_CROPC
464
+
465
+ #endif