void QgsHttpRequestHandler::setGetMapResponse( const QString& service, QImage* img, int imageQuality = -1 ) { Q_UNUSED( service ); QgsMessageLog::logMessage( "setting getmap response..." ); if ( img ) { bool png16Bit = ( mFormatString.compare( "image/png; mode=16bit", Qt::CaseInsensitive ) == 0 ); bool png8Bit = ( mFormatString.compare( "image/png; mode=8bit", Qt::CaseInsensitive ) == 0 ); bool png1Bit = ( mFormatString.compare( "image/png; mode=1bit", Qt::CaseInsensitive ) == 0 ); bool isBase64 = mFormatString.endsWith( ";base64", Qt::CaseInsensitive ); if ( mFormat != "PNG" && mFormat != "JPG" && !png16Bit && !png8Bit && !png1Bit ) { QgsMessageLog::logMessage( "service exception - incorrect image format requested..." ); setServiceException( QgsMapServiceException( "InvalidFormat", "Output format '" + mFormatString + "' is not supported in the GetMap request" ) ); return; } //store the image in a QByteArray and set it directly QByteArray ba; QBuffer buffer( &ba ); buffer.open( QIODevice::WriteOnly ); // Do not use imageQuality for PNG images // For now, QImage expects quality to be a range 0-9 for PNG if ( mFormat == "PNG" ) { imageQuality = -1; } if ( png8Bit ) { QVector<QRgb> colorTable; medianCut( colorTable, 256, *img ); QImage palettedImg = img->convertToFormat( QImage::Format_Indexed8, colorTable, Qt::ColorOnly | Qt::ThresholdDither | Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection ); palettedImg.save( &buffer, "PNG", imageQuality ); } else if ( png16Bit ) { QImage palettedImg = img->convertToFormat( QImage::Format_ARGB4444_Premultiplied ); palettedImg.save( &buffer, "PNG", imageQuality ); } else if ( png1Bit ) { QImage palettedImg = img->convertToFormat( QImage::Format_Mono, Qt::MonoOnly | Qt::ThresholdDither | Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection ); palettedImg.save( &buffer, "PNG", imageQuality ); } else { img->save( &buffer, mFormat.toUtf8().data(), imageQuality ); } if ( isBase64 ) { ba = ba.toBase64(); } setHttpResponse( &ba, formatToMimeType( mFormat ) ); } }
void QgsHttpRequestHandler::setGetPrintResponse( QByteArray* ba ) { if ( mFormatString.endsWith( ";base64", Qt::CaseInsensitive ) ) { *ba = ba->toBase64(); } setHttpResponse( ba, formatToMimeType( mFormat ) ); }
void QgsGetRequestHandler::sendGetMapResponse( const QString& service, QImage* img ) const { if ( img ) { if ( mFormat != "PNG" && mFormat != "JPG" ) { sendServiceException( QgsMapServiceException( "InvalidFormat", "Output format '" + mFormat + "' is not supported in the GetMap request" ) ); return; } //store the image in a QByteArray and send it directly QByteArray ba; QBuffer buffer( &ba ); buffer.open( QIODevice::WriteOnly ); img->save( &buffer, mFormat.toLocal8Bit().data(), -1 ); sendHttpResponse( &ba, formatToMimeType( mFormat ) ); } }
void QgsGetRequestHandler::sendGetPrintResponse( QByteArray* ba ) const { sendHttpResponse( ba, formatToMimeType( mFormat ) ); }