22 #include <QRegularExpression>
41 static QSet<QString> sFilter
43 QStringLiteral(
"REQUEST" ),
44 QStringLiteral(
"VERSION" ),
45 QStringLiteral(
"SERVICE" ),
46 QStringLiteral(
"LAYERS" ),
47 QStringLiteral(
"STYLES" ),
48 QStringLiteral(
"SLD_VERSION" ),
49 QStringLiteral(
"_DC" )
55 for (
auto param : q.queryItems() )
57 if ( sFilter.contains( param.first.toUpper() ) )
58 q.removeAllQueryItems( param.first );
70 if ( format.compare( QLatin1String(
"png" ), Qt::CaseInsensitive ) == 0 ||
71 format.compare( QLatin1String(
"image/png" ), Qt::CaseInsensitive ) == 0 )
75 else if ( format.compare( QLatin1String(
"jpg " ), Qt::CaseInsensitive ) == 0 ||
76 format.compare( QLatin1String(
"image/jpeg" ), Qt::CaseInsensitive ) == 0 )
80 else if ( format.compare( QLatin1String(
"webp" ), Qt::CaseInsensitive ) == 0 ||
81 format.compare( QLatin1String(
"image/webp" ), Qt::CaseInsensitive ) == 0 )
88 QRegularExpression modeExpr = QRegularExpression( QStringLiteral(
"image/png\\s*;\\s*mode=([^;]+)" ),
89 QRegularExpression::CaseInsensitiveOption );
91 QRegularExpressionMatch match = modeExpr.match( format );
92 QString mode = match.captured( 1 );
93 if ( mode.compare( QLatin1String(
"16bit" ), Qt::CaseInsensitive ) == 0 )
95 if ( mode.compare( QLatin1String(
"8bit" ), Qt::CaseInsensitive ) == 0 )
97 if ( mode.compare( QLatin1String(
"1bit" ), Qt::CaseInsensitive ) == 0 )
112 switch ( outputFormat )
116 contentType =
"image/png";
121 QVector<QRgb> colorTable;
126 QImage img256 = img.convertToFormat( QImage::Format_ARGB32 );
128 result = img256.convertToFormat( QImage::Format_Indexed8, colorTable,
129 Qt::ColorOnly | Qt::ThresholdDither |
130 Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
132 contentType =
"image/png";
136 result = img.convertToFormat( QImage::Format_ARGB4444_Premultiplied );
137 contentType =
"image/png";
141 result = img.convertToFormat( QImage::Format_Mono,
142 Qt::MonoOnly | Qt::ThresholdDither |
143 Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
144 contentType =
"image/png";
149 contentType =
"image/jpeg";
154 contentType = QStringLiteral(
"image/webp" );
155 saveFormat = QStringLiteral(
"WEBP" );
164 result.setDotsPerMeterX( img.dotsPerMeterX() );
165 result.setDotsPerMeterY( img.dotsPerMeterY() );
167 if ( outputFormat !=
UNKN )
169 response.
setHeader(
"Content-Type", contentType );
170 if ( saveFormat == QLatin1String(
"JPEG" ) || saveFormat == QLatin1String(
"WEBP" ) )
172 result.save( response.
io(), qPrintable( saveFormat ), imageQuality );
176 result.save( response.
io(), qPrintable( saveFormat ) );
182 parameter.
mValue = formatStr;
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QUrl originalUrl() const
Returns the request url as seen by the web server, by default this is equal to the url seen by QGIS s...
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
virtual QIODevice * io()=0
Returns the underlying QIODevice.
Provides a way to retrieve settings by prioritizing according to environment variables,...
Exception thrown in case of malformed request.
WMS parameter received from the client.
SERVER_EXPORT QString wmsServiceUrl(const QgsProject &project, const QgsServerRequest &request=QgsServerRequest(), const QgsServerSettings &settings=QgsServerSettings())
Returns the WMS service url.
Median cut implementation.
void writeImage(QgsServerResponse &response, QImage &img, const QString &formatStr, int imageQuality)
Write image response.
void medianCut(QVector< QRgb > &colorTable, int nColors, const QImage &inputImage)
Median cut implementation used when reducing RGB colors to palletized colors.
ImageOutputFormat
Supported image output format.
ImageOutputFormat parseImageFormat(const QString &format)
Parse image format parameter.
QUrl serviceUrl(const QgsServerRequest &request, const QgsProject *project, const QgsServerSettings &settings)
Returns WMS service URL.