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

ltiCMYKColor.h

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 .......: ltiCMYKColor.h
00027  * authors ....: Jochen Wickel
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 12.11.01
00030  * revisions ..: $Id: ltiCMYKColor.h,v 1.3 2006/02/07 18:07:01 ltilib Exp $
00031  */
00032 
00033 #ifndef LTI_CMYK_COLOR_H
00034 #define LTI_CMYK_COLOR_H
00035 
00036 namespace lti {
00037 
00038   /**
00039    * A little class for defining points in the CMYK color space.
00040    * At present, CMYK colors can only be used for EPS drawings.
00041    */
00042   class cmykColor {
00043   public:
00044 
00045     /**
00046      * Default constructor. Sets this color to (0,0,0,0) which
00047      * is the CMYK representation of white.
00048      */
00049     cmykColor() { c=m=y=k=0; };
00050 
00051     /**
00052      * Constructor. Sets the C, M, Y, and K components to the
00053      * given values.
00054      */
00055     cmykColor(float nc, float nm, float ny, float nk) {
00056       c=nc; m=nm; y=ny; k=nk;
00057     }
00058 
00059     /**
00060      * Returns the value of the C (=Cyan) component of this color.
00061      */
00062     inline float getCyan() const {
00063       return c;
00064     }
00065 
00066     /**
00067      * Returns the value of the M (=Magenta) component of this color.
00068      */
00069     inline float getMagenta() const {
00070       return m;
00071     }
00072 
00073     /**
00074      * Returns the value of the Y (=Yellow) component of this color.
00075      */
00076     inline float getYellow() const {
00077       return y;
00078     }
00079 
00080     /**
00081      * Returns the value of the K (=blacK) component of this color.
00082      */
00083     inline float getBlack() const {
00084       return k;
00085     }
00086 
00087     /**
00088      * sets the value of the Cyan component of this color
00089      */
00090     void setCyan(const float& cyan) {
00091       c=cyan;
00092     }
00093 
00094     /**
00095      * sets the value of the Magenta component of this color
00096      */
00097     void setMagenta(const float& magenta) {
00098       m=magenta;
00099     }
00100 
00101     /**
00102      * sets the value of the Yellow component of this color
00103      */
00104     void setYellow(const float& yellow) {
00105       y=yellow;
00106     }
00107 
00108     /**
00109      * sets the value of the Black component of this color
00110      */
00111     void setBlack(const float& black) {
00112       k=black;
00113     }
00114 
00115     /**
00116      * Copies the "other" color to this color.
00117      */
00118     inline cmykColor& copy(const cmykColor& other) {
00119       c=other.c;
00120       m=other.m;
00121       y=other.y;
00122       k=other.k;
00123       return (*this);
00124     };
00125 
00126     /**
00127      * Alias for copy.
00128      */
00129     inline cmykColor& operator=(const cmykColor& other) {
00130       return(copy(other));
00131     };
00132 
00133     /**
00134      * Compare two colors (true if equal!)
00135      */
00136     inline bool isEqual(const cmykColor& other) const {
00137       return (c == other.getCyan() && m == other.getMagenta()
00138               && y == other.getYellow() && k == other.getBlack());
00139     }
00140 
00141     /**
00142      * Alias for compare()
00143      */
00144     inline bool operator==(const cmykColor& other) const {
00145       return (isEqual(other));
00146     };
00147 
00148     /**
00149      * Alias for !compare()
00150      */
00151     inline bool operator!=(const cmykColor& other) const {
00152       return (!isEqual(other));
00153     };
00154 
00155     /**
00156      * An cmykColor is said to be "smaller" than another one, if
00157      * any of its component values is smaller than the other
00158      * component.
00159      */
00160     inline bool operator<(const cmykColor& other) const {
00161       return (k < other.getBlack() || c < other.getCyan()
00162               || m < other.getMagenta() || y < other.getYellow());
00163     }
00164 
00165     /**
00166      * An cmykColor is said to be "bigger" than another one, if
00167      * any of its component values is smaller than the other
00168      * component.
00169      */
00170     inline bool operator>(const cmykColor& other) const {
00171       return (k > other.getBlack() || c > other.getCyan()
00172               || m > other.getMagenta() || y > other.getYellow());
00173     }
00174 
00175 
00176   private:
00177     float c,m,y,k;
00178 
00179   };
00180 
00181 
00182   /**
00183    * read the vector from the given ioHandler.  The complete flag indicates
00184    * if the enclosing begin and end should be also be readed
00185    *
00186    * @ingroup gColor
00187    */
00188   inline bool read(ioHandler& handler,cmykColor& p,const bool complete=true) {
00189     float tmp;
00190     bool b = true;
00191 
00192     // the begin and end tokens are mandatory here! ignore the complete flag...
00193     handler.readBegin();
00194 
00195     b = b && handler.read(tmp);
00196     p.setCyan(tmp);
00197 
00198     b = b && handler.readDataSeparator();
00199 
00200     b = b && handler.read(tmp);
00201     p.setMagenta(tmp);
00202 
00203     b = b && handler.readDataSeparator();
00204 
00205     b = b && handler.read(tmp);
00206     p.setYellow(tmp);
00207 
00208     b = b && handler.readDataSeparator();
00209 
00210     b = b && handler.read(tmp);
00211     p.setBlack(tmp);
00212 
00213     b = b && handler.readEnd();
00214 
00215     return b;
00216   };
00217 
00218 
00219   /**
00220    * write the vector in the given ioHandler.  The complete flag indicates
00221    * if the enclosing begin and end should be also be written or not
00222    *
00223    * @ingroup gStorable
00224    */
00225   inline bool write(ioHandler& handler,const cmykColor& p,
00226                     const bool complete=true) {
00227     bool b = true;
00228 
00229     // the begin token is mandatory here, so ignore the complete flag
00230     b = b && handler.writeBegin();
00231 
00232     b = b && handler.write(p.getCyan());
00233     b = b && handler.writeDataSeparator();
00234     b = b && handler.write(p.getMagenta());
00235     b = b && handler.writeDataSeparator();
00236     b = b && handler.write(p.getYellow());
00237     b = b && handler.writeDataSeparator();
00238     b = b && handler.write(p.getBlack());
00239     b = b && handler.writeEnd();
00240 
00241     return b;
00242   };
00243 
00244 }
00245 
00246 #endif

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