Skip to content

Commit 3a2c0e9

Browse files
committedMar 4, 2012
[FEATURE]: support PNG 8Bit for GetMap in QGIS server
1 parent e7ef6e4 commit 3a2c0e9

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed
 

‎src/mapserver/qgshttprequesthandler.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
9797
QgsDebugMsg( "Sending getmap response..." );
9898
if ( img )
9999
{
100-
if ( mFormat != "PNG" && mFormat != "JPG" )
100+
bool png8Bit = ( mFormat.compare( "image/png; mode=8bit", Qt::CaseInsensitive ) == 0 );
101+
if ( mFormat != "PNG" && mFormat != "JPG" && !png8Bit )
101102
{
102103
QgsDebugMsg( "service exception - incorrect image format requested..." );
103104
sendServiceException( QgsMapServiceException( "InvalidFormat", "Output format '" + mFormat + "' is not supported in the GetMap request" ) );
@@ -108,7 +109,17 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
108109
QByteArray ba;
109110
QBuffer buffer( &ba );
110111
buffer.open( QIODevice::WriteOnly );
111-
img->save( &buffer, mFormat.toLocal8Bit().data(), -1 );
112+
113+
if ( png8Bit )
114+
{
115+
QImage palettedImg = img->convertToFormat( QImage::Format_Indexed8, Qt::ColorOnly | Qt::ThresholdDither |
116+
Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
117+
palettedImg.save( &buffer, "PNG", -1 );
118+
}
119+
else
120+
{
121+
img->save( &buffer, mFormat.toLocal8Bit().data(), -1 );
122+
}
112123

113124
sendHttpResponse( &ba, formatToMimeType( mFormat ) );
114125
}

‎src/mapserver/qgswmsserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ QDomDocument QgsWMSServer::getCapabilities( QString version )
217217

218218
//wms:GetMap
219219
elem = doc.createElement( "GetMap"/*wms:GetMap*/ );
220-
appendFormats( doc, elem, QStringList() << "image/jpeg" << "image/png" );
220+
appendFormats( doc, elem, QStringList() << "image/jpeg" << "image/png" << "image/png; mode=8bit" );
221221
elem.appendChild( dcpTypeElement.cloneNode().toElement() ); //this is the same as for 'GetCapabilities'
222222
requestElement.appendChild( elem );
223223

0 commit comments

Comments
 (0)
Please sign in to comment.