Created
May 18, 2013 00:16
-
-
Save NathanW2/5602734 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit e393191b58c2b5038462e1502d1b7097d8e5086c (HEAD, raster_alpha) | |
Author: Nathan Woodrow <[email protected]> | |
Date: Sat May 18 10:10:35 2013 +1000 | |
Raster alpha | |
diff --git a/python/core/raster/qgscolorrampshader.sip b/python/core/raster/qgscolorrampshader.sip | |
index 35404ab..c101db5 100644 | |
--- a/python/core/raster/qgscolorrampshader.sip | |
+++ b/python/core/raster/qgscolorrampshader.sip | |
@@ -58,10 +58,10 @@ class QgsColorRampShader : QgsRasterShaderFunction | |
void setMaximumColorCacheSize( int theSize ); | |
/** \brief Generates and new RGB value based on one input value */ | |
- bool shade( double, int* /Out/, int* /Out/, int* /Out/ ); | |
+ bool shade( double, int* /Out/, int* /Out/, int* /Out/, int* /Out/ ); | |
/** \brief Generates and new RGB value based on original RGB value */ | |
- bool shade( double, double, double, int* /Out/, int* /Out/, int* /Out/ ); | |
+ bool shade( double, double, double, double, int* /Out/, int* /Out/, int* /Out/, int* /Out/); | |
void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const; | |
}; | |
diff --git a/python/core/raster/qgsrastershader.sip b/python/core/raster/qgsrastershader.sip | |
index 25b086e..8fa3729 100644 | |
--- a/python/core/raster/qgsrastershader.sip | |
+++ b/python/core/raster/qgsrastershader.sip | |
@@ -29,10 +29,10 @@ class QgsRasterShader | |
* | |
*/ | |
/** \brief generates and new RGB value based on one input value */ | |
- bool shade(double, int* /Out/, int* /Out/, int* /Out/); | |
+ bool shade(double, int* /Out/, int* /Out/, int* /Out/, int* /Out/); | |
/** \brief generates and new RGB value based on original RGB value */ | |
- bool shade(double, double, double, int* /Out/, int* /Out/, int* /Out/); | |
+ bool shade(double, double, double, double, int* /Out/, int* /Out/, int* /Out/, int* /Out/); | |
/** \brief A public method that allows the user to set their own shader function | |
\note Raster shader takes ownership of the shader function instance */ | |
diff --git a/python/core/raster/qgsrastershaderfunction.sip b/python/core/raster/qgsrastershaderfunction.sip | |
index 57ed458..338fe1a 100644 | |
--- a/python/core/raster/qgsrastershaderfunction.sip | |
+++ b/python/core/raster/qgsrastershaderfunction.sip | |
@@ -27,10 +27,10 @@ class QgsRasterShaderFunction | |
virtual void setMinimumValue( double ); | |
/** \brief generates and new RGB value based on one input value */ | |
- virtual bool shade( double, int* /Out/, int* /Out/, int* /Out/ ); | |
+ virtual bool shade( double, int* /Out/, int* /Out/, int* /Out/, int* /Out/ ); | |
/** \brief generates and new RGB value based on original RGB value */ | |
- virtual bool shade( double, double, double, int* /Out/, int* /Out/, int* /Out/ ); | |
+ virtual bool shade( double, double, double, double, int* /Out/, int* /Out/, int* /Out/, int* /Out/ ); | |
double minimumMaximumRange() const; | |
diff --git a/src/core/raster/qgscolorrampshader.cpp b/src/core/raster/qgscolorrampshader.cpp | |
index fc4f9d2..fd7ddaa 100644 | |
--- a/src/core/raster/qgscolorrampshader.cpp | |
+++ b/src/core/raster/qgscolorrampshader.cpp | |
@@ -49,7 +49,7 @@ QString QgsColorRampShader::colorRampTypeAsQString() | |
return QString( "Unknown" ); | |
} | |
-bool QgsColorRampShader::discreteColor( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue ) | |
+bool QgsColorRampShader::discreteColor( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue, int* theReturnAlphaValue ) | |
{ | |
int myColorRampItemCount = mColorRampItemList.count(); | |
if ( myColorRampItemCount <= 0 ) | |
@@ -75,6 +75,7 @@ bool QgsColorRampShader::discreteColor( double theValue, int* theReturnRedValue, | |
*theReturnRedValue = myColorRampItem.color.red(); | |
*theReturnGreenValue = myColorRampItem.color.green(); | |
*theReturnBlueValue = myColorRampItem.color.blue(); | |
+ *theReturnAlphaValue = myColorRampItem.color.alpha(); | |
//Cache the shaded value | |
if ( mMaximumColorCacheSize >= mColorCache.size() ) | |
{ | |
@@ -92,7 +93,7 @@ bool QgsColorRampShader::discreteColor( double theValue, int* theReturnRedValue, | |
return false; // value not found | |
} | |
-bool QgsColorRampShader::exactColor( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue ) | |
+bool QgsColorRampShader::exactColor(double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue , int *theReturnAlphaValue) | |
{ | |
int myColorRampItemCount = mColorRampItemList.count(); | |
if ( myColorRampItemCount <= 0 ) | |
@@ -112,6 +113,7 @@ bool QgsColorRampShader::exactColor( double theValue, int* theReturnRedValue, in | |
*theReturnRedValue = myColorRampItem.color.red(); | |
*theReturnGreenValue = myColorRampItem.color.green(); | |
*theReturnBlueValue = myColorRampItem.color.blue(); | |
+ *theReturnAlphaValue = myColorRampItem.color.alpha(); | |
//Cache the shaded value | |
if ( mMaximumColorCacheSize >= mColorCache.size() ) | |
{ | |
@@ -141,8 +143,8 @@ bool QgsColorRampShader::exactColor( double theValue, int* theReturnRedValue, in | |
return false; // value not found | |
} | |
-bool QgsColorRampShader::interpolatedColor( double theValue, int* | |
- theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue ) | |
+bool QgsColorRampShader::interpolatedColor(double theValue, int* | |
+ theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue , int* theReturnAlphaValue) | |
{ | |
int myColorRampItemCount = mColorRampItemList.count(); | |
if ( myColorRampItemCount <= 0 ) | |
@@ -174,9 +176,10 @@ bool QgsColorRampShader::interpolatedColor( double theValue, int* | |
*theReturnRedValue = ( int )(( double ) myPreviousColorRampItem.color.red() + (( double )( myColorRampItem.color.red() - myPreviousColorRampItem.color.red() ) * scale ) ) ; | |
*theReturnGreenValue = ( int )(( double ) myPreviousColorRampItem.color.green() + (( double )( myColorRampItem.color.green() - myPreviousColorRampItem.color.green() ) * scale ) ); | |
*theReturnBlueValue = ( int )(( double ) myPreviousColorRampItem.color.blue() + (( double )( myColorRampItem.color.blue() - myPreviousColorRampItem.color.blue() ) * scale ) ); | |
+ *theReturnAlphaValue = ( int )(( double ) myPreviousColorRampItem.color.alpha() + (( double )( myColorRampItem.color.alpha() - myPreviousColorRampItem.color.alpha() ) * scale ) ); | |
if ( mMaximumColorCacheSize >= mColorCache.size() ) | |
{ | |
- QColor myNewColor( *theReturnRedValue, *theReturnGreenValue, *theReturnBlueValue ); | |
+ QColor myNewColor( *theReturnRedValue, *theReturnGreenValue, *theReturnBlueValue, *theReturnAlphaValue ); | |
mColorCache.insert( theValue, myNewColor ); | |
} | |
return true; | |
@@ -192,9 +195,10 @@ bool QgsColorRampShader::interpolatedColor( double theValue, int* | |
*theReturnRedValue = myColorRampItem.color.red(); | |
*theReturnGreenValue = myColorRampItem.color.green(); | |
*theReturnBlueValue = myColorRampItem.color.blue(); | |
+ *theReturnAlphaValue = myColorRampItem.color.alpha(); | |
if ( mMaximumColorCacheSize >= mColorCache.size() ) | |
{ | |
- QColor myNewColor( *theReturnRedValue, *theReturnGreenValue, *theReturnBlueValue ); | |
+ QColor myNewColor( *theReturnRedValue, *theReturnGreenValue, *theReturnBlueValue, *theReturnAlphaValue ); | |
mColorCache.insert( theValue, myNewColor ); | |
} | |
return true; | |
@@ -245,7 +249,7 @@ void QgsColorRampShader::setColorRampType( QString theType ) | |
} | |
} | |
-bool QgsColorRampShader::shade( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue ) | |
+bool QgsColorRampShader::shade(double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue , int *theReturnAlphaValue) | |
{ | |
//Get the shaded value from the cache if it exists already | |
@@ -255,6 +259,7 @@ bool QgsColorRampShader::shade( double theValue, int* theReturnRedValue, int* th | |
*theReturnRedValue = myColor.red(); | |
*theReturnGreenValue = myColor.green(); | |
*theReturnBlueValue = myColor.blue(); | |
+ *theReturnAlphaValue = myColor.alpha(); | |
return true; | |
} | |
@@ -272,27 +277,29 @@ bool QgsColorRampShader::shade( double theValue, int* theReturnRedValue, int* th | |
if ( QgsColorRampShader::EXACT == mColorRampType ) | |
{ | |
- return exactColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue ); | |
+ return exactColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue, theReturnAlphaValue ); | |
} | |
else if ( QgsColorRampShader::INTERPOLATED == mColorRampType ) | |
{ | |
- return interpolatedColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue ); | |
+ return interpolatedColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue, theReturnAlphaValue ); | |
} | |
- return discreteColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue ); | |
+ return discreteColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue, theReturnAlphaValue ); | |
} | |
-bool QgsColorRampShader::shade( double theRedValue, double theGreenValue, | |
- double theBlueValue, int* theReturnRedValue, int* theReturnGreenValue, int* | |
- theReturnBlueValue ) | |
+bool QgsColorRampShader::shade(double theRedValue, double theGreenValue, | |
+ double theBlueValue, double theAplhaValue, int* theReturnRedValue, int* theReturnGreenValue, int* | |
+ theReturnBlueValue , int* theReturnAlphaValue) | |
{ | |
Q_UNUSED( theRedValue ); | |
Q_UNUSED( theGreenValue ); | |
Q_UNUSED( theBlueValue ); | |
+ Q_UNUSED( theAplhaValue ); | |
*theReturnRedValue = 0; | |
*theReturnGreenValue = 0; | |
*theReturnBlueValue = 0; | |
+ *theReturnAlphaValue = 0; | |
return false; | |
} | |
diff --git a/src/core/raster/qgscolorrampshader.h b/src/core/raster/qgscolorrampshader.h | |
index 92de763..9912028 100644 | |
--- a/src/core/raster/qgscolorrampshader.h | |
+++ b/src/core/raster/qgscolorrampshader.h | |
@@ -86,10 +86,10 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction | |
void setMaximumColorCacheSize( int theSize ) { mMaximumColorCacheSize = theSize; } | |
/** \brief Generates and new RGB value based on one input value */ | |
- bool shade( double, int*, int*, int* ); | |
+ bool shade( double, int*, int*, int*, int* ); | |
/** \brief Generates and new RGB value based on original RGB value */ | |
- bool shade( double, double, double, int*, int*, int* ); | |
+ bool shade(double, double, double, double, int*, int*, int*, int* ); | |
void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const; | |
@@ -121,17 +121,17 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction | |
/** Gets the color for a pixel value from the classification vector | |
* mValueClassification. Assigns the color of the lower class for every | |
* pixel between two class breaks.*/ | |
- bool discreteColor( double, int*, int*, int* ); | |
+ bool discreteColor( double, int*, int*, int*, int* ); | |
/** Gets the color for a pixel value from the classification vector | |
* mValueClassification. Assigns the color of the exact matching value in | |
* the color ramp item list */ | |
- bool exactColor( double, int*, int*, int* ); | |
+ bool exactColor( double, int*, int*, int*, int* ); | |
/** Gets the color for a pixel value from the classification vector | |
* mValueClassification. Interpolates the color between two class breaks | |
* linearly.*/ | |
- bool interpolatedColor( double, int*, int*, int* ); | |
+ bool interpolatedColor( double, int*, int*, int*, int* ); | |
/** Do not render values out of range */ | |
bool mClip; | |
diff --git a/src/core/raster/qgsrasterlayer.cpp b/src/core/raster/qgsrasterlayer.cpp | |
index bc7d374..4321f21 100644 | |
--- a/src/core/raster/qgsrasterlayer.cpp | |
+++ b/src/core/raster/qgsrasterlayer.cpp | |
@@ -732,9 +732,9 @@ QPixmap QgsRasterLayer::paletteAsPixmap( int theBandNumber ) | |
for ( int myCol = 0; myCol < mySize; myCol++ ) | |
{ | |
myValue = myStep * ( double )( myCol + myRow * mySize ); | |
- int c1, c2, c3; | |
- myShader.shade( myValue, &c1, &c2, &c3 ); | |
- myLineBuffer[ myCol ] = qRgb( c1, c2, c3 ); | |
+ int c1, c2, c3, c4; | |
+ myShader.shade( myValue, &c1, &c2, &c3, &c4 ); | |
+ myLineBuffer[ myCol ] = qRgba( c1, c2, c3, c4 ); | |
} | |
} | |
diff --git a/src/core/raster/qgsrastershader.cpp b/src/core/raster/qgsrastershader.cpp | |
index b59fab2..d6576b1 100644 | |
--- a/src/core/raster/qgsrastershader.cpp | |
+++ b/src/core/raster/qgsrastershader.cpp | |
@@ -45,11 +45,11 @@ QgsRasterShader::~QgsRasterShader() | |
@param theReturnBlueValue The blue component of the new RGB value | |
@return True if the return values are valid otherwise false | |
*/ | |
-bool QgsRasterShader::shade( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue ) | |
+bool QgsRasterShader::shade(double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue , int *theReturnAlpha) | |
{ | |
if ( 0 != mRasterShaderFunction ) | |
{ | |
- return mRasterShaderFunction->shade( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue ); | |
+ return mRasterShaderFunction->shade( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue, theReturnAlpha ); | |
} | |
return false; | |
@@ -66,11 +66,11 @@ bool QgsRasterShader::shade( double theValue, int* theReturnRedValue, int* theRe | |
@param theReturnBlueValue The blue component of the new RGB value | |
@return True if the return values are valid otherwise false | |
*/ | |
-bool QgsRasterShader::shade( double theRedValue, double theGreenValue, double theBlueValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue ) | |
+bool QgsRasterShader::shade(double theRedValue, double theGreenValue, double theBlueValue, double theAplhaValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue, int* theReturnAlpha) | |
{ | |
if ( 0 != mRasterShaderFunction ) | |
{ | |
- return mRasterShaderFunction->shade( theRedValue, theGreenValue, theBlueValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue ); | |
+ return mRasterShaderFunction->shade( theRedValue, theGreenValue, theBlueValue, theAplhaValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue, theReturnAlpha ); | |
} | |
return false; | |
diff --git a/src/core/raster/qgsrastershader.h b/src/core/raster/qgsrastershader.h | |
index c291c24..873e71d 100644 | |
--- a/src/core/raster/qgsrastershader.h | |
+++ b/src/core/raster/qgsrastershader.h | |
@@ -54,11 +54,11 @@ class CORE_EXPORT QgsRasterShader | |
* Non-Static methods | |
* | |
*/ | |
- /** \brief generates and new RGB value based on one input value */ | |
- bool shade( double, int*, int*, int* ); | |
+ /** \brief generates and new RGBA value based on one input value */ | |
+ bool shade( double, int*, int*, int* , int* ); | |
- /** \brief generates and new RGB value based on original RGB value */ | |
- bool shade( double, double, double, int*, int*, int* ); | |
+ /** \brief generates and new RGBA value based on original RGBA value */ | |
+ bool shade(double, double, double, double, int*, int*, int* , int*); | |
/** \brief A public method that allows the user to set their own shader function | |
\note Raster shader takes ownership of the shader function instance */ | |
diff --git a/src/core/raster/qgsrastershaderfunction.cpp b/src/core/raster/qgsrastershaderfunction.cpp | |
index c473a85..3464fa6 100644 | |
--- a/src/core/raster/qgsrastershaderfunction.cpp | |
+++ b/src/core/raster/qgsrastershaderfunction.cpp | |
@@ -63,13 +63,14 @@ void QgsRasterShaderFunction::setMinimumValue( double theValue ) | |
@param theReturnBlueValue The blue component of the new RGB value | |
@return True if the return values are valid otherwise false | |
*/ | |
-bool QgsRasterShaderFunction::shade( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue ) | |
+bool QgsRasterShaderFunction::shade( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue, int* theReturnAplhaValue ) | |
{ | |
Q_UNUSED( theValue ); | |
*theReturnRedValue = 0; | |
*theReturnGreenValue = 0; | |
*theReturnBlueValue = 0; | |
+ *theReturnAplhaValue = 0; | |
return false; | |
} | |
@@ -86,15 +87,17 @@ bool QgsRasterShaderFunction::shade( double theValue, int* theReturnRedValue, in | |
@param theReturnBlueValue The blue component of the new RGB value | |
@return True if the return values are valid otherwise false | |
*/ | |
-bool QgsRasterShaderFunction::shade( double theRedValue, double theGreenValue, double theBlueValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue ) | |
+bool QgsRasterShaderFunction::shade(double theRedValue, double theGreenValue, double theBlueValue, double theAplhaValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue , int *theReturnAplhaValue) | |
{ | |
Q_UNUSED( theRedValue ); | |
Q_UNUSED( theGreenValue ); | |
Q_UNUSED( theBlueValue ); | |
+ Q_UNUSED( theAplhaValue ); | |
*theReturnRedValue = 0; | |
*theReturnGreenValue = 0; | |
*theReturnBlueValue = 0; | |
+ *theReturnAplhaValue = 0; | |
return false; | |
} | |
diff --git a/src/core/raster/qgsrastershaderfunction.h b/src/core/raster/qgsrastershaderfunction.h | |
index 305fb07..e388d4a 100644 | |
--- a/src/core/raster/qgsrastershaderfunction.h | |
+++ b/src/core/raster/qgsrastershaderfunction.h | |
@@ -40,11 +40,11 @@ class CORE_EXPORT QgsRasterShaderFunction | |
/** \brief Return the minimum value */ | |
virtual void setMinimumValue( double ); | |
- /** \brief generates and new RGB value based on one input value */ | |
- virtual bool shade( double, int*, int*, int* ); | |
+ /** \brief generates and new RGBA value based on one input value */ | |
+ virtual bool shade( double, int*, int*, int*, int* ); | |
- /** \brief generates and new RGB value based on original RGB value */ | |
- virtual bool shade( double, double, double, int*, int*, int* ); | |
+ /** \brief generates and new RGBA value based on original RGBA value */ | |
+ virtual bool shade( double, double, double, double, int*, int*, int*, int* ); | |
double minimumMaximumRange() const { return mMinimumMaximumRange; } | |
diff --git a/src/core/raster/qgssinglebandpseudocolorrenderer.cpp b/src/core/raster/qgssinglebandpseudocolorrenderer.cpp | |
index 18161b7..161e8d9 100644 | |
--- a/src/core/raster/qgssinglebandpseudocolorrenderer.cpp | |
+++ b/src/core/raster/qgssinglebandpseudocolorrenderer.cpp | |
@@ -156,8 +156,8 @@ QgsRasterBlock* QgsSingleBandPseudoColorRenderer::block( int bandNo, QgsRectangl | |
continue; | |
} | |
double val = inputBlock->value( i ); | |
- int red, green, blue; | |
- if ( !mShader->shade( val, &red, &green, &blue ) ) | |
+ int red, green, blue, aplha; | |
+ if ( !mShader->shade( val, &red, &green, &blue, &aplha ) ) | |
{ | |
outputBlock->setColor( i, myDefaultColor ); | |
continue; | |
@@ -165,7 +165,7 @@ QgsRasterBlock* QgsSingleBandPseudoColorRenderer::block( int bandNo, QgsRectangl | |
if ( !hasTransparency ) | |
{ | |
- outputBlock->setColor( i, qRgba( red, green, blue, 255 ) ); | |
+ outputBlock->setColor( i, qRgba( red, green, blue, aplha ) ); | |
} | |
else | |
{ | |
@@ -180,7 +180,7 @@ QgsRasterBlock* QgsSingleBandPseudoColorRenderer::block( int bandNo, QgsRectangl | |
currentOpacity *= alphaBlock->value( i ) / 255.0; | |
} | |
- outputBlock->setColor( i, qRgba( currentOpacity * red, currentOpacity * green, currentOpacity * blue, currentOpacity * 255 ) ); | |
+ outputBlock->setColor( i, qRgba( currentOpacity * red, currentOpacity * green, currentOpacity * blue, currentOpacity * aplha ) ); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment