Skip to content
Permalink
Browse files

Set raster no data color back to 0,0,0,0 and overwrite that in raster…

… drawer only for PDF output. Fixes #9101 and #9343
  • Loading branch information
blazek committed Jan 15, 2014
1 parent e721e7f commit 00efc467844fc710e12a4ab7a64b3fc76b133ad2
@@ -23,7 +23,8 @@
#include "qgslogger.h"
#include "qgsrasterblock.h"

const QRgb QgsRasterBlock::mNoDataColor = qRgba( 255, 255, 255, 0 );
// See #9101 before any change of NODATA_COLOR!
const QRgb QgsRasterBlock::mNoDataColor = qRgba( 0, 0, 0, 0 );

QgsRasterBlock::QgsRasterBlock()
: mValid( true )
@@ -301,7 +302,7 @@ QRgb QgsRasterBlock::color( qgssize index ) const

QRgb QgsRasterBlock::color( int row, int column ) const
{
if ( !mImage ) return qRgba( 255, 255, 255, 0 );
if ( !mImage ) return mNoDataColor;

return mImage->pixel( column, row );
}
@@ -597,7 +598,7 @@ bool QgsRasterBlock::setIsNoDataExcept( const QRect & theExceptRect )
return false;
}

QRgb nodataRgba = qRgba( 0, 0, 0, 0 );
QRgb nodataRgba = mNoDataColor;
QRgb *nodataRow = new QRgb[mWidth]; // full row of no data
int rgbSize = sizeof( QRgb );
for ( int c = 0; c < mWidth; c ++ )
@@ -22,6 +22,7 @@
#include "qgsmaptopixel.h"
#include <QImage>
#include <QPainter>
#include <QPrinter>

QgsRasterDrawer::QgsRasterDrawer( QgsRasterIterator* iterator ): mIterator( iterator )
{
@@ -66,6 +67,28 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM

QImage img = block->image();

// Because of bug in Acrobat Reader we must use "white" transparent color instead
// of "black" for PDF. See #9101.
QPrinter *printer = dynamic_cast<QPrinter *>( p->device() );
if ( printer && printer->outputFormat() == QPrinter::PdfFormat )
{
QgsDebugMsg( "PdfFormat" );

img = img.convertToFormat( QImage::Format_ARGB32 );
QRgb transparentBlack = qRgba( 0, 0, 0, 0 );
QRgb transparentWhite = qRgba( 255, 255, 255, 0 );
for ( int x = 0; x < img.width(); x++ )
{
for ( int y = 0; y < img.height(); y++ )
{
if ( img.pixel( x, y ) == transparentBlack )
{
img.setPixel( x, y, transparentWhite );
}
}
}
}

drawImage( p, viewPort, img, topLeftCol, topLeftRow );

delete block;
@@ -26,10 +26,8 @@

#define tr( sourceText ) QCoreApplication::translate ( "QgsRasterRenderer", sourceText )

// Changing RGB components of NODATA_COLOR may break tests
// (changed 2013-11-30 from 0,0,0,0 to 255,255,255,0)
// kepp NODATA_COLOR white, see #9101
const QRgb QgsRasterRenderer::NODATA_COLOR = qRgba( 255, 255, 255, 0 );
// See #9101 before any change of NODATA_COLOR!
const QRgb QgsRasterRenderer::NODATA_COLOR = qRgba( 0, 0, 0, 0 );

QgsRasterRenderer::QgsRasterRenderer( QgsRasterInterface* input, const QString& type )
: QgsRasterInterface( input )

0 comments on commit 00efc46

Please sign in to comment.
You can’t perform that action at this time.