Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PgmFile.H

Go to the documentation of this file.
00001  /*---------------------------------------------------------------------+
00002  | Library QgarLib, graphics analysis and recognition                  |
00003  | Copyright (C) 2002  Qgar Project, LORIA                             |
00004  |                                                                     |
00005  | This library is free software; you can redistribute it and/or       |
00006  | modify it under the terms of the GNU Lesser General Public          |
00007  | License version 2.1, as published by the Free Software Foundation.  |
00008  |                                                                     |
00009  | This library is distributed in the hope that it will be useful,     |
00010  | but WITHOUT ANY WARRANTY; without even the implied warranty of      |
00011  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                |
00012  | See the GNU Lesser General Public License for more details.         |
00013  |                                                                     |
00014  | The GNU Lesser General Public License is included in the file       |
00015  | LICENSE.LGPL, in the root directory of the Qgar packaging. See      |
00016  | http://www.gnu.org/licenses/lgpl.html for the terms of the licence. |
00017  | To receive a paper copy, write to the Free Software Foundation,     |
00018  | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.       |
00019  |                                                                     |
00020  | Contact Project Qgar for any information:                           |
00021  |   LORIA - équipe Qgar                                               |
00022  |   B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France                |
00023  |   email: qgar-contact@loria.fr                                      |
00024  |   http://www.qgar.org/                                              |
00025  *---------------------------------------------------------------------*/
00026 
00027 
00028 #ifndef __PGMFILE_H_INCLUDED__
00029 #define __PGMFILE_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file     PgmFile.H
00034  * @brief    Header file of class qgar::PgmFile.
00035  *
00036  * @author   <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00037  * @date     July 3,  2001  16:56
00038  * @since    Qgar 1.0
00039  */
00040 
00041 // For RCS/CVS use: Do not delete
00042 /* $Id: PgmFile.H,v 1.13 2005/07/13 16:29:02 masini Exp $ */
00043 
00044 
00045 
00046 // QGAR
00047 #include <qgarlib/AbstractPbmPlusFile.H>
00048 
00049 
00050 
00051 namespace qgar
00052 {
00053 
00054 /**
00055  * @class PgmFile PgmFile.H "qgarlib/PgmFile.H"
00056  * @ingroup IO_FILE
00057  *
00058  * @brief File containing a Grey-level image in PGM format.
00059  * 
00060  * Most of the code documented here is an adaptation of code from the PBM
00061  * software package. Here is the copyright notice of this package:
00062  *
00063 @verbatim
00064  +------------------------------------------------------------------------+
00065  | Copyright (C) 1988 by Jef Poskanzer                                    |
00066  |                                                                        |
00067  | Permission to use, copy, modify, and distribute this software and its  |
00068  | documentation for any purpose and without fee is hereby granted,       |
00069  | provided that the above copyright notice appear in all copies and that |
00070  | both that copyright notice and this permission notice appear in        |
00071  | supporting documentation.  This software is provided "as is" without   |
00072  | express or implied warranty.                                           |
00073  +------------------------------------------------------------------------+
00074 @endverbatim
00075  *
00076  *  For more information about PBM, see the
00077  *  <a href="http://www.bath.ac.uk/BUCS/Software/graphics/pbm/pbm.html">PBMPLUS home page</a>.
00078  *
00079  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00080  * @date   Jul, 3  2001  16:25
00081  * @since  Qgar 1.0
00082  */
00083 class PgmFile
00084 
00085   : public AbstractPbmPlusFile
00086 
00087 {
00088 // -------------------------------------------------------------------
00089 // P U B L I C    M E M B E R S
00090 // -------------------------------------------------------------------
00091 public:
00092 
00093   /** @name Constructors */
00094   //        ============
00095   //@{
00096 
00097   /**
00098    * @brief Initialize from file name and format.
00099    *
00100    * @param aFileName name of the new file
00101    * @param aFormat   format of the image contained in the file (default qgar::QGE_PBM_RAW)
00102    *
00103    * @warning
00104    * <ul>
00105    * <li>The number of rows and columns of the corresponding image
00106    *     are set to default (<b>0</b>).</li>
00107    * <li>Such a file cannot be opened
00108    *     in <b>write-only</b> or <b>read-write</b> modes.</li>
00109    * </ul>
00110    */
00111   PgmFile(const char* aFileName, QGEpbmFormat aFormat = QGE_PBM_RAW);
00112 
00113   /**
00114    * @brief Initialize from full data.
00115    *
00116    * @param aFileName  name of the new file
00117    * @param aRowCnt    number of rows of the corresponding image
00118    * @param aColCnt    number of columns of the corresponding image
00119    * @param aMax       maximum value of a pixel (default 255)
00120    * @param aFormat    format of the image contained in the file (default qgar::QGE_PBM_RAW)
00121    *
00122    * @warning Such a file is supposed to be used
00123    *   in <b>write-only</b> or <b>read-write</b> modes.
00124    */
00125   PgmFile(const char*  aFileName,
00126           unsigned int aRowCnt,
00127           unsigned int aColCnt,
00128           unsigned int aMax    = 255,
00129           QGEpbmFormat aFormat = QGE_PBM_RAW);
00130 
00131   //@}
00132 
00133 
00134   /** @name Access */
00135   //        ======
00136   //@{
00137 
00138   /**
00139    * @brief Get maximum value of pixel.
00140    */
00141   inline int maxPix();
00142 
00143   //@}
00144 
00145 
00146   /** @name Assignment */
00147   //        ==========
00148   //@{
00149 
00150   /**
00151    * @brief Set maximum value of pixel.
00152    */
00153   inline void setMaxPix(int aMax);
00154 
00155   //@}
00156 
00157 
00158   /** @name Input */
00159   //        =====
00160   //@{
00161 
00162   /**
00163    * @brief Read a row from the file.
00164    */
00165   void readRow();
00166 
00167   //@}
00168 
00169 
00170   /** @name Output */
00171   //        ======
00172   //@{
00173 
00174   /**
00175    * @brief Write a row into the file.
00176    */
00177   void writeRow();
00178 
00179   //@}
00180 
00181 
00182 // -------------------------------------------------------------------
00183 // P R O T E C T E D    M E M B E R S
00184 // -------------------------------------------------------------------
00185 protected:
00186 
00187   /** @name Magic numbers */
00188   //        =============
00189   //@{
00190 
00191   /**
00192    * @brief <b>PLAIN</b> format.
00193    */
00194   static const unsigned short _s_pgm_format;
00195 
00196   /**
00197    * @brief <b>PLAIN</b> format: Magic-1.
00198    */
00199   static const unsigned char  _s_pgm_magic1;
00200 
00201   /**
00202    * @brief <b>PLAIN</b> format: Magic-2.
00203    */
00204   static const unsigned char  _s_pgm_magic2;
00205 
00206   /**
00207    * @brief <b>RAW</b> format.
00208    */
00209   static const unsigned short _s_rpgm_format;
00210 
00211   /**
00212    * @brief <b>RAW</b> format: Magic-2.
00213    */
00214   static const unsigned char  _s_rpgm_magic2;
00215 
00216   //@}
00217 
00218 
00219   /** @name Image features */
00220   //        ==============
00221   //@{
00222 
00223   /**
00224    * @brief Maximum value of a pixel.
00225    */
00226   int _maxPix;
00227 
00228   //@}
00229 
00230 
00231   /** @name Input */
00232   //        =====
00233   //@{
00234 
00235   /**
00236    * @brief Read file header. 
00237    *
00238    * @exception qgar::QgarErrorIO 
00239    * (EOF while reading, bad magic number, bad max pixel value)
00240    */
00241   virtual void readHeader() throw(QgarErrorIO);
00242 
00243   //@}
00244 
00245 
00246   /** @name Output */
00247   //        ======
00248   //@{
00249 
00250   /**
00251    * @brief Write file header.
00252    */
00253   virtual void writeHeader();
00254 
00255   /**
00256    * @brief Write file footer.
00257    */
00258   virtual void writeFooter();
00259 
00260   /**
00261    * @brief Put an unsigned char into the file.
00262    */
00263   void putUchar(unsigned char);
00264 
00265   //@}
00266 
00267 
00268 // -------------------------------------------------------------------
00269 
00270 }; // class PgmFile
00271 
00272 
00273 
00274 
00275 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00276 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00277 // I N L I N E   F U N C T I O N S   I M P L E M E N T A T I O N 
00278 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00279 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00280 
00281 
00282 // ======
00283 // ACCESS
00284 // ======
00285 
00286 
00287 // GET MAXIMUM VALUE OF PIXEL
00288 
00289 inline int
00290 PgmFile::maxPix()
00291 {
00292   return _maxPix;
00293 }
00294 
00295 
00296 // ==========
00297 // ASSIGNMENT
00298 // ==========
00299 
00300 
00301 // SET MAXIMUM VALUE OF PIXEL
00302 
00303 inline void
00304 PgmFile::setMaxPix(int aMax)
00305 {
00306   _maxPix = aMax;
00307 }
00308 
00309 
00310 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00311 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00312 
00313 
00314 } // namespace qgar
00315 
00316 
00317 #endif /* __PGMFILE_H_INCLUDED__ */