LevelAdjust.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /*****************************************************************************
  2. **
  3. ** Copyright (C) 2017 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the Qt Add-On Graphical Effects module.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. *****************************************************************************/
  39. import QtQuick 2.12
  40. import QtGraphicalEffects.private 1.12
  41. /*!
  42. \qmltype LevelAdjust
  43. \inqmlmodule QtGraphicalEffects
  44. \since QtGraphicalEffects 1.0
  45. \inherits QtQuick2::Item
  46. \ingroup qtgraphicaleffects-color
  47. \brief Adjusts color levels in the RGBA color space.
  48. This effect adjusts the source item colors separately for each color
  49. channel. Source item contrast can be adjusted and color balance altered.
  50. \table
  51. \header
  52. \li Source
  53. \li Effect applied
  54. \row
  55. \li \image Original_butterfly.png
  56. \li \image LevelAdjust_butterfly.png
  57. \endtable
  58. \note This effect is available when running with OpenGL.
  59. \section1 Example
  60. The following example shows how to apply the effect.
  61. \snippet LevelAdjust-example.qml example
  62. */
  63. Item {
  64. id: rootItem
  65. /*!
  66. This property defines the source item that provides the source pixels
  67. for the effect.
  68. \note It is not supported to let the effect include itself, for
  69. instance by setting source to the effect's parent.
  70. */
  71. property variant source
  72. /*!
  73. This property defines the change factor for how the value of each pixel
  74. color channel is altered according to the equation:
  75. \code
  76. result.rgb = pow(original.rgb, 1.0 / gamma.rgb);
  77. \endcode
  78. Setting the gamma values under QtVector3d(1.0, 1.0, 1.0) makes the image
  79. darker, the values above QtVector3d(1.0, 1.0, 1.0) lighten it.
  80. The value ranges from QtVector3d(0.0, 0.0, 0.0) (darkest) to inf
  81. (lightest). By default, the property is set to \c QtVector3d(1.0, 1.0,
  82. 1.0) (no change).
  83. \table
  84. \header
  85. \li Output examples with different gamma values
  86. \li
  87. \li
  88. \row
  89. \li \image LevelAdjust_gamma1.png
  90. \li \image LevelAdjust_gamma2.png
  91. \li \image LevelAdjust_gamma3.png
  92. \row
  93. \li \b { gamma: Qt.vector3d(1.0, 1.0, 1.0) }
  94. \li \b { gamma: Qt.vector3d(1.0, 0.4, 2.0) }
  95. \li \b { gamma: Qt.vector3d(1.0, 0.1, 4.0) }
  96. \row
  97. \li \l minimumInput: #000000
  98. \li \l minimumInput: #000000
  99. \li \l minimumInput: #000000
  100. \row
  101. \li \l maximumInput: #ffffff
  102. \li \l maximumInput: #ffffff
  103. \li \l maximumInput: #ffffff
  104. \row
  105. \li \l minimumOutput: #000000
  106. \li \l minimumOutput: #000000
  107. \li \l minimumOutput: #000000
  108. \row
  109. \li \l maximumOutput: #ffffff
  110. \li \l maximumOutput: #ffffff
  111. \li \l maximumOutput: #ffffff
  112. \endtable
  113. \table
  114. \header
  115. \li Pixel color channel luminance curves of the above images.
  116. \li
  117. \li
  118. \row
  119. \li \image LevelAdjust_default_curve.png
  120. \li \image LevelAdjust_gamma2_curve.png
  121. \li \image LevelAdjust_gamma3_curve.png
  122. \row
  123. \li X-axis: pixel original luminance
  124. \li
  125. \li
  126. \row
  127. \li Y-axis: color channel luminance with effect applied
  128. \li
  129. \li
  130. \endtable
  131. */
  132. property variant gamma: Qt.vector3d(1.0, 1.0, 1.0)
  133. /*!
  134. This property defines the minimum input level for each color channel. It
  135. sets the black-point, all pixels having lower value than this property
  136. are rendered as black (per color channel). Increasing the value darkens
  137. the dark areas.
  138. The value ranges from "#00000000" to "#ffffffff". By default, the
  139. property is set to \c "#00000000" (no change).
  140. \table
  141. \header
  142. \li Output examples with different minimumInput values
  143. \li
  144. \li
  145. \row
  146. \li \image LevelAdjust_minimumInput1.png
  147. \li \image LevelAdjust_minimumInput2.png
  148. \li \image LevelAdjust_minimumInput3.png
  149. \row
  150. \li \b { minimumInput: #00000000 }
  151. \li \b { minimumInput: #00000040 }
  152. \li \b { minimumInput: #00000070 }
  153. \row
  154. \li \l maximumInput: #ffffff
  155. \li \l maximumInput: #ffffff
  156. \li \l maximumInput: #ffffff
  157. \row
  158. \li \l minimumOutput: #000000
  159. \li \l minimumOutput: #000000
  160. \li \l minimumOutput: #000000
  161. \row
  162. \li \l maximumOutput: #ffffff
  163. \li \l maximumOutput: #ffffff
  164. \li \l maximumOutput: #ffffff
  165. \row
  166. \li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
  167. \li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
  168. \li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
  169. \endtable
  170. \table
  171. \header
  172. \li Pixel color channel luminance curves of the above images.
  173. \li
  174. \li
  175. \row
  176. \li \image LevelAdjust_default_curve.png
  177. \li \image LevelAdjust_minimumInput2_curve.png
  178. \li \image LevelAdjust_minimumInput3_curve.png
  179. \row
  180. \li X-axis: pixel original luminance
  181. \li
  182. \li
  183. \row
  184. \li Y-axis: color channel luminance with effect applied
  185. \li
  186. \li
  187. \endtable
  188. */
  189. property color minimumInput: Qt.rgba(0.0, 0.0, 0.0, 0.0)
  190. /*!
  191. This property defines the maximum input level for each color channel.
  192. It sets the white-point, all pixels having higher value than this
  193. property are rendered as white (per color channel).
  194. Decreasing the value lightens the light areas.
  195. The value ranges from "#ffffffff" to "#00000000". By default, the
  196. property is set to \c "#ffffffff" (no change).
  197. \table
  198. \header
  199. \li Output examples with different maximumInput values
  200. \li
  201. \li
  202. \row
  203. \li \image LevelAdjust_maximumInput1.png
  204. \li \image LevelAdjust_maximumInput2.png
  205. \li \image LevelAdjust_maximumInput3.png
  206. \row
  207. \li \b { maximumInput: #FFFFFFFF }
  208. \li \b { maximumInput: #FFFFFF80 }
  209. \li \b { maximumInput: #FFFFFF30 }
  210. \row
  211. \li \l minimumInput: #000000
  212. \li \l minimumInput: #000000
  213. \li \l minimumInput: #000000
  214. \row
  215. \li \l minimumOutput: #000000
  216. \li \l minimumOutput: #000000
  217. \li \l minimumOutput: #000000
  218. \row
  219. \li \l maximumOutput: #ffffff
  220. \li \l maximumOutput: #ffffff
  221. \li \l maximumOutput: #ffffff
  222. \row
  223. \li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
  224. \li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
  225. \li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
  226. \endtable
  227. \table
  228. \header
  229. \li Pixel color channel luminance curves of the above images.
  230. \li
  231. \li
  232. \row
  233. \li \image LevelAdjust_default_curve.png
  234. \li \image LevelAdjust_maximumInput2_curve.png
  235. \li \image LevelAdjust_maximumInput3_curve.png
  236. \row
  237. \li X-axis: pixel original luminance
  238. \li
  239. \li
  240. \row
  241. \li Y-axis: color channel luminance with effect applied
  242. \li
  243. \li
  244. \endtable
  245. */
  246. property color maximumInput: Qt.rgba(1.0, 1.0, 1.0, 1.0)
  247. /*!
  248. This property defines the minimum output level for each color channel.
  249. Increasing the value lightens the dark areas, reducing the contrast.
  250. The value ranges from "#00000000" to "#ffffffff". By default, the
  251. property is set to \c "#00000000" (no change).
  252. \table
  253. \header
  254. \li Output examples with different minimumOutput values
  255. \li
  256. \li
  257. \row
  258. \li \image LevelAdjust_minimumOutput1.png
  259. \li \image LevelAdjust_minimumOutput2.png
  260. \li \image LevelAdjust_minimumOutput3.png
  261. \row
  262. \li \b { minimumOutput: #00000000 }
  263. \li \b { minimumOutput: #00000070 }
  264. \li \b { minimumOutput: #000000A0 }
  265. \row
  266. \li \l minimumInput: #000000
  267. \li \l minimumInput: #000000
  268. \li \l minimumInput: #000000
  269. \row
  270. \li \l maximumInput: #ffffff
  271. \li \l maximumInput: #ffffff
  272. \li \l maximumInput: #ffffff
  273. \row
  274. \li \l maximumOutput: #ffffff
  275. \li \l maximumOutput: #ffffff
  276. \li \l maximumOutput: #ffffff
  277. \row
  278. \li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
  279. \li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
  280. \li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
  281. \endtable
  282. \table
  283. \header
  284. \li Pixel color channel luminance curves of the above images.
  285. \li
  286. \li
  287. \row
  288. \li \image LevelAdjust_default_curve.png
  289. \li \image LevelAdjust_minimumOutput2_curve.png
  290. \li \image LevelAdjust_minimumOutput3_curve.png
  291. \row
  292. \li X-axis: pixel original luminance
  293. \li
  294. \li
  295. \row
  296. \li Y-axis: color channel luminance with effect applied
  297. \li
  298. \li
  299. \endtable
  300. */
  301. property color minimumOutput: Qt.rgba(0.0, 0.0, 0.0, 0.0)
  302. /*!
  303. This property defines the maximum output level for each color channel.
  304. Decreasing the value darkens the light areas, reducing the contrast.
  305. The value ranges from "#ffffffff" to "#00000000". By default, the
  306. property is set to \c "#ffffffff" (no change).
  307. \table
  308. \header
  309. \li Output examples with different maximumOutput values
  310. \li
  311. \li
  312. \row
  313. \li \image LevelAdjust_maximumOutput1.png
  314. \li \image LevelAdjust_maximumOutput2.png
  315. \li \image LevelAdjust_maximumOutput3.png
  316. \row
  317. \li \b { maximumOutput: #FFFFFFFF }
  318. \li \b { maximumOutput: #FFFFFF80 }
  319. \li \b { maximumOutput: #FFFFFF30 }
  320. \row
  321. \li \l minimumInput: #000000
  322. \li \l minimumInput: #000000
  323. \li \l minimumInput: #000000
  324. \row
  325. \li \l maximumInput: #ffffff
  326. \li \l maximumInput: #ffffff
  327. \li \l maximumInput: #ffffff
  328. \row
  329. \li \l minimumOutput: #000000
  330. \li \l minimumOutput: #000000
  331. \li \l minimumOutput: #000000
  332. \row
  333. \li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
  334. \li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
  335. \li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
  336. \endtable
  337. \table
  338. \header
  339. \li Pixel color channel luminance curves of the above images.
  340. \li
  341. \li
  342. \row
  343. \li \image LevelAdjust_default_curve.png
  344. \li \image LevelAdjust_maximumOutput2_curve.png
  345. \li \image LevelAdjust_maximumOutput3_curve.png
  346. \row
  347. \li X-axis: pixel original luminance
  348. \li
  349. \li
  350. \row
  351. \li Y-axis: color channel luminance with effect applied
  352. \li
  353. \li
  354. \endtable
  355. */
  356. property color maximumOutput: Qt.rgba(1.0, 1.0, 1.0, 1.0)
  357. /*!
  358. This property allows the effect output pixels to be cached in order to
  359. improve the rendering performance.
  360. Every time the source or effect properties are changed, the pixels in
  361. the cache must be updated. Memory consumption is increased, because an
  362. extra buffer of memory is required for storing the effect output.
  363. It is recommended to disable the cache when the source or the effect
  364. properties are animated.
  365. By default, the property is set to \c false.
  366. */
  367. property bool cached: false
  368. SourceProxy {
  369. id: sourceProxy
  370. input: rootItem.source
  371. interpolation: input && input.smooth ? SourceProxy.LinearInterpolation : SourceProxy.NearestInterpolation
  372. }
  373. ShaderEffectSource {
  374. id: cacheItem
  375. anchors.fill: parent
  376. visible: rootItem.cached
  377. smooth: true
  378. sourceItem: shaderItem
  379. live: true
  380. hideSource: visible
  381. }
  382. ShaderEffect {
  383. id: shaderItem
  384. property variant source: sourceProxy.output
  385. property variant minimumInputRGB: Qt.vector3d(rootItem.minimumInput.r, rootItem.minimumInput.g, rootItem.minimumInput.b)
  386. property variant maximumInputRGB: Qt.vector3d(rootItem.maximumInput.r, rootItem.maximumInput.g, rootItem.maximumInput.b)
  387. property real minimumInputAlpha: rootItem.minimumInput.a
  388. property real maximumInputAlpha: rootItem.maximumInput.a
  389. property variant minimumOutputRGB: Qt.vector3d(rootItem.minimumOutput.r, rootItem.minimumOutput.g, rootItem.minimumOutput.b)
  390. property variant maximumOutputRGB: Qt.vector3d(rootItem.maximumOutput.r, rootItem.maximumOutput.g, rootItem.maximumOutput.b)
  391. property real minimumOutputAlpha: rootItem.minimumOutput.a
  392. property real maximumOutputAlpha: rootItem.maximumOutput.a
  393. property variant gamma: Qt.vector3d(1.0 / Math.max(rootItem.gamma.x, 0.0001), 1.0 / Math.max(rootItem.gamma.y, 0.0001), 1.0 / Math.max(rootItem.gamma.z, 0.0001))
  394. anchors.fill: parent
  395. fragmentShader: "qrc:/qt-project.org/imports/QtGraphicalEffects/shaders/leveladjust.frag"
  396. }
  397. }