LevelAdjust.qml 13 KB

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