QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
30 #include <QDomDocument>
31 #include <QDomElement>
102 QgsDebugMsg( QStringLiteral(
"Unknown input data type" ) );
126 const int bandNumber = 1;
129 std::unique_ptr< QgsRasterBlock > outputBlock(
new QgsRasterBlock() );
131 return outputBlock.release();
133 double oversampling = 1.0;
135 double providerXRes = 0;
143 const double pixelRatio = outputXRes / providerXRes;
145 QgsDebugMsgLevel( QStringLiteral(
"xRes = %1 providerXRes = %2 pixelRatio = %3 oversampling = %4" ).arg( outputXRes ).arg( providerXRes ).arg( pixelRatio ).arg( oversampling ), 4 );
156 QgsDebugMsgLevel( QStringLiteral(
"oversampling %1" ).arg( oversampling ), 4 );
168 const double oversamplingX = (
static_cast< double >( width ) * oversampling ) / width;
169 const double oversamplingY = (
static_cast< double >( height ) * oversampling ) / height;
172 int tileBufferPixels = 0;
173 if ( providerXRes != 0 )
177 tileBufferPixels =
static_cast< int >( std::ceil(
mZoomedInResampler->tileBufferPixels() * oversampling ) );
181 tileBufferPixels =
static_cast< int >( std::ceil(
mZoomedOutResampler->tileBufferPixels() * oversampling ) );
184 const double sourceTileBufferSize = providerXRes * tileBufferPixels;
192 const int resWidth =
static_cast< int >( std::round( width * oversamplingX ) ) + 2 * tileBufferPixels;
193 const int resHeight =
static_cast< int >( std::round( height * oversamplingY ) ) + 2 * tileBufferPixels;
195 std::unique_ptr< QgsRasterBlock > inputBlock(
mInput->
block( bandNumber, bufferedExtent, resWidth, resHeight, feedback ) );
196 if ( !inputBlock || inputBlock->isEmpty() )
198 QgsDebugMsg( QStringLiteral(
"No raster data!" ) );
199 return outputBlock.release();
204 return outputBlock.release();
208 const QImage img = inputBlock->image();
210 const int resampleWidth =
static_cast< int >( std::round( width * ( bufferedExtent.
width() /
extent.
width() ) ) );
211 const int resampleHeight =
static_cast< int >( std::round( height * ( bufferedExtent.
height() /
extent.
height() ) ) );
220 dstImg = resamplerV2->resampleV2( img, QSize( resampleWidth, resampleHeight ) );
226 QImage dstImg = QImage( resampleWidth, resampleHeight, QImage::Format_ARGB32_Premultiplied );
237 dstImg = resamplerV2->resampleV2( img, QSize( resampleWidth, resampleHeight ) );
243 QImage dstImg = QImage( resampleWidth, resampleHeight, QImage::Format_ARGB32_Premultiplied );
251 QgsDebugMsg( QStringLiteral(
"Unexpected resampling" ) );
252 dstImg = img.scaled( width, height );
256 const QImage cropped = tileBufferPixels > 0 ? dstImg.copy( ( resampleWidth - width ) / 2, ( resampleHeight - height ) / 2, width, height )
258 outputBlock->setImage( &cropped );
260 return outputBlock.release();
265 if ( parentElem.isNull() )
270 QDomElement rasterRendererElem = doc.createElement( QStringLiteral(
"rasterresampler" ) );
272 rasterRendererElem.setAttribute( QStringLiteral(
"maxOversampling" ), QString::number(
mMaxOversampling ) );
275 rasterRendererElem.setAttribute( QStringLiteral(
"zoomedInResampler" ),
mZoomedInResampler->type() );
279 rasterRendererElem.setAttribute( QStringLiteral(
"zoomedOutResampler" ),
mZoomedOutResampler->type() );
281 parentElem.appendChild( rasterRendererElem );
286 if ( filterElem.isNull() )
291 mMaxOversampling = filterElem.attribute( QStringLiteral(
"maxOversampling" ), QStringLiteral(
"2.0" ) ).toDouble();
293 const QString zoomedInResamplerType = filterElem.attribute( QStringLiteral(
"zoomedInResampler" ) );
294 if ( zoomedInResamplerType == QLatin1String(
"bilinear" ) )
298 else if ( zoomedInResamplerType == QLatin1String(
"cubic" ) )
303 const QString zoomedOutResamplerType = filterElem.attribute( QStringLiteral(
"zoomedOutResampler" ) );
304 if ( zoomedOutResamplerType == QLatin1String(
"bilinear" ) )
308 else if ( zoomedOutResamplerType == QLatin1String(
"cubic" ) )
int bandCount() const override
Gets number of bands.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
@ Size
Original data source size (and thus resolution) is known, it is not always available,...
QgsRasterInterface * mInput
#define QgsDebugMsgLevel(str, level)
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Interface for resampling rasters (e.g. to have a smoother appearance)
DataType
Raster data types.
QgsRectangle extent() const override=0
Returns the extent of the layer.
A rectangle specified with double values.
Bilinear Raster Resampler.
#define Q_NOWARN_DEPRECATED_POP
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
virtual const QgsRasterInterface * sourceInput() const
Gets source / raw input, the first in pipe, usually provider.
virtual int xSize() const
Gets raster size.
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
double mMaxOversampling
Maximum boundary for oversampling (to avoid too much data traffic). Default: 2.0.
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
bool setInput(QgsRasterInterface *input) override
Set input.
Interface for resampling rasters (V2) (e.g. to have a smoother appearance), which provides a more eff...
@ UnknownDataType
Unknown or unspecified type.
QgsRasterResampleFilter(QgsRasterInterface *input=nullptr)
void setZoomedInResampler(QgsRasterResampler *r)
Sets resampler for zoomed in scales. Takes ownership of the object.
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
std::unique_ptr< QgsRasterResampler > mZoomedInResampler
Resampler used if screen resolution is higher than raster resolution (zoomed in). 0 means no resampli...
Base class for processing filters like renderers, reprojector, resampler etc.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Resample filter pipe for rasters.
virtual QgsRasterInterface * input() const
Current input.
Feedback object tailored for raster block reading.
std::unique_ptr< QgsRasterResampler > mZoomedOutResampler
Resampler used if raster resolution is higher than raster resolution (zoomed out)....
void writeXml(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
Qgis::DataType dataType(int bandNo) const override
Returns data type for the band specified by number.
virtual int bandCount() const =0
Gets number of bands.
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.
QgsRasterResampleFilter * clone() const override
Clone itself, create deep copy.
#define Q_NOWARN_DEPRECATED_PUSH
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
void setMaxOversampling(double os)
Base class for raster data providers.
void setZoomedOutResampler(QgsRasterResampler *r)
Sets resampler for zoomed out scales. Takes ownership of the object.
virtual QgsRectangle extent() const
Gets the extent of the interface.