BrightnessContrast.qml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 BrightnessContrast
  43. \inqmlmodule QtGraphicalEffects
  44. \since QtGraphicalEffects 1.0
  45. \inherits QtQuick2::Item
  46. \ingroup qtgraphicaleffects-color
  47. \brief Adjusts brightness and contrast.
  48. This effect adjusts the source item colors.
  49. Brightness adjustment changes the perceived luminance of the source item.
  50. Contrast adjustment increases or decreases the color
  51. and brightness variations.
  52. \table
  53. \header
  54. \li Source
  55. \li Effect applied
  56. \row
  57. \li \image Original_bug.png
  58. \li \image BrightnessContrast_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 BrightnessContrast-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
  74. /*!
  75. This property defines how much the source brightness is increased or
  76. decreased.
  77. The value ranges from -1.0 to 1.0. By default, the property is set to \c
  78. 0.0 (no change).
  79. \table
  80. \header
  81. \li Output examples with different brightness values
  82. \li
  83. \li
  84. \row
  85. \li \image BrightnessContrast_brightness1.png
  86. \li \image BrightnessContrast_brightness2.png
  87. \li \image BrightnessContrast_brightness3.png
  88. \row
  89. \li \b { brightness: -0.25 }
  90. \li \b { brightness: 0 }
  91. \li \b { brightness: 0.5 }
  92. \row
  93. \li \l contrast: 0
  94. \li \l contrast: 0
  95. \li \l contrast: 0
  96. \endtable
  97. */
  98. property real brightness: 0.0
  99. /*!
  100. This property defines how much the source contrast is increased or
  101. decreased. The decrease of the contrast is linear, but the increase is
  102. applied with a non-linear curve to allow very high contrast adjustment at
  103. the high end of the value range.
  104. \table
  105. \header
  106. \li Contrast adjustment curve
  107. \row
  108. \li \image BrightnessContrast_contrast_graph.png
  109. \endtable
  110. The value ranges from -1.0 to 1.0. By default, the property is set to \c 0.0 (no change).
  111. \table
  112. \header
  113. \li Output examples with different contrast values
  114. \li
  115. \li
  116. \row
  117. \li \image BrightnessContrast_contrast1.png
  118. \li \image BrightnessContrast_contrast2.png
  119. \li \image BrightnessContrast_contrast3.png
  120. \row
  121. \li \b { contrast: -0.5 }
  122. \li \b { contrast: 0 }
  123. \li \b { contrast: 0.5 }
  124. \row
  125. \li \l brightness: 0
  126. \li \l brightness: 0
  127. \li \l brightness: 0
  128. \endtable
  129. */
  130. property real contrast: 0.0
  131. /*!
  132. This property allows the effect output pixels to be cached in order to
  133. improve the rendering performance.
  134. Every time the source or effect properties are changed, the pixels in
  135. the cache must be updated. Memory consumption is increased, because an
  136. extra buffer of memory is required for storing the effect output.
  137. It is recommended to disable the cache when the source or the effect
  138. properties are animated.
  139. By default, the property is set to \c false.
  140. */
  141. property bool cached: false
  142. SourceProxy {
  143. id: sourceProxy
  144. input: rootItem.source
  145. interpolation: input && input.smooth ? SourceProxy.LinearInterpolation : SourceProxy.NearestInterpolation
  146. }
  147. ShaderEffectSource {
  148. id: cacheItem
  149. anchors.fill: parent
  150. visible: rootItem.cached
  151. smooth: true
  152. sourceItem: shaderItem
  153. live: true
  154. hideSource: visible
  155. }
  156. ShaderEffect {
  157. id: shaderItem
  158. property variant source: sourceProxy.output
  159. property real brightness: rootItem.brightness
  160. property real contrast: rootItem.contrast
  161. anchors.fill: parent
  162. blending: !rootItem.cached
  163. fragmentShader: "qrc:/qt-project.org/imports/QtGraphicalEffects/shaders/brightnesscontrast.frag"
  164. }
  165. }