BrightnessContrast.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 BrightnessContrast
  8. \inqmlmodule Qt5Compat.GraphicalEffects
  9. \since QtGraphicalEffects 1.0
  10. \inherits QtQuick2::Item
  11. \ingroup qtgraphicaleffects-color
  12. \brief Adjusts brightness and contrast.
  13. This effect adjusts the source item colors.
  14. Brightness adjustment changes the perceived luminance of the source item.
  15. Contrast adjustment increases or decreases the color
  16. and brightness variations.
  17. \table
  18. \header
  19. \li Source
  20. \li Effect applied
  21. \row
  22. \li \image Original_bug.png
  23. \li \image BrightnessContrast_bug.png
  24. \endtable
  25. \section1 Example
  26. The following example shows how to apply the effect.
  27. \snippet BrightnessContrast-example.qml example
  28. */
  29. Item {
  30. id: rootItem
  31. /*!
  32. This property defines the source item that provides the source pixels
  33. for the effect.
  34. \note It is not supported to let the effect include itself, for
  35. instance by setting source to the effect's parent.
  36. */
  37. property variant source
  38. /*!
  39. This property defines how much the source brightness is increased or
  40. decreased.
  41. The value ranges from -1.0 to 1.0. By default, the property is set to \c
  42. 0.0 (no change).
  43. \table
  44. \header
  45. \li Output examples with different brightness values
  46. \li
  47. \li
  48. \row
  49. \li \image BrightnessContrast_brightness1.png
  50. \li \image BrightnessContrast_brightness2.png
  51. \li \image BrightnessContrast_brightness3.png
  52. \row
  53. \li \b { brightness: -0.25 }
  54. \li \b { brightness: 0 }
  55. \li \b { brightness: 0.5 }
  56. \row
  57. \li \l contrast: 0
  58. \li \l contrast: 0
  59. \li \l contrast: 0
  60. \endtable
  61. */
  62. property real brightness: 0.0
  63. /*!
  64. This property defines how much the source contrast is increased or
  65. decreased. The decrease of the contrast is linear, but the increase is
  66. applied with a non-linear curve to allow very high contrast adjustment at
  67. the high end of the value range.
  68. \table
  69. \header
  70. \li Contrast adjustment curve
  71. \row
  72. \li \image BrightnessContrast_contrast_graph.png
  73. \endtable
  74. The value ranges from -1.0 to 1.0. By default, the property is set to \c 0.0 (no change).
  75. \table
  76. \header
  77. \li Output examples with different contrast values
  78. \li
  79. \li
  80. \row
  81. \li \image BrightnessContrast_contrast1.png
  82. \li \image BrightnessContrast_contrast2.png
  83. \li \image BrightnessContrast_contrast3.png
  84. \row
  85. \li \b { contrast: -0.5 }
  86. \li \b { contrast: 0 }
  87. \li \b { contrast: 0.5 }
  88. \row
  89. \li \l brightness: 0
  90. \li \l brightness: 0
  91. \li \l brightness: 0
  92. \endtable
  93. */
  94. property real contrast: 0.0
  95. /*!
  96. This property allows the effect output pixels to be cached in order to
  97. improve the rendering performance.
  98. Every time the source or effect properties are changed, the pixels in
  99. the cache must be updated. Memory consumption is increased, because an
  100. extra buffer of memory is required for storing the effect output.
  101. It is recommended to disable the cache when the source or the effect
  102. properties are animated.
  103. By default, the property is set to \c false.
  104. */
  105. property bool cached: false
  106. SourceProxy {
  107. id: sourceProxy
  108. input: rootItem.source
  109. interpolation: input && input.smooth ? SourceProxy.LinearInterpolation : SourceProxy.NearestInterpolation
  110. }
  111. ShaderEffectSource {
  112. id: cacheItem
  113. anchors.fill: parent
  114. visible: rootItem.cached
  115. smooth: true
  116. sourceItem: shaderItem
  117. live: true
  118. hideSource: visible
  119. }
  120. ShaderEffect {
  121. id: shaderItem
  122. property variant source: sourceProxy.output
  123. property real brightness: rootItem.brightness
  124. property real contrast: rootItem.contrast
  125. anchors.fill: parent
  126. blending: !rootItem.cached
  127. fragmentShader: "qrc:/qt-project.org/imports/Qt5Compat/GraphicalEffects/shaders_ng/brightnesscontrast.frag.qsb"
  128. }
  129. }