30 #include <QDomDocument>
31 #include <QDomElement>
102 QgsDebugMsg( QStringLiteral(
"Unknown input data type" ) );
125 std::unique_ptr< QgsRasterBlock > outputBlock(
new QgsRasterBlock() );
127 return outputBlock.release();
129 double oversampling = 1.0;
131 double providerXRes = 0;
139 double pixelRatio = outputXRes / providerXRes;
141 QgsDebugMsgLevel( QStringLiteral(
"xRes = %1 providerXRes = %2 pixelRatio = %3 oversampling = %4" ).arg( outputXRes ).arg( providerXRes ).arg( pixelRatio ).arg( oversampling ), 4 );
152 QgsDebugMsgLevel( QStringLiteral(
"oversampling %1" ).arg( oversampling ), 4 );
166 double oversamplingX = (
static_cast< double >( width ) * oversampling ) / width;
167 double oversamplingY = (
static_cast< double >( height ) * oversampling ) / height;
170 int tileBufferPixels = 0;
171 if ( providerXRes != 0 )
175 tileBufferPixels =
static_cast< int >( std::ceil(
mZoomedInResampler->tileBufferPixels() * oversampling ) );
179 tileBufferPixels =
static_cast< int >( std::ceil(
mZoomedOutResampler->tileBufferPixels() * oversampling ) );
182 const double sourceTileBufferSize = providerXRes * tileBufferPixels;
190 int resWidth =
static_cast< int >( std::round( width * oversamplingX ) ) + 2 * tileBufferPixels;
191 int resHeight =
static_cast< int >( std::round( height * oversamplingY ) ) + 2 * tileBufferPixels;
193 std::unique_ptr< QgsRasterBlock > inputBlock(
mInput->
block( bandNumber, bufferedExtent, resWidth, resHeight, feedback ) );
194 if ( !inputBlock || inputBlock->isEmpty() )
196 QgsDebugMsg( QStringLiteral(
"No raster data!" ) );
197 return outputBlock.release();
202 return outputBlock.release();
206 QImage img = inputBlock->image();
208 int resampleWidth =
static_cast< int >( std::round( width * ( bufferedExtent.
width() /
extent.
width() ) ) );
209 int resampleHeight =
static_cast< int >( std::round( height * ( bufferedExtent.
height() /
extent.
height() ) ) );
218 dstImg = resamplerV2->resampleV2( img, QSize( resampleWidth, resampleHeight ) );
224 QImage dstImg = QImage( resampleWidth, resampleHeight, QImage::Format_ARGB32_Premultiplied );
235 dstImg = resamplerV2->resampleV2( img, QSize( resampleWidth, resampleHeight ) );
241 QImage dstImg = QImage( resampleWidth, resampleHeight, QImage::Format_ARGB32_Premultiplied );
249 QgsDebugMsg( QStringLiteral(
"Unexpected resampling" ) );
250 dstImg = img.scaled( width, height );
254 QImage cropped = tileBufferPixels > 0 ? dstImg.copy( ( resampleWidth - width ) / 2, ( resampleHeight - height ) / 2, width, height )
256 outputBlock->setImage( &cropped );
258 return outputBlock.release();
263 if ( parentElem.isNull() )
268 QDomElement rasterRendererElem = doc.createElement( QStringLiteral(
"rasterresampler" ) );
270 rasterRendererElem.setAttribute( QStringLiteral(
"maxOversampling" ), QString::number(
mMaxOversampling ) );
273 rasterRendererElem.setAttribute( QStringLiteral(
"zoomedInResampler" ),
mZoomedInResampler->type() );
277 rasterRendererElem.setAttribute( QStringLiteral(
"zoomedOutResampler" ),
mZoomedOutResampler->type() );
279 parentElem.appendChild( rasterRendererElem );
284 if ( filterElem.isNull() )
289 mMaxOversampling = filterElem.attribute( QStringLiteral(
"maxOversampling" ), QStringLiteral(
"2.0" ) ).toDouble();
291 QString zoomedInResamplerType = filterElem.attribute( QStringLiteral(
"zoomedInResampler" ) );
292 if ( zoomedInResamplerType == QLatin1String(
"bilinear" ) )
296 else if ( zoomedInResamplerType == QLatin1String(
"cubic" ) )
301 QString zoomedOutResamplerType = filterElem.attribute( QStringLiteral(
"zoomedOutResampler" ) );
302 if ( zoomedOutResamplerType == QLatin1String(
"bilinear" ) )