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 )
82 else if ( format.compare( QLatin1String(
"webp" ), Qt::CaseInsensitive ) == 0 ||
83 format.compare( QLatin1String(
"image/webp" ), Qt::CaseInsensitive ) == 0 )
90 QRegularExpression modeExpr = QRegularExpression( QStringLiteral(
"image/png\\s*;\\s*mode=([^;]+)" ),
91 QRegularExpression::CaseInsensitiveOption );
93 QRegularExpressionMatch match = modeExpr.match( format );
94 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 )
114 switch ( outputFormat )
118 contentType =
"image/png";
123 QVector<QRgb> colorTable;
128 QImage img256 = img.convertToFormat( QImage::Format_ARGB32 );
130 result = img256.convertToFormat( QImage::Format_Indexed8, colorTable,
131 Qt::ColorOnly | Qt::ThresholdDither |
132 Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
134 contentType =
"image/png";
138 result = img.convertToFormat( QImage::Format_ARGB4444_Premultiplied );
139 contentType =
"image/png";
143 result = img.convertToFormat( QImage::Format_Mono,
144 Qt::MonoOnly | Qt::ThresholdDither |
145 Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
146 contentType =
"image/png";
151 contentType =
"image/jpeg";
156 contentType = QStringLiteral(
"image/webp" );
157 saveFormat = QStringLiteral(
"WEBP" );
166 result.setDotsPerMeterX( img.dotsPerMeterX() );
167 result.setDotsPerMeterY( img.dotsPerMeterY() );
169 if ( outputFormat !=
UNKN )
171 response.
setHeader(
"Content-Type", contentType );
172 if ( saveFormat == QLatin1String(
"JPEG" ) || saveFormat == QLatin1String(
"WEBP" ) )
174 result.save( response.
io(), qPrintable( saveFormat ), imageQuality );
178 result.save( response.
io(), qPrintable( saveFormat ) );
184 parameter.
mValue = formatStr;
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,...
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.
Exception thrown in case of malformed request.
WMS parameter received from the client.
SERVER_EXPORT QString wmsServiceUrl(const QgsProject &project)
Returns the WMS service url defined in a QGIS project.
Median cut implementation.
void writeImage(QgsServerResponse &response, QImage &img, const QString &formatStr, int imageQuality)
Write image response.
QUrl serviceUrl(const QgsServerRequest &request, const QgsProject *project)
Returns WMS service URL.
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.