@@ -1555,12 +1555,13 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
15551555 int newTransparency;
15561556 for ( int myHeightRunner = 0 ; myHeightRunner < myHeight; myHeightRunner++ )
15571557 {
1558+ QRgb* myLineBuffer = ( QRgb* ) transparentImageCopy->scanLine ( myHeightRunner );
15581559 for ( int myWidthRunner = 0 ; myWidthRunner < myWidth; myWidthRunner++ )
15591560 {
15601561 myRgb = image->pixel ( myWidthRunner, myHeightRunner );
15611562 // combine transparency from WMS and layer transparency
15621563 newTransparency = ( double ) mTransparencyLevel / 255.0 * ( double )( qAlpha ( myRgb ) );
1563- image-> setPixel ( myWidthRunner, myHeightRunner, qRgba ( qRed ( myRgb ), qGreen ( myRgb ), qBlue ( myRgb ), newTransparency ) );
1564+ myLineBuffer[ myWidthRunner ] = qRgba ( qRed ( myRgb ), qGreen ( myRgb ), qBlue ( myRgb ), newTransparency );
15641565 }
15651566 }
15661567 }
@@ -2864,13 +2865,13 @@ QPixmap QgsRasterLayer::paletteAsPixmap( int theBandNumber )
28642865 double myValue = 0.0 ;
28652866 for ( int myRow = 0 ; myRow < mySize; myRow++ )
28662867 {
2868+ QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine ( myRow );
28672869 for ( int myCol = 0 ; myCol < mySize; myCol++ )
28682870 {
2869-
28702871 myValue = myStep * ( double )( myCol + myRow * mySize );
28712872 int c1, c2, c3;
28722873 myShader.shade ( myValue, &c1, &c2, &c3 );
2873- myQImage. setPixel ( myCol, myRow, qRgb ( c1, c2, c3 ) );
2874+ myLineBuffer[ myCol ] = qRgb ( c1, c2, c3 );
28742875 }
28752876 }
28762877
@@ -4261,7 +4262,7 @@ void QgsRasterLayer::drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPo
42614262 }
42624263
42634264 QImage myQImage = QImage ( theRasterViewPort->drawableAreaXDim , theRasterViewPort->drawableAreaYDim , QImage::Format_ARGB32 );
4264- myQImage. fill ( qRgba ( 255 , 255 , 255 , 0 ) ); // fill transparent
4265+ QRgb myDefaultColor = qRgba ( 255 , 255 , 255 , 0 );
42654266
42664267 QgsRasterBandStats myRedBandStats;
42674268 QgsRasterBandStats myGreenBandStats;
@@ -4318,30 +4319,34 @@ void QgsRasterLayer::drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPo
43184319 QgsContrastEnhancement* myBlueContrastEnhancement = contrastEnhancement ( myBlueBandNo );
43194320
43204321 QgsDebugMsg ( " Starting main render loop" );
4321- for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaYDim ; ++myColumn )
4322+ for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaYDim ; ++myRow )
43224323 {
4323- for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaXDim ; ++myRow )
4324+ QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine ( myRow );
4325+ for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaXDim ; ++myColumn )
43244326 {
43254327 myRedValue = readValue ( myGdalRedData, ( GDALDataType )myRedType,
4326- myColumn * theRasterViewPort->drawableAreaXDim + myRow );
4328+ myRow * theRasterViewPort->drawableAreaXDim + myColumn );
43274329 myGreenValue = readValue ( myGdalGreenData, ( GDALDataType )myGreenType,
4328- myColumn * theRasterViewPort->drawableAreaXDim + myRow );
4330+ myRow * theRasterViewPort->drawableAreaXDim + myColumn );
43294331 myBlueValue = readValue ( myGdalBlueData, ( GDALDataType )myBlueType,
4330- myColumn * theRasterViewPort->drawableAreaXDim + myRow );
4332+ myRow * theRasterViewPort->drawableAreaXDim + myColumn );
43314333
43324334 if ( mValidNoDataValue && (( myRedValue == mNoDataValue || myRedValue != myRedValue ) || ( myGreenValue == mNoDataValue || myGreenValue != myGreenValue ) || ( myBlueValue == mNoDataValue || myBlueValue != myBlueValue ) ) )
43334335 {
4336+ myLineBuffer[ myColumn ] = myDefaultColor;
43344337 continue ;
43354338 }
43364339
43374340 if ( !myRedContrastEnhancement->isValueInDisplayableRange ( myRedValue ) || !myGreenContrastEnhancement->isValueInDisplayableRange ( myGreenValue ) || !myBlueContrastEnhancement->isValueInDisplayableRange ( myBlueValue ) )
43384341 {
4342+ myLineBuffer[ myColumn ] = myDefaultColor;
43394343 continue ;
43404344 }
43414345
43424346 myAlphaValue = mRasterTransparency .alphaValue ( myRedValue, myGreenValue, myBlueValue, mTransparencyLevel );
43434347 if ( 0 == myAlphaValue )
43444348 {
4349+ myLineBuffer[ myColumn ] = myDefaultColor;
43454350 continue ;
43464351 }
43474352
@@ -4356,7 +4361,7 @@ void QgsRasterLayer::drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPo
43564361 myStretchedBlueValue = 255 - myStretchedBlueValue;
43574362 }
43584363
4359- myQImage. setPixel ( myRow, myColumn, qRgba ( myStretchedRedValue, myStretchedGreenValue, myStretchedBlueValue, myAlphaValue ) );
4364+ myLineBuffer[ myColumn ] = qRgba ( myStretchedRedValue, myStretchedGreenValue, myStretchedBlueValue, myAlphaValue );
43604365 }
43614366 }
43624367 // free the scanline memory
@@ -4432,7 +4437,7 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
44324437 }
44334438
44344439 QImage myQImage = QImage ( theRasterViewPort->drawableAreaXDim , theRasterViewPort->drawableAreaYDim , QImage::Format_ARGB32 );
4435- myQImage. fill ( qRgba ( 255 , 255 , 255 , 0 ) ); // fill transparent
4440+ QRgb myDefaultColor = qRgba ( 255 , 255 , 255 , 0 );
44364441
44374442 double myPixelValue = 0.0 ;
44384443 int myRedValue = 0 ;
@@ -4441,41 +4446,45 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
44414446 int myAlphaValue = 0 ;
44424447
44434448 QgsDebugMsg ( " Starting main render loop" );
4444- for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaYDim ; ++myColumn )
4449+ for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaYDim ; ++myRow )
44454450 {
4446- for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaXDim ; ++myRow )
4451+ QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine ( myRow );
4452+ for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaXDim ; ++myColumn )
44474453 {
44484454 myRedValue = 0 ;
44494455 myGreenValue = 0 ;
44504456 myBlueValue = 0 ;
44514457 myPixelValue = readValue ( myGdalScanData, ( GDALDataType )myDataType,
4452- myColumn * theRasterViewPort->drawableAreaXDim + myRow );
4458+ myRow * theRasterViewPort->drawableAreaXDim + myColumn );
44534459
44544460 if ( mValidNoDataValue && ( myPixelValue == mNoDataValue || myPixelValue != myPixelValue ) )
44554461 {
4462+ myLineBuffer[ myColumn ] = myDefaultColor;
44564463 continue ;
44574464 }
44584465
44594466 myAlphaValue = mRasterTransparency .alphaValue ( myPixelValue, mTransparencyLevel );
44604467 if ( 0 == myAlphaValue )
44614468 {
4469+ myLineBuffer[ myColumn ] = myDefaultColor;
44624470 continue ;
44634471 }
44644472
44654473 if ( !mRasterShader ->shade ( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
44664474 {
4475+ myLineBuffer[ myColumn ] = myDefaultColor;
44674476 continue ;
44684477 }
44694478
44704479 if ( mInvertColor )
44714480 {
44724481 // Invert flag, flip blue and read
4473- myQImage. setPixel ( myRow, myColumn, qRgba ( myBlueValue, myGreenValue, myRedValue, myAlphaValue ) );
4482+ myLineBuffer[ myColumn ] = qRgba ( myBlueValue, myGreenValue, myRedValue, myAlphaValue );
44744483 }
44754484 else
44764485 {
44774486 // Normal
4478- myQImage. setPixel ( myRow, myColumn, qRgba ( myRedValue, myGreenValue, myBlueValue, myAlphaValue ) );
4487+ myLineBuffer[ myColumn ] = qRgba ( myRedValue, myGreenValue, myBlueValue, myAlphaValue );
44794488 }
44804489 }
44814490 }
@@ -4516,7 +4525,7 @@ void QgsRasterLayer::drawPalettedSingleBandGray( QPainter * theQPainter, QgsRast
45164525 }
45174526
45184527 QImage myQImage = QImage ( theRasterViewPort->drawableAreaXDim , theRasterViewPort->drawableAreaYDim , QImage::Format_ARGB32 );
4519- myQImage. fill ( qRgba ( 255 , 255 , 255 , 0 ) ); // fill transparent
4528+ QRgb myDefaultColor = qRgba ( 255 , 255 , 255 , 0 );
45204529
45214530 double myPixelValue = 0.0 ;
45224531 int myRedValue = 0 ;
@@ -4525,43 +4534,47 @@ void QgsRasterLayer::drawPalettedSingleBandGray( QPainter * theQPainter, QgsRast
45254534 int myAlphaValue = 0 ;
45264535
45274536 QgsDebugMsg ( " Starting main render loop" );
4528- for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaYDim ; ++myColumn )
4537+ for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaYDim ; ++myRow )
45294538 {
4530- for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaXDim ; ++myRow )
4539+ QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine ( myRow );
4540+ for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaXDim ; ++myColumn )
45314541 {
45324542 myRedValue = 0 ;
45334543 myGreenValue = 0 ;
45344544 myBlueValue = 0 ;
45354545 myPixelValue = readValue ( myGdalScanData, ( GDALDataType )myDataType,
4536- myColumn * theRasterViewPort->drawableAreaXDim + myRow );
4546+ myRow * theRasterViewPort->drawableAreaXDim + myColumn );
45374547
45384548 if ( mValidNoDataValue && ( myPixelValue == mNoDataValue || myPixelValue != myPixelValue ) )
45394549 {
4550+ myLineBuffer[ myColumn ] = myDefaultColor;
45404551 continue ;
45414552 }
45424553
45434554 myAlphaValue = mRasterTransparency .alphaValue ( myPixelValue, mTransparencyLevel );
45444555 if ( 0 == myAlphaValue )
45454556 {
4557+ myLineBuffer[ myColumn ] = myDefaultColor;
45464558 continue ;
45474559 }
45484560
45494561 if ( !mRasterShader ->shade ( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
45504562 {
4563+ myLineBuffer[ myColumn ] = myDefaultColor;
45514564 continue ;
45524565 }
45534566
45544567 if ( mInvertColor )
45554568 {
45564569 // Invert flag, flip blue and read
45574570 double myGrayValue = ( 0.3 * ( double )myRedValue ) + ( 0.59 * ( double )myGreenValue ) + ( 0.11 * ( double )myBlueValue );
4558- myQImage. setPixel ( myRow, myColumn, qRgba (( int )myGrayValue, ( int )myGrayValue, ( int )myGrayValue, myAlphaValue ) );
4571+ myLineBuffer[ myColumn ] = qRgba (( int )myGrayValue, ( int )myGrayValue, ( int )myGrayValue, myAlphaValue );
45594572 }
45604573 else
45614574 {
45624575 // Normal
45634576 double myGrayValue = ( 0.3 * ( double )myBlueValue ) + ( 0.59 * ( double )myGreenValue ) + ( 0.11 * ( double )myRedValue );
4564- myQImage. setPixel ( myRow, myColumn, qRgba (( int )myGrayValue, ( int )myGrayValue, ( int )myGrayValue, myAlphaValue ) );
4577+ myLineBuffer[ myColumn ] = qRgba (( int )myGrayValue, ( int )myGrayValue, ( int )myGrayValue, myAlphaValue );
45654578 }
45664579 }
45674580 }
@@ -4600,7 +4613,7 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
46004613 }
46014614
46024615 QImage myQImage = QImage ( theRasterViewPort->drawableAreaXDim , theRasterViewPort->drawableAreaYDim , QImage::Format_ARGB32 );
4603- myQImage. fill ( qRgba ( 255 , 255 , 255 , 0 ) ); // fill transparent
4616+ QRgb myDefaultColor = qRgba ( 255 , 255 , 255 , 0 );
46044617
46054618 if ( NULL == mRasterShader )
46064619 {
@@ -4631,41 +4644,45 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
46314644 int myAlphaValue = 0 ;
46324645
46334646 QgsDebugMsg ( " Starting main render loop" );
4634- for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaYDim ; ++myColumn )
4647+ for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaYDim ; ++myRow )
46354648 {
4636- for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaXDim ; ++myRow )
4649+ QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine ( myRow );
4650+ for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaXDim ; ++myColumn )
46374651 {
46384652 myRedValue = 0 ;
46394653 myGreenValue = 0 ;
46404654 myBlueValue = 0 ;
46414655 myPixelValue = readValue ( myGdalScanData, ( GDALDataType )myDataType,
4642- myColumn * theRasterViewPort->drawableAreaXDim + myRow );
4656+ myRow * theRasterViewPort->drawableAreaXDim + myColumn );
46434657
46444658 if ( mValidNoDataValue && ( myPixelValue == mNoDataValue || myPixelValue != myPixelValue ) )
46454659 {
4660+ myLineBuffer[ myColumn ] = myDefaultColor;
46464661 continue ;
46474662 }
46484663
46494664 myAlphaValue = mRasterTransparency .alphaValue ( myPixelValue, mTransparencyLevel );
46504665 if ( 0 == myAlphaValue )
46514666 {
4667+ myLineBuffer[ myColumn ] = myDefaultColor;
46524668 continue ;
46534669 }
46544670
46554671 if ( !mRasterShader ->shade ( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
46564672 {
4673+ myLineBuffer[ myColumn ] = myDefaultColor;
46574674 continue ;
46584675 }
46594676
46604677 if ( mInvertColor )
46614678 {
46624679 // Invert flag, flip blue and read
4663- myQImage. setPixel ( myRow, myColumn, qRgba ( myBlueValue, myGreenValue, myRedValue, myAlphaValue ) );
4680+ myLineBuffer[ myColumn ] = qRgba ( myBlueValue, myGreenValue, myRedValue, myAlphaValue );
46644681 }
46654682 else
46664683 {
46674684 // Normal
4668- myQImage. setPixel ( myRow, myColumn, qRgba ( myRedValue, myGreenValue, myBlueValue, myAlphaValue ) );
4685+ myLineBuffer[ myColumn ] = qRgba ( myRedValue, myGreenValue, myBlueValue, myAlphaValue );
46694686 }
46704687 }
46714688 }
@@ -4706,7 +4723,7 @@ void QgsRasterLayer::drawSingleBandGray( QPainter * theQPainter, QgsRasterViewPo
47064723 }
47074724
47084725 QImage myQImage = QImage ( theRasterViewPort->drawableAreaXDim , theRasterViewPort->drawableAreaYDim , QImage::Format_ARGB32 );
4709- myQImage. fill ( qRgba ( 255 , 255 , 255 , 0 ) ); // fill transparent
4726+ QRgb myDefaultColor = qRgba ( 255 , 255 , 255 , 0 );
47104727
47114728 QgsRasterBandStats myGrayBandStats;
47124729
@@ -4735,30 +4752,34 @@ void QgsRasterLayer::drawSingleBandGray( QPainter * theQPainter, QgsRasterViewPo
47354752 int myGrayVal = 0 ;
47364753 int myAlphaValue = 0 ;
47374754 QgsContrastEnhancement* myContrastEnhancement = contrastEnhancement ( theBandNo );
4738- for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaYDim ; ++myColumn )
4755+ for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaYDim ; ++myRow )
47394756 {
4740- for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaXDim ; ++myRow )
4757+ QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine ( myRow );
4758+ for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaXDim ; ++myColumn )
47414759 {
47424760 myGrayValue = readValue ( myGdalScanData, myDataType,
4743- myColumn * theRasterViewPort->drawableAreaXDim + myRow );
4761+ myRow * theRasterViewPort->drawableAreaXDim + myColumn );
47444762
47454763 // If mNoDataValue is 'nan', the comparison
47464764 // against myGrayVal will always fail ( nan==nan always
47474765 // returns false, by design), hence the slightly odd comparison
47484766 // of myGrayVal against itself.
47494767 if ( mValidNoDataValue && ( myGrayValue == mNoDataValue || myGrayValue != myGrayValue ) )
47504768 {
4769+ myLineBuffer[ myColumn ] = myDefaultColor;
47514770 continue ;
47524771 }
47534772
47544773 if ( !myContrastEnhancement->isValueInDisplayableRange ( myGrayValue ) )
47554774 {
4775+ myLineBuffer[ myColumn ] = myDefaultColor;
47564776 continue ;
47574777 }
47584778
47594779 myAlphaValue = mRasterTransparency .alphaValue ( myGrayValue, mTransparencyLevel );
47604780 if ( 0 == myAlphaValue )
47614781 {
4782+ myLineBuffer[ myColumn ] = myDefaultColor;
47624783 continue ;
47634784 }
47644785
@@ -4770,8 +4791,7 @@ void QgsRasterLayer::drawSingleBandGray( QPainter * theQPainter, QgsRasterViewPo
47704791 myGrayVal = 255 - myGrayVal;
47714792 }
47724793
4773- myQImage.setPixel ( myRow, myColumn, qRgba ( myGrayVal, myGrayVal, myGrayVal, myAlphaValue ) );
4774-
4794+ myLineBuffer[ myColumn ] = qRgba ( myGrayVal, myGrayVal, myGrayVal, myAlphaValue );
47754795 }
47764796 }
47774797
@@ -4807,7 +4827,7 @@ void QgsRasterLayer::drawSingleBandPseudoColor( QPainter * theQPainter,
48074827 }
48084828
48094829 QImage myQImage = QImage ( theRasterViewPort->drawableAreaXDim , theRasterViewPort->drawableAreaYDim , QImage::Format_ARGB32 );
4810- myQImage. fill ( qRgba ( 255 , 255 , 255 , 0 ) ); // fill transparent
4830+ QRgb myDefaultColor = qRgba ( 255 , 255 , 255 , 0 );
48114831
48124832 if ( NULL == mRasterShader )
48134833 {
@@ -4839,38 +4859,42 @@ void QgsRasterLayer::drawSingleBandPseudoColor( QPainter * theQPainter,
48394859 double myPixelValue = 0.0 ;
48404860 int myAlphaValue = 0 ;
48414861 QgsDebugMsg ( " Starting main render loop" );
4842- for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaYDim ; ++myColumn )
4862+ for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaYDim ; ++myRow )
48434863 {
4844- for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaXDim ; ++myRow )
4864+ QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine ( myRow );
4865+ for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaXDim ; ++myColumn )
48454866 {
48464867 myPixelValue = readValue ( myGdalScanData, myDataType,
4847- myColumn * theRasterViewPort->drawableAreaXDim + myRow );
4868+ myRow * theRasterViewPort->drawableAreaXDim + myColumn );
48484869
48494870 if ( mValidNoDataValue && ( myPixelValue == mNoDataValue || myPixelValue != myPixelValue ) )
48504871 {
4872+ myLineBuffer[ myColumn ] = myDefaultColor;
48514873 continue ;
48524874 }
48534875
48544876 myAlphaValue = mRasterTransparency .alphaValue ( myPixelValue, mTransparencyLevel );
48554877 if ( 0 == myAlphaValue )
48564878 {
4879+ myLineBuffer[ myColumn ] = myDefaultColor;
48574880 continue ;
48584881 }
48594882
48604883 if ( !mRasterShader ->shade ( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
48614884 {
4885+ myLineBuffer[ myColumn ] = myDefaultColor;
48624886 continue ;
48634887 }
48644888
48654889 if ( mInvertColor )
48664890 {
48674891 // Invert flag, flip blue and read
4868- myQImage. setPixel ( myRow, myColumn, qRgba ( myBlueValue, myGreenValue, myRedValue, myAlphaValue ) );
4892+ myLineBuffer[ myColumn ] = qRgba ( myBlueValue, myGreenValue, myRedValue, myAlphaValue );
48694893 }
48704894 else
48714895 {
48724896 // Normal
4873- myQImage. setPixel ( myRow, myColumn, qRgba ( myRedValue, myGreenValue, myBlueValue, myAlphaValue ) );
4897+ myLineBuffer[ myColumn ] = qRgba ( myRedValue, myGreenValue, myBlueValue, myAlphaValue );
48744898 }
48754899 } // end of columnwise loop
48764900 } // end of rowwise loop
0 commit comments