Skip to content

Commit 6d595a2

Browse files
author
ersts
committed
-updated rendering methods
-single band with color map now uses the previously unused method drawPalettedSingleBandColor git-svn-id: http://svn.osgeo.org/qgis/trunk@9203 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 96f2369 commit 6d595a2

File tree

3 files changed

+72
-134
lines changed

3 files changed

+72
-134
lines changed

src/app/qgsrasterlayerproperties.cpp

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,16 @@ void QgsRasterLayerProperties::sync()
480480
cboxContrastEnhancementAlgorithm->setEnabled( false );
481481
labelContrastEnhancement->setEnabled( false );
482482
break;
483+
case QgsRasterLayer::PALETTED_COLOR:
484+
rbtnThreeBand->setEnabled( false );
485+
rbtnSingleBand->setEnabled( true );
486+
rbtnSingleBand->setChecked( true );
487+
rbtnThreeBandMinMax->setEnabled( false );
488+
rbtnThreeBandStdDev->setEnabled( false );
489+
pbtnLoadMinMax->setEnabled( false );
490+
cboxContrastEnhancementAlgorithm->setEnabled( false );
491+
labelContrastEnhancement->setEnabled( false );
492+
break;
483493
case QgsRasterLayer::PALETTED_SINGLE_BAND_GRAY:
484494
rbtnThreeBand->setEnabled( true );
485495
rbtnSingleBand->setEnabled( true );
@@ -575,6 +585,7 @@ void QgsRasterLayerProperties::sync()
575585
//
576586
QgsDebugMsg( "colorShadingAlgorithm = " + QString::number( mRasterLayer->getColorShadingAlgorithm() ) );
577587
if ( mRasterLayer->getDrawingStyle() == QgsRasterLayer::SINGLE_BAND_PSEUDO_COLOR ||
588+
mRasterLayer->getDrawingStyle() == QgsRasterLayer::PALETTED_COLOR ||
578589
mRasterLayer->getDrawingStyle() == QgsRasterLayer::PALETTED_SINGLE_BAND_PSEUDO_COLOR ||
579590
mRasterLayer->getDrawingStyle() == QgsRasterLayer::MULTI_BAND_SINGLE_BAND_PSEUDO_COLOR )
580591
{
@@ -963,23 +974,29 @@ void QgsRasterLayerProperties::apply()
963974
//
964975
else if ( mRasterLayer->getRasterLayerType() == QgsRasterLayer::PALETTE )
965976
{
966-
if ( cboxColorMap->currentText() != tr( "Grayscale" ) )
977+
if ( cboxColorMap->currentText() == tr( "Grayscale" ) )
967978
{
968-
QgsDebugMsg( "Setting Raster Drawing Style to :: PALETTED_SINGLE_BAND_PSEUDO_COLOR" );
969-
970-
mRasterLayer->setDrawingStyle( QgsRasterLayer::PALETTED_SINGLE_BAND_PSEUDO_COLOR );
979+
QgsDebugMsg( "Setting Raster Drawing Style to :: PALETTED_SINGLE_BAND_GRAY" );
980+
QgsDebugMsg( QString( "Combo value : %1 GrayBand Mapping : %2" ).arg( cboGray->currentText() ).arg( mRasterLayer->
981+
getGrayBandName() ) );
982+
983+
mRasterLayer->setDrawingStyle( QgsRasterLayer::PALETTED_SINGLE_BAND_GRAY );
971984
}
972-
else
985+
else if ( cboxColorMap->currentText() == tr( "Colormap" ) )
973986
{
974-
QgsDebugMsg( "Setting Raster Drawing Style to :: PALETTED_SINGLE_BAND_GRAY" );
975-
#ifdef QGISDEBUG
976-
987+
QgsDebugMsg( "Setting Raster Drawing Style to :: PALETTED_COLOR" );
977988
QgsDebugMsg( QString( "Combo value : %1 GrayBand Mapping : %2" ).arg( cboGray->currentText() ).arg( mRasterLayer->
978989
getGrayBandName() ) );
979-
#endif
980990

981-
mRasterLayer->setDrawingStyle( QgsRasterLayer::PALETTED_SINGLE_BAND_GRAY );
991+
mRasterLayer->setDrawingStyle( QgsRasterLayer::PALETTED_COLOR );
992+
}
993+
else
994+
{
995+
QgsDebugMsg( "Setting Raster Drawing Style to :: PALETTED_SINGLE_BAND_PSEUDO_COLOR" );
996+
997+
mRasterLayer->setDrawingStyle( QgsRasterLayer::PALETTED_SINGLE_BAND_PSEUDO_COLOR );
982998
}
999+
9831000
}
9841001
//
9851002
// Mutltiband

src/core/raster/qgsrasterlayer.cpp

Lines changed: 42 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ bool QgsRasterLayer::readFile( QString const & fileName )
560560
mGrayBandName = getRasterBandName(1); //sensible default
561561
QgsDebugMsg(mGrayBandName);
562562

563-
drawingStyle = PALETTED_SINGLE_BAND_PSEUDO_COLOR; //sensible default
563+
drawingStyle = PALETTED_COLOR; //sensible default
564564

565565
//Load the color table from the band
566566
QList<QgsColorRampShader::ColorRampItem> myColorRampList;
@@ -784,6 +784,10 @@ void QgsRasterLayer::setDrawingStyle( QString const & theDrawingStyleQString )
784784
{
785785
drawingStyle = SINGLE_BAND_PSEUDO_COLOR;
786786
}
787+
else if ( theDrawingStyleQString == "PALETTED_COLOR" )//no need to tr() this its not shown in ui
788+
{
789+
drawingStyle = PALETTED_COLOR;
790+
}
787791
else if ( theDrawingStyleQString == "PALETTED_SINGLE_BAND_GRAY" )//no need to tr() this its not shown in ui
788792
{
789793
drawingStyle = PALETTED_SINGLE_BAND_GRAY;
@@ -1221,6 +1225,22 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
12211225
theQgsMapToPixel, getRasterBandNumber( mGrayBandName ) );
12221226
break;
12231227
}
1228+
// a single band with a color map
1229+
case PALETTED_COLOR:
1230+
//check the band is set!
1231+
if ( mGrayBandName == TRSTRING_NOT_SET )
1232+
{
1233+
break;
1234+
}
1235+
else
1236+
{
1237+
QgsDebugMsg( "PALETTED_COLOR drawing type detected..." );
1238+
1239+
drawPalettedSingleBandColor( theQPainter, theRasterViewPort,
1240+
theQgsMapToPixel, getRasterBandNumber(mGrayBandName ));
1241+
1242+
break;
1243+
}
12241244
// a "Palette" layer drawn in gray scale (using only one of the color components)
12251245
case PALETTED_SINGLE_BAND_GRAY:
12261246
//check the band is set!
@@ -1520,7 +1540,7 @@ void QgsRasterLayer::drawSingleBandPseudoColor( QPainter * theQPainter,
15201540
}
15211541

15221542
/**
1523-
* This method is used to render a paletted raster layer as a colour image.
1543+
* This method is used to render a single band with a color map.
15241544
* @param theQPainter - pointer to the QPainter onto which the layer should be drawn.
15251545
* @param theRasterViewPort - pointer to the ViewPort struct containing dimensions of viewable area and subset area to be extracted from data file.
15261546
* @param theGdalBand - pointer to the GDALRasterBand which should be rendered.
@@ -1535,6 +1555,11 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
15351555
return;
15361556
}
15371557

1558+
if ( NULL == mRasterShader )
1559+
{
1560+
return;
1561+
}
1562+
15381563
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
15391564
GDALDataType myDataType = GDALGetRasterDataType( myGdalBand );
15401565
void *myGdalScanData = readData( myGdalBand, theRasterViewPort );
@@ -1545,26 +1570,22 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
15451570
return;
15461571
}
15471572

1548-
QgsColorTable *myColorTable = colorTable( theBandNo );
1549-
15501573
QImage myQImage = QImage( theRasterViewPort->drawableAreaXDim, theRasterViewPort->drawableAreaYDim, QImage::Format_ARGB32 );
15511574
myQImage.fill( qRgba( 255, 255, 255, 0 ) ); // fill transparent
15521575

15531576
double myPixelValue = 0.0;
15541577
int myRedValue = 0;
15551578
int myGreenValue = 0;
15561579
int myBlueValue = 0;
1557-
bool found = false;
15581580
int myAlphaValue = 0;
1581+
15591582
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn )
15601583
{
15611584
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow )
15621585
{
1563-
//Reinitalize values;
15641586
myRedValue = 0;
15651587
myGreenValue = 0;
15661588
myBlueValue = 0;
1567-
found = false;
15681589
myPixelValue = readValue( myGdalScanData, ( GDALDataType )myDataType,
15691590
myColumn * theRasterViewPort->drawableAreaXDim + myRow );
15701591

@@ -1579,19 +1600,23 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
15791600
continue;
15801601
}
15811602

1582-
found = myColorTable->color( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue );
1583-
if ( !found ) continue;
1603+
if ( !mRasterShader->generateShadedValue( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
1604+
{
1605+
continue;
1606+
}
15841607

15851608
if ( mInvertPixelsFlag )
15861609
{
1587-
myRedValue = 255 - myRedValue;
1588-
myGreenValue = 255 - myGreenValue;
1589-
myBlueValue = 255 - myBlueValue;
1610+
//Invert flag, flip blue and read
1611+
myQImage.setPixel( myRow, myColumn, qRgba( myBlueValue, myGreenValue, myRedValue, myAlphaValue ) );
1612+
}
1613+
else
1614+
{
1615+
//Normal
1616+
myQImage.setPixel( myRow, myColumn, qRgba( myRedValue, myGreenValue, myBlueValue, myAlphaValue ) );
15901617
}
1591-
myQImage.setPixel( myRow, myColumn, qRgba( myRedValue, myGreenValue, myBlueValue, myAlphaValue ) );
15921618
}
15931619
}
1594-
15951620
CPLFree( myGdalScanData );
15961621

15971622
//render any inline filters
@@ -1717,12 +1742,7 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
17171742
return;
17181743
}
17191744

1720-
QgsRasterBandStats myRasterBandStats;
1721-
//If there is a color ramp, i.e., a paletted layer, then no need to generate stats
1722-
if(COLOR_RAMP != mColorShadingAlgorithm)
1723-
{
1724-
myRasterBandStats = getRasterBandStats( theBandNo );
1725-
}
1745+
QgsRasterBandStats myRasterBandStats = getRasterBandStats( theBandNo );
17261746
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
17271747
GDALDataType myDataType = GDALGetRasterDataType( myGdalBand );
17281748
void *myGdalScanData = readData( myGdalBand, theRasterViewPort );
@@ -1811,114 +1831,15 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
18111831
}
18121832

18131833
/**
1814-
* This method is used to render a paletted raster layer as a colour image.
1834+
* This method is used to render a paletted raster layer as a colour image -- currently not supported
18151835
* @param theQPainter - pointer to the QPainter onto which the layer should be drawn.
18161836
* @param theRasterViewPort - pointer to the ViewPort struct containing dimensions of viewable area and subset area to be extracted from data file.
18171837
* @param theGdalBand - pointer to the GDALRasterBand which should be rendered.
18181838
*/
18191839
void QgsRasterLayer::drawPalettedMultiBandColor( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,
18201840
const QgsMapToPixel* theQgsMapToPixel, int theBandNo )
18211841
{
1822-
QgsDebugMsg( "entered." );
1823-
//Invalid band number, segfault prevention
1824-
if ( 0 >= theBandNo )
1825-
{
1826-
return;
1827-
}
1828-
1829-
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
1830-
GDALDataType myDataType = GDALGetRasterDataType( myGdalBand );
1831-
void *myGdalScanData = readData( myGdalBand, theRasterViewPort );
1832-
1833-
/* Check for out of memory error */
1834-
if ( myGdalScanData == NULL )
1835-
{
1836-
return;
1837-
}
1838-
1839-
QgsColorTable *myColorTable = colorTable( theBandNo );
1840-
1841-
QImage myQImage = QImage( theRasterViewPort->drawableAreaXDim, theRasterViewPort->drawableAreaYDim, QImage::Format_ARGB32 );
1842-
myQImage.fill( qRgba( 255, 255, 255, 0 ) ); // fill transparent
1843-
1844-
double myPixelValue = 0.0;
1845-
int myRedLUTValue = 0;
1846-
int myGreenLUTValue = 0;
1847-
int myBlueLUTValue = 0;
1848-
1849-
int myRedValue = 0; //color 1 int
1850-
int myGreenValue = 0; //color 2 int
1851-
int myBlueValue = 0; //color 3 int
1852-
int myAlphaValue = 0;
1853-
for ( int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn )
1854-
{
1855-
for ( int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow )
1856-
{
1857-
myRedLUTValue = 0;
1858-
myGreenLUTValue = 0;
1859-
myBlueLUTValue = 0;
1860-
1861-
myRedValue = 0;
1862-
myGreenValue = 0;
1863-
myBlueValue = 0;
1864-
myPixelValue = readValue( myGdalScanData, ( GDALDataType )myDataType,
1865-
myColumn * theRasterViewPort->drawableAreaXDim + myRow );
1866-
1867-
if ( mValidNoDataValue && ( myPixelValue == mNoDataValue || myPixelValue != myPixelValue ) )
1868-
{
1869-
continue;
1870-
}
1871-
1872-
myAlphaValue = mRasterTransparency.getAlphaValue( myPixelValue, mTransparencyLevel );
1873-
if ( 0 == myAlphaValue )
1874-
{
1875-
continue;
1876-
}
1877-
1878-
bool found = myColorTable->color( myPixelValue, &myRedLUTValue, &myGreenLUTValue, &myBlueLUTValue );
1879-
if ( !found ) continue;
1880-
1881-
//check for alternate color mappings
1882-
if ( mRedBandName == "Red" )
1883-
myRedValue = myRedLUTValue;
1884-
else if ( mRedBandName == "Green" )
1885-
myRedValue = myGreenLUTValue;
1886-
else if ( mRedBandName == "Blue" )
1887-
myRedValue = myBlueLUTValue;
1888-
1889-
if ( mGreenBandName == "Red" )
1890-
myGreenValue = myRedLUTValue;
1891-
else if ( mGreenBandName == "Green" )
1892-
myGreenValue = myGreenLUTValue;
1893-
else if ( mGreenBandName == "Blue" )
1894-
1895-
myGreenValue = myBlueLUTValue;
1896-
1897-
if ( mBlueBandName == "Red" )
1898-
myBlueValue = myRedLUTValue;
1899-
else if ( mBlueBandName == "Green" )
1900-
myBlueValue = myGreenLUTValue;
1901-
else if ( mBlueBandName == "Blue" )
1902-
myBlueValue = myBlueLUTValue;
1903-
1904-
if ( mInvertPixelsFlag )
1905-
{
1906-
myRedValue = 255 - myRedValue;
1907-
myGreenValue = 255 - myGreenValue;
1908-
myBlueValue = 255 - myBlueValue;
1909-
1910-
}
1911-
1912-
myQImage.setPixel( myRow, myColumn, qRgba( myRedValue, myGreenValue, myBlueValue, myAlphaValue ) );
1913-
}
1914-
}
1915-
1916-
CPLFree( myGdalScanData );
1917-
1918-
//render any inline filters
1919-
filterLayer( &myQImage );
1920-
1921-
paintImageToCanvas( theQPainter, theRasterViewPort, theQgsMapToPixel, &myQImage );
1842+
QgsDebugMsg( "Not supported at this time" );
19221843
}
19231844

19241845

src/core/raster/qgsrasterlayer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
641641
SINGLE_BAND_PSEUDO_COLOR,// a "Gray" or "Undefined" layer drawn using a pseudocolor algorithm
642642
PALETTED_COLOR, //a "Palette" image drawn using color table
643643
PALETTED_SINGLE_BAND_GRAY,// a "Palette" layer drawn in gray scale (using only one of the color components)
644-
PALETTED_SINGLE_BAND_PSEUDO_COLOR, // a "Palette" layer having only one of its color components rendered as psuedo color --PJE20080827 this is no longer accurate as it is used to shade the color ramp as well
645-
PALETTED_MULTI_BAND_COLOR, // a "Palette" image is decomposed to 3 channels (RGB) and drawn --PJE20080827 this is no longer accurate
644+
PALETTED_SINGLE_BAND_PSEUDO_COLOR, // a "Palette" layer having only one of its color components rendered as psuedo color
645+
PALETTED_MULTI_BAND_COLOR, // currently not supported
646646
// as multiband
647647
MULTI_BAND_SINGLE_BAND_GRAY, // a layer containing 2 or more bands, but using only one band to produce a grayscale image
648648
MULTI_BAND_SINGLE_BAND_PSEUDO_COLOR, //a layer containing 2 or more bands, but using only one band to produce a pseudocolor image
@@ -930,7 +930,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
930930
// Paletted Layers
931931
//
932932

933-
/** \brief Drawing routine for paletted image, rendered as a single band image in color. */
933+
/** \brief Drawing routine for single band with a color map. */
934934
void drawPalettedSingleBandColor( QPainter * theQPainter,
935935
QgsRasterViewPort * theRasterViewPort,
936936
const QgsMapToPixel* theQgsMapToPixel,

0 commit comments

Comments
 (0)