30#include <QRegularExpression>
36 return QStringLiteral(
"1.3.0" );
47 static const QSet<QString> sFilter {
48 QStringLiteral(
"REQUEST" ),
49 QStringLiteral(
"VERSION" ),
50 QStringLiteral(
"SERVICE" ),
51 QStringLiteral(
"LAYERS" ),
52 QStringLiteral(
"STYLES" ),
53 QStringLiteral(
"SLD_VERSION" ),
54 QStringLiteral(
"_DC" )
60 const QList<QPair<QString, QString>> queryItems = q.queryItems();
61 for (
const QPair<QString, QString> ¶m : queryItems )
63 if ( sFilter.contains( param.first.toUpper() ) )
64 q.removeAllQueryItems( param.first );
76 if ( format.compare( QLatin1String(
"png" ), Qt::CaseInsensitive ) == 0 || format.compare( QLatin1String(
"image/png" ), Qt::CaseInsensitive ) == 0 )
80 else if ( format.compare( QLatin1String(
"jpg " ), Qt::CaseInsensitive ) == 0 || format.compare( QLatin1String(
"image/jpeg" ), Qt::CaseInsensitive ) == 0 )
84 else if ( format.compare( QLatin1String(
"webp" ), Qt::CaseInsensitive ) == 0 || format.compare( QLatin1String(
"image/webp" ), Qt::CaseInsensitive ) == 0 )
91 const thread_local QRegularExpression modeExpr = QRegularExpression( QStringLiteral(
"image/png\\s*;\\s*mode=([^;]+)" ), QRegularExpression::CaseInsensitiveOption );
93 const QRegularExpressionMatch match = modeExpr.match( format );
94 const QString mode = match.captured( 1 );
95 if ( mode.compare( QLatin1String(
"16bit" ), Qt::CaseInsensitive ) == 0 )
97 if ( mode.compare( QLatin1String(
"8bit" ), Qt::CaseInsensitive ) == 0 )
99 if ( mode.compare( QLatin1String(
"1bit" ), Qt::CaseInsensitive ) == 0 )
113 switch ( outputFormat )
117 contentType = QStringLiteral(
"image/png" );
118 saveFormat = QStringLiteral(
"PNG" );
122 QVector<QRgb> colorTable;
127 const QImage img256 = img.convertToFormat( QImage::Format_ARGB32 );
129 result = img256.convertToFormat( QImage::Format_Indexed8, colorTable, Qt::ColorOnly | Qt::ThresholdDither | Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
131 contentType = QStringLiteral(
"image/png" );
132 saveFormat = QStringLiteral(
"PNG" );
135 result = img.convertToFormat( QImage::Format_ARGB4444_Premultiplied );
136 contentType = QStringLiteral(
"image/png" );
137 saveFormat = QStringLiteral(
"PNG" );
140 result = img.convertToFormat( QImage::Format_Mono, Qt::MonoOnly | Qt::ThresholdDither | Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
141 contentType = QStringLiteral(
"image/png" );
142 saveFormat = QStringLiteral(
"PNG" );
146 contentType = QStringLiteral(
"image/jpeg" );
147 saveFormat = QStringLiteral(
"JPEG" );
151 contentType = QStringLiteral(
"image/webp" );
152 saveFormat = QStringLiteral(
"WEBP" );
156 saveFormat = QStringLiteral(
"Unknown" );
161 result.setDotsPerMeterX( img.dotsPerMeterX() );
162 result.setDotsPerMeterY( img.dotsPerMeterY() );
166 response.
setHeader(
"Content-Type", contentType );
167 if ( saveFormat == QLatin1String(
"JPEG" ) || saveFormat == QLatin1String(
"WEBP" ) )
169 result.save( response.
io(), qPrintable( saveFormat ), imageQuality );
173 result.save( response.
io(), qPrintable( saveFormat ) );
179 parameter.
mValue = formatStr;
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
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.
static QString wmsServiceUrl(const QgsProject &project, const QgsServerRequest &request=QgsServerRequest(), const QgsServerSettings &settings=QgsServerSettings())
Returns the WMS service url.
Defines requests passed to QgsService classes.
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...
Defines the response interface passed to QgsService.
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.
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.
QString implementationVersion()
Returns the highest version supported by this implementation.
ImageOutputFormat
Supported image output format.
@ Unknown
Unknown/invalid 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.