mirror of
https://github.com/izzy2lost/docker-android.git
synced 2026-06-19 01:16:28 -07:00
Added integreation with geny cloud
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
FROM appium/appium:1.8.1-p0
|
||||
|
||||
LABEL maintainer "Budi Utomo <budi.ut.1989@gmail.com>"
|
||||
|
||||
#=============
|
||||
# Set WORKDIR
|
||||
#=============
|
||||
WORKDIR /root
|
||||
|
||||
#==================
|
||||
# General Packages
|
||||
#------------------
|
||||
# xterm
|
||||
# Terminal emulator
|
||||
# supervisor
|
||||
# Process manager
|
||||
# socat
|
||||
# Port forwarder
|
||||
#------------------
|
||||
# NoVNC Packages
|
||||
#------------------
|
||||
# x11vnc
|
||||
# VNC server for X display
|
||||
# openbox
|
||||
# Windows manager
|
||||
# menu
|
||||
# Debian menu
|
||||
# python-numpy
|
||||
# Numpy, For faster performance: https://github.com/novnc/websockify/issues/77
|
||||
# net-tools
|
||||
# Netstat
|
||||
#------------------
|
||||
# Video Recording
|
||||
#------------------
|
||||
# ffmpeg
|
||||
# Video recorder
|
||||
# jq
|
||||
# Sed for JSON data
|
||||
#==================
|
||||
RUN apt-get -qqy update && apt-get -qqy install --no-install-recommends \
|
||||
xterm \
|
||||
supervisor \
|
||||
socat \
|
||||
x11vnc \
|
||||
openbox \
|
||||
menu \
|
||||
python-numpy \
|
||||
net-tools \
|
||||
ffmpeg \
|
||||
jq \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
#=======
|
||||
# noVNC
|
||||
# Use same commit id that docker-selenium uses
|
||||
# https://github.com/elgalu/docker-selenium/blob/236b861177bd2917d864e52291114b1f5e4540d7/Dockerfile#L412-L413
|
||||
#=======
|
||||
ENV NOVNC_SHA="b403cb92fb8de82d04f305b4f14fa978003890d7" \
|
||||
WEBSOCKIFY_SHA="558a6439f14b0d85a31145541745e25c255d576b"
|
||||
RUN wget -nv -O noVNC.zip "https://github.com/kanaka/noVNC/archive/${NOVNC_SHA}.zip" \
|
||||
&& unzip -x noVNC.zip \
|
||||
&& rm noVNC.zip \
|
||||
&& mv noVNC-${NOVNC_SHA} noVNC \
|
||||
&& wget -nv -O websockify.zip "https://github.com/kanaka/websockify/archive/${WEBSOCKIFY_SHA}.zip" \
|
||||
&& unzip -x websockify.zip \
|
||||
&& mv websockify-${WEBSOCKIFY_SHA} ./noVNC/utils/websockify \
|
||||
&& rm websockify.zip \
|
||||
&& ln noVNC/vnc_auto.html noVNC/index.html
|
||||
|
||||
#================================================
|
||||
# noVNC Default Configurations
|
||||
# These Configurations can be changed through -e
|
||||
#================================================
|
||||
ENV DISPLAY=:0 \
|
||||
SCREEN=0 \
|
||||
SCREEN_WIDTH=1600 \
|
||||
SCREEN_HEIGHT=900 \
|
||||
SCREEN_DEPTH=16 \
|
||||
LOCAL_PORT=5900 \
|
||||
TARGET_PORT=6080 \
|
||||
TIMEOUT=1 \
|
||||
VIDEO_PATH=/tmp/video \
|
||||
LOG_PATH=/var/log/supervisor
|
||||
|
||||
#====================
|
||||
# Install genymotion
|
||||
#====================
|
||||
ENV GENYMOTION_VERSION=2.12.1 \
|
||||
PATH="${PATH}:/root/genymotion"
|
||||
COPY genymotion/${GENYMOTION_VERSION}/genymotion /root/genymotion
|
||||
|
||||
#=======================
|
||||
# Set default variables
|
||||
#=======================
|
||||
ENV APPIUM_LOG=$LOG_PATH/appium.log
|
||||
ENV GENYMOTION=true
|
||||
COPY genymotion/generate_config.sh /root
|
||||
RUN chmod +x /root/generate_config.sh
|
||||
|
||||
#===============
|
||||
# Expose Ports
|
||||
#---------------
|
||||
# 4723
|
||||
# Appium port
|
||||
# 6080
|
||||
# noVNC port
|
||||
# 5555
|
||||
# ADB connection port
|
||||
#===============
|
||||
EXPOSE 4723 6080 5555
|
||||
|
||||
#=======================
|
||||
# Run docker-genymotion
|
||||
#=======================
|
||||
COPY src /root/src
|
||||
COPY supervisord.conf /root/
|
||||
RUN chmod -R +x /root/src && chmod +x /root/supervisord.conf
|
||||
|
||||
CMD /usr/bin/supervisord --configuration supervisord.conf
|
||||
@@ -0,0 +1,478 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype Blend
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-blend
|
||||
\brief Merges two source items by using a blend mode.
|
||||
|
||||
Blend mode can be selected with the \l{Blend::mode}{mode} property.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li source
|
||||
\li foregroundSource
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image Original_butterfly.png
|
||||
\li \image Blend_bug_and_butterfly.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet Blend-example.qml example
|
||||
|
||||
*/
|
||||
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that is going to be the base when
|
||||
\l{Blend::foregroundSource}{foregroundSource} is blended over it.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines the item that is going to be blended over the
|
||||
\l{Blend::source}{source}.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting foregroundSource to the effect's parent.
|
||||
*/
|
||||
property variant foregroundSource
|
||||
|
||||
/*!
|
||||
This property defines the mode which is used when foregroundSource is
|
||||
blended over source. Values are case insensitive.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li mode
|
||||
\li description
|
||||
\row
|
||||
\li normal
|
||||
\li The pixel component values from foregroundSource are written
|
||||
over source by using alpha blending.
|
||||
\row
|
||||
\li addition
|
||||
\li The pixel component values from source and foregroundSource are
|
||||
added together and written.
|
||||
\row
|
||||
\li average
|
||||
\li The pixel component values from source and foregroundSource are
|
||||
averaged and written.
|
||||
\row
|
||||
\li color
|
||||
\li The lightness value from source is combined with hue and
|
||||
saturation from foregroundSource and written.
|
||||
\row
|
||||
\li colorBurn
|
||||
\li The darker pixels from source are darkened more, if both source
|
||||
and foregroundSource pixels are light the result is light.
|
||||
\row
|
||||
\li colorDodge
|
||||
\li The lighter pixels from source are lightened more, if both
|
||||
source and foregroundSource pixels are dark the result is dark.
|
||||
\row
|
||||
\li darken
|
||||
\li The darker pixel component value from source and
|
||||
foregroundSource is written.
|
||||
\row
|
||||
\li darkerColor
|
||||
\li The lower luminance pixel rgb-value from source and
|
||||
foregroundSource is written.
|
||||
\row
|
||||
\li difference
|
||||
\li The absolute pixel component value difference between source and
|
||||
foregroundSource is written.
|
||||
\row
|
||||
\li divide
|
||||
\li The pixel component values from source is divided by the value
|
||||
from foregroundSource and written.
|
||||
\row
|
||||
\li exclusion
|
||||
\li The pixel component value difference with reduced contrast
|
||||
between source and foregroundSource is written.
|
||||
\row
|
||||
\li hardLight
|
||||
\li The pixel component values from source are lightened or darkened
|
||||
according to foregroundSource values and written.
|
||||
\row
|
||||
\li hue
|
||||
\li The hue value from foregroundSource is combined with saturation
|
||||
and lightness from source and written.
|
||||
\row
|
||||
\li lighten
|
||||
\li The lightest pixel component value from source and
|
||||
foregroundSource is written.
|
||||
\row
|
||||
\li lighterColor
|
||||
\li The higher luminance pixel rgb-value from source and
|
||||
foregroundSource is written.
|
||||
\row
|
||||
\li lightness
|
||||
\li The lightness value from foregroundSource is combined with hue
|
||||
and saturation from source and written.
|
||||
\row
|
||||
\li multiply
|
||||
\li The pixel component values from source and foregroundSource are
|
||||
multiplied together and written.
|
||||
\row
|
||||
\li negation
|
||||
\li The inverted absolute pixel component value difference between
|
||||
source and foregroundSource is written.
|
||||
\row
|
||||
\li saturation
|
||||
\li The saturation value from foregroundSource is combined with hue
|
||||
and lightness from source and written.
|
||||
\row
|
||||
\li screen
|
||||
\li The pixel values from source and foregroundSource are negated,
|
||||
then multiplied, negated again, and written.
|
||||
\row
|
||||
\li subtract
|
||||
\li Pixel value from foregroundSource is subracted from source and
|
||||
written.
|
||||
\row
|
||||
\li softLight
|
||||
\li The pixel component values from source are lightened or darkened
|
||||
slightly according to foregroundSource values and written.
|
||||
|
||||
\endtable
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Example source
|
||||
\li Example foregroundSource
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image Original_butterfly.png
|
||||
\endtable
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different mode values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image Blend_mode1.png
|
||||
\li \image Blend_mode2.png
|
||||
\li \image Blend_mode3.png
|
||||
\row
|
||||
\li \b { mode: normal }
|
||||
\li \b { mode: addition }
|
||||
\li \b { mode: average }
|
||||
\row
|
||||
\li \image Blend_mode4.png
|
||||
\li \image Blend_mode5.png
|
||||
\li \image Blend_mode6.png
|
||||
\row
|
||||
\li \b { mode: color }
|
||||
\li \b { mode: colorBurn }
|
||||
\li \b { mode: colorDodge }
|
||||
\row
|
||||
\li \image Blend_mode7.png
|
||||
\li \image Blend_mode8.png
|
||||
\li \image Blend_mode9.png
|
||||
\row
|
||||
\li \b { mode: darken }
|
||||
\li \b { mode: darkerColor }
|
||||
\li \b { mode: difference }
|
||||
\row
|
||||
\li \image Blend_mode10.png
|
||||
\li \image Blend_mode11.png
|
||||
\li \image Blend_mode12.png
|
||||
\row
|
||||
\li \b { mode: divide }
|
||||
\li \b { mode: exclusion }
|
||||
\li \b { mode: hardlight }
|
||||
\row
|
||||
\li \image Blend_mode13.png
|
||||
\li \image Blend_mode14.png
|
||||
\li \image Blend_mode15.png
|
||||
\row
|
||||
\li \b { mode: hue }
|
||||
\li \b { mode: lighten }
|
||||
\li \b { mode: lighterColor }
|
||||
\row
|
||||
\li \image Blend_mode16.png
|
||||
\li \image Blend_mode17.png
|
||||
\li \image Blend_mode18.png
|
||||
\row
|
||||
\li \b { mode: lightness }
|
||||
\li \b { mode: negation }
|
||||
\li \b { mode: multiply }
|
||||
\row
|
||||
\li \image Blend_mode19.png
|
||||
\li \image Blend_mode20.png
|
||||
\li \image Blend_mode21.png
|
||||
\row
|
||||
\li \b { mode: saturation }
|
||||
\li \b { mode: screen }
|
||||
\li \b { mode: subtract }
|
||||
\row
|
||||
\li \image Blend_mode22.png
|
||||
\row
|
||||
\li \b { mode: softLight }
|
||||
\endtable
|
||||
*/
|
||||
property string mode: "normal"
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in the
|
||||
cache must be updated. Memory consumption is increased, because an extra
|
||||
buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: backgroundSourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
SourceProxy {
|
||||
id: foregroundSourceProxy
|
||||
input: rootItem.foregroundSource
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: parent
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
property variant backgroundSource: backgroundSourceProxy.output
|
||||
property variant foregroundSource: foregroundSourceProxy.output
|
||||
property string mode: rootItem.mode
|
||||
anchors.fill: parent
|
||||
|
||||
fragmentShader: fragmentShaderBegin + blendModeNormal + fragmentShaderEnd
|
||||
|
||||
function buildFragmentShader() {
|
||||
var shader = fragmentShaderBegin
|
||||
|
||||
switch (mode.toLowerCase()) {
|
||||
case "addition" : shader += blendModeAddition; break;
|
||||
case "average" : shader += blendModeAverage; break;
|
||||
case "color" : shader += blendModeColor; break;
|
||||
case "colorburn" : shader += blendModeColorBurn; break;
|
||||
case "colordodge" : shader += blendModeColorDodge; break;
|
||||
case "darken" : shader += blendModeDarken; break;
|
||||
case "darkercolor" : shader += blendModeDarkerColor; break;
|
||||
case "difference" : shader += blendModeDifference; break;
|
||||
case "divide" : shader += blendModeDivide; break;
|
||||
case "exclusion" : shader += blendModeExclusion; break;
|
||||
case "hardlight" : shader += blendModeHardLight; break;
|
||||
case "hue" : shader += blendModeHue; break;
|
||||
case "lighten" : shader += blendModeLighten; break;
|
||||
case "lightercolor" : shader += blendModeLighterColor; break;
|
||||
case "lightness" : shader += blendModeLightness; break;
|
||||
case "negation" : shader += blendModeNegation; break;
|
||||
case "normal" : shader += blendModeNormal; break;
|
||||
case "multiply" : shader += blendModeMultiply; break;
|
||||
case "saturation" : shader += blendModeSaturation; break;
|
||||
case "screen" : shader += blendModeScreen; break;
|
||||
case "subtract" : shader += blendModeSubtract; break;
|
||||
case "softlight" : shader += blendModeSoftLight; break;
|
||||
default: shader += "gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);"; break;
|
||||
}
|
||||
|
||||
shader += fragmentShaderEnd
|
||||
fragmentShader = shader
|
||||
|
||||
// Workaraound for a bug just to make sure display gets updated when the mode changes.
|
||||
backgroundSourceChanged()
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
buildFragmentShader()
|
||||
}
|
||||
|
||||
onModeChanged: {
|
||||
buildFragmentShader()
|
||||
}
|
||||
|
||||
property string blendModeAddition: "result.rgb = min(rgb1 + rgb2, 1.0);"
|
||||
property string blendModeAverage: "result.rgb = 0.5 * (rgb1 + rgb2);"
|
||||
property string blendModeColor: "result.rgb = HSLtoRGB(vec3(RGBtoHSL(rgb2).xy, RGBtoL(rgb1)));"
|
||||
property string blendModeColorBurn: "result.rgb = clamp(1.0 - ((1.0 - rgb1) / max(vec3(1.0 / 256.0), rgb2)), vec3(0.0), vec3(1.0));"
|
||||
property string blendModeColorDodge: "result.rgb = clamp(rgb1 / max(vec3(1.0 / 256.0), (1.0 - rgb2)), vec3(0.0), vec3(1.0));"
|
||||
property string blendModeDarken: "result.rgb = min(rgb1, rgb2);"
|
||||
property string blendModeDarkerColor: "result.rgb = 0.3 * rgb1.r + 0.59 * rgb1.g + 0.11 * rgb1.b > 0.3 * rgb2.r + 0.59 * rgb2.g + 0.11 * rgb2.b ? rgb2 : rgb1;"
|
||||
property string blendModeDifference: "result.rgb = abs(rgb1 - rgb2);"
|
||||
property string blendModeDivide: "result.rgb = clamp(rgb1 / rgb2, 0.0, 1.0);"
|
||||
property string blendModeExclusion: "result.rgb = rgb1 + rgb2 - 2.0 * rgb1 * rgb2;"
|
||||
property string blendModeHardLight: "result.rgb = vec3(channelBlendHardLight(rgb1.r, rgb2.r), channelBlendHardLight(rgb1.g, rgb2.g), channelBlendHardLight(rgb1.b, rgb2.b));"
|
||||
property string blendModeHue: "result.rgb = HSLtoRGB(vec3(RGBtoHSL(rgb2).x, RGBtoHSL(rgb1).yz));"
|
||||
property string blendModeLighten: "result.rgb = max(rgb1, rgb2);"
|
||||
property string blendModeLighterColor: "result.rgb = 0.3 * rgb1.r + 0.59 * rgb1.g + 0.11 * rgb1.b > 0.3 * rgb2.r + 0.59 * rgb2.g + 0.11 * rgb2.b ? rgb1 : rgb2;"
|
||||
property string blendModeLightness: "result.rgb = HSLtoRGB(vec3(RGBtoHSL(rgb1).xy, RGBtoL(rgb2)));"
|
||||
property string blendModeMultiply: "result.rgb = rgb1 * rgb2;"
|
||||
property string blendModeNegation: "result.rgb = 1.0 - abs(1.0 - rgb1 - rgb2);"
|
||||
property string blendModeNormal: "result.rgb = rgb2; a = max(color1.a, color2.a);"
|
||||
property string blendModeSaturation: "lowp vec3 hsl1 = RGBtoHSL(rgb1); result.rgb = HSLtoRGB(vec3(hsl1.x, RGBtoHSL(rgb2).y, hsl1.z));"
|
||||
property string blendModeScreen: "result.rgb = 1.0 - (vec3(1.0) - rgb1) * (vec3(1.0) - rgb2);"
|
||||
property string blendModeSubtract: "result.rgb = max(rgb1 - rgb2, vec3(0.0));"
|
||||
property string blendModeSoftLight: "result.rgb = rgb1 * ((1.0 - rgb1) * rgb2 + (1.0 - (1.0 - rgb1) * (1.0 - rgb2)));"
|
||||
|
||||
property string fragmentShaderBegin: "
|
||||
varying mediump vec2 qt_TexCoord0;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform lowp sampler2D backgroundSource;
|
||||
uniform lowp sampler2D foregroundSource;
|
||||
|
||||
highp float RGBtoL(highp vec3 color) {
|
||||
highp float cmin = min(color.r, min(color.g, color.b));
|
||||
highp float cmax = max(color.r, max(color.g, color.b));
|
||||
highp float l = (cmin + cmax) / 2.0;
|
||||
return l;
|
||||
}
|
||||
|
||||
highp vec3 RGBtoHSL(highp vec3 color) {
|
||||
highp float cmin = min(color.r, min(color.g, color.b));
|
||||
highp float cmax = max(color.r, max(color.g, color.b));
|
||||
highp float h = 0.0;
|
||||
highp float s = 0.0;
|
||||
highp float l = (cmin + cmax) / 2.0;
|
||||
highp float diff = cmax - cmin;
|
||||
|
||||
if (diff > 1.0 / 256.0) {
|
||||
if (l < 0.5)
|
||||
s = diff / (cmin + cmax);
|
||||
else
|
||||
s = diff / (2.0 - (cmin + cmax));
|
||||
|
||||
if (color.r == cmax)
|
||||
h = (color.g - color.b) / diff;
|
||||
else if (color.g == cmax)
|
||||
h = 2.0 + (color.b - color.r) / diff;
|
||||
else
|
||||
h = 4.0 + (color.r - color.g) / diff;
|
||||
|
||||
h /= 6.0;
|
||||
}
|
||||
return vec3(h, s, l);
|
||||
}
|
||||
|
||||
highp float hueToIntensity(highp float v1, highp float v2, highp float h) {
|
||||
h = fract(h);
|
||||
if (h < 1.0 / 6.0)
|
||||
return v1 + (v2 - v1) * 6.0 * h;
|
||||
else if (h < 1.0 / 2.0)
|
||||
return v2;
|
||||
else if (h < 2.0 / 3.0)
|
||||
return v1 + (v2 - v1) * 6.0 * (2.0 / 3.0 - h);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
highp vec3 HSLtoRGB(highp vec3 color) {
|
||||
highp float h = color.x;
|
||||
highp float l = color.z;
|
||||
highp float s = color.y;
|
||||
|
||||
if (s < 1.0 / 256.0)
|
||||
return vec3(l, l, l);
|
||||
|
||||
highp float v1;
|
||||
highp float v2;
|
||||
if (l < 0.5)
|
||||
v2 = l * (1.0 + s);
|
||||
else
|
||||
v2 = (l + s) - (s * l);
|
||||
|
||||
v1 = 2.0 * l - v2;
|
||||
|
||||
highp float d = 1.0 / 3.0;
|
||||
highp float r = hueToIntensity(v1, v2, h + d);
|
||||
highp float g = hueToIntensity(v1, v2, h);
|
||||
highp float b = hueToIntensity(v1, v2, h - d);
|
||||
return vec3(r, g, b);
|
||||
}
|
||||
|
||||
lowp float channelBlendHardLight(lowp float c1, lowp float c2) {
|
||||
return c2 > 0.5 ? (1.0 - (1.0 - 2.0 * (c2 - 0.5)) * (1.0 - c1)) : (2.0 * c1 * c2);
|
||||
}
|
||||
|
||||
void main() {
|
||||
lowp vec4 result = vec4(0.0);
|
||||
lowp vec4 color1 = texture2D(backgroundSource, qt_TexCoord0);
|
||||
lowp vec4 color2 = texture2D(foregroundSource, qt_TexCoord0);
|
||||
lowp vec3 rgb1 = color1.rgb / max(1.0/256.0, color1.a);
|
||||
lowp vec3 rgb2 = color2.rgb / max(1.0/256.0, color2.a);
|
||||
highp float a = max(color1.a, color1.a * color2.a);
|
||||
"
|
||||
|
||||
property string fragmentShaderEnd: "
|
||||
gl_FragColor.rgb = mix(rgb1, result.rgb, color2.a);
|
||||
gl_FragColor.rbg *= a;
|
||||
gl_FragColor.a = a;
|
||||
gl_FragColor *= qt_Opacity;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype BrightnessContrast
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-color
|
||||
\brief Adjusts brightness and contrast.
|
||||
|
||||
This effect adjusts the source item colors.
|
||||
Brightness adjustment changes the perceived luminance of the source item.
|
||||
Contrast adjustment increases or decreases the color
|
||||
and brightness variations.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image BrightnessContrast_bug.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet BrightnessContrast-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that provides the source pixels
|
||||
for the effect.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines how much the source brightness is increased or
|
||||
decreased.
|
||||
|
||||
The value ranges from -1.0 to 1.0. By default, the property is set to \c
|
||||
0.0 (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different brightness values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image BrightnessContrast_brightness1.png
|
||||
\li \image BrightnessContrast_brightness2.png
|
||||
\li \image BrightnessContrast_brightness3.png
|
||||
\row
|
||||
\li \b { brightness: -0.25 }
|
||||
\li \b { brightness: 0 }
|
||||
\li \b { brightness: 0.5 }
|
||||
\row
|
||||
\li \l contrast: 0
|
||||
\li \l contrast: 0
|
||||
\li \l contrast: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real brightness: 0.0
|
||||
|
||||
/*!
|
||||
This property defines how much the source contrast is increased or
|
||||
decreased. The decrease of the contrast is linear, but the increase is
|
||||
applied with a non-linear curve to allow very high contrast adjustment at
|
||||
the high end of the value range.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Contrast adjustment curve
|
||||
\row
|
||||
\li \image BrightnessContrast_contrast_graph.png
|
||||
\endtable
|
||||
|
||||
The value ranges from -1.0 to 1.0. By default, the property is set to \c 0.0 (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different contrast values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image BrightnessContrast_contrast1.png
|
||||
\li \image BrightnessContrast_contrast2.png
|
||||
\li \image BrightnessContrast_contrast3.png
|
||||
\row
|
||||
\li \b { contrast: -0.5 }
|
||||
\li \b { contrast: 0 }
|
||||
\li \b { contrast: 0.5 }
|
||||
\row
|
||||
\li \l brightness: 0
|
||||
\li \l brightness: 0
|
||||
\li \l brightness: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real contrast: 0.0
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: parent
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
property variant source: sourceProxy.output
|
||||
property real brightness: rootItem.brightness
|
||||
property real contrast: rootItem.contrast
|
||||
|
||||
anchors.fill: parent
|
||||
blending: !rootItem.cached
|
||||
|
||||
fragmentShader: "
|
||||
varying mediump vec2 qt_TexCoord0;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform lowp sampler2D source;
|
||||
uniform highp float brightness;
|
||||
uniform highp float contrast;
|
||||
void main() {
|
||||
highp vec4 pixelColor = texture2D(source, qt_TexCoord0);
|
||||
pixelColor.rgb /= max(1.0/256.0, pixelColor.a);
|
||||
highp float c = 1.0 + contrast;
|
||||
highp float contrastGainFactor = 1.0 + c * c * c * c * step(0.0, contrast);
|
||||
pixelColor.rgb = ((pixelColor.rgb - 0.5) * (contrastGainFactor * contrast + 1.0)) + 0.5;
|
||||
pixelColor.rgb = mix(pixelColor.rgb, vec3(step(0.0, brightness)), abs(brightness));
|
||||
gl_FragColor = vec4(pixelColor.rgb * pixelColor.a, pixelColor.a) * qt_Opacity;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype ColorOverlay
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-color
|
||||
\brief Alters the colors of the source item by applying an overlay color.
|
||||
|
||||
The effect is similar to what happens when a colorized glass is put on top
|
||||
of a grayscale image. The color for the overlay is given in the RGBA format.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_butterfly.png
|
||||
\li \image ColorOverlay_butterfly.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet ColorOverlay-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that provides the source pixels
|
||||
for the effect.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines the RGBA color value which is used to colorize the
|
||||
source.
|
||||
|
||||
By default, the property is set to \c "transparent".
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different color values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image ColorOverlay_color1.png
|
||||
\li \image ColorOverlay_color2.png
|
||||
\li \image ColorOverlay_color3.png
|
||||
\row
|
||||
\li \b { color: #80ff0000 }
|
||||
\li \b { color: #8000ff00 }
|
||||
\li \b { color: #800000ff }
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property color color: "transparent"
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: parent
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
property variant source: sourceProxy.output
|
||||
property color color: rootItem.color
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
fragmentShader: "
|
||||
varying mediump vec2 qt_TexCoord0;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform lowp sampler2D source;
|
||||
uniform highp vec4 color;
|
||||
void main() {
|
||||
highp vec4 pixelColor = texture2D(source, qt_TexCoord0);
|
||||
gl_FragColor = vec4(mix(pixelColor.rgb/max(pixelColor.a, 0.00390625), color.rgb/max(color.a, 0.00390625), color.a) * pixelColor.a, pixelColor.a) * qt_Opacity;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype Colorize
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-color
|
||||
\brief Sets the color in the HSL color space.
|
||||
|
||||
The effect is similar to what happens when a colorized glass is put on top
|
||||
of a grayscale image. Colorize uses the hue, saturation, and lightness (HSL)
|
||||
color space. You can specify a desired value for each property. You can
|
||||
shift all HSL values with the
|
||||
\l{QtGraphicalEffects1::HueSaturation}{HueSaturation} effect.
|
||||
|
||||
Alternatively, you can use the
|
||||
\l{QtGraphicalEffects1::ColorOverlay}{ColorOverlay} effect to colorize the
|
||||
source item in the RGBA color space.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image Colorize_bug.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet Colorize-example.qml example
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that provides the source pixels
|
||||
for the effect.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines the hue value which is used to colorize the
|
||||
source.
|
||||
|
||||
The value ranges from 0.0 to 1.0. By default, the property is set to \c
|
||||
0.0, which produces a slightly red color.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Allowed hue values
|
||||
\row
|
||||
\li \image Colorize_hue_scale.png
|
||||
\endtable
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different hue values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image Colorize_hue1.png
|
||||
\li \image Colorize_hue2.png
|
||||
\li \image Colorize_hue3.png
|
||||
\row
|
||||
\li \b { hue: 0.2 }
|
||||
\li \b { hue: 0.5 }
|
||||
\li \b { hue: 0.8 }
|
||||
\row
|
||||
\li \l saturation: 1
|
||||
\li \l saturation: 1
|
||||
\li \l saturation: 1
|
||||
\row
|
||||
\li \l lightness: 0
|
||||
\li \l lightness: 0
|
||||
\li \l lightness: 0
|
||||
\endtable
|
||||
*/
|
||||
property real hue: 0.0
|
||||
|
||||
/*!
|
||||
This property defines the saturation value which is used to colorize the
|
||||
source.
|
||||
|
||||
The value ranges from 0.0 (desaturated) to 1.0 (saturated). By default,
|
||||
the property is set to \c 1.0 (saturated).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different saturation values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image Colorize_saturation1.png
|
||||
\li \image Colorize_saturation2.png
|
||||
\li \image Colorize_saturation3.png
|
||||
\row
|
||||
\li \b { saturation: 0 }
|
||||
\li \b { saturation: 0.5 }
|
||||
\li \b { saturation: 1 }
|
||||
\row
|
||||
\li \l hue: 0
|
||||
\li \l hue: 0
|
||||
\li \l hue: 0
|
||||
\row
|
||||
\li \l lightness: 0
|
||||
\li \l lightness: 0
|
||||
\li \l lightness: 0
|
||||
\endtable
|
||||
*/
|
||||
property real saturation: 1.0
|
||||
|
||||
/*!
|
||||
This property defines how much the source lightness value is increased
|
||||
or decreased.
|
||||
|
||||
Unlike hue and saturation properties, lightness does not set the used
|
||||
value, but it shifts the existing source pixel lightness value.
|
||||
|
||||
The value ranges from -1.0 (decreased) to 1.0 (increased). By default,
|
||||
the property is set to \c 0.0 (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different lightness values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image Colorize_lightness1.png
|
||||
\li \image Colorize_lightness2.png
|
||||
\li \image Colorize_lightness3.png
|
||||
\row
|
||||
\li \b { lightness: -0.75 }
|
||||
\li \b { lightness: 0 }
|
||||
\li \b { lightness: 0.75 }
|
||||
\row
|
||||
\li \l hue: 0
|
||||
\li \l hue: 0
|
||||
\li \l hue: 0
|
||||
\row
|
||||
\li \l saturation: 1
|
||||
\li \l saturation: 1
|
||||
\li \l saturation: 1
|
||||
\endtable
|
||||
*/
|
||||
property real lightness: 0.0
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: parent
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
property variant source: sourceProxy.output
|
||||
property real hue: rootItem.hue
|
||||
property real saturation: rootItem.saturation
|
||||
property real lightness: rootItem.lightness
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
fragmentShader: "
|
||||
varying mediump vec2 qt_TexCoord0;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform lowp sampler2D source;
|
||||
uniform highp float hue;
|
||||
uniform highp float saturation;
|
||||
uniform highp float lightness;
|
||||
|
||||
highp float RGBtoL(highp vec3 color) {
|
||||
highp float cmin = min(color.r, min(color.g, color.b));
|
||||
highp float cmax = max(color.r, max(color.g, color.b));
|
||||
highp float l = (cmin + cmax) / 2.0;
|
||||
return l;
|
||||
}
|
||||
|
||||
highp float hueToIntensity(highp float v1, highp float v2, highp float h) {
|
||||
h = fract(h);
|
||||
if (h < 1.0 / 6.0)
|
||||
return v1 + (v2 - v1) * 6.0 * h;
|
||||
else if (h < 1.0 / 2.0)
|
||||
return v2;
|
||||
else if (h < 2.0 / 3.0)
|
||||
return v1 + (v2 - v1) * 6.0 * (2.0 / 3.0 - h);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
highp vec3 HSLtoRGB(highp vec3 color) {
|
||||
highp float h = color.x;
|
||||
highp float l = color.z;
|
||||
highp float s = color.y;
|
||||
|
||||
if (s < 1.0 / 256.0)
|
||||
return vec3(l, l, l);
|
||||
|
||||
highp float v1;
|
||||
highp float v2;
|
||||
if (l < 0.5)
|
||||
v2 = l * (1.0 + s);
|
||||
else
|
||||
v2 = (l + s) - (s * l);
|
||||
|
||||
v1 = 2.0 * l - v2;
|
||||
|
||||
highp float d = 1.0 / 3.0;
|
||||
highp float r = hueToIntensity(v1, v2, h + d);
|
||||
highp float g = hueToIntensity(v1, v2, h);
|
||||
highp float b = hueToIntensity(v1, v2, h - d);
|
||||
return vec3(r, g, b);
|
||||
}
|
||||
|
||||
void main() {
|
||||
lowp vec4 sample = texture2D(source, qt_TexCoord0);
|
||||
sample = vec4(sample.rgb / max(1.0/256.0, sample.a), sample.a);
|
||||
highp float light = RGBtoL(sample.rgb);
|
||||
highp float c = step(0.0, lightness);
|
||||
sample.rgb = HSLtoRGB(vec3(hue, saturation, mix(light, c, abs(lightness))));
|
||||
gl_FragColor = vec4(sample.rgb * sample.a, sample.a) * qt_Opacity;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype ConicalGradient
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-gradient
|
||||
\brief Draws a conical gradient.
|
||||
|
||||
A gradient is defined by two or more colors, which are blended seamlessly.
|
||||
The colors start from the specified angle and end at 360 degrees larger
|
||||
angle value.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image ConicalGradient.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet ConicalGradient-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
/*!
|
||||
This property defines the starting angle where the color at the gradient
|
||||
position of 0.0 is rendered. Colors at larger position values are
|
||||
rendered into larger angle values and blended seamlessly. Angle values
|
||||
increase clockwise.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different angle values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image ConicalGradient_angle1.png
|
||||
\li \image ConicalGradient_angle2.png
|
||||
\li \image ConicalGradient_angle3.png
|
||||
\row
|
||||
\li \b { angle: 0 }
|
||||
\li \b { angle: 45 }
|
||||
\li \b { angle: 185 }
|
||||
\row
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\row
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real angle: 0.0
|
||||
|
||||
/*!
|
||||
\qmlproperty real QtGraphicalEffects1::ConicalGradient::horizontalOffset
|
||||
\qmlproperty real QtGraphicalEffects1::ConicalGradient::verticalOffset
|
||||
|
||||
The horizontalOffset and verticalOffset properties define the offset in
|
||||
pixels for the center point of the gradient compared to the item center.
|
||||
|
||||
The value ranges from -inf to inf. By default, the properties are set to \c
|
||||
0.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different horizontalOffset values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image ConicalGradient_horizontalOffset1.png
|
||||
\li \image ConicalGradient_horizontalOffset2.png
|
||||
\li \image ConicalGradient_horizontalOffset3.png
|
||||
\row
|
||||
\li \b { horizontalOffset: -50 }
|
||||
\li \b { horizontalOffset: 0 }
|
||||
\li \b { horizontalOffset: 50 }
|
||||
\row
|
||||
\li \l angle: 0
|
||||
\li \l angle: 0
|
||||
\li \l angle: 0
|
||||
\row
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\endtable
|
||||
*/
|
||||
property real horizontalOffset: 0.0
|
||||
property real verticalOffset: 0.0
|
||||
|
||||
/*!
|
||||
This property defines the item that is going to be filled with gradient.
|
||||
Source item gets rendered into an intermediate pixel buffer and the
|
||||
alpha values from the result are used to determine the gradient's pixels
|
||||
visibility in the display. The default value for source is undefined and
|
||||
in that case whole effect area is filled with gradient.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different source values
|
||||
\li
|
||||
\row
|
||||
\li \image ConicalGradient_maskSource1.png
|
||||
\li \image ConicalGradient_maskSource2.png
|
||||
\row
|
||||
\li \b { source: undefined }
|
||||
\li \b { source: }
|
||||
\row
|
||||
\li \l angle: 0
|
||||
\li \l angle: 0
|
||||
\row
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\row
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\endtable
|
||||
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
A gradient is defined by two or more colors, which are blended seamlessly.
|
||||
The colors are specified as a set of GradientStop child items, each of which
|
||||
defines a position on the gradient (from 0.0 to 1.0), and a color.
|
||||
The position of each GradientStop is defined by the position property.
|
||||
The color is defined by the color property.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different gradient values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image ConicalGradient_gradient1.png
|
||||
\li \image ConicalGradient_gradient2.png
|
||||
\li \image ConicalGradient_gradient3.png
|
||||
\row
|
||||
\li \b {gradient:} \code
|
||||
Gradient {
|
||||
GradientStop { position: 0.000
|
||||
color: Qt.rgba(1, 0, 0, 1) }
|
||||
GradientStop { position: 0.167;
|
||||
color: Qt.rgba(1, 1, 0, 1) }
|
||||
GradientStop { position: 0.333;
|
||||
color: Qt.rgba(0, 1, 0, 1) }
|
||||
GradientStop { position: 0.500;
|
||||
color: Qt.rgba(0, 1, 1, 1) }
|
||||
GradientStop { position: 0.667;
|
||||
color: Qt.rgba(0, 0, 1, 1) }
|
||||
GradientStop { position: 0.833;
|
||||
color: Qt.rgba(1, 0, 1, 1) }
|
||||
GradientStop { position: 1.000;
|
||||
color: Qt.rgba(1, 0, 0, 1) }
|
||||
}
|
||||
\endcode
|
||||
\li \b {gradient:} \code
|
||||
Gradient {
|
||||
GradientStop { position: 0.0
|
||||
color: "#F0F0F0"
|
||||
}
|
||||
GradientStop { position: 0.5
|
||||
color: "#000000"
|
||||
}
|
||||
GradientStop { position: 1.0
|
||||
color: "#F0F0F0"
|
||||
}
|
||||
}
|
||||
\endcode
|
||||
\li \b {gradient:} \code
|
||||
Gradient {
|
||||
GradientStop { position: 0.0
|
||||
color: "#00000000"
|
||||
}
|
||||
GradientStop { position: 1.0
|
||||
color: "#FF000000"
|
||||
}
|
||||
}
|
||||
\endcode
|
||||
\row
|
||||
\li \l angle: 0
|
||||
\li \l angle: 0
|
||||
\li \l angle: 0
|
||||
\row
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\row
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property Gradient gradient: Gradient {
|
||||
GradientStop { position: 0.0; color: "white" }
|
||||
GradientStop { position: 1.0; color: "black" }
|
||||
}
|
||||
|
||||
SourceProxy {
|
||||
id: maskSourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: gradientRect
|
||||
width: 16
|
||||
height: 256
|
||||
gradient: rootItem.gradient
|
||||
smooth: true
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: parent
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
rotation: shaderItem.rotation
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
property variant gradientSource: ShaderEffectSource {
|
||||
sourceItem: gradientRect
|
||||
smooth: true
|
||||
hideSource: true
|
||||
visible: false
|
||||
}
|
||||
property variant maskSource: maskSourceProxy.output
|
||||
property real startAngle: (rootItem.angle - 90) * Math.PI/180
|
||||
property variant center: Qt.point(0.5 + horizontalOffset / width, 0.5 + verticalOffset / height)
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
fragmentShader: maskSource == undefined ? noMaskShader : maskShader
|
||||
|
||||
onFragmentShaderChanged: startAngleChanged()
|
||||
|
||||
property string noMaskShader: "
|
||||
varying mediump vec2 qt_TexCoord0;
|
||||
uniform lowp sampler2D gradientSource;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform highp float startAngle;
|
||||
uniform highp vec2 center;
|
||||
|
||||
void main() {
|
||||
const highp float PI = 3.14159265;
|
||||
const highp float PIx2inv = 0.1591549;
|
||||
highp float a = (atan((center.y - qt_TexCoord0.t), (center.x - qt_TexCoord0.s)) + PI - startAngle) * PIx2inv;
|
||||
gl_FragColor = texture2D(gradientSource, vec2(0.0, fract(a))) * qt_Opacity;
|
||||
}
|
||||
"
|
||||
|
||||
property string maskShader: "
|
||||
varying mediump vec2 qt_TexCoord0;
|
||||
uniform lowp sampler2D gradientSource;
|
||||
uniform lowp sampler2D maskSource;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform highp float startAngle;
|
||||
uniform highp vec2 center;
|
||||
|
||||
void main() {
|
||||
lowp float maskAlpha = texture2D(maskSource, qt_TexCoord0).a;
|
||||
const highp float PI = 3.14159265;
|
||||
const highp float PIx2inv = 0.1591549;
|
||||
highp float a = (atan((center.y - qt_TexCoord0.t), (center.x - qt_TexCoord0.s)) + PI - startAngle) * PIx2inv;
|
||||
gl_FragColor = texture2D(gradientSource, vec2(0.0, fract(a))) * maskAlpha * qt_Opacity;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype Desaturate
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-color
|
||||
\brief Reduces the saturation of the colors.
|
||||
|
||||
Desaturated pixel values are calculated as averages of the original RGB
|
||||
component values of the source item.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image Desaturate_bug.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet Desaturate-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that provides the source pixels to
|
||||
the effect.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines how much the source colors are desaturated.
|
||||
|
||||
The value ranges from 0.0 (no change) to 1.0 (desaturated). By default,
|
||||
the property is set to \c 0.0 (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different desaturation values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image Desaturate_desaturation1.png
|
||||
\li \image Desaturate_desaturation2.png
|
||||
\li \image Desaturate_desaturation3.png
|
||||
\row
|
||||
\li \b { desaturation: 0.0 }
|
||||
\li \b { desaturation: 0.5 }
|
||||
\li \b { desaturation: 1.0 }
|
||||
\endtable
|
||||
*/
|
||||
property real desaturation: 0.0
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: parent
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
property variant source: sourceProxy.output
|
||||
property real desaturation: rootItem.desaturation
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
fragmentShader: "
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform lowp sampler2D source;
|
||||
uniform highp float desaturation;
|
||||
void main(void) {
|
||||
lowp vec4 textureColor = texture2D(source, qt_TexCoord0.st);
|
||||
lowp float grayColor = (textureColor.r + textureColor.g + textureColor.b) / 3.0;
|
||||
gl_FragColor = mix(textureColor, vec4(vec3(grayColor), textureColor.a), desaturation) * qt_Opacity;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype DirectionalBlur
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-motion-blur
|
||||
\brief Applies blur effect to the specified direction.
|
||||
|
||||
Effect creates perceived impression that the source item appears to be
|
||||
moving in the direction of the blur. Blur is applied to both sides of
|
||||
each pixel, therefore setting the direction to 0 and 180 provides the
|
||||
same result.
|
||||
|
||||
Other available motionblur effects are \l{QtGraphicalEffects1::ZoomBlur}{ZoomBlur} and
|
||||
\l{QtGraphicalEffects1::RadialBlur}{RadialBlur}.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image DirectionalBlur_bug.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet DirectionalBlur-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that is going to be blurred.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines the percieved amount of movement for each pixel.
|
||||
The movement is divided evenly to both sides of each pixel.
|
||||
|
||||
The quality of the blur depends on \l{DirectionalBlur::samples}{samples}
|
||||
property. If length value is large, more samples are needed to keep the
|
||||
visual quality at high level.
|
||||
|
||||
The value ranges from 0.0 to inf.
|
||||
By default the property is set to \c 0.0 (no blur).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different length values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image DirectionalBlur_length1.png
|
||||
\li \image DirectionalBlur_length2.png
|
||||
\li \image DirectionalBlur_length3.png
|
||||
\row
|
||||
\li \b { length: 0.0 }
|
||||
\li \b { length: 32.0 }
|
||||
\li \b { length: 48.0 }
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l angle: 0
|
||||
\li \l angle: 0
|
||||
\li \l angle: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real length: 0.0
|
||||
|
||||
/*!
|
||||
This property defines how many samples are taken per pixel when blur
|
||||
calculation is done. Larger value produces better quality, but is slower
|
||||
to render.
|
||||
|
||||
This property is not intended to be animated. Changing this property may
|
||||
cause the underlying OpenGL shaders to be recompiled.
|
||||
|
||||
Allowed values are between 0 and inf (practical maximum depends on GPU).
|
||||
By default the property is set to \c 0 (no samples).
|
||||
|
||||
*/
|
||||
property int samples: 0
|
||||
|
||||
/*!
|
||||
This property defines the direction for the blur. Blur is applied to
|
||||
both sides of each pixel, therefore setting the direction to 0 and 180
|
||||
produces the same result.
|
||||
|
||||
The value ranges from -180.0 to 180.0.
|
||||
By default the property is set to \c 0.0.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different angle values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image DirectionalBlur_angle1.png
|
||||
\li \image DirectionalBlur_angle2.png
|
||||
\li \image DirectionalBlur_angle3.png
|
||||
\row
|
||||
\li \b { angle: 0.0 }
|
||||
\li \b { angle: 45.0 }
|
||||
\li \b { angle: 90.0 }
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l length: 32
|
||||
\li \l length: 32
|
||||
\li \l length: 32
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real angle: 0.0
|
||||
|
||||
/*!
|
||||
This property defines the blur behavior near the edges of the item,
|
||||
where the pixel blurring is affected by the pixels outside the source
|
||||
edges.
|
||||
|
||||
If the property is set to \c true, the pixels outside the source are
|
||||
interpreted to be transparent, which is similar to OpenGL
|
||||
clamp-to-border extension. The blur is expanded slightly outside the
|
||||
effect item area.
|
||||
|
||||
If the property is set to \c false, the pixels outside the source are
|
||||
interpreted to contain the same color as the pixels at the edge of the
|
||||
item, which is similar to OpenGL clamp-to-edge behavior. The blur does
|
||||
not expand outside the effect item area.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool transparentBorder: false
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0)
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: shaderItem
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
property variant source: sourceProxy.output
|
||||
property real len: rootItem.length
|
||||
property bool transparentBorder: rootItem.transparentBorder
|
||||
property real samples: rootItem.samples
|
||||
property real weight: 1.0 / Math.max(1.0, rootItem.samples)
|
||||
property variant expandPixels: transparentBorder ? Qt.size(rootItem.samples, rootItem.samples) : Qt.size(0,0)
|
||||
property variant expand: transparentBorder ? Qt.size(expandPixels.width / width, expandPixels.height / height) : Qt.size(0,0)
|
||||
property variant delta: Qt.size(1.0 / rootItem.width * Math.cos((rootItem.angle + 90) * Math.PI/180), 1.0 / rootItem.height * Math.sin((rootItem.angle + 90) * Math.PI/180))
|
||||
|
||||
x: transparentBorder ? -expandPixels.width - 1: 0
|
||||
y: transparentBorder ? -expandPixels.height - 1 : 0
|
||||
width: transparentBorder ? parent.width + 2.0 * expandPixels.width + 2 : parent.width
|
||||
height: transparentBorder ? parent.height + 2.0 * expandPixels.height + 2 : parent.height
|
||||
|
||||
property string fragmentShaderSkeleton: "
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform lowp sampler2D source;
|
||||
uniform highp float len;
|
||||
uniform highp float samples;
|
||||
uniform highp float weight;
|
||||
uniform highp vec2 expand;
|
||||
uniform highp vec2 delta;
|
||||
|
||||
void main(void) {
|
||||
highp vec2 shift = delta * len / max(1.0, samples - 1.0);
|
||||
mediump vec2 texCoord = qt_TexCoord0;
|
||||
gl_FragColor = vec4(0.0);
|
||||
|
||||
PLACEHOLDER_EXPAND_STEPS
|
||||
|
||||
texCoord -= shift * max(0.0, samples - 1.0) * 0.5;
|
||||
|
||||
PLACEHOLDER_UNROLLED_LOOP
|
||||
|
||||
gl_FragColor *= weight * qt_Opacity;
|
||||
}
|
||||
"
|
||||
|
||||
function buildFragmentShader() {
|
||||
var shader = fragmentShaderSkeleton
|
||||
var expandSteps = ""
|
||||
|
||||
if (transparentBorder) {
|
||||
expandSteps += "texCoord = (texCoord - expand) / (1.0 - 2.0 * expand);"
|
||||
}
|
||||
|
||||
var unrolledLoop = "gl_FragColor += texture2D(source, texCoord);\n"
|
||||
|
||||
if (rootItem.samples > 1) {
|
||||
unrolledLoop = ""
|
||||
for (var i = 0; i < rootItem.samples; i++)
|
||||
unrolledLoop += "gl_FragColor += texture2D(source, texCoord); texCoord += shift;\n"
|
||||
}
|
||||
|
||||
shader = shader.replace("PLACEHOLDER_EXPAND_STEPS", expandSteps)
|
||||
fragmentShader = shader.replace("PLACEHOLDER_UNROLLED_LOOP", unrolledLoop)
|
||||
}
|
||||
|
||||
onFragmentShaderChanged: sourceChanged()
|
||||
onSamplesChanged: buildFragmentShader()
|
||||
onTransparentBorderChanged: buildFragmentShader()
|
||||
Component.onCompleted: buildFragmentShader()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype Displace
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-distortion
|
||||
\brief Moves the pixels of the source item according to the given
|
||||
displacement map.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li DisplacementSource
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image Displace_map.png
|
||||
\li \image Displace_bug.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet Displace-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item for the pixels that are going to
|
||||
be displaced according to the data from
|
||||
\l{Displace::displacementSource}{displacementSource}.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines the item that is going to be used as the
|
||||
displacement map. The displacementSource item gets rendered into the
|
||||
intermediate pixel buffer. The red and green component values from the
|
||||
result determine the displacement of the pixels from the source item.
|
||||
|
||||
The format for the displacement map is similar to the tangent space
|
||||
normal maps, which can be created with most 3D-modeling tools. Many
|
||||
image processing tools include the support for generating normal maps.
|
||||
Alternatively, the displacement map for this effect can also be a QML
|
||||
element which is colored appropriately. Like any QML element, it can be
|
||||
animated. It is recommended that the size of the diplacement map matches
|
||||
the size of the \l{Displace::source}{source}.
|
||||
|
||||
The displace data is interpreted in the RGBA format. For every pixel:
|
||||
the red channel stores the x-axis displacement, and the green channel
|
||||
stores the y-axis displacement. Blue and alpha channels are ignored for
|
||||
this effect.
|
||||
|
||||
Assuming that red channel value 1.0 is fully red (0.0 having no red at
|
||||
all), this effect considers pixel component value 0.5 to cause no
|
||||
displacement at all. Values above 0.5 shift pixels to the left, values
|
||||
below 0.5 do the shift to the right. In a similar way, green channel
|
||||
values above 0.5 displace the pixels upwards, and values below 0.5 shift
|
||||
the pixels downwards. The actual amount of displacement in pixels
|
||||
depends on the \l displacement property.
|
||||
|
||||
*/
|
||||
property variant displacementSource
|
||||
|
||||
/*!
|
||||
This property defines the scale for the displacement. The bigger scale,
|
||||
the bigger the displacement of the pixels. The value set to 0.0 causes
|
||||
no displacement.
|
||||
|
||||
The value ranges from -1.0 (inverted maximum shift, according to
|
||||
displacementSource) to 1.0 (maximum shift, according to
|
||||
displacementSource). By default, the property is set to \c 0.0 (no
|
||||
displacement).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different displacement values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image Displace_displacement1.png
|
||||
\li \image Displace_displacement2.png
|
||||
\li \image Displace_displacement3.png
|
||||
\row
|
||||
\li \b { displacement: -0.2 }
|
||||
\li \b { displacement: 0.0 }
|
||||
\li \b { displacement: 0.2 }
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real displacement: 0.0
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
SourceProxy {
|
||||
id: displacementSourceProxy
|
||||
input: rootItem.displacementSource
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: parent
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
property variant source: sourceProxy.output
|
||||
property variant displacementSource: displacementSourceProxy.output
|
||||
property real displacement: rootItem.displacement
|
||||
property real xPixel: 1.0/width
|
||||
property real yPixel: 1.0/height
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
fragmentShader: "
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform lowp sampler2D source;
|
||||
uniform lowp sampler2D displacementSource;
|
||||
uniform highp float displacement;
|
||||
uniform highp float xPixel;
|
||||
uniform highp float yPixel;
|
||||
|
||||
highp float linearstep(highp float e0, highp float e1, highp float x) {
|
||||
return clamp((x - e0) / (e1 - e0), 0.0, 1.0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
lowp vec4 offset = texture2D(displacementSource, qt_TexCoord0);
|
||||
offset.xy -= vec2(0.5, 0.5);
|
||||
offset.xy = offset.xy * step(vec2(1.0/256.0), abs(offset.xy));
|
||||
highp vec2 tx = qt_TexCoord0 + (vec2(-offset.x, offset.y) * displacement);
|
||||
|
||||
lowp float e1 = linearstep(0.0, xPixel, tx.x);
|
||||
lowp float e2 = linearstep(0.0, yPixel, tx.y);
|
||||
lowp float e3 = 1.0 - linearstep(1.0, 1.0 + xPixel, tx.x);
|
||||
lowp float e4 = 1.0 - linearstep(1.0, 1.0 + yPixel, tx.y);
|
||||
|
||||
lowp vec4 sample = texture2D(source, tx);
|
||||
sample.rgb *= e1 * e2 * e3 * e4;
|
||||
gl_FragColor = sample * qt_Opacity * offset.a;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,419 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype DropShadow
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-drop-shadow
|
||||
\brief Generates a colorized and blurred shadow image of the
|
||||
source and places it behind the original, giving the impression that
|
||||
source item is raised from the background.
|
||||
|
||||
By default the effect produces a high quality shadow image, thus the
|
||||
rendering speed of the shadow might not be the highest possible. The
|
||||
rendering speed is reduced especially if the shadow edges are heavily
|
||||
softened.
|
||||
|
||||
For use cases that require faster rendering speed and for which the highest
|
||||
possible visual quality is not necessary, the
|
||||
\l{DropShadow::fast}{fast} property can be set to \c true.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_butterfly.png
|
||||
\li \image DropShadow_butterfly.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet DropShadow-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that is going to be used as the
|
||||
source for the generated shadow.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
Radius defines the softness of the shadow. A larger radius causes the
|
||||
edges of the shadow to appear more blurry.
|
||||
|
||||
Depending on the radius value, value of the
|
||||
\l{DropShadow::samples}{samples} should be set to sufficiently large to
|
||||
ensure the visual quality.
|
||||
|
||||
The value ranges from 0.0 (no blur) to inf. By default, the property is
|
||||
set to \c 0.0 (no blur).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different radius values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image DropShadow_radius1.png
|
||||
\li \image DropShadow_radius2.png
|
||||
\li \image DropShadow_radius3.png
|
||||
\row
|
||||
\li \b { radius: 0 }
|
||||
\li \b { radius: 6 }
|
||||
\li \b { radius: 12 }
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\row
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\row
|
||||
\li \l verticalOffset: 20
|
||||
\li \l verticalOffset: 20
|
||||
\li \l verticalOffset: 20
|
||||
\row
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real radius: 0.0
|
||||
|
||||
/*!
|
||||
This property defines how many samples are taken per pixel when edge
|
||||
softening blur calculation is done. Larger value produces better
|
||||
quality, but is slower to render.
|
||||
|
||||
Ideally, this value should be twice as large as the highest required
|
||||
radius value, for example, if the radius is animated between 0.0 and
|
||||
4.0, samples should be set to 8.
|
||||
|
||||
The value ranges from 0 to 32. By default, the property is set to \c 0.
|
||||
|
||||
This property is not intended to be animated. Changing this property may
|
||||
cause the underlying OpenGL shaders to be recompiled.
|
||||
|
||||
When \l{DropShadow::fast}{fast} property is set to true, this property
|
||||
has no effect.
|
||||
|
||||
*/
|
||||
property int samples: 0
|
||||
|
||||
/*!
|
||||
This property defines the RGBA color value which is used for the shadow.
|
||||
|
||||
By default, the property is set to \c "black".
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different color values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image DropShadow_color1.png
|
||||
\li \image DropShadow_color2.png
|
||||
\li \image DropShadow_color3.png
|
||||
\row
|
||||
\li \b { color: #000000 }
|
||||
\li \b { color: #0000ff }
|
||||
\li \b { color: #aa000000 }
|
||||
\row
|
||||
\li \l radius: 8
|
||||
\li \l radius: 8
|
||||
\li \l radius: 8
|
||||
\row
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\row
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\row
|
||||
\li \l verticalOffset: 20
|
||||
\li \l verticalOffset: 20
|
||||
\li \l verticalOffset: 20
|
||||
\row
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property color color: "black"
|
||||
|
||||
/*!
|
||||
\qmlproperty real QtGraphicalEffects1::DropShadow::horizontalOffset
|
||||
\qmlproperty real QtGraphicalEffects1::DropShadow::verticalOffset
|
||||
|
||||
HorizontalOffset and verticalOffset properties define the offset for the
|
||||
rendered shadow compared to the DropShadow item position. Often, the
|
||||
DropShadow item is anchored so that it fills the source element. In this
|
||||
case, if the HorizontalOffset and verticalOffset properties are set to
|
||||
0, the shadow is rendered exactly under the source item. By changing the
|
||||
offset properties, the shadow can be positioned relatively to the source
|
||||
item.
|
||||
|
||||
The values range from -inf to inf. By default, the properties are set to
|
||||
\c 0.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different horizontalOffset values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image DropShadow_horizontalOffset1.png
|
||||
\li \image DropShadow_horizontalOffset2.png
|
||||
\li \image DropShadow_horizontalOffset3.png
|
||||
\row
|
||||
\li \b { horizontalOffset: -20 }
|
||||
\li \b { horizontalOffset: 0 }
|
||||
\li \b { horizontalOffset: 20 }
|
||||
\row
|
||||
\li \l radius: 4
|
||||
\li \l radius: 4
|
||||
\li \l radius: 4
|
||||
\row
|
||||
\li \l samples: 8
|
||||
\li \l samples: 8
|
||||
\li \l samples: 8
|
||||
\row
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\row
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\row
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real horizontalOffset: 0.0
|
||||
property real verticalOffset: 0.0
|
||||
|
||||
/*!
|
||||
This property defines how large part of the shadow color is strenghtened
|
||||
near the source edges.
|
||||
|
||||
The value ranges from 0.0 to 1.0. By default, the property is set to \c
|
||||
0.5.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different spread values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image DropShadow_spread1.png
|
||||
\li \image DropShadow_spread2.png
|
||||
\li \image DropShadow_spread3.png
|
||||
\row
|
||||
\li \b { spread: 0.0 }
|
||||
\li \b { spread: 0.5 }
|
||||
\li \b { spread: 1.0 }
|
||||
\row
|
||||
\li \l radius: 8
|
||||
\li \l radius: 8
|
||||
\li \l radius: 8
|
||||
\row
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\row
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\row
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\row
|
||||
\li \l verticalOffset: 20
|
||||
\li \l verticalOffset: 20
|
||||
\li \l verticalOffset: 20
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real spread: 0.0
|
||||
|
||||
/*!
|
||||
This property selects the blurring algorithm that is used to produce the
|
||||
softness for the effect. Setting this to true enables fast algorithm,
|
||||
setting value to false produces higher quality result.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different fast values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image DropShadow_fast1.png
|
||||
\li \image DropShadow_fast2.png
|
||||
\row
|
||||
\li \b { fast: false }
|
||||
\li \b { fast: true }
|
||||
\row
|
||||
\li \l radius: 16
|
||||
\li \l radius: 16
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\row
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\row
|
||||
\li \l verticalOffset: 20
|
||||
\li \l verticalOffset: 20
|
||||
\row
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property bool fast: false
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance. Every time the source or effect
|
||||
properties are changed, the pixels in the cache must be updated. Memory
|
||||
consumption is increased, because an extra buffer of memory is required
|
||||
for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
/*!
|
||||
This property determines whether or not the effect has a transparent
|
||||
border.
|
||||
|
||||
When set to \c true, the exterior of the item is padded with a 1 pixel
|
||||
wide transparent edge, making sampling outside the source texture use
|
||||
transparency instead of the edge pixels. Without this property, an
|
||||
image which has opaque edges will not get a blurred edge.
|
||||
|
||||
In the image below, the Rectangle on the left has transparent borders
|
||||
and has blurred edges, whereas the Rectangle on the right does not:
|
||||
|
||||
\snippet DropShadow-transparentBorder-example.qml example
|
||||
|
||||
\image transparentBorder.png
|
||||
*/
|
||||
property bool transparentBorder: false
|
||||
|
||||
Loader {
|
||||
x: rootItem.horizontalOffset
|
||||
y: rootItem.verticalOffset
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
sourceComponent: rootItem.fast ? fastGlow : gaussianGlow
|
||||
}
|
||||
|
||||
Component {
|
||||
id: gaussianGlow
|
||||
GaussianGlow {
|
||||
anchors.fill: parent
|
||||
source: sourceProxy.output
|
||||
radius: rootItem.radius
|
||||
maximumRadius: rootItem.samples * 0.5
|
||||
color: rootItem.color
|
||||
cached: rootItem.cached
|
||||
spread: rootItem.spread
|
||||
transparentBorder: rootItem.transparentBorder
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: fastGlow
|
||||
FastGlow {
|
||||
anchors.fill: parent
|
||||
source: sourceProxy.output
|
||||
blur: Math.pow(rootItem.radius / 64.0, 0.4)
|
||||
color: rootItem.color
|
||||
cached: rootItem.cached
|
||||
spread: rootItem.spread
|
||||
transparentBorder: rootItem.transparentBorder
|
||||
}
|
||||
}
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0)
|
||||
}
|
||||
ShaderEffect {
|
||||
anchors.fill: parent
|
||||
property variant source: sourceProxy.output
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,496 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype FastBlur
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-blur
|
||||
\brief Applies a fast blur effect to one or more source items.
|
||||
|
||||
FastBlur offers lower blur quality than
|
||||
\l{QtGraphicalEffects1::GaussianBlur}{GaussianBlur}, but it is faster to
|
||||
render. The FastBlur effect softens the source content by blurring it with
|
||||
algorithm which uses the source content downscaling and bilinear filtering.
|
||||
Use this effect in situations where the source content is rapidly changing
|
||||
and the highest possible blur quality is not
|
||||
needed.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image FastBlur_bug.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet FastBlur-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that is going to be blurred.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines the distance of the neighboring pixels which affect
|
||||
the blurring of an individual pixel. A larger radius increases the blur
|
||||
effect. FastBlur algorithm may internally reduce the accuracy of the radius in order to
|
||||
provide good rendering performance.
|
||||
|
||||
The value ranges from 0.0 (no blur) to inf. Visual quality of the blur is reduced when
|
||||
radius exceeds value 64. By default, the property is set to \c 0.0 (no blur).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different blur values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image FastBlur_radius1.png
|
||||
\li \image FastBlur_radius2.png
|
||||
\li \image FastBlur_radius3.png
|
||||
\row
|
||||
\li \b { radius: 0 }
|
||||
\li \b { radius: 32 }
|
||||
\li \b { radius: 64 }
|
||||
\endtable
|
||||
*/
|
||||
property real radius: 0.0
|
||||
|
||||
/*!
|
||||
This property defines the blur behavior near the edges of the item,
|
||||
where the pixel blurring is affected by the pixels outside the source
|
||||
edges.
|
||||
|
||||
If the property is set to \c true, the pixels outside the source are
|
||||
interpreted to be transparent, which is similar to OpenGL
|
||||
clamp-to-border extension. The blur is expanded slightly outside the
|
||||
effect item area.
|
||||
|
||||
If the property is set to \c false, the pixels outside the source are
|
||||
interpreted to contain the same color as the pixels at the edge of the
|
||||
item, which is similar to OpenGL clamp-to-edge behavior. The blur does
|
||||
not expand outside the effect item area.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different transparentBorder values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image FastBlur_transparentBorder1.png
|
||||
\li \image FastBlur_transparentBorder2.png
|
||||
\row
|
||||
\li \b { transparentBorder: false }
|
||||
\li \b { transparentBorder: true }
|
||||
\row
|
||||
\li \l radius: 64
|
||||
\li \l radius: 64
|
||||
\endtable
|
||||
*/
|
||||
property bool transparentBorder: false
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: shaderItem
|
||||
visible: rootItem.cached
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
smooth: rootItem.radius > 0
|
||||
}
|
||||
|
||||
/*! \internal */
|
||||
property string __internalBlurVertexShader: "
|
||||
attribute highp vec4 qt_Vertex;
|
||||
attribute highp vec2 qt_MultiTexCoord0;
|
||||
uniform highp mat4 qt_Matrix;
|
||||
uniform highp float yStep;
|
||||
uniform highp float xStep;
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
varying highp vec2 qt_TexCoord1;
|
||||
varying highp vec2 qt_TexCoord2;
|
||||
varying highp vec2 qt_TexCoord3;
|
||||
|
||||
void main() {
|
||||
qt_TexCoord0 = vec2(qt_MultiTexCoord0.x + xStep, qt_MultiTexCoord0.y + yStep * 0.36);
|
||||
qt_TexCoord1 = vec2(qt_MultiTexCoord0.x + xStep * 0.36, qt_MultiTexCoord0.y - yStep);
|
||||
qt_TexCoord2 = vec2(qt_MultiTexCoord0.x - xStep * 0.36, qt_MultiTexCoord0.y + yStep);
|
||||
qt_TexCoord3 = vec2(qt_MultiTexCoord0.x - xStep, qt_MultiTexCoord0.y - yStep * 0.36);
|
||||
gl_Position = qt_Matrix * qt_Vertex;
|
||||
}
|
||||
"
|
||||
|
||||
/*! \internal */
|
||||
property string __internalBlurFragmentShader: "
|
||||
uniform lowp sampler2D source;
|
||||
uniform lowp float qt_Opacity;
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
varying highp vec2 qt_TexCoord1;
|
||||
varying highp vec2 qt_TexCoord2;
|
||||
varying highp vec2 qt_TexCoord3;
|
||||
|
||||
void main() {
|
||||
highp vec4 sourceColor = (texture2D(source, qt_TexCoord0) +
|
||||
texture2D(source, qt_TexCoord1) +
|
||||
texture2D(source, qt_TexCoord2) +
|
||||
texture2D(source, qt_TexCoord3)) * 0.25;
|
||||
gl_FragColor = sourceColor * qt_Opacity;
|
||||
}
|
||||
"
|
||||
|
||||
ShaderEffect {
|
||||
id: level0
|
||||
property variant source: sourceProxy.output
|
||||
anchors.fill: parent
|
||||
visible: false
|
||||
smooth: true
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: level1
|
||||
width: Math.ceil(shaderItem.width / 32) * 32
|
||||
height: Math.ceil(shaderItem.height / 32) * 32
|
||||
sourceItem: level0
|
||||
hideSource: rootItem.visible
|
||||
sourceRect: transparentBorder ? Qt.rect(-64, -64, shaderItem.width, shaderItem.height) : Qt.rect(0, 0, 0, 0)
|
||||
visible: false
|
||||
smooth: rootItem.radius > 0
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: effect1
|
||||
property variant source: level1
|
||||
property real yStep: 1/height
|
||||
property real xStep: 1/width
|
||||
anchors.fill: level2
|
||||
visible: false
|
||||
smooth: true
|
||||
vertexShader: __internalBlurVertexShader
|
||||
fragmentShader: __internalBlurFragmentShader
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: level2
|
||||
width: level1.width / 2
|
||||
height: level1.height / 2
|
||||
sourceItem: effect1
|
||||
hideSource: rootItem.visible
|
||||
visible: false
|
||||
smooth: true
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: effect2
|
||||
property variant source: level2
|
||||
property real yStep: 1/height
|
||||
property real xStep: 1/width
|
||||
anchors.fill: level3
|
||||
visible: false
|
||||
smooth: true
|
||||
vertexShader: __internalBlurVertexShader
|
||||
fragmentShader: __internalBlurFragmentShader
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: level3
|
||||
width: level2.width / 2
|
||||
height: level2.height / 2
|
||||
sourceItem: effect2
|
||||
hideSource: rootItem.visible
|
||||
visible: false
|
||||
smooth: true
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: effect3
|
||||
property variant source: level3
|
||||
property real yStep: 1/height
|
||||
property real xStep: 1/width
|
||||
anchors.fill: level4
|
||||
visible: false
|
||||
smooth: true
|
||||
vertexShader: __internalBlurVertexShader
|
||||
fragmentShader: __internalBlurFragmentShader
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: level4
|
||||
width: level3.width / 2
|
||||
height: level3.height / 2
|
||||
sourceItem: effect3
|
||||
hideSource: rootItem.visible
|
||||
visible: false
|
||||
smooth: true
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: effect4
|
||||
property variant source: level4
|
||||
property real yStep: 1/height
|
||||
property real xStep: 1/width
|
||||
anchors.fill: level5
|
||||
visible: false
|
||||
smooth: true
|
||||
vertexShader: __internalBlurVertexShader
|
||||
fragmentShader: __internalBlurFragmentShader
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: level5
|
||||
width: level4.width / 2
|
||||
height: level4.height / 2
|
||||
sourceItem: effect4
|
||||
hideSource: rootItem.visible
|
||||
visible: false
|
||||
smooth: true
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: effect5
|
||||
property variant source: level5
|
||||
property real yStep: 1/height
|
||||
property real xStep: 1/width
|
||||
anchors.fill: level6
|
||||
visible: false
|
||||
smooth: true
|
||||
vertexShader: __internalBlurVertexShader
|
||||
fragmentShader: __internalBlurFragmentShader
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: level6
|
||||
width: level5.width / 2
|
||||
height: level5.height / 2
|
||||
sourceItem: effect5
|
||||
hideSource: rootItem.visible
|
||||
visible: false
|
||||
smooth: true
|
||||
}
|
||||
|
||||
Item {
|
||||
id: dummysource
|
||||
width: 1
|
||||
height: 1
|
||||
visible: false
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: dummy
|
||||
width: 1
|
||||
height: 1
|
||||
sourceItem: dummysource
|
||||
visible: false
|
||||
smooth: false
|
||||
live: false
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
|
||||
property variant source1: level1
|
||||
property variant source2: level2
|
||||
property variant source3: level3
|
||||
property variant source4: level4
|
||||
property variant source5: level5
|
||||
property variant source6: level6
|
||||
property real lod: Math.sqrt(rootItem.radius / 64.0) * 1.2 - 0.2
|
||||
property real weight1
|
||||
property real weight2
|
||||
property real weight3
|
||||
property real weight4
|
||||
property real weight5
|
||||
property real weight6
|
||||
|
||||
x: transparentBorder ? -64 : 0
|
||||
y: transparentBorder ? -64 : 0
|
||||
width: transparentBorder ? parent.width + 128 : parent.width
|
||||
height: transparentBorder ? parent.height + 128 : parent.height
|
||||
|
||||
function weight(v) {
|
||||
if (v <= 0.0)
|
||||
return 1.0
|
||||
if (v >= 0.5)
|
||||
return 0.0
|
||||
|
||||
return 1.0 - v * 2.0
|
||||
}
|
||||
|
||||
function calculateWeights() {
|
||||
|
||||
var w1 = weight(Math.abs(lod - 0.100))
|
||||
var w2 = weight(Math.abs(lod - 0.300))
|
||||
var w3 = weight(Math.abs(lod - 0.500))
|
||||
var w4 = weight(Math.abs(lod - 0.700))
|
||||
var w5 = weight(Math.abs(lod - 0.900))
|
||||
var w6 = weight(Math.abs(lod - 1.100))
|
||||
|
||||
var sum = w1 + w2 + w3 + w4 + w5 + w6;
|
||||
weight1 = w1 / sum;
|
||||
weight2 = w2 / sum;
|
||||
weight3 = w3 / sum;
|
||||
weight4 = w4 / sum;
|
||||
weight5 = w5 / sum;
|
||||
weight6 = w6 / sum;
|
||||
|
||||
upateSources()
|
||||
}
|
||||
|
||||
function upateSources() {
|
||||
var sources = new Array();
|
||||
var weights = new Array();
|
||||
|
||||
if (weight1 > 0) {
|
||||
sources.push(level1)
|
||||
weights.push(weight1)
|
||||
}
|
||||
|
||||
if (weight2 > 0) {
|
||||
sources.push(level2)
|
||||
weights.push(weight2)
|
||||
}
|
||||
|
||||
if (weight3 > 0) {
|
||||
sources.push(level3)
|
||||
weights.push(weight3)
|
||||
}
|
||||
|
||||
if (weight4 > 0) {
|
||||
sources.push(level4)
|
||||
weights.push(weight4)
|
||||
}
|
||||
|
||||
if (weight5 > 0) {
|
||||
sources.push(level5)
|
||||
weights.push(weight5)
|
||||
}
|
||||
|
||||
if (weight6 > 0) {
|
||||
sources.push(level6)
|
||||
weights.push(weight6)
|
||||
}
|
||||
|
||||
for (var j = sources.length; j < 6; j++) {
|
||||
sources.push(dummy)
|
||||
weights.push(0.0)
|
||||
}
|
||||
|
||||
source1 = sources[0]
|
||||
source2 = sources[1]
|
||||
source3 = sources[2]
|
||||
source4 = sources[3]
|
||||
source5 = sources[4]
|
||||
source6 = sources[5]
|
||||
|
||||
weight1 = weights[0]
|
||||
weight2 = weights[1]
|
||||
weight3 = weights[2]
|
||||
weight4 = weights[3]
|
||||
weight5 = weights[4]
|
||||
weight6 = weights[5]
|
||||
}
|
||||
|
||||
Component.onCompleted: calculateWeights()
|
||||
|
||||
onLodChanged: calculateWeights()
|
||||
|
||||
fragmentShader: "
|
||||
uniform lowp sampler2D source1;
|
||||
uniform lowp sampler2D source2;
|
||||
uniform lowp sampler2D source3;
|
||||
uniform lowp sampler2D source4;
|
||||
uniform lowp sampler2D source5;
|
||||
uniform mediump float weight1;
|
||||
uniform mediump float weight2;
|
||||
uniform mediump float weight3;
|
||||
uniform mediump float weight4;
|
||||
uniform mediump float weight5;
|
||||
uniform lowp float qt_Opacity;
|
||||
varying mediump vec2 qt_TexCoord0;
|
||||
|
||||
void main() {
|
||||
lowp vec4 sourceColor = texture2D(source1, qt_TexCoord0) * weight1;
|
||||
sourceColor += texture2D(source2, qt_TexCoord0) * weight2;
|
||||
sourceColor += texture2D(source3, qt_TexCoord0) * weight3;
|
||||
sourceColor += texture2D(source4, qt_TexCoord0) * weight4;
|
||||
sourceColor += texture2D(source5, qt_TexCoord0) * weight5;
|
||||
gl_FragColor = sourceColor * qt_Opacity;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype GammaAdjust
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-color
|
||||
\brief Alters the luminance of the source item.
|
||||
|
||||
GammaAdjust is applied to each pixel according to the curve which is
|
||||
pre-defined as a power-law expression, where the property gamma is used as the
|
||||
reciprocal scaling exponent. Refer to the property documentation of \l{GammaAdjust::gamma}{gamma}
|
||||
for more details.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image GammaAdjust_bug.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet GammaAdjust-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item for which the luminance is going to be
|
||||
adjusted.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines the change factor for how the luminance of each pixel
|
||||
is altered according to the equation:
|
||||
|
||||
\code
|
||||
luminance = pow(original_luminance, 1.0 / gamma); // The luminance is assumed to be between 0.0 and 1.0
|
||||
\endcode
|
||||
|
||||
Setting the gamma values under 1.0 makes the image darker, the values
|
||||
above 1.0 lighten it.
|
||||
|
||||
The value ranges from 0.0 (darkest) to inf (lightest). By default, the
|
||||
property is set to \c 1.0 (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different gamma values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image GammaAdjust_gamma1.png
|
||||
\li \image GammaAdjust_gamma2.png
|
||||
\li \image GammaAdjust_gamma3.png
|
||||
\row
|
||||
\li \b { gamma: 0.5 }
|
||||
\li \b { gamma: 1.0 }
|
||||
\li \b { gamma: 2.0 }
|
||||
\endtable
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Pixel luminance curves of the above images.
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image GammaAdjust_gamma1_graph.png
|
||||
\li \image GammaAdjust_gamma2_graph.png
|
||||
\li \image GammaAdjust_gamma3_graph.png
|
||||
\row
|
||||
\li Red curve: default gamma (1.0)
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li Yellow curve: effect applied
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li X-axis: pixel original luminance
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li Y-axis: pixel luminance with effect applied
|
||||
\li
|
||||
\li
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real gamma: 1.0
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: parent
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
property variant source: sourceProxy.output
|
||||
property real gamma: 1.0 / Math.max(rootItem.gamma, 0.0001)
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
fragmentShader: "
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform lowp sampler2D source;
|
||||
uniform highp float gamma;
|
||||
void main(void) {
|
||||
highp vec4 originalColor = texture2D(source, qt_TexCoord0.st);
|
||||
originalColor.rgb = originalColor.rgb / max(1.0/256.0, originalColor.a);
|
||||
highp vec3 adjustedColor = pow(originalColor.rgb, vec3(gamma));
|
||||
gl_FragColor = vec4(adjustedColor * originalColor.a, originalColor.a) * qt_Opacity;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype GaussianBlur
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-blur
|
||||
\brief Applies a higher quality blur effect.
|
||||
|
||||
GaussianBlur effect softens the image by blurring it with an algorithm that
|
||||
uses the Gaussian function to calculate the effect. The effect produces
|
||||
higher quality than \l{QtGraphicalEffects1::FastBlur}{FastBlur}, but is
|
||||
slower to render.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image GaussianBlur_bug.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet GaussianBlur-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that is going to be blurred.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines the distance of the neighboring pixels which
|
||||
affect the blurring of an individual pixel. A larger radius increases
|
||||
the blur effect.
|
||||
|
||||
Depending on the radius value, value of the
|
||||
\l{GaussianBlur::samples}{samples} should be set to sufficiently large
|
||||
to ensure the visual quality.
|
||||
|
||||
The value ranges from 0.0 (no blur) to inf. By default, the property is
|
||||
set to \c 0.0 (no blur).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different radius values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image GaussianBlur_radius1.png
|
||||
\li \image GaussianBlur_radius2.png
|
||||
\li \image GaussianBlur_radius3.png
|
||||
\row
|
||||
\li \b { radius: 0 }
|
||||
\li \b { radius: 4 }
|
||||
\li \b { radius: 8 }
|
||||
\row
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\row
|
||||
\li \l deviation: 3
|
||||
\li \l deviation: 3
|
||||
\li \l deviation: 3
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real radius: 0.0
|
||||
|
||||
/*!
|
||||
This property defines how many samples are taken per pixel when blur
|
||||
calculation is done. Larger value produces better quality, but is slower
|
||||
to render.
|
||||
|
||||
Ideally, this value should be twice as large as the highest required
|
||||
radius value, for example, if the radius is animated between 0.0 and
|
||||
4.0, samples should be set to 8.
|
||||
|
||||
The value ranges from 0 to 32. By default, the property is set to \c 0.
|
||||
|
||||
This property is not intended to be animated. Changing this property may
|
||||
cause the underlying OpenGL shaders to be recompiled.
|
||||
|
||||
*/
|
||||
property int samples: 0
|
||||
|
||||
/*!
|
||||
This property is a parameter to the gaussian function that is used when
|
||||
calculating neighboring pixel weights for the blurring. A larger
|
||||
deviation causes image to appear more blurry, but it also reduces the
|
||||
quality of the blur. A very large deviation value causes the effect to
|
||||
look a bit similar to what, for exmple, a box blur algorithm produces. A
|
||||
too small deviation values makes the effect insignificant for the pixels
|
||||
near the radius.
|
||||
|
||||
\inlineimage GaussianBlur_deviation_graph.png
|
||||
\caption The image above shows the Gaussian function with two different
|
||||
deviation values, yellow (1) and cyan (2.7). The y-axis shows the
|
||||
weights, the x-axis shows the pixel distance.
|
||||
|
||||
The value ranges from 0.0 (no deviation) to inf (maximum deviation). By
|
||||
default, devaition is binded to radius. When radius increases, deviation
|
||||
is automatically increased linearly. With the radius value of 8, the
|
||||
deviation default value becomes approximately 2.7034. This value
|
||||
produces a compromise between the blur quality and overall blurriness.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different deviation values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image GaussianBlur_deviation1.png
|
||||
\li \image GaussianBlur_deviation2.png
|
||||
\li \image GaussianBlur_deviation3.png
|
||||
\row
|
||||
\li \b { deviation: 1 }
|
||||
\li \b { deviation: 2 }
|
||||
\li \b { deviation: 4 }
|
||||
\row
|
||||
\li \l radius: 8
|
||||
\li \l radius: 8
|
||||
\li \l radius: 8
|
||||
\row
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real deviation: (radius + 1) / 3.3333
|
||||
|
||||
/*!
|
||||
This property defines the blur behavior near the edges of the item,
|
||||
where the pixel blurring is affected by the pixels outside the source
|
||||
edges.
|
||||
|
||||
If the property is set to \c true, the pixels outside the source are
|
||||
interpreted to be transparent, which is similar to OpenGL
|
||||
clamp-to-border extension. The blur is expanded slightly outside the
|
||||
effect item area.
|
||||
|
||||
If the property is set to \c false, the pixels outside the source are
|
||||
interpreted to contain the same color as the pixels at the edge of the
|
||||
item, which is similar to OpenGL clamp-to-edge behavior. The blur does
|
||||
not expand outside the effect item area.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different transparentBorder values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image GaussianBlur_transparentBorder1.png
|
||||
\li \image GaussianBlur_transparentBorder2.png
|
||||
\row
|
||||
\li \b { transparentBorder: false }
|
||||
\li \b { transparentBorder: true }
|
||||
\row
|
||||
\li \l radius: 8
|
||||
\li \l radius: 8
|
||||
\row
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\row
|
||||
\li \l deviation: 2.7
|
||||
\li \l deviation: 2.7
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property bool transparentBorder: false
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0)
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: verticalBlur
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: verticalBlur
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
GaussianDirectionalBlur {
|
||||
id: verticalBlur
|
||||
x: transparentBorder ? -maximumRadius - 1 : 0
|
||||
y: transparentBorder ? -maximumRadius - 1 : 0
|
||||
width: horizontalBlur.width
|
||||
height: horizontalBlur.height
|
||||
|
||||
horizontalStep: 0.0
|
||||
verticalStep: 1.0 / parent.height
|
||||
|
||||
source: ShaderEffectSource {
|
||||
id: horizontalBlurSource
|
||||
sourceItem: horizontalBlur
|
||||
hideSource: true
|
||||
visible: false
|
||||
smooth: true
|
||||
}
|
||||
|
||||
deviation: rootItem.deviation
|
||||
radius: rootItem.radius
|
||||
maximumRadius: rootItem.samples * 0.5
|
||||
transparentBorder: rootItem.transparentBorder
|
||||
}
|
||||
|
||||
GaussianDirectionalBlur {
|
||||
id: horizontalBlur
|
||||
width: transparentBorder ? parent.width + 2 * maximumRadius + 2 : parent.width
|
||||
height: transparentBorder ? parent.height + 2 * maximumRadius + 2 : parent.height
|
||||
|
||||
horizontalStep: 1.0 / parent.width
|
||||
verticalStep: 0.0
|
||||
|
||||
source: sourceProxy.output
|
||||
deviation: rootItem.deviation
|
||||
radius: rootItem.radius
|
||||
maximumRadius: rootItem.samples / 2.0
|
||||
transparentBorder: rootItem.transparentBorder
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype Glow
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-glow
|
||||
\brief Generates a blurred and colorized image of the source and places it
|
||||
behind the original, giving impression that the source is glowing.
|
||||
|
||||
By default effect produces a high quality glow image, thus the rendering
|
||||
speed of the effect may not be the highest possible. The rendering speed is
|
||||
reduced especially if the glow edges are heavily softened. For use cases
|
||||
that require faster rendering speed and the highest possible visual quality
|
||||
is not necessary, property \l{Glow::fast}{fast} can be set to true.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_butterfly_black.png
|
||||
\li \image Glow_butterfly.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet Glow-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that is going to be used as source
|
||||
for the generated glow.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
Radius defines the softness of the glow. A larger radius causes the
|
||||
edges of the glow to appear more blurry.
|
||||
|
||||
Depending on the radius value, value of the \l{Glow::samples}{samples}
|
||||
should be set to sufficiently large to ensure the visual quality.
|
||||
|
||||
The value ranges from 0.0 (no blur) to inf. By default, the property is
|
||||
set to \c 0.0 (no blur).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different radius values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image Glow_radius1.png
|
||||
\li \image Glow_radius2.png
|
||||
\li \image Glow_radius3.png
|
||||
\row
|
||||
\li \b { radius: 0 }
|
||||
\li \b { radius: 6 }
|
||||
\li \b { radius: 12 }
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l color: #ffffff
|
||||
\li \l color: #ffffff
|
||||
\li \l color: #ffffff
|
||||
\row
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\endtable
|
||||
*/
|
||||
property real radius: 0.0
|
||||
|
||||
/*!
|
||||
This property defines how many samples are taken per pixel when edge
|
||||
softening blur calculation is done. Larger value produces better
|
||||
quality, but is slower to render.
|
||||
|
||||
Ideally, this value should be twice as large as the highest required
|
||||
radius value, for example, if the radius is animated between 0.0 and
|
||||
4.0, samples should be set to 8.
|
||||
|
||||
The value ranges from 0 to 32. By default, the property is set to \c 0.
|
||||
|
||||
This property is not intended to be animated. Changing this property may
|
||||
cause the underlying OpenGL shaders to be recompiled.
|
||||
|
||||
When \l fast property is set to true, this property has no effect.
|
||||
|
||||
*/
|
||||
property int samples: 0
|
||||
|
||||
/*!
|
||||
This property defines how large part of the glow color is strenghtened
|
||||
near the source edges.
|
||||
|
||||
The values range from 0.0 to 1.0. By default, the property is set to \c
|
||||
0.5.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different spread values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image Glow_spread1.png
|
||||
\li \image Glow_spread2.png
|
||||
\li \image Glow_spread3.png
|
||||
\row
|
||||
\li \b { spread: 0.0 }
|
||||
\li \b { spread: 0.5 }
|
||||
\li \b { spread: 1.0 }
|
||||
\row
|
||||
\li \l radius: 8
|
||||
\li \l radius: 8
|
||||
\li \l radius: 8
|
||||
\row
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\row
|
||||
\li \l color: #ffffff
|
||||
\li \l color: #ffffff
|
||||
\li \l color: #ffffff
|
||||
\endtable
|
||||
*/
|
||||
property real spread: 0.0
|
||||
|
||||
/*!
|
||||
This property defines the RGBA color value which is used for the glow.
|
||||
|
||||
By default, the property is set to \c "white".
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different color values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image Glow_color1.png
|
||||
\li \image Glow_color2.png
|
||||
\li \image Glow_color3.png
|
||||
\row
|
||||
\li \b { color: #ffffff }
|
||||
\li \b { color: #00ff00 }
|
||||
\li \b { color: #aa00ff00 }
|
||||
\row
|
||||
\li \l radius: 8
|
||||
\li \l radius: 8
|
||||
\li \l radius: 8
|
||||
\row
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\li \l samples: 16
|
||||
\row
|
||||
\li \l spread: 0.5
|
||||
\li \l spread: 0.5
|
||||
\li \l spread: 0.5
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property color color: "white"
|
||||
|
||||
/*!
|
||||
This property selects the blurring algorithm that is used to produce the
|
||||
softness for the effect. Setting this to true enables fast algorithm,
|
||||
setting value to false produces higher quality result.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different fast values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image Glow_fast1.png
|
||||
\li \image Glow_fast2.png
|
||||
\row
|
||||
\li \b { fast: false }
|
||||
\li \b { fast: true }
|
||||
\row
|
||||
\li \l radius: 16
|
||||
\li \l radius: 16
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l color: #ffffff
|
||||
\li \l color: #ffffff
|
||||
\row
|
||||
\li \l spread: 0.3
|
||||
\li \l spread: 0.3
|
||||
\endtable
|
||||
*/
|
||||
property bool fast: false
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
/*!
|
||||
This property determines whether or not the effect has a transparent
|
||||
border.
|
||||
|
||||
When set to \c true, the exterior of the item is padded with a 1 pixel
|
||||
wide transparent edge, making sampling outside the source texture use
|
||||
transparency instead of the edge pixels. Without this property, an
|
||||
image which has opaque edges will not get a blurred edge.
|
||||
|
||||
In the snippet below, the Rectangle on the left has transparent borders
|
||||
and has blurred edges, whereas the Rectangle on the right does not.
|
||||
|
||||
\snippet Glow-transparentBorder-example.qml example
|
||||
|
||||
\image transparentBorder.png
|
||||
*/
|
||||
property bool transparentBorder: false
|
||||
|
||||
Loader {
|
||||
anchors.fill: parent
|
||||
sourceComponent: rootItem.fast ? fastGlow : gaussianGlow
|
||||
}
|
||||
|
||||
Component {
|
||||
id: gaussianGlow
|
||||
GaussianGlow {
|
||||
anchors.fill: parent
|
||||
source: sourceProxy.output
|
||||
radius: rootItem.radius
|
||||
maximumRadius: rootItem.samples * 0.5
|
||||
color: rootItem.color
|
||||
cached: rootItem.cached
|
||||
spread: rootItem.spread
|
||||
transparentBorder: rootItem.transparentBorder
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: fastGlow
|
||||
FastGlow {
|
||||
anchors.fill: parent
|
||||
source: sourceProxy.output
|
||||
blur: Math.pow(rootItem.radius / 64.0, 0.4)
|
||||
color: rootItem.color
|
||||
cached: rootItem.cached
|
||||
spread: rootItem.spread
|
||||
transparentBorder: rootItem.transparentBorder
|
||||
}
|
||||
}
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0)
|
||||
}
|
||||
ShaderEffect {
|
||||
anchors.fill: parent
|
||||
property variant source: sourceProxy.output
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype HueSaturation
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-color
|
||||
\brief Alters the source item colors in the HSL color space.
|
||||
|
||||
HueSaturation is similar to the \l{QtGraphicalEffects1::Colorize}{Colorize}
|
||||
effect, but the hue and saturation property values are handled differently.
|
||||
The HueSaturation effect always shifts the hue, saturation, and lightness
|
||||
from the original, instead of setting them.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image HueSaturation_bug.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet HueSaturation-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that provides the source pixels
|
||||
for the effect.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source: 0
|
||||
|
||||
/*!
|
||||
This property defines the hue value which is added to the source hue
|
||||
value.
|
||||
|
||||
The value ranges from -1.0 (decrease) to 1.0 (increase). By default, the
|
||||
property is set to \c 0.0 (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different hue values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image HueSaturation_hue1.png
|
||||
\li \image HueSaturation_hue2.png
|
||||
\li \image HueSaturation_hue3.png
|
||||
\row
|
||||
\li \b { hue: -0.3 }
|
||||
\li \b { hue: 0.0 }
|
||||
\li \b { hue: 0.3 }
|
||||
\row
|
||||
\li \l saturation: 0
|
||||
\li \l saturation: 0
|
||||
\li \l saturation: 0
|
||||
\row
|
||||
\li \l lightness: 0
|
||||
\li \l lightness: 0
|
||||
\li \l lightness: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real hue: 0.0
|
||||
|
||||
/*!
|
||||
This property defines the saturation value value which is added to the
|
||||
source saturation value.
|
||||
|
||||
The value ranges from -1.0 (decrease) to 1.0 (increase). By default, the
|
||||
property is set to \c 0.0 (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different saturation values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image HueSaturation_saturation1.png
|
||||
\li \image HueSaturation_saturation2.png
|
||||
\li \image HueSaturation_saturation3.png
|
||||
\row
|
||||
\li \b { saturation: -0.8 }
|
||||
\li \b { saturation: 0.0 }
|
||||
\li \b { saturation: 1.0 }
|
||||
\row
|
||||
\li \l hue: 0
|
||||
\li \l hue: 0
|
||||
\li \l hue: 0
|
||||
\row
|
||||
\li \l lightness: 0
|
||||
\li \l lightness: 0
|
||||
\li \l lightness: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real saturation: 0.0
|
||||
|
||||
/*!
|
||||
This property defines the lightness value which is added to the source
|
||||
saturation value.
|
||||
|
||||
The value ranges from -1.0 (decrease) to 1.0 (increase). By default, the
|
||||
property is set to \c 0.0 (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different lightness values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image HueSaturation_lightness1.png
|
||||
\li \image HueSaturation_lightness2.png
|
||||
\li \image HueSaturation_lightness3.png
|
||||
\row
|
||||
\li \b { lightness: -0.5 }
|
||||
\li \b { lightness: 0.0 }
|
||||
\li \b { lightness: 0.5 }
|
||||
\row
|
||||
\li \l hue: 0
|
||||
\li \l hue: 0
|
||||
\li \l hue: 0
|
||||
\row
|
||||
\li \l saturation: 0
|
||||
\li \l saturation: 0
|
||||
\li \l saturation: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real lightness: 0.0
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: parent
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
property variant source: sourceProxy.output
|
||||
property variant hsl: Qt.vector3d(rootItem.hue, rootItem.saturation, rootItem.lightness)
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
fragmentShader: "
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform highp sampler2D source;
|
||||
uniform highp vec3 hsl;
|
||||
|
||||
highp vec3 RGBtoHSL(highp vec3 color) {
|
||||
highp float cmin = min(color.r, min(color.g, color.b));
|
||||
highp float cmax = max(color.r, max(color.g, color.b));
|
||||
highp float h = 0.0;
|
||||
highp float s = 0.0;
|
||||
highp float l = (cmin + cmax) / 2.0;
|
||||
highp float diff = cmax - cmin;
|
||||
|
||||
if (diff > 1.0 / 256.0) {
|
||||
if (l < 0.5)
|
||||
s = diff / (cmin + cmax);
|
||||
else
|
||||
s = diff / (2.0 - (cmin + cmax));
|
||||
|
||||
if (color.r == cmax)
|
||||
h = (color.g - color.b) / diff;
|
||||
else if (color.g == cmax)
|
||||
h = 2.0 + (color.b - color.r) / diff;
|
||||
else
|
||||
h = 4.0 + (color.r - color.g) / diff;
|
||||
|
||||
h /= 6.0;
|
||||
}
|
||||
return vec3(h, s, l);
|
||||
}
|
||||
|
||||
highp float hueToIntensity(highp float v1, highp float v2, highp float h) {
|
||||
h = fract(h);
|
||||
if (h < 1.0 / 6.0)
|
||||
return v1 + (v2 - v1) * 6.0 * h;
|
||||
else if (h < 1.0 / 2.0)
|
||||
return v2;
|
||||
else if (h < 2.0 / 3.0)
|
||||
return v1 + (v2 - v1) * 6.0 * (2.0 / 3.0 - h);
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
highp vec3 HSLtoRGB(highp vec3 color) {
|
||||
highp float h = color.x;
|
||||
highp float l = color.z;
|
||||
highp float s = color.y;
|
||||
|
||||
if (s < 1.0 / 256.0)
|
||||
return vec3(l);
|
||||
|
||||
highp float v1;
|
||||
highp float v2;
|
||||
if (l < 0.5)
|
||||
v2 = l * (1.0 + s);
|
||||
else
|
||||
v2 = (l + s) - (s * l);
|
||||
|
||||
v1 = 2.0 * l - v2;
|
||||
|
||||
highp float d = 1.0 / 3.0;
|
||||
highp float r = hueToIntensity(v1, v2, h + d);
|
||||
highp float g = hueToIntensity(v1, v2, h);
|
||||
highp float b = hueToIntensity(v1, v2, h - d);
|
||||
return vec3(r, g, b);
|
||||
}
|
||||
|
||||
void main() {
|
||||
lowp vec4 sample = texture2D(source, qt_TexCoord0);
|
||||
sample = vec4(sample.rgb / max(1.0/256.0, sample.a), sample.a);
|
||||
sample.rgb = mix(vec3(dot(sample.rgb, vec3(0.2125, 0.7154, 0.0721))), sample.rgb, 1.0 + hsl.y);
|
||||
sample.xyz = RGBtoHSL(sample.rgb);
|
||||
sample.rgb = HSLtoRGB(vec3(sample.x + hsl.x, sample.y, sample.z));
|
||||
highp float c = step(0.0, hsl.z);
|
||||
sample.rgb = mix(sample.rgb, vec3(c), abs(hsl.z));
|
||||
gl_FragColor = vec4(sample.rgb * sample.a, sample.a) * qt_Opacity;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype InnerShadow
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-drop-shadow
|
||||
\brief Generates a colorized and blurred shadow inside the
|
||||
source.
|
||||
|
||||
By default the effect produces a high quality shadow image, thus the
|
||||
rendering speed of the shadow might not be the highest possible. The
|
||||
rendering speed is reduced especially if the shadow edges are heavily
|
||||
softened. For use cases that require faster rendering speed and for which
|
||||
the highest possible visual quality is not necessary, property
|
||||
\l{InnerShadow::fast}{fast} can be set to true.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_butterfly.png
|
||||
\li \image InnerShadow_butterfly.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet InnerShadow-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that is going to be used as the
|
||||
source for the generated shadow.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
Radius defines the softness of the shadow. A larger radius causes the
|
||||
edges of the shadow to appear more blurry.
|
||||
|
||||
Depending on the radius value, value of the
|
||||
\l{InnerShadow::samples}{samples} should be set to sufficiently large to
|
||||
ensure the visual quality.
|
||||
|
||||
The value ranges from 0.0 (no blur) to inf. By default, the property is
|
||||
set to \c 0.0 (no blur).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different radius values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image InnerShadow_radius1.png
|
||||
\li \image InnerShadow_radius2.png
|
||||
\li \image InnerShadow_radius3.png
|
||||
\row
|
||||
\li \b { radius: 0 }
|
||||
\li \b { radius: 6 }
|
||||
\li \b { radius: 12 }
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\row
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\row
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\row
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real radius: 0.0
|
||||
|
||||
/*!
|
||||
This property defines how many samples are taken per pixel when edge
|
||||
softening blur calculation is done. Larger value produces better
|
||||
quality, but is slower to render.
|
||||
|
||||
Ideally, this value should be twice as large as the highest required
|
||||
radius value, for example, if the radius is animated between 0.0 and
|
||||
4.0, samples should be set to 8.
|
||||
|
||||
The value ranges from 0 to 32. By default, the property is set to \c 0.
|
||||
|
||||
This property is not intended to be animated. Changing this property may
|
||||
cause the underlying OpenGL shaders to be recompiled.
|
||||
|
||||
When \l{InnerShadow::fast}{fast} property is set to true, this property
|
||||
has no effect.
|
||||
|
||||
*/
|
||||
property int samples: 0
|
||||
|
||||
/*!
|
||||
This property defines how large part of the shadow color is strenghtened
|
||||
near the source edges.
|
||||
|
||||
The value ranges from 0.0 to 1.0. By default, the property is set to \c
|
||||
0.5.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different spread values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image InnerShadow_spread1.png
|
||||
\li \image InnerShadow_spread2.png
|
||||
\li \image InnerShadow_spread3.png
|
||||
\row
|
||||
\li \b { spread: 0.0 }
|
||||
\li \b { spread: 0.3 }
|
||||
\li \b { spread: 0.5 }
|
||||
\row
|
||||
\li \l radius: 16
|
||||
\li \l radius: 16
|
||||
\li \l radius: 16
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\row
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\row
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real spread: 0.0
|
||||
|
||||
/*!
|
||||
This property defines the RGBA color value which is used for the shadow.
|
||||
|
||||
By default, the property is set to \c "black".
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different color values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image InnerShadow_color1.png
|
||||
\li \image InnerShadow_color2.png
|
||||
\li \image InnerShadow_color3.png
|
||||
\row
|
||||
\li \b { color: #000000 }
|
||||
\li \b { color: #ffffff }
|
||||
\li \b { color: #ff0000 }
|
||||
\row
|
||||
\li \l radius: 16
|
||||
\li \l radius: 16
|
||||
\li \l radius: 16
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\row
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\row
|
||||
\li \l spread: 0.2
|
||||
\li \l spread: 0.2
|
||||
\li \l spread: 0.2
|
||||
\endtable
|
||||
*/
|
||||
property color color: "black"
|
||||
|
||||
/*!
|
||||
\qmlproperty real QtGraphicalEffects1::InnerShadow::horizontalOffset
|
||||
\qmlproperty real QtGraphicalEffects1::InnerShadow::verticalOffset
|
||||
|
||||
HorizontalOffset and verticalOffset properties define the offset for the
|
||||
rendered shadow compared to the InnerShadow item position. Often, the
|
||||
InnerShadow item is anchored so that it fills the source element. In
|
||||
this case, if the HorizontalOffset and verticalOffset properties are set
|
||||
to 0, the shadow is rendered fully inside the source item. By changing
|
||||
the offset properties, the shadow can be positioned relatively to the
|
||||
source item.
|
||||
|
||||
The values range from -inf to inf. By default, the properties are set to
|
||||
\c 0.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different horizontalOffset values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image InnerShadow_horizontalOffset1.png
|
||||
\li \image InnerShadow_horizontalOffset2.png
|
||||
\li \image InnerShadow_horizontalOffset3.png
|
||||
\row
|
||||
\li \b { horizontalOffset: -20 }
|
||||
\li \b { horizontalOffset: 0 }
|
||||
\li \b { horizontalOffset: 20 }
|
||||
\row
|
||||
\li \l radius: 16
|
||||
\li \l radius: 16
|
||||
\li \l radius: 16
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\row
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\row
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\li \l spread: 0
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real horizontalOffset: 0
|
||||
property real verticalOffset: 0
|
||||
|
||||
/*!
|
||||
This property selects the blurring algorithm that is used to produce the
|
||||
softness for the effect. Setting this to true enables fast algorithm,
|
||||
setting value to false produces higher quality result.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different fast values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image InnerShadow_fast1.png
|
||||
\li \image InnerShadow_fast2.png
|
||||
\row
|
||||
\li \b { fast: false }
|
||||
\li \b { fast: true }
|
||||
\row
|
||||
\li \l radius: 16
|
||||
\li \l radius: 16
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l color: #000000
|
||||
\li \l color: #000000
|
||||
\row
|
||||
\li \l horizontalOffset: 0
|
||||
\li \l horizontalOffset: 0
|
||||
\row
|
||||
\li \l verticalOffset: 0
|
||||
\li \l verticalOffset: 0
|
||||
\row
|
||||
\li \l spread: 0.2
|
||||
\li \l spread: 0.2
|
||||
\endtable
|
||||
*/
|
||||
property bool fast: false
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance. Every time the source or effect
|
||||
properties are changed, the pixels in the cache must be updated. Memory
|
||||
consumption is increased, because an extra buffer of memory is required
|
||||
for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
Loader {
|
||||
anchors.fill: parent
|
||||
sourceComponent: rootItem.fast ? innerShadow : gaussianInnerShadow
|
||||
}
|
||||
|
||||
Component {
|
||||
id: gaussianInnerShadow
|
||||
GaussianInnerShadow {
|
||||
anchors.fill: parent
|
||||
source: rootItem.source
|
||||
radius: rootItem.radius
|
||||
maximumRadius: rootItem.samples * 0.5
|
||||
color: rootItem.color
|
||||
cached: rootItem.cached
|
||||
spread: rootItem.spread
|
||||
horizontalOffset: rootItem.horizontalOffset
|
||||
verticalOffset: rootItem.verticalOffset
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: innerShadow
|
||||
FastInnerShadow {
|
||||
anchors.fill: parent
|
||||
source: rootItem.source
|
||||
blur: Math.pow(rootItem.radius / 64.0, 0.4)
|
||||
color: rootItem.color
|
||||
cached: rootItem.cached
|
||||
spread: rootItem.spread
|
||||
horizontalOffset: rootItem.horizontalOffset
|
||||
verticalOffset: rootItem.verticalOffset
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,472 @@
|
||||
/*****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Add-On Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
*****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype LevelAdjust
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-color
|
||||
\brief Adjusts color levels in the RGBA color space.
|
||||
|
||||
This effect adjusts the source item colors separately for each color
|
||||
channel. Source item contrast can be adjusted and color balance altered.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_butterfly.png
|
||||
\li \image LevelAdjust_butterfly.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet LevelAdjust-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that provides the source pixels
|
||||
for the effect.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines the change factor for how the value of each pixel
|
||||
color channel is altered according to the equation:
|
||||
|
||||
\code result.rgb = pow(original.rgb, 1.0 / gamma.rgb); \endcode
|
||||
|
||||
Setting the gamma values under QtVector3d(1.0, 1.0, 1.0) makes the image
|
||||
darker, the values above QtVector3d(1.0, 1.0, 1.0) lighten it.
|
||||
|
||||
The value ranges from QtVector3d(0.0, 0.0, 0.0) (darkest) to inf
|
||||
(lightest). By default, the property is set to \c QtVector3d(1.0, 1.0,
|
||||
1.0) (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different gamma values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LevelAdjust_gamma1.png
|
||||
\li \image LevelAdjust_gamma2.png
|
||||
\li \image LevelAdjust_gamma3.png
|
||||
\row
|
||||
\li \b { gamma: Qt.vector3d(1.0, 1.0, 1.0) }
|
||||
\li \b { gamma: Qt.vector3d(1.0, 0.4, 2.0) }
|
||||
\li \b { gamma: Qt.vector3d(1.0, 0.1, 4.0) }
|
||||
\row
|
||||
\li \l minimumInput: #000000
|
||||
\li \l minimumInput: #000000
|
||||
\li \l minimumInput: #000000
|
||||
\row
|
||||
\li \l maximumInput: #ffffff
|
||||
\li \l maximumInput: #ffffff
|
||||
\li \l maximumInput: #ffffff
|
||||
\row
|
||||
\li \l minimumOutput: #000000
|
||||
\li \l minimumOutput: #000000
|
||||
\li \l minimumOutput: #000000
|
||||
\row
|
||||
\li \l maximumOutput: #ffffff
|
||||
\li \l maximumOutput: #ffffff
|
||||
\li \l maximumOutput: #ffffff
|
||||
\endtable
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Pixel color channel luminance curves of the above images.
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LevelAdjust_default_curve.png
|
||||
\li \image LevelAdjust_gamma2_curve.png
|
||||
\li \image LevelAdjust_gamma3_curve.png
|
||||
\row
|
||||
\li X-axis: pixel original luminance
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li Y-axis: color channel luminance with effect applied
|
||||
\li
|
||||
\li
|
||||
\endtable
|
||||
*/
|
||||
property variant gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
|
||||
/*!
|
||||
This property defines the minimum input level for each color channel. It
|
||||
sets the black-point, all pixels having lower value than this property
|
||||
are rendered as black (per color channel). Increasing the value darkens
|
||||
the dark areas.
|
||||
|
||||
The value ranges from "#00000000" to "#ffffffff". By default, the
|
||||
property is set to \c "#00000000" (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different minimumInput values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LevelAdjust_minimumInput1.png
|
||||
\li \image LevelAdjust_minimumInput2.png
|
||||
\li \image LevelAdjust_minimumInput3.png
|
||||
\row
|
||||
\li \b { minimumInput: #00000000 }
|
||||
\li \b { minimumInput: #00000040 }
|
||||
\li \b { minimumInput: #00000070 }
|
||||
\row
|
||||
\li \l maximumInput: #ffffff
|
||||
\li \l maximumInput: #ffffff
|
||||
\li \l maximumInput: #ffffff
|
||||
\row
|
||||
\li \l minimumOutput: #000000
|
||||
\li \l minimumOutput: #000000
|
||||
\li \l minimumOutput: #000000
|
||||
\row
|
||||
\li \l maximumOutput: #ffffff
|
||||
\li \l maximumOutput: #ffffff
|
||||
\li \l maximumOutput: #ffffff
|
||||
\row
|
||||
\li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
\li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
\li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
\endtable
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Pixel color channel luminance curves of the above images.
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LevelAdjust_default_curve.png
|
||||
\li \image LevelAdjust_minimumInput2_curve.png
|
||||
\li \image LevelAdjust_minimumInput3_curve.png
|
||||
\row
|
||||
\li X-axis: pixel original luminance
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li Y-axis: color channel luminance with effect applied
|
||||
\li
|
||||
\li
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property color minimumInput: Qt.rgba(0.0, 0.0, 0.0, 0.0)
|
||||
|
||||
/*!
|
||||
This property defines the maximum input level for each color channel.
|
||||
It sets the white-point, all pixels having higher value than this
|
||||
property are rendered as white (per color channel).
|
||||
Decreasing the value lightens the light areas.
|
||||
|
||||
The value ranges from "#ffffffff" to "#00000000". By default, the
|
||||
property is set to \c "#ffffffff" (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different maximumInput values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LevelAdjust_maximumInput1.png
|
||||
\li \image LevelAdjust_maximumInput2.png
|
||||
\li \image LevelAdjust_maximumInput3.png
|
||||
\row
|
||||
\li \b { maximumInput: #FFFFFFFF }
|
||||
\li \b { maximumInput: #FFFFFF80 }
|
||||
\li \b { maximumInput: #FFFFFF30 }
|
||||
\row
|
||||
\li \l minimumInput: #000000
|
||||
\li \l minimumInput: #000000
|
||||
\li \l minimumInput: #000000
|
||||
\row
|
||||
\li \l minimumOutput: #000000
|
||||
\li \l minimumOutput: #000000
|
||||
\li \l minimumOutput: #000000
|
||||
\row
|
||||
\li \l maximumOutput: #ffffff
|
||||
\li \l maximumOutput: #ffffff
|
||||
\li \l maximumOutput: #ffffff
|
||||
\row
|
||||
\li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
\li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
\li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
\endtable
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Pixel color channel luminance curves of the above images.
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LevelAdjust_default_curve.png
|
||||
\li \image LevelAdjust_maximumInput2_curve.png
|
||||
\li \image LevelAdjust_maximumInput3_curve.png
|
||||
\row
|
||||
\li X-axis: pixel original luminance
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li Y-axis: color channel luminance with effect applied
|
||||
\li
|
||||
\li
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property color maximumInput: Qt.rgba(1.0, 1.0, 1.0, 1.0)
|
||||
|
||||
/*!
|
||||
This property defines the minimum output level for each color channel.
|
||||
Increasing the value lightens the dark areas, reducing the contrast.
|
||||
|
||||
The value ranges from "#00000000" to "#ffffffff". By default, the
|
||||
property is set to \c "#00000000" (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different minimumOutput values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LevelAdjust_minimumOutput1.png
|
||||
\li \image LevelAdjust_minimumOutput2.png
|
||||
\li \image LevelAdjust_minimumOutput3.png
|
||||
\row
|
||||
\li \b { minimumOutput: #00000000 }
|
||||
\li \b { minimumOutput: #00000070 }
|
||||
\li \b { minimumOutput: #000000A0 }
|
||||
\row
|
||||
\li \l minimumInput: #000000
|
||||
\li \l minimumInput: #000000
|
||||
\li \l minimumInput: #000000
|
||||
\row
|
||||
\li \l maximumInput: #ffffff
|
||||
\li \l maximumInput: #ffffff
|
||||
\li \l maximumInput: #ffffff
|
||||
\row
|
||||
\li \l maximumOutput: #ffffff
|
||||
\li \l maximumOutput: #ffffff
|
||||
\li \l maximumOutput: #ffffff
|
||||
\row
|
||||
\li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
\li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
\li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
\endtable
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Pixel color channel luminance curves of the above images.
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LevelAdjust_default_curve.png
|
||||
\li \image LevelAdjust_minimumOutput2_curve.png
|
||||
\li \image LevelAdjust_minimumOutput3_curve.png
|
||||
\row
|
||||
\li X-axis: pixel original luminance
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li Y-axis: color channel luminance with effect applied
|
||||
\li
|
||||
\li
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property color minimumOutput: Qt.rgba(0.0, 0.0, 0.0, 0.0)
|
||||
|
||||
/*!
|
||||
This property defines the maximum output level for each color channel.
|
||||
Decreasing the value darkens the light areas, reducing the contrast.
|
||||
|
||||
The value ranges from "#ffffffff" to "#00000000". By default, the
|
||||
property is set to \c "#ffffffff" (no change).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different maximumOutput values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LevelAdjust_maximumOutput1.png
|
||||
\li \image LevelAdjust_maximumOutput2.png
|
||||
\li \image LevelAdjust_maximumOutput3.png
|
||||
\row
|
||||
\li \b { maximumOutput: #FFFFFFFF }
|
||||
\li \b { maximumOutput: #FFFFFF80 }
|
||||
\li \b { maximumOutput: #FFFFFF30 }
|
||||
\row
|
||||
\li \l minimumInput: #000000
|
||||
\li \l minimumInput: #000000
|
||||
\li \l minimumInput: #000000
|
||||
\row
|
||||
\li \l maximumInput: #ffffff
|
||||
\li \l maximumInput: #ffffff
|
||||
\li \l maximumInput: #ffffff
|
||||
\row
|
||||
\li \l minimumOutput: #000000
|
||||
\li \l minimumOutput: #000000
|
||||
\li \l minimumOutput: #000000
|
||||
\row
|
||||
\li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
\li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
\li \l gamma: Qt.vector3d(1.0, 1.0, 1.0)
|
||||
\endtable
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Pixel color channel luminance curves of the above images.
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LevelAdjust_default_curve.png
|
||||
\li \image LevelAdjust_maximumOutput2_curve.png
|
||||
\li \image LevelAdjust_maximumOutput3_curve.png
|
||||
\row
|
||||
\li X-axis: pixel original luminance
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li Y-axis: color channel luminance with effect applied
|
||||
\li
|
||||
\li
|
||||
\endtable
|
||||
*/
|
||||
property color maximumOutput: Qt.rgba(1.0, 1.0, 1.0, 1.0)
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: parent
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
property variant source: sourceProxy.output
|
||||
property variant minimumInputRGB: Qt.vector3d(rootItem.minimumInput.r, rootItem.minimumInput.g, rootItem.minimumInput.b)
|
||||
property variant maximumInputRGB: Qt.vector3d(rootItem.maximumInput.r, rootItem.maximumInput.g, rootItem.maximumInput.b)
|
||||
property real minimumInputAlpha: rootItem.minimumInput.a
|
||||
property real maximumInputAlpha: rootItem.maximumInput.a
|
||||
property variant minimumOutputRGB: Qt.vector3d(rootItem.minimumOutput.r, rootItem.minimumOutput.g, rootItem.minimumOutput.b)
|
||||
property variant maximumOutputRGB: Qt.vector3d(rootItem.maximumOutput.r, rootItem.maximumOutput.g, rootItem.maximumOutput.b)
|
||||
property real minimumOutputAlpha: rootItem.minimumOutput.a
|
||||
property real maximumOutputAlpha: rootItem.maximumOutput.a
|
||||
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))
|
||||
anchors.fill: parent
|
||||
|
||||
fragmentShader: "
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform lowp sampler2D source;
|
||||
uniform highp vec3 minimumInputRGB;
|
||||
uniform highp vec3 maximumInputRGB;
|
||||
uniform highp float minimumInputAlpha;
|
||||
uniform highp float maximumInputAlpha;
|
||||
uniform highp vec3 minimumOutputRGB;
|
||||
uniform highp vec3 maximumOutputRGB;
|
||||
uniform highp float minimumOutputAlpha;
|
||||
uniform highp float maximumOutputAlpha;
|
||||
uniform highp vec3 gamma;
|
||||
|
||||
highp float linearstep(highp float e0, highp float e1, highp float x) {
|
||||
return clamp((x - e0) / (e1 - e0), 0.0, 1.0);
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
highp vec4 textureColor = texture2D(source, qt_TexCoord0.st);
|
||||
highp vec4 color = vec4(textureColor.rgb / max(1.0/256.0, textureColor.a), textureColor.a);
|
||||
|
||||
color.r = linearstep(minimumInputRGB.r, maximumInputRGB.r, color.r);
|
||||
color.g = linearstep(minimumInputRGB.g, maximumInputRGB.g, color.g);
|
||||
color.b = linearstep(minimumInputRGB.b, maximumInputRGB.b, color.b);
|
||||
color.a = linearstep(minimumInputAlpha, maximumInputAlpha, color.a);
|
||||
|
||||
color.rgb = pow(color.rgb, gamma);
|
||||
|
||||
color.r = minimumOutputRGB.r + color.r * (maximumOutputRGB.r - minimumOutputRGB.r);
|
||||
color.g = minimumOutputRGB.g + color.g * (maximumOutputRGB.g - minimumOutputRGB.g);
|
||||
color.b = minimumOutputRGB.b + color.b * (maximumOutputRGB.b - minimumOutputRGB.b);
|
||||
color.a = minimumOutputAlpha + color.a * (maximumOutputAlpha - minimumOutputAlpha);
|
||||
|
||||
gl_FragColor = vec4(color.rgb * color.a, color.a) * qt_Opacity;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype LinearGradient
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-gradient
|
||||
\brief Draws a linear gradient.
|
||||
|
||||
A gradient is defined by two or more colors, which are blended seamlessly.
|
||||
The colors start from the given start point and end to the given end point.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image LinearGradient.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet LinearGradient-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the starting point where the color at gradient
|
||||
position of 0.0 is rendered. Colors at larger position values are
|
||||
rendered linearly towards the end point. The point is given in pixels
|
||||
and the default value is Qt.point(0, 0). Setting the default values for
|
||||
the start and \l{LinearGradient::end}{end} results in a full height
|
||||
linear gradient on the y-axis.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different start values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LinearGradient_start1.png
|
||||
\li \image LinearGradient_start2.png
|
||||
\li \image LinearGradient_start3.png
|
||||
\row
|
||||
\li \b { start: QPoint(0, 0) }
|
||||
\li \b { start: QPoint(150, 150) }
|
||||
\li \b { start: QPoint(300, 0) }
|
||||
\row
|
||||
\li \l end: QPoint(300, 300)
|
||||
\li \l end: QPoint(300, 300)
|
||||
\li \l end: QPoint(300, 300)
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property variant start: Qt.point(0, 0)
|
||||
|
||||
/*!
|
||||
This property defines the ending point where the color at gradient
|
||||
position of 1.0 is rendered. Colors at smaller position values are
|
||||
rendered linearly towards the start point. The point is given in pixels
|
||||
and the default value is Qt.point(0, height). Setting the default values
|
||||
for the \l{LinearGradient::start}{start} and end results in a full
|
||||
height linear gradient on the y-axis.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different end values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LinearGradient_end1.png
|
||||
\li \image LinearGradient_end2.png
|
||||
\li \image LinearGradient_end3.png
|
||||
\row
|
||||
\li \b { end: Qt.point(300, 300) }
|
||||
\li \b { end: Qt.point(150, 150) }
|
||||
\li \b { end: Qt.point(300, 0) }
|
||||
\row
|
||||
\li \l start: Qt.point(0, 0)
|
||||
\li \l start: Qt.point(0, 0)
|
||||
\li \l start: Qt.point(0, 0)
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property variant end: Qt.point(0, height)
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
/*!
|
||||
This property defines the item that is going to be filled with gradient.
|
||||
Source item gets rendered into an intermediate pixel buffer and the
|
||||
alpha values from the result are used to determine the gradient's pixels
|
||||
visibility in the display. The default value for source is undefined and
|
||||
in that case whole effect area is filled with gradient.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different source values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LinearGradient_maskSource1.png
|
||||
\li \image LinearGradient_maskSource2.png
|
||||
\row
|
||||
\li \b { source: undefined }
|
||||
\li \b { source: Image { source: images/butterfly.png } }
|
||||
\row
|
||||
\li \l start: Qt.point(0, 0)
|
||||
\li \l start: Qt.point(0, 0)
|
||||
\row
|
||||
\li \l end: Qt.point(300, 300)
|
||||
\li \l end: Qt.point(300, 300)
|
||||
\endtable
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
|
||||
/*!
|
||||
A gradient is defined by two or more colors, which are blended
|
||||
seamlessly. The colors are specified as a set of GradientStop child
|
||||
items, each of which defines a position on the gradient from 0.0 to 1.0
|
||||
and a color. The position of each GradientStop is defined by the
|
||||
position property, and the color is definded by the color property.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different gradient values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image LinearGradient_gradient1.png
|
||||
\li \image LinearGradient_gradient2.png
|
||||
\li \image LinearGradient_gradient3.png
|
||||
\row
|
||||
\li \b {gradient:} \code
|
||||
Gradient {
|
||||
GradientStop { position: 0.000
|
||||
color: Qt.rgba(1, 0, 0, 1) }
|
||||
GradientStop { position: 0.167;
|
||||
color: Qt.rgba(1, 1, 0, 1) }
|
||||
GradientStop { position: 0.333;
|
||||
color: Qt.rgba(0, 1, 0, 1) }
|
||||
GradientStop { position: 0.500;
|
||||
color: Qt.rgba(0, 1, 1, 1) }
|
||||
GradientStop { position: 0.667;
|
||||
color: Qt.rgba(0, 0, 1, 1) }
|
||||
GradientStop { position: 0.833;
|
||||
color: Qt.rgba(1, 0, 1, 1) }
|
||||
GradientStop { position: 1.000;
|
||||
color: Qt.rgba(1, 0, 0, 1) }
|
||||
}
|
||||
\endcode
|
||||
\li \b {gradient:} \code
|
||||
Gradient {
|
||||
GradientStop { position: 0.0
|
||||
color: "#F0F0F0"
|
||||
}
|
||||
GradientStop { position: 0.5
|
||||
color: "#000000"
|
||||
}
|
||||
GradientStop { position: 1.0
|
||||
color: "#F0F0F0"
|
||||
}
|
||||
}
|
||||
\endcode
|
||||
\li \b {gradient:} \code
|
||||
Gradient {
|
||||
GradientStop { position: 0.0
|
||||
color: "#00000000"
|
||||
}
|
||||
GradientStop { position: 1.0
|
||||
color: "#FF000000"
|
||||
}
|
||||
}
|
||||
\endcode
|
||||
\row
|
||||
\li \l start: Qt.point(0, 0)
|
||||
\li \l start: Qt.point(0, 0)
|
||||
\li \l start: Qt.point(0, 0)
|
||||
\row
|
||||
\li \l end: Qt.point(300, 300)
|
||||
\li \l end: Qt.point(300, 300)
|
||||
\li \l end: Qt.point(300, 300)
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property Gradient gradient: Gradient {
|
||||
GradientStop { position: 0.0; color: "white" }
|
||||
GradientStop { position: 1.0; color: "black" }
|
||||
}
|
||||
|
||||
SourceProxy {
|
||||
id: maskSourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: gradientSource
|
||||
sourceItem: Rectangle {
|
||||
width: 16
|
||||
height: 256
|
||||
gradient: rootItem.gradient
|
||||
smooth: true
|
||||
}
|
||||
smooth: true
|
||||
hideSource: true
|
||||
visible: false
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: parent
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
property variant source: gradientSource
|
||||
property variant maskSource: maskSourceProxy.output
|
||||
property variant startPoint: Qt.point(start.x / width, start.y / height)
|
||||
property real dx: end.x - start.x
|
||||
property real dy: end.y - start.y
|
||||
property real l: 1.0 / Math.sqrt(Math.pow(dx / width, 2.0) + Math.pow(dy / height, 2.0))
|
||||
property real angle: Math.atan2(dx, dy)
|
||||
property variant matrixData: Qt.point(Math.sin(angle), Math.cos(angle))
|
||||
|
||||
vertexShader: "
|
||||
attribute highp vec4 qt_Vertex;
|
||||
attribute highp vec2 qt_MultiTexCoord0;
|
||||
uniform highp mat4 qt_Matrix;
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
varying highp vec2 qt_TexCoord1;
|
||||
uniform highp vec2 startPoint;
|
||||
uniform highp float l;
|
||||
uniform highp vec2 matrixData;
|
||||
|
||||
void main() {
|
||||
highp mat2 rot = mat2(matrixData.y, -matrixData.x,
|
||||
matrixData.x, matrixData.y);
|
||||
|
||||
qt_TexCoord0 = qt_MultiTexCoord0;
|
||||
|
||||
qt_TexCoord1 = qt_MultiTexCoord0 * l;
|
||||
qt_TexCoord1 -= startPoint * l;
|
||||
qt_TexCoord1 *= rot;
|
||||
|
||||
gl_Position = qt_Matrix * qt_Vertex;
|
||||
}
|
||||
"
|
||||
|
||||
fragmentShader: maskSource == undefined ? noMaskShader : maskShader
|
||||
|
||||
onFragmentShaderChanged: lChanged()
|
||||
|
||||
property string maskShader: "
|
||||
uniform lowp sampler2D source;
|
||||
uniform lowp sampler2D maskSource;
|
||||
uniform lowp float qt_Opacity;
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
varying highp vec2 qt_TexCoord1;
|
||||
|
||||
void main() {
|
||||
lowp vec4 gradientColor = texture2D(source, qt_TexCoord1);
|
||||
lowp float maskAlpha = texture2D(maskSource, qt_TexCoord0).a;
|
||||
gl_FragColor = gradientColor * maskAlpha * qt_Opacity;
|
||||
}
|
||||
"
|
||||
|
||||
property string noMaskShader: "
|
||||
uniform lowp sampler2D source;
|
||||
uniform lowp float qt_Opacity;
|
||||
varying highp vec2 qt_TexCoord1;
|
||||
|
||||
void main() {
|
||||
gl_FragColor = texture2D(source, qt_TexCoord1) * qt_Opacity;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype MaskedBlur
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-blur
|
||||
\brief Applies a blur effect with a varying intesity.
|
||||
|
||||
MaskedBlur effect softens the image by blurring it. The intensity of the
|
||||
blur can be controlled for each pixel using maskSource so that some parts of
|
||||
the source are blurred more than others. By default the effect produces a
|
||||
high quality result, thus the rendering speed may not be the highest
|
||||
possible. The rendering speed is reduced especially if the
|
||||
\l{MaskedBlur::samples}{samples} is large. For use cases that require faster
|
||||
rendering speed and the highest possible visual quality is not necessary,
|
||||
property \l{MaskedBlur::fast}{fast} can be set to true.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li MaskSource
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image MaskedBlur_mask.png
|
||||
\li \image MaskedBlur_bug.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet MaskedBlur-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that is going to be blurred.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines the item that is controlling the final intensity
|
||||
of the blur. The pixel alpha channel value from maskSource defines the
|
||||
actual blur radius that is going to be used for blurring the
|
||||
corresponding source pixel.
|
||||
|
||||
Opaque maskSource pixels produce blur with specified
|
||||
\l{MaskedBlur::radius}{radius}, while transparent pixels suppress the
|
||||
blur completely. Semitransparent maskSource pixels produce blur with a
|
||||
radius that is interpolated according to the pixel transparency level.
|
||||
*/
|
||||
property variant maskSource
|
||||
|
||||
/*!
|
||||
This property defines the distance of the neighboring pixels which
|
||||
affect the blurring of an individual pixel. A larger radius increases
|
||||
the blur effect.
|
||||
|
||||
Depending on the radius value, value of the
|
||||
\l{MaskedBlur::samples}{samples} should be set to sufficiently large to
|
||||
ensure the visual quality.
|
||||
|
||||
The value ranges from 0.0 (no blur) to inf. By default, the property is
|
||||
set to \c 0.0 (no blur).
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different radius values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image MaskedBlur_radius1.png
|
||||
\li \image MaskedBlur_radius2.png
|
||||
\li \image MaskedBlur_radius3.png
|
||||
\row
|
||||
\li \b { radius: 0 }
|
||||
\li \b { radius: 8 }
|
||||
\li \b { radius: 16 }
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l transparentBorder: false
|
||||
\li \l transparentBorder: false
|
||||
\li \l transparentBorder: false
|
||||
\row
|
||||
\li \l fast: false
|
||||
\li \l fast: false
|
||||
\li \l fast: false
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property real radius: 0.0
|
||||
|
||||
/*!
|
||||
This property defines how many samples are taken per pixel when blur
|
||||
calculation is done. Larger value produces better quality, but is slower
|
||||
to render.
|
||||
|
||||
Ideally, this value should be twice as large as the highest required
|
||||
radius value, for example, if the radius is animated between 0.0 and
|
||||
4.0, samples should be set to 8.
|
||||
|
||||
The value ranges from 0 to 32. By default, the property is set to \c 0.
|
||||
|
||||
This property is not intended to be animated. Changing this property may
|
||||
cause the underlying OpenGL shaders to be recompiled.
|
||||
|
||||
When \l{MaskedBlur::fast}{fast} property is set to true, this property
|
||||
has no effect.
|
||||
*/
|
||||
property int samples: 0
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance. Every time the source or effect
|
||||
properties are changed, the pixels in the cache must be updated. Memory
|
||||
consumption is increased, because an extra buffer of memory is required
|
||||
for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
/*!
|
||||
This property selects the blurring algorithm that is used to produce the
|
||||
blur. Setting this to true enables fast algorithm, setting value to
|
||||
false produces higher quality result.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different fast values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image MaskedBlur_fast1.png
|
||||
\li \image MaskedBlur_fast2.png
|
||||
\row
|
||||
\li \b { fast: false }
|
||||
\li \b { fast: true }
|
||||
\row
|
||||
\li \l radius: 16
|
||||
\li \l radius: 16
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l transparentBorder: false
|
||||
\li \l transparentBorder: false
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property bool fast: false
|
||||
|
||||
/*!
|
||||
This property defines the blur behavior near the edges of the item,
|
||||
where the pixel blurring is affected by the pixels outside the source
|
||||
edges.
|
||||
|
||||
If the property is set to \c true, the pixels outside the source are
|
||||
interpreted to be transparent, which is similar to OpenGL
|
||||
clamp-to-border extension. The blur is expanded slightly outside the
|
||||
effect item area.
|
||||
|
||||
If the property is set to \c false, the pixels outside the source are
|
||||
interpreted to contain the same color as the pixels at the edge of the
|
||||
item, which is similar to OpenGL clamp-to-edge behavior. The blur does
|
||||
not expand outside the effect item area.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Output examples with different transparentBorder values
|
||||
\li
|
||||
\li
|
||||
\row
|
||||
\li \image MaskedBlur_transparentBorder1.png
|
||||
\li \image MaskedBlur_transparentBorder2.png
|
||||
\row
|
||||
\li \b { transparentBorder: false }
|
||||
\li \b { transparentBorder: true }
|
||||
\row
|
||||
\li \l radius: 64
|
||||
\li \l radius: 64
|
||||
\row
|
||||
\li \l samples: 24
|
||||
\li \l samples: 24
|
||||
\row
|
||||
\li \l fast: true
|
||||
\li \l fast: true
|
||||
\endtable
|
||||
|
||||
*/
|
||||
property bool transparentBorder: false
|
||||
|
||||
Loader {
|
||||
id: loaderItem
|
||||
anchors.fill: parent
|
||||
sourceComponent: rootItem.fast ? fastBlur : gaussianBlur
|
||||
}
|
||||
|
||||
Component {
|
||||
id: gaussianBlur
|
||||
GaussianMaskedBlur {
|
||||
anchors.fill: parent
|
||||
source: rootItem.source
|
||||
maskSource: rootItem.maskSource
|
||||
radius: rootItem.radius
|
||||
maximumRadius: rootItem.samples * 0.5
|
||||
transparentBorder: rootItem.transparentBorder
|
||||
cached: rootItem.cached
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: fastBlur
|
||||
FastMaskedBlur {
|
||||
anchors.fill: parent
|
||||
source:rootItem. source
|
||||
maskSource: rootItem.maskSource
|
||||
blur: Math.pow(rootItem.radius / 64.0, 0.4)
|
||||
transparentBorder: rootItem.transparentBorder
|
||||
cached: rootItem.cached
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Graphical Effects module.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "private"
|
||||
|
||||
/*!
|
||||
\qmltype OpacityMask
|
||||
\inqmlmodule QtGraphicalEffects
|
||||
\since QtGraphicalEffects 1.0
|
||||
\inherits QtQuick2::Item
|
||||
\ingroup qtgraphicaleffects-mask
|
||||
\brief Masks the source item with another item.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Source
|
||||
\li MaskSource
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image OpacityMask_mask.png
|
||||
\li \image OpacityMask_bug.png
|
||||
\endtable
|
||||
|
||||
\section1 Example
|
||||
|
||||
The following example shows how to apply the effect.
|
||||
\snippet OpacityMask-example.qml example
|
||||
|
||||
*/
|
||||
Item {
|
||||
id: rootItem
|
||||
|
||||
/*!
|
||||
This property defines the source item that is going to be masked.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting source to the effect's parent.
|
||||
*/
|
||||
property variant source
|
||||
|
||||
/*!
|
||||
This property defines the item that is going to be used as the mask. The
|
||||
mask item gets rendered into an intermediate pixel buffer and the alpha
|
||||
values from the result are used to determine the source item's pixels
|
||||
visibility in the display.
|
||||
|
||||
\table
|
||||
\header
|
||||
\li Original
|
||||
\li Mask
|
||||
\li Effect applied
|
||||
\row
|
||||
\li \image Original_bug.png
|
||||
\li \image OpacityMask_mask.png
|
||||
\li \image OpacityMask_bug.png
|
||||
\endtable
|
||||
*/
|
||||
property variant maskSource
|
||||
|
||||
/*!
|
||||
This property allows the effect output pixels to be cached in order to
|
||||
improve the rendering performance.
|
||||
|
||||
Every time the source or effect properties are changed, the pixels in
|
||||
the cache must be updated. Memory consumption is increased, because an
|
||||
extra buffer of memory is required for storing the effect output.
|
||||
|
||||
It is recommended to disable the cache when the source or the effect
|
||||
properties are animated.
|
||||
|
||||
By default, the property is set to \c false.
|
||||
|
||||
\note It is not supported to let the effect include itself, for
|
||||
instance by setting maskSource to the effect's parent.
|
||||
*/
|
||||
property bool cached: false
|
||||
|
||||
SourceProxy {
|
||||
id: sourceProxy
|
||||
input: rootItem.source
|
||||
}
|
||||
|
||||
SourceProxy {
|
||||
id: maskSourceProxy
|
||||
input: rootItem.maskSource
|
||||
}
|
||||
|
||||
ShaderEffectSource {
|
||||
id: cacheItem
|
||||
anchors.fill: parent
|
||||
visible: rootItem.cached
|
||||
smooth: true
|
||||
sourceItem: shaderItem
|
||||
live: true
|
||||
hideSource: visible
|
||||
}
|
||||
|
||||
ShaderEffect {
|
||||
id: shaderItem
|
||||
property variant source: sourceProxy.output
|
||||
property variant maskSource: maskSourceProxy.output
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
fragmentShader: "
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
uniform highp float qt_Opacity;
|
||||
uniform lowp sampler2D source;
|
||||
uniform lowp sampler2D maskSource;
|
||||
void main(void) {
|
||||
gl_FragColor = texture2D(source, qt_TexCoord0.st) * (texture2D(maskSource, qt_TexCoord0.st).a) * qt_Opacity;
|
||||
}
|
||||
"
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user