Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsrastertransparency.cpp
Go to the documentation of this file.
1 /* **************************************************************************
2  qgsrastertransparency.cpp - description
3  -------------------
4 begin : Mon Nov 30 2007
5 copyright : (C) 2007 by Peter J. Ersts
6 email : ersts@amnh.org
7 
8 ****************************************************************************/
9 
10 /* **************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 #include <QList>
19 
20 #include "qgsrastertransparency.h"
21 
23 {
24 
25 }
26 
30 QList<QgsRasterTransparency::TransparentSingleValuePixel> QgsRasterTransparency::transparentSingleValuePixelList() const
31 {
33 }
34 
38 QList<QgsRasterTransparency::TransparentThreeValuePixel> QgsRasterTransparency::transparentThreeValuePixelList() const
39 {
41 }
42 
47 {
48  //clear the existing list
50 
51  //add the initial value
52  TransparentSingleValuePixel myTransparentSingleValuePixel;
53  myTransparentSingleValuePixel.pixelValue = theValue;
54  myTransparentSingleValuePixel.percentTransparent = 100.0;
55  mTransparentSingleValuePixelList.append( myTransparentSingleValuePixel );
56 }
57 
61 void QgsRasterTransparency::initializeTransparentPixelList( double theRedValue, double theGreenValue, double theBlueValue )
62 {
63  //clearn the existing list
65 
66  //add the initial values
67  TransparentThreeValuePixel myTransparentThreeValuePixel;
68  myTransparentThreeValuePixel.red = theRedValue;
69  myTransparentThreeValuePixel.green = theGreenValue;
70  myTransparentThreeValuePixel.blue = theBlueValue;
71  myTransparentThreeValuePixel.percentTransparent = 100.0;
72  mTransparentThreeValuePixelList.append( myTransparentThreeValuePixel );
73 }
74 
75 
79 void QgsRasterTransparency::setTransparentSingleValuePixelList( QList<QgsRasterTransparency::TransparentSingleValuePixel> theNewList )
80 {
82 }
83 
87 void QgsRasterTransparency::setTransparentThreeValuePixelList( QList<QgsRasterTransparency::TransparentThreeValuePixel> theNewList )
88 {
90 }
91 
98 int QgsRasterTransparency::alphaValue( double theValue, int theGlobalTransparency ) const
99 {
100  //if NaN return 0, transparent
101  if ( theValue != theValue )
102  {
103  return 0;
104  }
105 
106  //Search through he transparency list looking for a match
107  bool myTransparentPixelFound = false;
108  TransparentSingleValuePixel myTransparentPixel = {0, 100};
109  for ( int myListRunner = 0; myListRunner < mTransparentSingleValuePixelList.count(); myListRunner++ )
110  {
111  myTransparentPixel = mTransparentSingleValuePixelList[myListRunner];
112  if ( myTransparentPixel.pixelValue == theValue )
113  {
114  myTransparentPixelFound = true;
115  break;
116  }
117  }
118 
119  //if a match was found use the stored transparency percentage
120  if ( myTransparentPixelFound )
121  {
122  return ( int )(( float )theGlobalTransparency *( 1.0 - ( myTransparentPixel.percentTransparent / 100.0 ) ) );
123  }
124 
125  return theGlobalTransparency;
126 }
127 
136 int QgsRasterTransparency::alphaValue( double theRedValue, double theGreenValue, double theBlueValue, int theGlobalTransparency ) const
137 {
138  //if NaN return 0, transparent
139  if ( theRedValue != theRedValue || theGreenValue != theGreenValue || theBlueValue != theBlueValue )
140  {
141  return 0;
142  }
143 
144  //Search through he transparency list looking for a match
145  bool myTransparentPixelFound = false;
146  TransparentThreeValuePixel myTransparentPixel = {0, 0, 0, 100};
147  for ( int myListRunner = 0; myListRunner < mTransparentThreeValuePixelList.count(); myListRunner++ )
148  {
149  myTransparentPixel = mTransparentThreeValuePixelList[myListRunner];
150  if ( myTransparentPixel.red == theRedValue )
151  {
152  if ( myTransparentPixel.green == theGreenValue )
153  {
154  if ( myTransparentPixel.blue == theBlueValue )
155  {
156  myTransparentPixelFound = true;
157  break;
158  }
159  }
160  }
161  }
162 
163  //if a match was found use the stored transparency percentage
164  if ( myTransparentPixelFound )
165  {
166  return ( int )(( float )theGlobalTransparency *( 1.0 - ( myTransparentPixel.percentTransparent / 100.0 ) ) );
167  }
168 
169  return theGlobalTransparency;
170 }