30 #include <QDomDocument> 31 #include <QDomElement> 102 QgsDebugMsg( QStringLiteral(
"Unknown input data type" ) );
124 QgsDebugMsgLevel( QStringLiteral(
"width = %1 height = %2 extent = %3" ).arg( width ).arg( height ).arg( extent.
toString() ), 4 );
125 std::unique_ptr< QgsRasterBlock > outputBlock(
new QgsRasterBlock() );
127 return outputBlock.release();
129 double oversampling = 1.0;
136 double xRes = extent.
width() / width;
138 double pixelRatio = xRes / providerXRes;
140 QgsDebugMsgLevel( QStringLiteral(
"xRes = %1 providerXRes = %2 pixelRatio = %3 oversampling = %4" ).arg( xRes ).arg( providerXRes ).arg( pixelRatio ).arg( oversampling ), 4 );
151 QgsDebugMsgLevel( QStringLiteral(
"oversampling %1" ).arg( oversampling ), 4 );
161 return mInput->
block( bandNumber, extent, width, height, feedback );
165 double oversamplingX = (
static_cast< double >( width ) * oversampling ) / width;
166 double oversamplingY = (
static_cast< double >( height ) * oversampling ) / height;
170 int resWidth = width * oversamplingX;
171 int resHeight = height * oversamplingY;
173 std::unique_ptr< QgsRasterBlock > inputBlock(
mInput->
block( bandNumber, extent, resWidth, resHeight, feedback ) );
174 if ( !inputBlock || inputBlock->isEmpty() )
176 QgsDebugMsg( QStringLiteral(
"No raster data!" ) );
177 return outputBlock.release();
182 return outputBlock.release();
186 QImage img = inputBlock->image();
188 QImage dstImg = QImage( width, height, QImage::Format_ARGB32_Premultiplied );
203 QgsDebugMsg( QStringLiteral(
"Unexpected resampling" ) );
204 dstImg = img.scaled( width, height );
207 outputBlock->setImage( &dstImg );
209 return outputBlock.release();
214 if ( parentElem.isNull() )
219 QDomElement rasterRendererElem = doc.createElement( QStringLiteral(
"rasterresampler" ) );
221 rasterRendererElem.setAttribute( QStringLiteral(
"maxOversampling" ), QString::number(
mMaxOversampling ) );
224 rasterRendererElem.setAttribute( QStringLiteral(
"zoomedInResampler" ),
mZoomedInResampler->type() );
228 rasterRendererElem.setAttribute( QStringLiteral(
"zoomedOutResampler" ),
mZoomedOutResampler->type() );
230 parentElem.appendChild( rasterRendererElem );
235 if ( filterElem.isNull() )
240 mMaxOversampling = filterElem.attribute( QStringLiteral(
"maxOversampling" ), QStringLiteral(
"2.0" ) ).toDouble();
242 QString zoomedInResamplerType = filterElem.attribute( QStringLiteral(
"zoomedInResampler" ) );
243 if ( zoomedInResamplerType == QLatin1String(
"bilinear" ) )
247 else if ( zoomedInResamplerType == QLatin1String(
"cubic" ) )
252 QString zoomedOutResamplerType = filterElem.attribute( QStringLiteral(
"zoomedOutResampler" ) );
253 if ( zoomedOutResamplerType == QLatin1String(
"bilinear" ) )
virtual int bandCount() const =0
Gets number of bands.
A rectangle specified with double values.
void setMaxOversampling(double os)
Interface for resampling rasters (e.g.
virtual QgsRectangle extent() const
Gets the extent of the interface.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
virtual QgsRasterInterface * input() const
Current input.
DataType
Raster data types.
Resample filter pipe for rasters.
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
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.
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
#define QgsDebugMsgLevel(str, level)
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 int capabilities() const
Returns a bitmask containing the supported capabilities.
QgsRectangle extent() const override=0
Returns the extent of the layer.
double width() const
Returns the width of the rectangle.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
Unknown or unspecified type.
QgsRasterResampleFilter(QgsRasterInterface *input=nullptr)
Base class for processing filters like renderers, reprojector, resampler etc.
double mMaxOversampling
Maximum boundary for oversampling (to avoid too much data traffic). Default: 2.0. ...
bool setInput(QgsRasterInterface *input) override
Set input.
std::unique_ptr< QgsRasterResampler > mZoomedOutResampler
Resampler used if raster resolution is higher than raster resolution (zoomed out). 0 mean no resampling (nearest neighbour)
Qgis::DataType dataType(int bandNo) const override
Returns data type for the band specified by number.
void setZoomedInResampler(QgsRasterResampler *r)
Sets resampler for zoomed in scales. Takes ownership of the object.
QgsRasterResampleFilter * clone() const override
Clone itself, create deep copy.
Bilinear Raster Resampler.
void writeXml(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
void setZoomedOutResampler(QgsRasterResampler *r)
Sets resampler for zoomed out scales. Takes ownership of the object.
std::unique_ptr< QgsRasterResampler > mZoomedInResampler
Resampler used if screen resolution is higher than raster resolution (zoomed in). 0 means no resampli...
QgsRasterInterface * mInput
Feedback object tailored for raster block reading.
virtual int xSize() const
Gets raster size.
int bandCount() const override
Gets number of bands.
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
virtual const QgsRasterInterface * sourceInput() const
Gets source / raw input, the first in pipe, usually provider.
Base class for raster data providers.