30#include <QRegularExpression>
33using namespace Qt::StringLiterals;
50 static const QSet<QString> sFilter {
63 const QList<QPair<QString, QString>> queryItems = q.queryItems();
64 for (
const QPair<QString, QString> ¶m : queryItems )
66 if ( sFilter.contains( param.first.toUpper() ) )
67 q.removeAllQueryItems( param.first );
79 if ( format.compare(
"png"_L1, Qt::CaseInsensitive ) == 0 || format.compare(
"image/png"_L1, Qt::CaseInsensitive ) == 0 )
83 else if ( format.compare(
"jpg "_L1, Qt::CaseInsensitive ) == 0 || format.compare(
"image/jpeg"_L1, Qt::CaseInsensitive ) == 0 )
87 else if ( format.compare(
"webp"_L1, Qt::CaseInsensitive ) == 0 || format.compare(
"image/webp"_L1, Qt::CaseInsensitive ) == 0 )
94 const thread_local QRegularExpression modeExpr = QRegularExpression( u
"image/png\\s*;\\s*mode=([^;]+)"_s, QRegularExpression::CaseInsensitiveOption );
96 const QRegularExpressionMatch match = modeExpr.match( format );
97 const QString mode = match.captured( 1 );
98 if ( mode.compare(
"16bit"_L1, Qt::CaseInsensitive ) == 0 )
100 if ( mode.compare(
"8bit"_L1, Qt::CaseInsensitive ) == 0 )
102 if ( mode.compare(
"1bit"_L1, Qt::CaseInsensitive ) == 0 )
116 switch ( outputFormat )
120 contentType = u
"image/png"_s;
121 saveFormat = u
"PNG"_s;
125 QVector<QRgb> colorTable;
130 const QImage img256 = img.convertToFormat( QImage::Format_ARGB32 );
132 result = img256.convertToFormat( QImage::Format_Indexed8, colorTable, Qt::ColorOnly | Qt::ThresholdDither | Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
134 contentType = u
"image/png"_s;
135 saveFormat = u
"PNG"_s;
138 result = img.convertToFormat( QImage::Format_ARGB4444_Premultiplied );
139 contentType = u
"image/png"_s;
140 saveFormat = u
"PNG"_s;
143 result = img.convertToFormat( QImage::Format_Mono, Qt::MonoOnly | Qt::ThresholdDither | Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
144 contentType = u
"image/png"_s;
145 saveFormat = u
"PNG"_s;
149 contentType = u
"image/jpeg"_s;
150 saveFormat = u
"JPEG"_s;
154 contentType = u
"image/webp"_s;
155 saveFormat = u
"WEBP"_s;
159 saveFormat = u
"Unknown"_s;
164 result.setDotsPerMeterX( img.dotsPerMeterX() );
165 result.setDotsPerMeterY( img.dotsPerMeterY() );
169 response.
setHeader(
"Content-Type", contentType );
170 if ( saveFormat ==
"JPEG"_L1 || saveFormat ==
"WEBP"_L1 )
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, 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.