Skip to content

Commit

Permalink
Set raster no data color back to 0,0,0,0 and overwrite that in raster…
Browse files Browse the repository at this point in the history
… drawer only for PDF output. Fixes #9101 and #9343
  • Loading branch information
blazek committed Jan 15, 2014
1 parent e721e7f commit 00efc46
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/core/raster/qgsrasterblock.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 ++ )
Expand Down
23 changes: 23 additions & 0 deletions src/core/raster/qgsrasterdrawer.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgsmaptopixel.h"
#include <QImage>
#include <QPainter>
#include <QPrinter>

QgsRasterDrawer::QgsRasterDrawer( QgsRasterIterator* iterator ): mIterator( iterator )
{
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/core/raster/qgsrasterrenderer.cpp
Expand Up @@ -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 )
Expand Down

0 comments on commit 00efc46

Please sign in to comment.