Skip to content
Permalink
Browse files
[FEATURE]: support PNG 8Bit for GetMap in QGIS server
  • Loading branch information
mhugent committed Mar 4, 2012
1 parent e7ef6e4 commit 3a2c0e9872270fbd62d6bfcd9149d9d2a16c09cf
Showing with 14 additions and 3 deletions.
  1. +13 −2 src/mapserver/qgshttprequesthandler.cpp
  2. +1 −1 src/mapserver/qgswmsserver.cpp
@@ -97,7 +97,8 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
QgsDebugMsg( "Sending getmap response..." );
if ( img )
{
if ( mFormat != "PNG" && mFormat != "JPG" )
bool png8Bit = ( mFormat.compare( "image/png; mode=8bit", Qt::CaseInsensitive ) == 0 );
if ( mFormat != "PNG" && mFormat != "JPG" && !png8Bit )
{
QgsDebugMsg( "service exception - incorrect image format requested..." );
sendServiceException( QgsMapServiceException( "InvalidFormat", "Output format '" + mFormat + "' is not supported in the GetMap request" ) );
@@ -108,7 +109,17 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
QByteArray ba;
QBuffer buffer( &ba );
buffer.open( QIODevice::WriteOnly );
img->save( &buffer, mFormat.toLocal8Bit().data(), -1 );

if ( png8Bit )
{
QImage palettedImg = img->convertToFormat( QImage::Format_Indexed8, Qt::ColorOnly | Qt::ThresholdDither |
Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
palettedImg.save( &buffer, "PNG", -1 );
}
else
{
img->save( &buffer, mFormat.toLocal8Bit().data(), -1 );
}

sendHttpResponse( &ba, formatToMimeType( mFormat ) );
}
@@ -217,7 +217,7 @@ QDomDocument QgsWMSServer::getCapabilities( QString version )

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

0 comments on commit 3a2c0e9

Please sign in to comment.