@@ -560,7 +560,7 @@ bool QgsRasterLayer::readFile( QString const & fileName )
560
560
mGrayBandName = getRasterBandName (1 ); // sensible default
561
561
QgsDebugMsg (mGrayBandName );
562
562
563
- drawingStyle = PALETTED_SINGLE_BAND_PSEUDO_COLOR ; // sensible default
563
+ drawingStyle = PALETTED_COLOR ; // sensible default
564
564
565
565
// Load the color table from the band
566
566
QList<QgsColorRampShader::ColorRampItem> myColorRampList;
@@ -784,6 +784,10 @@ void QgsRasterLayer::setDrawingStyle( QString const & theDrawingStyleQString )
784
784
{
785
785
drawingStyle = SINGLE_BAND_PSEUDO_COLOR;
786
786
}
787
+ else if ( theDrawingStyleQString == " PALETTED_COLOR" )// no need to tr() this its not shown in ui
788
+ {
789
+ drawingStyle = PALETTED_COLOR;
790
+ }
787
791
else if ( theDrawingStyleQString == " PALETTED_SINGLE_BAND_GRAY" )// no need to tr() this its not shown in ui
788
792
{
789
793
drawingStyle = PALETTED_SINGLE_BAND_GRAY;
@@ -1221,6 +1225,22 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
1221
1225
theQgsMapToPixel, getRasterBandNumber ( mGrayBandName ) );
1222
1226
break ;
1223
1227
}
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
+ }
1224
1244
// a "Palette" layer drawn in gray scale (using only one of the color components)
1225
1245
case PALETTED_SINGLE_BAND_GRAY:
1226
1246
// check the band is set!
@@ -1520,7 +1540,7 @@ void QgsRasterLayer::drawSingleBandPseudoColor( QPainter * theQPainter,
1520
1540
}
1521
1541
1522
1542
/* *
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 .
1524
1544
* @param theQPainter - pointer to the QPainter onto which the layer should be drawn.
1525
1545
* @param theRasterViewPort - pointer to the ViewPort struct containing dimensions of viewable area and subset area to be extracted from data file.
1526
1546
* @param theGdalBand - pointer to the GDALRasterBand which should be rendered.
@@ -1535,6 +1555,11 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
1535
1555
return ;
1536
1556
}
1537
1557
1558
+ if ( NULL == mRasterShader )
1559
+ {
1560
+ return ;
1561
+ }
1562
+
1538
1563
GDALRasterBandH myGdalBand = GDALGetRasterBand ( mGdalDataset , theBandNo );
1539
1564
GDALDataType myDataType = GDALGetRasterDataType ( myGdalBand );
1540
1565
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
@@ -1545,26 +1570,22 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
1545
1570
return ;
1546
1571
}
1547
1572
1548
- QgsColorTable *myColorTable = colorTable ( theBandNo );
1549
-
1550
1573
QImage myQImage = QImage ( theRasterViewPort->drawableAreaXDim , theRasterViewPort->drawableAreaYDim , QImage::Format_ARGB32 );
1551
1574
myQImage.fill ( qRgba ( 255 , 255 , 255 , 0 ) ); // fill transparent
1552
1575
1553
1576
double myPixelValue = 0.0 ;
1554
1577
int myRedValue = 0 ;
1555
1578
int myGreenValue = 0 ;
1556
1579
int myBlueValue = 0 ;
1557
- bool found = false ;
1558
1580
int myAlphaValue = 0 ;
1581
+
1559
1582
for ( int myColumn = 0 ; myColumn < theRasterViewPort->drawableAreaYDim ; ++myColumn )
1560
1583
{
1561
1584
for ( int myRow = 0 ; myRow < theRasterViewPort->drawableAreaXDim ; ++myRow )
1562
1585
{
1563
- // Reinitalize values;
1564
1586
myRedValue = 0 ;
1565
1587
myGreenValue = 0 ;
1566
1588
myBlueValue = 0 ;
1567
- found = false ;
1568
1589
myPixelValue = readValue ( myGdalScanData, ( GDALDataType )myDataType,
1569
1590
myColumn * theRasterViewPort->drawableAreaXDim + myRow );
1570
1591
@@ -1579,19 +1600,23 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
1579
1600
continue ;
1580
1601
}
1581
1602
1582
- found = myColorTable->color ( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue );
1583
- if ( !found ) continue ;
1603
+ if ( !mRasterShader ->generateShadedValue ( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
1604
+ {
1605
+ continue ;
1606
+ }
1584
1607
1585
1608
if ( mInvertPixelsFlag )
1586
1609
{
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 ) );
1590
1617
}
1591
- myQImage.setPixel ( myRow, myColumn, qRgba ( myRedValue, myGreenValue, myBlueValue, myAlphaValue ) );
1592
1618
}
1593
1619
}
1594
-
1595
1620
CPLFree ( myGdalScanData );
1596
1621
1597
1622
// render any inline filters
@@ -1717,12 +1742,7 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
1717
1742
return ;
1718
1743
}
1719
1744
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 );
1726
1746
GDALRasterBandH myGdalBand = GDALGetRasterBand ( mGdalDataset , theBandNo );
1727
1747
GDALDataType myDataType = GDALGetRasterDataType ( myGdalBand );
1728
1748
void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
@@ -1811,114 +1831,15 @@ void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
1811
1831
}
1812
1832
1813
1833
/* *
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
1815
1835
* @param theQPainter - pointer to the QPainter onto which the layer should be drawn.
1816
1836
* @param theRasterViewPort - pointer to the ViewPort struct containing dimensions of viewable area and subset area to be extracted from data file.
1817
1837
* @param theGdalBand - pointer to the GDALRasterBand which should be rendered.
1818
1838
*/
1819
1839
void QgsRasterLayer::drawPalettedMultiBandColor ( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,
1820
1840
const QgsMapToPixel* theQgsMapToPixel, int theBandNo )
1821
1841
{
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" );
1922
1843
}
1923
1844
1924
1845
0 commit comments