129 return mInput->block( bandNo,
extent, width, height, feedback );
131 const int bandNumber = 1;
133 QgsDebugMsgLevel( u
"width = %1 height = %2 extent = %3"_s.arg( width ).arg( height ).arg(
extent.toString() ), 4 );
134 auto outputBlock = std::make_unique<QgsRasterBlock>();
136 return outputBlock.release();
138 double oversampling = 1.0;
140 double providerXRes = 0;
146 outputXRes =
extent.width() / width;
148 const double pixelRatio = outputXRes / providerXRes;
150 QgsDebugMsgLevel( u
"xRes = %1 providerXRes = %2 pixelRatio = %3 oversampling = %4"_s.arg( outputXRes ).arg( providerXRes ).arg( pixelRatio ).arg( oversampling ), 4 );
169 return mInput->block( bandNumber,
extent, width, height, feedback );
173 const double oversamplingX = (
static_cast< double >( width ) * oversampling ) / width;
174 const double oversamplingY = (
static_cast< double >( height ) * oversampling ) / height;
177 int tileBufferPixels = 0;
178 if ( providerXRes != 0 )
182 tileBufferPixels =
static_cast< int >( std::ceil(
mZoomedInResampler->tileBufferPixels() * oversampling ) );
186 tileBufferPixels =
static_cast< int >( std::ceil(
mZoomedOutResampler->tileBufferPixels() * oversampling ) );
189 const double sourceTileBufferSize = providerXRes * tileBufferPixels;
191 const QgsRectangle bufferedExtent(
extent.xMinimum() - sourceTileBufferSize,
extent.yMinimum() - sourceTileBufferSize,
extent.xMaximum() + sourceTileBufferSize,
extent.yMaximum() + sourceTileBufferSize );
193 const int resWidth =
static_cast< int >( std::round( width * oversamplingX ) ) + 2 * tileBufferPixels;
194 const int resHeight =
static_cast< int >( std::round( height * oversamplingY ) ) + 2 * tileBufferPixels;
196 std::unique_ptr< QgsRasterBlock > inputBlock(
mInput->block( bandNumber, bufferedExtent, resWidth, resHeight, feedback ) );
197 if ( !inputBlock || inputBlock->isEmpty() )
200 return outputBlock.release();
205 return outputBlock.release();
209 const QImage img = inputBlock->image();
211 const int resampleWidth =
static_cast< int >( std::round( width * ( bufferedExtent.
width() /
extent.width() ) ) );
212 const int resampleHeight =
static_cast< int >( std::round( height * ( bufferedExtent.
height() /
extent.height() ) ) );
221 dstImg = resamplerV2->resampleV2( img, QSize( resampleWidth, resampleHeight ) );
227 QImage dstImg = QImage( resampleWidth, resampleHeight, QImage::Format_ARGB32_Premultiplied );
238 dstImg = resamplerV2->resampleV2( img, QSize( resampleWidth, resampleHeight ) );
244 QImage dstImg = QImage( resampleWidth, resampleHeight, QImage::Format_ARGB32_Premultiplied );
253 dstImg = img.scaled( width, height );
257 const QImage cropped = tileBufferPixels > 0 ? dstImg.copy( ( resampleWidth - width ) / 2, ( resampleHeight - height ) / 2, width, height ) : dstImg;
258 outputBlock->setImage( &cropped );
260 return outputBlock.release();
286 if ( filterElem.isNull() )
291 mMaxOversampling = filterElem.attribute( u
"maxOversampling"_s, u
"2.0"_s ).toDouble();
293 const QString zoomedInResamplerType = filterElem.attribute( u
"zoomedInResampler"_s );
294 if ( zoomedInResamplerType ==
"bilinear"_L1 )
298 else if ( zoomedInResamplerType ==
"cubic"_L1 )
303 const QString zoomedOutResamplerType = filterElem.attribute( u
"zoomedOutResampler"_s );
304 if ( zoomedOutResamplerType ==
"bilinear"_L1 )
308 else if ( zoomedOutResamplerType ==
"cubic"_L1 )