LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiColors.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /*----------------------------------------------------------------
00025  * project ....: LTI Digital Image/Signal Processing Library
00026  * file .......: ltiColors.h
00027  * authors ....: Jochen Wickel
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 12.11.01
00030  * revisions ..: $Id: ltiColors.h,v 1.5 2007/01/10 02:25:31 alvarado Exp $
00031  */
00032 
00033 #ifndef LTI_COLORS_H
00034 #define LTI_COLORS_H
00035 
00036 #include "ltiRGBPixel.h"
00037 // we need this for min and max
00038 #include "ltiMath.h"
00039 
00040 /**
00041  * @file ltiColors.h
00042  * This file contains some more symbolic color definitions, like orange,
00043  * Pink, etc.
00044  */
00045 
00046 namespace lti {
00047 
00048   /**
00049    * An alias for the rgbPixel type. It has several useful methods
00050    * though that can be used for reading color definitions
00051    * from external sources.
00052    */
00053   class rgbColor: public rgbPixel {
00054 
00055   public:
00056     /**
00057      * default constructor
00058      */
00059     rgbColor() : rgbPixel() {};
00060 
00061     /**
00062      * constructor with member initialization
00063      *
00064      * Per default a new rgbColor will be initialized with the given value.
00065      * @param val a 4 byte value to be
00066      *            assign to the three channels + dummy.
00067      *             Note that the order depends on the system endianness:
00068      *             - If you use little endian (for example: Intel Processor)
00069      *               a value of 0x00010203 means red=01,green=02 and blue=03
00070      *             - If you use big endian (for example: PowerPC Processor)
00071      *               a value of 0x00010203 means red=02,green=01 and blue=00
00072      *             Avoid the use of this constructor if you want to maintain
00073      *             platform compatibility.
00074      */
00075     rgbColor(const uint32 val)
00076     : rgbPixel(val) {
00077       // nothing else
00078     };
00079 
00080     /**
00081      * Upgrade constructor.
00082      */
00083     rgbColor(const rgbPixel& other)
00084     : rgbPixel(other.getValue()) {
00085       // nothing else
00086     };
00087 
00088     /**
00089      * rgb constructor
00090      * @param r 8 bit value for the red component
00091      * @param g 8 bit value for the green component
00092      * @param b 8 bit value for the blue component
00093      * @param d 8 bit value for the dummy byte (default value 0)
00094      */
00095     rgbColor(const ubyte r,const ubyte g,const ubyte b,const ubyte d=0)
00096     : rgbPixel(r,g,b,d) {
00097       // nothing else
00098     };
00099 
00100 
00101     /**
00102      * Parses a HTML color definition string and sets this color
00103      * to the given one. In HTML, RGB colors
00104      * are defined by the following syntax:
00105      * <pre>
00106      * Color = \#RRGGBB
00107      * RR = ( 0 | 1 | 2 | ... | 9 | a | A | b | B | ... | f | F ){2}
00108      * GG = ( 0 | 1 | 2 | ... | 9 | a | A | b | B | ... | f | F ){2}
00109      * BB = ( 0 | 1 | 2 | ... | 9 | a | A | b | B | ... | f | F ){2}
00110      * </pre>
00111      * For instance, "#ff0000" means red (r=255,g=0,b=0).
00112      * This method also can accept an extension which also includes
00113      * the alpha value as a fourth component (Color = \#RRGGBBAA).
00114      * If the component is not present, it will be assumed zero.
00115      * If a string cannot be parsed, the value of this color
00116      * object will be undefined.
00117      *
00118      * @param s the HTML color definition.
00119      * @param acceptAlpha if this is true, the method accepts
00120      * a fourth component which is interpreted as alpha value.
00121      * If it is false, such a string will lead to an error.
00122      * @return true if the string could be parsed, false
00123      *         otherwise.
00124      */
00125     bool parseHTML(const std::string& s, bool acceptAlpha=false);
00126 
00127     /**
00128      * Returns a HTML color definition of this color.
00129      * @param getAlpha if this is true, the returned definition
00130      *        will also contain the alpha channel.
00131      */
00132     std::string makeHTML(bool getAlpha=false) const;
00133 
00134     /**
00135      * Parses a color name (which colors are defined, is
00136      * system dependent) and sets this color to the giveon one.
00137      * If the color name is undefined, the method will return false;
00138      * @param s the color name
00139      * @return true if the name is known and defined, false otherwise.
00140      */
00141     bool parseName(const std::string& s);
00142 
00143   };
00144 
00145   /**
00146    * @name Color Constants.
00147    *
00148    * These color constants are defined in the file ltiColors.h.
00149    * The six primary and secondary colors are defined in ltiTypes.h
00150    * (which is also included in ltiColors.h!)
00151    * @see lti::Red,lti::Green,lti::Blue,lti::Cyan,lti::Magenta,lti::Yellow
00152    *
00153    * Note that the color names are all own
00154    * creations, they are not correlated to any official naming
00155    * standards at all.
00156    */
00157   //@{
00158 
00159   // darker primary colors
00160 
00161   /**
00162    * Constant for dark red
00163    */
00164   static const rgbColor DarkRed(127,0,0);
00165 
00166   /**
00167    * Constant for dark green
00168    */
00169   static const rgbColor DarkGreen(0,127,0);
00170 
00171   /**
00172    * Constant for dark blue
00173    */
00174   static const rgbColor DarkBlue(0,0,127);
00175 
00176   // darker secondary colors
00177 
00178   /**
00179    * constant for the color dark yellow
00180    */
00181   static const rgbColor DarkYellow(127,127,0);
00182 
00183   /**
00184    * constant for some kind of dark cyan.
00185    */
00186   static const rgbColor DarkCyan(0,127,127);
00187 
00188   /**
00189    * constant for some kind of dark magenta.
00190    */
00191   static const rgbColor DarkMagenta(127,0,127);
00192 
00193   // brighter primary colors
00194 
00195   /**
00196    * constant for a kind of bright green.
00197    */
00198   static const rgbColor BrightGreen(0,255,127);
00199 
00200   /**
00201    * constant for a kind of bright green.
00202    */
00203   static const rgbColor BrightBlue(0,127,255);
00204 
00205   /**
00206    * constant for a kind of bright red.
00207    */
00208   static const rgbColor BrightRed(255,127,64);
00209 
00210   // brighter secondary colors
00211 
00212   /**
00213    * constant for some kind of bright magenta.
00214    */
00215   static const rgbColor BrightMagenta(255,127,255);
00216 
00217   /**
00218    * constant for some kind of bright yellow.
00219    */
00220   static const rgbColor BrightYellow(255,255,127);
00221 
00222   /**
00223    * constant for some kind of bright cyan.
00224    */
00225   static const rgbColor BrightCyan(127,255,255);
00226 
00227 
00228   // other colors
00229 
00230   /**
00231    * constant for the color orange.
00232    */
00233   static const rgbColor DarkOrange(192,64,0);
00234 
00235   /**
00236    * constant for the color fusia.
00237    */
00238   static const rgbColor Fusia(255,0,127);
00239 
00240   /**
00241    * constant for the color pink.
00242    */
00243   static const rgbColor Pink(255,127,127);
00244 
00245   /**
00246    * constant for another kind of bright green.
00247    */
00248   static const rgbColor LawnGreen(127,255,0);
00249 
00250   /**
00251    * constant for some kind of lemon color
00252    */
00253   static const rgbColor Lemon(127,255,127);
00254 
00255   /**
00256    * constant for a light blue.
00257    */
00258   static const rgbColor LightBlue(0,127,255);
00259 
00260   /**
00261    * constant for a light blue.
00262    */
00263   static const rgbColor DarkViolet(127,0,255);
00264 
00265   /**
00266    * constant for the color violet.
00267    */
00268   static const rgbColor Violet(127,127,255);
00269 
00270 
00271   /**
00272    * Function for scaling a color's intensity.
00273    * @param src rgbColor of the original color
00274    * @param f factor by which to multiply the R, G and B values. Warning:
00275    * Saturation effects might lead to strange results.
00276    * @return rgbColor where R, G and B have the given value <code>t</code>.
00277    */
00278   inline rgbColor scale(const rgbColor& src, double f) {
00279     double r=max(0.0,min(double(src.getRed())*f,255.0));
00280     double g=max(0.0,min(double(src.getGreen())*f,255.0));
00281     double b=max(0.0,min(double(src.getBlue())*f,255.0));
00282     return rgbColor(int(r),int(g),int(b));
00283   }
00284 
00285   /**
00286    * Function for darkening a color.
00287    * @param src rgbColor of the original color
00288    * @param f factor which tells how much darker the new color should be.
00289    * Example: 0.2 means: Make the color 20% darker. 0 means:
00290    * leave the original, 1.0 means: make it black
00291    * @return rgbColor where R, G and B have the given value <code>t</code>.
00292    */
00293   inline rgbColor darker(const rgbColor& src, double f=0.5) {
00294     return scale(src,(1.0-f));
00295   }
00296 
00297   /**
00298    * Function for brightening a color.
00299    * @param src rgbColor of the original color
00300    * @param f factor which tells how much darker the new color should be.
00301    * Example: 0.2 means: Make the color 20% brighter. 0 means:
00302    * leave the original, 1.0 means: make it twice as bright. Warning:
00303    * Saturation effects might lead to strange results.
00304    * @return rgbColor where R, G and B have the given value <code>t</code>.
00305    */
00306   inline rgbColor brighter(const rgbColor& src, double f=0.5) {
00307     return scale(src,(1.0+f));
00308   }
00309 
00310 
00311   /**
00312    * function for returning a grey value.
00313    * @param t grey value must be between 0 and 255
00314    * @return rgbColor where R, G and B have the given value <code>t</code>.
00315    */
00316   inline rgbColor grey(int t) {
00317     return rgbColor(t,t,t);
00318   }
00319 
00320   /**
00321    * function for returning a gray value.
00322    * @param t grey value must be between 0 and 255
00323    * @return rgbColor where R, G and B have the given value <code>t</code>.
00324    */
00325   inline rgbColor gray(int t) {
00326     return rgbColor(t,t,t);
00327   }
00328 
00329   /**
00330    * function for returning a grey value.
00331    * @param t grey value must be between 0 and 1
00332    * @return rgbColor where R, G and B have the given value <code>t*255</code>.
00333    */
00334   inline rgbColor grey(double t) {
00335     return rgbColor(int(t*255),int(t*255),int(t*255.0));
00336   }
00337 
00338   /**
00339    * function for returning a gray value.
00340    * @param t grey value must be between 0 and 1
00341    * @return rgbColor where R, G and B have the given value <code>t*255</code>.
00342    */
00343   inline rgbColor gray(double t) {
00344     return rgbColor(int(t*255),int(t*255),int(t*255.0));
00345   }
00346 
00347   /**
00348    * Definition for a 100% bright grey, i.e. White
00349    */
00350   static const rgbColor Grey100(255,255,255);
00351 
00352   /**
00353    * Definition for a 75% bright grey, i.e. bright grey
00354    */
00355   static const rgbColor Grey75(191,191,191);
00356 
00357   /**
00358    * Definition for a 50% bright grey, i.e. medium grey
00359    */
00360   static const rgbColor Grey50(127,127,127);
00361 
00362   /**
00363    * Definition for a 25% bright grey, i.e. dark grey
00364    */
00365   static const rgbColor Grey25(63,63,63);
00366 
00367   /**
00368    * Definition for a 0% bright grey, i.e. Black
00369    */
00370   static const rgbColor Grey0(0,0,0);
00371 
00372 
00373 
00374 }
00375 
00376 #endif

Generated on Sat Apr 10 15:25:16 2010 for LTI-Lib by Doxygen 1.6.1