⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgsrastertransparency.cpp

📁 一个非常好的GIS开源新版本
💻 CPP
字号:
/* **************************************************************************                qgsrastertransparency.cpp -  description                       -------------------begin                : Mon Nov 30 2007copyright            : (C) 2007 by Peter J. Erstsemail                : ersts@amnh.org****************************************************************************//* ************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/#include <QList>#include "qgsrastertransparency.h"QgsRasterTransparency::QgsRasterTransparency(){}/**   Accessor for transparentSingleValuePixelList*/QList<QgsRasterTransparency::TransparentSingleValuePixel> QgsRasterTransparency::getTransparentSingleValuePixelList(){  return mTransparentSingleValuePixelList;}/**   Accessor for transparentThreeValuePixelList*/QList<QgsRasterTransparency::TransparentThreeValuePixel> QgsRasterTransparency::getTransparentThreeValuePixelList(){  return mTransparentThreeValuePixelList;}/**   Reset to the transparency list to a single value */void QgsRasterTransparency::initializeTransparentPixelList(double theValue){  //clear the existing list  mTransparentSingleValuePixelList.clear();    //add the initial value  TransparentSingleValuePixel myTransparentSingleValuePixel;  myTransparentSingleValuePixel.pixelValue = theValue;  myTransparentSingleValuePixel.percentTransparent = 100.0;  mTransparentSingleValuePixelList.append(myTransparentSingleValuePixel);}/**   Reset to the transparency list to a single value */void QgsRasterTransparency::initializeTransparentPixelList(double theRedValue, double theGreenValue, double theBlueValue){  //clearn the existing list  mTransparentThreeValuePixelList.clear();    //add the initial values  TransparentThreeValuePixel myTransparentThreeValuePixel;  myTransparentThreeValuePixel.red = theRedValue;  myTransparentThreeValuePixel.green = theGreenValue;  myTransparentThreeValuePixel.blue = theBlueValue;  myTransparentThreeValuePixel.percentTransparent = 100.0;  mTransparentThreeValuePixelList.append(myTransparentThreeValuePixel);}/**   Mutator for transparentSingleValuePixelList, , replaces the whole list */void QgsRasterTransparency::setTransparentSingleValuePixelList(QList<QgsRasterTransparency::TransparentSingleValuePixel> theNewList){  mTransparentSingleValuePixelList = theNewList;}/**   Mutator for transparentThreeValuePixelList, , replaces the whole list */void QgsRasterTransparency::setTransparentThreeValuePixelList(QList<QgsRasterTransparency::TransparentThreeValuePixel> theNewList){  mTransparentThreeValuePixelList = theNewList;}/**  Searches throught the transparency list, if a match is found, the global transparency value is scaled  by the stored transparency value.  @param theValue the needle to search for in the transparency hay stack  @param theGlobalTransparency  the overal transparency level for the layer*/int QgsRasterTransparency::getAlphaValue(double theValue, int theGlobalTransparency){  //if NaN return 0, transparent   if(theValue != theValue)  {    return 0;  }    //Search throught he transparency list looking for a match  bool myTransparentPixelFound = false;  TransparentSingleValuePixel myTransparentPixel;  for(int myListRunner = 0; myListRunner < mTransparentSingleValuePixelList.count(); myListRunner++)  {    myTransparentPixel = mTransparentSingleValuePixelList[myListRunner];    if(myTransparentPixel.pixelValue == theValue)    {      myTransparentPixelFound = true;      break;    }  }    //if a match was found use the stored transparency percentage  if(myTransparentPixelFound)  {    return (int)((float)theGlobalTransparency * (1.0 - (myTransparentPixel.percentTransparent/100.0)));  }  return theGlobalTransparency;}/**  Searches throught the transparency list, if a match is found, the global transparency value is scaled  by the stored transparency value.  @param theRedValue the red portion of the needle to search for in the transparency hay stack  @param theGreenValue  the green portion of the needle to search for in the transparency hay stack  @param theBlueValue the green portion of the needle to search for in the transparency hay stack  @param theGlobalTransparency  the overal transparency level for the layer*/int QgsRasterTransparency::getAlphaValue(double theRedValue, double theGreenValue, double theBlueValue, int theGlobalTransparency){  //if NaN return 0, transparent   if(theRedValue != theRedValue || theGreenValue != theGreenValue || theBlueValue != theBlueValue)  {    return 0;  }    //Search throught he transparency list looking for a match  bool myTransparentPixelFound = false;  TransparentThreeValuePixel myTransparentPixel;  for(int myListRunner = 0; myListRunner < mTransparentThreeValuePixelList.count(); myListRunner++)  {    myTransparentPixel = mTransparentThreeValuePixelList[myListRunner];    if(myTransparentPixel.red == theRedValue)    {      if(myTransparentPixel.green == theGreenValue)      {        if(myTransparentPixel.blue == theBlueValue)        {          myTransparentPixelFound = true;          break;        }      }    }  }    //if a match was found use the stored transparency percentage  if(myTransparentPixelFound)  {    return  (int)((float)theGlobalTransparency * (1.0 - (myTransparentPixel.percentTransparent/100.0)));  }    return theGlobalTransparency;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -