QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgscubicrasterresampler.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscubicrasterresampler.cpp
3  ----------------------------
4  begin : December 2011
5  copyright : (C) 2011 by Marco Hugentobler
6  email : marco at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 #include <QImage>
20 
22 {
23  return new QgsCubicRasterResampler();
24 }
25 
26 void QgsCubicRasterResampler::resample( const QImage &srcImage, QImage &dstImage )
27 {
28  int nCols = srcImage.width();
29  int nRows = srcImage.height();
30 
31  int pos = 0;
32  QRgb px;
33  int *redMatrix = new int[ nCols * nRows ];
34  int *greenMatrix = new int[ nCols * nRows ];
35  int *blueMatrix = new int[ nCols * nRows ];
36  int *alphaMatrix = new int[ nCols * nRows ];
37 
38  for ( int heightIndex = 0; heightIndex < nRows; ++heightIndex )
39  {
40  QRgb *scanLine = ( QRgb * )srcImage.constScanLine( heightIndex );
41  for ( int widthIndex = 0; widthIndex < nCols; ++widthIndex )
42  {
43  px = scanLine[widthIndex];
44  int alpha = qAlpha( px );
45  alphaMatrix[pos] = alpha;
46  redMatrix[pos] = qRed( px );
47  greenMatrix[pos] = qGreen( px );
48  blueMatrix[pos] = qBlue( px );
49 
50  pos++;
51  }
52  }
53 
54  //derivative x
55  double *xDerivativeMatrixRed = new double[ nCols * nRows ];
56  xDerivativeMatrix( nCols, nRows, xDerivativeMatrixRed, redMatrix );
57  double *xDerivativeMatrixGreen = new double[ nCols * nRows ];
58  xDerivativeMatrix( nCols, nRows, xDerivativeMatrixGreen, greenMatrix );
59  double *xDerivativeMatrixBlue = new double[ nCols * nRows ];
60  xDerivativeMatrix( nCols, nRows, xDerivativeMatrixBlue, blueMatrix );
61  double *xDerivativeMatrixAlpha = new double[ nCols * nRows ];
62  xDerivativeMatrix( nCols, nRows, xDerivativeMatrixAlpha, alphaMatrix );
63 
64  //derivative y
65  double *yDerivativeMatrixRed = new double[ nCols * nRows ];
66  yDerivativeMatrix( nCols, nRows, yDerivativeMatrixRed, redMatrix );
67  double *yDerivativeMatrixGreen = new double[ nCols * nRows ];
68  yDerivativeMatrix( nCols, nRows, yDerivativeMatrixGreen, greenMatrix );
69  double *yDerivativeMatrixBlue = new double[ nCols * nRows ];
70  yDerivativeMatrix( nCols, nRows, yDerivativeMatrixBlue, blueMatrix );
71  double *yDerivativeMatrixAlpha = new double[ nCols * nRows ];
72  yDerivativeMatrix( nCols, nRows, yDerivativeMatrixAlpha, alphaMatrix );
73 
74  //compute output
75  double nSrcPerDstX = ( double ) srcImage.width() / ( double ) dstImage.width();
76  double nSrcPerDstY = ( double ) srcImage.height() / ( double ) dstImage.height();
77 
78  double currentSrcRow = nSrcPerDstY / 2.0 - 0.5;
79  double currentSrcCol;
80  int currentSrcColInt;
81  int currentSrcRowInt;
82  int lastSrcColInt = -100;
83  int lastSrcRowInt = -100;
84 
85  //bernstein polynomials
86  double bp0u, bp1u, bp2u, bp3u, bp0v, bp1v, bp2v, bp3v;
87  double u, v;
88 
89  for ( int y = 0; y < dstImage.height(); ++y )
90  {
91  currentSrcRowInt = std::floor( currentSrcRow );
92  v = currentSrcRow - currentSrcRowInt;
93 
94  currentSrcCol = nSrcPerDstX / 2.0 - 0.5;
95 
96  QRgb *scanLine = ( QRgb * )dstImage.scanLine( y );
97  for ( int x = 0; x < dstImage.width(); ++x )
98  {
99  currentSrcColInt = std::floor( currentSrcCol );
100  u = currentSrcCol - currentSrcColInt;
101 
102  //handle eight edge-cases
103  if ( ( currentSrcRowInt < 0 || currentSrcRowInt >= ( srcImage.height() - 1 ) || currentSrcColInt < 0 || currentSrcColInt >= ( srcImage.width() - 1 ) ) )
104  {
105  QRgb px1, px2;
106  //pixels at the border of the source image needs to be handled in a special way
107  if ( currentSrcRowInt < 0 && currentSrcColInt < 0 )
108  {
109  scanLine[x] = srcImage.pixel( 0, 0 );
110  }
111  else if ( currentSrcRowInt < 0 && currentSrcColInt >= ( srcImage.width() - 1 ) )
112  {
113  scanLine[x] = srcImage.pixel( srcImage.width() - 1, 0 );
114  }
115  else if ( currentSrcRowInt >= ( srcImage.height() - 1 ) && currentSrcColInt >= ( srcImage.width() - 1 ) )
116  {
117  scanLine[x] = srcImage.pixel( srcImage.width() - 1, srcImage.height() - 1 );
118  }
119  else if ( currentSrcRowInt >= ( srcImage.height() - 1 ) && currentSrcColInt < 0 )
120  {
121  scanLine[x] = srcImage.pixel( 0, srcImage.height() - 1 );
122  }
123  else if ( currentSrcRowInt < 0 )
124  {
125  px1 = srcImage.pixel( currentSrcColInt, 0 );
126  px2 = srcImage.pixel( currentSrcColInt + 1, 0 );
127  scanLine[x] = curveInterpolation( px1, px2, u, xDerivativeMatrixRed[ currentSrcColInt ], xDerivativeMatrixGreen[ currentSrcColInt ],
128  xDerivativeMatrixBlue[ currentSrcColInt ], xDerivativeMatrixAlpha[ currentSrcColInt ], xDerivativeMatrixRed[ currentSrcColInt + 1 ], xDerivativeMatrixGreen[ currentSrcColInt + 1 ],
129  xDerivativeMatrixBlue[ currentSrcColInt + 1 ], xDerivativeMatrixAlpha[ currentSrcColInt + 1 ] );
130  }
131  else if ( currentSrcRowInt >= ( srcImage.height() - 1 ) )
132  {
133  int idx = ( srcImage.height() - 1 ) * srcImage.width() + currentSrcColInt;
134  px1 = srcImage.pixel( currentSrcColInt, srcImage.height() - 1 );
135  px2 = srcImage.pixel( currentSrcColInt + 1, srcImage.height() - 1 );
136  scanLine[x] = curveInterpolation( px1, px2, u, xDerivativeMatrixRed[ idx ], xDerivativeMatrixGreen[ idx ], xDerivativeMatrixBlue[idx],
137  xDerivativeMatrixAlpha[idx], xDerivativeMatrixRed[ idx + 1 ], xDerivativeMatrixGreen[ idx + 1 ], xDerivativeMatrixBlue[idx + 1],
138  xDerivativeMatrixAlpha[idx + 1] );
139  }
140  else if ( currentSrcColInt < 0 )
141  {
142  int idx1 = currentSrcRowInt * srcImage.width();
143  int idx2 = idx1 + srcImage.width();
144  px1 = srcImage.pixel( 0, currentSrcRowInt );
145  px2 = srcImage.pixel( 0, currentSrcRowInt + 1 );
146  scanLine[x] = curveInterpolation( px1, px2, v, yDerivativeMatrixRed[ idx1 ], yDerivativeMatrixGreen[ idx1 ], yDerivativeMatrixBlue[ idx1],
147  yDerivativeMatrixAlpha[ idx1], yDerivativeMatrixRed[ idx2 ], yDerivativeMatrixGreen[ idx2 ], yDerivativeMatrixBlue[ idx2],
148  yDerivativeMatrixAlpha[ idx2] );
149  }
150  else if ( currentSrcColInt >= ( srcImage.width() - 1 ) )
151  {
152  int idx1 = currentSrcRowInt * srcImage.width() + srcImage.width() - 1;
153  int idx2 = idx1 + srcImage.width();
154  px1 = srcImage.pixel( srcImage.width() - 1, currentSrcRowInt );
155  px2 = srcImage.pixel( srcImage.width() - 1, currentSrcRowInt + 1 );
156  scanLine[x] = curveInterpolation( px1, px2, v, yDerivativeMatrixRed[ idx1 ], yDerivativeMatrixGreen[ idx1 ], yDerivativeMatrixBlue[ idx1],
157  yDerivativeMatrixAlpha[ idx1], yDerivativeMatrixRed[ idx2 ], yDerivativeMatrixGreen[ idx2 ], yDerivativeMatrixBlue[ idx2],
158  yDerivativeMatrixAlpha[ idx2] );
159  }
160  currentSrcCol += nSrcPerDstX;
161  continue;
162  }
163 
164  //first update the control points if necessary
165  if ( currentSrcColInt != lastSrcColInt || currentSrcRowInt != lastSrcRowInt )
166  {
167  calculateControlPoints( nCols, nRows, currentSrcRowInt, currentSrcColInt, redMatrix, greenMatrix, blueMatrix, alphaMatrix,
168  xDerivativeMatrixRed, xDerivativeMatrixGreen, xDerivativeMatrixBlue, xDerivativeMatrixAlpha,
169  yDerivativeMatrixRed, yDerivativeMatrixGreen, yDerivativeMatrixBlue, yDerivativeMatrixAlpha );
170  }
171 
172  //bernstein polynomials
173  bp0u = calcBernsteinPolyN3( 0, u );
174  bp1u = calcBernsteinPolyN3( 1, u );
175  bp2u = calcBernsteinPolyN3( 2, u );
176  bp3u = calcBernsteinPolyN3( 3, u );
177  bp0v = calcBernsteinPolyN3( 0, v );
178  bp1v = calcBernsteinPolyN3( 1, v );
179  bp2v = calcBernsteinPolyN3( 2, v );
180  bp3v = calcBernsteinPolyN3( 3, v );
181 
182  //then calculate value based on bernstein form of Bezier patch
183  //todo: move into function
184  int r = bp0u * bp0v * cRed00 +
185  bp1u * bp0v * cRed10 +
186  bp2u * bp0v * cRed20 +
187  bp3u * bp0v * cRed30 +
188  bp0u * bp1v * cRed01 +
189  bp1u * bp1v * cRed11 +
190  bp2u * bp1v * cRed21 +
191  bp3u * bp1v * cRed31 +
192  bp0u * bp2v * cRed02 +
193  bp1u * bp2v * cRed12 +
194  bp2u * bp2v * cRed22 +
195  bp3u * bp2v * cRed32 +
196  bp0u * bp3v * cRed03 +
197  bp1u * bp3v * cRed13 +
198  bp2u * bp3v * cRed23 +
199  bp3u * bp3v * cRed33;
200 
201  int g = bp0u * bp0v * cGreen00 +
202  bp1u * bp0v * cGreen10 +
203  bp2u * bp0v * cGreen20 +
204  bp3u * bp0v * cGreen30 +
205  bp0u * bp1v * cGreen01 +
206  bp1u * bp1v * cGreen11 +
207  bp2u * bp1v * cGreen21 +
208  bp3u * bp1v * cGreen31 +
209  bp0u * bp2v * cGreen02 +
210  bp1u * bp2v * cGreen12 +
211  bp2u * bp2v * cGreen22 +
212  bp3u * bp2v * cGreen32 +
213  bp0u * bp3v * cGreen03 +
214  bp1u * bp3v * cGreen13 +
215  bp2u * bp3v * cGreen23 +
216  bp3u * bp3v * cGreen33;
217 
218  int b = bp0u * bp0v * cBlue00 +
219  bp1u * bp0v * cBlue10 +
220  bp2u * bp0v * cBlue20 +
221  bp3u * bp0v * cBlue30 +
222  bp0u * bp1v * cBlue01 +
223  bp1u * bp1v * cBlue11 +
224  bp2u * bp1v * cBlue21 +
225  bp3u * bp1v * cBlue31 +
226  bp0u * bp2v * cBlue02 +
227  bp1u * bp2v * cBlue12 +
228  bp2u * bp2v * cBlue22 +
229  bp3u * bp2v * cBlue32 +
230  bp0u * bp3v * cBlue03 +
231  bp1u * bp3v * cBlue13 +
232  bp2u * bp3v * cBlue23 +
233  bp3u * bp3v * cBlue33;
234 
235  int a = bp0u * bp0v * cAlpha00 +
236  bp1u * bp0v * cAlpha10 +
237  bp2u * bp0v * cAlpha20 +
238  bp3u * bp0v * cAlpha30 +
239  bp0u * bp1v * cAlpha01 +
240  bp1u * bp1v * cAlpha11 +
241  bp2u * bp1v * cAlpha21 +
242  bp3u * bp1v * cAlpha31 +
243  bp0u * bp2v * cAlpha02 +
244  bp1u * bp2v * cAlpha12 +
245  bp2u * bp2v * cAlpha22 +
246  bp3u * bp2v * cAlpha32 +
247  bp0u * bp3v * cAlpha03 +
248  bp1u * bp3v * cAlpha13 +
249  bp2u * bp3v * cAlpha23 +
250  bp3u * bp3v * cAlpha33;
251 
252  scanLine[x] = createPremultipliedColor( r, g, b, a );
253 
254  lastSrcColInt = currentSrcColInt;
255  currentSrcCol += nSrcPerDstX;
256  }
257  lastSrcRowInt = currentSrcRowInt;
258  currentSrcRow += nSrcPerDstY;
259  }
260 
261 
262  //cleanup memory
263  delete[] redMatrix;
264  delete[] greenMatrix;
265  delete[] blueMatrix;
266  delete[] alphaMatrix;
267  delete[] xDerivativeMatrixRed;
268  delete[] xDerivativeMatrixGreen;
269  delete[] xDerivativeMatrixBlue;
270  delete[] xDerivativeMatrixAlpha;
271  delete[] yDerivativeMatrixRed;
272  delete[] yDerivativeMatrixGreen;
273  delete[] yDerivativeMatrixBlue;
274  delete[] yDerivativeMatrixAlpha;
275 }
276 
277 void QgsCubicRasterResampler::xDerivativeMatrix( int nCols, int nRows, double *matrix, const int *colorMatrix )
278 {
279  double val = 0;
280  int index = 0;
281 
282  for ( int y = 0; y < nRows; ++y )
283  {
284  for ( int x = 0; x < nCols; ++x )
285  {
286  if ( x == 0 )
287  {
288  val = colorMatrix[index + 1] - colorMatrix[index];
289  }
290  else if ( x == ( nCols - 1 ) )
291  {
292  val = colorMatrix[index] - colorMatrix[ index - 1 ];
293  }
294  else
295  {
296  val = ( colorMatrix[index + 1] - colorMatrix[index - 1] ) / 2.0;
297  }
298  matrix[index] = val;
299  ++index;
300  }
301  }
302 }
303 
304 void QgsCubicRasterResampler::yDerivativeMatrix( int nCols, int nRows, double *matrix, const int *colorMatrix )
305 {
306  double val = 0;
307  int index = 0;
308 
309  for ( int y = 0; y < nRows; ++y )
310  {
311  for ( int x = 0; x < nCols; ++x )
312  {
313  if ( y == 0 )
314  {
315  val = colorMatrix[ index + nCols ] - colorMatrix[ index ];
316  }
317  else if ( y == ( nRows - 1 ) )
318  {
319  val = colorMatrix[ index ] - colorMatrix[ index - nCols ];
320  }
321  else
322  {
323  val = ( colorMatrix[ index + nCols ] - colorMatrix[ index - nCols ] ) / 2.0;
324  }
325  matrix[index] = val;
326  ++index;
327  }
328  }
329 }
330 
331 void QgsCubicRasterResampler::calculateControlPoints( int nCols, int nRows, int currentRow, int currentCol, int *redMatrix, int *greenMatrix, int *blueMatrix,
332  int *alphaMatrix, double *xDerivativeMatrixRed, double *xDerivativeMatrixGreen, double *xDerivativeMatrixBlue, double *xDerivativeMatrixAlpha,
333  double *yDerivativeMatrixRed, double *yDerivativeMatrixGreen, double *yDerivativeMatrixBlue, double *yDerivativeMatrixAlpha )
334 {
335  Q_UNUSED( nRows );
336  int idx00 = currentRow * nCols + currentCol;
337  int idx10 = idx00 + 1;
338  int idx01 = idx00 + nCols;
339  int idx11 = idx01 + 1;
340 
341  //corner points
342  cRed00 = redMatrix[idx00];
343  cGreen00 = greenMatrix[idx00];
344  cBlue00 = blueMatrix[idx00];
345  cAlpha00 = alphaMatrix[idx00];
346  cRed30 = redMatrix[idx10];
347  cGreen30 = greenMatrix[idx10];
348  cBlue30 = blueMatrix[idx10];
349  cAlpha30 = alphaMatrix[idx10];
350  cRed03 = redMatrix[idx01];
351  cGreen03 = greenMatrix[idx01];
352  cBlue03 = blueMatrix[idx01];
353  cAlpha03 = alphaMatrix[idx01];
354  cRed33 = redMatrix[idx11];
355  cGreen33 = greenMatrix[idx11];
356  cBlue33 = blueMatrix[idx11];
357  cAlpha33 = alphaMatrix[idx11];
358 
359  //control points near c00
360  cRed10 = cRed00 + 0.333 * xDerivativeMatrixRed[idx00];
361  cGreen10 = cGreen00 + 0.333 * xDerivativeMatrixGreen[idx00];
362  cBlue10 = cBlue00 + 0.333 * xDerivativeMatrixBlue[idx00];
363  cAlpha10 = cAlpha00 + 0.333 * xDerivativeMatrixAlpha[idx00];
364  cRed01 = cRed00 + 0.333 * yDerivativeMatrixRed[idx00];
365  cGreen01 = cGreen00 + 0.333 * yDerivativeMatrixGreen[idx00];
366  cBlue01 = cBlue00 + 0.333 * yDerivativeMatrixBlue[idx00];
367  cAlpha01 = cAlpha00 + 0.333 * yDerivativeMatrixAlpha[idx00];
368  cRed11 = cRed10 + 0.333 * yDerivativeMatrixRed[idx00];
369  cGreen11 = cGreen10 + 0.333 * yDerivativeMatrixGreen[idx00];
370  cBlue11 = cBlue10 + 0.333 * yDerivativeMatrixBlue[idx00];
371  cAlpha11 = cAlpha10 + 0.333 * yDerivativeMatrixAlpha[idx00];
372 
373  //control points near c30
374  cRed20 = cRed30 - 0.333 * xDerivativeMatrixRed[idx10];
375  cGreen20 = cGreen30 - 0.333 * xDerivativeMatrixGreen[idx10];
376  cBlue20 = cBlue30 - 0.333 * xDerivativeMatrixBlue[idx10];
377  cAlpha20 = cAlpha30 - 0.333 * xDerivativeMatrixAlpha[idx10];
378  cRed31 = cRed30 + 0.333 * yDerivativeMatrixRed[idx10];
379  cGreen31 = cGreen30 + 0.333 * yDerivativeMatrixGreen[idx10];
380  cBlue31 = cBlue30 + 0.333 * yDerivativeMatrixBlue[idx10];
381  cAlpha31 = cAlpha30 + 0.333 * yDerivativeMatrixAlpha[idx10];
382  cRed21 = cRed20 + 0.333 * yDerivativeMatrixRed[idx10];
383  cGreen21 = cGreen20 + 0.333 * yDerivativeMatrixGreen[idx10];
384  cBlue21 = cBlue20 + 0.333 * yDerivativeMatrixBlue[idx10];
385  cAlpha21 = cAlpha20 + 0.333 * yDerivativeMatrixAlpha[idx10];
386 
387  //control points near c03
388  cRed13 = cRed03 + 0.333 * xDerivativeMatrixRed[idx01];
389  cGreen13 = cGreen03 + 0.333 * xDerivativeMatrixGreen[idx01];
390  cBlue13 = cBlue03 + 0.333 * xDerivativeMatrixBlue[idx01];
391  cAlpha13 = cAlpha03 + 0.333 * xDerivativeMatrixAlpha[idx01];
392  cRed02 = cRed03 - 0.333 * yDerivativeMatrixRed[idx01];
393  cGreen02 = cGreen03 - 0.333 * yDerivativeMatrixGreen[idx01];
394  cBlue02 = cBlue03 - 0.333 * yDerivativeMatrixBlue[idx01];
395  cAlpha02 = cAlpha03 - 0.333 * yDerivativeMatrixAlpha[idx01];
396  cRed12 = cRed02 + 0.333 * xDerivativeMatrixRed[idx01];
397  cGreen12 = cGreen02 + 0.333 * xDerivativeMatrixGreen[idx01];
398  cBlue12 = cBlue02 + 0.333 * xDerivativeMatrixBlue[idx01];
399  cAlpha12 = cAlpha02 + 0.333 * xDerivativeMatrixAlpha[idx01];
400 
401  //control points near c33
402  cRed23 = cRed33 - 0.333 * xDerivativeMatrixRed[idx11];
403  cGreen23 = cGreen33 - 0.333 * xDerivativeMatrixGreen[idx11];
404  cBlue23 = cBlue33 - 0.333 * xDerivativeMatrixBlue[idx11];
405  cAlpha23 = cAlpha33 - 0.333 * xDerivativeMatrixAlpha[idx11];
406  cRed32 = cRed33 - 0.333 * yDerivativeMatrixRed[idx11];
407  cGreen32 = cGreen33 - 0.333 * yDerivativeMatrixGreen[idx11];
408  cBlue32 = cBlue33 - 0.333 * yDerivativeMatrixBlue[idx11];
409  cAlpha32 = cAlpha33 - 0.333 * yDerivativeMatrixAlpha[idx11];
410  cRed22 = cRed32 - 0.333 * xDerivativeMatrixRed[idx11];
411  cGreen22 = cGreen32 - 0.333 * xDerivativeMatrixGreen[idx11];
412  cBlue22 = cBlue32 - 0.333 * xDerivativeMatrixBlue[idx11];
413  cAlpha22 = cAlpha32 - 0.333 * xDerivativeMatrixAlpha[idx11];
414 }
415 
416 QRgb QgsCubicRasterResampler::curveInterpolation( QRgb pt1, QRgb pt2, double t, double d1red, double d1green, double d1blue, double d1alpha,
417  double d2red, double d2green, double d2blue, double d2alpha )
418 {
419  //control points
420  double p0r = qRed( pt1 );
421  double p1r = p0r + 0.333 * d1red;
422  double p3r = qRed( pt2 );
423  double p2r = p3r - 0.333 * d2red;
424  double p0g = qGreen( pt1 );
425  double p1g = p0g + 0.333 * d1green;
426  double p3g = qGreen( pt2 );
427  double p2g = p3g - 0.333 * d2green;
428  double p0b = qBlue( pt1 );
429  double p1b = p0b + 0.333 * d1blue;
430  double p3b = qBlue( pt2 );
431  double p2b = p3b - 0.333 * d2blue;
432  double p0a = qAlpha( pt1 );
433  double p1a = p0a + 0.333 * d1alpha;
434  double p3a = qAlpha( pt2 );
435  double p2a = p3a - 0.333 * d2alpha;
436 
437  //bernstein polynomials
438  double bp0 = calcBernsteinPolyN3( 0, t );
439  double bp1 = calcBernsteinPolyN3( 1, t );
440  double bp2 = calcBernsteinPolyN3( 2, t );
441  double bp3 = calcBernsteinPolyN3( 3, t );
442 
443  int red = bp0 * p0r + bp1 * p1r + bp2 * p2r + bp3 * p3r;
444  int green = bp0 * p0g + bp1 * p1g + bp2 * p2g + bp3 * p3g;
445  int blue = bp0 * p0b + bp1 * p1b + bp2 * p2b + bp3 * p3b;
446  int alpha = bp0 * p0a + bp1 * p1a + bp2 * p2a + bp3 * p3a;
447 
448  return createPremultipliedColor( red, green, blue, alpha );
449 }
450 
451 double QgsCubicRasterResampler::calcBernsteinPolyN3( int i, double t )
452 {
453  if ( i < 0 )
454  {
455  return 0;
456  }
457 
458  return lowerN3( i ) * std::pow( t, i ) * std::pow( ( 1 - t ), ( 3 - i ) );
459 }
460 
461 inline int QgsCubicRasterResampler::lowerN3( int i )
462 {
463  switch ( i )
464  {
465  case 0:
466  case 3:
467  return 1;
468  case 1:
469  case 2:
470  return 3;
471  default:
472  return 0;
473  }
474 }
475 
476 QRgb QgsCubicRasterResampler::createPremultipliedColor( const int r, const int g, const int b, const int a )
477 {
478  int maxComponentBounds = qBound( 0, a, 255 );
479  return qRgba( qBound( 0, r, maxComponentBounds ),
480  qBound( 0, g, maxComponentBounds ),
481  qBound( 0, b, maxComponentBounds ),
482  a );
483 }
Cubic Raster Resampler.
QgsCubicRasterResampler * clone() const override
Gets a deep copy of this object.
void resample(const QImage &srcImage, QImage &dstImage) override
QgsCubicRasterResampler()=default
Constructor for QgsCubicRasterResampler.