Skip to content

Commit c036e7e

Browse files
committed
Merge pull request #428 from schmandr/master
Add support for 1bit PNG format to QGIS Server WMS
2 parents c1527af + 2e84efa commit c036e7e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/mapserver/qgshttprequesthandler.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
9797
if ( img )
9898
{
9999
bool png8Bit = ( mFormat.compare( "image/png; mode=8bit", Qt::CaseInsensitive ) == 0 );
100-
if ( mFormat != "PNG" && mFormat != "JPG" && !png8Bit )
100+
bool png1Bit = ( mFormat.compare( "image/png; mode=1bit", Qt::CaseInsensitive ) == 0 );
101+
if ( mFormat != "PNG" && mFormat != "JPG" && !png8Bit && !png1Bit )
101102
{
102103
QgsDebugMsg( "service exception - incorrect image format requested..." );
103104
sendServiceException( QgsMapServiceException( "InvalidFormat", "Output format '" + mFormat + "' is not supported in the GetMap request" ) );
@@ -117,6 +118,12 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
117118
Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
118119
palettedImg.save( &buffer, "PNG", -1 );
119120
}
121+
else if ( png1Bit )
122+
{
123+
QImage palettedImg = img->convertToFormat( QImage::Format_Mono, Qt::MonoOnly | Qt::ThresholdDither |
124+
Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
125+
palettedImg.save( &buffer, "PNG", -1 );
126+
}
120127
else
121128
{
122129
img->save( &buffer, mFormat.toLocal8Bit().data(), -1 );

src/mapserver/qgswmsserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ QDomDocument QgsWMSServer::getCapabilities( QString version, bool fullProjectInf
172172

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

0 commit comments

Comments
 (0)