32 Q_ASSERT( top->
image() );
34 Q_ASSERT( bottom->
format() == QImage::Format_ARGB32_Premultiplied );
38 painter.drawImage( 0, 0, *top->
image() );
45 Q_ASSERT( top->
image() );
47 Q_ASSERT( bottom->
format() == QImage::Format_ARGB32_Premultiplied );
51 int const width = bottom->
width();
52 int const height = bottom->
height();
54 for (
int y = 0; y < height; ++y ) {
55 for (
int x = 0; x < width; ++x ) {
56 QRgb
const topPixel = topImagePremult.pixel( x, y );
57 int const gray = qGray( topPixel );
58 QRgb
const grayPixel = qRgb( gray, gray, gray );
73 Q_ASSERT( bottom->
size() == topImage->
size() );
74 Q_ASSERT( bottom->
format() == QImage::Format_ARGB32_Premultiplied );
76 int const width = bottom->
width();
77 int const height = bottom->
height();
79 for (
int y = 0; y < height; ++y ) {
80 for (
int x = 0; x < width; ++x ) {
81 QRgb
const bottomPixel = bottom->
pixel( x, y );
82 QRgb
const topPixel = topImagePremult.
pixel( x, y );
83 qreal
const resultRed = blendChannel( qRed( bottomPixel ) / 255.0,
84 qRed( topPixel ) / 255.0 );
85 qreal
const resultGreen = blendChannel( qGreen( bottomPixel ) / 255.0,
86 qGreen( topPixel ) / 255.0 );
87 qreal
const resultBlue = blendChannel( qBlue( bottomPixel ) / 255.0,
88 qBlue( topPixel ) / 255.0 );
89 bottom->
setPixel( x, y, qRgb( resultRed * 255.0,
91 resultBlue * 255.0 ));
99 qreal AllanonBlending::blendChannel( qreal
const bottomColorIntensity,
100 qreal
const topColorIntensity )
const
102 return ( bottomColorIntensity + topColorIntensity ) / 2.0;
105 qreal ArcusTangentBlending::blendChannel( qreal
const bottomColorIntensity,
106 qreal
const topColorIntensity )
const
108 return 2.0 * atan( topColorIntensity / bottomColorIntensity ) /
M_PI;
111 qreal GeometricMeanBlending::blendChannel( qreal
const bottomColorIntensity,
112 qreal
const topColorIntensity )
const
114 return sqrt( bottomColorIntensity * topColorIntensity );
117 qreal LinearLightBlending::blendChannel( qreal
const bottomColorIntensity,
118 qreal
const topColorIntensity )
const
120 return qMin( qreal( 1.0 ),
121 qMax( qreal( 0.0 ), qreal( bottomColorIntensity + 2.0 * topColorIntensity - 1.0 )));
124 qreal OverlayBlending::blendChannel( qreal
const bottomColorIntensity,
125 qreal
const topColorIntensity )
const
127 if ( bottomColorIntensity < 0.5 )
128 return 2.0 * bottomColorIntensity * topColorIntensity;
130 return 1.0 - 2.0 * ( 1.0 - bottomColorIntensity ) * ( 1.0 - topColorIntensity );
133 qreal ParallelBlending::blendChannel( qreal
const bottomColorIntensity,
134 qreal
const topColorIntensity )
const
136 Q_UNUSED(bottomColorIntensity);
137 Q_UNUSED(topColorIntensity);
142 qreal TextureBlending::blendChannel( qreal
const bottomColorIntensity,
143 qreal
const topColorIntensity )
const
145 Q_UNUSED(bottomColorIntensity);
146 Q_UNUSED(topColorIntensity);
154 qreal ColorBurnBlending::blendChannel( qreal
const bottomColorIntensity,
155 qreal
const topColorIntensity )
const
157 Q_UNUSED(bottomColorIntensity);
158 Q_UNUSED(topColorIntensity);
160 return qMin( qreal( 1.0 ),
161 qMax( qreal( 0.0 ), qreal( 1.0 - ( 1.0 - bottomColorIntensity ) / topColorIntensity )));
164 qreal DarkBlending::blendChannel( qreal
const bottomColorIntensity,
165 qreal
const topColorIntensity )
const
167 return ( bottomColorIntensity + 1.0 - topColorIntensity ) * topColorIntensity;
170 qreal DarkenBlending::blendChannel( qreal
const bottomColorIntensity,
171 qreal
const topColorIntensity )
const
174 return bottomColorIntensity > topColorIntensity ? topColorIntensity : bottomColorIntensity;
177 qreal DivideBlending::blendChannel( qreal
const bottomColorIntensity,
178 qreal
const topColorIntensity )
const
180 return log( 1.0 + bottomColorIntensity / ( 1.0 - topColorIntensity ) / 8.0) / log(2.0);
183 qreal GammaDarkBlending::blendChannel( qreal
const bottomColorIntensity,
184 qreal
const topColorIntensity )
const
186 return pow( bottomColorIntensity, 1.0 / topColorIntensity );
189 qreal LinearBurnBlending::blendChannel( qreal
const bottomColorIntensity,
190 qreal
const topColorIntensity )
const
192 return qMax( qreal(0.0), bottomColorIntensity + topColorIntensity - qreal( 1.0 ) );
195 qreal MultiplyBlending::blendChannel( qreal
const bottomColorIntensity,
196 qreal
const topColorIntensity )
const
198 return bottomColorIntensity * topColorIntensity;
201 qreal SubtractiveBlending::blendChannel( qreal
const bottomColorIntensity,
202 qreal
const topColorIntensity )
const
204 return qMax( bottomColorIntensity - topColorIntensity, qreal(0.0) );
210 qreal AdditiveBlending::blendChannel( qreal
const bottomColorIntensity,
211 qreal
const topColorIntensity )
const
213 return qMin( topColorIntensity + bottomColorIntensity, qreal(1.0) );
216 qreal ColorDodgeBlending::blendChannel( qreal
const bottomColorIntensity,
217 qreal
const topColorIntensity )
const
219 return qMin( qreal( 1.0 ),
220 qMax( qreal( 0.0 ), qreal( bottomColorIntensity / ( 1.0 - topColorIntensity ))));
223 qreal GammaLightBlending::blendChannel( qreal
const bottomColorIntensity,
224 qreal
const topColorIntensity )
const
226 return pow( bottomColorIntensity, topColorIntensity );
229 qreal HardLightBlending::blendChannel( qreal
const bottomColorIntensity,
230 qreal
const topColorIntensity )
const
232 return topColorIntensity < 0.5
233 ? 2.0 * bottomColorIntensity * topColorIntensity
234 : 1.0 - 2.0 * ( 1.0 - bottomColorIntensity ) * ( 1.0 - topColorIntensity );
237 qreal LightBlending::blendChannel( qreal
const bottomColorIntensity,
238 qreal
const topColorIntensity )
const
240 return bottomColorIntensity * ( 1.0 - topColorIntensity ) + pow( topColorIntensity, 2 );
243 qreal LightenBlending::blendChannel( qreal
const bottomColorIntensity,
244 qreal
const topColorIntensity )
const
247 return bottomColorIntensity < topColorIntensity ? topColorIntensity : bottomColorIntensity;
250 qreal PinLightBlending::blendChannel( qreal
const bottomColorIntensity,
251 qreal
const topColorIntensity )
const
253 return qMax( qreal(0.0), qMax( qreal(2.0 + topColorIntensity - 1.0),
254 qMin( bottomColorIntensity, qreal(2.0 * topColorIntensity ))));
257 qreal ScreenBlending::blendChannel( qreal
const bottomColorIntensity,
258 qreal
const topColorIntensity )
const
260 return 1.0 - ( 1.0 - bottomColorIntensity ) * ( 1.0 - topColorIntensity );
263 qreal SoftLightBlending::blendChannel( qreal
const bottomColorIntensity,
264 qreal
const topColorIntensity )
const
266 return pow( bottomColorIntensity, pow( 2.0, ( 2.0 * ( 0.5 - topColorIntensity ))));
269 qreal VividLightBlending::blendChannel( qreal
const bottomColorIntensity,
270 qreal
const topColorIntensity )
const
272 return topColorIntensity < 0.5
273 ? qMin( qreal( 1.0 ),
274 qMax( qreal( 0.0 ), qreal( 1.0 - ( 1.0 - bottomColorIntensity ) / ( 2.0 * topColorIntensity ))))
275 : qMin( qreal( 1.0 ),
276 qMax( qreal( 0.0 ), qreal( bottomColorIntensity / ( 2.0 * ( 1.0 - topColorIntensity )))));
282 qreal AdditiveSubtractiveBlending::blendChannel( qreal
const bottomColorIntensity,
283 qreal
const topColorIntensity )
const
285 Q_UNUSED(bottomColorIntensity);
286 Q_UNUSED(topColorIntensity);
293 qreal BleachBlending::blendChannel( qreal
const bottomColorIntensity,
294 qreal
const topColorIntensity )
const
297 return 1.0 - ( 1.0 - bottomColorIntensity ) * ( 1.0 - topColorIntensity );
300 qreal DifferenceBlending::blendChannel( qreal
const bottomColorIntensity,
301 qreal
const topColorIntensity )
const
303 return qMax( qMin( qreal( 1.0 ), qreal( bottomColorIntensity - topColorIntensity + 0.5 )),
307 qreal EquivalenceBlending::blendChannel( qreal
const bottomColorIntensity,
308 qreal
const topColorIntensity )
const
310 return 1.0 -
abs( bottomColorIntensity - topColorIntensity );
313 qreal HalfDifferenceBlending::blendChannel( qreal
const bottomColorIntensity,
314 qreal
const topColorIntensity )
const
316 return bottomColorIntensity + topColorIntensity
317 - 2.0 * ( bottomColorIntensity * topColorIntensity );
326 Q_ASSERT( topImage );
327 Q_ASSERT( bottom->
size() == topImage->
size() );
328 int const width = bottom->
width();
329 int const height = bottom->
height();
330 for (
int y = 0; y < height; ++y ) {
331 for (
int x = 0; x < width; ++x ) {
332 qreal
const c = qRed( topImage->
pixel( x, y )) / 255.0;
333 QRgb
const bottomPixel = bottom->
pixel( x, y );
334 int const bottomRed = qRed( bottomPixel );
335 int const bottomGreen = qGreen( bottomPixel );
336 int const bottomBlue = qBlue( bottomPixel );
337 bottom->
setPixel( x, y, qRgb((
int )( bottomRed + ( 255 - bottomRed ) * c ),
338 (
int )( bottomGreen + ( 255 - bottomGreen ) * c ),
339 (
int )( bottomBlue + ( 255 - bottomBlue ) * c )));
virtual void blend(QImage *const bottom, TextureTile const *const top) const
A class that resembles an image tile (extends Tile).
void setPixel(int x, int y, uint index_or_rgb)
virtual void blend(QImage *const bottom, TextureTile const *const top) const
QImage const * image() const
Returns the QImage that describes the look of the Tile.
QRgb pixel(int x, int y) const
virtual void blend(QImage *const bottom, TextureTile const *const top) const
double abs(const Vec3 &c)
virtual void blend(QImage *const bottom, TextureTile const *const top) const