Skip to content
Permalink
Browse files

Fix for ticket #288 (transparent images aren't drawn with transparency).

git-svn-id: http://svn.osgeo.org/qgis/branches/Release-0_8_0@6393 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m
g_j_m committed Jan 4, 2007
1 parent a082022 commit 4598a0c08f11a58d2ab1921b1dc39a4a5292dcbb
@@ -203,10 +203,12 @@ QgsRasterLayerProperties::QgsRasterLayerProperties(QgsMapLayer *lyr, QWidget *pa
cboRed->insertItem(myQString);
cboGreen->insertItem(myQString);
cboBlue->insertItem(myQString);
cboTransparent->insertItem(myQString);
}
cboRed->insertItem(tr("Not Set"));
cboGreen->insertItem(tr("Not Set"));
cboBlue->insertItem(tr("Not Set"));
cboTransparent->insertItem(tr("Not Set"));
if (cboGray->count() != 1)
cboGray->insertItem(tr("Not Set"));
}
@@ -291,6 +293,7 @@ void QgsRasterLayerProperties::apply()
rasterLayer->setGreenBandName(cboGreen->currentText());
rasterLayer->setBlueBandName(cboBlue->currentText());
rasterLayer->setGrayBandName(cboGray->currentText());
rasterLayer->setTransparentBandName(cboTransparent->currentText());
//set the appropriate color ramping type
if (cboColorMap->currentText() == tr("Pseudocolor"))
{
@@ -682,6 +685,7 @@ void QgsRasterLayerProperties::sync()
cboGreen->setCurrentText(rasterLayer->getGreenBandName());
cboBlue->setCurrentText(rasterLayer->getBlueBandName());
cboGray->setCurrentText(rasterLayer->getGrayBandName());
cboTransparent->setCurrentText(rasterLayer->getTransparentBandName());


} // QgsRasterLayerProperties::sync()
@@ -653,6 +653,7 @@ QgsRasterLayer::readFile( QString const & fileName )
redBandNameQString = "Red"; // sensible default
greenBandNameQString = "Green"; // sensible default
blueBandNameQString = "Blue";// sensible default
transparentBandNameQString = tr("Not Set"); // sensible default
grayBandNameQString = tr("Not Set"); //sensible default
drawingStyle = PALETTED_MULTI_BAND_COLOR; //sensible default
}
@@ -670,6 +671,11 @@ QgsRasterLayer::readFile( QString const & fileName )
{
blueBandNameQString = tr("Not Set"); // sensible default
}
if (gdalDataset->GetRasterCount() > 3)
transparentBandNameQString = getRasterBandName(4);
else
transparentBandNameQString = tr("Not Set");

grayBandNameQString = tr("Not Set"); //sensible default
drawingStyle = MULTI_BAND_COLOR; //sensible default
}
@@ -679,6 +685,7 @@ QgsRasterLayer::readFile( QString const & fileName )
redBandNameQString = tr("Not Set"); //sensible default
greenBandNameQString = tr("Not Set"); //sensible default
blueBandNameQString = tr("Not Set"); //sensible default
transparentBandNameQString = tr("Not Set"); //sensible default
drawingStyle = SINGLE_BAND_GRAY; //sensible default
grayBandNameQString = getRasterBandName(1); // usually gdal will return gray or undefined
}
@@ -2333,6 +2340,20 @@ void QgsRasterLayer::drawMultiBandColor(QPainter * theQPainter, QgsRasterViewPor
void *myGdalGreenData = readData ( myGdalGreenBand, theRasterViewPort );
void *myGdalBlueData = readData ( myGdalBlueBand, theRasterViewPort );

bool haveTransparencyBand(false);
GDALRasterBand *myGdalTransparentBand;
GDALDataType myTransparentType;
void *myGdalTransparentData;

if (transparentBandNameQString != tr("Not Set"))
{
haveTransparencyBand = true;
int myTransparentBandNoInt = getRasterBandNumber(transparentBandNameQString);
myGdalTransparentBand = gdalDataset->GetRasterBand(myTransparentBandNoInt);
myTransparentType = myGdalTransparentBand->GetRasterDataType();
myGdalTransparentData = readData ( myGdalTransparentBand, theRasterViewPort );
}

QImage myQImage = QImage(theRasterViewPort->drawableAreaXDimInt, theRasterViewPort->drawableAreaYDimInt, 32);
//myQImage.fill(0);
myQImage.setAlphaBuffer(true);
@@ -2347,9 +2368,16 @@ void QgsRasterLayer::drawMultiBandColor(QPainter * theQPainter, QgsRasterViewPor
myColumnInt * theRasterViewPort->drawableAreaXDimInt + myRowInt );
double myBlueValueDouble = readValue ( myGdalBlueData, myBlueType,
myColumnInt * theRasterViewPort->drawableAreaXDimInt + myRowInt );
if (haveTransparencyBand)
{
double myTransparentValueDouble = readValue ( myGdalTransparentData, myTransparentType,
myColumnInt * theRasterViewPort->drawableAreaXDimInt + myRowInt );
if (myTransparentValueDouble == 0.0)
continue;
}

// TODO: check all channels ?
if ( myRedValueDouble == noDataValueDouble || myRedValueDouble != myRedValueDouble )
if ( myRedValueDouble == noDataValueDouble || myRedValueDouble != myRedValueDouble)
{
#ifdef QGISDEBUG
QgsLogger::debug("myRedValueDouble", myRedValueDouble, __FILE__, __FUNCTION__, __LINE__, 1);
@@ -2439,6 +2467,8 @@ QgsDebugMsg("QgsRasterLayer::drawSingleBandGray: painting image to canvas from s
CPLFree(myGdalRedData);
CPLFree(myGdalGreenData);
CPLFree(myGdalBlueData);
if (haveTransparencyBand)
CPLFree(myGdalTransparentData);
}


@@ -3007,6 +3037,38 @@ void QgsRasterLayer::setBlueBandName(QString const & theBandNameQString)
return;
}

//mutator for transparent band name
void QgsRasterLayer::setTransparentBandName(QString const & theBandNameQString)
{
//check if the band is unset
if (theBandNameQString == tr("Not Set"))
{
transparentBandNameQString = theBandNameQString;
return;
}
//check if the image is paletted
if (rasterLayerType == PALETTE && (theBandNameQString == "Red" || theBandNameQString == "Green" || theBandNameQString == "Blue"))
{
transparentBandNameQString = theBandNameQString;
return;
}
//check that a valid band name was passed

for (int myIteratorInt = 0; myIteratorInt < rasterStatsVector.size(); ++myIteratorInt)
{
//find out the name of this band
QgsRasterBandStats myRasterBandStats = rasterStatsVector[myIteratorInt];
if (myRasterBandStats.bandName == theBandNameQString)
{
transparentBandNameQString = theBandNameQString;
return;
}
}

//if no matches were found default to not set
transparentBandNameQString = tr("Not Set");
return;
}


//mutator for gray band name
@@ -415,6 +415,16 @@ class QgsRasterLayer : public QgsMapLayer
/** \brief Mutator for blue band name mapping. */
void setBlueBandName(QString const & theBandNameQString);
//
// Accessor and mutator for transparent band name
//
/** \brief Accessor for transparent band name mapping. */
QString getTransparentBandName()
{
return transparentBandNameQString;
};
/** \brief Mutator for transparent band name mapping. */
void setTransparentBandName(QString const & theBandNameQString);
//
// Accessor and mutator for gray band name
//
/** \brief Accessor for gray band name mapping. */
@@ -1007,6 +1017,8 @@ public slots:
QString greenBandNameQString;
/** \brief The band to be associated with the color blue - usually 3. */
QString blueBandNameQString;
/** \brief The band to be associated with transparency. */
QString transparentBandNameQString;
/** \brief The band to be associated with the grayscale only ouput - usually 1. */
QString grayBandNameQString;
/** \brief Minimum red value - used in scaling procedure. */
@@ -191,20 +191,27 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="4" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
<item row="3" column="1" >
<widget class="QComboBox" name="cboBlue" />
</item>
<item row="1" column="1" >
<widget class="QComboBox" name="cboRed" />
</item>
<item row="0" column="0" >
<widget class="QLabel" name="textLabel2_4" >
<property name="text" >
<string>Color</string>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLabel" name="textLabel2_5" >
<property name="text" >
<string>Band</string>
</property>
</spacer>
</widget>
</item>
<item row="4" column="0" >
<item row="5" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
@@ -217,18 +224,8 @@
</property>
</spacer>
</item>
<item row="3" column="1" >
<widget class="QComboBox" name="cboBlue" />
</item>
<item row="3" column="0" >
<widget class="QLabel" name="textLabel2_3" >
<property name="text" >
<string>&lt;b>&lt;font color="#0000ff">Blue&lt;/font>&lt;/b></string>
</property>
<property name="buddy" >
<cstring>cboBlue</cstring>
</property>
</widget>
<item row="2" column="1" >
<widget class="QComboBox" name="cboGreen" />
</item>
<item row="2" column="0" >
<widget class="QLabel" name="textLabel2_2" >
@@ -240,12 +237,6 @@
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QComboBox" name="cboGreen" />
</item>
<item row="1" column="1" >
<widget class="QComboBox" name="cboRed" />
</item>
<item row="1" column="0" >
<widget class="QLabel" name="textLabel2" >
<property name="text" >
@@ -256,20 +247,39 @@
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLabel" name="textLabel2_5" >
<item row="5" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" >
<widget class="QLabel" name="textLabel2_3" >
<property name="text" >
<string>Band</string>
<string>&lt;b>&lt;font color="#0000ff">Blue&lt;/font>&lt;/b></string>
</property>
<property name="buddy" >
<cstring>cboBlue</cstring>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="textLabel2_4" >
<item row="4" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Color</string>
<string>Transparent</string>
</property>
</widget>
</item>
<item row="4" column="1" >
<widget class="QComboBox" name="cboTransparent" />
</item>
</layout>
</widget>
</item>
@@ -1068,9 +1078,14 @@
<layoutdefault spacing="6" margin="11" />
<customwidgets>
<customwidget>
<class>Q3TextBrowser</class>
<extends>Q3TextEdit</extends>
<header>Qt3Support/Q3TextBrowser</header>
<class>Q3TextEdit</class>
<extends>Q3Frame</extends>
<header>q3textedit.h</header>
</customwidget>
<customwidget>
<class>Q3ListBox</class>
<extends>Q3Frame</extends>
<header>q3listbox.h</header>
</customwidget>
<customwidget>
<class>Q3GroupBox</class>
@@ -1079,14 +1094,9 @@
<container>1</container>
</customwidget>
<customwidget>
<class>Q3ListBox</class>
<extends>Q3Frame</extends>
<header>q3listbox.h</header>
</customwidget>
<customwidget>
<class>Q3TextEdit</class>
<extends>Q3Frame</extends>
<header>q3textedit.h</header>
<class>Q3TextBrowser</class>
<extends>Q3TextEdit</extends>
<header>Qt3Support/Q3TextBrowser</header>
</customwidget>
</customwidgets>
<tabstops>

0 comments on commit 4598a0c

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