37 int nCols = srcImage.width();
38 int nRows = srcImage.height();
42 int* redMatrix =
new int[ nCols * nRows ];
43 int* greenMatrix =
new int[ nCols * nRows ];
44 int* blueMatrix =
new int[ nCols * nRows ];
45 int* alphaMatrix =
new int[ nCols * nRows ];
47 for (
int i = 0; i < nRows; ++i )
49 for (
int j = 0; j < nCols; ++j )
51 px = srcImage.pixel( j, i );
52 redMatrix[pos] = qRed( px );
53 greenMatrix[pos] = qGreen( px );
54 blueMatrix[pos] = qBlue( px );
55 alphaMatrix[pos] = qAlpha( px );
61 double* xDerivativeMatrixRed =
new double[ nCols * nRows ];
63 double* xDerivativeMatrixGreen =
new double[ nCols * nRows ];
65 double* xDerivativeMatrixBlue =
new double[ nCols * nRows ];
67 double* xDerivativeMatrixAlpha =
new double[ nCols * nRows ];
71 double* yDerivativeMatrixRed =
new double[ nCols * nRows ];
73 double* yDerivativeMatrixGreen =
new double[ nCols * nRows ];
75 double* yDerivativeMatrixBlue =
new double[ nCols * nRows ];
77 double* yDerivativeMatrixAlpha =
new double[ nCols * nRows ];
81 double nSrcPerDstX = ( double ) srcImage.width() / ( double ) dstImage.width();
82 double nSrcPerDstY = ( double ) srcImage.height() / ( double ) dstImage.height();
84 double currentSrcRow = nSrcPerDstY / 2.0 - 0.5;
88 int lastSrcColInt = -1;
89 int lastSrcRowInt = -1;
93 double bp0u, bp1u, bp2u, bp3u, bp0v, bp1v, bp2v, bp3v;
96 for (
int i = 0; i < dstImage.height(); ++i )
98 currentSrcRowInt = floor( currentSrcRow );
99 v = currentSrcRow - currentSrcRowInt;
101 currentSrcCol = nSrcPerDstX / 2.0 - 0.5;
102 for (
int j = 0; j < dstImage.width(); ++j )
104 currentSrcColInt = floor( currentSrcCol );
105 u = currentSrcCol - currentSrcColInt;
108 if ( currentSrcRowInt < 0 || currentSrcRowInt >= ( srcImage.height() - 1 ) || currentSrcColInt < 0 || currentSrcColInt >= ( srcImage.width() - 1 ) )
112 if ( currentSrcRowInt < 0 && currentSrcColInt < 0 )
114 dstImage.setPixel( j, i, srcImage.pixel( 0, 0 ) );
116 else if ( currentSrcRowInt < 0 && currentSrcColInt >= ( srcImage.width() - 1 ) )
118 dstImage.setPixel( j, i, srcImage.pixel( srcImage.width() - 1, 0 ) );
120 else if ( currentSrcRowInt >= ( srcImage.height() - 1 ) && currentSrcColInt >= ( srcImage.width() - 1 ) )
122 dstImage.setPixel( j, i, srcImage.pixel( srcImage.width() - 1, srcImage.height() - 1 ) );
124 else if ( currentSrcRowInt >= ( srcImage.height() - 1 ) && currentSrcColInt < 0 )
126 dstImage.setPixel( j, i, srcImage.pixel( 0, srcImage.height() - 1 ) );
128 else if ( currentSrcRowInt < 0 )
130 px1 = srcImage.pixel( currentSrcColInt, 0 );
131 px2 = srcImage.pixel( currentSrcColInt + 1, 0 );
132 dstImage.setPixel( j, i,
curveInterpolation( px1, px2, u, xDerivativeMatrixRed[ currentSrcColInt ], xDerivativeMatrixGreen[ currentSrcColInt ],
133 xDerivativeMatrixBlue[ currentSrcColInt ], xDerivativeMatrixAlpha[ currentSrcColInt ], xDerivativeMatrixRed[ currentSrcColInt + 1 ], xDerivativeMatrixGreen[ currentSrcColInt + 1 ],
134 xDerivativeMatrixBlue[ currentSrcColInt + 1 ], xDerivativeMatrixAlpha[ currentSrcColInt + 1 ] ) );
136 else if ( currentSrcRowInt >= ( srcImage.height() - 1 ) )
138 int idx = ( srcImage.height() - 1 ) * srcImage.width() + currentSrcColInt;
139 px1 = srcImage.pixel( currentSrcColInt, srcImage.height() - 1 );
140 px2 = srcImage.pixel( currentSrcColInt + 1, srcImage.height() - 1 );
141 dstImage.setPixel( j, i,
curveInterpolation( px1, px2, u, xDerivativeMatrixRed[ idx ], xDerivativeMatrixGreen[ idx ], xDerivativeMatrixBlue[idx],
142 xDerivativeMatrixAlpha[idx], xDerivativeMatrixRed[ idx + 1 ], xDerivativeMatrixGreen[ idx + 1 ], xDerivativeMatrixBlue[idx + 1],
143 xDerivativeMatrixAlpha[idx + 1] ) );
145 else if ( currentSrcColInt < 0 )
147 int idx1 = currentSrcRowInt * srcImage.width();
148 int idx2 = idx1 + srcImage.width();
149 px1 = srcImage.pixel( 0, currentSrcRowInt );
150 px2 = srcImage.pixel( 0, currentSrcRowInt + 1 );
151 dstImage.setPixel( j, i,
curveInterpolation( px1, px2, v, yDerivativeMatrixRed[ idx1 ], yDerivativeMatrixGreen[ idx1 ], yDerivativeMatrixBlue[ idx1],
152 yDerivativeMatrixAlpha[ idx1], yDerivativeMatrixRed[ idx2 ], yDerivativeMatrixGreen[ idx2 ], yDerivativeMatrixBlue[ idx2],
153 yDerivativeMatrixAlpha[ idx2] ) );
155 else if ( currentSrcColInt >= ( srcImage.width() - 1 ) )
157 int idx1 = currentSrcRowInt * srcImage.width() + srcImage.width() - 1;
158 int idx2 = idx1 + srcImage.width();
159 px1 = srcImage.pixel( srcImage.width() - 1, currentSrcRowInt );
160 px2 = srcImage.pixel( srcImage.width() - 1, currentSrcRowInt + 1 );
161 dstImage.setPixel( j, i,
curveInterpolation( px1, px2, v, yDerivativeMatrixRed[ idx1 ], yDerivativeMatrixGreen[ idx1 ], yDerivativeMatrixBlue[ idx1],
162 yDerivativeMatrixAlpha[ idx1], yDerivativeMatrixRed[ idx2 ], yDerivativeMatrixGreen[ idx2 ], yDerivativeMatrixBlue[ idx2],
163 yDerivativeMatrixAlpha[ idx2] ) );
165 currentSrcCol += nSrcPerDstX;
170 if ( currentSrcColInt != lastSrcColInt || currentSrcRowInt != lastSrcRowInt )
172 calculateControlPoints( nCols, nRows, currentSrcRowInt, currentSrcColInt, redMatrix, greenMatrix, blueMatrix, alphaMatrix,
173 xDerivativeMatrixRed, xDerivativeMatrixGreen, xDerivativeMatrixBlue, xDerivativeMatrixAlpha,
174 yDerivativeMatrixRed, yDerivativeMatrixGreen, yDerivativeMatrixBlue, yDerivativeMatrixAlpha );
185 r = bp0u * bp0v *
cRed00 +
253 dstImage.setPixel( j, i, qRgba( r, g, b, a ) );
254 lastSrcColInt = currentSrcColInt;
255 currentSrcCol += nSrcPerDstX;
257 lastSrcRowInt = currentSrcRowInt;
258 currentSrcRow += nSrcPerDstY;
264 delete[] greenMatrix;
266 delete[] xDerivativeMatrixRed;
267 delete[] xDerivativeMatrixGreen;
268 delete[] xDerivativeMatrixBlue;
269 delete[] yDerivativeMatrixRed;
270 delete[] yDerivativeMatrixGreen;
271 delete[] yDerivativeMatrixBlue;
279 for (
int i = 0; i < nRows; ++i )
281 for (
int j = 0; j < nCols; ++j )
285 val = colorMatrix[index + 1] - colorMatrix[
index];
287 else if ( j == ( nCols - 1 ) )
289 val = colorMatrix[
index] - colorMatrix[ index - 1 ];
293 val = ( colorMatrix[index + 1] - colorMatrix[index - 1] ) / 2.0;
306 for (
int i = 0; i < nRows; ++i )
308 for (
int j = 0; j < nCols; ++j )
312 val = colorMatrix[ index + nCols ] - colorMatrix[
index ];
314 else if ( i == ( nRows - 1 ) )
316 val = colorMatrix[
index ] - colorMatrix[ index - nCols ];
320 val = ( colorMatrix[ index + nCols ] - colorMatrix[ index - nCols ] ) / 2.0;
329 int* alphaMatrix,
double* xDerivativeMatrixRed,
double* xDerivativeMatrixGreen,
double* xDerivativeMatrixBlue,
double* xDerivativeMatrixAlpha,
330 double* yDerivativeMatrixRed,
double* yDerivativeMatrixGreen,
double* yDerivativeMatrixBlue,
double* yDerivativeMatrixAlpha )
333 int idx00 = currentRow * nCols + currentCol;
334 int idx10 = idx00 + 1;
335 int idx01 = idx00 + nCols;
336 int idx11 = idx01 + 1;
378 double d2red,
double d2green,
double d2blue,
double d2alpha )
381 double p0r = qRed( pt1 );
double p1r = p0r + 0.333 * d1red;
double p3r = qRed( pt2 );
double p2r = p3r - 0.333 * d2red;
382 double p0g = qGreen( pt1 );
double p1g = p0g + 0.333 * d1green;
double p3g = qGreen( pt2 );
double p2g = p3g - 0.333 * d2green;
383 double p0b = qBlue( pt1 );
double p1b = p0b + 0.333 * d1blue;
double p3b = qBlue( pt2 );
double p2b = p3b - 0.333 * d2blue;
384 double p0a = qAlpha( pt1 );
double p1a = p0a + 0.333 * d1alpha;
double p3a = qAlpha( pt2 );
double p2a = p3a - 0.333 * d2alpha;
392 int red = bp0 * p0r + bp1 * p1r + bp2 * p2r + bp3 * p3r;
393 int green = bp0 * p0g + bp1 * p1g + bp2 * p2g + bp3 * p3g;
394 int blue = bp0 * p0b + bp1 * p1b + bp2 * p2b + bp3 * p3b;
395 int alpha = bp0 * p0a + bp1 * p1a + bp2 * p2a + bp3 * p3a;
397 return qRgba( red, green, blue, alpha );
412 if ( i >= 0 && i <= n )
429 for (
int i = 2; i <= qAbs((
double )b ); i++ )
453 if ( n == 0 || n == 1 )
456 for ( i = n - 1; i >= 2; i-- )