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;
123 QImage img256 = img.convertToFormat( QImage::Format_ARGB32 );
125 result = img256.convertToFormat( QImage::Format_Indexed8, colorTable,
126 Qt::ColorOnly | Qt::ThresholdDither |
127 Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
129 contentType =
"image/png";
133 result = img.convertToFormat( QImage::Format_ARGB4444_Premultiplied );
134 contentType =
"image/png";
138 result = img.convertToFormat( QImage::Format_Mono,
139 Qt::MonoOnly | Qt::ThresholdDither |
140 Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
141 contentType =
"image/png";
146 contentType =
"image/jpeg";
155 if ( outputFormat !=
UNKN )
157 response.
setHeader(
"Content-Type", contentType );
158 if ( saveFormat ==
"JPEG" )
160 result.save( response.
io(), qPrintable( saveFormat ), imageQuality );
164 result.save( response.
io(), qPrintable( saveFormat ) );
170 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).
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
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.