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";
155 contentType = QStringLiteral(
"image/webp" );
156 saveFormat = QStringLiteral(
"WEBP" );
165 result.setDotsPerMeterX( img.dotsPerMeterX() );
166 result.setDotsPerMeterY( img.dotsPerMeterY() );
168 if ( outputFormat !=
UNKN )
170 response.
setHeader(
"Content-Type", contentType );
171 if ( saveFormat == QLatin1String(
"JPEG" ) || saveFormat == QLatin1String(
"WEBP" ) )
173 result.save( response.
io(), qPrintable( saveFormat ), imageQuality );
177 result.save( response.
io(), qPrintable( saveFormat ) );
183 parameter.mValue = formatStr;