Quantum GIS API Documentation  1.8
src/core/raster/qgslinearminmaxenhancementwithclip.cpp
Go to the documentation of this file.
00001 /* **************************************************************************
00002               qgslinearminmaxenhancementwithclip.cpp -  description
00003                        -------------------
00004 begin                : Fri Nov 16 2007
00005 copyright            : (C) 2007 by Peter J. Ersts
00006 email                : ersts@amnh.org
00007 
00008 ****************************************************************************/
00009 
00010 /* **************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #include "qgslinearminmaxenhancementwithclip.h"
00020 
00021 QgsLinearMinMaxEnhancementWithClip::QgsLinearMinMaxEnhancementWithClip( QgsContrastEnhancement::QgsRasterDataType theQgsRasterDataType, double theMinimumValue, double theMaximumValue ) : QgsContrastEnhancementFunction( theQgsRasterDataType, theMinimumValue, theMaximumValue )
00022 {
00023 }
00024 
00025 int QgsLinearMinMaxEnhancementWithClip::enhance( double theValue )
00026 {
00027   if ( theValue < mMinimumValue || theValue > mMaximumValue )
00028   {
00029     return -1;
00030   }
00031 
00032   int myStretchedValue = static_cast<int>((( theValue - mMinimumValue ) / ( mMinimumMaximumRange ) ) * 255.0 );
00033   if ( myStretchedValue < 0 )
00034   {
00035     return 0;
00036   }
00037   else if ( myStretchedValue > 255 )
00038   {
00039     return 255;
00040   }
00041 
00042   return myStretchedValue;
00043 }
00044 
00045 bool QgsLinearMinMaxEnhancementWithClip::isValueInDisplayableRange( double theValue )
00046 {
00047   if ( theValue < mMinimumValue || theValue > mMaximumValue )
00048   {
00049     return false;
00050   }
00051 
00052   return true;
00053 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines