27#include <QDomDocument> 
  123  const int bandNumber = 1;
 
  126  auto outputBlock = std::make_unique<QgsRasterBlock>();
 
  128    return outputBlock.release();
 
  130  double oversampling = 1.0; 
 
  132  double providerXRes = 0;
 
  140      const double pixelRatio = outputXRes / providerXRes;
 
  142      QgsDebugMsgLevel( QStringLiteral( 
"xRes = %1 providerXRes = %2 pixelRatio = %3 oversampling = %4" ).arg( outputXRes ).arg( providerXRes ).arg( pixelRatio ).arg( oversampling ), 4 );
 
  153  QgsDebugMsgLevel( QStringLiteral( 
"oversampling %1" ).arg( oversampling ), 4 );
 
  165  const double oversamplingX = ( 
static_cast< double >( width ) * oversampling ) / width;
 
  166  const double oversamplingY = ( 
static_cast< double >( height ) * oversampling ) / height;
 
  169  int tileBufferPixels = 0;
 
  170  if ( providerXRes != 0 )
 
  174      tileBufferPixels = 
static_cast< int >( std::ceil( 
mZoomedInResampler->tileBufferPixels() * oversampling ) );
 
  178      tileBufferPixels = 
static_cast< int >( std::ceil( 
mZoomedOutResampler->tileBufferPixels() * oversampling ) );
 
  181  const double sourceTileBufferSize = providerXRes * tileBufferPixels;
 
  189  const int resWidth = 
static_cast< int >( std::round( width * oversamplingX ) ) + 2 * tileBufferPixels;
 
  190  const int resHeight = 
static_cast< int >( std::round( height * oversamplingY ) ) + 2 * tileBufferPixels;
 
  192  std::unique_ptr< QgsRasterBlock > inputBlock( 
mInput->
block( bandNumber, bufferedExtent, resWidth, resHeight, feedback ) );
 
  193  if ( !inputBlock || inputBlock->isEmpty() )
 
  196    return outputBlock.release();
 
  201    return outputBlock.release();
 
  205  const QImage img = inputBlock->image();
 
  207  const int resampleWidth = 
static_cast< int >( std::round( width * ( bufferedExtent.
width() / 
extent.
width() ) ) );
 
  208  const int resampleHeight = 
static_cast< int >( std::round( height * ( bufferedExtent.
height() / 
extent.
height() ) ) );
 
  217      dstImg = resamplerV2->resampleV2( img, QSize( resampleWidth, resampleHeight ) );
 
  223      QImage dstImg = QImage( resampleWidth, resampleHeight, QImage::Format_ARGB32_Premultiplied );
 
  234      dstImg = resamplerV2->resampleV2( img, QSize( resampleWidth, resampleHeight ) );
 
  240      QImage dstImg = QImage( resampleWidth, resampleHeight, QImage::Format_ARGB32_Premultiplied );
 
  249    dstImg = img.scaled( width, height );
 
  253  const QImage cropped = tileBufferPixels > 0 ? dstImg.copy( ( resampleWidth - width ) / 2, ( resampleHeight - height ) / 2, width, height )
 
  255  outputBlock->setImage( &cropped );
 
  257  return outputBlock.release(); 
 
 
  262  if ( parentElem.isNull() )
 
  267  QDomElement rasterRendererElem = doc.createElement( QStringLiteral( 
"rasterresampler" ) );
 
  269  rasterRendererElem.setAttribute( QStringLiteral( 
"maxOversampling" ), QString::number( 
mMaxOversampling ) );
 
  272    rasterRendererElem.setAttribute( QStringLiteral( 
"zoomedInResampler" ), 
mZoomedInResampler->type() );
 
  276    rasterRendererElem.setAttribute( QStringLiteral( 
"zoomedOutResampler" ), 
mZoomedOutResampler->type() );
 
  278  parentElem.appendChild( rasterRendererElem );
 
 
  283  if ( filterElem.isNull() )
 
  288  mMaxOversampling = filterElem.attribute( QStringLiteral( 
"maxOversampling" ), QStringLiteral( 
"2.0" ) ).toDouble();
 
  290  const QString zoomedInResamplerType = filterElem.attribute( QStringLiteral( 
"zoomedInResampler" ) );
 
  291  if ( zoomedInResamplerType == QLatin1String( 
"bilinear" ) )
 
  295  else if ( zoomedInResamplerType == QLatin1String( 
"cubic" ) )
 
  300  const QString zoomedOutResamplerType = filterElem.attribute( QStringLiteral( 
"zoomedOutResampler" ) );
 
  301  if ( zoomedOutResamplerType == QLatin1String( 
"bilinear" ) )
 
  305  else if ( zoomedOutResamplerType == QLatin1String( 
"cubic" ) )
 
 
@ Size
Original data source size (and thus resolution) is known, it is not always available,...
 
DataType
Raster data types.
 
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
 
@ UnknownDataType
Unknown or unspecified type.
 
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
 
Bilinear raster resampler.
 
Feedback object tailored for raster block reading.
 
Base class for raster data providers.
 
QgsRectangle extent() const override=0
Returns the extent of the layer.
 
Base class for processing filters like renderers, reprojector, resampler etc.
 
virtual Qgis::RasterInterfaceCapabilities capabilities() const
Returns the capabilities supported by the interface.
 
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)=0
Read block of data using given extent and size.
 
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
 
virtual int xSize() const
Gets raster size.
 
virtual int bandCount() const =0
Gets number of bands.
 
QgsRasterInterface * mInput
 
virtual QgsRectangle extent() const
Gets the extent of the interface.
 
virtual QgsRasterInterface * input() const
Current input.
 
virtual const QgsRasterInterface * sourceInput() const
Gets source / raw input, the first in pipe, usually provider.
 
Resample filter pipe for rasters.
 
double mMaxOversampling
Maximum boundary for oversampling (to avoid too much data traffic). Default: 2.0.
 
bool setInput(QgsRasterInterface *input) override
Set input.
 
void setZoomedOutResampler(QgsRasterResampler *r)
Sets resampler for zoomed out scales. Takes ownership of the object.
 
void writeXml(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
 
void setMaxOversampling(double os)
 
Qgis::DataType dataType(int bandNo) const override
Returns data type for the band specified by number.
 
std::unique_ptr< QgsRasterResampler > mZoomedInResampler
Resampler used if screen resolution is higher than raster resolution (zoomed in). 0 means no resampli...
 
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
 
std::unique_ptr< QgsRasterResampler > mZoomedOutResampler
Resampler used if raster resolution is higher than raster resolution (zoomed out)....
 
QgsRasterResampleFilter(QgsRasterInterface *input=nullptr)
 
int bandCount() const override
Gets number of bands.
 
QgsRasterResampleFilter * clone() const override
Clone itself, create deep copy.
 
void setZoomedInResampler(QgsRasterResampler *r)
Sets resampler for zoomed in scales. Takes ownership of the object.
 
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
 
Interface for resampling rasters (V2) (e.g.
 
Interface for resampling rasters (e.g.
 
A rectangle specified with double values.
 
Q_INVOKABLE QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
 
#define Q_NOWARN_DEPRECATED_POP
 
#define Q_NOWARN_DEPRECATED_PUSH
 
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
 
#define QgsDebugMsgLevel(str, level)
 
#define QgsDebugError(str)