HueSaturation.qml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 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 HueSaturation
  43. \inqmlmodule QtGraphicalEffects
  44. \since QtGraphicalEffects 1.0
  45. \inherits QtQuick2::Item
  46. \ingroup qtgraphicaleffects-color
  47. \brief Alters the source item colors in the HSL color space.
  48. HueSaturation is similar to the \l{QtGraphicalEffects::Colorize}{Colorize}
  49. effect, but the hue and saturation property values are handled differently.
  50. The HueSaturation effect always shifts the hue, saturation, and lightness
  51. from the original, instead of setting them.
  52. \table
  53. \header
  54. \li Source
  55. \li Effect applied
  56. \row
  57. \li \image Original_bug.png
  58. \li \image HueSaturation_bug.png
  59. \endtable
  60. \note This effect is available when running with OpenGL.
  61. \section1 Example
  62. The following example shows how to apply the effect.
  63. \snippet HueSaturation-example.qml example
  64. */
  65. Item {
  66. id: rootItem
  67. /*!
  68. This property defines the source item that provides the source pixels
  69. for the effect.
  70. \note It is not supported to let the effect include itself, for
  71. instance by setting source to the effect's parent.
  72. */
  73. property variant source: 0
  74. /*!
  75. This property defines the hue value which is added to the source hue
  76. value.
  77. The value ranges from -1.0 (decrease) to 1.0 (increase). By default, the
  78. property is set to \c 0.0 (no change).
  79. \table
  80. \header
  81. \li Output examples with different hue values
  82. \li
  83. \li
  84. \row
  85. \li \image HueSaturation_hue1.png
  86. \li \image HueSaturation_hue2.png
  87. \li \image HueSaturation_hue3.png
  88. \row
  89. \li \b { hue: -0.3 }
  90. \li \b { hue: 0.0 }
  91. \li \b { hue: 0.3 }
  92. \row
  93. \li \l saturation: 0
  94. \li \l saturation: 0
  95. \li \l saturation: 0
  96. \row
  97. \li \l lightness: 0
  98. \li \l lightness: 0
  99. \li \l lightness: 0
  100. \endtable
  101. */
  102. property real hue: 0.0
  103. /*!
  104. This property defines the saturation value value which is added to the
  105. source saturation value.
  106. The value ranges from -1.0 (decrease) to 1.0 (increase). By default, the
  107. property is set to \c 0.0 (no change).
  108. \table
  109. \header
  110. \li Output examples with different saturation values
  111. \li
  112. \li
  113. \row
  114. \li \image HueSaturation_saturation1.png
  115. \li \image HueSaturation_saturation2.png
  116. \li \image HueSaturation_saturation3.png
  117. \row
  118. \li \b { saturation: -0.8 }
  119. \li \b { saturation: 0.0 }
  120. \li \b { saturation: 1.0 }
  121. \row
  122. \li \l hue: 0
  123. \li \l hue: 0
  124. \li \l hue: 0
  125. \row
  126. \li \l lightness: 0
  127. \li \l lightness: 0
  128. \li \l lightness: 0
  129. \endtable
  130. */
  131. property real saturation: 0.0
  132. /*!
  133. This property defines the lightness value which is added to the source
  134. saturation value.
  135. The value ranges from -1.0 (decrease) to 1.0 (increase). By default, the
  136. property is set to \c 0.0 (no change).
  137. \table
  138. \header
  139. \li Output examples with different lightness values
  140. \li
  141. \li
  142. \row
  143. \li \image HueSaturation_lightness1.png
  144. \li \image HueSaturation_lightness2.png
  145. \li \image HueSaturation_lightness3.png
  146. \row
  147. \li \b { lightness: -0.5 }
  148. \li \b { lightness: 0.0 }
  149. \li \b { lightness: 0.5 }
  150. \row
  151. \li \l hue: 0
  152. \li \l hue: 0
  153. \li \l hue: 0
  154. \row
  155. \li \l saturation: 0
  156. \li \l saturation: 0
  157. \li \l saturation: 0
  158. \endtable
  159. */
  160. property real lightness: 0.0
  161. /*!
  162. This property allows the effect output pixels to be cached in order to
  163. improve the rendering performance.
  164. Every time the source or effect properties are changed, the pixels in
  165. the cache must be updated. Memory consumption is increased, because an
  166. extra buffer of memory is required for storing the effect output.
  167. It is recommended to disable the cache when the source or the effect
  168. properties are animated.
  169. By default, the property is set to \c false.
  170. */
  171. property bool cached: false
  172. SourceProxy {
  173. id: sourceProxy
  174. input: rootItem.source
  175. interpolation: input && input.smooth ? SourceProxy.LinearInterpolation : SourceProxy.NearestInterpolation
  176. }
  177. ShaderEffectSource {
  178. id: cacheItem
  179. anchors.fill: parent
  180. visible: rootItem.cached
  181. smooth: true
  182. sourceItem: shaderItem
  183. live: true
  184. hideSource: visible
  185. }
  186. ShaderEffect {
  187. id: shaderItem
  188. property variant source: sourceProxy.output
  189. property variant hsl: Qt.vector3d(rootItem.hue, rootItem.saturation, rootItem.lightness)
  190. anchors.fill: parent
  191. fragmentShader: "qrc:/qt-project.org/imports/QtGraphicalEffects/shaders/huesaturation.frag"
  192. }
  193. }