17
17
18
18
#include " qgscubicrasterresampler.h"
19
19
#include < QImage>
20
- #include < cmath >
20
+ #include < qmath.h >
21
21
22
22
QgsCubicRasterResampler::QgsCubicRasterResampler ()
23
23
// red
@@ -56,16 +56,19 @@ void QgsCubicRasterResampler::resample( const QImage& srcImage, QImage& dstImage
56
56
int *blueMatrix = new int [ nCols * nRows ];
57
57
int *alphaMatrix = new int [ nCols * nRows ];
58
58
59
- for ( int i = 0 ; i < nRows; ++i )
59
+ for ( int heightIndex = 0 ; heightIndex < nRows; ++heightIndex )
60
60
{
61
- for ( int j = 0 ; j < nCols; ++j )
61
+ QRgb* scanLine = ( QRgb* )srcImage.constScanLine ( heightIndex );
62
+ for ( int widthIndex = 0 ; widthIndex < nCols; ++widthIndex )
62
63
{
63
- px = srcImage.pixel ( j, i );
64
+ px = scanLine[widthIndex];
65
+ int alpha = qAlpha ( px );
66
+ alphaMatrix[pos] = alpha;
64
67
redMatrix[pos] = qRed ( px );
65
68
greenMatrix[pos] = qGreen ( px );
66
69
blueMatrix[pos] = qBlue ( px );
67
- alphaMatrix[pos] = qAlpha ( px );
68
- ++pos ;
70
+
71
+ pos++ ;
69
72
}
70
73
}
71
74
@@ -97,82 +100,83 @@ void QgsCubicRasterResampler::resample( const QImage& srcImage, QImage& dstImage
97
100
double currentSrcCol;
98
101
int currentSrcColInt;
99
102
int currentSrcRowInt;
100
- int lastSrcColInt = -1 ;
101
- int lastSrcRowInt = -1 ;
103
+ int lastSrcColInt = -100 ;
104
+ int lastSrcRowInt = -100 ;
102
105
103
- int r, g, b, a;
104
106
// bernstein polynomials
105
107
double bp0u, bp1u, bp2u, bp3u, bp0v, bp1v, bp2v, bp3v;
106
108
double u, v;
107
109
108
- for ( int i = 0 ; i < dstImage.height (); ++i )
110
+ for ( int y = 0 ; y < dstImage.height (); ++y )
109
111
{
110
112
currentSrcRowInt = floor ( currentSrcRow );
111
113
v = currentSrcRow - currentSrcRowInt;
112
114
113
115
currentSrcCol = nSrcPerDstX / 2.0 - 0.5 ;
114
- for ( int j = 0 ; j < dstImage.width (); ++j )
116
+
117
+ QRgb* scanLine = ( QRgb* )dstImage.scanLine ( y );
118
+ for ( int x = 0 ; x < dstImage.width (); ++x )
115
119
{
116
120
currentSrcColInt = floor ( currentSrcCol );
117
121
u = currentSrcCol - currentSrcColInt;
118
122
119
123
// handle eight edge-cases
120
- if ( currentSrcRowInt < 0 || currentSrcRowInt >= ( srcImage.height () - 1 ) || currentSrcColInt < 0 || currentSrcColInt >= ( srcImage.width () - 1 ) )
124
+ if (( currentSrcRowInt < 0 || currentSrcRowInt >= ( srcImage.height () - 1 ) || currentSrcColInt < 0 || currentSrcColInt >= ( srcImage.width () - 1 ) ) )
121
125
{
122
126
QRgb px1, px2;
123
127
// pixels at the border of the source image needs to be handled in a special way
124
128
if ( currentSrcRowInt < 0 && currentSrcColInt < 0 )
125
129
{
126
- dstImage. setPixel ( j, i, srcImage.pixel ( 0 , 0 ) );
130
+ scanLine[x] = srcImage.pixel ( 0 , 0 );
127
131
}
128
132
else if ( currentSrcRowInt < 0 && currentSrcColInt >= ( srcImage.width () - 1 ) )
129
133
{
130
- dstImage. setPixel ( j, i, srcImage.pixel ( srcImage.width () - 1 , 0 ) );
134
+ scanLine[x] = srcImage.pixel ( srcImage.width () - 1 , 0 );
131
135
}
132
136
else if ( currentSrcRowInt >= ( srcImage.height () - 1 ) && currentSrcColInt >= ( srcImage.width () - 1 ) )
133
137
{
134
- dstImage. setPixel ( j, i, srcImage.pixel ( srcImage.width () - 1 , srcImage.height () - 1 ) );
138
+ scanLine[x] = srcImage.pixel ( srcImage.width () - 1 , srcImage.height () - 1 );
135
139
}
136
140
else if ( currentSrcRowInt >= ( srcImage.height () - 1 ) && currentSrcColInt < 0 )
137
141
{
138
- dstImage. setPixel ( j, i, srcImage.pixel ( 0 , srcImage.height () - 1 ) );
142
+ scanLine[x] = srcImage.pixel ( 0 , srcImage.height () - 1 );
139
143
}
140
144
else if ( currentSrcRowInt < 0 )
141
145
{
142
146
px1 = srcImage.pixel ( currentSrcColInt, 0 );
143
147
px2 = srcImage.pixel ( currentSrcColInt + 1 , 0 );
144
- dstImage. setPixel ( j, i, curveInterpolation ( px1, px2, u, xDerivativeMatrixRed[ currentSrcColInt ], xDerivativeMatrixGreen[ currentSrcColInt ],
145
- xDerivativeMatrixBlue[ currentSrcColInt ], xDerivativeMatrixAlpha[ currentSrcColInt ], xDerivativeMatrixRed[ currentSrcColInt + 1 ], xDerivativeMatrixGreen[ currentSrcColInt + 1 ],
146
- xDerivativeMatrixBlue[ currentSrcColInt + 1 ], xDerivativeMatrixAlpha[ currentSrcColInt + 1 ] ) );
148
+ scanLine[x] = curveInterpolation ( px1, px2, u, xDerivativeMatrixRed[ currentSrcColInt ], xDerivativeMatrixGreen[ currentSrcColInt ],
149
+ xDerivativeMatrixBlue[ currentSrcColInt ], xDerivativeMatrixAlpha[ currentSrcColInt ], xDerivativeMatrixRed[ currentSrcColInt + 1 ], xDerivativeMatrixGreen[ currentSrcColInt + 1 ],
150
+ xDerivativeMatrixBlue[ currentSrcColInt + 1 ], xDerivativeMatrixAlpha[ currentSrcColInt + 1 ] );
147
151
}
148
152
else if ( currentSrcRowInt >= ( srcImage.height () - 1 ) )
149
153
{
150
154
int idx = ( srcImage.height () - 1 ) * srcImage.width () + currentSrcColInt;
151
155
px1 = srcImage.pixel ( currentSrcColInt, srcImage.height () - 1 );
152
156
px2 = srcImage.pixel ( currentSrcColInt + 1 , srcImage.height () - 1 );
153
- dstImage. setPixel ( j, i, curveInterpolation ( px1, px2, u, xDerivativeMatrixRed[ idx ], xDerivativeMatrixGreen[ idx ], xDerivativeMatrixBlue[idx],
154
- xDerivativeMatrixAlpha[idx], xDerivativeMatrixRed[ idx + 1 ], xDerivativeMatrixGreen[ idx + 1 ], xDerivativeMatrixBlue[idx + 1 ],
155
- xDerivativeMatrixAlpha[idx + 1 ] ) );
157
+ scanLine[x] = curveInterpolation ( px1, px2, u, xDerivativeMatrixRed[ idx ], xDerivativeMatrixGreen[ idx ], xDerivativeMatrixBlue[idx],
158
+ xDerivativeMatrixAlpha[idx], xDerivativeMatrixRed[ idx + 1 ], xDerivativeMatrixGreen[ idx + 1 ], xDerivativeMatrixBlue[idx + 1 ],
159
+ xDerivativeMatrixAlpha[idx + 1 ] );
156
160
}
157
161
else if ( currentSrcColInt < 0 )
158
162
{
159
163
int idx1 = currentSrcRowInt * srcImage.width ();
160
164
int idx2 = idx1 + srcImage.width ();
161
165
px1 = srcImage.pixel ( 0 , currentSrcRowInt );
162
166
px2 = srcImage.pixel ( 0 , currentSrcRowInt + 1 );
163
- dstImage. setPixel ( j, i, curveInterpolation ( px1, px2, v, yDerivativeMatrixRed[ idx1 ], yDerivativeMatrixGreen[ idx1 ], yDerivativeMatrixBlue[ idx1],
164
- yDerivativeMatrixAlpha[ idx1], yDerivativeMatrixRed[ idx2 ], yDerivativeMatrixGreen[ idx2 ], yDerivativeMatrixBlue[ idx2],
165
- yDerivativeMatrixAlpha[ idx2] ) );
167
+ scanLine[x] = curveInterpolation ( px1, px2, v, yDerivativeMatrixRed[ idx1 ], yDerivativeMatrixGreen[ idx1 ], yDerivativeMatrixBlue[ idx1],
168
+ yDerivativeMatrixAlpha[ idx1], yDerivativeMatrixRed[ idx2 ], yDerivativeMatrixGreen[ idx2 ], yDerivativeMatrixBlue[ idx2],
169
+ yDerivativeMatrixAlpha[ idx2] );
166
170
}
167
171
else if ( currentSrcColInt >= ( srcImage.width () - 1 ) )
168
172
{
169
173
int idx1 = currentSrcRowInt * srcImage.width () + srcImage.width () - 1 ;
170
174
int idx2 = idx1 + srcImage.width ();
171
175
px1 = srcImage.pixel ( srcImage.width () - 1 , currentSrcRowInt );
172
176
px2 = srcImage.pixel ( srcImage.width () - 1 , currentSrcRowInt + 1 );
173
- dstImage. setPixel ( j, i, curveInterpolation ( px1, px2, v, yDerivativeMatrixRed[ idx1 ], yDerivativeMatrixGreen[ idx1 ], yDerivativeMatrixBlue[ idx1],
174
- yDerivativeMatrixAlpha[ idx1], yDerivativeMatrixRed[ idx2 ], yDerivativeMatrixGreen[ idx2 ], yDerivativeMatrixBlue[ idx2],
175
- yDerivativeMatrixAlpha[ idx2] ) );
177
+ scanLine[x] = curveInterpolation ( px1, px2, v, yDerivativeMatrixRed[ idx1 ], yDerivativeMatrixGreen[ idx1 ], yDerivativeMatrixBlue[ idx1],
178
+ yDerivativeMatrixAlpha[ idx1], yDerivativeMatrixRed[ idx2 ], yDerivativeMatrixGreen[ idx2 ], yDerivativeMatrixBlue[ idx2],
179
+ yDerivativeMatrixAlpha[ idx2] );
176
180
}
177
181
currentSrcCol += nSrcPerDstX;
178
182
continue ;
@@ -187,82 +191,83 @@ void QgsCubicRasterResampler::resample( const QImage& srcImage, QImage& dstImage
187
191
}
188
192
189
193
// bernstein polynomials
190
- bp0u = calcBernsteinPoly ( 3 , 0 , u ); bp1u = calcBernsteinPoly ( 3 , 1 , u );
191
- bp2u = calcBernsteinPoly ( 3 , 2 , u ); bp3u = calcBernsteinPoly ( 3 , 3 , u );
192
- bp0v = calcBernsteinPoly ( 3 , 0 , v ); bp1v = calcBernsteinPoly ( 3 , 1 , v );
193
- bp2v = calcBernsteinPoly ( 3 , 2 , v ); bp3v = calcBernsteinPoly ( 3 , 3 , v );
194
+ bp0u = calcBernsteinPolyN3 ( 0 , u ); bp1u = calcBernsteinPolyN3 ( 1 , u );
195
+ bp2u = calcBernsteinPolyN3 ( 2 , u ); bp3u = calcBernsteinPolyN3 ( 3 , u );
196
+ bp0v = calcBernsteinPolyN3 ( 0 , v ); bp1v = calcBernsteinPolyN3 ( 1 , v );
197
+ bp2v = calcBernsteinPolyN3 ( 2 , v ); bp3v = calcBernsteinPolyN3 ( 3 , v );
194
198
195
199
// then calculate value based on bernstein form of Bezier patch
196
200
// todo: move into function
197
- r = bp0u * bp0v * cRed00 +
198
- bp1u * bp0v * cRed10 +
199
- bp2u * bp0v * cRed20 +
200
- bp3u * bp0v * cRed30 +
201
- bp0u * bp1v * cRed01 +
202
- bp1u * bp1v * cRed11 +
203
- bp2u * bp1v * cRed21 +
204
- bp3u * bp1v * cRed31 +
205
- bp0u * bp2v * cRed02 +
206
- bp1u * bp2v * cRed12 +
207
- bp2u * bp2v * cRed22 +
208
- bp3u * bp2v * cRed32 +
209
- bp0u * bp3v * cRed03 +
210
- bp1u * bp3v * cRed13 +
211
- bp2u * bp3v * cRed23 +
212
- bp3u * bp3v * cRed33;
213
-
214
- g = bp0u * bp0v * cGreen00 +
215
- bp1u * bp0v * cGreen10 +
216
- bp2u * bp0v * cGreen20 +
217
- bp3u * bp0v * cGreen30 +
218
- bp0u * bp1v * cGreen01 +
219
- bp1u * bp1v * cGreen11 +
220
- bp2u * bp1v * cGreen21 +
221
- bp3u * bp1v * cGreen31 +
222
- bp0u * bp2v * cGreen02 +
223
- bp1u * bp2v * cGreen12 +
224
- bp2u * bp2v * cGreen22 +
225
- bp3u * bp2v * cGreen32 +
226
- bp0u * bp3v * cGreen03 +
227
- bp1u * bp3v * cGreen13 +
228
- bp2u * bp3v * cGreen23 +
229
- bp3u * bp3v * cGreen33;
230
-
231
- b = bp0u * bp0v * cBlue00 +
232
- bp1u * bp0v * cBlue10 +
233
- bp2u * bp0v * cBlue20 +
234
- bp3u * bp0v * cBlue30 +
235
- bp0u * bp1v * cBlue01 +
236
- bp1u * bp1v * cBlue11 +
237
- bp2u * bp1v * cBlue21 +
238
- bp3u * bp1v * cBlue31 +
239
- bp0u * bp2v * cBlue02 +
240
- bp1u * bp2v * cBlue12 +
241
- bp2u * bp2v * cBlue22 +
242
- bp3u * bp2v * cBlue32 +
243
- bp0u * bp3v * cBlue03 +
244
- bp1u * bp3v * cBlue13 +
245
- bp2u * bp3v * cBlue23 +
246
- bp3u * bp3v * cBlue33;
247
-
248
- a = bp0u * bp0v * cAlpha00 +
249
- bp1u * bp0v * cAlpha10 +
250
- bp2u * bp0v * cAlpha20 +
251
- bp3u * bp0v * cAlpha30 +
252
- bp0u * bp1v * cAlpha01 +
253
- bp1u * bp1v * cAlpha11 +
254
- bp2u * bp1v * cAlpha21 +
255
- bp3u * bp1v * cAlpha31 +
256
- bp0u * bp2v * cAlpha02 +
257
- bp1u * bp2v * cAlpha12 +
258
- bp2u * bp2v * cAlpha22 +
259
- bp3u * bp2v * cAlpha32 +
260
- bp0u * bp3v * cAlpha03 +
261
- bp1u * bp3v * cAlpha13 +
262
- bp2u * bp3v * cAlpha23 +
263
- bp3u * bp3v * cAlpha33;
264
-
265
- dstImage.setPixel ( j, i, qRgba ( r, g, b, a ) );
201
+ int r = bp0u * bp0v * cRed00 +
202
+ bp1u * bp0v * cRed10 +
203
+ bp2u * bp0v * cRed20 +
204
+ bp3u * bp0v * cRed30 +
205
+ bp0u * bp1v * cRed01 +
206
+ bp1u * bp1v * cRed11 +
207
+ bp2u * bp1v * cRed21 +
208
+ bp3u * bp1v * cRed31 +
209
+ bp0u * bp2v * cRed02 +
210
+ bp1u * bp2v * cRed12 +
211
+ bp2u * bp2v * cRed22 +
212
+ bp3u * bp2v * cRed32 +
213
+ bp0u * bp3v * cRed03 +
214
+ bp1u * bp3v * cRed13 +
215
+ bp2u * bp3v * cRed23 +
216
+ bp3u * bp3v * cRed33;
217
+
218
+ int g = bp0u * bp0v * cGreen00 +
219
+ bp1u * bp0v * cGreen10 +
220
+ bp2u * bp0v * cGreen20 +
221
+ bp3u * bp0v * cGreen30 +
222
+ bp0u * bp1v * cGreen01 +
223
+ bp1u * bp1v * cGreen11 +
224
+ bp2u * bp1v * cGreen21 +
225
+ bp3u * bp1v * cGreen31 +
226
+ bp0u * bp2v * cGreen02 +
227
+ bp1u * bp2v * cGreen12 +
228
+ bp2u * bp2v * cGreen22 +
229
+ bp3u * bp2v * cGreen32 +
230
+ bp0u * bp3v * cGreen03 +
231
+ bp1u * bp3v * cGreen13 +
232
+ bp2u * bp3v * cGreen23 +
233
+ bp3u * bp3v * cGreen33;
234
+
235
+ int b = bp0u * bp0v * cBlue00 +
236
+ bp1u * bp0v * cBlue10 +
237
+ bp2u * bp0v * cBlue20 +
238
+ bp3u * bp0v * cBlue30 +
239
+ bp0u * bp1v * cBlue01 +
240
+ bp1u * bp1v * cBlue11 +
241
+ bp2u * bp1v * cBlue21 +
242
+ bp3u * bp1v * cBlue31 +
243
+ bp0u * bp2v * cBlue02 +
244
+ bp1u * bp2v * cBlue12 +
245
+ bp2u * bp2v * cBlue22 +
246
+ bp3u * bp2v * cBlue32 +
247
+ bp0u * bp3v * cBlue03 +
248
+ bp1u * bp3v * cBlue13 +
249
+ bp2u * bp3v * cBlue23 +
250
+ bp3u * bp3v * cBlue33;
251
+
252
+ int a = bp0u * bp0v * cAlpha00 +
253
+ bp1u * bp0v * cAlpha10 +
254
+ bp2u * bp0v * cAlpha20 +
255
+ bp3u * bp0v * cAlpha30 +
256
+ bp0u * bp1v * cAlpha01 +
257
+ bp1u * bp1v * cAlpha11 +
258
+ bp2u * bp1v * cAlpha21 +
259
+ bp3u * bp1v * cAlpha31 +
260
+ bp0u * bp2v * cAlpha02 +
261
+ bp1u * bp2v * cAlpha12 +
262
+ bp2u * bp2v * cAlpha22 +
263
+ bp3u * bp2v * cAlpha32 +
264
+ bp0u * bp3v * cAlpha03 +
265
+ bp1u * bp3v * cAlpha13 +
266
+ bp2u * bp3v * cAlpha23 +
267
+ bp3u * bp3v * cAlpha33;
268
+
269
+ scanLine[x] = createPremultipliedColor ( r, g, b, a );
270
+
266
271
lastSrcColInt = currentSrcColInt;
267
272
currentSrcCol += nSrcPerDstX;
268
273
}
@@ -291,15 +296,15 @@ void QgsCubicRasterResampler::xDerivativeMatrix( int nCols, int nRows, double* m
291
296
double val = 0 ;
292
297
int index = 0 ;
293
298
294
- for ( int i = 0 ; i < nRows; ++i )
299
+ for ( int y = 0 ; y < nRows; ++y )
295
300
{
296
- for ( int j = 0 ; j < nCols; ++j )
301
+ for ( int x = 0 ; x < nCols; ++x )
297
302
{
298
- if ( j < 1 )
303
+ if ( x == 0 )
299
304
{
300
305
val = colorMatrix[index + 1 ] - colorMatrix[index];
301
306
}
302
- else if ( j == ( nCols - 1 ) )
307
+ else if ( x == ( nCols - 1 ) )
303
308
{
304
309
val = colorMatrix[index] - colorMatrix[ index - 1 ];
305
310
}
@@ -318,15 +323,15 @@ void QgsCubicRasterResampler::yDerivativeMatrix( int nCols, int nRows, double* m
318
323
double val = 0 ;
319
324
int index = 0 ;
320
325
321
- for ( int i = 0 ; i < nRows; ++i )
326
+ for ( int y = 0 ; y < nRows; ++y )
322
327
{
323
- for ( int j = 0 ; j < nCols; ++j )
328
+ for ( int x = 0 ; x < nCols; ++x )
324
329
{
325
- if ( i == 0 )
330
+ if ( y == 0 )
326
331
{
327
332
val = colorMatrix[ index + nCols ] - colorMatrix[ index ];
328
333
}
329
- else if ( i == ( nRows - 1 ) )
334
+ else if ( y == ( nRows - 1 ) )
330
335
{
331
336
val = colorMatrix[ index ] - colorMatrix[ index - nCols ];
332
337
}
@@ -399,78 +404,49 @@ QRgb QgsCubicRasterResampler::curveInterpolation( QRgb pt1, QRgb pt2, double t,
399
404
double p0a = qAlpha ( pt1 ); double p1a = p0a + 0.333 * d1alpha; double p3a = qAlpha ( pt2 ); double p2a = p3a - 0.333 * d2alpha;
400
405
401
406
// bernstein polynomials
402
- double bp0 = calcBernsteinPoly ( 3 , 0 , t );
403
- double bp1 = calcBernsteinPoly ( 3 , 1 , t );
404
- double bp2 = calcBernsteinPoly ( 3 , 2 , t );
405
- double bp3 = calcBernsteinPoly ( 3 , 3 , t );
407
+ double bp0 = calcBernsteinPolyN3 ( 0 , t );
408
+ double bp1 = calcBernsteinPolyN3 ( 1 , t );
409
+ double bp2 = calcBernsteinPolyN3 ( 2 , t );
410
+ double bp3 = calcBernsteinPolyN3 ( 3 , t );
406
411
407
412
int red = bp0 * p0r + bp1 * p1r + bp2 * p2r + bp3 * p3r;
408
413
int green = bp0 * p0g + bp1 * p1g + bp2 * p2g + bp3 * p3g;
409
414
int blue = bp0 * p0b + bp1 * p1b + bp2 * p2b + bp3 * p3b;
410
415
int alpha = bp0 * p0a + bp1 * p1a + bp2 * p2a + bp3 * p3a;
411
416
412
- return qRgba ( red, green, blue, alpha );
417
+ return createPremultipliedColor ( red, green, blue, alpha );
413
418
}
414
419
415
- double QgsCubicRasterResampler::calcBernsteinPoly ( int n, int i, double t )
420
+ double QgsCubicRasterResampler::calcBernsteinPolyN3 ( int i, double t )
416
421
{
417
422
if ( i < 0 )
418
423
{
419
424
return 0 ;
420
425
}
421
426
422
- return lower ( n, i )* power ( t, i )* power (( 1 - t ), ( n - i ) );
427
+ return lowerN3 ( i ) * qPow ( t, i ) * qPow (( 1 - t ), ( 3 - i ) );
423
428
}
424
429
425
- int QgsCubicRasterResampler::lower ( int n, int i )
430
+ inline int QgsCubicRasterResampler::lowerN3 ( int i )
426
431
{
427
- if ( i >= 0 && i <= n )
432
+ switch ( i )
428
433
{
429
- return faculty ( n ) / ( faculty ( i )*faculty ( n - i ) );
430
- }
431
- else
432
- {
433
- return 0 ;
434
+ case 0 :
435
+ case 3 :
436
+ return 1 ;
437
+ case 1 :
438
+ case 2 :
439
+ return 3 ;
440
+ default :
441
+ return 0 ;
434
442
}
435
443
}
436
444
437
- double QgsCubicRasterResampler::power ( double a, int b )
445
+ QRgb QgsCubicRasterResampler::createPremultipliedColor ( const int r, const int g, const int b, const int a )
438
446
{
439
- if ( b == 0 )
440
- {
441
- return 1 ;
442
- }
443
- double tmp = a;
444
- for ( int i = 2 ; i <= qAbs (( double )b ); i++ )
445
- {
446
-
447
- a *= tmp;
448
- }
449
- if ( b > 0 )
450
- {
451
- return a;
452
- }
453
- else
454
- {
455
- return ( 1.0 / a );
456
- }
457
- }
458
-
459
- int QgsCubicRasterResampler::faculty ( int n )
460
- {
461
- if ( n < 0 )// Is faculty also defined for negative integers?
462
- {
463
- return 0 ;
464
- }
465
- int i;
466
- int result = n;
467
-
468
- if ( n == 0 || n == 1 )
469
- {return 1 ;}// faculty of 0 is 1!
470
-
471
- for ( i = n - 1 ; i >= 2 ; i-- )
472
- {
473
- result *= i;
474
- }
475
- return result;
447
+ int maxComponentBounds = qBound ( 0 , a, 255 );
448
+ return qRgba ( qBound ( 0 , r, maxComponentBounds ),
449
+ qBound ( 0 , g, maxComponentBounds ),
450
+ qBound ( 0 , b, maxComponentBounds ),
451
+ a );
476
452
}
0 commit comments