22 #include <QRegularExpression> 43 static QSet<QString> sFilter
45 QStringLiteral(
"REQUEST" ),
46 QStringLiteral(
"VERSION" ),
47 QStringLiteral(
"SERVICE" ),
48 QStringLiteral(
"LAYERS" ),
49 QStringLiteral(
"STYLES" ),
50 QStringLiteral(
"SLD_VERSION" ),
51 QStringLiteral(
"_DC" )
57 for (
auto param : q.queryItems() )
59 if ( sFilter.contains( param.first.toUpper() ) )
60 q.removeAllQueryItems( param.first );
72 if ( format.compare( QLatin1String(
"png" ), Qt::CaseInsensitive ) == 0 ||
73 format.compare( QLatin1String(
"image/png" ), Qt::CaseInsensitive ) == 0 )
77 else if ( format.compare( QLatin1String(
"jpg " ), Qt::CaseInsensitive ) == 0 ||
78 format.compare( QLatin1String(
"image/jpeg" ), Qt::CaseInsensitive ) == 0 )
85 QRegularExpression modeExpr = QRegularExpression( QStringLiteral(
"image/png\\s*;\\s*mode=([^;]+)" ),
86 QRegularExpression::CaseInsensitiveOption );
88 QRegularExpressionMatch match = modeExpr.match( format );
89 QString mode = match.captured( 1 );
90 if ( mode.compare( QLatin1String(
"16bit" ), Qt::CaseInsensitive ) == 0 )
92 if ( mode.compare( QLatin1String(
"8bit" ), Qt::CaseInsensitive ) == 0 )
94 if ( mode.compare( QLatin1String(
"1bit" ), Qt::CaseInsensitive ) == 0 )
109 switch ( outputFormat )
113 contentType =
"image/png";
118 QVector<QRgb> colorTable;
120 result = img.convertToFormat( QImage::Format_Indexed8, colorTable,
121 Qt::ColorOnly | Qt::ThresholdDither |
122 Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
124 contentType =
"image/png";
128 result = img.convertToFormat( QImage::Format_ARGB4444_Premultiplied );
129 contentType =
"image/png";
133 result = img.convertToFormat( QImage::Format_Mono,
134 Qt::MonoOnly | Qt::ThresholdDither |
135 Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
136 contentType =
"image/png";
141 contentType =
"image/jpeg";
150 if ( outputFormat !=
UNKN )
152 response.
setHeader(
"Content-Type", contentType );
153 if ( saveFormat ==
"JPEG" )
155 result.save( response.
io(), qPrintable( saveFormat ), imageQuality );
159 result.save( response.
io(), qPrintable( saveFormat ) );
165 parameter.
mValue = formatStr;
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...
SERVER_EXPORT QString wmsServiceUrl(const QgsProject &project)
Returns the WMS service url defined in a QGIS project.
Exception thrown in case of malformed request.
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...
void writeImage(QgsServerResponse &response, QImage &img, const QString &formatStr, int imageQuality)
Write image response.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Reads and writes project states.
Median cut implementation.
void medianCut(QVector< QRgb > &colorTable, int nColors, const QImage &inputImage)
Median cut implementation used when reducing RGB colors to palletized colors.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
virtual QIODevice * io()=0
Returns the underlying QIODevice.
QUrl serviceUrl(const QgsServerRequest &request, const QgsProject *project)
Returns WMS service URL.
ImageOutputFormat
Supported image output format.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
WMS parameter received from the client.
ImageOutputFormat parseImageFormat(const QString &format)
Parse image format parameter.