[SCM] qgis branch, master, updated. a2ee769957385f4e084c5e8b6ba178a8c877d1db

Marco Hugentobler marco.hugentobler at sourcepole.ch
Tue Mar 20 13:42:47 UTC 2012


The following commit has been merged in the master branch:
commit 3a2c0e9872270fbd62d6bfcd9149d9d2a16c09cf
Author: Marco Hugentobler <marco.hugentobler at sourcepole.ch>
Date:   Sun Mar 4 22:17:20 2012 +0100

    [FEATURE]: support PNG 8Bit for GetMap in QGIS server

diff --git a/src/mapserver/qgshttprequesthandler.cpp b/src/mapserver/qgshttprequesthandler.cpp
index 4fd4777..caa9fe9 100644
--- a/src/mapserver/qgshttprequesthandler.cpp
+++ b/src/mapserver/qgshttprequesthandler.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 ) );
   }
diff --git a/src/mapserver/qgswmsserver.cpp b/src/mapserver/qgswmsserver.cpp
index 61ca3d7..637c02a 100644
--- a/src/mapserver/qgswmsserver.cpp
+++ b/src/mapserver/qgswmsserver.cpp
@@ -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 );
 

-- 
The Quantum GIS in Debian project



More information about the Pkg-grass-devel mailing list